summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaurus Cuelenaere <mcuelenaere@gmail.com>2010-06-15 18:33:56 +0000
committerMaurus Cuelenaere <mcuelenaere@gmail.com>2010-06-15 18:33:56 +0000
commita8c35f4d5608d173b77f172d66d1aac9289cb65c (patch)
tree4468c3d4d1e5e3b1a99f6c0b1d8cdd9eabb946c2
parentc6cac023fd24d83e9564ac39102f434eb1488dcd (diff)
downloadrockbox-a8c35f4d5608d173b77f172d66d1aac9289cb65c.tar.gz
rockbox-a8c35f4d5608d173b77f172d66d1aac9289cb65c.tar.bz2
rockbox-a8c35f4d5608d173b77f172d66d1aac9289cb65c.zip
SDL target: remove mouse polling and replace it with an event-based mechanism, this makes touchscreen on the sim much smoother
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26860 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--firmware/target/hosted/sdl/button-sdl.c66
1 files changed, 31 insertions, 35 deletions
diff --git a/firmware/target/hosted/sdl/button-sdl.c b/firmware/target/hosted/sdl/button-sdl.c
index dd55373ef3..8b236c19f1 100644
--- a/firmware/target/hosted/sdl/button-sdl.c
+++ b/firmware/target/hosted/sdl/button-sdl.c
@@ -86,6 +86,23 @@ static void button_event(int key, bool pressed);
extern bool debug_wps;
extern bool mapping;
+#ifdef HAVE_TOUCHSCREEN
+static void touchscreen_event(int x, int y)
+{
+ if(background) {
+ x -= UI_LCD_POSX;
+ y -= UI_LCD_POSY;
+ }
+
+ if(x >= 0 && y >= 0 && x < SIM_LCD_WIDTH && y < SIM_LCD_HEIGHT) {
+ mouse_coords = (x << 16) | y;
+ button_event(BUTTON_TOUCHSCREEN, true);
+ if (debug_wps)
+ printf("Mouse at: (%d, %d)\n", x, y);
+ }
+}
+#endif
+
bool gui_message_loop(void)
{
SDL_Event event;
@@ -100,6 +117,12 @@ bool gui_message_loop(void)
case SDL_KEYUP:
button_event(event.key.keysym.sym, event.type == SDL_KEYDOWN);
break;
+#ifdef HAVE_TOUCHSCREEN
+ case SDL_MOUSEMOTION:
+ if (event.motion.state & SDL_BUTTON(1))
+ touchscreen_event(event.motion.x, event.motion.y);
+ break;
+#endif
case SDL_MOUSEBUTTONDOWN:
switch ( event.button.button ) {
#ifdef HAVE_SCROLLWHEEL
@@ -118,10 +141,16 @@ bool gui_message_loop(void)
}
if ( background ) {
xybutton = xy2button( event.button.x, event.button.y );
- if( xybutton )
+ if( xybutton ) {
button_event( xybutton, true );
+ break;
+ }
}
+#ifdef HAVE_TOUCHSCREEN
+ touchscreen_event(event.button.x, event.button.y);
+#endif
break;
+
default:
break;
}
@@ -162,9 +191,8 @@ bool gui_message_loop(void)
xybutton = 0;
}
#ifdef HAVE_TOUCHSCREEN
- else {
+ else
button_event(BUTTON_TOUCHSCREEN, false);
- }
#endif
break;
default:
@@ -335,39 +363,7 @@ int button_read_device(void)
return btn;
}
-
-#ifdef HAVE_TOUCHSCREEN
-extern bool debug_wps;
-void mouse_tick_task(void)
-{
- static int last_check = 0;
- int x,y;
- if (TIME_BEFORE(current_tick, last_check+(HZ/10)))
- return;
- last_check = current_tick;
- if (SDL_GetMouseState(&x, &y) & SDL_BUTTON(SDL_BUTTON_LEFT))
- {
- if(background)
- {
- x -= UI_LCD_POSX;
- y -= UI_LCD_POSY;
-
- if(x<0 || y<0 || x>SIM_LCD_WIDTH || y>SIM_LCD_HEIGHT)
- return;
- }
-
- mouse_coords = (x<<16)|y;
- button_event(BUTTON_TOUCHSCREEN, true);
- if (debug_wps)
- printf("Mouse at: (%d, %d)\n", x, y);
- }
-}
-#endif
-
void button_init_device(void)
{
SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
-#ifdef HAVE_TOUCHSCREEN
- tick_add_task(mouse_tick_task);
-#endif
}