Updated copyright notice to 2014
[xboard.git] / board.c
diff --git a/board.c b/board.c
index 6abbabb..5c55b4f 100644 (file)
--- 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, 2014 Free Software Foundation, Inc.
  *
  * The following terms apply to Digital Equipment Corporation's copyright
  * interest in XBoard:
@@ -163,7 +163,7 @@ 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
 
@@ -479,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 */
@@ -503,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 */
@@ -522,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
@@ -764,7 +771,7 @@ DrawDragPiece ()
      it's being dragged around the board. So we erase the square
      that the piece is on and draw it at the last known drag point. */
   DrawOneSquare(anims[Player].startSquare.x, anims[Player].startSquare.y,
-               EmptySquare, anims[Player].startColor, 0, NULL, 0);
+               EmptySquare, anims[Player].startColor, 0, NULL, NULL, 0);
   AnimationFrame(Player, &anims[Player].prevFrame, anims[Player].dragPiece);
   damage[0][anims[Player].startBoardY][anims[Player].startBoardX] = TRUE;
 }
@@ -774,7 +781,7 @@ DrawSquare (int row, int column, ChessSquare piece, int do_flash)
 {
     int square_color, x, y, align=0;
     int i;
-    char string[2];
+    char tString[3], bString[2];
     int flash_delay;
 
     /* Calculate delay in milliseconds (2-delays per complete flash) */
@@ -792,37 +799,37 @@ DrawSquare (int row, int column, ChessSquare piece, int do_flash)
 
     square_color = SquareColor(row, column);
 
-    string[1] = NULLCHAR;
+    bString[1] = bString[0] = NULLCHAR;
     if (appData.showCoords && row == (flipView ? BOARD_HEIGHT-1 : 0)
                && column >= 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<appData.flashCount; ++i) {
-           DrawOneSquare(x, y, piece, square_color, 0, string, 0);
+           DrawOneSquare(x, y, piece, square_color, 0, tString, bString, 0);
            GraphExpose(currBoard, x, y, squareSize, squareSize);
            FlashDelay(flash_delay);
-           DrawOneSquare(x, y, EmptySquare, square_color, 0, string, 0);
+           DrawOneSquare(x, y, EmptySquare, square_color, 0, tString, bString, 0);
            GraphExpose(currBoard, x, y, squareSize, squareSize);
            FlashDelay(flash_delay);
        }
     }
-    DrawOneSquare(x, y, piece, square_color, partnerUp ? 0 : marker[row][column], string, align);
+    DrawOneSquare(x, y, piece, square_color, partnerUp ? 0 : marker[row][column], tString, bString, align);
 }
 
 /* Returns 1 if there are "too many" differences between b1 and b2
@@ -911,7 +918,7 @@ DrawPosition (int repaint, Board board)
        MarkMenuItem("View.Flip View", flipView);
     }
 
-    if(nr) { SlavePopUp(); SwitchWindow(); } // [HGM] popup board if not yet popped up, and switch drawing to it.
+    if(nr) { SlavePopUp(); SwitchWindow(0); } // [HGM] popup board if not yet popped up, and switch drawing to it.
 
     /*
      * It would be simpler to clear the window with XClearWindow()
@@ -946,7 +953,7 @@ DrawPosition (int repaint, Board board)
                DrawSquare(i, j, board[i][j], 0);
                if(damage[nr][i][j] & 2) {
                    drawHighlight(j, i, 0);   // repair arrow damage
-                   damage[nr][i][j] = False; // this flushed the square as well
+                   if(lineGap) damage[nr][i][j] = False; // this flushed the square as well
                } else damage[nr][i][j] = 1;  // mark for expose
            }
 
@@ -981,19 +988,19 @@ DrawPosition (int repaint, Board board)
     /* Draw highlights */
     if (pm1X >= 0 && pm1Y >= 0) {
       drawHighlight(pm1X, pm1Y, 2);
-      damage[nr][pm1Y][pm1X] = False;
+      if(lineGap) damage[nr][pm1Y][pm1X] = False;
     }
     if (pm2X >= 0 && pm2Y >= 0) {
       drawHighlight(pm2X, pm2Y, 2);
-      damage[nr][pm2Y][pm2X] = False;
+      if(lineGap) damage[nr][pm2Y][pm2X] = False;
     }
     if (hi1X >= 0 && hi1Y >= 0) {
       drawHighlight(hi1X, hi1Y, 1);
-      damage[nr][hi1Y][hi1X] = False;
+      if(lineGap) damage[nr][hi1Y][hi1X] = False;
     }
     if (hi2X >= 0 && hi2Y >= 0) {
       drawHighlight(hi2X, hi2Y, 1);
-      damage[nr][hi2Y][hi2X] = False;
+      if(lineGap) damage[nr][hi2Y][hi2X] = False;
     }
     DrawArrowHighlight(hi1X, hi1Y, hi2X, hi2Y);
   }
@@ -1022,12 +1029,12 @@ DrawPosition (int repaint, Board board)
                        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
+                   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 */
@@ -1235,5 +1242,3 @@ DrawArrowHighlight (int fromX, int fromY, int toX,int toY)
     if( IsDrawArrowEnabled() && fromX >= 0 && fromY >= 0 && toX >= 0 && toY >= 0)
         DrawArrowBetweenSquares(fromX, fromY, toX, toY);
 }
-
-