diff options
Diffstat (limited to 'uisimulator/sdl/lcd-sdl.c')
-rw-r--r-- | uisimulator/sdl/lcd-sdl.c | 82 |
1 files changed, 76 insertions, 6 deletions
diff --git a/uisimulator/sdl/lcd-sdl.c b/uisimulator/sdl/lcd-sdl.c index 1014a371c0..a3dc87fed0 100644 --- a/uisimulator/sdl/lcd-sdl.c +++ b/uisimulator/sdl/lcd-sdl.c | |||
@@ -23,6 +23,9 @@ | |||
23 | #include "uisdl.h" | 23 | #include "uisdl.h" |
24 | 24 | ||
25 | int display_zoom = 1; | 25 | int display_zoom = 1; |
26 | #ifdef UI_LCD_SPLIT | ||
27 | static int gradient_steps = 0; | ||
28 | #endif | ||
26 | 29 | ||
27 | void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width, | 30 | void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width, |
28 | int height, int max_x, int max_y, | 31 | int height, int max_x, int max_y, |
@@ -44,13 +47,13 @@ void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width, | |||
44 | 47 | ||
45 | dest.w = display_zoom; | 48 | dest.w = display_zoom; |
46 | dest.h = display_zoom; | 49 | dest.h = display_zoom; |
47 | 50 | ||
48 | for (x = x_start; x < xmax; x++) { | 51 | for (x = x_start; x < xmax; x++) { |
49 | dest.x = x * display_zoom; | 52 | dest.x = x * display_zoom; |
50 | 53 | ||
51 | for (y = y_start; y < ymax; y++) { | 54 | for (y = y_start; y < ymax; y++) { |
52 | dest.y = y * display_zoom; | 55 | dest.y = y * display_zoom; |
53 | 56 | ||
54 | SDL_FillRect(surface, &dest, (Uint32)getpixel(x, y)); | 57 | SDL_FillRect(surface, &dest, (Uint32)getpixel(x, y)); |
55 | } | 58 | } |
56 | } | 59 | } |
@@ -58,9 +61,11 @@ void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width, | |||
58 | SDL_UnlockSurface(surface); | 61 | SDL_UnlockSurface(surface); |
59 | } | 62 | } |
60 | 63 | ||
61 | void sdl_gui_update(SDL_Surface *surface, int x_start, int y_start, int width, | 64 | void sdl_gui_update(SDL_Surface *surface, IFSPLIT(SDL_Surface *real_surface,) |
65 | int x_start, int y_start, int width, | ||
62 | int height, int max_x, int max_y, int ui_x, int ui_y) | 66 | int height, int max_x, int max_y, int ui_x, int ui_y) |
63 | { | 67 | { |
68 | printf("(%d, %d, %d, %d);\n", x_start, y_start, width, height); | ||
64 | int xmax, ymax; | 69 | int xmax, ymax; |
65 | 70 | ||
66 | ymax = y_start + height; | 71 | ymax = y_start + height; |
@@ -76,16 +81,73 @@ void sdl_gui_update(SDL_Surface *surface, int x_start, int y_start, int width, | |||
76 | SDL_Rect dest= {(ui_x + x_start) * display_zoom, (ui_y + y_start) * display_zoom, | 81 | SDL_Rect dest= {(ui_x + x_start) * display_zoom, (ui_y + y_start) * display_zoom, |
77 | xmax * display_zoom, ymax * display_zoom}; | 82 | xmax * display_zoom, ymax * display_zoom}; |
78 | 83 | ||
84 | #ifdef UI_LCD_SPLIT | ||
85 | /* fix real screen coordinates */ | ||
86 | if(ymax >= UI_LCD_SPLIT_LINES) | ||
87 | src.h += UI_LCD_SPLIT_BLACK_LINES * display_zoom; | ||
88 | |||
89 | SDL_LockSurface(surface); | ||
90 | SDL_LockSurface(real_surface); | ||
91 | |||
92 | int pixel, npixels; | ||
93 | |||
94 | #if LCD_DEPTH != 1 | ||
95 | #error "Split screen only works for monochrome displays !" | ||
96 | #endif | ||
97 | |||
98 | npixels = display_zoom * display_zoom * UI_LCD_SPLIT_LINES * surface->pitch; | ||
99 | const unsigned char * pixels_src = (const unsigned char*)surface->pixels; | ||
100 | unsigned char * pixels_dst = (unsigned char*)real_surface->pixels; | ||
101 | const int start_pixel = UI_LCD_SPLIT_LINES * surface->pitch * display_zoom; | ||
102 | const int stop_pixel = (UI_LCD_SPLIT_LINES+UI_LCD_SPLIT_BLACK_LINES) | ||
103 | * surface->pitch * display_zoom; | ||
104 | |||
105 | /* draw top pixels, change the color */ | ||
106 | for (pixel = 0; pixel < npixels ; pixel++) | ||
107 | { | ||
108 | int pix = pixels_src[pixel] + gradient_steps; | ||
109 | if(pix > 255) pix = 255; | ||
110 | |||
111 | pixels_dst[pixel] = pix; | ||
112 | } | ||
113 | |||
114 | /* copy bottom pixels */ | ||
115 | memcpy(&pixels_dst[stop_pixel], &pixels_src[start_pixel], | ||
116 | (UI_LCD_HEIGHT - UI_LCD_SPLIT_LINES) * surface->pitch * display_zoom); | ||
117 | |||
118 | /* separation lines are off */ | ||
119 | for (pixel = start_pixel; pixel < stop_pixel ; pixel++) | ||
120 | pixels_dst[pixel] = 0; | ||
121 | |||
122 | SDL_UnlockSurface(surface); | ||
123 | SDL_UnlockSurface(real_surface); | ||
124 | |||
125 | SDL_BlitSurface(real_surface, &src, gui_surface, &dest); | ||
126 | #else | ||
79 | SDL_BlitSurface(surface, &src, gui_surface, &dest); | 127 | SDL_BlitSurface(surface, &src, gui_surface, &dest); |
128 | #endif | ||
129 | |||
80 | SDL_Flip(gui_surface); | 130 | SDL_Flip(gui_surface); |
81 | } | 131 | } |
82 | 132 | ||
83 | /* set a range of bitmap indices to a gradient from startcolour to endcolour */ | 133 | /* set a range of bitmap indices to a gradient from startcolour to endcolour */ |
84 | void sdl_set_gradient(SDL_Surface *surface, SDL_Color *start, SDL_Color *end, | 134 | void sdl_set_gradient(SDL_Surface *surface, SDL_Color *start, SDL_Color *end, |
85 | int first, int steps) | 135 | IFSPLIT(SDL_Color *split_start,) |
136 | IFSPLIT(SDL_Color *split_end ,) int first, int steps) | ||
86 | { | 137 | { |
87 | int i; | 138 | int i; |
88 | SDL_Color palette[steps]; | 139 | |
140 | #ifdef UI_LCD_SPLIT | ||
141 | int tot_steps = steps * 2; | ||
142 | if (tot_steps > 256) | ||
143 | tot_steps = 256; | ||
144 | |||
145 | gradient_steps = steps; | ||
146 | #else | ||
147 | #define tot_steps steps | ||
148 | #endif | ||
149 | |||
150 | SDL_Color palette[tot_steps]; | ||
89 | 151 | ||
90 | for (i = 0; i < steps; i++) { | 152 | for (i = 0; i < steps; i++) { |
91 | palette[i].r = start->r + (end->r - start->r) * i / (steps - 1); | 153 | palette[i].r = start->r + (end->r - start->r) * i / (steps - 1); |
@@ -93,6 +155,14 @@ void sdl_set_gradient(SDL_Surface *surface, SDL_Color *start, SDL_Color *end, | |||
93 | palette[i].b = start->b + (end->b - start->b) * i / (steps - 1); | 155 | palette[i].b = start->b + (end->b - start->b) * i / (steps - 1); |
94 | } | 156 | } |
95 | 157 | ||
96 | SDL_SetPalette(surface, SDL_LOGPAL|SDL_PHYSPAL, palette, first, steps); | 158 | #ifdef UI_LCD_SPLIT /* extra color */ |
159 | for (i = steps ; i < tot_steps; i++) { | ||
160 | palette[i].r = split_start->r + (split_end->r - split_start->r) * (i - steps) / (tot_steps - steps - 1); | ||
161 | palette[i].g = split_start->g + (split_end->g - split_start->g) * (i - steps) / (tot_steps - steps - 1); | ||
162 | palette[i].b = split_start->b + (split_end->b - split_start->b) * (i - steps) / (tot_steps - steps - 1); | ||
163 | } | ||
164 | #endif | ||
165 | |||
166 | SDL_SetPalette(surface, SDL_LOGPAL|SDL_PHYSPAL, palette, first, tot_steps); | ||
97 | } | 167 | } |
98 | 168 | ||