-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCFillData.cpp
165 lines (147 loc) · 3.48 KB
/
CFillData.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#include "common.h"
/* CALLBACK */
CFillUser::CFillUser(RUNDATA* __rdPtr, const TCHAR* name)
{
fillName = _tcsdup(name);
rdPtr = __rdPtr;
}
CFillUser::~CFillUser()
{
free(fillName);
}
BOOL CFillUser::Fill(cSurface FAR * pSf, int l, int t, int r, int b, BOOL bForceOpaqueBlack)
{
//Save temporary infos
//rdPtr->userData = fillName;
//rdPtr->userRect.left = l;
//rdPtr->userRect.top = t;
//rdPtr->userRect.right = r;
//rdPtr->userRect.bottom = b;
//Loop through all pixels
for(rdPtr->callX=l; rdPtr->callX<=r; ++rdPtr->callX)
{
for(rdPtr->callY=t; rdPtr->callY<=b; ++rdPtr->callY)
{
rdPtr->colRet = false;
rdPtr->callback = fillName;
rdPtr->rRd->GenerateEvent(8);
//Sucessfully returned from the action!
if(rdPtr->colRet)
pSf->SetPixel(rdPtr->callX,rdPtr->callY,rdPtr->colNew);
}
}
return TRUE;
}
//BOOL CFillUser::Fill(cSurface FAR * pSf, int l, int t, int r, int b, BOOL bForceOpaqueBlack)
//{
// //Save temporary infos
// rdPtr->userData = fillName;
// rdPtr->userRect.left = l;
// rdPtr->userRect.top = t;
// rdPtr->userRect.right = r;
// rdPtr->userRect.bottom = b;
//
// //Color channel
// BYTE* buff;
// buff = TargetImg->LockBuffer();
// if(!buff) return FALSE;
//
// int height = b-t;
// int pitch = TargetImg->GetPitch();
// if(pitch < 0)
// {
// pitch *= -1;
// buff -= pitch*(height-1);
// }
// int size = pitch*height;
// int byte = TargetImg->GetDepth()>>3;
//
// for(rdPtr->userX=l;rdPtr->userX<=r;rdPtr->userX++)
// {
// for(rdPtr->userY=t;rdPtr->userY<=b;rdPtr->userY++)
// {
// BYTE* p = buff+rdPtr->userY*pitch+rdPtr->userX*byte;
// rdPtr->userTrigger = false;
// rdPtr->rRd->GenerateEvent(8);
// //Sucessfully returned from the action!
// if(rdPtr->userTrigger)
// {
// memcpy(p,&rdPtr->userCol,3);
// p[0] ^= p[2] ^= p[0] ^= p[2];
// }
// }
// }
//
// TargetImg->UnlockBuffer(buff);
//
// return TRUE;
//}
/* LINEAR GRADIENT */
CFillDirEx::CFillDirEx(COLORREF crFrom, COLORREF crTo, BOOL Vertical)
{
m_crFrom = crFrom;
m_crTo = crTo;
m_vert = Vertical;
}
void CFillDirEx::SetColors(COLORREF crFrom, COLORREF crTo)
{
m_crFrom = crFrom;
m_crTo = crTo;
}
void CFillDirEx::SetDir(BOOL vert)
{
m_vert = vert;
}
BOOL CFillDirEx::Fill(cSurface FAR * pSf, int l, int t, int r, int b, BOOL bForceOpaqueBlack)
{
BYTE ra=GetRValue(m_crFrom),ga=GetGValue(m_crFrom),ba=GetBValue(m_crFrom),
rb=GetRValue(m_crTo),gb=GetGValue(m_crTo),bb=GetBValue(m_crTo);
for(int x=l;x<=r;x++)
{
for(int y=t;y<=b;y++)
{
//Get percentage
float fade;
fade = m_vert?y/(float)(b-t):x/(float)(r-l);
//Fade colors
int cr,cg,cb;
cr = ra+(rb-ra)*fade;
cg = ga+(gb-ga)*fade;
cb = ba+(bb-ba)*fade;
pSf->SetPixel(x,y,RGB(cr,cg,cb));
}
}
return TRUE;
}
/* RADIAL GRADIENT */
CFillRadial::CFillRadial(COLORREF crFrom, COLORREF crTo)
{
m_crFrom = crFrom;
m_crTo = crTo;
}
void CFillRadial::SetColors(COLORREF crFrom, COLORREF crTo)
{
m_crFrom = crFrom;
m_crTo = crTo;
}
BOOL CFillRadial::Fill(cSurface FAR * pSf, int l, int t, int r, int b, BOOL bForceOpaqueBlack)
{
float cx = (r-l)/2.0f;
float cy = (b-t)/2.0f;
BYTE ra=GetRValue(m_crFrom),ga=GetGValue(m_crFrom),ba=GetBValue(m_crFrom),
rb=GetRValue(m_crTo),gb=GetGValue(m_crTo),bb=GetBValue(m_crTo);
for(int x=l;x<=r;x++)
{
for(int y=t;y<=b;y++)
{
float fade = sqrt(pow((x-cx)/cx,2)+pow((y-cy)/cy,2));
fade = max(0.0f,min(1.0f,fade));
int cr,cg,cb;
cr = ra+(rb-ra)*fade;
cg = ga+(gb-ga)*fade;
cb = ba+(bb-ba)*fade;
pSf->SetPixel(x,y,RGB(cr,cg,cb));
}
}
return TRUE;
}