From dd67211f46050409861a109a9778af6594279569 Mon Sep 17 00:00:00 2001 From: H.G. Muller <h.g.muller@hccnet.nl> Date: Wed, 6 Feb 2013 10:56:20 +0100 Subject: [PATCH] Draw both coords in a1 The lower-left board square needed two inscriptions, but DrawOneSquare() only allowed one, so that the file ID would not be written. Now two strings can be passed, and when align > 1 to indicate the alignment of the top string, it is still checked if a bottom string is present as well, which then is drawn with alignment 1 (= bottom right). The rank coord or piece count can now also be double digit. --- board.c | 20 ++++++++++---------- board.h | 2 +- draw.c | 33 ++++++++++++++++++++------------- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/board.c b/board.c index d5b4766..0becf9a 100644 --- a/board.c +++ b/board.c @@ -771,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; } @@ -781,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) */ @@ -799,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 diff --git a/board.h b/board.h index 0d80544..d5efc44 100644 --- a/board.h +++ b/board.h @@ -78,7 +78,7 @@ typedef struct { extern AnimState anims[]; void DrawPolygon P((Pnt arrow[], int nr)); -void DrawOneSquare P((int x, int y, ChessSquare piece, int square_color, int marker, char *string, int align)); +void DrawOneSquare P((int x, int y, ChessSquare piece, int square_color, int marker, char *tString, char *bString, int align)); void DrawDot P((int marker, int x, int y, int r)); void DrawGrid P((void)); int SquareColor P((int row, int column)); diff --git a/draw.c b/draw.c index 2034be3..53156f0 100644 --- a/draw.c +++ b/draw.c @@ -670,21 +670,12 @@ DrawDot (int marker, int x, int y, int r) GraphExpose(currBoard, x-r, y-r, 2*r, 2*r); } -void -DrawOneSquare (int x, int y, ChessSquare piece, int square_color, int marker, char *string, int align) -{ // basic front-end board-draw function: takes care of everything that can be in square: - // piece, background, coordinate/count, marker dot - cairo_t *cr; - - if (piece == EmptySquare) { - BlankSquare(csBoardWindow, x, y, square_color, piece, 1); - } else { - pngDrawPiece(csBoardWindow, piece, square_color, x, y); - } - - if(align) { // square carries inscription (coord or piece count) +static void +DrawText (char *string, int x, int y, int align) +{ int xx = x, yy = y; cairo_text_extents_t te; + cairo_t *cr; cr = cairo_create (csBoardWindow); cairo_select_font_face (cr, "Sans", @@ -712,6 +703,22 @@ DrawOneSquare (int x, int y, ChessSquare piece, int square_color, int marker, ch else cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); cairo_show_text (cr, string); cairo_destroy (cr); +} + +void +DrawOneSquare (int x, int y, ChessSquare piece, int square_color, int marker, char *tString, char *bString, int align) +{ // basic front-end board-draw function: takes care of everything that can be in square: + // piece, background, coordinate/count, marker dot + + if (piece == EmptySquare) { + BlankSquare(csBoardWindow, x, y, square_color, piece, 1); + } else { + pngDrawPiece(csBoardWindow, piece, square_color, x, y); + } + + if(align) { // square carries inscription (coord or piece count) + if(align > 1) DrawText(tString, x, y, align); // top (rank or count) + if(bString && *bString) DrawText(bString, x, y, 1); // bottom (always lower right file ID) } if(marker) { // print fat marker dot, if requested -- 1.7.0.4