Skip to content

Commit

Permalink
Let -sweepPromotions also work for click-click moves
Browse files Browse the repository at this point in the history
A click-click promotion no longer causes auto-queening, but the down-click
on the to-square causes a Queen to stick to the mouse pointer, and then
allows the user to change it through dragging backwards before releasing it
with an up-click.
  In WinBoard this required a slight change in DragPieceBegin, because
the dragged piece there only was made visible when the mouse pointer
actually started moving (and dragInfo.pos was set), presumably under the
assumption that before mouse move the piece was already on the clicked
square. Which in the case of a to-square was of course not true. (Because
a piece jumps to the mouse pointer when the click is not centered on a
square, this gives less jittery static clicks.) So DragPieceBegin has
been given an extra argument now, to indicate whether it should attach
the piece to the mouse pointer immediately.
  To make the click-click sweepPromotions work in Shogi (for which the
drag-drop sweepPromotions could never work, because it is not clear the
piece has a posibility to promote when you pick it up), translation of
the sweep-selected piece to a Shogi promoChar had to e added.
  • Loading branch information
HGMuller committed Jul 4, 2011
1 parent fd1000e commit fd1213c
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 15 deletions.
31 changes: 21 additions & 10 deletions backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -6080,7 +6080,7 @@ DefaultPromoChoice(int white)
static int autoQueen; // [HGM] oneclick

int
HasPromotionChoice(int fromX, int fromY, int toX, int toY, char *promoChoice)
HasPromotionChoice(int fromX, int fromY, int toX, int toY, char *promoChoice, int sweepSelect)
{
/* [HGM] rewritten IsPromotion to only flag promotions that offer a choice */
/* [HGM] add Shogi promotions */
Expand Down Expand Up @@ -6162,9 +6162,9 @@ HasPromotionChoice(int fromX, int fromY, int toX, int toY, char *promoChoice)
}
// give caller the default choice even if we will not make it
*promoChoice = ToLower(PieceToChar(defaultPromoChoice));
if(gameInfo.variant == VariantShogi) *promoChoice = '+';
if(appData.sweepSelect && gameInfo.variant != VariantGreat
&& gameInfo.variant != VariantShogi
if(gameInfo.variant == VariantShogi) *promoChoice = (defaultPromoChoice == piece ? '=' : '+');
if( sweepSelect && gameInfo.variant != VariantGreat
&& gameInfo.variant != VariantGrand
&& gameInfo.variant != VariantSuper) return FALSE;
if(autoQueen) return FALSE; // predetermined

Expand Down Expand Up @@ -6819,7 +6819,7 @@ void LeftClick(ClickType clickType, int xPix, int yPix)
defaultPromoChoice = promoSweep;
promoSweep = EmptySquare; // terminate sweep
promoDefaultAltered = TRUE;
if(!selectFlag) x = fromX, y = fromY; // and fake up-click on same square if we were still selecting
if(!selectFlag && (x != toX || y != toY)) x = fromX, y = fromY; // and fake up-click on same square if we were still selecting
}

if(promotionChoice) { // we are waiting for a click to indicate promotion piece
Expand Down Expand Up @@ -6872,15 +6872,15 @@ void LeftClick(ClickType clickType, int xPix, int yPix)
}
return;
}
fromX = x; fromY = y;
fromX = x; fromY = y; toX = toY = -1;
if(!appData.oneClick || !OnlyMove(&x, &y, FALSE) ||
// even if only move, we treat as normal when this would trigger a promotion popup, to allow sweep selection
appData.sweepSelect && CanPromote(boards[currentMove][fromY][fromX], fromY) && originalY != y) {
/* First square */
if (OKToStartUserMove(fromX, fromY)) {
second = 0;
MarkTargetSquares(0);
DragPieceBegin(xPix, yPix); dragging = 1;
DragPieceBegin(xPix, yPix, FALSE); dragging = 1;
if(appData.sweepSelect && CanPromote(piece = boards[currentMove][fromY][fromX], fromY)) {
promoSweep = defaultPromoChoice;
selectFlag = 0; lastX = xPix; lastY = yPix;
Expand Down Expand Up @@ -6935,7 +6935,7 @@ void LeftClick(ClickType clickType, int xPix, int yPix)
fromX = x;
fromY = y; dragging = 1;
MarkTargetSquares(0);
DragPieceBegin(xPix, yPix);
DragPieceBegin(xPix, yPix, FALSE);
if(appData.sweepSelect && CanPromote(piece = boards[currentMove][y][x], y)) {
promoSweep = defaultPromoChoice;
selectFlag = 0; lastX = xPix; lastY = yPix;
Expand Down Expand Up @@ -6990,10 +6990,21 @@ void LeftClick(ClickType clickType, int xPix, int yPix)
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
fromX = x; fromY = y; DragPieceBegin(xPix, yPix, FALSE); 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;
}
if(appData.sweepSelect && HasPromotionChoice(fromX, fromY, toX, toY, &promoChoice, FALSE)) {
ChessSquare piece = boards[currentMove][fromY][fromX];
DragPieceBegin(xPix, yPix, TRUE); dragging = 1;
promoSweep = defaultPromoChoice;
if(PieceToChar(PROMOTED piece) == '+') promoSweep = PROMOTED piece;
selectFlag = 0; lastX = xPix; lastY = yPix;
Sweep(0); // Pawn that is going to promote: preview promotion piece
DisplayMessage("", _("Pull pawn backwards to under-promote"));
DrawPosition(FALSE, boards[currentMove]);
return;
}
/* Finish clickclick move */
if (appData.animate || appData.highlightLastMove) {
SetHighlights(fromX, fromY, toX, toY);
Expand Down Expand Up @@ -7044,7 +7055,7 @@ void LeftClick(ClickType clickType, int xPix, int yPix)

if(gatingPiece != EmptySquare) promoChoice = ToLower(PieceToChar(gatingPiece));

if (HasPromotionChoice(fromX, fromY, toX, toY, &promoChoice)) {
if (HasPromotionChoice(fromX, fromY, toX, toY, &promoChoice, appData.sweepSelect)) {
SetHighlights(fromX, fromY, toX, toY);
if(gameInfo.variant == VariantSuper || gameInfo.variant == VariantGreat || gameInfo.variant == VariantGrand) {
// [HGM] super: promotion to captured piece selected from holdings
Expand Down
2 changes: 1 addition & 1 deletion backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ void SetBlackToPlayEvent P((void));
void UploadGameEvent P((void));
void InitBackEnd1 P((void));
void InitBackEnd2 P((void));
int HasPromotionChoice P((int fromX, int fromY, int toX, int toY, char *choice));
int HasPromotionChoice P((int fromX, int fromY, int toX, int toY, char *choice, int sweep));
int InPalace P((int row, int column));
int PieceForSquare P((int x, int y));
int OKToStartUserMove P((int x, int y));
Expand Down
2 changes: 1 addition & 1 deletion frontend.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void CancelDelayedEvent P((void));
extern int fromX, fromY, toX, toY;
typedef enum { Press, Release } ClickType;
void PromotionPopUp P((void));
void DragPieceBegin P((int x, int y));
void DragPieceBegin P((int x, int y, Boolean instantly));
void DragPieceEnd P((int x, int y));
void LeftClick P((ClickType c, int x, int y));
int RightClick P((ClickType c, int x, int y, int *col, int *row));
Expand Down
3 changes: 2 additions & 1 deletion winboard/winboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -4067,10 +4067,11 @@ SetupDropMenu(HMENU hmenu)
}
}

void DragPieceBegin(int x, int y)
void DragPieceBegin(int x, int y, Boolean instantly)
{
dragInfo.lastpos.x = boardRect.left + x;
dragInfo.lastpos.y = boardRect.top + y;
if(instantly) dragInfo.pos = dragInfo.lastpos;
dragInfo.from.x = fromX;
dragInfo.from.y = fromY;
dragInfo.piece = boards[currentMove][fromY][fromX];
Expand Down
4 changes: 2 additions & 2 deletions xboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -8644,8 +8644,8 @@ AnimateMove(board, fromX, fromY, toX, toY)
}

void
DragPieceBegin(x, y)
int x; int y;
DragPieceBegin(x, y, instantly)
int x; int y; Boolean instantly;
{
int boardX, boardY, color;
XPoint corner;
Expand Down

0 comments on commit fd1213c

Please sign in to comment.