From: Nick Bowler Date: Thu, 10 Mar 2022 02:51:22 +0000 (-0500) Subject: Right clicking on game area now shows the objective. X-Git-Url: http://git.draconx.ca/gitweb/rrace.git/commitdiff_plain/26fb4b6902a32be6e9f504bee44724a0dd4292f7 Right clicking on game area now shows the objective. --- diff --git a/src/game.c b/src/game.c index bdb18a1..f7cc2bb 100644 --- a/src/game.c +++ b/src/game.c @@ -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; diff --git a/src/game.h b/src/game.h index 301dfac..6a02a42 100644 --- a/src/game.h +++ b/src/game.h @@ -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. diff --git a/src/motif.h b/src/motif.h index 406b087..6461f06 100644 --- a/src/motif.h +++ b/src/motif.h @@ -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; diff --git a/src/motif_ui.c b/src/motif_ui.c index 4734d05..eca3e79 100644 --- a/src/motif_ui.c +++ b/src/motif_ui.c @@ -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. */ diff --git a/src/x11.c b/src/x11.c index 1bd19c9..3b4818e 100644 --- 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,