diff options
author | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2010-06-15 18:33:56 +0000 |
---|---|---|
committer | Maurus Cuelenaere <mcuelenaere@gmail.com> | 2010-06-15 18:33:56 +0000 |
commit | a8c35f4d5608d173b77f172d66d1aac9289cb65c (patch) | |
tree | 4468c3d4d1e5e3b1a99f6c0b1d8cdd9eabb946c2 /firmware/target/hosted/sdl | |
parent | c6cac023fd24d83e9564ac39102f434eb1488dcd (diff) | |
download | rockbox-a8c35f4d5608d173b77f172d66d1aac9289cb65c.tar.gz 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
Diffstat (limited to 'firmware/target/hosted/sdl')
-rw-r--r-- | firmware/target/hosted/sdl/button-sdl.c | 66 |
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); | |||
86 | extern bool debug_wps; | 86 | extern bool debug_wps; |
87 | extern bool mapping; | 87 | extern bool mapping; |
88 | 88 | ||
89 | #ifdef HAVE_TOUCHSCREEN | ||
90 | static void touchscreen_event(int x, int y) | ||
91 | { | ||
92 | if(background) { | ||
93 | x -= UI_LCD_POSX; | ||
94 | y -= UI_LCD_POSY; | ||
95 | } | ||
96 | |||
97 | if(x >= 0 && y >= 0 && x < SIM_LCD_WIDTH && y < SIM_LCD_HEIGHT) { | ||
98 | mouse_coords = (x << 16) | y; | ||
99 | button_event(BUTTON_TOUCHSCREEN, true); | ||
100 | if (debug_wps) | ||
101 | printf("Mouse at: (%d, %d)\n", x, y); | ||
102 | } | ||
103 | } | ||
104 | #endif | ||
105 | |||
89 | bool gui_message_loop(void) | 106 | bool gui_message_loop(void) |
90 | { | 107 | { |
91 | SDL_Event event; | 108 | SDL_Event event; |
@@ -100,6 +117,12 @@ bool gui_message_loop(void) | |||
100 | case SDL_KEYUP: | 117 | case SDL_KEYUP: |
101 | button_event(event.key.keysym.sym, event.type == SDL_KEYDOWN); | 118 | button_event(event.key.keysym.sym, event.type == SDL_KEYDOWN); |
102 | break; | 119 | break; |
120 | #ifdef HAVE_TOUCHSCREEN | ||
121 | case SDL_MOUSEMOTION: | ||
122 | if (event.motion.state & SDL_BUTTON(1)) | ||
123 | touchscreen_event(event.motion.x, event.motion.y); | ||
124 | break; | ||
125 | #endif | ||
103 | case SDL_MOUSEBUTTONDOWN: | 126 | case SDL_MOUSEBUTTONDOWN: |
104 | switch ( event.button.button ) { | 127 | switch ( event.button.button ) { |
105 | #ifdef HAVE_SCROLLWHEEL | 128 | #ifdef HAVE_SCROLLWHEEL |
@@ -118,10 +141,16 @@ bool gui_message_loop(void) | |||
118 | } | 141 | } |
119 | if ( background ) { | 142 | if ( background ) { |
120 | xybutton = xy2button( event.button.x, event.button.y ); | 143 | xybutton = xy2button( event.button.x, event.button.y ); |
121 | if( xybutton ) | 144 | if( xybutton ) { |
122 | button_event( xybutton, true ); | 145 | button_event( xybutton, true ); |
146 | break; | ||
147 | } | ||
123 | } | 148 | } |
149 | #ifdef HAVE_TOUCHSCREEN | ||
150 | touchscreen_event(event.button.x, event.button.y); | ||
151 | #endif | ||
124 | break; | 152 | break; |
153 | |||
125 | default: | 154 | default: |
126 | break; | 155 | break; |
127 | } | 156 | } |
@@ -162,9 +191,8 @@ bool gui_message_loop(void) | |||
162 | xybutton = 0; | 191 | xybutton = 0; |
163 | } | 192 | } |
164 | #ifdef HAVE_TOUCHSCREEN | 193 | #ifdef HAVE_TOUCHSCREEN |
165 | else { | 194 | else |
166 | button_event(BUTTON_TOUCHSCREEN, false); | 195 | button_event(BUTTON_TOUCHSCREEN, false); |
167 | } | ||
168 | #endif | 196 | #endif |
169 | break; | 197 | break; |
170 | default: | 198 | default: |
@@ -335,39 +363,7 @@ int button_read_device(void) | |||
335 | return btn; | 363 | return btn; |
336 | } | 364 | } |
337 | 365 | ||
338 | |||
339 | #ifdef HAVE_TOUCHSCREEN | ||
340 | extern bool debug_wps; | ||
341 | void mouse_tick_task(void) | ||
342 | { | ||
343 | static int last_check = 0; | ||
344 | int x,y; | ||
345 | if (TIME_BEFORE(current_tick, last_check+(HZ/10))) | ||
346 | return; | ||
347 | last_check = current_tick; | ||
348 | if (SDL_GetMouseState(&x, &y) & SDL_BUTTON(SDL_BUTTON_LEFT)) | ||
349 | { | ||
350 | if(background) | ||
351 | { | ||
352 | x -= UI_LCD_POSX; | ||
353 | y -= UI_LCD_POSY; | ||
354 | |||
355 | if(x<0 || y<0 || x>SIM_LCD_WIDTH || y>SIM_LCD_HEIGHT) | ||
356 | return; | ||
357 | } | ||
358 | |||
359 | mouse_coords = (x<<16)|y; | ||
360 | button_event(BUTTON_TOUCHSCREEN, true); | ||
361 | if (debug_wps) | ||
362 | printf("Mouse at: (%d, %d)\n", x, y); | ||
363 | } | ||
364 | } | ||
365 | #endif | ||
366 | |||
367 | void button_init_device(void) | 366 | void button_init_device(void) |
368 | { | 367 | { |
369 | SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); | 368 | SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); |
370 | #ifdef HAVE_TOUCHSCREEN | ||
371 | tick_add_task(mouse_tick_task); | ||
372 | #endif | ||
373 | } | 369 | } |