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