diff options
Diffstat (limited to 'uisimulator/sdl/uisdl.c')
-rw-r--r-- | uisimulator/sdl/uisdl.c | 287 |
1 files changed, 123 insertions, 164 deletions
diff --git a/uisimulator/sdl/uisdl.c b/uisimulator/sdl/uisdl.c index e17a925313..b55e3ee8ff 100644 --- a/uisimulator/sdl/uisdl.c +++ b/uisimulator/sdl/uisdl.c | |||
@@ -7,7 +7,7 @@ | |||
7 | * \/ \/ \/ \/ \/ | 7 | * \/ \/ \/ \/ \/ |
8 | * $Id$ | 8 | * $Id$ |
9 | * | 9 | * |
10 | * Copyright (C) 2002 by Daniel Stenberg <daniel@haxx.se> | 10 | * Copyright (C) 2006 by Daniel Everton <dan@iocaine.org> |
11 | * | 11 | * |
12 | * All files in this archive are subject to the GNU General Public License. | 12 | * All files in this archive are subject to the GNU General Public License. |
13 | * See the file COPYING in the source tree root for full license agreement. | 13 | * See the file COPYING in the source tree root for full license agreement. |
@@ -16,211 +16,170 @@ | |||
16 | * KIND, either express or implied. | 16 | * KIND, either express or implied. |
17 | * | 17 | * |
18 | ****************************************************************************/ | 18 | ****************************************************************************/ |
19 | #include <stdio.h> | ||
20 | #include <string.h> | ||
21 | #include <stdarg.h> | ||
22 | #include <stdlib.h> | ||
23 | #include <ctype.h> | ||
24 | #include <sys/types.h> | ||
25 | #include <sys/stat.h> | ||
26 | #include <fcntl.h> | ||
27 | |||
28 | #include <errno.h> | ||
29 | #include <ctype.h> | ||
30 | #include <time.h> | ||
31 | |||
32 | #include <SDL.h> | ||
33 | |||
34 | #include "config.h" | ||
35 | #include "screenhack.h" | ||
36 | |||
37 | #include "version.h" | ||
38 | |||
39 | #include "lcd-x11.h" | ||
40 | #include "lcd-playersim.h" | ||
41 | |||
42 | #define MAX(x,y) ((x)>(y)?(x):(y)) | ||
43 | #define MIN(x,y) ((x)<(y)?(x):(y)) | ||
44 | |||
45 | #define PROGNAME "rockboxui" | ||
46 | |||
47 | /* -- -- */ | ||
48 | |||
49 | extern SDL_Surface *surface; | ||
50 | 19 | ||
51 | int display_zoom=2; | 20 | #include <stdlib.h> |
21 | #include "autoconf.h" | ||
22 | #include "uisdl.h" | ||
23 | #include "button.h" | ||
24 | #include "thread.h" | ||
25 | #include "thread-sdl.h" | ||
26 | #include "kernel.h" | ||
27 | #include "sound.h" | ||
28 | |||
29 | // extern functions | ||
30 | extern void app_main (void *); // mod entry point | ||
31 | extern void new_key(int key); | ||
32 | extern void sim_tick_tasks(void); | ||
33 | |||
34 | void button_event(int key, bool pressed); | ||
35 | |||
36 | SDL_Surface *gui_surface; | ||
37 | |||
38 | SDL_Thread *gui_thread; | ||
39 | SDL_TimerID tick_timer_id; | ||
40 | #ifdef ROCKBOX_HAS_SIMSOUND | ||
41 | SDL_Thread *sound_thread; | ||
42 | #endif | ||
52 | 43 | ||
53 | bool lcd_display_redraw=true; | 44 | bool lcd_display_redraw=true; // Used for player simulator |
45 | char having_new_lcd=true; // Used for player simulator | ||
54 | 46 | ||
55 | char *progclass = "rockboxui"; | 47 | long start_tick; |
56 | 48 | ||
57 | void init_window () | 49 | Uint32 tick_timer(Uint32 interval, void *param) |
58 | { | 50 | { |
59 | /* stub */ | 51 | long new_tick; |
60 | } | ||
61 | 52 | ||
62 | /* used for the player sim */ | 53 | (void) interval; |
63 | void drawdots(int color, struct coordinate *points, int count) | 54 | (void) param; |
64 | { | ||
65 | SDL_Rect rect; | ||
66 | 55 | ||
67 | while (count--) { | 56 | new_tick = (SDL_GetTicks() - start_tick) * HZ / 1000; |
68 | rect.x = points[count].x * display_zoom; | ||
69 | rect.y = points[count].y * display_zoom; | ||
70 | rect.w = display_zoom; | ||
71 | rect.h = display_zoom; | ||
72 | 57 | ||
73 | SDL_FillRect(surface, &rect, color); | 58 | if (new_tick != current_tick) |
59 | { | ||
60 | long i; | ||
61 | for (i = new_tick - current_tick; i > 0; i--) | ||
62 | sim_tick_tasks(); | ||
63 | current_tick = new_tick; | ||
74 | } | 64 | } |
75 | } | ||
76 | |||
77 | void drawrect(int color, int x1, int y1, int x2, int y2) | ||
78 | { | ||
79 | SDL_Rect rect; | ||
80 | 65 | ||
81 | rect.x = x1 * display_zoom; | 66 | return 1; |
82 | rect.y = y1 * display_zoom; | ||
83 | rect.w = (x2-x1) * display_zoom; | ||
84 | rect.h = (y2-y1) * display_zoom; | ||
85 | |||
86 | SDL_FillRect(surface, &rect, color); | ||
87 | } | 67 | } |
88 | 68 | ||
89 | #if 0 | 69 | void gui_message_loop(void) |
90 | static void help(void) | ||
91 | { | 70 | { |
92 | printf(PROGNAME " " ROCKBOXUI_VERSION " " __DATE__ "\n" | 71 | SDL_Event event; |
93 | "usage: " PROGNAME "\n"); | 72 | bool done = false; |
73 | |||
74 | while(!done && SDL_WaitEvent(&event)) | ||
75 | { | ||
76 | switch(event.type) | ||
77 | { | ||
78 | case SDL_KEYDOWN: | ||
79 | button_event(event.key.keysym.sym, true); | ||
80 | break; | ||
81 | case SDL_KEYUP: | ||
82 | button_event(event.key.keysym.sym, false); | ||
83 | break; | ||
84 | case SDL_QUIT: | ||
85 | done = true; | ||
86 | break; | ||
87 | default: | ||
88 | //printf("Unhandled event\n"); | ||
89 | break; | ||
90 | } | ||
91 | } | ||
94 | } | 92 | } |
95 | #endif | ||
96 | 93 | ||
97 | void dots(int *colors, struct coordinate *points, int count) | 94 | bool gui_startup() |
98 | { | 95 | { |
99 | int bpp = surface->format->BytesPerPixel; | 96 | SDL_Surface *picture_surface; |
100 | 97 | ||
101 | if (SDL_MUSTLOCK(surface)) { | 98 | if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO|SDL_INIT_TIMER)) { |
102 | if (SDL_LockSurface(surface)) { | 99 | fprintf(stderr, "fatal: %s", SDL_GetError()); |
103 | fprintf(stderr, "cannot lock surface: %s", SDL_GetError()); | 100 | return false; |
104 | exit(-1); | ||
105 | } | ||
106 | } | 101 | } |
107 | 102 | ||
108 | while (count--) { | 103 | atexit(SDL_Quit); |
109 | int x_off, y_off; | ||
110 | 104 | ||
111 | for (x_off = 0; x_off < display_zoom; x_off++) { | 105 | if ((gui_surface = SDL_SetVideoMode(UI_WIDTH, UI_HEIGHT, 24, SDL_HWSURFACE|SDL_DOUBLEBUF)) == NULL) { |
112 | for (y_off = 0; y_off < display_zoom; y_off++) { | 106 | fprintf(stderr, "fatal: %s", SDL_GetError()); |
113 | int x = points[count].x*display_zoom + x_off; | 107 | return false; |
114 | int y = points[count].y*display_zoom + y_off; | 108 | } |
115 | 109 | ||
116 | Uint8 *p = (Uint8 *) surface->pixels + y * surface->pitch + x * bpp; | 110 | SDL_WM_SetCaption(UI_TITLE, NULL); |
117 | 111 | ||
118 | switch (bpp) { | 112 | simlcdinit(); |
119 | case 1: | ||
120 | *p = colors[count]; | ||
121 | break; | ||
122 | 113 | ||
123 | case 2: | 114 | SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL); |
124 | *(Uint16 *)p = colors[count]; | ||
125 | break; | ||
126 | 115 | ||
127 | case 3: | 116 | picture_surface = SDL_LoadBMP("UI256.bmp"); |
128 | if (SDL_BYTEORDER == SDL_BIG_ENDIAN) { | 117 | if (picture_surface == NULL) { |
129 | p[0] = (colors[count] >> 16) & 0xff; | 118 | fprintf(stderr, "warn: %s", SDL_GetError()); |
130 | p[1] = (colors[count] >> 8) & 0xff; | ||
131 | p[2] = (colors[count]) & 0xff; | ||
132 | } else { | 119 | } else { |
133 | p[2] = (colors[count] >> 16) & 0xff; | 120 | SDL_BlitSurface(picture_surface, NULL, gui_surface, NULL); |
134 | p[1] = (colors[count] >> 8) & 0xff; | 121 | SDL_UpdateRect(gui_surface, 0, 0, 0, 0); |
135 | p[0] = (colors[count]) & 0xff; | ||
136 | } | 122 | } |
137 | break; | ||
138 | 123 | ||
139 | case 4: | 124 | start_tick = SDL_GetTicks(); |
140 | *(Uint32 *)p = colors[count]; | ||
141 | break; | ||
142 | } | ||
143 | } | ||
144 | } | ||
145 | } | ||
146 | |||
147 | if (SDL_MUSTLOCK(surface)) { | ||
148 | SDL_UnlockSurface(surface); | ||
149 | } | ||
150 | 125 | ||
151 | SDL_UpdateRect(surface, 0, 0, 0, 0); | 126 | return true; |
152 | } | 127 | } |
153 | 128 | ||
154 | /* this is where the applicaton starts */ | 129 | bool gui_shutdown() |
155 | extern void app_main(void); | ||
156 | |||
157 | void screenhack() | ||
158 | { | 130 | { |
159 | #if 0 | 131 | int i; |
160 | Bool helpme; | ||
161 | 132 | ||
162 | /* This doesn't work, but I don't know why (Daniel 1999-12-01) */ | 133 | SDL_KillThread(gui_thread); |
163 | helpme = get_boolean_resource ("help", "Boolean"); | 134 | SDL_RemoveTimer(tick_timer_id); |
164 | if(helpme) | 135 | #ifdef ROCKBOX_HAS_SIMSOUND |
165 | help(); | 136 | SDL_KillThread(sound_thread); |
166 | #endif | 137 | #endif |
167 | 138 | ||
168 | printf(PROGNAME " " ROCKBOXUI_VERSION " (" __DATE__ ")\n"); | 139 | for (i = 0; i < threadCount; i++) |
140 | { | ||
141 | SDL_KillThread(threads[i]); | ||
142 | } | ||
169 | 143 | ||
170 | init_window(); | 144 | return true; |
145 | } | ||
171 | 146 | ||
172 | screen_redraw(); | 147 | /** |
148 | * Thin wrapper around normal app_main() to stop gcc complaining about types. | ||
149 | */ | ||
150 | int sim_app_main(void *param) | ||
151 | { | ||
152 | app_main(param); | ||
173 | 153 | ||
174 | app_main(); | 154 | return 0; |
175 | } | 155 | } |
176 | 156 | ||
177 | /* used for the player sim */ | 157 | int main(int argc, char *argv[]) |
178 | void drawrectangles(int color, struct rectangle *points, int count) | ||
179 | { | 158 | { |
180 | SDL_Rect rect; | 159 | (void)argc; |
181 | Uint32 sdl_white = SDL_MapRGB(surface->format, 255, 255, 255); | 160 | (void)argv; |
182 | Uint32 sdl_black = SDL_MapRGB(surface->format, 0, 0, 0); | 161 | |
183 | 162 | if (!gui_startup()) | |
184 | while (count--) { | 163 | return -1; |
185 | rect.x = points[count].x * display_zoom; | 164 | |
186 | rect.y = points[count].y * display_zoom; | 165 | gui_thread = SDL_CreateThread(sim_app_main, NULL); |
187 | rect.w = points[count].width * display_zoom; | 166 | if (gui_thread == NULL) { |
188 | rect.h = points[count].height * display_zoom; | 167 | printf("Error creating GUI thread!\n"); |
189 | 168 | return -1; | |
190 | SDL_FillRect(surface, &rect, color ? sdl_white : sdl_black); | ||
191 | } | 169 | } |
192 | } | ||
193 | 170 | ||
171 | tick_timer_id = SDL_AddTimer(10, tick_timer, NULL); | ||
194 | 172 | ||
195 | void screen_redraw() | 173 | #ifdef ROCKBOX_HAS_SIMSOUND |
196 | { | 174 | sound_thread = SDL_CreateThread(sound_playback_thread, NULL); |
197 | /* draw a border around the screen */ | 175 | if (sound_thread == NULL) { |
198 | int X1 = 0; | 176 | printf("Error creating sound thread!\n"); |
199 | int Y1 = 0; | 177 | return -1; |
200 | int X2 = LCD_WIDTH + 2*MARGIN_X - 1; | 178 | } |
201 | int Y2 = LCD_HEIGHT + 2*MARGIN_Y - 1; | ||
202 | |||
203 | drawrect(SDL_MapRGB(surface->format, 255, 255, 255), X1, Y1, X2, Y1+1); | ||
204 | drawrect(SDL_MapRGB(surface->format, 255, 255, 255), X2, Y1, X2+1, Y2); | ||
205 | drawrect(SDL_MapRGB(surface->format, 255, 255, 255), X1, Y2, X2, Y2+1); | ||
206 | drawrect(SDL_MapRGB(surface->format, 255, 255, 255), X1, Y1, X1+1, Y2); | ||
207 | |||
208 | lcd_display_redraw = true; | ||
209 | lcd_update(); | ||
210 | |||
211 | #ifdef LCD_REMOTE_HEIGHT | ||
212 | /* draw a border around the remote LCD screen */ | ||
213 | int RX1 = 0; | ||
214 | int RY1 = Y2 + 1; | ||
215 | int RX2 = LCD_REMOTE_WIDTH + 2*MARGIN_X - 1; | ||
216 | int RY2 = RY1 + LCD_REMOTE_HEIGHT + 2*MARGIN_Y - 1; | ||
217 | |||
218 | drawrect(SDL_MapRGB(surface->format, 255, 255, 255), RX1, RY1, RX2, RY1+1); | ||
219 | drawrect(SDL_MapRGB(surface->format, 255, 255, 255), RX2, RY1, RX2+1, RY2); | ||
220 | drawrect(SDL_MapRGB(surface->format, 255, 255, 255), RX1, RY2, RX2, RY2+1); | ||
221 | drawrect(SDL_MapRGB(surface->format, 255, 255, 255), RX1, RY1, RX1+1, RY2); | ||
222 | |||
223 | lcd_display_redraw = true; | ||
224 | lcd_remote_update(); | ||
225 | #endif | 179 | #endif |
180 | |||
181 | gui_message_loop(); | ||
182 | |||
183 | return gui_shutdown(); | ||
226 | } | 184 | } |
185 | |||