From 9c7cb89d6ae88edc97bc99e51fb6779ddf6e33b8 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Sat, 13 Nov 2010 20:02:31 +0100 Subject: [PATCH] Implement entering gating moves with mouse A move with a back-rank piece that starts when a piece in the holdings is selected will be interpreted as a gating move in variant seirawan. The front-end uses a 'gatingPiece' selected this way todisplay it on the from square during animate dragging. --- backend.c | 13 ++++++++++++- backend.h | 1 + winboard/winboard.c | 2 +- xboard.c | 11 +++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/backend.c b/backend.c index 05f7dfc..958c92e 100644 --- a/backend.c +++ b/backend.c @@ -6340,6 +6340,8 @@ Explode(Board board, int fromX, int fromY, int toX, int toY) return FALSE; } +ChessSquare gatingPiece = EmptySquare; // exported to front-end, for dragging + void LeftClick(ClickType clickType, int xPix, int yPix) { int x, y; @@ -6396,6 +6398,7 @@ void LeftClick(ClickType clickType, int xPix, int yPix) autoQueen = appData.alwaysPromoteToQueen; if (fromX == -1) { + gatingPiece = EmptySquare; if(!appData.oneClick || !OnlyMove(&x, &y, FALSE)) { if (clickType == Press) { /* First square */ @@ -6429,7 +6432,7 @@ void LeftClick(ClickType clickType, int xPix, int yPix) /* Check if clicking again on the same color piece */ fromP = boards[currentMove][fromY][fromX]; toP = boards[currentMove][y][x]; - frc = gameInfo.variant == VariantFischeRandom || gameInfo.variant == VariantCapaRandom; + frc = gameInfo.variant == VariantFischeRandom || gameInfo.variant == VariantCapaRandom || gameInfo.variant == VariantSChess; if ((WhitePawn <= fromP && fromP <= WhiteKing && WhitePawn <= toP && toP <= WhiteKing && !(fromP == WhiteKing && toP == WhiteRook && frc) && @@ -6447,6 +6450,11 @@ void LeftClick(ClickType clickType, int xPix, int yPix) ClearHighlights(); } if (OKToStartUserMove(x, y)) { + if(gameInfo.variant == VariantSChess && // S-Chess: back-rank piece selected after holdings means gating + (fromX == BOARD_LEFT-2 || fromX == BOARD_RGHT+1) && + y == (toP < BlackPawn ? 0 : BOARD_HEIGHT-1)) + gatingPiece = boards[currentMove][fromY][fromX]; + else gatingPiece = EmptySquare; fromX = x; fromY = y; dragging = 1; MarkTargetSquares(0); @@ -6470,6 +6478,7 @@ void LeftClick(ClickType clickType, int xPix, int yPix) /* Second up/down in same square; just abort move */ second = 0; fromX = fromY = -1; + gatingPiece = EmptySquare; ClearHighlights(); gotPremove = 0; ClearPremoveHighlights(); @@ -6534,6 +6543,8 @@ void LeftClick(ClickType clickType, int xPix, int yPix) // off-board moves should not be highlighted if(x < 0 || y < 0) ClearHighlights(); + if(gatingPiece != EmptySquare) promoChoice = ToLower(PieceToChar(gatingPiece)); + if (HasPromotionChoice(fromX, fromY, toX, toY, &promoChoice)) { SetHighlights(fromX, fromY, toX, toY); if(gameInfo.variant == VariantSuper || gameInfo.variant == VariantGreat) { diff --git a/backend.h b/backend.h index 6da6323..7e5accd 100644 --- a/backend.h +++ b/backend.h @@ -274,6 +274,7 @@ typedef struct _ListGame { GameInfo gameInfo; /* Note that some entries may be NULL. */ } ListGame; +extern ChessSquare gatingPiece; extern List gameList; void ClearGameInfo P((GameInfo *)); int GameListBuild P((FILE *)); diff --git a/winboard/winboard.c b/winboard/winboard.c index e98e516..fcadd27 100644 --- a/winboard/winboard.c +++ b/winboard/winboard.c @@ -3505,7 +3505,7 @@ HDCDrawPosition(HDC hdc, BOOLEAN repaint, Board board) if(--board[dragInfo.from.y][dragInfo.from.x-1] == 0 ) board[dragInfo.from.y][dragInfo.from.x] = EmptySquare; } else - board[dragInfo.from.y][dragInfo.from.x] = EmptySquare; + board[dragInfo.from.y][dragInfo.from.x] = gatingPiece; } /* Figure out which squares need updating by comparing the diff --git a/xboard.c b/xboard.c index d1d00a3..3a39fe0 100644 --- a/xboard.c +++ b/xboard.c @@ -9048,6 +9048,17 @@ DragPieceBegin(x, y) XCopyArea(xDisplay, xBoardWindow, player.saveBuf, player.blitGC, corner.x, corner.y, squareSize, squareSize, 0, 0); // [HGM] zh: unstack in stead of grab + if(gatingPiece != EmptySquare) { + /* Kludge alert: When gating we want the introduced + piece to appear on the from square. To generate an + image of it, we draw it on the board, copy the image, + and draw the original piece again. */ + ChessSquare piece = boards[currentMove][boardY][boardX]; + DrawSquare(boardY, boardX, gatingPiece, 0); + XCopyArea(xDisplay, xBoardWindow, player.saveBuf, player.blitGC, + corner.x, corner.y, squareSize, squareSize, 0, 0); + DrawSquare(boardY, boardX, piece, 0); + } damage[0][boardY][boardX] = True; } else { player.dragActive = False; -- 1.7.0.4