summaryrefslogtreecommitdiff
path: root/uisimulator/sdl/uisdl.c
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2010-05-15 21:02:47 +0000
committerThomas Martitz <kugel@rockbox.org>2010-05-15 21:02:47 +0000
commit3d0cee8abbaf764958743e8a7851eee94e60a913 (patch)
treea96b1ec825003a71643a7da4707c300f64824f82 /uisimulator/sdl/uisdl.c
parentdcf442e61f21fb2aef5ce7de0547f733557b156e (diff)
downloadrockbox-3d0cee8abbaf764958743e8a7851eee94e60a913.tar.gz
rockbox-3d0cee8abbaf764958743e8a7851eee94e60a913.zip
- Move uisimulator/sdl/*.[ch] into the target tree, under firmware/target/hosted/sdl, uisdl.c is split up across button-sdl.c and system-sdl.c.
- Refactor the program startup. main() is now in main.c like on target, and the implicit application thread will now act as our main thread (previously a separate one was created for this in thread initialization). This is part of Rockbox as an application and is the first step to make an application port from the uisimulator. In a further step the sim bits from the sdl build will be separated out. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26065 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'uisimulator/sdl/uisdl.c')
-rw-r--r--uisimulator/sdl/uisdl.c368
1 files changed, 0 insertions, 368 deletions
diff --git a/uisimulator/sdl/uisdl.c b/uisimulator/sdl/uisdl.c
deleted file mode 100644
index 8cf4b42ba0..0000000000
--- a/uisimulator/sdl/uisdl.c
+++ /dev/null
@@ -1,368 +0,0 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2006 by Daniel Everton <dan@iocaine.org>
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21
22#include <stdlib.h>
23#include <string.h>
24#include <setjmp.h>
25#include "autoconf.h"
26#include "button.h"
27#include "system-sdl.h"
28#include "thread.h"
29#include "kernel.h"
30#include "uisdl.h"
31#include "lcd-sdl.h"
32#ifdef HAVE_LCD_BITMAP
33#include "lcd-bitmap.h"
34#elif defined(HAVE_LCD_CHARCELLS)
35#include "lcd-charcells.h"
36#endif
37#ifdef HAVE_REMOTE_LCD
38#include "lcd-remote-bitmap.h"
39#endif
40#include "thread-sdl.h"
41#include "SDL_mutex.h"
42#include "SDL_thread.h"
43#include "math.h"
44
45
46/* extern functions */
47extern void new_key(int key);
48extern int xy2button( int x, int y);
49void button_event(int key, bool pressed);
50
51SDL_Surface *gui_surface;
52bool background = true; /* use backgrounds by default */
53#ifdef HAVE_REMOTE_LCD
54static bool showremote = true; /* include remote by default */
55#endif
56bool mapping = false;
57bool debug_buttons = false;
58
59bool lcd_display_redraw = true; /* Used for player simulator */
60char having_new_lcd = true; /* Used for player simulator */
61bool sim_alarm_wakeup = false;
62const char *sim_root_dir = NULL;
63
64bool debug_audio = false;
65
66bool debug_wps = false;
67int wps_verbose_level = 3;
68
69
70void irq_button_event(int key, bool pressed) {
71 sim_enter_irq_handler();
72 button_event( key, pressed );
73 sim_exit_irq_handler();
74}
75
76int sqr( int a ) {
77 return a*a;
78}
79
80void gui_message_loop(void)
81{
82 SDL_Event event;
83 bool done = false;
84 static int x,y,xybutton = 0;
85
86 while(!done && SDL_WaitEvent(&event))
87 {
88 switch(event.type)
89 {
90 case SDL_KEYDOWN:
91 irq_button_event(event.key.keysym.sym, true);
92 break;
93 case SDL_KEYUP:
94 irq_button_event(event.key.keysym.sym, false);
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
121 if (debug_wps && event.button.button == 1)
122 {
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
139 }
140 break;
141 case SDL_MOUSEBUTTONUP:
142 switch ( event.button.button ) {
143 /* The scrollwheel button up events are ignored as they are queued immediately */
144 case SDL_BUTTON_LEFT:
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 }
157#endif
158 break;
159 default:
160 break;
161 }
162 break;
163
164
165 case SDL_QUIT:
166 done = true;
167 break;
168 default:
169 /*printf("Unhandled event\n"); */
170 break;
171 }
172 }
173}
174
175bool gui_startup(void)
176{
177 SDL_Surface *picture_surface;
178 int width, height;
179
180 if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER)) {
181 fprintf(stderr, "fatal: %s\n", SDL_GetError());
182 return false;
183 }
184
185 atexit(SDL_Quit);
186
187 /* Try and load the background image. If it fails go without */
188 if (background) {
189 picture_surface = SDL_LoadBMP("UI256.bmp");
190 if (picture_surface == NULL) {
191 background = false;
192 fprintf(stderr, "warn: %s\n", SDL_GetError());
193 }
194 }
195
196 /* Set things up */
197 if (background)
198 {
199 width = UI_WIDTH;
200 height = UI_HEIGHT;
201 }
202 else
203 {
204#ifdef HAVE_REMOTE_LCD
205 if (showremote)
206 {
207 width = SIM_LCD_WIDTH > SIM_REMOTE_WIDTH ? SIM_LCD_WIDTH : SIM_REMOTE_WIDTH;
208 height = SIM_LCD_HEIGHT + SIM_REMOTE_HEIGHT;
209 }
210 else
211#endif
212 {
213 width = SIM_LCD_WIDTH;
214 height = SIM_LCD_HEIGHT;
215 }
216 }
217
218
219 if ((gui_surface = SDL_SetVideoMode(width * display_zoom, height * display_zoom, 24, SDL_HWSURFACE|SDL_DOUBLEBUF)) == NULL) {
220 fprintf(stderr, "fatal: %s\n", SDL_GetError());
221 return false;
222 }
223
224 SDL_WM_SetCaption(UI_TITLE, NULL);
225
226 sim_lcd_init();
227#ifdef HAVE_REMOTE_LCD
228 if (showremote)
229 sim_lcd_remote_init();
230#endif
231
232 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
233
234 if (background && picture_surface != NULL) {
235 SDL_BlitSurface(picture_surface, NULL, gui_surface, NULL);
236 SDL_UpdateRect(gui_surface, 0, 0, 0, 0);
237 }
238
239 return true;
240}
241
242bool gui_shutdown(void)
243{
244 /* Order here is relevent to prevent deadlocks and use of destroyed
245 sync primitives by kernel threads */
246 thread_sdl_shutdown();
247 sim_kernel_shutdown();
248 return true;
249}
250
251#if defined(WIN32) && defined(main)
252/* Don't use SDL_main on windows -> no more stdio redirection */
253#undef main
254#endif
255
256int main(int argc, char *argv[])
257{
258 if (argc >= 1)
259 {
260 int x;
261 for (x = 1; x < argc; x++)
262 {
263 if (!strcmp("--debugaudio", argv[x]))
264 {
265 debug_audio = true;
266 printf("Writing debug audio file.\n");
267 }
268 else if (!strcmp("--debugwps", argv[x]))
269 {
270 debug_wps = true;
271 printf("WPS debug mode enabled.\n");
272 }
273 else if (!strcmp("--nobackground", argv[x]))
274 {
275 background = false;
276 printf("Disabling background image.\n");
277 }
278#ifdef HAVE_REMOTE_LCD
279 else if (!strcmp("--noremote", argv[x]))
280 {
281 showremote = false;
282 background = false;
283 printf("Disabling remote image.\n");
284 }
285#endif
286 else if (!strcmp("--old_lcd", argv[x]))
287 {
288 having_new_lcd = false;
289 printf("Using old LCD layout.\n");
290 }
291 else if (!strcmp("--zoom", argv[x]))
292 {
293 x++;
294 if(x < argc)
295 display_zoom=atoi(argv[x]);
296 else
297 display_zoom = 2;
298 printf("Window zoom is %d\n", display_zoom);
299 }
300 else if (!strcmp("--alarm", argv[x]))
301 {
302 sim_alarm_wakeup = true;
303 printf("Simulating alarm wakeup.\n");
304 }
305 else if (!strcmp("--root", argv[x]))
306 {
307 x++;
308 if (x < argc)
309 {
310 sim_root_dir = argv[x];
311 printf("Root directory: %s\n", sim_root_dir);
312 }
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 }
324 else
325 {
326 printf("rockboxui\n");
327 printf("Arguments:\n");
328 printf(" --debugaudio \t Write raw PCM data to audiodebug.raw\n");
329 printf(" --debugwps \t Print advanced WPS debug info\n");
330 printf(" --nobackground \t Disable the background image\n");
331#ifdef HAVE_REMOTE_LCD
332 printf(" --noremote \t Disable the remote image (will disable backgrounds)\n");
333#endif
334 printf(" --old_lcd \t [Player] simulate old playermodel (ROM version<4.51)\n");
335 printf(" --zoom [VAL]\t Window zoom (will disable backgrounds)\n");
336 printf(" --alarm \t Simulate a wake-up on alarm\n");
337 printf(" --root [DIR]\t Set root directory\n");
338 printf(" --mapping \t Output coordinates and radius for mapping backgrounds\n");
339 exit(0);
340 }
341 }
342 }
343
344 if (display_zoom > 1) {
345 background = false;
346 }
347
348 if (!sim_kernel_init()) {
349 fprintf(stderr, "sim_kernel_init failed\n");
350 return -1;
351 }
352
353 if (!gui_startup()) {
354 fprintf(stderr, "gui_startup failed\n");
355 return -1;
356 }
357
358 /* app_main will be called by the new main thread */
359 if (!thread_sdl_init(NULL)) {
360 fprintf(stderr, "thread_sdl_init failed\n");
361 return -1;
362 }
363
364 gui_message_loop();
365
366 return gui_shutdown();
367}
368