X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=draw.c;h=930b02c21b2e74e4e86f9988fc55f6716e0c31b9;hb=2987ec348b8b2cbf38ba9a6a0793652a6b238ae8;hp=783f2400ea81c96e04fa836c3e6426cc41f18919;hpb=abd8f79dc7c4945e4d04b9199fad6591206ff705;p=xboard.git diff --git a/draw.c b/draw.c index 783f240..930b02c 100644 --- a/draw.c +++ b/draw.c @@ -5,7 +5,7 @@ * Massachusetts. * * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006, - * 2007, 2008, 2009, 2010, 2011, 2012, 2013 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: @@ -117,6 +117,8 @@ int useTexture, textureW[2], textureH[2]; #define White(piece) ((int)(piece) < (int)BlackPawn) +char svgDir[MSG_SIZ] = SVGDIR; + char *crWhite = "#FFFFB0"; char *crBlack = "#AD5D3D"; @@ -175,10 +177,20 @@ InitDrawingSizes (BoardSize boardSize, int flags) int boardWidth, boardHeight; static int oldWidth, oldHeight; static VariantClass oldVariant; - static int oldTwoBoards = 0; + static int oldTwoBoards = 0, oldNrOfFiles = 0; if(!mainOptions[W_BOARD].handle) return; + if(boardSize == -2 && gameInfo.variant != oldVariant + && oldNrOfFiles && oldNrOfFiles != BOARD_WIDTH) { // called because variant switch changed board format + squareSize = ((squareSize + lineGap) * oldNrOfFiles + 0.5*BOARD_WIDTH) / BOARD_WIDTH; // keep total width fixed + if(appData.overrideLineGap < 0) lineGap = squareSize < 37 ? 1 : squareSize < 59 ? 2 : squareSize < 116 ? 3 : 4; + squareSize -= lineGap; + CreatePNGPieces(); + CreateGrid(); + } + oldNrOfFiles = BOARD_WIDTH; + if(oldTwoBoards && !twoBoards) PopDown(DummyDlg); oldTwoBoards = twoBoards; @@ -306,7 +318,7 @@ ScaleOnePiece (int color, int piece) if(!pngPieceImages[color][piece]) { // we still did not manage to acquire a piece bitmap static int warned = 0; - if(!(svgPieces[color][piece] = LoadSVG(SVGDIR, color, piece, 0)) && !warned) { // try to fall back on installed svg + if(!(svgPieces[color][piece] = LoadSVG(svgDir, color, piece, 0)) && !warned) { // try to fall back on installed svg char *msg = _("No default pieces installed!\nSelect your own using '-pieceImageDirectory'."); printf("%s\n", msg); // give up DisplayError(msg, 0); @@ -698,7 +710,7 @@ DrawText (char *string, int x, int y, int align) CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD); - cairo_set_font_size (cr, squareSize/4); + cairo_set_font_size (cr, align < 0 ? 2*squareSize/3 : squareSize/4); // calculate where it goes cairo_text_extents (cr, string, &te); @@ -712,9 +724,12 @@ DrawText (char *string, int x, int y, int align) yy += -te.y_bearing + 3; } else if (align == 4) { xx += te.x_bearing + 1, yy += -te.y_bearing + 3; + } else if (align < 0) { + xx += squareSize/2 - te.width/2, yy += 9*squareSize/16 - te.y_bearing/2; } cairo_move_to (cr, xx-1, yy); + if(align == -2) cairo_set_source_rgb (cr, 1.0, 0.0, 0.0); else if(align < 3) cairo_set_source_rgb (cr, 0.0, 0.0, 0.0); else cairo_set_source_rgb (cr, 1.0, 1.0, 1.0); cairo_show_text (cr, string); @@ -722,6 +737,31 @@ DrawText (char *string, int x, int y, int align) } void +InscribeKanji (ChessSquare piece, int x, int y) +{ + char *p, *q, buf[10]; + int n; + if(piece == EmptySquare) return; + if(piece >= BlackPawn) piece = BLACK_TO_WHITE piece; + p = appData.inscriptions; + n = piece; + while(piece > WhitePawn) { + if(*p++ == NULLCHAR) { + if(n != WhiteKing) return; + p = q; + break; + } + q = p - 1; + while((*p & 0xC0) == 0x80) p++; // skip UTF-8 continuation bytes + piece--; + } + strncpy(buf, p, 10); + for(q=buf; (*++q & 0xC0) == 0x80;); + *q = NULLCHAR; + DrawText(buf, x, y, n > WhiteLion ? -2 : -1); +} + +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 @@ -730,6 +770,7 @@ DrawOneSquare (int x, int y, ChessSquare piece, int square_color, int marker, ch BlankSquare(csBoardWindow, x, y, square_color, piece, 1); } else { pngDrawPiece(csBoardWindow, piece, square_color, x, y); + if(appData.inscriptions[0]) InscribeKanji(piece, x, y); } if(align) { // square carries inscription (coord or piece count)