summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFranklin Wei <git@fwei.tk>2017-11-21 21:41:50 -0500
committerFranklin Wei <git@fwei.tk>2017-11-24 20:31:45 -0500
commitf51544a0e545d30d4bd266fca10e1c3d3461794d (patch)
treec07b0097e46e65dafecb80391d5e9c746503cbec
parentab6e40b977a2c8b1ffacf15b1d412046db38c673 (diff)
downloadrockbox-f51544a0e545d30d4bd266fca10e1c3d3461794d.tar.gz
rockbox-f51544a0e545d30d4bd266fca10e1c3d3461794d.tar.bz2
rockbox-f51544a0e545d30d4bd266fca10e1c3d3461794d.zip
puzzles: polish mouse mode
Reduces lag when dragging. Also throws some comments in. Change-Id: Ibd0d95e94200ae6de8258ce8d2e001c931161385
-rw-r--r--apps/plugins/puzzles/rockbox.c53
1 files changed, 28 insertions, 25 deletions
diff --git a/apps/plugins/puzzles/rockbox.c b/apps/plugins/puzzles/rockbox.c
index eec4e71996..1a399c48f9 100644
--- a/apps/plugins/puzzles/rockbox.c
+++ b/apps/plugins/puzzles/rockbox.c
@@ -1585,6 +1585,8 @@ static int process_input(int tmo, bool do_pausemenu)
* following code is needed for mouse mode. */
if(mouse_mode)
{
+ static int last_mousedir = 0, held_count = 0, v = 1;
+
if(button & BTN_UP)
state = CURSOR_UP;
else if(button & BTN_DOWN)
@@ -1599,6 +1601,32 @@ static int process_input(int tmo, bool do_pausemenu)
last_keystate = button;
+ /* move */
+ /* get the direction vector the cursor is moving in. */
+ int new_x = mouse_x, new_y = mouse_y;
+
+ /* in src/misc.c */
+ move_cursor(state, &new_x, &new_y, LCD_WIDTH, LCD_HEIGHT, FALSE);
+
+ int dx = new_x - mouse_x, dy = new_y - mouse_y;
+
+ mouse_x += dx * v;
+ mouse_y += dy * v;
+
+ /* clamp */
+ /* The % operator with negative operands is messy; this is much
+ * simpler. */
+ if(mouse_x < 0)
+ mouse_x = 0;
+ if(mouse_y < 0)
+ mouse_y = 0;
+
+ if(mouse_x >= LCD_WIDTH)
+ mouse_x = LCD_WIDTH - 1;
+ if(mouse_y >= LCD_HEIGHT)
+ mouse_y = LCD_HEIGHT - 1;
+
+ /* clicking/dragging */
/* rclick on hold requires that we fire left-click on a
* release, otherwise it's impossible to distinguish the
* two. */
@@ -1620,8 +1648,6 @@ static int process_input(int tmo, bool do_pausemenu)
send_click(LEFT_DRAG, false);
}
- static int last_mousedir = 0, held_count = 0, v = 0;
-
/* acceleration */
if(state && state == last_mousedir)
{
@@ -1640,29 +1666,6 @@ static int process_input(int tmo, bool do_pausemenu)
held_count = 0;
}
- /* get the direction vector the cursor is moving in. */
- int new_x = mouse_x, new_y = mouse_y;
-
- /* in src/misc.c */
- move_cursor(state, &new_x, &new_y, LCD_WIDTH, LCD_HEIGHT, FALSE);
-
- int dx = new_x - mouse_x, dy = new_y - mouse_y;
-
- mouse_x += dx * v;
- mouse_y += dy * v;
-
- /* The % operator with negative operands is messy; this is much
- * simpler. */
- if(mouse_x < 0)
- mouse_x = 0;
- if(mouse_y < 0)
- mouse_y = 0;
-
- if(mouse_x >= LCD_WIDTH)
- mouse_x = LCD_WIDTH - 1;
- if(mouse_y >= LCD_HEIGHT)
- mouse_y = LCD_HEIGHT - 1;
-
/* no buttons are sent to the midend in mouse mode */
return 0;
}