Skip to content

Commit c424d97

Browse files
committed
Fixed #28 - display question mark on promotion target square.
When a human player is promoting a pawn, right before displaying the dialog box to pick the promotion piece, display a pawn in the promotion square with a little question mark symbol near it. Before now, we were not even putting the pawn there yet. This is a much better visual signal to reflect the promotion.
1 parent a92acc9 commit c424d97

File tree

12 files changed

+88
-16
lines changed

12 files changed

+88
-16
lines changed

chenserver/uiserver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ bool ChessUI_Server::ReadMove(
3939
return false;
4040
}
4141

42-
SQUARE ChessUI_Server::PromotePawn(int /*PawnDest*/, ChessSide)
42+
SQUARE ChessUI_Server::PromotePawn(int /*PawnSource*/, int /*PawnDest*/, ChessSide)
4343
{
4444
ChessFatal("ChessUI_Server::PromotePawn() should not have been called!");
4545
return 0;

chenserver/uiserver.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class ChessUI_Server : public ChessUI
3939
// Must return one of the following values:
4040
// Q_INDEX, R_INDEX, B_INDEX, N_INDEX
4141
//--------------------------------------------------------------
42-
virtual SQUARE PromotePawn(int PawnDest, ChessSide);
42+
virtual SQUARE PromotePawn(int PawnSource, int PawnDest, ChessSide);
4343

4444
//--------------------------------------------------------------
4545
// The following function should display the given Move

src/chess.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ class ChessUI
503503
// Must return one of the following values:
504504
// Q_INDEX, R_INDEX, B_INDEX, N_INDEX
505505
//--------------------------------------------------------------
506-
virtual SQUARE PromotePawn ( int PawnDest, ChessSide ) = 0;
506+
virtual SQUARE PromotePawn(int PawnSource, int PawnDest, ChessSide) = 0;
507507

508508
//--------------------------------------------------------------
509509
// The following member function is called bracketing

src/misc.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ void Move::Fix (
398398
dest = SPECIAL_MOVE_PROMOTE_CAP_WEST | Q_INDEX;
399399

400400
if (LegalMoves.IsLegal(*this))
401-
prom = Ui.PromotePawn(Dest, side);
401+
prom = Ui.PromotePawn(Source, Dest, side);
402402
else
403403
prom = Q_INDEX; // caller will also notice promotion is illegal
404404
}
@@ -426,7 +426,7 @@ void Move::Fix (
426426
// If promoting to a queen is legal, then underpromoting is legal too.
427427
dest = SPECIAL_MOVE_PROMOTE_NORM | Q_INDEX;
428428
if (LegalMoves.IsLegal(*this))
429-
prom = Ui.PromotePawn(Dest, side);
429+
prom = Ui.PromotePawn(Source, Dest, side);
430430
else
431431
prom = Q_INDEX; // caller will also notice promotion is illegal
432432
}

src/uistdio.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,7 +704,7 @@ static int AskPawnPromote()
704704

705705

706706

707-
SQUARE ChessUI_stdio::PromotePawn ( int, ChessSide )
707+
SQUARE ChessUI_stdio::PromotePawn ( int, int, ChessSide )
708708
{
709709
return AskPawnPromote();
710710
}

src/uistdio.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ChessUI_stdio: public ChessUI
4444

4545
ChessPlayer *CreatePlayer ( ChessSide );
4646
bool ReadMove ( ChessBoard &, int &source, int &dest, SQUARE &promIndex );
47-
SQUARE PromotePawn ( int PawnDest, ChessSide );
47+
SQUARE PromotePawn ( int PawnSource, int PawnDest, ChessSide );
4848
void DisplayMove ( ChessBoard &, Move );
4949
void RecordMove ( ChessBoard &, Move, INT32 thinkTime );
5050
void DrawBoard ( const ChessBoard & );

src/uiwin32.cpp

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,14 +1481,23 @@ bool ChessUI_win32_gui::ReadMove (
14811481
}
14821482

14831483

1484-
SQUARE ChessUI_win32_gui::PromotePawn ( int, ChessSide side )
1484+
SQUARE ChessUI_win32_gui::PromotePawn(int source, int dest, ChessSide side)
14851485
{
1486+
const int sx = XPART(source) - 2;
1487+
const int sy = YPART(source) - 2;
1488+
const int dx = XPART(dest) - 2;
1489+
const int dy = YPART(dest) - 2;
1490+
1491+
TheBoardDisplayBuffer.enterPawnPromotionPrompt(side, sx, sy, dx, dy);
1492+
14861493
static volatile SQUARE prom;
14871494
prom = EMPTY;
14881495
PostMessage ( hwnd, WM_DDC_PROMOTE_PAWN, WPARAM(side), LPARAM(&prom) );
14891496

1490-
while ( prom == EMPTY )
1491-
Sleep ( 100 );
1497+
while (prom == EMPTY)
1498+
Sleep(100);
1499+
1500+
TheBoardDisplayBuffer.exitPawnPromotionPrompt();
14921501

14931502
return prom;
14941503
}

src/uixboard.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ bool ChessUI_xboard::ReadMove ( ChessBoard &, int & /*source*/, int & /*dest*/,
246246
}
247247

248248

249-
SQUARE ChessUI_xboard::PromotePawn ( int /*PawnDest*/, ChessSide )
249+
SQUARE ChessUI_xboard::PromotePawn ( int /*PawnSource*/, int /*PawnDest*/, ChessSide )
250250
{
251251
ChessFatal ("Should not have been called: ChessUI_xboard::PromotePawn()");
252252
return EMPTY;

src/uixboard.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class ChessUI_xboard: public ChessUI
4747

4848
ChessPlayer *CreatePlayer ( ChessSide );
4949
bool ReadMove ( ChessBoard &, int &source, int &dest, SQUARE &promIndex );
50-
SQUARE PromotePawn ( int PawnDest, ChessSide );
50+
SQUARE PromotePawn ( int PawnSource, int PawnDest, ChessSide );
5151
void DisplayMove ( ChessBoard &, Move );
5252
void RecordMove ( ChessBoard &, Move, INT32 thinkTime );
5353
void DrawBoard ( const ChessBoard & );

src/wbrdbuf.cpp

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ BoardDisplayBuffer::BoardDisplayBuffer():
4646
hiliteKeyX ( 3 ),
4747
hiliteKeyY ( 3 ),
4848
algebraicRank('\0'),
49-
tempHDC ( 0 )
49+
tempHDC(nullptr),
50+
inPromotionPrompt(false),
51+
prom_x(-1),
52+
prom_y(-1)
5053
{
5154
for ( int x=0; x < 8; x++ )
5255
{
@@ -290,6 +293,32 @@ void BoardDisplayBuffer::drawSquare (
290293
DeleteObject ( hpen );
291294
}
292295

296+
if (inPromotionPrompt && (x == prom_x) && (y == prom_y))
297+
{
298+
// Draw a "?" on top of the pawn being promoted.
299+
const char* text = "?";
300+
301+
HFONT font = CreateFont(
302+
32, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, DEFAULT_CHARSET, 0,
303+
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, VARIABLE_PITCH, "Arial");
304+
305+
HFONT oldfont = (HFONT)SelectObject(hdc, font);
306+
307+
SIZE size;
308+
GetTextExtentPoint32(hdc, text, (int)strlen(text), &size);
309+
int text_x = xStart + (5*(CHESS_BITMAP_DX - size.cx) / 6);
310+
int text_y = yStart + (1*(CHESS_BITMAP_DY - size.cy) / 6);
311+
312+
int prevMode = SetBkMode(hdc, TRANSPARENT);
313+
COLORREF oldTextColor = SetTextColor(hdc, RGB(99, 14, 98));
314+
TextOut(hdc, text_x, text_y, text, (int)strlen(text));
315+
SetTextColor(hdc, oldTextColor);
316+
SetBkMode(hdc, prevMode);
317+
318+
SelectObject(hdc, oldfont);
319+
DeleteObject(font);
320+
}
321+
293322
changed[x][y] = false;
294323
}
295324

@@ -593,6 +622,34 @@ void BoardDisplayBuffer::sendAlgebraicChar(char c)
593622
}
594623

595624

625+
void BoardDisplayBuffer::enterPawnPromotionPrompt(ChessSide side, int sx, int sy, int dx, int dy)
626+
{
627+
if (DisplayCoordsValid(sx, sy) && DisplayCoordsValid(dx, dy))
628+
{
629+
prom_x = dx;
630+
prom_y = dy;
631+
inPromotionPrompt = true;
632+
setSquareContents(sx, sy, EMPTY);
633+
setSquareContents(dx, dy, (side == SIDE_WHITE) ? WPAWN : BPAWN);
634+
freshenSquare(sx, sy);
635+
freshenSquare(dx, dy);
636+
}
637+
else
638+
{
639+
ChessFatal("Entered pawn promotion prompt with invalid coordinates.");
640+
}
641+
}
642+
643+
644+
void BoardDisplayBuffer::exitPawnPromotionPrompt()
645+
{
646+
inPromotionPrompt = false;
647+
prom_x = -1;
648+
prom_y = -1;
649+
}
650+
651+
652+
596653
BoardDisplayBuffer TheBoardDisplayBuffer;
597654

598655

0 commit comments

Comments
 (0)