]> git.draconx.ca Git - rrace.git/commitdiff
Right clicking on game area now shows the objective.
authorNick Bowler <nbowler@draconx.ca>
Thu, 10 Mar 2022 02:51:22 +0000 (21:51 -0500)
committerNick Bowler <nbowler@draconx.ca>
Thu, 10 Mar 2022 02:51:22 +0000 (21:51 -0500)
src/game.c
src/game.h
src/motif.h
src/motif_ui.c
src/x11.c

index bdb18a1c20f1318f90e75fe348fd96699db36281..f7cc2bb706b519c7b4ed60b4f7ec1b29bcae6f6f 100644 (file)
@@ -191,8 +191,6 @@ int game_do_move(struct board *board, int x, int y)
        return 0;
 }
 
-#define GOAL_MASK 0x739c0
-
 int game_check_goal(struct board *board)
 {
        int i, ret = 1;
index 301dfac022c87681b9be53b88f96bc91dd1b01b0..6a02a428551db68e5cee0c4909901ccc95737c84 100644 (file)
@@ -32,7 +32,9 @@ enum {
        TILE_MAX
 };
 
-enum { GOAL_SHIFT = 6 };
+#define GOAL_SHIFT 6
+#define GOAL_MASK 0x739c0ul
+
 struct board {
        /*
         * Bit planes representing the current game area.
index 406b0871cfce9f9e1b574946f40203d4b524fa48..6461f06e12779525f9a79e6110894aba10024b0d 100644 (file)
@@ -29,6 +29,9 @@ struct app_state {
 
        Widget game, goal;
 
+       /* If true, the goal will be displayed over the main play area. */
+       int view_goal_on_game;
+
        /* Whether to set _NET_WM_ICON property on WMShell */
        int use_ewmh_icons;
 
index 4734d054958cee5a495568fb8a16a2fcb66da4af..eca3e797605d5f42d910439144ac425782a31b4c 100644 (file)
@@ -238,27 +238,45 @@ static void do_input_move(struct app_state *state, int x, int y)
        }
 }
 
+static void set_view_goal(struct app_state *state, int view_goal)
+{
+       state->view_goal_on_game = view_goal;
+       x11_redraw_game(state, GOAL_MASK);
+}
+
 static void game_input(Widget w, void *data, void *cb_data)
 {
        XmDrawingAreaCallbackStruct *cbs = cb_data;
-       XButtonEvent *click = &cbs->event->xbutton;
+       XButtonEvent *b = &cbs->event->xbutton;
        struct app_state *state = data;
        Dimension width, height;
-       unsigned x = -1, y = -1;
 
        switch (cbs->event->type) {
        case ButtonPress:
-               XtVaGetValues(w, XmNwidth, &width,
-                                XmNheight, &height,
-                                (char *)NULL);
-               x = click->x / (width/5);
-               y = click->y / (height/5);
+               switch (b->button) {
+               case Button1:
+                       if (b->state & Button3Mask)
+                               break;
+
+                       XtVaGetValues(w, XmNwidth, &width,
+                                        XmNheight, &height,
+                                        (char *)NULL);
+
+                       do_input_move(state, b->x / (width / 5),
+                                            b->y / (height / 5));
+                       break;
+               case Button3:
+                       set_view_goal(state, 1);
+                       break;
+               }
+               break;
+       case ButtonRelease:
+               switch (b->button) {
+               case Button3:
+                       set_view_goal(state, 0);
+                       break;
+               }
        }
-
-       if (x > 4 || y > 4)
-               return;
-
-       do_input_move(state, x, y);
 }
 
 /* Figure out which tiles intersect a rectangle. */
index 1bd19c97f158ae01efb79a9c8fafc08805c398a7..3b4818e1f67659a9a8edad9b8971e147c8fab6a2 100644 (file)
--- a/src/x11.c
+++ b/src/x11.c
@@ -247,13 +247,21 @@ 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) {
                        redraw_tile(state, display, game,