From: H.G. Muller Date: Mon, 17 Mar 2014 21:56:07 +0000 (+0100) Subject: Allow writing text on pieces X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=b5529b539614b61fa62d9f6cc374f335e7103024;p=xboard.git Allow writing text on pieces A new persistent string option -inscriptions allows the user to define characters to be written on the various piece types. The string is interpreted as UTF-8. This option is useful for on-the-fly synthesis of Shogi pieces, where the string can contain the various kanji in the canonical pieceToCharTable order. Except that only a single color has to be given. --- diff --git a/args.h b/args.h index f52404f..e8ef298 100644 --- a/args.h +++ b/args.h @@ -608,6 +608,7 @@ ArgDescriptor argDescriptors[] = { { "ub", ArgBoolean, (void *) &appData.useBorder, FALSE, INVALID }, { "border", ArgFilename, (void *) &appData.border, TRUE, (ArgIniType) "" }, { "finger", ArgFilename, (void *) &appData.finger, FALSE, (ArgIniType) "" }, + { "inscriptions", ArgString, (void *) &appData.inscriptions, XBOARD, (ArgIniType) "" }, // [HGM] tournament options { "tourneyFile", ArgFilename, (void *) &appData.tourneyFile, FALSE, (ArgIniType) "" }, diff --git a/backend.c b/backend.c index 95697fa..dd962a3 100644 --- a/backend.c +++ b/backend.c @@ -8705,7 +8705,7 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h } /* [AS] Adjudicate game if needed (note: remember that forwardMostMove now points past the last move) */ - if( gameMode == TwoMachinesPlay && adjudicateLossThreshold != 0 && forwardMostMove >= adjudicateLossPlies ) { + if( gameMode == TwoMachinesPlay && appData.adjudicateLossThreshold != 0 && forwardMostMove >= adjudicateLossPlies ) { int count = 0; while( count < adjudicateLossPlies ) { @@ -8714,8 +8714,8 @@ FakeBookMove: // [HGM] book: we jump here to simulate machine moves after book h if( count & 1 ) { score = -score; /* Flip score for winning side */ } - - if( score > adjudicateLossThreshold ) { +printf("score=%d count=%d\n",score,count); + if( score > appData.adjudicateLossThreshold ) { break; } diff --git a/common.h b/common.h index 2f66365..bf26600 100644 --- a/common.h +++ b/common.h @@ -631,6 +631,7 @@ typedef struct { int darkBackTextureMode; char * renderPiecesWithFont; /* Name of font for rendering chess pieces */ char * fontToPieceTable; /* Map to translate font character to chess pieces */ + char * inscriptions; /* text (kanji) to write on top of a piece */ int fontBackColorWhite; int fontForeColorWhite; int fontBackColorBlack; diff --git a/draw.c b/draw.c index 3eeff67..080fd82 100644 --- a/draw.c +++ b/draw.c @@ -708,7 +708,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); @@ -722,6 +722,8 @@ 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); @@ -732,6 +734,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, -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 @@ -740,6 +767,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); + InscribeKanji(piece, x, y); } if(align) { // square carries inscription (coord or piece count)