Skip to content

Commit 90c104b

Browse files
committed
New improved piece graphics: now drawing light and dark squares again.
Now that the piece bitmaps have transparent parts, I needed to add special code to draw the light and dark squares beneath them.
1 parent 5e3ce40 commit 90c104b

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

src/wbrdbuf.cpp

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -184,9 +184,9 @@ void DrawBitmap (
184184
}
185185

186186

187-
void DrawOffboard ( HDC hdc, int x, int y, bool whiteViewFlag )
187+
static void FillSquare(HDC hdc, int x, int y, bool whiteViewFlag, COLORREF color)
188188
{
189-
if ( !whiteViewFlag )
189+
if (!whiteViewFlag)
190190
{
191191
x = 7 - x;
192192
y = 7 - y;
@@ -198,11 +198,11 @@ void DrawOffboard ( HDC hdc, int x, int y, bool whiteViewFlag )
198198
rect.top = SQUARE_SCREENY1(y);
199199
rect.bottom = SQUARE_SCREENY2(y)+1;
200200

201-
HBRUSH hbrush = CreateSolidBrush (CHESS_BACKGROUND_COLOR);
201+
HBRUSH hbrush = CreateSolidBrush(color);
202202
HBRUSH oldBrush = (HBRUSH)SelectObject ( hdc, hbrush );
203-
FillRect ( hdc, &rect, hbrush );
204-
SelectObject ( hdc, oldBrush );
205-
DeleteObject ( hbrush );
203+
FillRect(hdc, &rect, hbrush);
204+
SelectObject(hdc, oldBrush);
205+
DeleteObject(hbrush);
206206
}
207207

208208

@@ -215,7 +215,6 @@ void BoardDisplayBuffer::drawSquare (
215215
HBRUSH oldbrush;
216216
HPEN hpen;
217217
HPEN oldpen;
218-
int whiteSquare = (x + y) & 1;
219218

220219
// FIXFIXFIX_GRAPHICS - render light and dark squares beneath transparent bitmaps
221220

@@ -235,28 +234,27 @@ void BoardDisplayBuffer::drawSquare (
235234
case BQUEEN: hbm = bq; break;
236235
case BKING: hbm = bk; break;
237236

238-
case OFFBOARD: DrawOffboard(hdc,x,y,whiteViewFlag); return;
239-
240-
//case EMPTY: hbm = whiteSquare ? ew : eb; break;
237+
case OFFBOARD: FillSquare(hdc,x,y,whiteViewFlag, CHESS_BACKGROUND_COLOR); return;
241238
default: hbm = NULL;
242239
}
243240

244-
DrawOffboard(hdc, x, y, whiteViewFlag); // FIXFIXFIX_GRAPHICS !!! HACK TO TEST TRANSPARENT BITMAPS
241+
COLORREF squareColor = ((x + y) & 1) ? CHESS_LIGHT_SQUARE : CHESS_DARK_SQUARE;
242+
FillSquare(hdc, x, y, whiteViewFlag, squareColor);
245243

246244
short xStart, yStart;
247245

248-
if ( whiteViewFlag )
246+
if (whiteViewFlag)
249247
{
250-
xStart = SQUARE_SCREENX1 ( x );
251-
yStart = SQUARE_SCREENY1 ( y );
248+
xStart = SQUARE_SCREENX1(x);
249+
yStart = SQUARE_SCREENY1(y);
252250
}
253251
else
254252
{
255-
xStart = SQUARE_SCREENX1 ( 7 - x );
256-
yStart = SQUARE_SCREENY1 ( 7 - y );
253+
xStart = SQUARE_SCREENX1(7 - x);
254+
yStart = SQUARE_SCREENY1(7 - y);
257255
}
258256

259-
if (hdc != NULL)
257+
if (hbm != NULL)
260258
DrawBitmap(hdc, hbm, xStart, yStart);
261259

262260
if ( selX == x && selY == y )

src/winguich.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ void NewBoardSize ( int );
129129
#define CHESS_TEXT_COLOR RGB(255,255,255)
130130
#define CHESS_TEXT_COLOR2 RGB(255,255,0)
131131
#define CHESS_BACKGROUND_COLOR RGB(0,0,127)
132+
#define CHESS_LIGHT_SQUARE RGB(213, 219, 200)
133+
#define CHESS_DARK_SQUARE RGB(155, 174, 199)
132134

133135
bool ProcessChessCommands ( ChessBoard &board, int &source, int &dest );
134136

0 commit comments

Comments
 (0)