aboutsummaryrefslogtreecommitdiff
path: root/cube.c
diff options
context:
space:
mode:
authorFranklin Wei <franklin@rockbox.org>2020-07-06 22:06:30 -0400
committerSimon Tatham <anakin@pobox.com>2020-12-07 19:40:06 +0000
commit78bc9ea7f79f379634f822d5f95242900f5716b9 (patch)
tree20dd3aa4e3ea4025fb72953c9d9950792ada7023 /cube.c
parent9aa7b7cdfb2bcd200f45941a58d6ae698882a2d4 (diff)
downloadpuzzles-78bc9ea7f79f379634f822d5f95242900f5716b9.zip
puzzles-78bc9ea7f79f379634f822d5f95242900f5716b9.tar.gz
puzzles-78bc9ea7f79f379634f822d5f95242900f5716b9.tar.bz2
puzzles-78bc9ea7f79f379634f822d5f95242900f5716b9.tar.xz
Add method for frontends to query the backend's cursor location.
The Rockbox frontend allows games to be displayed in a "zoomed-in" state targets with small displays. Currently we use a modal interface -- a "viewing" mode in which the cursor keys are used to pan around the rendered bitmap; and an "interaction" mode that actually sends keys to the game. This commit adds a midend_get_cursor_location() function to allow the frontend to retrieve the backend's cursor location or other "region of interest" -- such as the player location in Cube or Inertia. With this information, the Rockbox frontend can now intelligently follow the cursor around in the zoomed-in state, eliminating the need for a modal interface.
Diffstat (limited to 'cube.c')
-rw-r--r--cube.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/cube.c b/cube.c
index bda7623..8c8c46f 100644
--- a/cube.c
+++ b/cube.c
@@ -1535,6 +1535,27 @@ static void game_free_drawstate(drawing *dr, game_drawstate *ds)
sfree(ds);
}
+static void game_get_cursor_location(const game_ui *ui,
+ const game_drawstate *ds,
+ const game_state *state,
+ const game_params *params,
+ int *x, int *y, int *w, int *h)
+{
+ struct bbox bb;
+
+ bb.l = 2.0F * (params->d1 + params->d2);
+ bb.r = -2.0F * (params->d1 + params->d2);
+ bb.u = 2.0F * (params->d1 + params->d2);
+ bb.d = -2.0F * (params->d1 + params->d2);
+
+ find_bbox_callback(&bb, state->grid->squares + state->current);
+
+ *x = ((int)(bb.l * GRID_SCALE) + ds->ox);
+ *y = ((int)(bb.u * GRID_SCALE) + ds->oy);
+ *w = (bb.r - bb.l) * GRID_SCALE;
+ *h = (bb.d - bb.u) * GRID_SCALE;
+}
+
static void game_redraw(drawing *dr, game_drawstate *ds,
const game_state *oldstate, const game_state *state,
int dir, const game_ui *ui,
@@ -1762,6 +1783,7 @@ const struct game thegame = {
game_redraw,
game_anim_length,
game_flash_length,
+ game_get_cursor_location,
game_status,
false, false, game_print_size, game_print,
true, /* wants_statusbar */