]> git.draconx.ca Git - rrace.git/blobdiff - src/x11.c
Add a more direct way to specify the game background.
[rrace.git] / src / x11.c
index 3b4818e1f67659a9a8edad9b8971e147c8fab6a2..955b93945e892e7c586deea2fe9b7ed920de2425 100644 (file)
--- a/src/x11.c
+++ b/src/x11.c
 /* Size of the traditional icon pixmap (multiple of 3) */
 #define ICON_SIZE 48
 
-typedef String colour_tab[COLOUR_MAX*(TILE_MAX-1)];
+enum {
+       NUM_TILE_COLOURS = COLOUR_MAX*(TILE_MAX-1),
+       COLOUR_UI_GAMEBG = NUM_TILE_COLOURS,
+       COLOUR_UI_MAX
+};
+typedef Pixel colour_tab[COLOUR_UI_MAX];
 
 #define COLOURRES(name, index, def) { \
-       (name), (NULL), XtRString, sizeof (String), \
+       (name), (NULL), XtRPixel, sizeof (String), \
        offsetof(struct { colour_tab t; }, t[index]), \
        XtRString, (def) }
 
@@ -59,31 +64,26 @@ static XtResource colour_resources[] = {
        COLOURRES("colourLight3", 15, COLOUR3_LIGHT),
        COLOURRES("colourLight4", 16, COLOUR4_LIGHT),
        COLOURRES("colourLight5", 17, COLOUR5_LIGHT),
+
+       COLOURRES("gameBackground", COLOUR_UI_GAMEBG, "#181818")
 };
 
 static void init_colours(struct app_state *state, Widget shell)
 {
-       Display *display = XtDisplay(shell);
-       Screen *screen = XtScreen(shell);
-       Colormap cmap = DefaultColormapOfScreen(screen);
        unsigned i;
 
-       colour_tab names;
-       XtGetApplicationResources(shell, &names, colour_resources,
+       colour_tab colours;
+       XtGetApplicationResources(shell, &colours, colour_resources,
                                  XtNumber(colour_resources), NULL, 0);
 
-       for (i = 0; i < XtNumber(names); i++) {
+       for (i = 0; i < NUM_TILE_COLOURS; i++) {
                unsigned tile = i % (TILE_MAX-1), shade = i / (TILE_MAX-1);
-               XColor c;
 
-               assert(names[i]);
-               if (!XAllocNamedColor(display, cmap, names[i], &c, &c)) {
-                       printf("warning: could not allocate colour: %s\n",
-                              names[i]);
-                       c.pixel = 0;
-               }
-               state->tile_colour[tile][shade] = c.pixel;
+               state->tile_colour[tile][shade] = colours[i];
        }
+
+       XtVaSetValues(state->game, XtNbackground, colours[COLOUR_UI_GAMEBG],
+                                  (char *)NULL);
 }
 
 void x11_initialize(struct app_state *state, Widget shell)