Update the API version too.
[kugel-rb.git] / uisimulator / sdl / lcd-sdl.c
blob6431c5f39d027b9afc08df0b1fc6f33d06b9eb8e
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2006 Dan Everton
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "lcd-sdl.h"
23 #include "uisdl.h"
25 int display_zoom = 1;
26 #ifdef UI_LCD_SPLIT
27 static int gradient_steps = 0;
28 #endif
30 void sdl_update_rect(SDL_Surface *surface, int x_start, int y_start, int width,
31 int height, int max_x, int max_y,
32 unsigned long (*getpixel)(int, int))
34 int x, y;
35 int xmax, ymax;
36 SDL_Rect dest;
38 ymax = y_start + height;
39 xmax = x_start + width;
41 if(xmax > max_x)
42 xmax = max_x;
43 if(ymax >= max_y)
44 ymax = max_y;
46 SDL_LockSurface(surface);
48 dest.w = display_zoom;
49 dest.h = display_zoom;
51 for (x = x_start; x < xmax; x++) {
52 dest.x = x * display_zoom;
54 for (y = y_start; y < ymax; y++) {
55 dest.y = y * display_zoom;
57 SDL_FillRect(surface, &dest, (Uint32)getpixel(x, y));
61 SDL_UnlockSurface(surface);
64 void sdl_gui_update(SDL_Surface *surface, IFSPLIT(SDL_Surface *real_surface,)
65 int x_start, int y_start, int width,
66 int height, int max_x, int max_y, int ui_x, int ui_y)
68 int xmax, ymax;
70 ymax = y_start + height;
71 xmax = x_start + width;
73 if(xmax > max_x)
74 xmax = max_x;
75 if(ymax >= max_y)
76 ymax = max_y;
78 SDL_Rect src = {x_start * display_zoom, y_start * display_zoom,
79 xmax * display_zoom, ymax * display_zoom};
80 SDL_Rect dest= {(ui_x + x_start) * display_zoom, (ui_y + y_start) * display_zoom,
81 xmax * display_zoom, ymax * display_zoom};
83 #ifdef UI_LCD_SPLIT
84 /* fix real screen coordinates */
85 if(ymax >= UI_LCD_SPLIT_LINES)
86 src.h += UI_LCD_SPLIT_BLACK_LINES * display_zoom;
88 SDL_LockSurface(surface);
89 SDL_LockSurface(real_surface);
91 int pixel, npixels;
93 #if LCD_DEPTH != 1
94 #error "Split screen only works for monochrome displays !"
95 #endif
97 npixels = display_zoom * display_zoom * UI_LCD_SPLIT_LINES * surface->pitch;
98 const unsigned char * pixels_src = (const unsigned char*)surface->pixels;
99 unsigned char * pixels_dst = (unsigned char*)real_surface->pixels;
100 const int start_pixel = UI_LCD_SPLIT_LINES * surface->pitch * display_zoom;
101 const int stop_pixel = (UI_LCD_SPLIT_LINES+UI_LCD_SPLIT_BLACK_LINES)
102 * surface->pitch * display_zoom;
104 /* draw top pixels, change the color */
105 for (pixel = 0; pixel < npixels ; pixel++)
107 int pix = pixels_src[pixel] + gradient_steps;
108 if(pix > 255) pix = 255;
110 pixels_dst[pixel] = pix;
113 /* copy bottom pixels */
114 memcpy(&pixels_dst[stop_pixel], &pixels_src[start_pixel],
115 (UI_LCD_HEIGHT - UI_LCD_SPLIT_LINES) * surface->pitch * display_zoom);
117 /* separation lines are off */
118 for (pixel = start_pixel; pixel < stop_pixel ; pixel++)
119 pixels_dst[pixel] = 0;
121 SDL_UnlockSurface(surface);
122 SDL_UnlockSurface(real_surface);
124 SDL_BlitSurface(real_surface, &src, gui_surface, &dest);
125 #else
126 SDL_BlitSurface(surface, &src, gui_surface, &dest);
127 #endif
129 SDL_Flip(gui_surface);
132 /* set a range of bitmap indices to a gradient from startcolour to endcolour */
133 void sdl_set_gradient(SDL_Surface *surface, SDL_Color *start, SDL_Color *end,
134 IFSPLIT(SDL_Color *split_start,)
135 IFSPLIT(SDL_Color *split_end ,) int first, int steps)
137 int i;
139 #ifdef UI_LCD_SPLIT
140 int tot_steps = steps * 2;
141 if (tot_steps > 256)
142 tot_steps = 256;
144 gradient_steps = steps;
145 #else
146 #define tot_steps steps
147 #endif
149 SDL_Color palette[tot_steps];
151 for (i = 0; i < steps; i++) {
152 palette[i].r = start->r + (end->r - start->r) * i / (steps - 1);
153 palette[i].g = start->g + (end->g - start->g) * i / (steps - 1);
154 palette[i].b = start->b + (end->b - start->b) * i / (steps - 1);
157 #ifdef UI_LCD_SPLIT /* extra color */
158 for (i = steps ; i < tot_steps; i++) {
159 palette[i].r = split_start->r + (split_end->r - split_start->r) * (i - steps) / (tot_steps - steps - 1);
160 palette[i].g = split_start->g + (split_end->g - split_start->g) * (i - steps) / (tot_steps - steps - 1);
161 palette[i].b = split_start->b + (split_end->b - split_start->b) * (i - steps) / (tot_steps - steps - 1);
163 #endif
165 SDL_SetPalette(surface, SDL_LOGPAL|SDL_PHYSPAL, palette, first, tot_steps);