get rid of the filename in the delete bookmark confirmation as its not really helpful
[kugel-rb.git] / uisimulator / sdl / uisdl.c
blob3ab098e5ba0206b6fb79dd310ec7ea9caf5d0cd9
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2006 by Daniel Everton <dan@iocaine.org>
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
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"
44 /* extern functions */
45 extern void new_key(int key);
47 void button_event(int key, bool pressed);
49 SDL_Surface *gui_surface;
50 bool background = true; /* use backgrounds by default */
51 #ifdef HAVE_REMOTE_LCD
52 static bool showremote = true; /* include remote by default */
53 #endif
55 bool lcd_display_redraw = true; /* Used for player simulator */
56 char having_new_lcd = true; /* Used for player simulator */
57 bool sim_alarm_wakeup = false;
58 const char *sim_root_dir = NULL;
60 bool debug_audio = false;
62 bool debug_wps = false;
63 int wps_verbose_level = 3;
65 void gui_message_loop(void)
67 SDL_Event event;
68 bool done = false;
70 while(!done && SDL_WaitEvent(&event))
72 switch(event.type)
74 case SDL_KEYDOWN:
75 sim_enter_irq_handler();
76 button_event(event.key.keysym.sym, true);
77 sim_exit_irq_handler();
78 break;
79 case SDL_KEYUP:
80 sim_enter_irq_handler();
81 button_event(event.key.keysym.sym, false);
82 sim_exit_irq_handler();
83 break;
84 #ifndef HAVE_TOUCHSCREEN
85 case SDL_MOUSEBUTTONDOWN:
86 if (debug_wps && event.button.button == 1)
88 printf("Mouse at: (%d, %d)\n", event.button.x, event.button.y);
90 break;
91 #else
92 case SDL_MOUSEBUTTONUP:
93 sim_enter_irq_handler();
94 button_event(BUTTON_TOUCHSCREEN, false);
95 sim_exit_irq_handler();
96 break;
97 #endif
98 case SDL_QUIT:
99 done = true;
100 break;
101 default:
102 /*printf("Unhandled event\n"); */
103 break;
108 bool gui_startup(void)
110 SDL_Surface *picture_surface;
111 int width, height;
113 if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER)) {
114 fprintf(stderr, "fatal: %s\n", SDL_GetError());
115 return false;
118 atexit(SDL_Quit);
120 /* Try and load the background image. If it fails go without */
121 if (background) {
122 picture_surface = SDL_LoadBMP("UI256.bmp");
123 if (picture_surface == NULL) {
124 background = false;
125 fprintf(stderr, "warn: %s\n", SDL_GetError());
129 /* Set things up */
130 if (background)
132 width = UI_WIDTH;
133 height = UI_HEIGHT;
135 else
137 #ifdef HAVE_REMOTE_LCD
138 if (showremote)
140 width = SIM_LCD_WIDTH > SIM_REMOTE_WIDTH ? SIM_LCD_WIDTH : SIM_REMOTE_WIDTH;
141 height = SIM_LCD_HEIGHT + SIM_REMOTE_HEIGHT;
143 else
144 #endif
146 width = SIM_LCD_WIDTH;
147 height = SIM_LCD_HEIGHT;
152 if ((gui_surface = SDL_SetVideoMode(width * display_zoom, height * display_zoom, 24, SDL_HWSURFACE|SDL_DOUBLEBUF)) == NULL) {
153 fprintf(stderr, "fatal: %s\n", SDL_GetError());
154 return false;
157 SDL_WM_SetCaption(UI_TITLE, NULL);
159 sim_lcd_init();
160 #ifdef HAVE_REMOTE_LCD
161 if (showremote)
162 sim_lcd_remote_init();
163 #endif
165 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
167 if (background && picture_surface != NULL) {
168 SDL_BlitSurface(picture_surface, NULL, gui_surface, NULL);
169 SDL_UpdateRect(gui_surface, 0, 0, 0, 0);
172 return true;
175 bool gui_shutdown(void)
177 /* Order here is relevent to prevent deadlocks and use of destroyed
178 sync primitives by kernel threads */
179 thread_sdl_shutdown();
180 sim_kernel_shutdown();
181 return true;
184 #if defined(WIN32) && defined(main)
185 /* Don't use SDL_main on windows -> no more stdio redirection */
186 #undef main
187 #endif
189 int main(int argc, char *argv[])
191 if (argc >= 1)
193 int x;
194 for (x = 1; x < argc; x++)
196 if (!strcmp("--debugaudio", argv[x]))
198 debug_audio = true;
199 printf("Writing debug audio file.\n");
201 else if (!strcmp("--debugwps", argv[x]))
203 debug_wps = true;
204 printf("WPS debug mode enabled.\n");
206 else if (!strcmp("--nobackground", argv[x]))
208 background = false;
209 printf("Disabling background image.\n");
211 #ifdef HAVE_REMOTE_LCD
212 else if (!strcmp("--noremote", argv[x]))
214 showremote = false;
215 background = false;
216 printf("Disabling remote image.\n");
218 #endif
219 else if (!strcmp("--old_lcd", argv[x]))
221 having_new_lcd = false;
222 printf("Using old LCD layout.\n");
224 else if (!strcmp("--zoom", argv[x]))
226 x++;
227 if(x < argc)
228 display_zoom=atoi(argv[x]);
229 else
230 display_zoom = 2;
231 printf("Window zoom is %d\n", display_zoom);
233 else if (!strcmp("--alarm", argv[x]))
235 sim_alarm_wakeup = true;
236 printf("Simulating alarm wakeup.\n");
238 else if (!strcmp("--root", argv[x]))
240 x++;
241 if (x < argc)
243 sim_root_dir = argv[x];
244 printf("Root directory: %s\n", sim_root_dir);
247 else
249 printf("rockboxui\n");
250 printf("Arguments:\n");
251 printf(" --debugaudio \t Write raw PCM data to audiodebug.raw\n");
252 printf(" --debugwps \t Print advanced WPS debug info\n");
253 printf(" --nobackground \t Disable the background image\n");
254 #ifdef HAVE_REMOTE_LCD
255 printf(" --noremote \t Disable the remote image (will disable backgrounds)\n");
256 #endif
257 printf(" --old_lcd \t [Player] simulate old playermodel (ROM version<4.51)\n");
258 printf(" --zoom [VAL]\t Window zoom (will disable backgrounds)\n");
259 printf(" --alarm \t Simulate a wake-up on alarm\n");
260 printf(" --root [DIR]\t Set root directory\n");
261 exit(0);
266 if (display_zoom > 1) {
267 background = false;
270 if (!sim_kernel_init()) {
271 fprintf(stderr, "sim_kernel_init failed\n");
272 return -1;
275 if (!gui_startup()) {
276 fprintf(stderr, "gui_startup failed\n");
277 return -1;
280 /* app_main will be called by the new main thread */
281 if (!thread_sdl_init(NULL)) {
282 fprintf(stderr, "thread_sdl_init failed\n");
283 return -1;
286 gui_message_loop();
288 return gui_shutdown();