fixed premove recapture problem;promotion popup appearing on obviously illegal moves...
[xboard.git] / winboard / winboard.c
index df76074..0fa4807 100644 (file)
@@ -494,7 +494,7 @@ void ThawUI()
   DrawMenuBar(hwndMain);\r
 }\r
 \r
-static int fromX = -1, fromY = -1, toX, toY; // [HGM] moved upstream, so JAWS can use them\r
+/*static*/ int fromX = -1, fromY = -1, toX, toY; // [HGM] moved upstream, so JAWS can use them\r
 \r
 /* JAWS preparation patch (WinBoard for the sight impaired). Define required insertions as empty */\r
 #ifdef JAWS\r
@@ -5120,17 +5120,14 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
        toY = y;\r
         /* [HGM] <popupFix> UserMoveEvent requires two calls now,\r
            to make sure move is legal before showing promotion popup */\r
-        moveType = UserMoveTest(fromX, fromY, toX, toY, NULLCHAR);\r
+        moveType = UserMoveTest(fromX, fromY, toX, toY, NULLCHAR, FALSE);\r
        if(moveType == AmbiguousMove) { /* [HGM] Edit-Position move executed */\r
                fromX = fromY = -1; \r
                ClearHighlights();\r
                DrawPosition(FALSE, boards[currentMove]);\r
                break; \r
        } else \r
-        if(moveType != ImpossibleMove) {\r
-         if(moveType == IllegalMove) {\r
-               ;\r
-         } else\r
+        if(moveType != ImpossibleMove && moveType != Comment) {\r
           /* [HGM] We use PromotionToKnight in Shogi to indicate frorced promotion */\r
           if (moveType == WhitePromotionKnight || moveType == BlackPromotionKnight ||\r
             ((moveType == WhitePromotionQueen || moveType == BlackPromotionQueen) &&\r
@@ -5155,9 +5152,11 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
                    DrawPosition(FALSE, boards[currentMove]);\r
                    boards[currentMove][fromY][fromX] = p; // take back, but display stays\r
                    boards[currentMove][toY][toX] = q;\r
+                   DisplayMessage("Select piece from holdings", "");\r
                  } else\r
                   PromotionPopup(hwnd);\r
-          } else {       /* not a promotion */\r
+                 goto noClear;\r
+          } else { // not a promotion. Move can be illegal if testLegality off, and should be made then.\r
              if (appData.animate || appData.highlightLastMove) {\r
                  SetHighlights(fromX, fromY, toX, toY);\r
              } else {\r
@@ -5170,14 +5169,16 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
              }\r
           }\r
           fromX = fromY = -1;\r
+       noClear:\r
          break;\r
         }\r
-        if (gotPremove) {\r
+        if (gotPremove && moveType != Comment) {\r
            SetPremoveHighlights(fromX, fromY, toX, toY);\r
-            DrawPosition(forceFullRepaint || FALSE, NULL);\r
+//            DrawPosition(forceFullRepaint || FALSE, NULL);\r
        } else ClearHighlights();\r
         fromX = fromY = -1;\r
         DrawPosition(forceFullRepaint || FALSE, NULL);\r
+       if(moveType != Comment) break;\r
     }\r
     /* First downclick, or restart on a square with same color piece */\r
     if (!frozen && OKToStartUserMove(x, y)) {\r
@@ -5225,7 +5226,7 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
       toY = y;\r
       saveAnimate = appData.animate; /* sorry, Hawk :) */\r
       appData.animate = appData.animate && !appData.animateDragging;\r
-      moveType = UserMoveTest(fromX, fromY, toX, toY, NULLCHAR);\r
+      moveType = UserMoveTest(fromX, fromY, toX, toY, NULLCHAR, TRUE);\r
       if(moveType == AmbiguousMove) { /* [HGM] Edit-Position move executed */\r
                fromX = fromY = -1; \r
                ClearHighlights();\r
@@ -5253,6 +5254,7 @@ MouseEvent(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
                    boards[currentMove][fromY][fromX] = p; // take back, but display stays\r
                    boards[currentMove][toY][toX] = q;\r
                    appData.animate = saveAnimate;\r
+                   DisplayMessage("Select piece from holdings", "");\r
                    break;\r
                  } else\r
                PromotionPopup(hwnd); /* [HGM] Popup now calls FinishMove */\r