X-Git-Url: https://git.draconx.ca/gitweb/rrace.git/blobdiff_plain/5d299c8b50dd94caac916b410af6782d1b20f3fe..991d1e7ca8ae3bee59619812e9f08bde8c17ad02:/src/x11.c diff --git a/src/x11.c b/src/x11.c index 1bd19c9..0a9bef0 100644 --- a/src/x11.c +++ b/src/x11.c @@ -31,10 +31,20 @@ /* Size of the traditional icon pixmap (multiple of 3) */ #define ICON_SIZE 48 -typedef String colour_tab[COLOUR_MAX*(TILE_MAX-1)]; +/* Define to 1 to add highlights and delays for visually debugging redraws */ +#if X11_RENDER_DEBUG +# include +#endif + +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 +69,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) @@ -167,7 +172,7 @@ redraw_goal_tile(struct app_state *state, Display *display, Drawable d, void x11_redraw_goal(struct app_state *state, uint_fast32_t mask) { Display *display = XtDisplay(state->goal); - Window window = XtWindow(state->goal); + Window goal = XtWindow(state->goal); Dimension w, h; int i; @@ -176,8 +181,14 @@ void x11_redraw_goal(struct app_state *state, uint_fast32_t mask) int x = i%3, y = i/3; if (mask & 1) { - redraw_goal_tile(state, display, window, - x, y, w/3, h/3); +#if X11_RENDER_DEBUG + XRectangle r = { w/3*(i%3), w/3*(i/3), w/3, h/3 }; + XSetForeground(display, state->tile_gc, 0xff0000); + XFillRectangles(display, goal, state->tile_gc, &r, 1); + XFlush(display); + usleep(70000); +#endif + redraw_goal_tile(state, display, goal, x, y, w/3, h/3); } /* @@ -247,15 +258,30 @@ void x11_redraw_game(struct app_state *state, uint_fast32_t mask) { Display *display = XtDisplay(state->goal); Window game = XtWindow(state->game); - uint_least32_t *gp = state->board.game; + uint_least32_t buf[3], *gp = state->board.game; Dimension w, h; int i; XtVaGetValues(state->game, XtNwidth, &w, XtNheight, &h, (char *)NULL); w /= 5; h /= 5; + if (state->view_goal_on_game) { + for (i = 0; i < 3; i++) { + buf[i] = state->board.goal[i]; + buf[i] = (gp[i] & ~GOAL_MASK) | (buf[i] << GOAL_SHIFT); + } + gp = buf; + } + for (i = 0; i < 25; i++) { if (mask & 1) { +#if X11_RENDER_DEBUG + XRectangle r = { w*(i%5), w*(i/5), w, h }; + XSetForeground(display, state->tile_gc, 0xff0000); + XFillRectangles(display, game, state->tile_gc, &r, 1); + XFlush(display); + usleep(70000); +#endif redraw_tile(state, display, game, gp[0], gp[1], gp[2], i%5, i/5, w, h);