diff options
author | Dan Everton <dan@iocaine.org> | 2006-02-09 21:49:28 +0000 |
---|---|---|
committer | Dan Everton <dan@iocaine.org> | 2006-02-09 21:49:28 +0000 |
commit | b585e87b454917f0424541a34c0b41b1fe83f694 (patch) | |
tree | f93652b42b4791ce4f8b64421a1a063c58e511b0 /uisimulator/sdl/lcd-sdl.c | |
parent | f42f42e5543f18d11142bb98e3c8677a04b99318 (diff) | |
download | rockbox-b585e87b454917f0424541a34c0b41b1fe83f694.tar.gz rockbox-b585e87b454917f0424541a34c0b41b1fe83f694.zip |
Refactor SDL sim source so drawing routines are written once. Split bitmap, remote, and charcell LCD in to their own files. Add zoom support, use --zoom factor (e.g. --zoom 2 for two times zoom) to use it.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8645 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'uisimulator/sdl/lcd-sdl.c')
-rw-r--r-- | uisimulator/sdl/lcd-sdl.c | 297 |
1 files changed, 34 insertions, 263 deletions
diff --git a/uisimulator/sdl/lcd-sdl.c b/uisimulator/sdl/lcd-sdl.c index 1a6e8da8e8..4a0962dbec 100644 --- a/uisimulator/sdl/lcd-sdl.c +++ b/uisimulator/sdl/lcd-sdl.c | |||
@@ -17,296 +17,67 @@ | |||
17 | * | 17 | * |
18 | ****************************************************************************/ | 18 | ****************************************************************************/ |
19 | 19 | ||
20 | #include "lcd-sdl.h" | ||
20 | #include "uisdl.h" | 21 | #include "uisdl.h" |
21 | #include "lcd.h" | ||
22 | #include "lcd-playersim.h" | ||
23 | 22 | ||
24 | SDL_Surface* lcd_surface; | 23 | int display_zoom = 1; |
25 | 24 | ||
26 | #if LCD_DEPTH == 16 | 25 | void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width, |
27 | #else | 26 | int height, int max_x, int max_y, int ui_x, int ui_y, |
28 | SDL_Color lcd_palette[(1<<LCD_DEPTH)]; | 27 | Uint32 (*getpixel)(int, int)) |
29 | SDL_Color lcd_color_zero = {UI_LCD_BGCOLORLIGHT, 0}; | ||
30 | SDL_Color lcd_color_max = {0, 0, 0, 0}; | ||
31 | |||
32 | #endif | ||
33 | |||
34 | #ifdef HAVE_LCD_BITMAP | ||
35 | |||
36 | #ifdef HAVE_REMOTE_LCD | ||
37 | SDL_Surface *remote_surface; | ||
38 | SDL_Color remote_palette[(1<<LCD_REMOTE_DEPTH)]; | ||
39 | SDL_Color remote_color_zero = {UI_REMOTE_BGCOLORLIGHT, 0}; | ||
40 | SDL_Color remote_color_max = {0, 0, 0, 0}; | ||
41 | |||
42 | #endif | ||
43 | |||
44 | void lcd_update (void) | ||
45 | { | ||
46 | /* update a full screen rect */ | ||
47 | lcd_update_rect(0, 0, LCD_WIDTH, LCD_HEIGHT); | ||
48 | } | ||
49 | |||
50 | void lcd_update_rect(int x_start, int y_start, int width, int height) | ||
51 | { | 28 | { |
52 | int x, y; | 29 | int x, y; |
53 | int xmax, ymax; | 30 | int xmax, ymax; |
31 | SDL_Rect dest; | ||
54 | 32 | ||
55 | ymax = y_start + height; | 33 | ymax = y_start + height; |
56 | xmax = x_start + width; | 34 | xmax = x_start + width; |
57 | 35 | ||
58 | if(xmax > LCD_WIDTH) | 36 | if(xmax > max_x) |
59 | xmax = LCD_WIDTH; | 37 | xmax = max_x; |
60 | if(ymax >= LCD_HEIGHT) | 38 | if(ymax >= max_y) |
61 | ymax = LCD_HEIGHT; | 39 | ymax = max_y; |
62 | |||
63 | SDL_LockSurface(lcd_surface); | ||
64 | 40 | ||
65 | int bpp = lcd_surface->format->BytesPerPixel; | 41 | SDL_LockSurface(surface); |
66 | 42 | ||
67 | for (x = x_start; x < xmax; x++) | 43 | dest.w = display_zoom; |
68 | { | 44 | dest.h = display_zoom; |
69 | for (y = y_start; y < ymax; y++) | 45 | |
70 | { | 46 | for (x = x_start; x < xmax; x++) { |
71 | Uint8 *p = (Uint8 *)lcd_surface->pixels + y * lcd_surface->pitch + x * bpp; | 47 | dest.x = x * display_zoom; |
72 | 48 | ||
73 | #if LCD_DEPTH == 1 | 49 | for (y = y_start; y < ymax; y++) { |
74 | *p = ((lcd_framebuffer[y/8][x] >> (y & 7)) & 1); | 50 | dest.y = y * display_zoom; |
75 | #elif LCD_DEPTH == 2 | 51 | |
76 | #if LCD_PIXELFORMAT == HORIZONTAL_PACKING | 52 | SDL_FillRect(surface, &dest, getpixel(x, y)); |
77 | *p = ((lcd_framebuffer[y][x/4] >> (2 * (x & 3))) & 3); | ||
78 | #else | ||
79 | *p = ((lcd_framebuffer[y/4][x] >> (2 * (y & 3))) & 3); | ||
80 | #endif | ||
81 | #elif LCD_DEPTH == 16 | ||
82 | #if LCD_PIXELFORMAT == RGB565SWAPPED | ||
83 | unsigned bits = lcd_framebuffer[y][x]; | ||
84 | *(Uint16 *)p = (bits >> 8) | (bits << 8); | ||
85 | #else | ||
86 | *(Uint16 *)p = lcd_framebuffer[y][x]; | ||
87 | #endif | ||
88 | #endif | ||
89 | } | 53 | } |
90 | } | 54 | } |
91 | 55 | ||
92 | SDL_UnlockSurface(lcd_surface); | 56 | SDL_UnlockSurface(surface); |
93 | |||
94 | SDL_Rect src = {x_start, y_start, xmax, ymax}; | ||
95 | SDL_Rect dest = {UI_LCD_POSX + x_start, UI_LCD_POSY + y_start, xmax, ymax}; | ||
96 | 57 | ||
97 | if (!background) { | 58 | SDL_Rect src = {x_start * display_zoom, y_start * display_zoom, xmax * display_zoom, ymax * display_zoom}; |
98 | dest.x -= UI_LCD_POSX; | 59 | dest.x = (ui_x + x_start) * display_zoom; |
99 | dest.y -= UI_LCD_POSY; | 60 | dest.y = (ui_y + y_start) * display_zoom;; |
100 | } | 61 | dest.w = xmax * display_zoom; |
62 | dest.h = ymax * display_zoom; | ||
101 | 63 | ||
102 | SDL_BlitSurface(lcd_surface, &src, gui_surface, &dest); | 64 | SDL_BlitSurface(surface, &src, gui_surface, &dest); |
103 | SDL_UpdateRect(gui_surface, dest.x, dest.y, dest.w, dest.h); | 65 | SDL_UpdateRect(gui_surface, dest.x, dest.y, dest.w, dest.h); |
104 | SDL_Flip(gui_surface); | 66 | SDL_Flip(gui_surface); |
105 | |||
106 | } | 67 | } |
107 | 68 | ||
108 | #ifdef HAVE_REMOTE_LCD | ||
109 | |||
110 | extern unsigned char lcd_remote_framebuffer[LCD_REMOTE_HEIGHT/8][LCD_REMOTE_WIDTH]; | ||
111 | |||
112 | void lcd_remote_update (void) | ||
113 | { | ||
114 | lcd_remote_update_rect(0, 0, LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT); | ||
115 | } | ||
116 | |||
117 | void lcd_remote_update_rect(int x_start, int y_start, | ||
118 | int width, int height) | ||
119 | { | ||
120 | int x, y; | ||
121 | int xmax, ymax; | ||
122 | |||
123 | ymax = y_start + height; | ||
124 | xmax = x_start + width; | ||
125 | |||
126 | if(xmax > LCD_REMOTE_WIDTH) | ||
127 | xmax = LCD_REMOTE_WIDTH; | ||
128 | if(ymax >= LCD_REMOTE_HEIGHT) | ||
129 | ymax = LCD_REMOTE_HEIGHT; | ||
130 | |||
131 | SDL_LockSurface(remote_surface); | ||
132 | |||
133 | int bpp = remote_surface->format->BytesPerPixel; | ||
134 | |||
135 | for (x = x_start; x < xmax; x++) | ||
136 | for (y = y_start; y < ymax; y++) | ||
137 | { | ||
138 | Uint8 *p = (Uint8 *)remote_surface->pixels + y * remote_surface->pitch + x * bpp; | ||
139 | |||
140 | *p = ((lcd_remote_framebuffer[y/8][x] >> (y & 7)) & 1); | ||
141 | } | ||
142 | |||
143 | SDL_UnlockSurface(remote_surface); | ||
144 | |||
145 | SDL_Rect src = {x_start, y_start, xmax, ymax}; | ||
146 | SDL_Rect dest = {UI_REMOTE_POSX + x_start, UI_REMOTE_POSY + y_start, xmax, ymax}; | ||
147 | |||
148 | if (!background) { | ||
149 | dest.x -= UI_REMOTE_POSX; | ||
150 | dest.y -= UI_REMOTE_POSY; | ||
151 | dest.y += UI_LCD_HEIGHT; | ||
152 | } | ||
153 | |||
154 | SDL_BlitSurface(remote_surface, &src, gui_surface, &dest); | ||
155 | SDL_UpdateRect(gui_surface, dest.x, dest.y, dest.w, dest.h); | ||
156 | SDL_Flip(gui_surface); | ||
157 | |||
158 | } | ||
159 | |||
160 | #endif /* HAVE_REMOTE_LCD */ | ||
161 | #endif /* HAVE_LCD_BITMAP */ | ||
162 | |||
163 | #ifdef HAVE_LCD_CHARCELLS | ||
164 | /* Defined in lcd-playersim.c */ | ||
165 | extern void lcd_print_char(int x, int y); | ||
166 | extern bool lcd_display_redraw; | ||
167 | extern unsigned char hardware_buffer_lcd[11][2]; | ||
168 | static unsigned char lcd_buffer_copy[11][2]; | ||
169 | |||
170 | void lcd_update(void) | ||
171 | { | ||
172 | int x, y; | ||
173 | bool changed = false; | ||
174 | SDL_Rect dest = {UI_LCD_POSX, UI_LCD_POSY, UI_LCD_WIDTH, UI_LCD_HEIGHT}; | ||
175 | |||
176 | for (y = 0; y < 2; y++) | ||
177 | { | ||
178 | for (x = 0; x < 11; x++) | ||
179 | { | ||
180 | if (lcd_display_redraw || | ||
181 | lcd_buffer_copy[x][y] != hardware_buffer_lcd[x][y]) | ||
182 | { | ||
183 | lcd_buffer_copy[x][y] = hardware_buffer_lcd[x][y]; | ||
184 | lcd_print_char(x, y); | ||
185 | changed = true; | ||
186 | } | ||
187 | } | ||
188 | } | ||
189 | |||
190 | if (changed) | ||
191 | { | ||
192 | if (!background) { | ||
193 | dest.x -= UI_LCD_POSX; | ||
194 | dest.y -= UI_LCD_POSY; | ||
195 | } | ||
196 | |||
197 | SDL_BlitSurface(lcd_surface, NULL, gui_surface, &dest); | ||
198 | SDL_UpdateRect(gui_surface, dest.x, dest.y, dest.w, dest.h); | ||
199 | SDL_Flip(gui_surface); | ||
200 | } | ||
201 | |||
202 | lcd_display_redraw = false; | ||
203 | } | ||
204 | |||
205 | void drawdots(int color, struct coordinate *points, int count) | ||
206 | { | ||
207 | int bpp = lcd_surface->format->BytesPerPixel; | ||
208 | |||
209 | SDL_LockSurface(lcd_surface); | ||
210 | |||
211 | while (count--) | ||
212 | { | ||
213 | Uint8 *p = (Uint8 *)lcd_surface->pixels + (points[count].y) * lcd_surface->pitch + (points[count].x) * bpp; | ||
214 | |||
215 | *p = color; | ||
216 | } | ||
217 | |||
218 | SDL_UnlockSurface(lcd_surface); | ||
219 | } | ||
220 | |||
221 | void drawrectangles(int color, struct rectangle *points, int count) | ||
222 | { | ||
223 | int bpp = lcd_surface->format->BytesPerPixel; | ||
224 | |||
225 | SDL_LockSurface(lcd_surface); | ||
226 | |||
227 | while (count--) | ||
228 | { | ||
229 | int x; | ||
230 | int y; | ||
231 | int ix; | ||
232 | int iy; | ||
233 | |||
234 | for (x = points[count].x, ix = 0; ix < points[count].width; x++, ix++) | ||
235 | { | ||
236 | for (y = points[count].y, iy = 0; iy < points[count].height; y++, iy++) | ||
237 | { | ||
238 | Uint8 *p = (Uint8 *)lcd_surface->pixels + y * lcd_surface->pitch + x * bpp; | ||
239 | |||
240 | *p = color; | ||
241 | } | ||
242 | } | ||
243 | } | ||
244 | |||
245 | SDL_UnlockSurface(lcd_surface); | ||
246 | } | ||
247 | #endif /* HAVE_LCD_CHARCELLS */ | ||
248 | |||
249 | #if LCD_DEPTH <= 8 | ||
250 | /* set a range of bitmap indices to a gradient from startcolour to endcolour */ | 69 | /* set a range of bitmap indices to a gradient from startcolour to endcolour */ |
251 | void lcdcolors(int index, int count, SDL_Color *start, SDL_Color *end) | 70 | void sdl_set_gradient(SDL_Surface *surface, SDL_Color *start, SDL_Color *end, int steps) |
252 | { | 71 | { |
253 | int i; | 72 | int i; |
73 | SDL_Color palette[steps]; | ||
254 | 74 | ||
255 | count--; | 75 | for (i = 0; i < steps; i++) { |
256 | for (i = 0; i <= count; i++) | 76 | palette[i].r = start->r + (end->r - start->r) * i / steps; |
257 | { | 77 | palette[i].g = start->g + (end->g - start->g) * i / steps; |
258 | lcd_palette[i+index].r = start->r | 78 | palette[i].b = start->b + (end->b - start->b) * i / steps; |
259 | + (end->r - start->r) * i / count; | ||
260 | lcd_palette[i+index].g = start->g | ||
261 | + (end->g - start->g) * i / count; | ||
262 | lcd_palette[i+index].b = start->b | ||
263 | + (end->b - start->b) * i / count; | ||
264 | } | 79 | } |
265 | 80 | ||
266 | SDL_SetPalette(lcd_surface, SDL_LOGPAL|SDL_PHYSPAL, lcd_palette, index, count); | 81 | SDL_SetPalette(surface, SDL_LOGPAL|SDL_PHYSPAL, palette, 0, steps); |
267 | } | 82 | } |
268 | #endif | ||
269 | 83 | ||
270 | #ifdef HAVE_REMOTE_LCD | ||
271 | /* set a range of bitmap indices to a gradient from startcolour to endcolour */ | ||
272 | void lcdremotecolors(int index, int count, SDL_Color *start, SDL_Color *end) | ||
273 | { | ||
274 | int i; | ||
275 | |||
276 | count--; | ||
277 | for (i = 0; i <= count; i++) | ||
278 | { | ||
279 | remote_palette[i+index].r = start->r | ||
280 | + (end->r - start->r) * i / count; | ||
281 | remote_palette[i+index].g = start->g | ||
282 | + (end->g - start->g) * i / count; | ||
283 | remote_palette[i+index].b = start->b | ||
284 | + (end->b - start->b) * i / count; | ||
285 | } | ||
286 | |||
287 | SDL_SetPalette(remote_surface, SDL_LOGPAL|SDL_PHYSPAL, remote_palette, index, count); | ||
288 | } | ||
289 | #endif | ||
290 | |||
291 | /* initialise simulator lcd driver */ | ||
292 | void simlcdinit(void) | ||
293 | { | ||
294 | #if LCD_DEPTH == 16 | ||
295 | lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, LCD_WIDTH, LCD_HEIGHT, 16, | ||
296 | 0, 0, 0, 0); | ||
297 | #else | ||
298 | lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, LCD_WIDTH, LCD_HEIGHT, 8, | ||
299 | 0, 0, 0, 0); | ||
300 | #endif | ||
301 | |||
302 | #if LCD_DEPTH <= 8 | ||
303 | lcdcolors(0, (1<<LCD_DEPTH), &lcd_color_zero, &lcd_color_max); | ||
304 | #endif | ||
305 | |||
306 | #ifdef HAVE_REMOTE_LCD | ||
307 | remote_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT, 8, | ||
308 | 0, 0, 0, 0); | ||
309 | |||
310 | lcdremotecolors(0, (1<<LCD_REMOTE_DEPTH), &remote_color_zero, &remote_color_max); | ||
311 | #endif | ||
312 | } | ||