Fix logo repainting
authorH.G. Muller <h.g.muller@hccnet.nl>
Tue, 11 Jan 2011 10:18:15 +0000 (11:18 +0100)
committerArun Persaud <arun@nubati.net>
Sat, 29 Jan 2011 02:13:15 +0000 (18:13 -0800)
The logos were not repainted when the main window was moved out of the
display area, and then back into view. The reason for this is
unknown, as the PaintProc calls HDCDrawPosition, which was calling
DrawLogoOnDC. But the logos were not drawn, (or on an expose event
sometimes half drawn!) despite the fact that the rest of the board was.
The drawing of logos now has been decoupled from drawing the board,
and has been moved to a separate routine DisplayLogos() (in analogy to
DisplayBothClocks()). This is cleaner anyway, as the logos usually do
not change when the board does. So apart from in PaintProc, it has only
to be called when the mode changes (ModeHighlight()) or on swap clocks.
This seems to fix the problem.

winboard/winboard.c

index 4f0fc10..5cf1712 100644 (file)
@@ -3394,6 +3394,48 @@ DrawLogoOnDC(HDC hdc, RECT logoRect, HBITMAP logo)
   DeleteDC(tmphdc);\r
 }\r
 \r
+VOID\r
+DisplayLogos()\r
+{\r
+  if(logoHeight) {\r
+       HDC hdc = GetDC(hwndMain);\r
+       HBITMAP whiteLogo = (HBITMAP) first.programLogo, blackLogo = (HBITMAP) second.programLogo;\r
+       if(appData.autoLogo) {\r
+         \r
+         switch(gameMode) { // pick logos based on game mode\r
+           case IcsObserving:\r
+               whiteLogo = second.programLogo; // ICS logo\r
+               blackLogo = second.programLogo;\r
+           default:\r
+               break;\r
+           case IcsPlayingWhite:\r
+               if(!appData.zippyPlay) whiteLogo = userLogo;\r
+               blackLogo = second.programLogo; // ICS logo\r
+               break;\r
+           case IcsPlayingBlack:\r
+               whiteLogo = second.programLogo; // ICS logo\r
+               blackLogo = appData.zippyPlay ? first.programLogo : userLogo;\r
+               break;\r
+           case TwoMachinesPlay:\r
+               if(first.twoMachinesColor[0] == 'b') {\r
+                   whiteLogo = second.programLogo;\r
+                   blackLogo = first.programLogo;\r
+               }\r
+               break;\r
+           case MachinePlaysWhite:\r
+               blackLogo = userLogo;\r
+               break;\r
+           case MachinePlaysBlack:\r
+               whiteLogo = userLogo;\r
+               blackLogo = first.programLogo;\r
+         }\r
+       }\r
+       DrawLogoOnDC(hdc, leftLogoRect, flipClock ? blackLogo : whiteLogo);\r
+       DrawLogoOnDC(hdc, rightLogoRect, flipClock ? whiteLogo : blackLogo);\r
+       ReleaseDC(hwndMain, hdc);\r
+  }\r
+}\r
+\r
 static HDC hdcSeek;\r
 \r
 // [HGM] seekgraph\r
@@ -3732,41 +3774,6 @@ HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board)
        }\r
     }\r
   }\r
-  if(logoHeight) {\r
-       HBITMAP whiteLogo = (HBITMAP) first.programLogo, blackLogo = (HBITMAP) second.programLogo;\r
-       if(appData.autoLogo) {\r
-         \r
-         switch(gameMode) { // pick logos based on game mode\r
-           case IcsObserving:\r
-               whiteLogo = second.programLogo; // ICS logo\r
-               blackLogo = second.programLogo;\r
-           default:\r
-               break;\r
-           case IcsPlayingWhite:\r
-               if(!appData.zippyPlay) whiteLogo = userLogo;\r
-               blackLogo = second.programLogo; // ICS logo\r
-               break;\r
-           case IcsPlayingBlack:\r
-               whiteLogo = second.programLogo; // ICS logo\r
-               blackLogo = appData.zippyPlay ? first.programLogo : userLogo;\r
-               break;\r
-           case TwoMachinesPlay:\r
-               if(first.twoMachinesColor[0] == 'b') {\r
-                   whiteLogo = second.programLogo;\r
-                   blackLogo = first.programLogo;\r
-               }\r
-               break;\r
-           case MachinePlaysWhite:\r
-               blackLogo = userLogo;\r
-               break;\r
-           case MachinePlaysBlack:\r
-               whiteLogo = userLogo;\r
-               blackLogo = first.programLogo;\r
-         }\r
-       }\r
-       DrawLogoOnDC(hdc, leftLogoRect, flipClock ? blackLogo : whiteLogo);\r
-       DrawLogoOnDC(hdc, rightLogoRect, flipClock ? whiteLogo : blackLogo);\r
-  }\r
 \r
   if( appData.highlightMoveWithArrow ) {\r
     DrawArrowHighlight(hdcmem);\r
@@ -3981,6 +3988,7 @@ PaintProc(HWND hwnd)
                 &messageRect, messageText, strlen(messageText), NULL);\r
       SelectObject(hdc, oldFont);\r
       DisplayBothClocks();\r
+      DisplayLogos();\r
     }\r
     EndPaint(hwnd,&ps);\r
   }\r
@@ -5068,7 +5076,7 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
     case IDM_FlipClock:\r
       flipClock = !flipClock;\r
       DisplayBothClocks();\r
-      DrawPosition(FALSE, NULL);\r
+      DisplayLogos();\r
       break;\r
 \r
     case IDM_MuteSounds:\r
@@ -8020,6 +8028,7 @@ ModeHighlight()
                        MF_BYCOMMAND|MF_UNCHECKED);\r
        }\r
   }\r
+  DisplayLogos(); // [HGM] logos: mode change could have altered logos\r
 }\r
 \r
 VOID\r