aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFranklin Wei <franklin@rockbox.org>2024-07-21 18:06:37 -0400
committerSimon Tatham <anakin@pobox.com>2024-07-31 23:29:00 +0100
commit5de69c22b0ff037f648a740a7c01869e78587df2 (patch)
treea4ea1196ffd2942a0937ae5d05a92710c6be6589
parentc010ca122f8e5a9b9828a846cbbc0d32de489b20 (diff)
downloadpuzzles-5de69c22b0ff037f648a740a7c01869e78587df2.zip
puzzles-5de69c22b0ff037f648a740a7c01869e78587df2.tar.gz
puzzles-5de69c22b0ff037f648a740a7c01869e78587df2.tar.bz2
puzzles-5de69c22b0ff037f648a740a7c01869e78587df2.tar.xz
Refactor `button & ~MOD_MASK' as `STRIP_BUTTON_MODIFIERS(button)'.
This refactors all instances of bitwise-ANDs with `~MOD_MASK'. There is a handful of more complex instances I left unchanged (in cube.c, midend.c, and twiddle.c), since those AND with `~MOD_MASK | MOD_NUM_KEYPAD' or similar. I don't think it's worth writing a macro for those cases. Also document this new macro's usage in devel.but.
-rw-r--r--bridges.c2
-rw-r--r--devel.but12
-rw-r--r--fifteen.c2
-rw-r--r--filling.c2
-rw-r--r--keen.c2
-rw-r--r--loopy.c2
-rw-r--r--midend.c6
-rw-r--r--net.c2
-rw-r--r--netslide.c2
-rw-r--r--palisade.c2
-rw-r--r--pattern.c2
-rw-r--r--pearl.c2
-rw-r--r--rect.c2
-rw-r--r--sixteen.c2
-rw-r--r--solo.c2
-rw-r--r--tents.c2
-rw-r--r--towers.c2
-rw-r--r--unequal.c2
-rw-r--r--unfinished/group.c2
-rw-r--r--unruly.c2
20 files changed, 32 insertions, 22 deletions
diff --git a/bridges.c b/bridges.c
index 6de61f1..7e87764 100644
--- a/bridges.c
+++ b/bridges.c
@@ -2391,7 +2391,7 @@ static char *interpret_move(const game_state *state, game_ui *ui,
char buf[80], *ret;
grid_type ggrid = INGRID(state,gx,gy) ? GRID(state,gx,gy) : 0;
bool shift = button & MOD_SHFT, control = button & MOD_CTRL;
- button &= ~MOD_MASK;
+ button = STRIP_BUTTON_MODIFIERS(button);
if (button == LEFT_BUTTON || button == RIGHT_BUTTON) {
if (!INGRID(state, gx, gy)) return MOVE_UNUSED;
diff --git a/devel.but b/devel.but
index 577e74d..71bc60d 100644
--- a/devel.but
+++ b/devel.but
@@ -1161,8 +1161,10 @@ input probably just wants to treat the numeric keypad as numbers).
\dt \cw{MOD_MASK}
\dd This mask is the bitwise OR of all the available modifiers; you
-can bitwise-AND with \cw{~MOD_MASK} to strip all the modifiers off
-any input value.
+can bitwise-AND with \cw{~MOD_MASK} to strip all the modifiers off any
+input value; as this is a common operation, the
+\cw{STRIP_BUTTON_MODIFIERS()} macro can do this for you (see
+\k{utils-strip-button-modifiers}).
\S{backend-execute-move} \cw{execute_move()}
@@ -5322,6 +5324,12 @@ many domino tilings of the same grid.
The returned array is delivered in \c{grid}.
+\S{utils-strip-button-modifiers} \cw{STRIP_BUTTON_MODIFIERS()}
+
+This macro, defined in the main Puzzles header file, strips the
+modifier flags from the key code passed as an argument. It is
+equivalent to a bitwise-AND with \cw{~MOD_MASK}.
+
\C{writing} How to write a new puzzle
This chapter gives a guide to how to actually write a new puzzle:
diff --git a/fifteen.c b/fifteen.c
index 6651d43..a2a9554 100644
--- a/fifteen.c
+++ b/fifteen.c
@@ -755,7 +755,7 @@ static char *interpret_move(const game_state *state, game_ui *ui,
int cy = Y(state, state->gap_pos), ny = cy;
char buf[80];
- button &= ~MOD_MASK;
+ button = STRIP_BUTTON_MODIFIERS(button);
if (button == LEFT_BUTTON) {
nx = FROMCOORD(x);
diff --git a/filling.c b/filling.c
index 80a06dd..ccae7e2 100644
--- a/filling.c
+++ b/filling.c
@@ -1474,7 +1474,7 @@ static char *interpret_move(const game_state *state, game_ui *ui,
assert(ui);
assert(ds);
- button &= ~MOD_MASK;
+ button = STRIP_BUTTON_MODIFIERS(button);
if (button == LEFT_BUTTON || button == LEFT_DRAG) {
/* A left-click anywhere will clear the current selection. */
diff --git a/keen.c b/keen.c
index f9228dc..7e2f71c 100644
--- a/keen.c
+++ b/keen.c
@@ -1742,7 +1742,7 @@ static char *interpret_move(const game_state *state, game_ui *ui,
int tx, ty;
char buf[80];
- button &= ~MOD_MASK;
+ button = STRIP_BUTTON_MODIFIERS(button);
tx = FROMCOORD(x);
ty = FROMCOORD(y);
diff --git a/loopy.c b/loopy.c
index 7d79876..b30dd68 100644
--- a/loopy.c
+++ b/loopy.c
@@ -3048,7 +3048,7 @@ static char *interpret_move(const game_state *state, game_ui *ui,
char button_char = ' ';
enum line_state old_state;
- button &= ~MOD_MASK;
+ button = STRIP_BUTTON_MODIFIERS(button);
/* Convert mouse-click (x,y) to grid coordinates */
x -= BORDER(ds->tilesize);
diff --git a/midend.c b/midend.c
index bcacfc2..30fdf1b 100644
--- a/midend.c
+++ b/midend.c
@@ -1214,7 +1214,8 @@ int midend_process_key(midend *me, int x, int y, int button)
/* Canonicalise CTRL+ASCII. */
if ((button & MOD_CTRL) &&
- (button & ~MOD_MASK) >= 0x40 && (button & ~MOD_MASK) < 0x80)
+ STRIP_BUTTON_MODIFIERS(button) >= 0x40 &&
+ STRIP_BUTTON_MODIFIERS(button) < 0x80)
button = button & (0x1f | (MOD_MASK & ~MOD_CTRL));
/* Special handling to make CTRL+SHFT+Z into REDO. */
if ((button & (~MOD_MASK | MOD_SHFT)) == (MOD_SHFT | '\x1A'))
@@ -1230,7 +1231,8 @@ int midend_process_key(midend *me, int x, int y, int button)
button &= ~(MOD_CTRL | MOD_SHFT);
}
/* interpret_move() expects NUM_KEYPAD only on numbers. */
- if ((button & ~MOD_MASK) < '0' || (button & ~MOD_MASK) > '9')
+ if (STRIP_BUTTON_MODIFIERS(button) < '0' ||
+ STRIP_BUTTON_MODIFIERS(button) > '9')
button &= ~MOD_NUM_KEYPAD;
/*
* Translate keyboard presses to cursor selection.
diff --git a/net.c b/net.c
index 0268033..3200253 100644
--- a/net.c
+++ b/net.c
@@ -2148,7 +2148,7 @@ static char *interpret_move(const game_state *state, game_ui *ui,
MOVE_ORIGIN, MOVE_SOURCE, MOVE_ORIGIN_AND_SOURCE, MOVE_CURSOR
} action;
- button &= ~MOD_MASK;
+ button = STRIP_BUTTON_MODIFIERS(button);
nullret = NULL;
action = NONE;
diff --git a/netslide.c b/netslide.c
index 33447ae..e3d03c4 100644
--- a/netslide.c
+++ b/netslide.c
@@ -1058,7 +1058,7 @@ static char *interpret_move(const game_state *state, game_ui *ui,
int dx, dy;
char buf[80];
- button &= ~MOD_MASK;
+ button = STRIP_BUTTON_MODIFIERS(button);
if (IS_CURSOR_MOVE(button)) {
int cpos, diff = 0;
diff --git a/palisade.c b/palisade.c
index 2f3545c..811204b 100644
--- a/palisade.c
+++ b/palisade.c
@@ -912,7 +912,7 @@ static char *interpret_move(const game_state *state, game_ui *ui,
int w = state->shared->params.w, h = state->shared->params.h;
bool control = button & MOD_CTRL, shift = button & MOD_SHFT;
- button &= ~MOD_MASK;
+ button = STRIP_BUTTON_MODIFIERS(button);
if (button == LEFT_BUTTON || button == RIGHT_BUTTON) {
int gx = FROMCOORD(x), gy = FROMCOORD(y), possible = BORDER_MASK;
diff --git a/pattern.c b/pattern.c
index de0fb97..d38cada 100644
--- a/pattern.c
+++ b/pattern.c
@@ -1292,7 +1292,7 @@ static char *interpret_move(const game_state *state, game_ui *ui,
int x, int y, int button)
{
bool control = button & MOD_CTRL, shift = button & MOD_SHFT;
- button &= ~MOD_MASK;
+ button = STRIP_BUTTON_MODIFIERS(button);
x = FROMCOORD(state->common->w, x);
y = FROMCOORD(state->common->h, y);
diff --git a/pearl.c b/pearl.c
index 51897b0..9599317 100644
--- a/pearl.c
+++ b/pearl.c
@@ -2167,7 +2167,7 @@ static char *interpret_move(const game_state *state, game_ui *ui,
char tmpbuf[80];
bool shift = button & MOD_SHFT, control = button & MOD_CTRL;
- button &= ~MOD_MASK;
+ button = STRIP_BUTTON_MODIFIERS(button);
if (IS_MOUSE_DOWN(button)) {
ui->cursor_active = false;
diff --git a/rect.c b/rect.c
index 89f3a02..c3ee1ab 100644
--- a/rect.c
+++ b/rect.c
@@ -2394,7 +2394,7 @@ static char *interpret_move(const game_state *from, game_ui *ui,
bool startdrag = false, enddrag = false, active = false, erasing = false;
char buf[80], *ret;
- button &= ~MOD_MASK;
+ button = STRIP_BUTTON_MODIFIERS(button);
coord_round(FROMCOORD((float)x), FROMCOORD((float)y), &xc, &yc);
diff --git a/sixteen.c b/sixteen.c
index f8763ff..fef2e5f 100644
--- a/sixteen.c
+++ b/sixteen.c
@@ -621,7 +621,7 @@ static char *interpret_move(const game_state *state, game_ui *ui,
bool shift = button & MOD_SHFT, control = button & MOD_CTRL;
int pad = button & MOD_NUM_KEYPAD;
- button &= ~MOD_MASK;
+ button = STRIP_BUTTON_MODIFIERS(button);
if (IS_CURSOR_MOVE(button) || pad) {
if (!ui->cur_visible) {
diff --git a/solo.c b/solo.c
index fb851ca..2445501 100644
--- a/solo.c
+++ b/solo.c
@@ -4653,7 +4653,7 @@ static char *interpret_move(const game_state *state, game_ui *ui,
int tx, ty;
char buf[80];
- button &= ~MOD_MASK;
+ button = STRIP_BUTTON_MODIFIERS(button);
tx = (x + TILE_SIZE - BORDER) / TILE_SIZE - 1;
ty = (y + TILE_SIZE - BORDER) / TILE_SIZE - 1;
diff --git a/tents.c b/tents.c
index 52fedda..0d40959 100644
--- a/tents.c
+++ b/tents.c
@@ -1576,7 +1576,7 @@ static char *interpret_move(const game_state *state, game_ui *ui,
char tmpbuf[80];
bool shift = button & MOD_SHFT, control = button & MOD_CTRL;
- button &= ~MOD_MASK;
+ button = STRIP_BUTTON_MODIFIERS(button);
if (button == LEFT_BUTTON || button == RIGHT_BUTTON) {
x = FROMCOORD(x);
diff --git a/towers.c b/towers.c
index c26e530..4dd9484 100644
--- a/towers.c
+++ b/towers.c
@@ -1424,7 +1424,7 @@ static char *interpret_move(const game_state *state, game_ui *ui,
int tx, ty;
char buf[80];
- button &= ~MOD_MASK;
+ button = STRIP_BUTTON_MODIFIERS(button);
tx = FROMCOORD(x);
ty = FROMCOORD(y);
diff --git a/unequal.c b/unequal.c
index c2f7311..ab32e4a 100644
--- a/unequal.c
+++ b/unequal.c
@@ -1530,7 +1530,7 @@ static char *interpret_move(const game_state *state, game_ui *ui,
char buf[80];
bool shift_or_control = button & (MOD_SHFT | MOD_CTRL);
- button &= ~MOD_MASK;
+ button = STRIP_BUTTON_MODIFIERS(button);
if (x >= 0 && x < ds->order && y >= 0 && y < ds->order && IS_MOUSE_DOWN(button)) {
if (oy - COORD(y) > TILE_SIZE && ox - COORD(x) > TILE_SIZE)
diff --git a/unfinished/group.c b/unfinished/group.c
index 943767f..faffa89 100644
--- a/unfinished/group.c
+++ b/unfinished/group.c
@@ -1543,7 +1543,7 @@ static char *interpret_move(const game_state *state, game_ui *ui,
int tx, ty;
char buf[80];
- button &= ~MOD_MASK;
+ button = STRIP_BUTTON_MODIFIERS(button);
tx = FROMCOORD(x);
ty = FROMCOORD(y);
diff --git a/unruly.c b/unruly.c
index c30e450..01685b7 100644
--- a/unruly.c
+++ b/unruly.c
@@ -1614,7 +1614,7 @@ static char *interpret_move(const game_state *state, game_ui *ui,
char *nullret = MOVE_NO_EFFECT;
- button &= ~MOD_MASK;
+ button = STRIP_BUTTON_MODIFIERS(button);
/* Mouse click */
if (button == LEFT_BUTTON || button == RIGHT_BUTTON ||