/*
* X11 GUI for slide puzzle game
- * Copyright © 2022 Nick Bowler
+ * Copyright © 2022-2023 Nick Bowler
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
if (state->board.x > 4) {
/* Game is over */
- state->timer_tick = 0;
+ state->flags &= ~FLAG_TIMER_RUNNING;
return;
}
- app = XtWidgetToApplicationContext(state->game);
ui_timer_update(state, game_elapsed(&state->board));
- state->timer_tick = XtAppAddTimeOut(app, TIMER_UPDATE_MS,
- timer_tick, state);
+ app = XtWidgetToApplicationContext(state->game);
+ XtAppAddTimeOut(app, TIMER_UPDATE_MS, timer_tick, state);
}
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;
+ state->flags &= ~FLAG_VIEW_GOAL_ON_GAME;
+ state->flags |= view_goal ? FLAG_VIEW_GOAL_ON_GAME : 0;
+
x11_redraw_game(state, game_check_goal(&state->board));
}
static void proc_new_game(Widget w, XEvent *e, String *argv, Cardinal *argc)
{
+ XtAppContext app;
+
game_reset(&state.board);
x11_redraw_goal(&state, -1, get_shell(w));
x11_redraw_game(&state, -1);
- if (!state.timer_tick) {
- XtAppContext app = XtWidgetToApplicationContext(w);
- state.timer_tick = XtAppAddTimeOut(app, TIMER_UPDATE_MS,
- timer_tick, &state);
- }
-
game_begin(&state.board);
+ if (!(state.flags & FLAG_TIMER_RUNNING)) {
+ state.flags |= FLAG_TIMER_RUNNING;
+ timer_tick(&state, 0);
+ }
}
static void proc_about(Widget w, XEvent *e, String *argv, Cardinal *argc)
state.board.game[i] = state.board.goal[i] << GOAL_SHIFT;
game_finish(&state.board);
- state.use_ewmh_icons = ewmh_probe_wm_icon(shell);
+ state.flags = ewmh_probe_wm_icon(shell);
XtRealizeWidget(shell);
x11_redraw_goal(&state, 0, shell);
/*
* X11 GUI for slide puzzle game
- * Copyright © 2022 Nick Bowler
+ * Copyright © 2022-2023 Nick Bowler
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "colour.h"
#include "game.h"
+/* If set, _NET_WM_ICON property will be added/updated to toplevel window. */
+#define FLAG_USE_EWMH_ICONS 1u
+
+/* If set, the goal will be displayed over the main play area. */
+#define FLAG_VIEW_GOAL_ON_GAME 2u
+
+/* If set, the Xt timer update process is currently installed. */
+#define FLAG_TIMER_RUNNING 4u
+
struct app_state {
struct board board;
Widget game, goal;
struct xcounter *timer;
- XtIntervalId timer_tick;
Pixmap icon_pixmap;
GC tile_gc;
uint_least32_t render_game_mask;
uint_least16_t render_goal_mask;
uint_least16_t game_tile_sz, goal_tile_sz;
-
- /* If true, the goal will be displayed over the main play area. */
- uint_least8_t view_goal_on_game;
-
- /* Whether to set _NET_WM_ICON property on WMShell */
- uint_least8_t use_ewmh_icons;
+ uint_least16_t flags;
uint_least32_t tile_colour[TILE_MAX-1][3];
};
+/*
+ * Version string boilerplate for slide puzzle game.
+ * Copyright © 2022-2023 Nick Bowler
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
#include <config.h>
#include <stdio.h>
#include <stdarg.h>
return "(C)";
}
-#define VERSION_HEAD_FMT "%s (RRace) %s\nCopyright %s 2022 Nick Bowler"
+#define VERSION_HEAD_FMT "%s (RRace) %s\nCopyright %s 2023 Nick Bowler"
#define VERSION_HEAD_ARGS progname, PACKAGE_VERSION, copysign
void version_print_head(const char *progname, FILE *f)
+/*
+ * Version string boilerplate for slide puzzle game.
+ * Copyright © 2022-2023 Nick Bowler
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
#ifndef RRACE_VERSION_H_
#define RRACE_VERSION_H_
/*
* X11 GUI for slide puzzle game
- * Copyright © 2022 Nick Bowler
+ * Copyright © 2022-2023 Nick Bowler
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
XtVaSetValues(shell, XtNiconPixmap, None, (char *)NULL);
XtVaSetValues(shell, XtNiconPixmap, state->icon_pixmap, (char *)NULL);
- if (state->use_ewmh_icons) {
+ if (state->flags & FLAG_USE_EWMH_ICONS) {
Atom net_wm_icon = XInternAtom(display, "_NET_WM_ICON", FALSE);
Colormap cmap = DefaultColormapOfScreen(XtScreen(shell));
XColor colours[(TILE_MAX-1)*COLOUR_MAX];
unsigned sz = state->game_tile_sz;
int i;
- if (state->view_goal_on_game) {
+ if (state->flags & FLAG_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);