From: H.G. Muller Date: Sat, 6 Oct 2012 19:30:59 +0000 (+0200) Subject: Reload piece images when pngDirectory is changed X-Git-Url: http://winboard.nl/cgi-bin?a=commitdiff_plain;h=54fc63f1e8ea41966f47d2b60b616db0a9c5010d;hp=1cb7d2e7d2ed173e267748ed1216c5d28e3968f8;p=xboard.git Reload piece images when pngDirectory is changed The OK function of the board options dialog now tests for a change in pngDirectory and passes a parameter to InitDrawingParams to tell it to destroy the old images. This cause a reload on scaling the pieces. --- diff --git a/dialogs.c b/dialogs.c index 8bf5c76..721b2a2 100644 --- a/dialogs.c +++ b/dialogs.c @@ -752,11 +752,13 @@ SoundOptionsProc () static void DefColor P((int n)); static void AdjustColor P((int i)); +static char oldPngDir[MSG_SIZ]; + static int BoardOptionsOK (int n) { if(appData.overrideLineGap >= 0) lineGap = appData.overrideLineGap; else lineGap = defaultLineGap; - InitDrawingParams(); + InitDrawingParams(strcmp(oldPngDir, appData.pngDirectory)); InitDrawingSizes(-1, 0); DrawPosition(True, NULL); return 1; @@ -859,6 +861,7 @@ AdjustColor (int i) void BoardOptionsProc () { + strncpy(oldPngDir, appData.pngDirectory, MSG_SIZ-1); // to see if it changed GenericPopUp(boardOptions, _("Board Options"), TransientDlg, BoardWindow, MODAL, 0); } @@ -2047,8 +2050,8 @@ MenuCallback (int n) static Option * Exp (int n, int x, int y) { - static int but1, but3, oldSquareSize; - int menuNr = -3; + static int but1, but3, oldW, oldH; + int menuNr = -3, sizing; if(n == 0) { // motion if(SeekGraphClick(Press, x, y, 1)) return NULL; @@ -2068,9 +2071,10 @@ Exp (int n, int x, int y) case -2: shiftKey = !shiftKey; case -3: menuNr = RightClick(Release, x, y, &pmFromX, &pmFromY), but3 = 0; break; case 10: - if(squareSize != oldSquareSize) return NULL; // don't redraw while sizing + sizing = (oldW != x || oldH != y); + oldW = x; oldH = y; + if(sizing) return NULL; // don't redraw while sizing DrawPosition(True, NULL); - oldSquareSize = squareSize; default: return NULL; } diff --git a/dialogs.h b/dialogs.h index 9bd7515..64b9552 100644 --- a/dialogs.h +++ b/dialogs.h @@ -164,7 +164,7 @@ void DisplayLogos P((void *left, void *right)); void Browse P((DialogClass dlg, char *label, char *proposed, char *ext, Boolean pathFlag, char *mode, char **name, FILE **fp)); -void InitDrawingParams P(()); // in xboard.c +void InitDrawingParams P((int reload)); // in draw.c void DrawLogo P((void *handle, void *logo)); void ErrorPopUp P((char *title, char *text, int modal)); int ShiftKeys P((void)); diff --git a/draw.c b/draw.c index 20553e2..3bd6465 100644 --- a/draw.c +++ b/draw.c @@ -111,6 +111,7 @@ extern char *getenv(); #define OUTLINE 1 Boolean cairoAnimate; static cairo_surface_t *csBoardWindow, *csBoardBackup, *csDualBoard; +static cairo_surface_t *pngPieceImages[2][(int)BlackPawn+4]; // png 256 x 256 images static cairo_surface_t *pngPieceBitmaps[2][(int)BlackPawn]; // scaled pieces as used static cairo_surface_t *pngPieceBitmaps2[2][(int)BlackPawn+4]; // scaled pieces in store static cairo_surface_t *pngBoardBitmap[2]; @@ -277,7 +278,6 @@ ScaleOnePiece (char *name, int color, int piece) char buf[MSG_SIZ]; cairo_surface_t *img, *cs; cairo_t *cr; - static cairo_surface_t *pngPieceImages[2][(int)BlackPawn+4]; // png 256 x 256 images if((img = pngPieceImages[color][piece]) == NULL) { // if PNG file for this piece was not yet read, read it now and store it if(!*appData.pngDirectory) img = ConvertPixmap(color, piece); else { @@ -339,9 +339,15 @@ CreateAnyPieces () } void -InitDrawingParams () +InitDrawingParams (int reloadPieces) { + int i, p; MakeColors(); + if(reloadPieces) + for(i=0; i<2; i++) for(p=0; p