]> git.draconx.ca Git - rrace.git/commitdiff
Add build-time option to help debug X11 rendering.
authorNick Bowler <nbowler@draconx.ca>
Sat, 12 Mar 2022 21:15:24 +0000 (16:15 -0500)
committerNick Bowler <nbowler@draconx.ca>
Sat, 12 Mar 2022 21:18:07 +0000 (16:18 -0500)
Add #define that can be manually set in config.h to enable additional
debug drawing.  This is intended purely for development.  Currently this
causes the system to highlight tiles before they are redrawn, in order
to watch things like expose handling and tile movement.

configure.ac
src/x11.c

index 3ef5c675879f37f535e185daa391910a92875c27..2378c8e8770c94f1330604530b1ab25ceb1794e5 100644 (file)
@@ -44,6 +44,8 @@ AS_IF([test x"$dx_cv_have_motif" = x"yes"],
   [MOTIF_CFLAGS=$dx_cv_motif_cflags MOTIF_LIBS=$dx_cv_motif_libs],
   [AC_DEFINE([X_DISPLAY_MISSING])])
 AM_CONDITIONAL([HAVE_MOTIF], [test x"$dx_cv_have_motif" = x"yes"])
+AH_TEMPLATE([X11_RENDER_DEBUG],
+  [Define to 1 to enable visual aids for debugging X11 rendering.])
 
 AC_CONFIG_TESTDIR([.], [t:.])
 DX_PROG_AUTOTEST
index 955b93945e892e7c586deea2fe9b7ed920de2425..0a9bef0a78684ad47ae791c2fd017cc3a1fc0be6 100644 (file)
--- a/src/x11.c
+++ b/src/x11.c
 /* Size of the traditional icon pixmap (multiple of 3) */
 #define ICON_SIZE 48
 
+/* Define to 1 to add highlights and delays for visually debugging redraws */
+#if X11_RENDER_DEBUG
+#  include <unistd.h>
+#endif
+
 enum {
        NUM_TILE_COLOURS = COLOUR_MAX*(TILE_MAX-1),
        COLOUR_UI_GAMEBG = NUM_TILE_COLOURS,
@@ -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);
                }
 
                /*
@@ -264,6 +275,13 @@ void x11_redraw_game(struct app_state *state, uint_fast32_t mask)
 
        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);