diff options
Diffstat (limited to 'uisimulator/sdl/screenhack.c')
-rw-r--r-- | uisimulator/sdl/screenhack.c | 228 |
1 files changed, 228 insertions, 0 deletions
diff --git a/uisimulator/sdl/screenhack.c b/uisimulator/sdl/screenhack.c new file mode 100644 index 0000000000..c77cb575e4 --- /dev/null +++ b/uisimulator/sdl/screenhack.c | |||
@@ -0,0 +1,228 @@ | |||
1 | /* xscreensaver, Copyright (c) 1992, 1995, 1997, 1998 | ||
2 | * Jamie Zawinski <jwz@jwz.org> | ||
3 | * | ||
4 | * Permission to use, copy, modify, distribute, and sell this software and its | ||
5 | * documentation for any purpose is hereby granted without fee, provided that | ||
6 | * the above copyright notice appear in all copies and that both that | ||
7 | * copyright notice and this permission notice appear in supporting | ||
8 | * documentation. No representations are made about the suitability of this | ||
9 | * software for any purpose. It is provided "as is" without express or | ||
10 | * implied warranty. | ||
11 | * | ||
12 | * And remember: X Windows is to graphics hacking as roman numerals are to | ||
13 | * the square root of pi. | ||
14 | */ | ||
15 | |||
16 | /* This file contains simple code to open a window or draw on the root. | ||
17 | The idea being that, when writing a graphics hack, you can just link | ||
18 | with this .o to get all of the uninteresting junk out of the way. | ||
19 | |||
20 | - create a procedure `screenhack(dpy, window)' | ||
21 | |||
22 | - create a variable `char *progclass' which names this program's | ||
23 | resource class. | ||
24 | |||
25 | - create a variable `char defaults []' for the default resources, and | ||
26 | null-terminate it. | ||
27 | |||
28 | - create a variable `XrmOptionDescRec options[]' for the command-line, | ||
29 | and null-terminate it. | ||
30 | |||
31 | And that's it... | ||
32 | */ | ||
33 | |||
34 | #include <stdio.h> | ||
35 | #include <string.h> | ||
36 | #include <SDL.h> | ||
37 | #include "lcd-x11.h" | ||
38 | #include "screenhack.h" | ||
39 | #include "version.h" | ||
40 | |||
41 | #include "debug.h" | ||
42 | #include "config.h" | ||
43 | |||
44 | #ifndef isupper | ||
45 | # define isupper(c) ((c) >= 'A' && (c) <= 'Z') | ||
46 | #endif | ||
47 | #ifndef _tolower | ||
48 | # define _tolower(c) ((c) - 'A' + 'a') | ||
49 | #endif | ||
50 | |||
51 | #define KEYBOARD_GENERIC \ | ||
52 | "Keyboard Rockbox\n" \ | ||
53 | "-------- ------------\n" \ | ||
54 | "4, Left LEFT\n" \ | ||
55 | "6, Right RIGHT\n" | ||
56 | |||
57 | #if CONFIG_KEYPAD == PLAYER_PAD | ||
58 | #define KEYBOARD_SPECIFIC \ | ||
59 | "8, Up PLAY\n" \ | ||
60 | "2, Down STOP\n" \ | ||
61 | "+, Q ON\n" \ | ||
62 | "., INS MENU\n" | ||
63 | |||
64 | #elif CONFIG_KEYPAD == RECORDER_PAD | ||
65 | #define KEYBOARD_SPECIFIC \ | ||
66 | "8, Up UP\n" \ | ||
67 | "2, Down DOWN\n" \ | ||
68 | "5, Space PLAY\n" \ | ||
69 | "+, Q ON\n" \ | ||
70 | "Enter, A OFF\n" \ | ||
71 | "/, (F1) F1\n" \ | ||
72 | "*, (F2) F2\n" \ | ||
73 | "-, (F3) F3\n" | ||
74 | |||
75 | #elif CONFIG_KEYPAD == ONDIO_PAD | ||
76 | #define KEYBOARD_SPECIFIC \ | ||
77 | "8, Up UP\n" \ | ||
78 | "2, Down DOWN\n" \ | ||
79 | "., INS MENU\n" \ | ||
80 | "Enter, A OFF\n" | ||
81 | |||
82 | #elif CONFIG_KEYPAD == IRIVER_H100_PAD | ||
83 | #define KEYBOARD_SPECIFIC \ | ||
84 | "8, Up UP\n" \ | ||
85 | "2, Down DOWN\n" \ | ||
86 | "5, Space SELECT\n" \ | ||
87 | "+, Q ON\n" \ | ||
88 | "Enter, A OFF\n" \ | ||
89 | "., INS MODE\n" \ | ||
90 | "/, (F1) RECORD\n" | ||
91 | |||
92 | #elif CONFIG_KEYPAD == IRIVER_H300_PAD | ||
93 | #define KEYBOARD_SPECIFIC \ | ||
94 | "8, Up UP\n" \ | ||
95 | "2, Down DOWN\n" \ | ||
96 | "4, Left LEFT\n" \ | ||
97 | "6, Right RIGHT\n" \ | ||
98 | "5, Space SELECT\n" \ | ||
99 | "+, Q ON\n" \ | ||
100 | "Enter, A OFF\n" \ | ||
101 | "., INS MODE\n" \ | ||
102 | "/, (F1) RECORD\n" | ||
103 | |||
104 | #elif CONFIG_KEYPAD == GMINI100_PAD | ||
105 | #define KEYBOARD_SPECIFIC \ | ||
106 | "8, Up UP\n" \ | ||
107 | "2, Down DOWN\n" \ | ||
108 | "5, Space PLAY\n" \ | ||
109 | "+, Q ON\n" \ | ||
110 | "Enter, A OFF\n" \ | ||
111 | "., INS MENU\n" | ||
112 | |||
113 | #elif (CONFIG_KEYPAD == IPOD_4G_PAD) | ||
114 | #define KEYBOARD_SPECIFIC \ | ||
115 | "[not written yet]" | ||
116 | |||
117 | #endif | ||
118 | |||
119 | |||
120 | SDL_Surface *surface; | ||
121 | |||
122 | char having_new_lcd = true; | ||
123 | |||
124 | extern int display_zoom; | ||
125 | |||
126 | /* Dead-trivial event handling. | ||
127 | */ | ||
128 | int screenhack_handle_event(SDL_Event *event, bool *release) | ||
129 | { | ||
130 | int key = 0; | ||
131 | |||
132 | *release = false; | ||
133 | |||
134 | switch (event->type) { | ||
135 | case SDL_KEYDOWN: | ||
136 | { | ||
137 | key = event->key.keysym.sym; | ||
138 | *release = false; | ||
139 | } | ||
140 | break; | ||
141 | case SDL_KEYUP: | ||
142 | { | ||
143 | key = event->key.keysym.sym; | ||
144 | *release = true; | ||
145 | } | ||
146 | break; | ||
147 | case SDL_QUIT: | ||
148 | { | ||
149 | SDL_Quit(); | ||
150 | exit(0); | ||
151 | } | ||
152 | break; | ||
153 | default: | ||
154 | break; | ||
155 | } | ||
156 | |||
157 | return key; | ||
158 | } | ||
159 | |||
160 | int screenhack_handle_events(bool *release) | ||
161 | { | ||
162 | int key = 0; | ||
163 | SDL_Event event; | ||
164 | |||
165 | if (SDL_PollEvent(&event)) { | ||
166 | key = screenhack_handle_event(&event, release); | ||
167 | } | ||
168 | |||
169 | return key; | ||
170 | } | ||
171 | |||
172 | |||
173 | int main (int argc, char **argv) | ||
174 | { | ||
175 | int window_width; | ||
176 | int window_height; | ||
177 | |||
178 | if (argc > 1) | ||
179 | { | ||
180 | int x; | ||
181 | for (x=1; x<argc; x++) { | ||
182 | if (!strcmp("--old_lcd", argv[x])) { | ||
183 | having_new_lcd=false; | ||
184 | printf("Using old LCD layout.\n"); | ||
185 | } else if (!strcmp("--zoom", argv[x])) { | ||
186 | if (++x < argc) { | ||
187 | display_zoom=atoi(argv[x]); | ||
188 | printf("Window zoom is %d\n", display_zoom); | ||
189 | if (display_zoom < 1 || display_zoom > 5) { | ||
190 | printf("fatal: --zoom argument must be between 1 and 5\n"); | ||
191 | exit(0); | ||
192 | } | ||
193 | } else { | ||
194 | printf("fatal: --zoom requires an integer argument\n"); | ||
195 | exit(0); | ||
196 | } | ||
197 | } else { | ||
198 | printf("rockboxui\n"); | ||
199 | printf("Arguments:\n"); | ||
200 | printf(" --old_lcd \t [Player] simulate old playermodel (ROM version<4.51)\n"); | ||
201 | printf(" --zoom [1-5]\t window zoom\n"); | ||
202 | printf(KEYBOARD_GENERIC KEYBOARD_SPECIFIC); | ||
203 | exit(0); | ||
204 | } | ||
205 | } | ||
206 | } | ||
207 | |||
208 | window_width = (LCD_WIDTH + 2*MARGIN_X) * display_zoom; | ||
209 | window_height = (LCD_HEIGHT + 2*MARGIN_Y) * display_zoom; | ||
210 | #ifdef LCD_REMOTE_HEIGHT | ||
211 | window_height += (LCD_REMOTE_HEIGHT + 2*MARGIN_Y) * display_zoom; | ||
212 | #endif | ||
213 | |||
214 | if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO)) { | ||
215 | fprintf(stderr, "fatal: %s", SDL_GetError()); | ||
216 | exit(-1); | ||
217 | } | ||
218 | |||
219 | atexit(SDL_Quit); | ||
220 | |||
221 | if ((surface = SDL_SetVideoMode(window_width, window_height, 24, 0)) == NULL) { | ||
222 | fprintf(stderr, "fatal: %s", SDL_GetError()); | ||
223 | exit(-1); | ||
224 | } | ||
225 | |||
226 | screenhack(); /* doesn't return */ | ||
227 | return 0; | ||
228 | } | ||