X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=board.c;h=0941fc97e16c11a94d7e7f890e28b7c33e92e4a4;hb=b737badf310f917fb0f7d5657fe7418aa4a8e401;hp=676ea0b9e154eb13f007ed6e7c5ebd6c791cf0e7;hpb=c0d0ea91773838e5d11c3cd3b407fea251058c34;p=xboard.git diff --git a/board.c b/board.c index 676ea0b..0941fc9 100644 --- a/board.c +++ b/board.c @@ -5,7 +5,7 @@ * Massachusetts. * * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006, - * 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. + * 2007, 2008, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc. * * The following terms apply to Digital Equipment Corporation's copyright * interest in XBoard: @@ -96,8 +96,10 @@ extern char *getenv(); #include "common.h" #include "frontend.h" #include "backend.h" +#include "xboard2.h" #include "moves.h" #include "board.h" +#include "draw.h" #ifdef __EMX__ @@ -118,6 +120,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) @@ -136,7 +141,7 @@ drawHighlight (int file, int rank, int type) (squareSize + lineGap); } - DrawBorder(x,y, type); + DrawBorder(x,y, type, lineGap & 1); // pass whether lineGap is odd } int hi1X = -1, hi1Y = -1, hi2X = -1, hi2Y = -1; @@ -145,6 +150,8 @@ int pm1X = -1, pm1Y = -1, pm2X = -1, pm2Y = -1; void SetHighlights (int fromX, int fromY, int toX, int toY) { + int arrow = hi2X >= 0 && hi1Y >= 0 && IsDrawArrowEnabled(); + if (hi1X != fromX || hi1Y != fromY) { if (hi1X >= 0 && hi1Y >= 0) { drawHighlight(hi1X, hi1Y, 0); @@ -156,6 +163,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 +178,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 && fromY >= 0 && IsDrawArrowEnabled()) + DrawPosition(FALSE, NULL); // repair any arrow damage, or draw a new one } void @@ -468,12 +479,12 @@ AnimationFrame (AnimNr anr, Pnt *frame, ChessSquare piece) MyRectangle updates[4]; MyRectangle overlap; Pnt pt; - int count, i; AnimState *anim = &anims[anr]; + int count, i, x, y, w, h; /* Save what we are about to draw into the new buffer */ CopyRectangle(anr, DISP, 0, - frame->x, frame->y, squareSize, squareSize, + x = frame->x, y = frame->y, w = squareSize, h = squareSize, 0, 0); /* Erase bits of the previous frame */ @@ -492,11 +503,17 @@ AnimationFrame (AnimNr anr, Pnt *frame, ChessSquare piece) updates[i].y - anim->prevFrame.y, updates[i].width, updates[i].height, updates[i].x, updates[i].y); + /* [HGM] correct expose rectangle to encompass both overlapping squares */ + if(x > anim->prevFrame.x) w += x - anim->prevFrame.x, x = anim->prevFrame.x; + else w += anim->prevFrame.x - x; + if(y > anim->prevFrame.y) h += y - anim->prevFrame.y, y = anim->prevFrame.y; + else h += anim->prevFrame.y - y; } else { /* Easy when no overlap */ CopyRectangle(anr, 2, DISP, 0, 0, squareSize, squareSize, anim->prevFrame.x, anim->prevFrame.y); + GraphExpose(currBoard, anim->prevFrame.x, anim->prevFrame.y, squareSize, squareSize); } /* Save this frame for next time round */ @@ -511,6 +528,7 @@ AnimationFrame (AnimNr anr, Pnt *frame, ChessSquare piece) CopyRectangle(anr, 0, DISP, 0, 0, squareSize, squareSize, frame->x, frame->y); + GraphExpose(currBoard, x, y, w, h); } static void @@ -572,6 +590,7 @@ AnimateAtomicCapture (Board board, int fromX, int fromY, int toX, int toY) FrameDelay(appData.animSpeed); } board[fromY][toY] = piece; + DrawGrid(); } /* Main control logic for deciding what to animate and how */ @@ -629,11 +648,11 @@ AnimateMove (Board board, int fromX, int fromY, int toX, int toY) if(Explode(board, fromX, fromY, toX, toY)) { // mark as damaged int i,j; for(i=0; i= BOARD_LEFT && column < BOARD_RGHT) { - string[0] = 'a' + column - BOARD_LEFT; + bString[0] = 'a' + column - BOARD_LEFT; align = 1; // coord in lower-right corner } if (appData.showCoords && column == (flipView ? BOARD_RGHT-1 : BOARD_LEFT)) { - string[0] = ONE + row; + snprintf(tString, 3, "%d", ONE - '0' + row); align = 2; // coord in upper-left corner } if (column == (flipView ? BOARD_LEFT-1 : BOARD_RGHT) && piece > 1 ) { - string[0] = '0' + piece; + snprintf(tString, 3, "%d", piece); align = 3; // holdings count in upper-right corner } if (column == (flipView ? BOARD_RGHT : BOARD_LEFT-1) && piece > 1) { - string[0] = '0' + piece; + snprintf(tString, 3, "%d", piece); align = 4; // holdings count in upper-left corner } if(square_color == 2 || appData.blindfold) piece = EmptySquare; if (do_flash && piece != EmptySquare && appData.flashCount > 0) { for (i=0; i 0) @@ -949,25 +973,34 @@ DrawPosition (int repaint, Board board) DrawSquare(i, j, board[i][j], 0); damage[nr][i][j] = False; } + + exposeAll = True; } CopyBoard(lastBoard[nr], board); lastBoardValid[nr] = 1; if(nr == 0) { // [HGM] dual: no highlights on second board yet lastFlipView = flipView; + for (i = 0; i < BOARD_HEIGHT; i++) + for (j = 0; j < BOARD_WIDTH; j++) + lastMarker[i][j] = marker[i][j]; /* Draw highlights */ if (pm1X >= 0 && pm1Y >= 0) { drawHighlight(pm1X, pm1Y, 2); + if(lineGap) damage[nr][pm1Y][pm1X] = False; } if (pm2X >= 0 && pm2Y >= 0) { drawHighlight(pm2X, pm2Y, 2); + if(lineGap) damage[nr][pm2Y][pm2X] = False; } if (hi1X >= 0 && hi1Y >= 0) { drawHighlight(hi1X, hi1Y, 1); + if(lineGap) damage[nr][hi1Y][hi1X] = False; } if (hi2X >= 0 && hi2Y >= 0) { drawHighlight(hi2X, hi2Y, 1); + if(lineGap) damage[nr][hi2Y][hi2X] = False; } DrawArrowHighlight(hi1X, hi1Y, hi2X, hi2Y); } @@ -976,8 +1009,32 @@ DrawPosition (int repaint, Board board) /* If piece being dragged around board, must redraw that too */ DrawDragPiece(); + if(exposeAll) + GraphExpose(currBoard, 0, 0, BOARD_WIDTH*(squareSize + lineGap) + lineGap, BOARD_HEIGHT*(squareSize + lineGap) + lineGap); + else { + for (i = 0; i < BOARD_HEIGHT; i++) + for (j = 0; j < BOARD_WIDTH; j++) + if(damage[nr][i][j]) { + int x, y; + if (flipView) { + x = lineGap + ((BOARD_WIDTH-1)-j) * + (squareSize + lineGap); + y = lineGap + i * (squareSize + lineGap); + } else { + x = lineGap + j * (squareSize + lineGap); + y = lineGap + ((BOARD_HEIGHT-1)-i) * + (squareSize + lineGap); + } + if(damage[nr][i][j] & 2) // damage by old or new arrow + GraphExpose(currBoard, x - lineGap, y - lineGap, squareSize + 2*lineGap, squareSize + 2*lineGap); + else + GraphExpose(currBoard, x, y, squareSize, squareSize); + damage[nr][i][j] &= ~2; // remember damage by newly drawn error in '2' bit, to schedule it for erasure next draw + } + } + FlashDelay(0); // this flushes drawing queue; - if(nr) SwitchWindow(); + if(nr) SwitchWindow(1); } /* [AS] Arrow highlighting support */ @@ -1012,7 +1069,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]; @@ -1115,22 +1172,22 @@ 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; hor = 64*s_col + 32; vert = 64*s_row + 32; for(i=0; i<= 64; i++) { - damage[n][vert+6>>6][hor+6>>6] = True; - damage[n][vert-6>>6][hor+6>>6] = True; - damage[n][vert+6>>6][hor-6>>6] = True; - damage[n][vert-6>>6][hor-6>>6] = True; + damage[n][vert+6>>6][hor+6>>6] |= 2; + damage[n][vert-6>>6][hor+6>>6] |= 2; + damage[n][vert+6>>6][hor-6>>6] |= 2; + damage[n][vert-6>>6][hor-6>>6] |= 2; hor += d_col - s_col; vert += d_row - s_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; @@ -1173,17 +1230,15 @@ 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) DrawArrowBetweenSquares(fromX, fromY, toX, toY); } - -