]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Linux SDL/GLX: allow loading the icon from .xpm at runtime (darkplaces-icon.xpm)...
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Sun, 25 Jul 2010 17:10:11 +0000 (17:10 +0000)
committerRudolf Polzer <divverent@alientrap.org>
Tue, 27 Jul 2010 19:19:05 +0000 (21:19 +0200)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@10362 d7cf8633-e32d-0410-b094-e92efae38249
::stable-branch::merge=f4766980b5d1313e24e4b704dfebd0b99d03d792

common.c
common.h
vid_glx.c
vid_sdl.c

index b52b0bfaf9cf5529d107c381f632f78977a196cc..028014bc7420a96b24d7cf232b73f497af7a4cb8 100644 (file)
--- 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;
+}
index 638c7d448e9b0e602d73df944c6bc777ec55dbbb..228a133e572874b95059abc0cf268a83259c4167 100644 (file)
--- 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
 
index 01d2486be4d5a0e09d1aa764b2aab474179f31f5..e1b4bc72ec5686afb868402091c1dd40fdd7a3d5 100644 (file)
--- 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");
index 4d9153b4f5b9a9c366dac30c11ccd02d9d775676..e751030db90594cec9ec21100bccf92f9111e8c8 100644 (file)
--- 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)
        {