From dff5c053266d7b78bbadc95d7bf1f84ca97bf0c6 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Thu, 14 Apr 2011 11:56:59 +0200 Subject: [PATCH] Alter treatment of moves with empty squares In Edit Position mode one can move empty squares, and use them to 'capture' pieces as a means to clear their square. But this often leads to unintended disappearence of pieces one wants to grab for dragging, if a previous click had inadvertantly left an empty square selected: the click on the piece is then seen as the to-click of a click-click move. This patch treats to-clicks of moves with an empty-square differently from other to-clicks: Rather than performing the move (in this case clearing of the to-square) on the down-click, it defers that to the up-click, and only does it if that up-click is in the same square. This allows the user to grab the piece on the down-click, and drag it to another square, if that is what he wanted to do, without being disturbed by sudden implosion of the piece he tried to grab. If the to-square is in the holdings, grabbing the piece is the only action, as moves of empty squares into the holdings are forbidden anyway. --- backend.c | 18 +++++++++++++++++- 1 files changed, 17 insertions(+), 1 deletions(-) diff --git a/backend.c b/backend.c index b1df197..1165932 100644 --- a/backend.c +++ b/backend.c @@ -6445,7 +6445,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, clearFlag = 0; char promoChoice = NULLCHAR; ChessSquare piece; @@ -6602,6 +6602,14 @@ void LeftClick(ClickType clickType, int xPix, int yPix) if (clickType == Release && x == fromX && y == fromY) { DragPieceEnd(xPix, yPix); dragging = 0; + if(clearFlag) { + // a deferred attempt to click-click move an empty square on top of a piece + boards[currentMove][y][x] = EmptySquare; + ClearHighlights(); + DrawPosition(FALSE, boards[currentMove]); + fromX = fromY = -1; clearFlag = 0; + return; + } if (appData.animateDragging) { /* Undo animation damage if any */ DrawPosition(FALSE, NULL); @@ -6621,12 +6629,20 @@ void LeftClick(ClickType clickType, int xPix, int yPix) return; } + clearFlag = 0; + /* we now have a different from- and (possibly off-board) to-square */ /* Completed move */ toX = x; toY = y; saveAnimate = appData.animate; if (clickType == Press) { + if(gameMode == EditPosition && boards[currentMove][fromY][fromX] == EmptySquare) { + // must be Edit Position mode with empty-square selected + fromX = x; fromY = y; DragPieceBegin(xPix, yPix); dragging = 1; // consider this a new attempt to drag + if(x >= BOARD_LEFT && x < BOARD_RGHT) clearFlag = 1; // and defer click-click move of empty-square to up-click + return; + } /* Finish clickclick move */ if (appData.animate || appData.highlightLastMove) { SetHighlights(fromX, fromY, toX, toY); -- 1.7.0.4