diff options
Diffstat (limited to 'uisimulator/sdl/uisdl.c')
-rw-r--r-- | uisimulator/sdl/uisdl.c | 108 |
1 files changed, 93 insertions, 15 deletions
diff --git a/uisimulator/sdl/uisdl.c b/uisimulator/sdl/uisdl.c index 3ab098e5ba..8cf4b42ba0 100644 --- a/uisimulator/sdl/uisdl.c +++ b/uisimulator/sdl/uisdl.c | |||
@@ -40,10 +40,12 @@ | |||
40 | #include "thread-sdl.h" | 40 | #include "thread-sdl.h" |
41 | #include "SDL_mutex.h" | 41 | #include "SDL_mutex.h" |
42 | #include "SDL_thread.h" | 42 | #include "SDL_thread.h" |
43 | #include "math.h" | ||
44 | |||
43 | 45 | ||
44 | /* extern functions */ | 46 | /* extern functions */ |
45 | extern void new_key(int key); | 47 | extern void new_key(int key); |
46 | 48 | extern int xy2button( int x, int y); | |
47 | void button_event(int key, bool pressed); | 49 | void button_event(int key, bool pressed); |
48 | 50 | ||
49 | SDL_Surface *gui_surface; | 51 | SDL_Surface *gui_surface; |
@@ -51,6 +53,8 @@ bool background = true; /* use backgrounds by default */ | |||
51 | #ifdef HAVE_REMOTE_LCD | 53 | #ifdef HAVE_REMOTE_LCD |
52 | static bool showremote = true; /* include remote by default */ | 54 | static bool showremote = true; /* include remote by default */ |
53 | #endif | 55 | #endif |
56 | bool mapping = false; | ||
57 | bool debug_buttons = false; | ||
54 | 58 | ||
55 | bool lcd_display_redraw = true; /* Used for player simulator */ | 59 | bool lcd_display_redraw = true; /* Used for player simulator */ |
56 | char having_new_lcd = true; /* Used for player simulator */ | 60 | char having_new_lcd = true; /* Used for player simulator */ |
@@ -62,39 +66,102 @@ bool debug_audio = false; | |||
62 | bool debug_wps = false; | 66 | bool debug_wps = false; |
63 | int wps_verbose_level = 3; | 67 | int wps_verbose_level = 3; |
64 | 68 | ||
69 | |||
70 | void irq_button_event(int key, bool pressed) { | ||
71 | sim_enter_irq_handler(); | ||
72 | button_event( key, pressed ); | ||
73 | sim_exit_irq_handler(); | ||
74 | } | ||
75 | |||
76 | int sqr( int a ) { | ||
77 | return a*a; | ||
78 | } | ||
79 | |||
65 | void gui_message_loop(void) | 80 | void gui_message_loop(void) |
66 | { | 81 | { |
67 | SDL_Event event; | 82 | SDL_Event event; |
68 | bool done = false; | 83 | bool done = false; |
84 | static int x,y,xybutton = 0; | ||
69 | 85 | ||
70 | while(!done && SDL_WaitEvent(&event)) | 86 | while(!done && SDL_WaitEvent(&event)) |
71 | { | 87 | { |
72 | switch(event.type) | 88 | switch(event.type) |
73 | { | 89 | { |
74 | case SDL_KEYDOWN: | 90 | case SDL_KEYDOWN: |
75 | sim_enter_irq_handler(); | 91 | irq_button_event(event.key.keysym.sym, true); |
76 | button_event(event.key.keysym.sym, true); | ||
77 | sim_exit_irq_handler(); | ||
78 | break; | 92 | break; |
79 | case SDL_KEYUP: | 93 | case SDL_KEYUP: |
80 | sim_enter_irq_handler(); | 94 | irq_button_event(event.key.keysym.sym, false); |
81 | button_event(event.key.keysym.sym, false); | ||
82 | sim_exit_irq_handler(); | ||
83 | break; | ||
84 | #ifndef HAVE_TOUCHSCREEN | ||
85 | case SDL_MOUSEBUTTONDOWN: | 95 | case SDL_MOUSEBUTTONDOWN: |
96 | switch ( event.button.button ) { | ||
97 | #ifdef HAVE_SCROLLWHEEL | ||
98 | case SDL_BUTTON_WHEELUP: | ||
99 | irq_button_event( SDLK_UP, true ); | ||
100 | break; | ||
101 | case SDL_BUTTON_WHEELDOWN: | ||
102 | irq_button_event( SDLK_DOWN, true ); | ||
103 | break; | ||
104 | #endif | ||
105 | case SDL_BUTTON_LEFT: | ||
106 | case SDL_BUTTON_MIDDLE: | ||
107 | if ( mapping && background ) { | ||
108 | x = event.button.x; | ||
109 | y = event.button.y; | ||
110 | } | ||
111 | if ( background ) { | ||
112 | xybutton = xy2button( event.button.x, event.button.y ); | ||
113 | if( xybutton ) | ||
114 | irq_button_event( xybutton, true ); | ||
115 | } | ||
116 | break; | ||
117 | default: | ||
118 | break; | ||
119 | } | ||
120 | |||
86 | if (debug_wps && event.button.button == 1) | 121 | if (debug_wps && event.button.button == 1) |
87 | { | 122 | { |
88 | printf("Mouse at: (%d, %d)\n", event.button.x, event.button.y); | 123 | if ( background ) |
124 | #ifdef HAVE_REMOTE | ||
125 | if ( event.button.y < UI_REMOTE_POSY ) /* Main Screen */ | ||
126 | printf("Mouse at: (%d, %d)\n", event.button.x - UI_LCD_POSX -1 , event.button.y - UI_LCD_POSY - 1 ); | ||
127 | else | ||
128 | printf("Mouse at: (%d, %d)\n", event.button.x - UI_REMOTE_POSX -1 , event.button.y - UI_REMOTE_POSY - 1 ); | ||
129 | #else | ||
130 | printf("Mouse at: (%d, %d)\n", event.button.x - UI_LCD_POSX -1 , event.button.y - UI_LCD_POSY - 1 ); | ||
131 | #endif | ||
132 | else | ||
133 | if ( event.button.y/display_zoom < LCD_HEIGHT ) /* Main Screen */ | ||
134 | printf("Mouse at: (%d, %d)\n", event.button.x/display_zoom, event.button.y/display_zoom ); | ||
135 | #ifdef HAVE_REMOTE | ||
136 | else | ||
137 | printf("Mouse at: (%d, %d)\n", event.button.x/display_zoom, event.button.y/display_zoom - LCD_HEIGHT ); | ||
138 | #endif | ||
89 | } | 139 | } |
90 | break; | 140 | break; |
91 | #else | ||
92 | case SDL_MOUSEBUTTONUP: | 141 | case SDL_MOUSEBUTTONUP: |
93 | sim_enter_irq_handler(); | 142 | switch ( event.button.button ) { |
94 | button_event(BUTTON_TOUCHSCREEN, false); | 143 | /* The scrollwheel button up events are ignored as they are queued immediately */ |
95 | sim_exit_irq_handler(); | 144 | case SDL_BUTTON_LEFT: |
96 | break; | 145 | case SDL_BUTTON_MIDDLE: |
146 | if ( mapping && background ) { | ||
147 | printf(" { SDLK_, %d, %d, %d, \"\" },\n", x, y, (int)sqrt( sqr(x-(int)event.button.x) + sqr(y-(int)event.button.y)) ); | ||
148 | } | ||
149 | if ( background && xybutton ) { | ||
150 | irq_button_event( xybutton, false ); | ||
151 | xybutton = 0; | ||
152 | } | ||
153 | #ifdef HAVE_TOUCHSCREEN | ||
154 | else { | ||
155 | irq_button_event(BUTTON_TOUCHSCREEN, false); | ||
156 | } | ||
97 | #endif | 157 | #endif |
158 | break; | ||
159 | default: | ||
160 | break; | ||
161 | } | ||
162 | break; | ||
163 | |||
164 | |||
98 | case SDL_QUIT: | 165 | case SDL_QUIT: |
99 | done = true; | 166 | done = true; |
100 | break; | 167 | break; |
@@ -244,6 +311,16 @@ int main(int argc, char *argv[]) | |||
244 | printf("Root directory: %s\n", sim_root_dir); | 311 | printf("Root directory: %s\n", sim_root_dir); |
245 | } | 312 | } |
246 | } | 313 | } |
314 | else if (!strcmp("--mapping", argv[x])) | ||
315 | { | ||
316 | mapping = true; | ||
317 | printf("Printing click coords with drag radii.\n"); | ||
318 | } | ||
319 | else if (!strcmp("--debugbuttons", argv[x])) | ||
320 | { | ||
321 | debug_buttons = true; | ||
322 | printf("Printing background button clicks.\n"); | ||
323 | } | ||
247 | else | 324 | else |
248 | { | 325 | { |
249 | printf("rockboxui\n"); | 326 | printf("rockboxui\n"); |
@@ -258,6 +335,7 @@ int main(int argc, char *argv[]) | |||
258 | printf(" --zoom [VAL]\t Window zoom (will disable backgrounds)\n"); | 335 | printf(" --zoom [VAL]\t Window zoom (will disable backgrounds)\n"); |
259 | printf(" --alarm \t Simulate a wake-up on alarm\n"); | 336 | printf(" --alarm \t Simulate a wake-up on alarm\n"); |
260 | printf(" --root [DIR]\t Set root directory\n"); | 337 | printf(" --root [DIR]\t Set root directory\n"); |
338 | printf(" --mapping \t Output coordinates and radius for mapping backgrounds\n"); | ||
261 | exit(0); | 339 | exit(0); |
262 | } | 340 | } |
263 | } | 341 | } |