summaryrefslogtreecommitdiff
path: root/uisimulator/sdl/uisdl.c
diff options
context:
space:
mode:
Diffstat (limited to 'uisimulator/sdl/uisdl.c')
-rw-r--r--uisimulator/sdl/uisdl.c226
1 files changed, 226 insertions, 0 deletions
diff --git a/uisimulator/sdl/uisdl.c b/uisimulator/sdl/uisdl.c
new file mode 100644
index 0000000000..e17a925313
--- /dev/null
+++ b/uisimulator/sdl/uisdl.c
@@ -0,0 +1,226 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Daniel Stenberg <daniel@haxx.se>
11 *
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.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
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
49extern SDL_Surface *surface;
50
51int display_zoom=2;
52
53bool lcd_display_redraw=true;
54
55char *progclass = "rockboxui";
56
57void init_window ()
58{
59 /* stub */
60}
61
62/* used for the player sim */
63void drawdots(int color, struct coordinate *points, int count)
64{
65 SDL_Rect rect;
66
67 while (count--) {
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
73 SDL_FillRect(surface, &rect, color);
74 }
75}
76
77void drawrect(int color, int x1, int y1, int x2, int y2)
78{
79 SDL_Rect rect;
80
81 rect.x = x1 * display_zoom;
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}
88
89#if 0
90static void help(void)
91{
92 printf(PROGNAME " " ROCKBOXUI_VERSION " " __DATE__ "\n"
93 "usage: " PROGNAME "\n");
94}
95#endif
96
97void dots(int *colors, struct coordinate *points, int count)
98{
99 int bpp = surface->format->BytesPerPixel;
100
101 if (SDL_MUSTLOCK(surface)) {
102 if (SDL_LockSurface(surface)) {
103 fprintf(stderr, "cannot lock surface: %s", SDL_GetError());
104 exit(-1);
105 }
106 }
107
108 while (count--) {
109 int x_off, y_off;
110
111 for (x_off = 0; x_off < display_zoom; x_off++) {
112 for (y_off = 0; y_off < display_zoom; y_off++) {
113 int x = points[count].x*display_zoom + x_off;
114 int y = points[count].y*display_zoom + y_off;
115
116 Uint8 *p = (Uint8 *) surface->pixels + y * surface->pitch + x * bpp;
117
118 switch (bpp) {
119 case 1:
120 *p = colors[count];
121 break;
122
123 case 2:
124 *(Uint16 *)p = colors[count];
125 break;
126
127 case 3:
128 if (SDL_BYTEORDER == SDL_BIG_ENDIAN) {
129 p[0] = (colors[count] >> 16) & 0xff;
130 p[1] = (colors[count] >> 8) & 0xff;
131 p[2] = (colors[count]) & 0xff;
132 } else {
133 p[2] = (colors[count] >> 16) & 0xff;
134 p[1] = (colors[count] >> 8) & 0xff;
135 p[0] = (colors[count]) & 0xff;
136 }
137 break;
138
139 case 4:
140 *(Uint32 *)p = colors[count];
141 break;
142 }
143 }
144 }
145 }
146
147 if (SDL_MUSTLOCK(surface)) {
148 SDL_UnlockSurface(surface);
149 }
150
151 SDL_UpdateRect(surface, 0, 0, 0, 0);
152}
153
154/* this is where the applicaton starts */
155extern void app_main(void);
156
157void screenhack()
158{
159#if 0
160 Bool helpme;
161
162 /* This doesn't work, but I don't know why (Daniel 1999-12-01) */
163 helpme = get_boolean_resource ("help", "Boolean");
164 if(helpme)
165 help();
166#endif
167
168 printf(PROGNAME " " ROCKBOXUI_VERSION " (" __DATE__ ")\n");
169
170 init_window();
171
172 screen_redraw();
173
174 app_main();
175}
176
177/* used for the player sim */
178void drawrectangles(int color, struct rectangle *points, int count)
179{
180 SDL_Rect rect;
181 Uint32 sdl_white = SDL_MapRGB(surface->format, 255, 255, 255);
182 Uint32 sdl_black = SDL_MapRGB(surface->format, 0, 0, 0);
183
184 while (count--) {
185 rect.x = points[count].x * display_zoom;
186 rect.y = points[count].y * display_zoom;
187 rect.w = points[count].width * display_zoom;
188 rect.h = points[count].height * display_zoom;
189
190 SDL_FillRect(surface, &rect, color ? sdl_white : sdl_black);
191 }
192}
193
194
195void screen_redraw()
196{
197 /* draw a border around the screen */
198 int X1 = 0;
199 int Y1 = 0;
200 int X2 = LCD_WIDTH + 2*MARGIN_X - 1;
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
226}