diff options
| author | Franklin Wei <franklin@rockbox.org> | 2024-07-21 18:06:37 -0400 |
|---|---|---|
| committer | Simon Tatham <anakin@pobox.com> | 2024-07-31 23:29:00 +0100 |
| commit | 5de69c22b0ff037f648a740a7c01869e78587df2 (patch) | |
| tree | a4ea1196ffd2942a0937ae5d05a92710c6be6589 | |
| parent | c010ca122f8e5a9b9828a846cbbc0d32de489b20 (diff) | |
| download | puzzles-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.c | 2 | ||||
| -rw-r--r-- | devel.but | 12 | ||||
| -rw-r--r-- | fifteen.c | 2 | ||||
| -rw-r--r-- | filling.c | 2 | ||||
| -rw-r--r-- | keen.c | 2 | ||||
| -rw-r--r-- | loopy.c | 2 | ||||
| -rw-r--r-- | midend.c | 6 | ||||
| -rw-r--r-- | net.c | 2 | ||||
| -rw-r--r-- | netslide.c | 2 | ||||
| -rw-r--r-- | palisade.c | 2 | ||||
| -rw-r--r-- | pattern.c | 2 | ||||
| -rw-r--r-- | pearl.c | 2 | ||||
| -rw-r--r-- | rect.c | 2 | ||||
| -rw-r--r-- | sixteen.c | 2 | ||||
| -rw-r--r-- | solo.c | 2 | ||||
| -rw-r--r-- | tents.c | 2 | ||||
| -rw-r--r-- | towers.c | 2 | ||||
| -rw-r--r-- | unequal.c | 2 | ||||
| -rw-r--r-- | unfinished/group.c | 2 | ||||
| -rw-r--r-- | unruly.c | 2 |
20 files changed, 32 insertions, 22 deletions
@@ -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; @@ -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: @@ -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); @@ -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. */ @@ -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); @@ -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); @@ -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. @@ -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; @@ -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; @@ -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; @@ -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); @@ -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; @@ -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); @@ -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) { @@ -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; @@ -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); @@ -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); @@ -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); @@ -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 || |