From: H.G. Muller <h.g.muller@hccnet.nl>
Date: Mon, 10 May 2010 08:32:19 +0000 (+0200)
Subject: Fix game end during dragging
X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=2c35298bc21162cfb3c1d7f012e5d632bc5e2725;p=xboard.git

Fix game end during dragging

The stale-first-click fix interfered with proper handling of a piece
being dragged when a game suddenly ended (because of opponent resign,
or caling the flag), because up-clicks when the from-square was reset
were completely ignored. Now such an 'unmatched' upclick calls
DragPieceEnd() and redraws the board.
---

diff --git a/backend.c b/backend.c
index 36a7ea2..84f64e5 100644
--- a/backend.c
+++ b/backend.c
@@ -6266,7 +6266,7 @@ void LeftClick(ClickType clickType, int xPix, int yPix)
 {
     int x, y;
     Boolean saveAnimate;
-    static int second = 0, promotionChoice = 0;
+    static int second = 0, promotionChoice = 0, dragging = 0;
     char promoChoice = NULLCHAR;
 
     if(appData.seekGraph && appData.icsActive && loggedOn &&
@@ -6326,11 +6326,14 @@ void LeftClick(ClickType clickType, int xPix, int yPix)
 		fromY = y;
 		second = 0;
 		MarkTargetSquares(0);
-		DragPieceBegin(xPix, yPix);
+		DragPieceBegin(xPix, yPix); dragging = 1;
 		if (appData.highlightDragging) {
 		    SetHighlights(x, y, -1, -1);
 		}
 	    }
+	} else if(dragging); { // [HGM] from-square must have been reset due to game end since last press
+	    DragPieceEnd(xPix, yPix); dragging = 0;
+	    DrawPosition(FALSE, NULL);
 	}
 	return;
       }
@@ -6367,7 +6370,7 @@ void LeftClick(ClickType clickType, int xPix, int yPix)
 	    }
 	    if (OKToStartUserMove(x, y)) {
 		fromX = x;
-		fromY = y;
+		fromY = y; dragging = 1;
 		MarkTargetSquares(0);
 		DragPieceBegin(xPix, yPix);
 	    }
@@ -6379,7 +6382,7 @@ void LeftClick(ClickType clickType, int xPix, int yPix)
     }
 
     if (clickType == Release && x == fromX && y == fromY) {
-	DragPieceEnd(xPix, yPix);
+	DragPieceEnd(xPix, yPix); dragging = 0;
 	if (appData.animateDragging) {
 	    /* Undo animation damage if any */
 	    DrawPosition(FALSE, NULL);
@@ -6417,7 +6420,7 @@ void LeftClick(ClickType clickType, int xPix, int yPix)
 	} else {
 	    ClearHighlights();
 	}
-	DragPieceEnd(xPix, yPix);
+	DragPieceEnd(xPix, yPix); dragging = 0;
 	/* Don't animate move and drag both */
 	appData.animate = FALSE;
     }