From e63b5c4d1965ee2ea238441ed0dba468f64da137 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Wed, 9 Mar 2022 23:18:18 -0500 Subject: [PATCH] Add a more direct way to specify the game background. 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 | 4 ++++ src/motif.c | 1 - src/x11.c | 32 ++++++++++++++++---------------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/doc/rrace-motif.1 b/doc/rrace-motif.1 index ab85b7b..7f5e141 100644 --- a/doc/rrace-motif.1 +++ b/doc/rrace-motif.1 @@ -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 diff --git a/src/motif.c b/src/motif.c index be5900d..d7eb5e8 100644 --- a/src/motif.c +++ b/src/motif.c @@ -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: CtrlN", "*gameNew.acceleratorText: Ctrl+N", diff --git a/src/x11.c b/src/x11.c index 3b4818e..955b939 100644 --- a/src/x11.c +++ b/src/x11.c @@ -31,10 +31,15 @@ /* 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) -- 2.43.2