From b16fa6548a01d63f00b21e73e1d58009c88d20e4 Mon Sep 17 00:00:00 2001 From: H.G.Muller Date: Thu, 11 Sep 2014 10:23:42 +0200 Subject: [PATCH 1/1] Make SVGDIR a variable Replace all occurrences of SVGDIR in the source by svgDir, a char array that is initialized to SVGDIR, so that it can be altered at run time. This is needed to make portable apps. Where SVGDIR was used in string concatenation, the code had to be re-written to use snprintf to do the concatenation at run time, through a new function LoadIconFile. The extension of image files used there is now made dependent on the __APPLE__ switch, so that it can use .png in OS X (which does not seem to understand SVG icons). --- draw.c | 4 +++- draw.h | 1 + gtk/xboard.c | 16 ++++++++++++++-- gtk/xboard.h | 1 + gtk/xengineoutput.c | 19 ++++++++----------- 5 files changed, 27 insertions(+), 14 deletions(-) diff --git a/draw.c b/draw.c index fb66db2..930b02c 100644 --- a/draw.c +++ b/draw.c @@ -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"; @@ -316,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); diff --git a/draw.h b/draw.h index cf6ceab..517e067 100644 --- a/draw.h +++ b/draw.h @@ -68,6 +68,7 @@ void DrawSegment P((int x, int y, int *lastX, int *lastY, int p)); void DrawRectangle P((int left, int top, int right, int bottom, int side, int style)); void DrawEvalText P((char *buf, int cbBuf, int y)); extern Option *disp; +extern char svgDir[]; // defined in evaldraw.c float Color P((char *col, int n)); diff --git a/gtk/xboard.c b/gtk/xboard.c index a7cbd45..2c51e01 100644 --- a/gtk/xboard.c +++ b/gtk/xboard.c @@ -172,6 +172,7 @@ extern char *getenv(); // prevent pathname of positional file argument provided by OS X being be mistaken for option name // (price is that we won't recognize Windows option format anymore). # define SLASH '-' +# define IMG ".png" // redefine some defaults # undef ICS_LOGON # undef DATADIR @@ -183,6 +184,7 @@ extern char *getenv(); char masterSettings[MSG_SIZ]; #else # define SLASH '/' +# define IMG ".svg" #endif #ifdef __EMX__ @@ -806,6 +808,15 @@ SlaveResize (Option *opt) gtk_window_resize(GTK_WINDOW(shells[DummyDlg]), slaveW + opt->max, slaveH + opt->value); } +GdkPixbuf * +LoadIconFile (gchar *svgFilename) +{ + char buf[MSG_SIZ]; + + snprintf(buf, MSG_SIZ, "%s/%s" IMG, svgDir, svgFilename); + return gdk_pixbuf_new_from_file(buf, NULL); +} + #ifdef __APPLE__ static char clickedFile[MSG_SIZ]; static int suppress; @@ -858,6 +869,7 @@ main (int argc, char **argv) theApp = g_object_new(GTKOSX_TYPE_APPLICATION, NULL); strncpy(dataDir, path, MSG_SIZ); snprintf(masterSettings, MSG_SIZ, "%s/Contents/Resources/etc/xboard.conf", path); + snprintf(svgDir, MSG_SIZ, "%s/Contents/Resources/share/xboard/themes/default", path); suppress = (argc == 1 || argc > 1 && argv[1][00] != '-'); // OSX sends signal even if name was already argv[1]! g_signal_connect(theApp, "NSApplicationOpenFile", G_CALLBACK(StartNewXBoard), NULL); // we must call application ready before we can get the signal, @@ -1125,8 +1137,8 @@ main (int argc, char **argv) /* * Create an icon. (Use two icons, to indicate whther it is white's or black's turn.) */ - WhiteIcon = gdk_pixbuf_new_from_file(SVGDIR "/icon_white.svg", NULL); - BlackIcon = gdk_pixbuf_new_from_file(SVGDIR "/icon_black.svg", NULL); + WhiteIcon = LoadIconFile("icon_white"); + BlackIcon = LoadIconFile("icon_black"); SetClockIcon(0); // sets white icon diff --git a/gtk/xboard.h b/gtk/xboard.h index b839418..234692d 100644 --- a/gtk/xboard.h +++ b/gtk/xboard.h @@ -120,6 +120,7 @@ typedef struct { #define SETTINGS_FILE SYSCONFDIR"/xboard.conf" #define COLOR_BKGD "white" +GdkPixbuf *LoadIconFile P((char *name)); void NewTagsPopup P((char *text, char *msg)); int AppendText P((Option *opt, char *s)); void NewCommentPopup P((char *title, char *text, int index)); diff --git a/gtk/xengineoutput.c b/gtk/xengineoutput.c index 74ae0e6..def18f7 100644 --- a/gtk/xengineoutput.c +++ b/gtk/xengineoutput.c @@ -77,10 +77,7 @@ static GdkPixbuf *iconsGTK[8]; static void ReadIcon (gchar *svgFilename, int iconNr) { - char buf[MSG_SIZ]; - - snprintf(buf, MSG_SIZ, "%s/%s", SVGDIR, svgFilename); - iconsGTK[iconNr] = gdk_pixbuf_new_from_file(buf, NULL); + iconsGTK[iconNr] = LoadIconFile(svgFilename); } void @@ -90,14 +87,14 @@ InitEngineOutput (Option *opt, Option *memo2) Widget w = opt->handle; memoWidget = memo2->handle; #endif - ReadIcon("eo_White.svg", nColorWhite); - ReadIcon("eo_Black.svg", nColorBlack); - ReadIcon("eo_Unknown.svg", nColorUnknown); - - ReadIcon("eo_Clear.svg", nClear); - ReadIcon("eo_Ponder.svg", nPondering); - ReadIcon("eo_Thinking.svg", nThinking); - ReadIcon("eo_Analyzing.svg", nAnalyzing); + ReadIcon("eo_White", nColorWhite); + ReadIcon("eo_Black", nColorBlack); + ReadIcon("eo_Unknown", nColorUnknown); + + ReadIcon("eo_Clear", nClear); + ReadIcon("eo_Ponder", nPondering); + ReadIcon("eo_Thinking", nThinking); + ReadIcon("eo_Analyzing", nAnalyzing); } void -- 1.7.0.4