]> git.draconx.ca Git - rrace.git/blobdiff - src/motif_ui.c
Reimplement xcounter based on pre-rendered pixmpas.
[rrace.git] / src / motif_ui.c
index 3edd3aba3cf4964074b48217fb568aa6773e30f4..6abdbc9d6db5dbe0aca21eab9cb6d28a358056bf 100644 (file)
@@ -116,21 +116,22 @@ void ui_timer_update(struct app_state *state, int_fast32_t ms)
        char buf[100];
 
        if (ms < 0) {
-               xcounter_simple_update(state->timer, "\n");
+               xcounter_update(state->timer, "\n");
                return;
        }
 
-       xcounter_simple_update(state->timer, timer_text(ms, buf));
+       xcounter_update(state->timer, timer_text(ms, buf));
 }
 
 static void configure_mainwin(struct app_state *state, Widget form)
 {
        Widget gamearea = XtNameToWidget(form, &tree_strtab[gameArea]);
        Widget goalarea = XtNameToWidget(form, &tree_strtab[goalArea]);
+       Widget timer = XtNameToWidget(form, &tree_strtab[timeDisplay]);
        XtActionsRec resize_rec;
        char xc_template[100];
 
-       assert(gamearea && goalarea);
+       assert(gamearea && goalarea && timer);
        XtVaSetValues(form, XmNfractionBase, SPLIT_DENOMINATOR, (char *)NULL);
 
        state->game = XtNameToWidget(gamearea, &tree_strtab[gameCanvas]);
@@ -145,15 +146,13 @@ static void configure_mainwin(struct app_state *state, Widget form)
                                XmNtopWidget, gamearea,
                                (char *)NULL);
 
-       state->timer = XtNameToWidget(form, &tree_strtab[timeDisplay]);
-       XtVaSetValues(state->timer, XmNleftAttachment, XmATTACH_WIDGET,
-                                   XmNleftWidget, gamearea,
-                                   XmNtopAttachment, XmATTACH_WIDGET,
-                                   XmNtopWidget, goalarea,
-                                   XmNrightAttachment, XmATTACH_FORM,
-                                   (char *)NULL);
-
-       xcounter_simple_setup(state->timer, timer_text(20000, xc_template));
+       XtVaSetValues(timer, XmNleftAttachment, XmATTACH_WIDGET,
+                            XmNleftWidget, gamearea,
+                            XmNtopAttachment, XmATTACH_WIDGET,
+                            XmNtopWidget, goalarea,
+                            XmNrightAttachment, XmATTACH_FORM,
+                            (char *)NULL);
+       state->timer = xcounter_simple_init(timer, timer_text(0, xc_template));
        ui_timer_update(state, -1);
 
        resize_rec.string = "ResizeGameArea";
@@ -258,62 +257,52 @@ construct_menu(const struct ui_menuitem *root, Widget parent, unsigned i)
 }
 
 /* Figure out which tiles intersect a rectangle. */
-static uint_fast32_t
-expose_mask(int rect_x, int rect_y, int rect_w, int rect_h,
-                                    int tile_w, int tile_h)
+static uint_fast32_t x11_expose_mask(XExposeEvent *e, int tile_w, int tile_h)
 {
-       return board_rect( rect_x/tile_w,
-                          rect_y/tile_h,
-                         (rect_x+rect_w-1)/tile_w,
-                         (rect_y+rect_h-1)/tile_h );
+       return board_rect( e->x/tile_w,
+                          e->y/tile_h,
+                         (e->x+e->width-1)/tile_w,
+                         (e->y+e->height-1)/tile_h );
 }
 
-static void game_resize(Widget w, void *data, void *cb_data)
+static void resize(Widget w, void *data, void *cb_data)
 {
-       x11_queue_render(data, -1, 0);
-}
-
-static void goal_resize(Widget w, void *data, void *cb_data)
-{
-       x11_queue_render(data, 0, -1);
-}
-
-static void game_expose(Widget w, void *data, void *cb_data)
-{
-       XmDrawingAreaCallbackStruct *cbs = cb_data;
-       XExposeEvent *e = &cbs->event->xexpose;
        struct app_state *state = data;
-       uint_least32_t *gp = state->board.game;
-       Dimension width, height;
-       uint_fast32_t mask;
-
-       XtVaGetValues(w, XmNwidth, &width, XmNheight, &height, (char *)NULL);
-       if (!(width /= 5) || !(height /= 5))
-               return;
 
-       /*
-        * Only draw exposed nonempty tiles; exposed areas are filled with the
-        * background automatically and thus exposed empty spaces don't need
-        * to be drawn again.
-        */
-       mask = gp[0] | gp[1] | gp[2];
-       mask &= expose_mask(e->x, e->y, e->width, e->height, width, height);
-       x11_queue_render(state, mask, 0);
+       x11_queue_render(data, -1, 1 << (w == state->game));
 }
 
-static void goal_expose(Widget w, void *data, void *cb_data)
+static void expose(Widget w, void *data, void *cb_data)
 {
        XmDrawingAreaCallbackStruct *cbs = cb_data;
        XExposeEvent *e = &cbs->event->xexpose;
-       Dimension width, height;
+       struct app_state *state = data;
+       Dimension tile_w, tile_h;
        uint_fast32_t mask;
 
-       XtVaGetValues(w, XmNwidth, &width, XmNheight, &height, (char *)NULL);
-       if (!(width /= 3) || !(height /= 3))
-               return;
+       XtVaGetValues(w, XmNwidth, &tile_w, XmNheight, &tile_h, (char *)NULL);
+       if (w == state->game) {
+               uint_least32_t *gp = state->board.game;
+
+               if (!(tile_w /= 5) || !(tile_h /= 5))
+                       return;
+
+               /*
+                * Only draw exposed nonempty tiles; exposed areas are filled
+                * with the background automatically and thus exposed empty
+                * spaces don't need to be drawn again.
+                */
+               mask = gp[0] | gp[1] | gp[2];
+       } else {
+               if (!(tile_w /= 3) || !(tile_h /= 3))
+                       return;
+
+               /* Goal area never has empty tiles. */
+               mask = -1;
+       }
 
-       mask = expose_mask(e->x, e->y, e->width, e->height, width, height);
-       x11_queue_render(data, 0, mask);
+       mask &= x11_expose_mask(e, tile_w, tile_h);
+       x11_queue_render(state, mask, 1<<(w == state->game));
 }
 
 void ui_initialize(struct app_state *state, Widget shell)
@@ -333,14 +322,14 @@ void ui_initialize(struct app_state *state, Widget shell)
        XtVaGetValues(state->game, XmNwidth, &state->game_sz[0],
                                   XmNheight, &state->game_sz[1],
                                   (char *)NULL);
-       XtAddCallback(state->game, XmNresizeCallback, game_resize, state);
-       XtAddCallback(state->game, XmNexposeCallback, game_expose, state);
+       XtAddCallback(state->game, XmNresizeCallback, resize, state);
+       XtAddCallback(state->game, XmNexposeCallback, expose, state);
 
        XtVaGetValues(state->game, XmNwidth, &state->goal_sz[0],
                                   XmNheight, &state->goal_sz[1],
                                   (char *)NULL);
-       XtAddCallback(state->goal, XmNresizeCallback, goal_resize, state);
-       XtAddCallback(state->goal, XmNexposeCallback, goal_expose, state);
+       XtAddCallback(state->goal, XmNresizeCallback, resize, state);
+       XtAddCallback(state->goal, XmNexposeCallback, expose, state);
 }
 
 static void dialog_close(Widget w, void *data, void *cb_data)