From f4766980b5d1313e24e4b704dfebd0b99d03d792 Mon Sep 17 00:00:00 2001 From: divverent Date: Sun, 25 Jul 2010 17:10:11 +0000 Subject: [PATCH] Linux SDL/GLX: allow loading the icon from .xpm at runtime (darkplaces-icon.xpm). Allows for easier branding. git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10362 d7cf8633-e32d-0410-b094-e92efae38249 --- common.c | 28 ++++++++++++++++++++++++++++ common.h | 3 +++ vid_glx.c | 14 +++++++++++++- vid_sdl.c | 16 +++++++++++++--- 4 files changed, 57 insertions(+), 4 deletions(-) diff --git a/common.c b/common.c index b52b0bfa..028014bc 100644 --- a/common.c +++ b/common.c @@ -2228,3 +2228,31 @@ void FindFraction(double val, int *num, int *denom, int denomMax) } } } + +// decodes an XPM from C syntax +char **XPM_DecodeString(const char *in) +{ + static char *tokens[257]; + static char lines[257][512]; + size_t line = 0; + + // skip until "{" token + while(COM_ParseToken_QuakeC(&in, false) && strcmp(com_token, "{")); + + // now, read in succession: string, comma-or-} + while(COM_ParseToken_QuakeC(&in, false)) + { + tokens[line] = lines[line]; + strlcpy(lines[line++], com_token, sizeof(lines[0])); + if(!COM_ParseToken_QuakeC(&in, false)) + return NULL; + if(!strcmp(com_token, "}")) + break; + if(strcmp(com_token, ",")) + return NULL; + if(line >= sizeof(tokens) / sizeof(tokens[0])) + return NULL; + } + + return tokens; +} diff --git a/common.h b/common.h index 638c7d44..228a133e 100644 --- a/common.h +++ b/common.h @@ -348,5 +348,8 @@ size_t strlcpy(char *dst, const char *src, size_t siz); void FindFraction(double val, int *num, int *denom, int denomMax); +// decodes XPM file to XPM array (as if #include'd) +char **XPM_DecodeString(const char *in); + #endif diff --git a/vid_glx.c b/vid_glx.c index 01d2486b..e1b4bc72 100644 --- a/vid_glx.c +++ b/vid_glx.c @@ -815,6 +815,8 @@ qboolean VID_InitMode(viddef_mode_t *mode) XVisualInfo *visinfo; int MajorVersion, MinorVersion; const char *drivername; + char *xpm; + char **idata; vid_isfullscreen = false; vid_isnetwmfullscreen = false; @@ -997,12 +999,22 @@ qboolean VID_InitMode(viddef_mode_t *mode) win = XCreateWindow(vidx11_display, root, 0, 0, mode->width, mode->height, 0, visinfo->depth, InputOutput, visinfo->visual, mask, &attr); + xpm = (char *) FS_LoadFile("darkplaces-icon.xpm", tempmempool, false, NULL); + idata = NULL; + if(xpm) + idata = XPM_DecodeString(xpm); + if(!idata) + idata = ENGINE_ICON; + wmhints = XAllocWMHints(); if(XpmCreatePixmapFromData(vidx11_display, win, - (gamemode == GAME_NEXUIZ) ? nexuiz_xpm : darkplaces_xpm, + idata, &wmhints->icon_pixmap, &wmhints->icon_mask, NULL) == XpmSuccess) wmhints->flags |= IconPixmapHint | IconMaskHint; + if(xpm) + Mem_Free(xpm); + clshints = XAllocClassHint(); clshints->res_name = strdup(gamename); clshints->res_class = strdup("DarkPlaces"); diff --git a/vid_sdl.c b/vid_sdl.c index 4d9153b4..e751030d 100644 --- a/vid_sdl.c +++ b/vid_sdl.c @@ -549,9 +549,19 @@ static void VID_SetIcon(void) int thenone = -1; static SDL_Color palette[256]; unsigned short palenc[256]; // store color id by char - - char **idata = ENGINE_ICON; - char *data = idata[0]; + char *xpm; + char **idata, *data; + + xpm = (char *) FS_LoadFile("darkplaces-icon.xpm", tempmempool, false, NULL); + idata = NULL; + if(xpm) + idata = XPM_DecodeString(xpm); + if(!idata) + idata = ENGINE_ICON; + if(xpm) + Mem_Free(xpm); + + data = idata[0]; if(sscanf(data, "%i %i %i %i", &width, &height, &colors, &isize) != 4) { -- 2.39.2