Allow editing of holdings in EditPosition mode
[xboard.git] / winboard / winboard.c
index 7c8142c..aa13836 100644 (file)
@@ -153,6 +153,7 @@ char *programName;
 char *settingsFileName;\r
 Boolean saveSettingsOnExit;\r
 char installDir[MSG_SIZ];\r
+int errorExitStatus;\r
 \r
 BoardSize boardSize;\r
 Boolean chessProgram;\r
@@ -190,6 +191,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
   whitePieceBrush, blackPieceBrush, iconBkgndBrush /*, outlineBrush*/;\r
 static POINT gridEndpoints[(BOARD_RANKS + BOARD_FILES + 2) * 2];\r
 static DWORD gridVertexCounts[BOARD_RANKS + BOARD_FILES + 2];\r
@@ -1852,6 +1854,7 @@ 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
   if( fontBitmapSquareSize > 0 ) {\r
     fontBitmapSquareSize = 0;\r
@@ -3311,6 +3314,18 @@ HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board)
     DrawHighlightsOnDC(hdcmem);\r
     DrawBoardOnDC(hdcmem, board, tmphdc);\r
   }\r
+  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
+           SquareToPos(row, column, &x, &y);\r
+           Ellipse(hdcmem, x + squareSize/4, y + squareSize/4,\r
+                         x + 3*squareSize/4, y + 3*squareSize/4);\r
+           SelectObject(hdcmem, oldBrush);\r
+       }\r
+    }\r
+  }\r
   if(logoHeight) {\r
        HBITMAP whiteLogo = (HBITMAP) first.programLogo, blackLogo = (HBITMAP) second.programLogo;\r
        if(appData.autoLogo) {\r
@@ -3704,6 +3719,7 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
     break;\r
 \r
   case WM_MOUSEMOVE:\r
+    MovePV(pt.x - boardRect.left, pt.y - boardRect.top, boardRect.bottom - boardRect.top);
     if ((appData.animateDragging || appData.highlightDragging)\r
        && (wParam & MK_LBUTTON)\r
        && dragInfo.from.x >= 0) \r
@@ -3741,6 +3757,12 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
     }\r
     break;\r
 \r
+  case WM_MBUTTONUP:
+  case WM_RBUTTONUP:
+    ReleaseCapture();
+    UnLoadPV();
+    break;
   case WM_MBUTTONDOWN:\r
   case WM_RBUTTONDOWN:\r
     ErrorPopDown();\r
@@ -3764,8 +3786,10 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
     DrawPosition(TRUE, NULL);\r
 \r
     switch (gameMode) {\r
-    case EditPosition:\r
     case IcsExamining:\r
+      if(x < BOARD_LEFT || x >= BOARD_RGHT) break;\r
+    case EditPosition:\r
+      if (x == BOARD_LEFT-1 || x == BOARD_RGHT) break;\r
       if (x < 0 || y < 0) break;\r
       fromX = x;\r
       fromY = y;\r
@@ -3785,15 +3809,29 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
             MenuPopup(hwnd, pt, LoadMenu(hInst, "ShogiPieceMenu"), -1);\r
       }\r
       break;\r
-    case IcsPlayingWhite:\r
-    case IcsPlayingBlack:\r
-    case EditGame:\r
-    case MachinePlaysWhite:\r
-    case MachinePlaysBlack:\r
-      if (appData.testLegality &&\r
-         gameInfo.variant != VariantBughouse &&\r
-         gameInfo.variant != VariantCrazyhouse) break;\r
-      if (x < 0 || y < 0) break;\r
+    case IcsObserving:
+      if(!appData.icsEngineAnalyze) break;
+    case IcsPlayingWhite:
+    case IcsPlayingBlack:
+      if(!appData.zippyPlay) goto noZip;
+    case MachinePlaysWhite:
+    case MachinePlaysBlack:
+    case TwoMachinesPlay:
+    case AnalyzeMode:
+    case AnalyzeFile:
+      if (!appData.dropMenu) {
+        SetCapture(hwndMain);
+        LoadPV(pt.x - boardRect.left, pt.y - boardRect.top);
+        break;
+      }
+      if(gameMode == TwoMachinesPlay || gameMode == AnalyzeMode ||
+         gameMode == AnalyzeFile || gameMode == IcsObserving) break;
+    case EditGame:
+    noZip:
+      if (x < 0 || y < 0) break;
+      if (!appData.dropMenu || appData.testLegality &&
+         gameInfo.variant != VariantBughouse &&
+         gameInfo.variant != VariantCrazyhouse) break;
       fromX = x;\r
       fromY = y;\r
       hmenu = LoadMenu(hInst, "DropPieceMenu");\r
@@ -6065,6 +6103,7 @@ ErrorPopDown()
   if (errorDialog == NULL) return;\r
   DestroyWindow(errorDialog);\r
   errorDialog = NULL;\r
+  if(errorExitStatus) ExitEvent(errorExitStatus);\r
 }\r
 \r
 LRESULT CALLBACK\r