]> git.draconx.ca Git - rrace.git/commitdiff
Add a more direct way to specify the game background.
authorNick Bowler <nbowler@draconx.ca>
Thu, 10 Mar 2022 04:18:18 +0000 (23:18 -0500)
committerNick Bowler <nbowler@draconx.ca>
Thu, 10 Mar 2022 04:18:18 +0000 (23:18 -0500)
Rather than the user needing to know any details of the widget
hierarchy, add an application resource to set the game background
too (along with the tile colours).

We can also leverage Xt to allocate colours for us, which simplifies
things a bit.

doc/rrace-motif.1
src/motif.c
src/x11.c

index ab85b7bf202ef50a547397b8754f2f0580e220bb..7f5e1415a4836b99149f704fec6c5580b75e7fbc 100644 (file)
@@ -59,6 +59,10 @@ can be configured via X resources.
 .It Li rrace.colourLight0, rrace.colourLight1 , Em ... Li rrace.colourLight5
 These resources configure the six primary tile colours as well as their
 corresponding light and dark shades.
+.Pp
+.It Li rrace.gameBackground
+Specify the background colour of the play area.
+This is the colour that will be seen through the empty tile position.
 .El
 .Sh AUTHORS
 Nick Bowler <nbowler@draconx.ca>
index be5900d7bcadc9ccc43965dc1d552bbdc2348fe0..d7eb5e880c63240286a540ff1b1d8de59574aa5e 100644 (file)
@@ -40,7 +40,6 @@ static char * const default_resources[] = {
        "*game.XmFrame.shadowThickness: 3",
        "*game.XmFrame.shadowType: shadow_in",
        "*goalArea.leftOffset: 1",
-       "*gameCanvas.background: #202020",
 
        "*gameNew.accelerator: Ctrl<Key>N",
        "*gameNew.acceleratorText: Ctrl+N",
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)