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.
.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.
.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>
.El
.Sh AUTHORS
Nick Bowler <nbowler@draconx.ca>
"*game.XmFrame.shadowThickness: 3",
"*game.XmFrame.shadowType: shadow_in",
"*goalArea.leftOffset: 1",
"*game.XmFrame.shadowThickness: 3",
"*game.XmFrame.shadowType: shadow_in",
"*goalArea.leftOffset: 1",
- "*gameCanvas.background: #202020",
"*gameNew.accelerator: Ctrl<Key>N",
"*gameNew.acceleratorText: Ctrl+N",
"*gameNew.accelerator: Ctrl<Key>N",
"*gameNew.acceleratorText: Ctrl+N",
/* Size of the traditional icon pixmap (multiple of 3) */
#define ICON_SIZE 48
/* 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) { \
#define COLOURRES(name, index, def) { \
- (name), (NULL), XtRString, sizeof (String), \
+ (name), (NULL), XtRPixel, sizeof (String), \
offsetof(struct { colour_tab t; }, t[index]), \
XtRString, (def) }
offsetof(struct { colour_tab t; }, t[index]), \
XtRString, (def) }
COLOURRES("colourLight3", 15, COLOUR3_LIGHT),
COLOURRES("colourLight4", 16, COLOUR4_LIGHT),
COLOURRES("colourLight5", 17, COLOUR5_LIGHT),
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)
{
};
static void init_colours(struct app_state *state, Widget shell)
{
- Display *display = XtDisplay(shell);
- Screen *screen = XtScreen(shell);
- Colormap cmap = DefaultColormapOfScreen(screen);
- colour_tab names;
- XtGetApplicationResources(shell, &names, colour_resources,
+ colour_tab colours;
+ XtGetApplicationResources(shell, &colours, colour_resources,
XtNumber(colour_resources), NULL, 0);
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);
unsigned tile = i % (TILE_MAX-1), shade = i / (TILE_MAX-1);
- 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)
}
void x11_initialize(struct app_state *state, Widget shell)