Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
Zakk Roberts | b81f596 | 2006-03-21 02:02:04 +0000 | [diff] [blame] | 8 | * $Id$ |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 9 | * |
| 10 | * Copyright (C) Jonathan Gordon (2006) |
| 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 | ****************************************************************************/ |
Dave Chapman | 3ea74cc | 2006-07-19 14:31:24 +0000 | [diff] [blame] | 19 | #include "config.h" |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 20 | #include "stdarg.h" |
| 21 | #include "string.h" |
| 22 | #include "stdio.h" |
| 23 | #include "kernel.h" |
| 24 | #include "system.h" |
| 25 | #include "screen_access.h" |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 26 | #include "font.h" |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 27 | #include "debug.h" |
| 28 | #include "misc.h" |
| 29 | #include "settings.h" |
| 30 | #include "scrollbar.h" |
| 31 | #include "lang.h" |
Zakk Roberts | 87142ab | 2006-03-04 10:55:54 +0000 | [diff] [blame] | 32 | #include "splash.h" |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 33 | #include "action.h" |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 34 | #include "icon.h" |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 35 | |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 36 | /* structure for color info */ |
| 37 | struct rgb_pick |
| 38 | { |
| 39 | unsigned color; /* native color value */ |
| 40 | union |
| 41 | { |
| 42 | unsigned char rgb_val[6]; /* access to components as array */ |
| 43 | struct |
| 44 | { |
| 45 | unsigned char r; /* native red value */ |
| 46 | unsigned char g; /* native green value */ |
| 47 | unsigned char b; /* native blue value */ |
| 48 | unsigned char red; /* 8 bit red value */ |
| 49 | unsigned char green; /* 8 bit green value */ |
| 50 | unsigned char blue; /* 8 bit blue value */ |
| 51 | } __attribute__ ((__packed__)); /* assume byte packing */ |
| 52 | }; |
| 53 | }; |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 54 | |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 55 | |
| 56 | /* list of primary colors */ |
Michael Sevakis | 661c340 | 2006-10-13 04:16:49 +0000 | [diff] [blame] | 57 | #define SB_PRIM 0 |
| 58 | #define SB_FILL 1 |
Michael Sevakis | e0710b2 | 2006-10-15 17:51:00 +0000 | [diff] [blame] | 59 | static const fb_data prim_rgb[][3] = |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 60 | { |
Michael Sevakis | 661c340 | 2006-10-13 04:16:49 +0000 | [diff] [blame] | 61 | /* Foreground colors for sliders */ |
| 62 | { |
| 63 | LCD_RGBPACK(255, 0, 0), |
| 64 | LCD_RGBPACK( 0, 255, 0), |
| 65 | LCD_RGBPACK( 0, 0, 255), |
| 66 | }, |
| 67 | /* Fill colors for sliders */ |
| 68 | { |
| 69 | LCD_RGBPACK( 85, 0, 0), |
| 70 | LCD_RGBPACK( 0, 85, 0), |
| 71 | LCD_RGBPACK( 0, 0, 85), |
| 72 | }, |
Michael Sevakis | e0710b2 | 2006-10-15 17:51:00 +0000 | [diff] [blame] | 73 | }; |
| 74 | |
| 75 | /* maximum values for components */ |
| 76 | static const unsigned char rgb_max[3] = |
| 77 | { |
| 78 | LCD_MAX_RED, |
| 79 | LCD_MAX_GREEN, |
| 80 | LCD_MAX_BLUE |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | /* Unpacks the color value into native rgb values and 24 bit rgb values */ |
| 84 | static void unpack_rgb(struct rgb_pick *rgb) |
| 85 | { |
Michael Sevakis | e0710b2 | 2006-10-15 17:51:00 +0000 | [diff] [blame] | 86 | unsigned color = _LCD_UNSWAP_COLOR(rgb->color); |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 87 | rgb->red = _RGB_UNPACK_RED(color); |
| 88 | rgb->green = _RGB_UNPACK_GREEN(color); |
| 89 | rgb->blue = _RGB_UNPACK_BLUE(color); |
Michael Sevakis | e0710b2 | 2006-10-15 17:51:00 +0000 | [diff] [blame] | 90 | rgb->r = _RGB_UNPACK_RED_LCD(color); |
| 91 | rgb->g = _RGB_UNPACK_GREEN_LCD(color); |
| 92 | rgb->b = _RGB_UNPACK_BLUE_LCD(color); |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | /* Packs the native rgb colors into a color value */ |
Michael Sevakis | e0710b2 | 2006-10-15 17:51:00 +0000 | [diff] [blame] | 96 | static inline void pack_rgb(struct rgb_pick *rgb) |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 97 | { |
Michael Sevakis | e0710b2 | 2006-10-15 17:51:00 +0000 | [diff] [blame] | 98 | rgb->color = LCD_RGBPACK_LCD(rgb->r, rgb->g, rgb->b); |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | /* Returns LCD_BLACK if the color is above a threshold brightness |
| 102 | else return LCD_WHITE */ |
| 103 | static inline unsigned get_black_or_white(const struct rgb_pick *rgb) |
| 104 | { |
Michael Sevakis | 661c340 | 2006-10-13 04:16:49 +0000 | [diff] [blame] | 105 | return (2*rgb->red + 5*rgb->green + rgb->blue) >= 1024 ? |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 106 | LCD_BLACK : LCD_WHITE; |
| 107 | } |
| 108 | |
Michael Sevakis | 661c340 | 2006-10-13 04:16:49 +0000 | [diff] [blame] | 109 | #define MARGIN_LEFT 0 /* Left margin of screen */ |
| 110 | #define MARGIN_TOP 2 /* Top margin of screen */ |
| 111 | #define MARGIN_RIGHT 0 /* Right margin of screen */ |
| 112 | #define MARGIN_BOTTOM 6 /* Bottom margin of screen */ |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 113 | #define SLIDER_MARGIN_LEFT 2 /* Gap to left of sliders */ |
| 114 | #define SLIDER_MARGIN_RIGHT 2 /* Gap to right of sliders */ |
| 115 | #define TITLE_MARGIN_BOTTOM 4 /* Space below title bar */ |
Michael Sevakis | 661c340 | 2006-10-13 04:16:49 +0000 | [diff] [blame] | 116 | #define SELECTOR_LR_MARGIN 0 /* Margin between ">" and text */ |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 117 | #define SELECTOR_TB_MARGIN 1 /* Margin on top and bottom of selector */ |
| 118 | #define SWATCH_TOP_MARGIN 4 /* Space between last slider and swatch */ |
Jonathan Gordon | cfe0f48 | 2007-06-11 13:32:29 +0000 | [diff] [blame^] | 119 | #define SELECTOR_WIDTH get_icon_width(display->screen_type) |
Michael Sevakis | 661c340 | 2006-10-13 04:16:49 +0000 | [diff] [blame] | 120 | #define SELECTOR_HEIGHT 8 /* Height of > and < bitmaps */ |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 121 | |
| 122 | /* dunno why lcd_set_drawinfo should be left out of struct screen */ |
| 123 | static void set_drawinfo(struct screen *display, int mode, |
| 124 | unsigned foreground, unsigned background) |
| 125 | { |
| 126 | display->set_drawmode(mode); |
| 127 | if (display->depth > 1) |
| 128 | { |
| 129 | display->set_foreground(foreground); |
| 130 | display->set_background(background); |
| 131 | } |
| 132 | } |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 133 | |
Zakk Roberts | b81f596 | 2006-03-21 02:02:04 +0000 | [diff] [blame] | 134 | static void draw_screen(struct screen *display, char *title, |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 135 | struct rgb_pick *rgb, int row) |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 136 | { |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 137 | unsigned text_color = LCD_BLACK; |
| 138 | unsigned background_color = LCD_WHITE; |
| 139 | char buf[32]; |
| 140 | int i, x, y; |
| 141 | int text_top; |
| 142 | int slider_left, slider_width; |
| 143 | bool display_three_rows; |
| 144 | int max_label_width; |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 145 | |
| 146 | display->clear_display(); |
| 147 | |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 148 | if (display->depth > 1) |
| 149 | { |
| 150 | text_color = display->get_foreground(); |
| 151 | background_color = display->get_background(); |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 152 | } |
| 153 | |
Michael Sevakis | a7c8c71 | 2006-10-12 00:50:13 +0000 | [diff] [blame] | 154 | /* Find out if there's enough room for three sliders or just |
| 155 | enough to display the selected slider - calculate total height |
| 156 | of display with three sliders present */ |
| 157 | display_three_rows = |
| 158 | display->height >= MARGIN_TOP + |
| 159 | display->char_height*4 + /* Title + 3 sliders */ |
| 160 | TITLE_MARGIN_BOTTOM + |
| 161 | SELECTOR_TB_MARGIN*6 + /* 2 margins/slider */ |
| 162 | MARGIN_BOTTOM; |
Zakk Roberts | b81f596 | 2006-03-21 02:02:04 +0000 | [diff] [blame] | 163 | |
Michael Sevakis | a7c8c71 | 2006-10-12 00:50:13 +0000 | [diff] [blame] | 164 | /* Figure out widest label character in case they vary - |
| 165 | this function assumes labels are one character */ |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 166 | for (i = 0, max_label_width = 0; i < 3; i++) |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 167 | { |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 168 | buf[0] = str(LANG_COLOR_RGB_LABELS)[i]; |
| 169 | buf[1] = '\0'; |
| 170 | x = display->getstringsize(buf, NULL, NULL); |
| 171 | if (x > max_label_width) |
| 172 | max_label_width = x; |
| 173 | } |
| 174 | |
| 175 | /* Draw title string */ |
| 176 | set_drawinfo(display, DRMODE_SOLID, text_color, background_color); |
| 177 | display->getstringsize(title, &x, &y); |
| 178 | display->putsxy((display->width - x) / 2, MARGIN_TOP, title); |
| 179 | |
| 180 | /* Get slider positions and top starting position */ |
| 181 | text_top = MARGIN_TOP + y + TITLE_MARGIN_BOTTOM + SELECTOR_TB_MARGIN; |
Michael Sevakis | 661c340 | 2006-10-13 04:16:49 +0000 | [diff] [blame] | 182 | slider_left = MARGIN_LEFT + SELECTOR_WIDTH + SELECTOR_LR_MARGIN + |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 183 | max_label_width + SLIDER_MARGIN_LEFT; |
| 184 | slider_width = display->width - slider_left - SLIDER_MARGIN_RIGHT - |
Michael Sevakis | 661c340 | 2006-10-13 04:16:49 +0000 | [diff] [blame] | 185 | display->char_width*2 - SELECTOR_LR_MARGIN - SELECTOR_WIDTH - |
| 186 | MARGIN_RIGHT; |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 187 | |
| 188 | for (i = 0; i < 3; i++) |
| 189 | { |
Michael Sevakis | 661c340 | 2006-10-13 04:16:49 +0000 | [diff] [blame] | 190 | unsigned sb_flags = HORIZONTAL; |
| 191 | int mode = DRMODE_SOLID; |
| 192 | unsigned fg = text_color; |
| 193 | unsigned bg = background_color; |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 194 | |
Dave Chapman | 3ea74cc | 2006-07-19 14:31:24 +0000 | [diff] [blame] | 195 | if (!display_three_rows) |
Michael Sevakis | 661c340 | 2006-10-13 04:16:49 +0000 | [diff] [blame] | 196 | i = row; |
Zakk Roberts | b81f596 | 2006-03-21 02:02:04 +0000 | [diff] [blame] | 197 | |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 198 | if (i == row) |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 199 | { |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 200 | set_drawinfo(display, DRMODE_SOLID, text_color, |
| 201 | background_color); |
| 202 | |
| 203 | if (global_settings.invert_cursor) |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 204 | { |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 205 | /* Draw solid bar selection bar */ |
| 206 | display->fillrect(0, |
| 207 | text_top - SELECTOR_TB_MARGIN, |
| 208 | display->width, |
| 209 | display->char_height + |
| 210 | SELECTOR_TB_MARGIN*2); |
| 211 | |
Michael Sevakis | 661c340 | 2006-10-13 04:16:49 +0000 | [diff] [blame] | 212 | if (display->depth < 16) |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 213 | { |
Michael Sevakis | 661c340 | 2006-10-13 04:16:49 +0000 | [diff] [blame] | 214 | sb_flags |= FOREGROUND | INNER_FILL; |
| 215 | mode |= DRMODE_INVERSEVID; |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 216 | } |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 217 | } |
Dave Chapman | 3ea74cc | 2006-07-19 14:31:24 +0000 | [diff] [blame] | 218 | else if (display_three_rows) |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 219 | { |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 220 | /* Draw "> <" around sliders */ |
Michael Sevakis | 661c340 | 2006-10-13 04:16:49 +0000 | [diff] [blame] | 221 | int top = text_top + (display->char_height - |
| 222 | SELECTOR_HEIGHT) / 2; |
Jonathan Gordon | 6a5cc0b | 2007-04-16 09:14:36 +0000 | [diff] [blame] | 223 | screen_put_iconxy(display, MARGIN_LEFT, top, Icon_Cursor); |
| 224 | screen_put_iconxy(display, |
| 225 | display->width - MARGIN_RIGHT - |
| 226 | get_icon_width(display->screen_type), |
| 227 | top, Icon_Cursor); |
Michael Sevakis | 661c340 | 2006-10-13 04:16:49 +0000 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | if (display->depth >= 16) |
| 231 | { |
| 232 | sb_flags |= FOREGROUND | INNER_BGFILL; |
| 233 | mode = DRMODE_FG; |
| 234 | fg = prim_rgb[SB_PRIM][i]; |
| 235 | bg = prim_rgb[SB_FILL][i]; |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 236 | } |
| 237 | } |
Michael Sevakis | 661c340 | 2006-10-13 04:16:49 +0000 | [diff] [blame] | 238 | |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 239 | set_drawinfo(display, mode, fg, bg); |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 240 | |
Michael Sevakis | a7c8c71 | 2006-10-12 00:50:13 +0000 | [diff] [blame] | 241 | /* Draw label */ |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 242 | buf[0] = str(LANG_COLOR_RGB_LABELS)[i]; |
| 243 | buf[1] = '\0'; |
| 244 | display->putsxy(slider_left - display->char_width - |
| 245 | SLIDER_MARGIN_LEFT, text_top, buf); |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 246 | |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 247 | /* Draw color value */ |
| 248 | snprintf(buf, 3, "%02d", rgb->rgb_val[i]); |
| 249 | display->putsxy(slider_left + slider_width + SLIDER_MARGIN_RIGHT, |
| 250 | text_top, buf); |
Zakk Roberts | b81f596 | 2006-03-21 02:02:04 +0000 | [diff] [blame] | 251 | |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 252 | /* Draw scrollbar */ |
| 253 | gui_scrollbar_draw(display, |
| 254 | slider_left, |
| 255 | text_top + display->char_height / 4, |
| 256 | slider_width, |
| 257 | display->char_height / 2, |
Michael Sevakis | e0710b2 | 2006-10-15 17:51:00 +0000 | [diff] [blame] | 258 | rgb_max[i], |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 259 | 0, |
| 260 | rgb->rgb_val[i], |
Michael Sevakis | 661c340 | 2006-10-13 04:16:49 +0000 | [diff] [blame] | 261 | sb_flags); |
Zakk Roberts | b81f596 | 2006-03-21 02:02:04 +0000 | [diff] [blame] | 262 | |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 263 | /* Advance to next line */ |
| 264 | text_top += display->char_height + 2*SELECTOR_TB_MARGIN; |
| 265 | |
Dave Chapman | 3ea74cc | 2006-07-19 14:31:24 +0000 | [diff] [blame] | 266 | if (!display_three_rows) |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 267 | break; |
Michael Sevakis | 661c340 | 2006-10-13 04:16:49 +0000 | [diff] [blame] | 268 | } /* end for */ |
| 269 | |
| 270 | /* Draw color value in system font */ |
| 271 | display->setfont(FONT_SYSFIXED); |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 272 | |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 273 | /* Format RGB: #rrggbb */ |
| 274 | snprintf(buf, sizeof(buf), str(LANG_COLOR_RGB_VALUE), |
| 275 | rgb->red, rgb->green, rgb->blue); |
| 276 | |
| 277 | if (display->depth >= 16) |
| 278 | { |
| 279 | /* Display color swatch on color screens only */ |
Michael Sevakis | 661c340 | 2006-10-13 04:16:49 +0000 | [diff] [blame] | 280 | int left = MARGIN_LEFT + SELECTOR_WIDTH + SELECTOR_LR_MARGIN; |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 281 | int top = text_top + SWATCH_TOP_MARGIN; |
Michael Sevakis | 661c340 | 2006-10-13 04:16:49 +0000 | [diff] [blame] | 282 | int width = display->width - left - SELECTOR_LR_MARGIN - |
| 283 | SELECTOR_WIDTH - MARGIN_RIGHT; |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 284 | int height = display->height - top - MARGIN_BOTTOM; |
| 285 | |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 286 | /* Only draw if room */ |
| 287 | if (height >= display->char_height + 2) |
| 288 | { |
| 289 | display->set_foreground(rgb->color); |
| 290 | display->fillrect(left, top, width, height); |
| 291 | |
| 292 | /* Draw RGB: #rrggbb in middle of swatch */ |
| 293 | display->set_drawmode(DRMODE_FG); |
| 294 | display->getstringsize(buf, &x, &y); |
| 295 | display->set_foreground(get_black_or_white(rgb)); |
| 296 | |
| 297 | x = left + (width - x) / 2; |
| 298 | y = top + (height - y) / 2; |
| 299 | |
| 300 | display->putsxy(x, y, buf); |
| 301 | display->set_drawmode(DRMODE_SOLID); |
| 302 | |
| 303 | /* Draw border */ |
| 304 | display->set_foreground(text_color); |
Michael Sevakis | 661c340 | 2006-10-13 04:16:49 +0000 | [diff] [blame] | 305 | display->drawrect(left, top, width, height); |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 306 | } |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 307 | } |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 308 | else |
| 309 | { |
| 310 | /* Display RGB value only centered on remaining display if room */ |
| 311 | display->getstringsize(buf, &x, &y); |
| 312 | i = text_top + SWATCH_TOP_MARGIN; |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 313 | |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 314 | if (i + y <= display->height - MARGIN_BOTTOM) |
| 315 | { |
| 316 | set_drawinfo(display, DRMODE_SOLID, text_color, background_color); |
| 317 | x = (display->width - x) / 2; |
| 318 | y = (i + display->height - MARGIN_BOTTOM - y) / 2; |
| 319 | display->putsxy(x, y, buf); |
| 320 | } |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 321 | } |
| 322 | |
Michael Sevakis | 661c340 | 2006-10-13 04:16:49 +0000 | [diff] [blame] | 323 | display->setfont(FONT_UI); |
| 324 | |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 325 | display->update(); |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 326 | /* Be sure screen mode is reset */ |
| 327 | set_drawinfo(display, DRMODE_SOLID, text_color, background_color); |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 328 | } |
| 329 | |
| 330 | /*********** |
Zakk Roberts | b81f596 | 2006-03-21 02:02:04 +0000 | [diff] [blame] | 331 | set_color |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 332 | returns true if USB was inserted, false otherwise |
| 333 | color is a pointer to the colour (in native format) to modify |
Zakk Roberts | 87142ab | 2006-03-04 10:55:54 +0000 | [diff] [blame] | 334 | set banned_color to -1 to allow all |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 335 | ***********/ |
Michael Sevakis | e0710b2 | 2006-10-15 17:51:00 +0000 | [diff] [blame] | 336 | bool set_color(struct screen *display, char *title, unsigned *color, |
| 337 | unsigned banned_color) |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 338 | { |
Michael Sevakis | e0710b2 | 2006-10-15 17:51:00 +0000 | [diff] [blame] | 339 | int exit = 0, slider = 0; |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 340 | struct rgb_pick rgb; |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 341 | |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 342 | rgb.color = *color; |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 343 | |
| 344 | while (!exit) |
| 345 | { |
Michael Sevakis | e0710b2 | 2006-10-15 17:51:00 +0000 | [diff] [blame] | 346 | int button; |
| 347 | |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 348 | unpack_rgb(&rgb); |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 349 | |
Michael Sevakis | e0710b2 | 2006-10-15 17:51:00 +0000 | [diff] [blame] | 350 | if (display != NULL) |
Dave Chapman | 3ea74cc | 2006-07-19 14:31:24 +0000 | [diff] [blame] | 351 | { |
Michael Sevakis | e0710b2 | 2006-10-15 17:51:00 +0000 | [diff] [blame] | 352 | draw_screen(display, title, &rgb, slider); |
| 353 | } |
| 354 | else |
| 355 | { |
| 356 | int i; |
| 357 | FOR_NB_SCREENS(i) |
| 358 | draw_screen(&screens[i], title, &rgb, slider); |
Dave Chapman | 3ea74cc | 2006-07-19 14:31:24 +0000 | [diff] [blame] | 359 | } |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 360 | |
| 361 | button = get_action(CONTEXT_SETTINGS_COLOURCHOOSER, TIMEOUT_BLOCK); |
| 362 | |
Zakk Roberts | b81f596 | 2006-03-21 02:02:04 +0000 | [diff] [blame] | 363 | switch (button) |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 364 | { |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 365 | case ACTION_STD_PREV: |
Jonathan Gordon | d12f81d | 2006-08-21 07:03:15 +0000 | [diff] [blame] | 366 | case ACTION_STD_PREVREPEAT: |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 367 | slider = (slider + 2) % 3; |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 368 | break; |
| 369 | |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 370 | case ACTION_STD_NEXT: |
Jonathan Gordon | d12f81d | 2006-08-21 07:03:15 +0000 | [diff] [blame] | 371 | case ACTION_STD_NEXTREPEAT: |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 372 | slider = (slider + 1) % 3; |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 373 | break; |
| 374 | |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 375 | case ACTION_SETTINGS_INC: |
| 376 | case ACTION_SETTINGS_INCREPEAT: |
Michael Sevakis | e0710b2 | 2006-10-15 17:51:00 +0000 | [diff] [blame] | 377 | if (rgb.rgb_val[slider] < rgb_max[slider]) |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 378 | rgb.rgb_val[slider]++; |
| 379 | pack_rgb(&rgb); |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 380 | break; |
| 381 | |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 382 | case ACTION_SETTINGS_DEC: |
| 383 | case ACTION_SETTINGS_DECREPEAT: |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 384 | if (rgb.rgb_val[slider] > 0) |
| 385 | rgb.rgb_val[slider]--; |
| 386 | pack_rgb(&rgb); |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 387 | break; |
Zakk Roberts | b81f596 | 2006-03-21 02:02:04 +0000 | [diff] [blame] | 388 | |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 389 | case ACTION_STD_OK: |
Michael Sevakis | e0710b2 | 2006-10-15 17:51:00 +0000 | [diff] [blame] | 390 | if (banned_color != (unsigned)-1 && |
| 391 | banned_color == rgb.color) |
Zakk Roberts | 87142ab | 2006-03-04 10:55:54 +0000 | [diff] [blame] | 392 | { |
Jens Arnold | 4d6374c | 2007-03-16 21:56:08 +0000 | [diff] [blame] | 393 | gui_syncsplash(HZ*2, str(LANG_COLOR_UNACCEPTABLE)); |
Zakk Roberts | 87142ab | 2006-03-04 10:55:54 +0000 | [diff] [blame] | 394 | break; |
Zakk Roberts | b81f596 | 2006-03-21 02:02:04 +0000 | [diff] [blame] | 395 | } |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 396 | *color = rgb.color; |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 397 | exit = 1; |
| 398 | break; |
| 399 | |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 400 | case ACTION_STD_CANCEL: |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 401 | exit = 1; |
| 402 | break; |
| 403 | |
| 404 | default: |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 405 | if (default_event_handler(button) == SYS_USB_CONNECTED) |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 406 | return true; |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 407 | break; |
| 408 | } |
| 409 | } |
Michael Sevakis | cc66aea | 2006-10-11 20:34:25 +0000 | [diff] [blame] | 410 | |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 411 | action_signalscreenchange(); |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 412 | return false; |
| 413 | } |