@@ -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
33333333ChessDisplayTextBuffer::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
34633468HFONT 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
34823497void 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
0 commit comments