-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFadeTile.cpp
More file actions
155 lines (129 loc) · 3.14 KB
/
FadeTile.cpp
File metadata and controls
155 lines (129 loc) · 3.14 KB
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
// FadeTile.cpp: implementation of the CFadeTile class.
//
//////////////////////////////////////////////////////////////////////
#include "FadeTile.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CFadeTile::CFadeTile()
{
RGBShade = 30;
PixelX = 0;
PixelY = 0;
iShade = RGBShade;
Screen = NULL;
memset(TileBuffer, 0, sizeof(TileBuffer));
}
CFadeTile::~CFadeTile()
{
}
void CFadeTile::CopyTile(int x, int y, int iShade/*=0*/, int iShadeLevel/*=19*/)
{
// Copies the pixels of this 40x40 tile into a buffer for redrawing later.
SetPos(x, y);
if (iShadeLevel > 40)
iShadeLevel = 40;
for (int i=0; i<40; i++)
for (int j=0; j<40; j++)
{
COLORREF pColor = -1;
if (PixelX+i > -1 && PixelY+j > -1)
{
pColor = Screen->GetBack()->GetPixel(PixelX+i, PixelY+j);
// Pull out R,G,B and convert to 565 format.
int r = GetRValue(pColor);
int g = GetGValue(pColor);
int b = GetBValue(pColor);
r >>= 3; // 8-bit to 5-bit
g >>= 2; // 8-bit to 6-bit
b >>= 3; // 8-bit to 5-bit
if (iShade == 1 && i < iShadeLevel)
{
// SHADE LEFT OF TILE
if (pColor > 0)
{
/*r -= (iShadeLevel)-i;
g -= (iShadeLevel)-i;
b -= (iShadeLevel)-i;*/
if (r < 0) r = 0;
if (g < 0) g = 0;
if (b < 0) b = 0;
pColor = RGB565(r, g, b);
}
}
else if (iShade == 2 && i > iShadeLevel)
{
// SHADE RIGHT OF TILE
if (pColor > 0)
{
/*r -= i-(iShadeLevel);
g -= i-(iShadeLevel);
b -= i-(iShadeLevel);*/
if (r < 0) r = 0;
if (g < 0) g = 0;
if (b < 0) b = 0;
pColor = RGB565(r, g, b);
}
}
else if (iShade == 3 && j < iShadeLevel)
{
// SHADE TOP OF TILE
if (pColor > 0)
{
/*r -= (iShadeLevel)-j;
g -= (iShadeLevel)-j;
b -= (iShadeLevel)-j;*/
if (r < 0) r = 0;
if (g < 0) g = 0;
if (b < 0) b = 0;
pColor = RGB565(r, g, b);
}
}
else if (iShade == 4 && j > iShadeLevel)
{
// SHADE BOTTOM OF TILE
if (pColor > 0)
{
/*r -= j-(iShadeLevel);
g -= j-(iShadeLevel);
b -= j-(iShadeLevel);*/
if (r < 0) r = 0;
if (g < 0) g = 0;
if (b < 0) b = 0;
pColor = RGB565(r, g, b);
}
}
}
TileBuffer[i][j] = pColor;
}
}
void CFadeTile::DrawTile()
{
for (int i=0; i<40; i++)
for (int j=0; j<40; j++)
{
COLORREF pColor = TileBuffer[i][j];
if (pColor != -1 && (PixelX+i > -1) && (PixelY+j > -1))
Screen->GetBack()->PutPixel(PixelX+i, PixelY+j, pColor);
}
}
/*void CFadeTile::Draw()
{
if (Screen == NULL)
return;
// USER MUST LOCK SURFACE!
if (iShade > 0)
for (int xx=0; xx < 40; xx++)
for (int yy=0; yy < 40; yy++)
{
int pColor = Screen->GetBack()->GetPixel24(PixelX + xx, PixelY+yy);
if (pColor != 0)
{
pColor -= RGB565(iShade,iShade,iShade);
if (pColor < 0) pColor = 0;
Screen->GetBack()->PutPixel24(PixelX + xx, PixelY+yy, pColor);
}
}
if (iShade < 1)
iShade = RGBShade;
}*/