Skip to content

Commit 3f3d830

Browse files
committed
Updated text fonts for modern displays.
The old fonts were too small for the current graphics layout. No longer using stock ANSI fonts; instead, create custom fonts. Fixed bugs calculating the invalidation rectangles for text areas. There is a much better function now GetTextExtentPoint32() that makes it easy to calculate the dimenions, compared with GetTextMetrics(). Made the debug area wider to fit the new larger fonts.
1 parent 9af738d commit 3f3d830

File tree

2 files changed

+60
-45
lines changed

2 files changed

+60
-45
lines changed

src/wingui.cpp

Lines changed: 54 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2464,55 +2464,54 @@ LRESULT CALLBACK ChessWndProc (
24642464
else
24652465
{
24662466
const int textSep = 2;
2467-
const int textHeight = 12;
2467+
const int textHeight = 16;
24682468
const int textWidth = 8;
24692469

24702470
ChessDisplayTextBuffer *tb = new ChessDisplayTextBuffer (
24712471
hwnd, STATIC_ID_WHITES_MOVE, CHESS_BOARD_BORDER_DX, 0,
2472-
ChessDisplayTextBuffer::margin_bottom, ANSI_VAR_FONT );
2472+
ChessDisplayTextBuffer::margin_bottom, CHENARD_PROPORTIONAL_FONT );
24732473

24742474
tb = new ChessDisplayTextBuffer (
24752475
hwnd, STATIC_ID_BLACKS_MOVE, 170, 0,
2476-
ChessDisplayTextBuffer::margin_bottom, ANSI_VAR_FONT );
2476+
ChessDisplayTextBuffer::margin_bottom, CHENARD_PROPORTIONAL_FONT);
24772477

24782478
tb = new ChessDisplayTextBuffer (
24792479
hwnd, STATIC_ID_THINKING, SQUARE_SCREENX1(8) - 8*textWidth, 0,
2480-
ChessDisplayTextBuffer::margin_bottom, ANSI_VAR_FONT );
2480+
ChessDisplayTextBuffer::margin_bottom, CHENARD_PROPORTIONAL_FONT);
24812481

24822482
int textY = 8;
24832483
int textID;
24842484
int depth = 0;
2485-
for ( textID = FIRST_RIGHT_TEXTID;
2486-
textID <= LAST_RIGHT_TEXTID;
2487-
textID++, depth++ )
2485+
for (textID = FIRST_RIGHT_TEXTID; textID <= LAST_RIGHT_TEXTID; textID++, depth++)
24882486
{
24892487
// Creating the object puts it in the class's list of instances
24902488
tb = new ChessDisplayTextBuffer (
24912489
hwnd, textID, 0, textY,
2492-
ChessDisplayTextBuffer::margin_right, ANSI_FIXED_FONT,
2490+
ChessDisplayTextBuffer::margin_right, CHENARD_MONOSPACE_FONT,
24932491
(textID>=STATIC_ID_BESTPATH(0)) ? (depth & 1) : 0 );
24942492

24952493
textY += (textHeight + textSep);
24962494
}
24972495

2498-
for ( textID = STATIC_ID_ADHOC1; textID <= STATIC_ID_ADHOC2; ++textID )
2496+
for (textID = STATIC_ID_ADHOC1; textID <= STATIC_ID_ADHOC2; ++textID)
24992497
{
25002498
tb = new ChessDisplayTextBuffer (
25012499
hwnd, textID, 0, textY,
2502-
ChessDisplayTextBuffer::margin_right, ANSI_FIXED_FONT, 0 );
2500+
ChessDisplayTextBuffer::margin_right, CHENARD_MONOSPACE_FONT, 0 );
25032501

25042502
textY += (textHeight + textSep);
25052503
}
25062504

25072505
char coordString [2] = {0, 0};
2508-
for ( int coord = 0; coord < 8; ++coord )
2506+
for (int coord = 0; coord < 8; ++coord)
25092507
{
25102508
tb = new ChessDisplayTextBuffer (
25112509
hwnd, STATIC_ID_COORD_RANK_BASE + coord,
25122510
0, // x-coord will be calculated later by RepositionAll()
25132511
0, // same for y-coord
25142512
ChessDisplayTextBuffer::margin_rank,
2515-
ANSI_VAR_FONT, 1 );
2513+
CHENARD_PROPORTIONAL_FONT,
2514+
1 );
25162515

25172516
coordString[0] = '1' + coord;
25182517
tb->setText ( coordString );
@@ -2522,7 +2521,8 @@ LRESULT CALLBACK ChessWndProc (
25222521
0, // x-coord will be calculated later by RepositionAll()
25232522
0, // same for y-coord
25242523
ChessDisplayTextBuffer::margin_file,
2525-
ANSI_VAR_FONT, 1 );
2524+
CHENARD_PROPORTIONAL_FONT,
2525+
1 );
25262526

25272527
coordString[0] = 'a' + coord;
25282528
tb->setText ( coordString );
@@ -2537,7 +2537,7 @@ LRESULT CALLBACK ChessWndProc (
25372537
0, // x-coord will be calculated later by RepositionAll()
25382538
0, // same for y-coord
25392539
ChessDisplayTextBuffer::margin_center,
2540-
0, // HACK: use large font
2540+
CHENARD_GAMERESULT_FONT,
25412541
1,
25422542
false // transparent background
25432543
);
@@ -2552,7 +2552,7 @@ LRESULT CALLBACK ChessWndProc (
25522552
0, // x-coord calculated by RepositionAll()
25532553
0, // y-coord calculated by RepositionAll()
25542554
ChessDisplayTextBuffer::margin_blunderAnalysis,
2555-
ANSI_VAR_FONT
2555+
CHENARD_PROPORTIONAL_FONT
25562556
);
25572557

25582558
// Make blunder line somewhat reddish color...
@@ -2565,7 +2565,7 @@ LRESULT CALLBACK ChessWndProc (
25652565
0, // x-coord calculated by RepositionAll()
25662566
0, // y-coord calculated by RepositionAll()
25672567
ChessDisplayTextBuffer::margin_betterAnalysis,
2568-
ANSI_VAR_FONT,
2568+
CHENARD_PROPORTIONAL_FONT,
25692569
1 // highlight yellow
25702570
);
25712571

@@ -3327,7 +3327,7 @@ void ChessBeep ( int freq, int duration )
33273327
//------------------------------------------------------------------
33283328

33293329

3330-
ChessDisplayTextBuffer *ChessDisplayTextBuffer::All = 0;
3330+
ChessDisplayTextBuffer *ChessDisplayTextBuffer::All = nullptr;
33313331

33323332

33333333
ChessDisplayTextBuffer::ChessDisplayTextBuffer (
@@ -3445,47 +3445,59 @@ void ChessDisplayTextBuffer::calcRegion ( RECT &rect ) const
34453445
rect.left = x;
34463446
rect.top = y;
34473447

3448-
HDC hdc = GetDC(hwnd);
3449-
TEXTMETRIC tm;
3450-
HFONT font = createFont();
3451-
HFONT oldFont = (HFONT) SelectObject(hdc, font);
3452-
GetTextMetrics ( hdc, &tm );
3453-
SelectObject ( hdc, oldFont );
3454-
deleteFont(font);
3455-
ReleaseDC ( hwnd, hdc );
3448+
SIZE size;
3449+
size.cx = 0;
3450+
size.cy = 0;
3451+
3452+
if (text != nullptr)
3453+
{
3454+
HDC hdc = GetDC(hwnd);
3455+
HFONT font = createFont();
3456+
HFONT oldFont = (HFONT)SelectObject(hdc, font);
3457+
GetTextExtentPoint32(hdc, text, (int)strlen(text), &size);
3458+
SelectObject(hdc, oldFont);
3459+
deleteFont(font);
3460+
ReleaseDC(hwnd, hdc);
3461+
}
34563462

3457-
size_t numChars = text ? strlen(text) : 0;
3458-
rect.right = (LONG) (x + numChars * tm.tmAveCharWidth + 3);
3459-
rect.bottom = (LONG) (y + tm.tmHeight + tm.tmExternalLeading + 3);
3463+
rect.right = (LONG)(x + size.cx);
3464+
rect.bottom = (LONG)(y + size.cy);
34603465
}
34613466

34623467

34633468
HFONT ChessDisplayTextBuffer::createFont() const
34643469
{
34653470
HFONT font;
3466-
if (textFont == 0)
3471+
3472+
switch (textFont)
34673473
{
3468-
// Hack: create our own special large font.
3469-
// This is used for the game result text.
3470-
// http://msdn.microsoft.com/en-us/library/windows/desktop/dd183499(v=vs.85).aspx
3474+
case CHENARD_GAMERESULT_FONT:
34713475
font = CreateFont(
3472-
48, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, DEFAULT_CHARSET, 0,
3473-
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, VARIABLE_PITCH, "Arial");
3474-
}
3475-
else
3476-
{
3477-
font = (HFONT)GetStockObject(textFont);
3476+
80, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, DEFAULT_CHARSET, 0,
3477+
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, VARIABLE_PITCH, "Arial");
3478+
break;
3479+
3480+
case CHENARD_PROPORTIONAL_FONT:
3481+
font = CreateFont(
3482+
16, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, DEFAULT_CHARSET, 0,
3483+
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, VARIABLE_PITCH, "Arial");
3484+
break;
3485+
3486+
case CHENARD_MONOSPACE_FONT:
3487+
default:
3488+
font = CreateFont(
3489+
18, 0, 0, 0, FW_DONTCARE, FALSE, FALSE, FALSE, DEFAULT_CHARSET, 0,
3490+
CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, VARIABLE_PITCH, "Courier New");
3491+
break;
34783492
}
3493+
34793494
return font;
34803495
}
34813496

34823497
void ChessDisplayTextBuffer::deleteFont(HFONT font) const
34833498
{
3484-
if (textFont == 0)
3485-
{
3486-
// Clean up our custom font.
3499+
if (font != NULL)
34873500
DeleteObject(font);
3488-
}
34893501
}
34903502

34913503

src/winguich.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ extern int RawBitmapDX, RawBitmapDY;
6464
extern int ChessBoardSize; // facilitates saving/loading option (0=small, 1=medium, 2=large)
6565
void NewBoardSize ( int );
6666

67+
#define CHENARD_MONOSPACE_FONT 1001
68+
#define CHENARD_PROPORTIONAL_FONT 1002
69+
#define CHENARD_GAMERESULT_FONT 1003
70+
6771
// Added following 3 Jan 1999 for displaying rank numbers and file letters...
6872
#define CHESS_LEFT_MARGIN 8
6973
#define CHESS_BOTTOM_MARGIN 16
@@ -93,7 +97,7 @@ void NewBoardSize ( int );
9397
#define SQUARE_CHESSY(y) (7-(((y)-CHESS_BOARD_BORDER_DY)/CHESS_BITMAP_DY))
9498

9599
// Width of the text debug display area in the client window...
96-
#define DEBUG_WINDOW_DX 200
100+
#define DEBUG_WINDOW_DX 240
97101

98102
// Extra window height when either player has blunder alert enabled...
99103
#define BLUNDER_WINDOW_DY 50
@@ -125,7 +129,6 @@ void NewBoardSize ( int );
125129
#define LAST_RIGHT_TEXTID STATIC_ID_BESTPATH(MAX_BESTPATH_DISPLAY)
126130

127131
#define MAX_CHESS_TEXT 128
128-
#define CHESS_TEXT_FONT ANSI_FIXED_FONT
129132
#define CHESS_TEXT_COLOR RGB(255,255,255)
130133
#define CHESS_TEXT_COLOR2 RGB(255,255,0)
131134
#define CHESS_BACKGROUND_COLOR RGB(0,0,127)
@@ -150,7 +153,7 @@ class ChessDisplayTextBuffer
150153
};
151154

152155
ChessDisplayTextBuffer ( HWND, int _id, int _x, int _y,
153-
marginType _margin=margin_right, int _textFont=ANSI_FIXED_FONT,
156+
marginType _margin=margin_right, int _textFont=CHENARD_MONOSPACE_FONT,
154157
int _highlight = 0,
155158
bool _isBackgroundOpaque = true);
156159

0 commit comments

Comments
 (0)