summaryrefslogtreecommitdiff
path: root/uisimulator/sdl
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2006-02-26 13:37:42 +0000
committerJens Arnold <amiconn@rockbox.org>2006-02-26 13:37:42 +0000
commit6a972e02497d3015236189f72931c3d59fa51755 (patch)
tree0c0185dd66b47d7d1ee2d91e4a3ffb6dbabcc7d1 /uisimulator/sdl
parent14fe89aa8d2ef05595bdba0e0b78f021f3e8d087 (diff)
downloadrockbox-6a972e02497d3015236189f72931c3d59fa51755.tar.gz
rockbox-6a972e02497d3015236189f72931c3d59fa51755.zip
Finally - grayscale library support for the simulators. Currently SDL only, win32 and x11 won't link anymore due to missing simulator functions.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8845 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'uisimulator/sdl')
-rw-r--r--uisimulator/sdl/lcd-bitmap.c89
-rw-r--r--uisimulator/sdl/lcd-bitmap.h4
-rw-r--r--uisimulator/sdl/lcd-charcell.c9
-rw-r--r--uisimulator/sdl/lcd-remote.c19
-rw-r--r--uisimulator/sdl/lcd-sdl.c36
-rw-r--r--uisimulator/sdl/lcd-sdl.h9
6 files changed, 128 insertions, 38 deletions
diff --git a/uisimulator/sdl/lcd-bitmap.c b/uisimulator/sdl/lcd-bitmap.c
index 2fd7576ecc..788a5f662d 100644
--- a/uisimulator/sdl/lcd-bitmap.c
+++ b/uisimulator/sdl/lcd-bitmap.c
@@ -22,6 +22,7 @@
22#include "lcd-sdl.h" 22#include "lcd-sdl.h"
23 23
24SDL_Surface* lcd_surface; 24SDL_Surface* lcd_surface;
25int lcd_backlight_val;
25 26
26#if LCD_DEPTH <= 8 27#if LCD_DEPTH <= 8
27SDL_Color lcd_color_zero = {UI_LCD_BGCOLOR, 0}; 28SDL_Color lcd_color_zero = {UI_LCD_BGCOLOR, 0};
@@ -29,22 +30,27 @@ SDL_Color lcd_backlight_color_zero = {UI_LCD_BGCOLORLIGHT, 0};
29SDL_Color lcd_color_max = {0, 0, 0, 0}; 30SDL_Color lcd_color_max = {0, 0, 0, 0};
30#endif 31#endif
31 32
32static inline Uint32 get_lcd_pixel(int x, int y) 33#if LCD_DEPTH < 8
34int lcd_ex_shades = 0;
35unsigned long (*lcd_ex_getpixel)(int, int) = NULL;
36#endif
37
38static unsigned long get_lcd_pixel(int x, int y)
33{ 39{
34#if LCD_DEPTH == 1 40#if LCD_DEPTH == 1
35 return ((lcd_framebuffer[y/8][x] >> (y & 7)) & 1); 41 return ((lcd_framebuffer[y/8][x] >> (y & 7)) & 1);
36#elif LCD_DEPTH == 2 42#elif LCD_DEPTH == 2
37#if LCD_PIXELFORMAT == HORIZONTAL_PACKING 43#if LCD_PIXELFORMAT == HORIZONTAL_PACKING
38 return ((lcd_framebuffer[y][x/4] >> (2 * (x & 3))) & 3); 44 return ((lcd_framebuffer[y][x/4] >> (2 * (x & 3))) & 3);
39#else 45#else
40 return ((lcd_framebuffer[y/4][x] >> (2 * (y & 3))) & 3); 46 return ((lcd_framebuffer[y/4][x] >> (2 * (y & 3))) & 3);
41#endif 47#endif
42#elif LCD_DEPTH == 16 48#elif LCD_DEPTH == 16
43#if LCD_PIXELFORMAT == RGB565SWAPPED 49#if LCD_PIXELFORMAT == RGB565SWAPPED
44 unsigned bits = lcd_framebuffer[y][x]; 50 unsigned bits = lcd_framebuffer[y][x];
45 return (bits >> 8) | (bits << 8); 51 return (bits >> 8) | (bits << 8);
46#else 52#else
47 return lcd_framebuffer[y][x]; 53 return lcd_framebuffer[y][x];
48#endif 54#endif
49#endif 55#endif
50} 56}
@@ -57,22 +63,41 @@ void lcd_update(void)
57 63
58void lcd_update_rect(int x_start, int y_start, int width, int height) 64void lcd_update_rect(int x_start, int y_start, int width, int height)
59{ 65{
60 sdl_update_rect(lcd_surface, x_start, y_start, width, height, LCD_WIDTH, LCD_HEIGHT, 66 sdl_update_rect(lcd_surface, x_start, y_start, width, height, LCD_WIDTH,
61 background ? UI_LCD_POSX : 0, background? UI_LCD_POSY : 0, 67 LCD_HEIGHT, get_lcd_pixel);
62 get_lcd_pixel); 68 sdl_gui_update(lcd_surface, x_start, y_start, width, height, LCD_WIDTH,
69 LCD_HEIGHT, background ? UI_LCD_POSX : 0, background? UI_LCD_POSY : 0);
63} 70}
64 71
65#ifdef CONFIG_BACKLIGHT 72#ifdef CONFIG_BACKLIGHT
66void sim_backlight(int value) 73void sim_backlight(int value)
67{ 74{
75 lcd_backlight_val = value;
76
68#if LCD_DEPTH <= 8 77#if LCD_DEPTH <= 8
69 if (value > 0) { 78 if (value > 0) {
70 sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero, &lcd_color_max, (1<<LCD_DEPTH)); 79 sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero,
80 &lcd_color_max, 0, (1<<LCD_DEPTH));
71 } else { 81 } else {
72 sdl_set_gradient(lcd_surface, &lcd_color_zero, &lcd_color_max, (1<<LCD_DEPTH)); 82 sdl_set_gradient(lcd_surface, &lcd_color_zero, &lcd_color_max,
83 0, (1<<LCD_DEPTH));
73 } 84 }
74 85#if LCD_DEPTH < 8
75 lcd_update(); 86 if (lcd_ex_shades) {
87 if (value > 0) {
88 sdl_set_gradient(lcd_surface, &lcd_color_max,
89 &lcd_backlight_color_zero, (1<<LCD_DEPTH),
90 lcd_ex_shades);
91 } else {
92 sdl_set_gradient(lcd_surface, &lcd_color_max, &lcd_color_zero,
93 (1<<LCD_DEPTH), lcd_ex_shades);
94 }
95 }
96#endif
97
98 sdl_gui_update(lcd_surface, 0, 0, LCD_WIDTH, LCD_HEIGHT, LCD_WIDTH,
99 LCD_HEIGHT, background ? UI_LCD_POSX : 0, background? UI_LCD_POSY : 0);
100
76#else 101#else
77 DEBUGF("backlight: %s\n", (value > 0) ? "on" : "off"); 102 DEBUGF("backlight: %s\n", (value > 0) ? "on" : "off");
78#endif 103#endif
@@ -91,7 +116,41 @@ void sim_lcd_init(void)
91#endif 116#endif
92 117
93#if LCD_DEPTH <= 8 118#if LCD_DEPTH <= 8
94 sdl_set_gradient(lcd_surface, &lcd_color_zero, &lcd_color_max, (1<<LCD_DEPTH)); 119 sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero, &lcd_color_max,
120 0, (1<<LCD_DEPTH));
121#endif
122}
123
124#if LCD_DEPTH < 8
125void sim_lcd_ex_init(int shades, unsigned long (*getpixel)(int, int))
126{
127 lcd_ex_shades = shades;
128 lcd_ex_getpixel = getpixel;
129 if (shades) {
130#ifdef CONFIG_BACKLIGHT
131 if (lcd_backlight_val > 0) {
132 sdl_set_gradient(lcd_surface, &lcd_color_max,
133 &lcd_backlight_color_zero, (1<<LCD_DEPTH),
134 shades);
135 }
136 else
95#endif 137#endif
138 {
139 sdl_set_gradient(lcd_surface, &lcd_color_max, &lcd_color_zero,
140 (1<<LCD_DEPTH), shades);
141 }
142 }
96} 143}
97 144
145void sim_lcd_ex_update_rect(int x_start, int y_start, int width, int height)
146{
147 if (lcd_ex_getpixel) {
148 sdl_update_rect(lcd_surface, x_start, y_start, width, height,
149 LCD_WIDTH, LCD_HEIGHT, lcd_ex_getpixel);
150 sdl_gui_update(lcd_surface, x_start, y_start, width, height, LCD_WIDTH,
151 LCD_HEIGHT, background ? UI_LCD_POSX : 0,
152 background? UI_LCD_POSY : 0);
153 }
154}
155#endif
156
diff --git a/uisimulator/sdl/lcd-bitmap.h b/uisimulator/sdl/lcd-bitmap.h
index 514c4d3ffb..31403385b9 100644
--- a/uisimulator/sdl/lcd-bitmap.h
+++ b/uisimulator/sdl/lcd-bitmap.h
@@ -24,6 +24,10 @@
24#include "SDL.h" 24#include "SDL.h"
25 25
26void sim_lcd_init(void); 26void sim_lcd_init(void);
27#if LCD_DEPTH < 8
28void sim_lcd_ex_init(int shades, unsigned long (*getpixel)(int, int));
29void sim_lcd_ex_update_rect(int x, int y, int width, int height);
30#endif
27 31
28#endif // #ifndef __LCDBITMAP_H__ 32#endif // #ifndef __LCDBITMAP_H__
29 33
diff --git a/uisimulator/sdl/lcd-charcell.c b/uisimulator/sdl/lcd-charcell.c
index 2ef86d0baf..89c46f7738 100644
--- a/uisimulator/sdl/lcd-charcell.c
+++ b/uisimulator/sdl/lcd-charcell.c
@@ -109,9 +109,11 @@ void drawrectangles(int color, struct rectangle *points, int count)
109void sim_backlight(int value) 109void sim_backlight(int value)
110{ 110{
111 if (value > 0) { 111 if (value > 0) {
112 sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero, &lcd_color_max, (1<<LCD_DEPTH)); 112 sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero, &lcd_color_max,
113 0, (1<<LCD_DEPTH));
113 } else { 114 } else {
114 sdl_set_gradient(lcd_surface, &lcd_color_zero, &lcd_color_max, (1<<LCD_DEPTH)); 115 sdl_set_gradient(lcd_surface, &lcd_color_zero, &lcd_color_max,
116 0, (1<<LCD_DEPTH));
115 } 117 }
116 118
117 lcd_update(); 119 lcd_update();
@@ -124,6 +126,7 @@ void sim_lcd_init(void)
124 lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, LCD_WIDTH * display_zoom, 126 lcd_surface = SDL_CreateRGBSurface(SDL_SWSURFACE, LCD_WIDTH * display_zoom,
125 LCD_HEIGHT * display_zoom, 8, 0, 0, 0, 0); 127 LCD_HEIGHT * display_zoom, 8, 0, 0, 0, 0);
126 128
127 sdl_set_gradient(lcd_surface, &lcd_color_zero, &lcd_color_max, (1<<LCD_DEPTH)); 129 sdl_set_gradient(lcd_surface, &lcd_backlight_color_zero, &lcd_color_max,
130 0, (1<<LCD_DEPTH));
128} 131}
129 132
diff --git a/uisimulator/sdl/lcd-remote.c b/uisimulator/sdl/lcd-remote.c
index 64b641ad6d..f1d04b33f8 100644
--- a/uisimulator/sdl/lcd-remote.c
+++ b/uisimulator/sdl/lcd-remote.c
@@ -41,19 +41,26 @@ void lcd_remote_update (void)
41void lcd_remote_update_rect(int x_start, int y_start, int width, int height) 41void lcd_remote_update_rect(int x_start, int y_start, int width, int height)
42{ 42{
43 sdl_update_rect(remote_surface, x_start, y_start, width, height, 43 sdl_update_rect(remote_surface, x_start, y_start, width, height,
44 LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT, get_lcd_remote_pixel);
45 sdl_gui_update(remote_surface, x_start, y_start, width, height,
44 LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT, background ? UI_REMOTE_POSX : 0, 46 LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT, background ? UI_REMOTE_POSX : 0,
45 (background ? UI_REMOTE_POSY : LCD_HEIGHT), get_lcd_remote_pixel); 47 background ? UI_REMOTE_POSY : LCD_HEIGHT);
46} 48}
47 49
48void sim_remote_backlight(int value) 50void sim_remote_backlight(int value)
49{ 51{
50 if (value > 0) { 52 if (value > 0) {
51 sdl_set_gradient(remote_surface, &remote_backlight_color_zero, &remote_color_max, (1<<LCD_REMOTE_DEPTH)); 53 sdl_set_gradient(remote_surface, &remote_backlight_color_zero,
54 &remote_color_max, 0, (1<<LCD_REMOTE_DEPTH));
52 } else { 55 } else {
53 sdl_set_gradient(remote_surface, &remote_color_zero, &remote_color_max, (1<<LCD_REMOTE_DEPTH)); 56 sdl_set_gradient(remote_surface, &remote_color_zero, &remote_color_max,
57 0, (1<<LCD_REMOTE_DEPTH));
54 } 58 }
55 59
56 lcd_remote_update(); 60 sdl_gui_update(remote_surface, 0, 0, LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT,
61 LCD_REMOTE_WIDTH, LCD_REMOTE_HEIGHT,
62 background ? UI_REMOTE_POSX : 0,
63 background? UI_REMOTE_POSY : LCD_HEIGHT);
57} 64}
58 65
59/* initialise simulator lcd remote driver */ 66/* initialise simulator lcd remote driver */
@@ -63,7 +70,7 @@ void sim_lcd_remote_init(void)
63 LCD_REMOTE_WIDTH * display_zoom, LCD_REMOTE_HEIGHT * display_zoom, 70 LCD_REMOTE_WIDTH * display_zoom, LCD_REMOTE_HEIGHT * display_zoom,
64 8, 0, 0, 0, 0); 71 8, 0, 0, 0, 0);
65 72
66 sdl_set_gradient(remote_surface, &remote_color_zero, &remote_color_max, 73 sdl_set_gradient(remote_surface, &remote_backlight_color_zero,
67 (1<<LCD_REMOTE_DEPTH)); 74 &remote_color_max, 0, (1<<LCD_REMOTE_DEPTH));
68} 75}
69 76
diff --git a/uisimulator/sdl/lcd-sdl.c b/uisimulator/sdl/lcd-sdl.c
index 3327dd8350..be10b468cb 100644
--- a/uisimulator/sdl/lcd-sdl.c
+++ b/uisimulator/sdl/lcd-sdl.c
@@ -23,8 +23,8 @@
23int display_zoom = 1; 23int display_zoom = 1;
24 24
25void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width, 25void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width,
26 int height, int max_x, int max_y, int ui_x, int ui_y, 26 int height, int max_x, int max_y,
27 Uint32 (*getpixel)(int, int)) 27 unsigned long (*getpixel)(int, int))
28{ 28{
29 int x, y; 29 int x, y;
30 int xmax, ymax; 30 int xmax, ymax;
@@ -49,25 +49,39 @@ void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width,
49 for (y = y_start; y < ymax; y++) { 49 for (y = y_start; y < ymax; y++) {
50 dest.y = y * display_zoom; 50 dest.y = y * display_zoom;
51 51
52 SDL_FillRect(surface, &dest, getpixel(x, y)); 52 SDL_FillRect(surface, &dest, (Uint32)getpixel(x, y));
53 } 53 }
54 } 54 }
55 55
56 SDL_UnlockSurface(surface); 56 SDL_UnlockSurface(surface);
57}
58
59void sdl_gui_update(SDL_Surface *surface, int x_start, int y_start, int width,
60 int height, int max_x, int max_y, int ui_x, int ui_y)
61{
62 int xmax, ymax;
63
64 ymax = y_start + height;
65 xmax = x_start + width;
66
67 if(xmax > max_x)
68 xmax = max_x;
69 if(ymax >= max_y)
70 ymax = max_y;
71
72 SDL_Rect src = {x_start * display_zoom, y_start * display_zoom,
73 xmax * display_zoom, ymax * display_zoom};
74 SDL_Rect dest= {(ui_x + x_start) * display_zoom, (ui_y + y_start) * display_zoom,
75 xmax * display_zoom, ymax * display_zoom};
57 76
58 SDL_Rect src = {x_start * display_zoom, y_start * display_zoom, xmax * display_zoom, ymax * display_zoom};
59 dest.x = (ui_x + x_start) * display_zoom;
60 dest.y = (ui_y + y_start) * display_zoom;;
61 dest.w = xmax * display_zoom;
62 dest.h = ymax * display_zoom;
63
64 SDL_BlitSurface(surface, &src, gui_surface, &dest); 77 SDL_BlitSurface(surface, &src, gui_surface, &dest);
65 SDL_UpdateRect(gui_surface, dest.x, dest.y, dest.w, dest.h); 78 SDL_UpdateRect(gui_surface, dest.x, dest.y, dest.w, dest.h);
66 SDL_Flip(gui_surface); 79 SDL_Flip(gui_surface);
67} 80}
68 81
69/* set a range of bitmap indices to a gradient from startcolour to endcolour */ 82/* set a range of bitmap indices to a gradient from startcolour to endcolour */
70void sdl_set_gradient(SDL_Surface *surface, SDL_Color *start, SDL_Color *end, int steps) 83void sdl_set_gradient(SDL_Surface *surface, SDL_Color *start, SDL_Color *end,
84 int first, int steps)
71{ 85{
72 int i; 86 int i;
73 SDL_Color palette[steps]; 87 SDL_Color palette[steps];
@@ -78,6 +92,6 @@ void sdl_set_gradient(SDL_Surface *surface, SDL_Color *start, SDL_Color *end, in
78 palette[i].b = start->b + (end->b - start->b) * i / (steps - 1); 92 palette[i].b = start->b + (end->b - start->b) * i / (steps - 1);
79 } 93 }
80 94
81 SDL_SetPalette(surface, SDL_LOGPAL|SDL_PHYSPAL, palette, 0, steps); 95 SDL_SetPalette(surface, SDL_LOGPAL|SDL_PHYSPAL, palette, first, steps);
82} 96}
83 97
diff --git a/uisimulator/sdl/lcd-sdl.h b/uisimulator/sdl/lcd-sdl.h
index d371639a64..10c2ea74b5 100644
--- a/uisimulator/sdl/lcd-sdl.h
+++ b/uisimulator/sdl/lcd-sdl.h
@@ -27,11 +27,14 @@
27extern int display_zoom; 27extern int display_zoom;
28 28
29void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width, 29void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width,
30 int height, int max_x, int max_y, int ui_x, int ui_y, 30 int height, int max_x, int max_y,
31 Uint32 (*getpixel)(int, int)); 31 unsigned long (*getpixel)(int, int));
32
33void sdl_gui_update(SDL_Surface *surface, int x_start, int y_start, int width,
34 int height, int max_x, int max_y, int ui_x, int ui_y);
32 35
33void sdl_set_gradient(SDL_Surface *surface, SDL_Color *start, SDL_Color *end, 36void sdl_set_gradient(SDL_Surface *surface, SDL_Color *start, SDL_Color *end,
34 int steps); 37 int first, int steps);
35 38
36#endif // #ifndef __LCDSDL_H__ 39#endif // #ifndef __LCDSDL_H__
37 40