From: H.G. Muller Date: Fri, 13 Apr 2012 14:05:16 +0000 (+0200) Subject: Improve arrow drawing X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=fbcf1f3b86b144dd4940b326c32d4b105c0f74b3;p=xboard.git Improve arrow drawing The arrow is now erased together with the border highlights, by marking the damage it did, and then doing a selected redraw of the board to let the damaged square be re-drawn. Highlights of a previous move are now cleared on the down-click that selects a new piece, so there never is an arrow to infavorably interact with animation of dragging. --- diff --git a/backend.c b/backend.c index 2bde9f6..9ac6a58 100644 --- a/backend.c +++ b/backend.c @@ -7073,6 +7073,8 @@ LeftClick (ClickType clickType, int xPix, int yPix) } if (appData.highlightDragging) { SetHighlights(fromX, fromY, -1, -1); + } else { + ClearHighlights(); } } else fromX = fromY = -1; return; @@ -7181,12 +7183,6 @@ LeftClick (ClickType clickType, int xPix, int yPix) 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); - } else { - ClearHighlights(); - } if(HasPromotionChoice(fromX, fromY, toX, toY, &promoChoice, FALSE)) { if(appData.sweepSelect) { ChessSquare piece = boards[currentMove][fromY][fromX]; @@ -7203,6 +7199,12 @@ LeftClick (ClickType clickType, int xPix, int yPix) } return; // promo popup appears on up-click } + /* Finish clickclick move */ + if (appData.animate || appData.highlightLastMove) { + SetHighlights(fromX, fromY, toX, toY); + } else { + ClearHighlights(); + } } else { /* Finish drag move */ if (appData.highlightLastMove) { diff --git a/board.c b/board.c index a725895..0bc81f8 100644 --- a/board.c +++ b/board.c @@ -118,6 +118,9 @@ int damage[2][BOARD_RANKS][BOARD_FILES]; AnimState anims[NrOfAnims]; static void DrawSquare P((int row, int column, ChessSquare piece, int do_flash)); +static Boolean IsDrawArrowEnabled P((void)); +static void DrawArrowHighlight P((int fromX, int fromY, int toX,int toY)); +static void ArrowDamage P((int s_col, int s_row, int d_col, int d_row)); static void drawHighlight (int file, int rank, int type) @@ -145,6 +148,8 @@ int pm1X = -1, pm1Y = -1, pm2X = -1, pm2Y = -1; void SetHighlights (int fromX, int fromY, int toX, int toY) { + int arrow = hi2X > 0 && IsDrawArrowEnabled(); + if (hi1X != fromX || hi1Y != fromY) { if (hi1X >= 0 && hi1Y >= 0) { drawHighlight(hi1X, hi1Y, 0); @@ -156,6 +161,10 @@ SetHighlights (int fromX, int fromY, int toX, int toY) drawHighlight(hi2X, hi2Y, 0); } } + + if(arrow) // there currently is an arrow displayed + ArrowDamage(hi1X, hi1Y, hi2X, hi2Y); // mark which squares it damaged + if (hi1X != fromX || hi1Y != fromY) { if (fromX >= 0 && fromY >= 0) { drawHighlight(fromX, fromY, 1); @@ -167,13 +176,13 @@ SetHighlights (int fromX, int fromY, int toX, int toY) } } - if(toX<0) // clearing the highlights must have damaged arrow - DrawArrowHighlight(hi1X, hi1Y, hi2X, hi2Y); // for now, redraw it (should really be cleared!) - hi1X = fromX; hi1Y = fromY; hi2X = toX; hi2Y = toY; + + if(arrow || toX < 0 && IsDrawArrowEnabled()) + DrawPosition(FALSE, NULL); // repair any arrow damage, or draw a new one } void @@ -1016,7 +1025,7 @@ SquareToPos (int rank, int file, int *x, int *y) } /* Draw an arrow between two points using current settings */ -void +static void DrawArrowBetweenPoints (int s_x, int s_y, int d_x, int d_y) { Pnt arrow[8]; @@ -1119,7 +1128,7 @@ DrawArrowBetweenPoints (int s_x, int s_y, int d_x, int d_y) // Polygon( hdc, arrow, 7 ); } -void +static void ArrowDamage (int s_col, int s_row, int d_col, int d_row) { int hor, vert, i, n = partnerUp * twoBoards; @@ -1134,7 +1143,7 @@ ArrowDamage (int s_col, int s_row, int d_col, int d_row) } /* [AS] Draw an arrow between two squares */ -void +static void DrawArrowBetweenSquares (int s_col, int s_row, int d_col, int d_row) { int s_x, s_y, d_x, d_y; @@ -1177,13 +1186,13 @@ DrawArrowBetweenSquares (int s_col, int s_row, int d_col, int d_row) ArrowDamage(s_col, s_row, d_col, d_row); } -Boolean +static Boolean IsDrawArrowEnabled () { return (appData.highlightMoveWithArrow || twoBoards && partnerUp) && squareSize >= 32; } -void +static void DrawArrowHighlight (int fromX, int fromY, int toX,int toY) { if( IsDrawArrowEnabled() && fromX >= 0 && fromY >= 0 && toX >= 0 && toY >= 0) diff --git a/board.h b/board.h index 8f0c9db..9fc8f59 100644 --- a/board.h +++ b/board.h @@ -90,8 +90,6 @@ void DrawBlank P((AnimNr anr, int x, int y, int startColor)); void CopyRectangle P((AnimNr anr, int srcBuf, int destBuf, int srcX, int srcY, int width, int height, int destX, int destY)); void SetDragPiece P((AnimNr anr, ChessSquare piece)); void DragPieceMove P((int x, int y)); -void DrawArrowHighlight P((int fromX, int fromY, int toX,int toY)); -Boolean IsDrawArrowEnabled P((void)); extern int damage[2][BOARD_RANKS][BOARD_FILES];