blob: 239a8b4c81613c9a2b2afb1aef0f63ac78b7e708 [file] [log] [blame]
Dave Chapman603f87f2006-02-26 02:48:05 +00001/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
Zakk Robertsb81f5962006-03-21 02:02:04 +00008 * $Id$
Dave Chapman603f87f2006-02-26 02:48:05 +00009 *
10 * Copyright (C) Jonathan Gordon (2006)
11 *
Daniel Stenberg2acc0ac2008-06-28 18:10:04 +000012 * 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 Chapman603f87f2006-02-26 02:48:05 +000016 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
Dave Chapman3ea74cc2006-07-19 14:31:24 +000021#include "config.h"
Dave Chapman603f87f2006-02-26 02:48:05 +000022#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 Sevakiscc66aea2006-10-11 20:34:25 +000028#include "font.h"
Dave Chapman603f87f2006-02-26 02:48:05 +000029#include "debug.h"
30#include "misc.h"
31#include "settings.h"
32#include "scrollbar.h"
33#include "lang.h"
Zakk Roberts87142ab2006-03-04 10:55:54 +000034#include "splash.h"
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +000035#include "action.h"
Jonathan Gordon6a5cc0b2007-04-16 09:14:36 +000036#include "icon.h"
Bertrik Sikkene15f8a22008-05-03 08:35:14 +000037#include "color_picker.h"
Dave Chapman603f87f2006-02-26 02:48:05 +000038
Michael Sevakiscc66aea2006-10-11 20:34:25 +000039/* structure for color info */
40struct 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 Chapman603f87f2006-02-26 02:48:05 +000057
Michael Sevakiscc66aea2006-10-11 20:34:25 +000058
59/* list of primary colors */
Michael Sevakis661c3402006-10-13 04:16:49 +000060#define SB_PRIM 0
61#define SB_FILL 1
Michael Sevakise0710b22006-10-15 17:51:00 +000062static const fb_data prim_rgb[][3] =
Michael Sevakiscc66aea2006-10-11 20:34:25 +000063{
Michael Sevakis661c3402006-10-13 04:16:49 +000064 /* 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 Sevakise0710b22006-10-15 17:51:00 +000076};
77
78/* maximum values for components */
79static const unsigned char rgb_max[3] =
80{
81 LCD_MAX_RED,
82 LCD_MAX_GREEN,
83 LCD_MAX_BLUE
Michael Sevakiscc66aea2006-10-11 20:34:25 +000084};
85
86/* Unpacks the color value into native rgb values and 24 bit rgb values */
87static void unpack_rgb(struct rgb_pick *rgb)
88{
Michael Sevakise0710b22006-10-15 17:51:00 +000089 unsigned color = _LCD_UNSWAP_COLOR(rgb->color);
Michael Sevakiscc66aea2006-10-11 20:34:25 +000090 rgb->red = _RGB_UNPACK_RED(color);
91 rgb->green = _RGB_UNPACK_GREEN(color);
92 rgb->blue = _RGB_UNPACK_BLUE(color);
Michael Sevakise0710b22006-10-15 17:51:00 +000093 rgb->r = _RGB_UNPACK_RED_LCD(color);
94 rgb->g = _RGB_UNPACK_GREEN_LCD(color);
95 rgb->b = _RGB_UNPACK_BLUE_LCD(color);
Michael Sevakiscc66aea2006-10-11 20:34:25 +000096}
97
98/* Packs the native rgb colors into a color value */
Michael Sevakise0710b22006-10-15 17:51:00 +000099static inline void pack_rgb(struct rgb_pick *rgb)
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000100{
Michael Sevakise0710b22006-10-15 17:51:00 +0000101 rgb->color = LCD_RGBPACK_LCD(rgb->r, rgb->g, rgb->b);
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000102}
103
104/* Returns LCD_BLACK if the color is above a threshold brightness
105 else return LCD_WHITE */
106static inline unsigned get_black_or_white(const struct rgb_pick *rgb)
107{
Michael Sevakis661c3402006-10-13 04:16:49 +0000108 return (2*rgb->red + 5*rgb->green + rgb->blue) >= 1024 ?
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000109 LCD_BLACK : LCD_WHITE;
110}
111
Michael Sevakis661c3402006-10-13 04:16:49 +0000112#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 Sevakiscc66aea2006-10-11 20:34:25 +0000116#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 Sevakis661c3402006-10-13 04:16:49 +0000119#define SELECTOR_LR_MARGIN 0 /* Margin between ">" and text */
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000120#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 Gordoncfe0f482007-06-11 13:32:29 +0000122#define SELECTOR_WIDTH get_icon_width(display->screen_type)
Michael Sevakis661c3402006-10-13 04:16:49 +0000123#define SELECTOR_HEIGHT 8 /* Height of > and < bitmaps */
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000124
125/* dunno why lcd_set_drawinfo should be left out of struct screen */
126static 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 Chapman603f87f2006-02-26 02:48:05 +0000136
Zakk Robertsb81f5962006-03-21 02:02:04 +0000137static void draw_screen(struct screen *display, char *title,
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000138 struct rgb_pick *rgb, int row)
Dave Chapman603f87f2006-02-26 02:48:05 +0000139{
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000140 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 Chapman603f87f2006-02-26 02:48:05 +0000148
149 display->clear_display();
150
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000151 if (display->depth > 1)
152 {
153 text_color = display->get_foreground();
154 background_color = display->get_background();
Dave Chapman603f87f2006-02-26 02:48:05 +0000155 }
156
Michael Sevakisa7c8c712006-10-12 00:50:13 +0000157 /* 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 Robertsb81f5962006-03-21 02:02:04 +0000166
Michael Sevakisa7c8c712006-10-12 00:50:13 +0000167 /* Figure out widest label character in case they vary -
168 this function assumes labels are one character */
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000169 for (i = 0, max_label_width = 0; i < 3; i++)
Dave Chapman603f87f2006-02-26 02:48:05 +0000170 {
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000171 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 Sevakis661c3402006-10-13 04:16:49 +0000185 slider_left = MARGIN_LEFT + SELECTOR_WIDTH + SELECTOR_LR_MARGIN +
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000186 max_label_width + SLIDER_MARGIN_LEFT;
187 slider_width = display->width - slider_left - SLIDER_MARGIN_RIGHT -
Michael Sevakis661c3402006-10-13 04:16:49 +0000188 display->char_width*2 - SELECTOR_LR_MARGIN - SELECTOR_WIDTH -
189 MARGIN_RIGHT;
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000190
191 for (i = 0; i < 3; i++)
192 {
Michael Sevakis661c3402006-10-13 04:16:49 +0000193 unsigned sb_flags = HORIZONTAL;
194 int mode = DRMODE_SOLID;
195 unsigned fg = text_color;
196 unsigned bg = background_color;
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000197
Dave Chapman3ea74cc2006-07-19 14:31:24 +0000198 if (!display_three_rows)
Michael Sevakis661c3402006-10-13 04:16:49 +0000199 i = row;
Zakk Robertsb81f5962006-03-21 02:02:04 +0000200
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000201 if (i == row)
Dave Chapman603f87f2006-02-26 02:48:05 +0000202 {
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000203 set_drawinfo(display, DRMODE_SOLID, text_color,
204 background_color);
205
Nicolas Pennequinf3b015f2007-09-27 15:42:55 +0000206 if (global_settings.cursor_style != 0)
Dave Chapman603f87f2006-02-26 02:48:05 +0000207 {
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000208 /* 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 Sevakis661c3402006-10-13 04:16:49 +0000215 if (display->depth < 16)
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000216 {
Michael Sevakis661c3402006-10-13 04:16:49 +0000217 sb_flags |= FOREGROUND | INNER_FILL;
218 mode |= DRMODE_INVERSEVID;
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000219 }
Dave Chapman603f87f2006-02-26 02:48:05 +0000220 }
Dave Chapman3ea74cc2006-07-19 14:31:24 +0000221 else if (display_three_rows)
Dave Chapman603f87f2006-02-26 02:48:05 +0000222 {
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000223 /* Draw "> <" around sliders */
Michael Sevakis661c3402006-10-13 04:16:49 +0000224 int top = text_top + (display->char_height -
225 SELECTOR_HEIGHT) / 2;
Jonathan Gordon6a5cc0b2007-04-16 09:14:36 +0000226 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 Sevakis661c3402006-10-13 04:16:49 +0000231 }
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 Chapman603f87f2006-02-26 02:48:05 +0000239 }
240 }
Michael Sevakis661c3402006-10-13 04:16:49 +0000241
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000242 set_drawinfo(display, mode, fg, bg);
Dave Chapman603f87f2006-02-26 02:48:05 +0000243
Michael Sevakisa7c8c712006-10-12 00:50:13 +0000244 /* Draw label */
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000245 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 Chapman603f87f2006-02-26 02:48:05 +0000249
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000250 /* 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 Robertsb81f5962006-03-21 02:02:04 +0000254
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000255 /* 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 Sevakise0710b22006-10-15 17:51:00 +0000261 rgb_max[i],
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000262 0,
263 rgb->rgb_val[i],
Michael Sevakis661c3402006-10-13 04:16:49 +0000264 sb_flags);
Zakk Robertsb81f5962006-03-21 02:02:04 +0000265
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000266 /* Advance to next line */
267 text_top += display->char_height + 2*SELECTOR_TB_MARGIN;
268
Dave Chapman3ea74cc2006-07-19 14:31:24 +0000269 if (!display_three_rows)
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000270 break;
Michael Sevakis661c3402006-10-13 04:16:49 +0000271 } /* end for */
272
273 /* Draw color value in system font */
274 display->setfont(FONT_SYSFIXED);
Dave Chapman603f87f2006-02-26 02:48:05 +0000275
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000276 /* 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 Sevakis661c3402006-10-13 04:16:49 +0000283 int left = MARGIN_LEFT + SELECTOR_WIDTH + SELECTOR_LR_MARGIN;
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000284 int top = text_top + SWATCH_TOP_MARGIN;
Michael Sevakis661c3402006-10-13 04:16:49 +0000285 int width = display->width - left - SELECTOR_LR_MARGIN -
286 SELECTOR_WIDTH - MARGIN_RIGHT;
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000287 int height = display->height - top - MARGIN_BOTTOM;
288
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000289 /* 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 Sevakis661c3402006-10-13 04:16:49 +0000308 display->drawrect(left, top, width, height);
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000309 }
Dave Chapman603f87f2006-02-26 02:48:05 +0000310 }
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000311 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 Chapman603f87f2006-02-26 02:48:05 +0000316
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000317 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 Chapman603f87f2006-02-26 02:48:05 +0000324 }
325
Michael Sevakis661c3402006-10-13 04:16:49 +0000326 display->setfont(FONT_UI);
327
Dave Chapman603f87f2006-02-26 02:48:05 +0000328 display->update();
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000329 /* Be sure screen mode is reset */
330 set_drawinfo(display, DRMODE_SOLID, text_color, background_color);
Dave Chapman603f87f2006-02-26 02:48:05 +0000331}
332
Jonathan Gordonfd9bad62007-11-04 10:42:22 +0000333#ifdef HAVE_TOUCHPAD
Bertrik Sikken6a0340f2008-05-03 23:18:56 +0000334static int touchpad_slider(struct rgb_pick *rgb, int *selected_slider)
Jonathan Gordonfd9bad62007-11-04 10:42:22 +0000335{
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 Gordoneb201492007-11-04 10:51:11 +0000384 if (pressed_slider != *selected_slider)
Jonathan Gordonfd9bad62007-11-04 10:42:22 +0000385 *selected_slider = pressed_slider;
Jonathan Gordon4ada9ed2007-11-04 10:57:06 +0000386 if (x < slider_left+slider_width &&
387 x > slider_left)
Jonathan Gordonfd9bad62007-11-04 10:42:22 +0000388 {
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 Chapman603f87f2006-02-26 02:48:05 +0000397/***********
Zakk Robertsb81f5962006-03-21 02:02:04 +0000398 set_color
Dave Chapman603f87f2006-02-26 02:48:05 +0000399 returns true if USB was inserted, false otherwise
400 color is a pointer to the colour (in native format) to modify
Zakk Roberts87142ab2006-03-04 10:55:54 +0000401 set banned_color to -1 to allow all
Dave Chapman603f87f2006-02-26 02:48:05 +0000402 ***********/
Michael Sevakise0710b22006-10-15 17:51:00 +0000403bool set_color(struct screen *display, char *title, unsigned *color,
404 unsigned banned_color)
Dave Chapman603f87f2006-02-26 02:48:05 +0000405{
Michael Sevakise0710b22006-10-15 17:51:00 +0000406 int exit = 0, slider = 0;
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000407 struct rgb_pick rgb;
Dave Chapman603f87f2006-02-26 02:48:05 +0000408
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000409 rgb.color = *color;
Dave Chapman603f87f2006-02-26 02:48:05 +0000410
411 while (!exit)
412 {
Michael Sevakise0710b22006-10-15 17:51:00 +0000413 int button;
414
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000415 unpack_rgb(&rgb);
Dave Chapman603f87f2006-02-26 02:48:05 +0000416
Michael Sevakise0710b22006-10-15 17:51:00 +0000417 if (display != NULL)
Dave Chapman3ea74cc2006-07-19 14:31:24 +0000418 {
Michael Sevakise0710b22006-10-15 17:51:00 +0000419 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 Chapman3ea74cc2006-07-19 14:31:24 +0000426 }
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000427
428 button = get_action(CONTEXT_SETTINGS_COLOURCHOOSER, TIMEOUT_BLOCK);
Jonathan Gordonfd9bad62007-11-04 10:42:22 +0000429#ifdef HAVE_TOUCHPAD
430 if (button == ACTION_TOUCHPAD)
431 button = touchpad_slider(&rgb, &slider);
432#endif
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000433
Zakk Robertsb81f5962006-03-21 02:02:04 +0000434 switch (button)
Dave Chapman603f87f2006-02-26 02:48:05 +0000435 {
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000436 case ACTION_STD_PREV:
Jonathan Gordond12f81d2006-08-21 07:03:15 +0000437 case ACTION_STD_PREVREPEAT:
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000438 slider = (slider + 2) % 3;
Dave Chapman603f87f2006-02-26 02:48:05 +0000439 break;
440
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000441 case ACTION_STD_NEXT:
Jonathan Gordond12f81d2006-08-21 07:03:15 +0000442 case ACTION_STD_NEXTREPEAT:
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000443 slider = (slider + 1) % 3;
Dave Chapman603f87f2006-02-26 02:48:05 +0000444 break;
445
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000446 case ACTION_SETTINGS_INC:
447 case ACTION_SETTINGS_INCREPEAT:
Michael Sevakise0710b22006-10-15 17:51:00 +0000448 if (rgb.rgb_val[slider] < rgb_max[slider])
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000449 rgb.rgb_val[slider]++;
450 pack_rgb(&rgb);
Dave Chapman603f87f2006-02-26 02:48:05 +0000451 break;
452
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000453 case ACTION_SETTINGS_DEC:
454 case ACTION_SETTINGS_DECREPEAT:
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000455 if (rgb.rgb_val[slider] > 0)
456 rgb.rgb_val[slider]--;
457 pack_rgb(&rgb);
Dave Chapman603f87f2006-02-26 02:48:05 +0000458 break;
Zakk Robertsb81f5962006-03-21 02:02:04 +0000459
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000460 case ACTION_STD_OK:
Michael Sevakise0710b22006-10-15 17:51:00 +0000461 if (banned_color != (unsigned)-1 &&
462 banned_color == rgb.color)
Zakk Roberts87142ab2006-03-04 10:55:54 +0000463 {
Jonathan Gordonfd9bad62007-11-04 10:42:22 +0000464 gui_syncsplash(HZ*2, ID2P(LANG_COLOR_UNACCEPTABLE));
Zakk Roberts87142ab2006-03-04 10:55:54 +0000465 break;
Zakk Robertsb81f5962006-03-21 02:02:04 +0000466 }
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000467 *color = rgb.color;
Dave Chapman603f87f2006-02-26 02:48:05 +0000468 exit = 1;
469 break;
470
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000471 case ACTION_STD_CANCEL:
Dave Chapman603f87f2006-02-26 02:48:05 +0000472 exit = 1;
473 break;
474
475 default:
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000476 if (default_event_handler(button) == SYS_USB_CONNECTED)
Dave Chapman603f87f2006-02-26 02:48:05 +0000477 return true;
Dave Chapman603f87f2006-02-26 02:48:05 +0000478 break;
479 }
480 }
Michael Sevakiscc66aea2006-10-11 20:34:25 +0000481
Dave Chapman603f87f2006-02-26 02:48:05 +0000482 return false;
483}