If the line gap is zero the only way to see last- and premoves is to enable
the arrows option.
The attached patch will color the "from" and "to" squares interior when the
line gap is zero, with the resulting behavior being analogous to Lichess'
and Chess.com's.
Are you interested in the patch? Do you think it should be added as a separate
option instead? Or maybe reworked into say a single highligh option with
a combobox for {square interior, arrow, border}?
Cheers,
Nathan Teodosio
Author: Nathan Pratta Teodosio <[email protected]>
Description: If line gap is zero, color squares interior for last- and premove.
Date: 2025-02-16
diff --git a/board.c b/board.c
index 533e7fb..f0b34b1 100644
--- a/board.c
+++ b/board.c
@@ -126,11 +126,10 @@ 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)
+drawHighlight (int file, int rank, int type, ChessSquare piece)
{
int x, y;
- if (lineGap == 0) return;
if (flipView) {
x = lineGap/2 + ((BOARD_WIDTH-1)-file) *
@@ -142,7 +141,18 @@ drawHighlight (int file, int rank, int type)
(squareSize + lineGap);
}
- DrawBorder(x,y, type, lineGap & 1); // pass whether lineGap is odd
+ if (lineGap == 0) {
+ /* Hereby hardcoding type1->3->lastmove and type2->4->premove.
+ * Maybe horrible, but I'm trying to follow the existing style.
+ * And maybe due to be reworked to an enum if upstream likes the patch.
+ */
+ if (type == 1) {
+ DrawOneSquare(x, y, piece, 3, 0, "", "", 0);
+ } else if (type == 2) {
+ DrawOneSquare(x, y, PieceForSquare(file, rank), 4, 0, "", "", 0);
+ }
+ } else
+ DrawBorder(x,y, type, lineGap & 1); // pass whether lineGap is odd
}
int hi1X = -1, hi1Y = -1, hi2X = -1, hi2Y = -1;
@@ -964,7 +973,7 @@ DrawPosition (int repaint, Board board)
if (damage[nr][i][j] || !nr && marker[i][j] != lastMarker[i][j]) {
DrawSquare(i, j, board[i][j], 0);
if(lineGap && damage[nr][i][j] & 2) {
- drawHighlight(j, i, 0);
+ drawHighlight(j, i, 0, board[i][j]);
SquareExpose(i, j, lineGap);
} else SquareExpose(i, j, 0);
damage[nr][i][j] = 0;
@@ -1011,19 +1020,19 @@ DrawPosition (int repaint, Board board)
/* Draw highlights */
if (pm1X >= 0 && pm1Y >= 0) {
- drawHighlight(pm1X, pm1Y, 2);
+ drawHighlight(pm1X, pm1Y, 2, board[pm1Y][pm1X]);
if(lineGap) damage[nr][pm1Y][pm1X] |= 2;
}
if (pm2X >= 0 && pm2Y >= 0) {
- drawHighlight(pm2X, pm2Y, 2);
+ drawHighlight(pm2X, pm2Y, 2, board[pm2Y][pm2X]);
if(lineGap) damage[nr][pm2Y][pm2X] |= 2;
}
if (hi1X >= 0 && hi1Y >= 0) {
- drawHighlight(hi1X, hi1Y, 1);
+ drawHighlight(hi1X, hi1Y, 1, board[hi1Y][hi1X]);
if(lineGap) damage[nr][hi1Y][hi1X] |= 2;
}
if (hi2X >= 0 && hi2Y >= 0) {
- drawHighlight(hi2X, hi2Y, 1);
+ drawHighlight(hi2X, hi2Y, 1, board[hi2Y][hi2X]);
if(lineGap) damage[nr][hi2Y][hi2X] |= 2;
}
DrawArrowHighlight(hi1X, hi1Y, hi2X, hi2Y);
diff --git a/draw.c b/draw.c
index 8b78892..a4e4bb4 100644
--- a/draw.c
+++ b/draw.c
@@ -753,6 +753,8 @@ BlankSquare (cairo_surface_t *dest, int x, int y, int color, ChessSquare piece,
case 0: col = appData.darkSquareColor; break;
case 1: col = appData.lightSquareColor; break;
case 2: col = "#000000"; break;
+ case 3: col = appData.highlightSquareColor; break;
+ case 4: col = appData.premoveHighlightColor; break;
default: col = "#808080"; break; // cannot happen
}
SetPen(cr, 2.0, col, 0);
@@ -766,6 +768,7 @@ BlankSquare (cairo_surface_t *dest, int x, int y, int color, ChessSquare piece,
cairo_rectangle (cr, x*fac, y*fac, squareSize, squareSize);
cairo_fill (cr);
}
+ //if (color == 4) GraphExpose(currBoard, x, y, squareSize, squareSize);
cairo_destroy (cr);
}
@@ -788,6 +791,7 @@ pngDrawPiece (cairo_surface_t *dest, ChessSquare piece, int square_color, int x,
cairo_set_source_surface (cr, pngPieceBitmaps[kind][piece], x, y);
cairo_paint(cr);
cairo_destroy (cr);
+ //if (square_color == 4) GraphExpose(currBoard, x, y, squareSize, squareSize);
}
static char *markerColor[8] = { "#FFFF00", "#FF0000", "#00FF00", "#0000FF", "#00FFFF", "#FF00FF", "#FFFFFF", "#000000" };
@@ -926,6 +930,7 @@ DrawOneSquare (int x, int y, ChessSquare piece, int square_color, int marker, ch
pngDrawPiece(CsBoardWindow(currBoard), piece, square_color, x, y);
if(appData.inscriptions[0]) InscribeKanji(CsBoardWindow(currBoard), piece, x, y);
}
+ if (square_color == 4) GraphExpose(currBoard, x, y, squareSize, squareSize);
if(align) { // square carries inscription (coord or piece count)
if(align > 1) DrawText(tString, x, y, align); // top (rank or count)