Implement entering gating moves with mouse
[xboard.git] / winboard / winboard.c
index 73a36b6..fcadd27 100644 (file)
@@ -105,7 +105,6 @@ void DisplayHoldingsCount(HDC hdc, int x, int y, int align, int copyNumber);
 VOID NewVariantPopup(HWND hwnd);\r
 int FinishMove P((ChessMove moveType, int fromX, int fromY, int toX, int toY,\r
                   /*char*/int promoChar));\r
-void AnimateAtomicCapture(int fromX, int fromY, int toX, int toY, int nFrames);\r
 void DisplayMove P((int moveNumber));\r
 Boolean ParseFEN P((Board board, int *blackPlaysFirst, char *fen));\r
 void ChatPopUp P((char *s));\r
@@ -187,6 +186,7 @@ COLORREF lightSquareColor, darkSquareColor, whitePieceColor,
 HPALETTE hPal;\r
 ColorClass currentColorClass;\r
 \r
+static HWND savedHwnd;\r
 HWND hCommPort = NULL;    /* currently open comm port */\r
 static HWND hwndPause;    /* pause button */\r
 static HBITMAP pieceBitmap[3][(int) BlackPawn]; /* [HGM] nr of bitmaps referred to bP in stead of wK */\r
@@ -306,7 +306,7 @@ int dialogItems[][40] = {
   OPT_VariantBughouse, OPT_VariantTwilight, OPT_VariantShogi, OPT_VariantSuper,\r
   OPT_VariantKnightmate, OPT_VariantBerolina, OPT_VariantCylinder, OPT_VariantFairy,\r
   OPT_VariantMakruk, OPT_VariantGothic, OPT_VariantCapablanca, OPT_VariantJanus,\r
-  OPT_VariantCRC, OPT_VariantFalcon, OPT_VariantCourier, OPT_VariantGreat,\r
+  OPT_VariantCRC, OPT_VariantFalcon, OPT_VariantCourier, OPT_VariantGreat, OPT_VariantSChess,\r
   OPT_VariantShatranj, OPT_VariantXiangqi, GPB_Variant, GPB_Board, IDC_Height,\r
   IDC_Width, IDC_Hand, IDC_Pieces, IDC_Def }, \r
 { DLG_Fonts, IDOK, IDCANCEL, OPT_ChooseClockFont, OPT_ChooseMessageFont,\r
@@ -3505,7 +3505,7 @@ HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board)
             if(--board[dragInfo.from.y][dragInfo.from.x-1] == 0 )\r
         board[dragInfo.from.y][dragInfo.from.x] = EmptySquare;\r
     } else \r
-        board[dragInfo.from.y][dragInfo.from.x] = EmptySquare;\r
+        board[dragInfo.from.y][dragInfo.from.x] = gatingPiece;\r
   }\r
 \r
   /* Figure out which squares need updating by comparing the \r
@@ -3667,6 +3667,7 @@ HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board)
   if(explodeInfo.radius) { // [HGM] atomic\r
        HBRUSH oldBrush;\r
        int x, y, r=(explodeInfo.radius * squareSize)/100;\r
+        ChessSquare piece = board[explodeInfo.fromY][explodeInfo.fromX];\r
         board[explodeInfo.fromY][explodeInfo.fromX] = EmptySquare; // suppress display of capturer\r
        SquareToPos(explodeInfo.toY, explodeInfo.toX, &x, &y);\r
        x += squareSize/2;\r
@@ -3679,6 +3680,7 @@ HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board)
        DrawHighlightsOnDC(hdcmem, &highlightInfo, HIGHLIGHT_PEN);\r
        DrawHighlightsOnDC(hdcmem, &premoveHighlightInfo, PREMOVE_PEN);\r
        DrawBoardOnDC(hdcmem, board, tmphdc);\r
+        board[explodeInfo.fromY][explodeInfo.fromX] = piece;\r
        oldBrush = SelectObject(hdcmem, explodeBrush);\r
        Ellipse(hdcmem, x-r, y-r, x+r, y+r);\r
        SelectObject(hdcmem, oldBrush);\r
@@ -5051,6 +5053,8 @@ WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
       break;\r
 \r
     case IDM_Engine2Options:\r
+      savedHwnd = hwnd;\r
+      if(WaitForSecond(SettingsMenuIfReady)) break;\r
       EngineOptionsPopup(hwnd, &second);\r
       break;\r
 \r
@@ -5709,12 +5713,12 @@ OpenFileDialog(HWND hwnd, char *write, char *defName, char *defExt, // [HGM] dia
 \r
   if (fileName == NULL) fileName = buf1;\r
   if (defName == NULL) {\r
-    safeStrCpy(fileName, "*.", sizeof(fileName)/sizeof(fileName[0]) );\r
+    safeStrCpy(fileName, "*.", 3 );\r
     strcat(fileName, defExt);\r
   } else {\r
-    safeStrCpy(fileName, defName, sizeof(fileName)/sizeof(fileName[0]) );\r
+    safeStrCpy(fileName, defName, MSG_SIZ );\r
   }\r
-    if (fileTitle) safeStrCpy(fileTitle, "", sizeof(fileTitle)/sizeof(fileTitle[0]) );\r
+    if (fileTitle) safeStrCpy(fileTitle, "", MSG_SIZ );\r
   if (number) *number = 0;\r
 \r
   openFileName.lStructSize       = sizeof(OPENFILENAME);\r
@@ -6798,6 +6802,7 @@ CommandX(HWND hwnd, char *command, BOOLEAN getname, BOOLEAN immediate)
     SendMessage(hwnd, EM_GETSELTEXT, 0, (LPARAM) name);\r
   }\r
   if (immediate) {\r
+    if(strstr(command, "%s")) snprintf(buf, MSG_SIZ, command, name); else\r
     snprintf(buf, MSG_SIZ, "%s %s", command, name);\r
     SetWindowText(hInput, buf);\r
     SendMessage(hInput, WM_CHAR, '\r', 0);\r
@@ -9616,26 +9621,26 @@ static void Tween( POINT * start, POINT * mid, POINT * finish, int factor,
      POINT frames[], int * nFrames);\r
 \r
 \r
+#define kFactor 4\r
+\r
 void\r
-AnimateAtomicCapture(int fromX, int fromY, int toX, int toY, int nFrames)\r
+AnimateAtomicCapture(Board board, int fromX, int fromY, int toX, int toY)\r
 {      // [HGM] atomic: animate blast wave\r
        int i;\r
-if(appData.debugMode) fprintf(debugFP, "exploding (%d,%d)\n", toX, toY);\r
+\r
        explodeInfo.fromX = fromX;\r
        explodeInfo.fromY = fromY;\r
        explodeInfo.toX = toX;\r
        explodeInfo.toY = toY;\r
-       for(i=1; i<nFrames; i++) {\r
-           explodeInfo.radius = (i*180)/(nFrames-1);\r
-           DrawPosition(FALSE, NULL);\r
+       for(i=1; i<4*kFactor; i++) {\r
+           explodeInfo.radius = (i*180)/(4*kFactor-1);\r
+           DrawPosition(FALSE, board);\r
            Sleep(appData.animSpeed);\r
        }\r
        explodeInfo.radius = 0;\r
-       DrawPosition(TRUE, NULL);\r
+       DrawPosition(TRUE, board);\r
 }\r
 \r
-#define kFactor 4\r
-\r
 void\r
 AnimateMove(board, fromX, fromY, toX, toY)\r
      Board board;\r
@@ -9694,9 +9699,7 @@ AnimateMove(board, fromX, fromY, toX, toY)
   animInfo.pos = finish;\r
   DrawPosition(FALSE, NULL);\r
   animInfo.piece = EmptySquare;\r
-  if(gameInfo.variant == VariantAtomic && \r
-     (board[toY][toX] != EmptySquare || fromX != toX && (piece == WhitePawn || piece == BlackPawn) ) )\r
-       AnimateAtomicCapture(fromX, fromY, toX, toY, 2*nFrames);\r
+  Explode(board, fromX, fromY, toX, toY);\r
 }\r
 \r
 /*      Convert board position to corner of screen rect and color       */\r
@@ -9764,3 +9767,9 @@ HistorySet( char movelist[][2*MOVE_LEN], int first, int last, int current )
 \r
     EvalGraphSet( first, last, current, pvInfoList );\r
 }\r
+\r
+void\r
+SettingsPopUp(ChessProgramState *cps)\r
+{     // [HGM] wrapper needed because handles must not be passed through back-end\r
+      EngineOptionsPopup(savedHwnd, cps);\r
+}\r