Implement (inaccessible) dark squares
[xboard.git] / winboard / winboard.c
index 1651947..e5df6db 100644 (file)
@@ -5,7 +5,7 @@
  * Massachusetts. \r
  *\r
  * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006,\r
- * 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.\r
+ * 2007, 2008, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc.\r
  *\r
  * Enhancements Copyright 2005 Alessandro Scotti\r
  *\r
@@ -187,6 +187,7 @@ Boolean alwaysOnTop = FALSE;
 RECT boardRect;\r
 COLORREF lightSquareColor, darkSquareColor, whitePieceColor, \r
   blackPieceColor, highlightSquareColor, premoveHighlightColor;\r
+COLORREF markerColor[8] = { 0x00FFFF, 0x0000FF, 0x00FF00, 0xFF0000, 0xFFFF00, 0xFF00FF, 0xFFFFFF, 0x000000 };\r
 HPALETTE hPal;\r
 ColorClass currentColorClass;\r
 \r
@@ -197,7 +198,7 @@ static HBITMAP pieceBitmap[3][(int) BlackPawn]; /* [HGM] nr of bitmaps referred
 static HBRUSH lightSquareBrush, darkSquareBrush,\r
   blackSquareBrush, /* [HGM] for band between board and holdings */\r
   explodeBrush,     /* [HGM] atomic */\r
-  markerBrush,      /* [HGM] markers */\r
+  markerBrush[8],   /* [HGM] markers */\r
   whitePieceBrush, blackPieceBrush, iconBkgndBrush /*, outlineBrush*/;\r
 static POINT gridEndpoints[(BOARD_RANKS + BOARD_FILES + 2) * 2];\r
 static DWORD gridVertexCounts[BOARD_RANKS + BOARD_FILES + 2];\r
@@ -222,6 +223,7 @@ static struct { int x; int y; int mode; } backTextureSquareInfo[BOARD_RANKS][BOA
 #if __GNUC__ && !defined(_winmajor)\r
 #define oldDialog 0 /* cygwin doesn't define _winmajor; mingw does */\r
 #else\r
+\r
 #if defined(_winmajor)\r
 #define oldDialog (_winmajor < 4)\r
 #else\r
@@ -296,7 +298,7 @@ int dialogItems[][42] = {
   OPT_ChooseTellColor, OPT_ChooseChallengeColor, OPT_ChooseRequestColor,\r
   OPT_ChooseSeekColor, OPT_ChooseNormalColor, OPT_ChooseBackgroundColor,\r
   OPT_DefaultColors, OPT_DontColorize, IDC_Boxes, GPB_Colors, GPB_Premove,\r
-  GPB_General, GPB_Alarm }, \r
+  GPB_General, GPB_Alarm, OPT_AutoCreate }, \r
 { DLG_BoardOptions, IDOK, IDCANCEL, OPT_SizeTiny, OPT_SizeTeeny, OPT_SizeDinky,\r
   OPT_SizePetite, OPT_SizeSlim, OPT_SizeSmall, OPT_SizeMediocre, OPT_SizeMiddling,\r
   OPT_SizeAverage, OPT_SizeModerate, OPT_SizeMedium, OPT_SizeBulky, OPT_SizeLarge,\r
@@ -1063,6 +1065,7 @@ InitInstance(HINSTANCE hInstance, int nCmdShow, LPSTR lpCmdLine)
 \r
   if (SearchPath(NULL, "WinBoard.exe", NULL, MSG_SIZ, installDir, &filepart)) {\r
     *filepart = NULLCHAR;\r
+    SetCurrentDirectory(installDir);\r
   } else {\r
     GetCurrentDirectory(MSG_SIZ, installDir);\r
   }\r
@@ -1116,6 +1119,7 @@ InitInstance(HINSTANCE hInstance, int nCmdShow, LPSTR lpCmdLine)
   InitDrawingColors();\r
   screenHeight = GetSystemMetrics(SM_CYSCREEN);\r
   screenWidth = GetSystemMetrics(SM_CXSCREEN);\r
+  InitPosition(0); // to set nr of ranks and files, which might be non-default through command-line args\r
   for (ibs = (int) NUM_SIZES - 1; ibs >= 0; ibs--) {\r
     /* Compute window size for each board size, and use the largest\r
        size that fits on this screen as the default. */\r
@@ -1279,6 +1283,7 @@ ParseFontName(char *name, MyFontParams *mfp)
     p = q + 1;\r
   } else {\r
     q = mfp->faceName;\r
+\r
     while (*p && !isdigit(*p)) {\r
       *q++ = *p++;\r
       if (q - mfp->faceName >= sizeof(mfp->faceName))\r
@@ -2160,6 +2165,7 @@ InsertInPalette(COLORREF color)
 VOID\r
 InitDrawingColors()\r
 {\r
+  int i;\r
   if (pLogPal == NULL) {\r
     /* Allocate enough memory for a logical palette with\r
      * PALETTESIZE entries and set the size and version fields\r
@@ -2191,8 +2197,9 @@ InitDrawingColors()
   blackPieceBrush = CreateSolidBrush(blackPieceColor);\r
   iconBkgndBrush = CreateSolidBrush(GetSysColor(COLOR_BACKGROUND));\r
   explodeBrush = CreateSolidBrush(highlightSquareColor); // [HGM] atomic\r
-  markerBrush = CreateSolidBrush(premoveHighlightColor); // [HGM] markers\r
-  /* [AS] Force rendering of the font-based pieces */\r
+    for(i=0; i<8;i++) markerBrush[i] = CreateSolidBrush(markerColor[i]); // [HGM] markers\r
+\r
+   /* [AS] Force rendering of the font-based pieces */\r
   if( fontBitmapSquareSize > 0 ) {\r
     fontBitmapSquareSize = 0;\r
   }\r
@@ -2257,6 +2264,7 @@ InitDrawingSizes(BoardSize boardSize, int flags)
 \r
   /* [HGM] call with -2 uses old size (for if nr of files, ranks changes) */\r
   if(boardSize == (BoardSize)(-2) ) boardSize = oldBoardSize;\r
+  if(boardSize == -1) return;     // no size defined yet; abort (to allow early call of InitPosition)\r
   oldBoardSize = boardSize;\r
 \r
   if(boardSize != SizeMiddling && boardSize != SizePetite && boardSize != SizeBulky && !appData.useFont)\r
@@ -2271,7 +2279,7 @@ InitDrawingSizes(BoardSize boardSize, int flags)
                                    boardSize = SizeMiddling;\r
     }\r
   }\r
-  if(!appData.useFont && boardSize == SizePetite && (v == VariantShogi || v == VariantKnightmate)) boardSize = SizeMiddling; // no Unicorn in Petite\r
+  if(!appData.useFont && boardSize == SizePetite && (v == VariantKnightmate)) boardSize = SizeMiddling; // no Unicorn in Petite\r
 \r
   oldRect.left = wpMain.x; //[HGM] placement: remember previous window params\r
   oldRect.top = wpMain.y;\r
@@ -3242,6 +3250,7 @@ BOOL HasHighlightInfo()
     }\r
 \r
     return result;\r
+\r
 }\r
 \r
 BOOL IsDrawArrowEnabled()\r
@@ -3351,7 +3360,7 @@ DrawBackgroundOnDC(HDC hdc)
   HDC tmphdc;\r
   HBITMAP hbm;\r
   static char oldBorder[MSG_SIZ];\r
-  int w = 600, h = 600;\r
+  int w = 600, h = 600, mode;\r
 \r
   if(strcmp(appData.border, oldBorder)) { // load new one when old one no longer valid\r
     strncpy(oldBorder, appData.border, MSG_SIZ-1);\r
@@ -3367,8 +3376,10 @@ DrawBackgroundOnDC(HDC hdc)
             w = bi.bmWidth;\r
             h = bi.bmHeight;\r
   }\r
+  mode = SetStretchBltMode(hdc, COLORONCOLOR);\r
   StretchBlt(hdc, boardRect.left, boardRect.top, boardRect.right - boardRect.left, \r
                   boardRect.bottom - boardRect.top, tmphdc, 0, 0, w, h, SRCCOPY);\r
+  SetStretchBltMode(hdc, mode);\r
   SelectObject(tmphdc, hbm);\r
   DeleteDC(tmphdc);\r
 }\r
@@ -3431,6 +3442,7 @@ DrawBoardOnDC(HDC hdc, Board board, HDC tmphdc)
             DisplayHoldingsCount(hdc, x, y, flipView, (int) board[row][column]);\r
       else if( column == BOARD_RGHT) /* right align */\r
             DisplayHoldingsCount(hdc, x, y, !flipView, (int) board[row][column]);\r
+      else if( piece == DarkSquare) DisplayHoldingsCount(hdc, x, y, 0, 0);\r
       else\r
       if (appData.monoMode) {\r
         if (piece == EmptySquare) {\r
@@ -3613,7 +3625,7 @@ void DrawSeekDot(int x, int y, int color)
 {\r
        int square = color & 0x80;\r
        HBRUSH oldBrush = SelectObject(hdcSeek, \r
-                       color == 0 ? markerBrush : color == 1 ? darkSquareBrush : explodeBrush);\r
+                       color == 0 ? markerBrush[1] : color == 1 ? darkSquareBrush : explodeBrush);\r
        color &= 0x7F;\r
        if(square)\r
            Rectangle(hdcSeek, boardRect.left+x - squareSize/9, boardRect.top+y - squareSize/9,\r
@@ -3906,8 +3918,7 @@ HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board)
   for (row = 0; row < BOARD_HEIGHT; row++) {\r
     for (column = 0; column < BOARD_WIDTH; column++) {\r
        if (marker[row][column]) { // marker changes only occur with full repaint!\r
-           HBRUSH oldBrush = SelectObject(hdcmem, \r
-                       marker[row][column] == 2 ? markerBrush : explodeBrush);\r
+           HBRUSH oldBrush = SelectObject(hdcmem, markerBrush[marker[row][column]-1]);\r
            SquareToPos(row, column, &x, &y);\r
            Ellipse(hdcmem, x + squareSize/4, y + squareSize/4,\r
                          x + 3*squareSize/4, y + 3*squareSize/4);\r
@@ -4254,6 +4265,7 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
   }\r
 \r
   shiftKey = GetKeyState(VK_SHIFT) < 0; // [HGM] remember last shift status\r
+  controlKey = GetKeyState(VK_CONTROL) < 0; // [HGM] remember last shift status\r
 \r
   switch (message) {\r
   case WM_LBUTTONDOWN:\r
@@ -4292,7 +4304,7 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
        dragInfo.pos = pt;\r
       }\r
       if (appData.highlightDragging) {\r
-       SetHighlights(fromX, fromY, x, y);\r
+       HoverEvent(highlightInfo.sq[1].x, highlightInfo.sq[1].y, x, y);\r
         if( IsDrawArrowEnabled() && (x < 0 || x >= BOARD_WIDTH || y < 0 || y >= BOARD_HEIGHT) ) {\r
             full_repaint = TRUE;\r
         }\r
@@ -4676,7 +4688,6 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
   FILE *f;\r
   UINT number;\r
   char fileTitle[MSG_SIZ];\r
-  char buf[MSG_SIZ];\r
   static SnapData sd;\r
   static int peek=0;\r
 \r
@@ -4751,6 +4762,7 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
       nnew = RealizePalette(hdc);\r
       if (nnew > 0) {\r
        paletteChanged = TRUE;\r
+\r
         InvalidateRect(hwnd, &boardRect, FALSE);\r
       }\r
       ReleaseDC(hwnd, hdc);\r
@@ -4867,6 +4879,10 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
       }\r
       break;\r
 \r
+    case IDM_CreateBook:\r
+      CreateBookEvent();\r
+      break;\r
+\r
     case IDM_CopyGame:\r
       CopyGameToClipboard();\r
       break;\r
@@ -9764,7 +9780,7 @@ CmailSigHandlerCallBack(InputSourceRef isr, VOIDSTAR closure,
 /* see wedittags.c for Edit Tags functions */\r
 \r
 \r
-VOID\r
+int\r
 ICSInitScript()\r
 {\r
   FILE *f;\r
@@ -9776,8 +9792,10 @@ ICSInitScript()
     if (f != NULL) {\r
       ProcessICSInitScript(f);\r
       fclose(f);\r
+      return TRUE;\r
     }\r
   }\r
+  return FALSE;\r
 }\r
 \r
 \r
@@ -10023,6 +10041,6 @@ ActivateTheme (int new)
    InitTextures();\r
    if(new) InitDrawingColors();\r
    fontBitmapSquareSize = 0; // request creation of new font pieces\r
-   InitDrawingSizes(-2, 0);\r
+   InitDrawingSizes(boardSize, 0);\r
    InvalidateRect(hwndMain, NULL, TRUE);\r
 }\r