blob: 1217fcd08c102e303cf17d1b8e2dab92dcb4ad1e [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 *
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 Chapman3ea74cc2006-07-19 14:31:24 +000019#include "config.h"
Dave Chapman603f87f2006-02-26 02:48:05 +000020#include "stdarg.h"
21#include "string.h"
22#include "stdio.h"
23#include "kernel.h"
24#include "system.h"
25#include "screen_access.h"
26#include "debug.h"
27#include "misc.h"
28#include "settings.h"
29#include "scrollbar.h"
30#include "lang.h"
Zakk Roberts87142ab2006-03-04 10:55:54 +000031#include "splash.h"
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +000032#include "action.h"
Dave Chapman603f87f2006-02-26 02:48:05 +000033
34#define TEXT_MARGIN display->char_width+2
35#define SLIDER_START 20
36
Dave Chapman603f87f2006-02-26 02:48:05 +000037static const int max_val[3] = {LCD_MAX_RED,LCD_MAX_GREEN,LCD_MAX_BLUE};
38
Zakk Robertsb81f5962006-03-21 02:02:04 +000039static void draw_screen(struct screen *display, char *title,
Dave Chapman603f87f2006-02-26 02:48:05 +000040 int *rgb_val, int color, int row)
41{
42 int i;
43 char *textrgb = str(LANG_COLOR_RGB_LABELS), rgb_dummy[2] = {0,0};
44 int text_top;
45 int text_centre, bg_col;
46 char buf[32];
47 int slider_width = (display->width-SLIDER_START-(display->char_width*5));
48 int background_color = global_settings.bg_color;
49 int text_color = global_settings.fg_color;
Dave Chapman3ea74cc2006-07-19 14:31:24 +000050 bool display_three_rows = (display->height/6) > display->char_height;
Dave Chapman603f87f2006-02-26 02:48:05 +000051
52 display->clear_display();
53
54 if (display->depth > 1) {
55 display->set_foreground(text_color);
56 }
57
58 i = display->getstringsize(title,0,0);
59 display->putsxy((display->width-i)/2,6,title );
Zakk Robertsb81f5962006-03-21 02:02:04 +000060
Dave Chapman3ea74cc2006-07-19 14:31:24 +000061 text_top = display->char_height*2;
Dave Chapman91d26782006-07-19 15:07:08 +000062 bg_col = background_color;
Dave Chapman3ea74cc2006-07-19 14:31:24 +000063 for (i=0; i<3 ;i++)
Dave Chapman603f87f2006-02-26 02:48:05 +000064 {
Dave Chapman3ea74cc2006-07-19 14:31:24 +000065 if (!display_three_rows)
66 i = row;
Zakk Robertsb81f5962006-03-21 02:02:04 +000067
Dave Chapman603f87f2006-02-26 02:48:05 +000068 if (i==row)
69 {
Dave Chapman3ea74cc2006-07-19 14:31:24 +000070 if ((global_settings.invert_cursor) && (display->depth >2))
Dave Chapman603f87f2006-02-26 02:48:05 +000071 {
72 display->fillrect(0,text_top-1,display->width,display->char_height+2);
73 bg_col = text_color;
74 }
Dave Chapman3ea74cc2006-07-19 14:31:24 +000075 else if (display_three_rows)
Dave Chapman603f87f2006-02-26 02:48:05 +000076 {
77 display->putsxy(0,text_top,">");
Dave Chapman3ea74cc2006-07-19 14:31:24 +000078 display->putsxy(display->width-display->char_width-2,text_top,"<");
Dave Chapman603f87f2006-02-26 02:48:05 +000079 bg_col = background_color;
80 }
81 if (display->depth > 1)
82 {
83 if (i==0)
84 display->set_foreground(LCD_RGBPACK(255, 0, 0));
85 else if (i==1)
86 display->set_foreground(LCD_RGBPACK(0, 255, 0));
87 else if (i==2)
88 display->set_foreground(LCD_RGBPACK(0 ,0 ,255));
89 }
90 }
91 else
Zakk Robertsb81f5962006-03-21 02:02:04 +000092 {
Dave Chapman603f87f2006-02-26 02:48:05 +000093 if (display->depth > 1)
Zakk Robertsb81f5962006-03-21 02:02:04 +000094 display->set_foreground(text_color);
Dave Chapman603f87f2006-02-26 02:48:05 +000095 bg_col = background_color;
96 }
97
98 if (display->depth > 1)
99 display->set_background(bg_col);
100
101 text_centre = text_top+(display->char_height/2);
102 rgb_dummy[0] = textrgb[i];
103 display->putsxy(TEXT_MARGIN,text_top,rgb_dummy);
104 snprintf(buf,3,"%02d",rgb_val[i]);
105 display->putsxy(display->width-(display->char_width*4),text_top,buf);
Zakk Robertsb81f5962006-03-21 02:02:04 +0000106
Dave Chapman603f87f2006-02-26 02:48:05 +0000107 text_top += display->char_height/4;
Zakk Robertsb81f5962006-03-21 02:02:04 +0000108
Dave Chapman603f87f2006-02-26 02:48:05 +0000109 gui_scrollbar_draw(display,SLIDER_START,text_top,slider_width,
110 display->char_height/2,
Zakk Robertsb81f5962006-03-21 02:02:04 +0000111 max_val[i],0,rgb_val[i],HORIZONTAL);
Dave Chapman3ea74cc2006-07-19 14:31:24 +0000112 if (!display_three_rows)
113 break;
114 text_top += display->char_height;
Dave Chapman603f87f2006-02-26 02:48:05 +0000115 }
116
117 if (display->depth > 1) {
118 display->set_background(background_color);
119 display->set_foreground(text_color);
120 }
121
Dave Chapman3ea74cc2006-07-19 14:31:24 +0000122 if (text_top + (display->char_height*2) < (display->height-40-display->char_height))
Dave Chapman603f87f2006-02-26 02:48:05 +0000123 text_top += (display->char_height*2);
124 else text_top += (display->char_height);
125
126 /* Display RGB: #rrggbb */
127 snprintf(buf,sizeof(buf),str(LANG_COLOR_RGB_VALUE),
128 RGB_UNPACK_RED(color),
129 RGB_UNPACK_GREEN(color),
130 RGB_UNPACK_BLUE(color));
131
Dave Chapman3ea74cc2006-07-19 14:31:24 +0000132 display->putsxy((display->width-(display->char_width*11))/2,text_top,buf);
Dave Chapman603f87f2006-02-26 02:48:05 +0000133
134 if (display->depth > 1) {
135 display->set_foreground(color);
136 display->fillrect(SLIDER_START,LCD_HEIGHT-40,slider_width,35);
137
138 display->set_foreground(LCD_BLACK);
139 display->drawrect(SLIDER_START-1,LCD_HEIGHT-41,slider_width+2,37);
140 }
141
142 display->update();
143}
144
145/***********
Zakk Robertsb81f5962006-03-21 02:02:04 +0000146 set_color
Dave Chapman603f87f2006-02-26 02:48:05 +0000147 returns true if USB was inserted, false otherwise
148 color is a pointer to the colour (in native format) to modify
Zakk Roberts87142ab2006-03-04 10:55:54 +0000149 set banned_color to -1 to allow all
Dave Chapman603f87f2006-02-26 02:48:05 +0000150 ***********/
Zakk Roberts87142ab2006-03-04 10:55:54 +0000151bool set_color(struct screen *display,char *title, int* color, int banned_color)
Dave Chapman603f87f2006-02-26 02:48:05 +0000152{
153 int exit = 0, button, slider=0;
154 int rgb_val[3]; /* native depth r,g,b*/;
155 int fgcolor = display->get_foreground();
156 int newcolor = *color;
157 int i;
158
159#if LCD_PIXELFORMAT == RGB565
160 rgb_val[0] = ((*color)&0xf800) >> 11;
161 rgb_val[1] = ((*color)&0x07e0) >> 5;
162 rgb_val[2] = ((*color)&0x001f);
163#elif LCD_PIXELFORMAT == RGB565SWAPPED
164 rgb_val[0] = ((swap16(*color))&0xf800) >> 11;
165 rgb_val[1] = ((swap16(*color))&0x07e0) >> 5;
166 rgb_val[2] = ((swap16(*color))&0x001f);
167#endif
168
169 while (!exit)
170 {
171 /* We need to maintain three versions of the colour:
172
173 rgb_val[3] - the native depth RGB values
174 newcolor - the native format packed colour
175 */
176
177#if LCD_PIXELFORMAT == RGB565
178 newcolor = (rgb_val[0] << 11) | (rgb_val[1] << 5) | (rgb_val[2]);
179#elif LCD_PIXELFORMAT == RGB565SWAPPED
180 newcolor = swap16((rgb_val[0] << 11) | (rgb_val[1] << 5) | (rgb_val[2]));
181#endif
182 FOR_NB_SCREENS(i)
Dave Chapman3ea74cc2006-07-19 14:31:24 +0000183 {
Dave Chapman603f87f2006-02-26 02:48:05 +0000184 draw_screen(&screens[i], title, rgb_val, newcolor, slider);
Dave Chapman3ea74cc2006-07-19 14:31:24 +0000185 }
186
Jonathan Gordond12f81d2006-08-21 07:03:15 +0000187 button = get_action(CONTEXT_SETTINGS_COLOURCHOOSER,TIMEOUT_BLOCK);
Zakk Robertsb81f5962006-03-21 02:02:04 +0000188 switch (button)
Dave Chapman603f87f2006-02-26 02:48:05 +0000189 {
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000190 case ACTION_STD_PREV:
Jonathan Gordond12f81d2006-08-21 07:03:15 +0000191 case ACTION_STD_PREVREPEAT:
Dave Chapman603f87f2006-02-26 02:48:05 +0000192 slider = (slider+2)%3;
193 break;
194
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000195 case ACTION_STD_NEXT:
Jonathan Gordond12f81d2006-08-21 07:03:15 +0000196 case ACTION_STD_NEXTREPEAT:
Dave Chapman603f87f2006-02-26 02:48:05 +0000197 slider = (slider+1)%3;
198 break;
199
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000200 case ACTION_SETTINGS_INC:
201 case ACTION_SETTINGS_INCREPEAT:
Dave Chapman603f87f2006-02-26 02:48:05 +0000202 if (rgb_val[slider] < max_val[slider])
203 rgb_val[slider]++;
204 break;
205
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000206 case ACTION_SETTINGS_DEC:
207 case ACTION_SETTINGS_DECREPEAT:
Dave Chapman603f87f2006-02-26 02:48:05 +0000208 if (rgb_val[slider] > 0)
209 rgb_val[slider]--;
210 break;
Zakk Robertsb81f5962006-03-21 02:02:04 +0000211
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000212 case ACTION_STD_OK:
Zakk Roberts87142ab2006-03-04 10:55:54 +0000213 if ((banned_color!=-1) && (banned_color == newcolor))
214 {
215 gui_syncsplash(HZ*2,true,str(LANG_COLOR_UNACCEPTABLE));
216 break;
Zakk Robertsb81f5962006-03-21 02:02:04 +0000217 }
Dave Chapman603f87f2006-02-26 02:48:05 +0000218 *color = newcolor;
219 exit = 1;
220 break;
221
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000222 case ACTION_STD_CANCEL:
Dave Chapman603f87f2006-02-26 02:48:05 +0000223 exit = 1;
224 break;
225
226 default:
227 if(default_event_handler(button) == SYS_USB_CONNECTED) {
228 display->set_foreground(fgcolor);
229 return true;
230 }
231 break;
232 }
233 }
234 display->set_foreground(fgcolor);
Linus Nielsen Feltzing224c0a12006-08-15 12:27:07 +0000235 action_signalscreenchange();
Dave Chapman603f87f2006-02-26 02:48:05 +0000236 return false;
237}