Updated copyright notice to 2013
[xboard.git] / board.c
diff --git a/board.c b/board.c
index e0f0649..d28fb75 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 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__
@@ -139,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;
@@ -477,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 */
@@ -501,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 */
@@ -520,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
@@ -581,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 */
@@ -638,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_WIDTH; i++) for(j=0; j<BOARD_HEIGHT; j++)
-      if((i-toX)*(i-toX) + (j-toY)*(j-toY) < 6) damage[0][j][i] = True;
+      if((i-toX)*(i-toX) + (j-toY)*(j-toY) < 6) damage[0][j][i] |=  1 + ((i-toX ^ j-toY) & 1);
   }
 
   /* Be sure end square is redrawn */
-  damage[0][toY][toX] = True;
+  damage[0][toY][toX] |= True;
 }
 
 void
@@ -812,10 +822,10 @@ DrawSquare (int row, int column, ChessSquare piece, int do_flash)
     if (do_flash && piece != EmptySquare && appData.flashCount > 0) {
        for (i=0; i<appData.flashCount; ++i) {
            DrawOneSquare(x, y, piece, square_color, 0, string, 0);
-           DrawExpose(NULL, x, y, squareSize, squareSize);
+           GraphExpose(currBoard, x, y, squareSize, squareSize);
            FlashDelay(flash_delay);
            DrawOneSquare(x, y, EmptySquare, square_color, 0, string, 0);
-           DrawExpose(NULL, x, y, squareSize, squareSize);
+           GraphExpose(currBoard, x, y, squareSize, squareSize);
            FlashDelay(flash_delay);
        }
     }
@@ -1000,7 +1010,7 @@ DrawPosition (int repaint, Board board)
     DrawDragPiece();
 
     if(exposeAll)
-       DrawExpose(NULL, 0, 0, BOARD_WIDTH*(squareSize + lineGap) + lineGap, BOARD_HEIGHT*(squareSize + lineGap) + lineGap);
+       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++)
@@ -1016,9 +1026,9 @@ DrawPosition (int repaint, Board board)
                          (squareSize + lineGap);
                    }
                    if(damage[nr][i][j] & 2) // damage by old or new arrow
-                       DrawExpose(NULL, x - lineGap, y - lineGap, squareSize + 2*lineGap, squareSize  + 2*lineGap);
+                       GraphExpose(currBoard, x - lineGap, y - lineGap, squareSize + 2*lineGap, squareSize  + 2*lineGap);
                    else
-                       DrawExpose(NULL, x, y, squareSize, squareSize);
+                       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
                }
     }