summaryrefslogtreecommitdiff
path: root/apps/gui/color_picker.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/gui/color_picker.c')
-rw-r--r--apps/gui/color_picker.c261
1 files changed, 261 insertions, 0 deletions
diff --git a/apps/gui/color_picker.c b/apps/gui/color_picker.c
new file mode 100644
index 0000000000..2f851d269e
--- /dev/null
+++ b/apps/gui/color_picker.c
@@ -0,0 +1,261 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id:
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 ****************************************************************************/
19#include "stdarg.h"
20#include "string.h"
21#include "stdio.h"
22#include "kernel.h"
23#include "system.h"
24#include "screen_access.h"
25#include "debug.h"
26#include "misc.h"
27#include "settings.h"
28#include "scrollbar.h"
29#include "lang.h"
30
31#define TEXT_MARGIN display->char_width+2
32#define SLIDER_START 20
33
34#if (CONFIG_KEYPAD == IRIVER_H300_PAD)
35#define SLIDER_UP BUTTON_UP
36#define SLIDER_DOWN BUTTON_DOWN
37#define SLIDER_LEFT BUTTON_LEFT
38#define SLIDER_RIGHT BUTTON_RIGHT
39#define SLIDER_OK BUTTON_ON
40#define SLIDER_CANCEL BUTTON_OFF
41
42#define SLIDER_RC_UP BUTTON_RC_REW
43#define SLIDER_RC_DOWN BUTTON_RC_FF
44#define SLIDER_RC_LEFT BUTTON_RC_SOURCE
45#define SLIDER_RC_RIGHT BUTTON_RC_BITRATE
46#define SLIDER_RC_OK BUTTON_RC_ON
47#define SLIDER_RC_CANCEL BUTTON_RC_STOP
48
49#elif (CONFIG_KEYPAD == IPOD_4G_PAD)
50#define SLIDER_UP BUTTON_LEFT
51#define SLIDER_DOWN BUTTON_RIGHT
52#define SLIDER_LEFT BUTTON_SCROLL_BACK
53#define SLIDER_RIGHT BUTTON_SCROLL_FWD
54#define SLIDER_OK BUTTON_SELECT
55#define SLIDER_CANCEL BUTTON_MENU
56#endif
57
58static const int max_val[3] = {LCD_MAX_RED,LCD_MAX_GREEN,LCD_MAX_BLUE};
59
60static void draw_screen(struct screen *display, char *title,
61 int *rgb_val, int color, int row)
62{
63 int i;
64 char *textrgb = str(LANG_COLOR_RGB_LABELS), rgb_dummy[2] = {0,0};
65 int text_top;
66 int text_centre, bg_col;
67 char buf[32];
68 int slider_width = (display->width-SLIDER_START-(display->char_width*5));
69 int background_color = global_settings.bg_color;
70 int text_color = global_settings.fg_color;
71
72 display->clear_display();
73
74 if (display->depth > 1) {
75 display->set_foreground(text_color);
76 }
77
78 i = display->getstringsize(title,0,0);
79 display->putsxy((display->width-i)/2,6,title );
80
81 for (i=0;i<3;i++)
82 {
83 text_top =display->char_height*((i*2)+2);
84
85 if (i==row)
86 {
87 if (global_settings.invert_cursor)
88 {
89 display->fillrect(0,text_top-1,display->width,display->char_height+2);
90 bg_col = text_color;
91 }
92 else
93 {
94 display->putsxy(0,text_top,">");
95 display->putsxy(display->width-TEXT_MARGIN,text_top,"<");
96 bg_col = background_color;
97 }
98 if (display->depth > 1)
99 {
100 if (i==0)
101 display->set_foreground(LCD_RGBPACK(255, 0, 0));
102 else if (i==1)
103 display->set_foreground(LCD_RGBPACK(0, 255, 0));
104 else if (i==2)
105 display->set_foreground(LCD_RGBPACK(0 ,0 ,255));
106 }
107 }
108 else
109 {
110 if (display->depth > 1)
111 display->set_foreground(text_color);
112 bg_col = background_color;
113 }
114
115 if (display->depth > 1)
116 display->set_background(bg_col);
117
118 text_centre = text_top+(display->char_height/2);
119 rgb_dummy[0] = textrgb[i];
120 display->putsxy(TEXT_MARGIN,text_top,rgb_dummy);
121 snprintf(buf,3,"%02d",rgb_val[i]);
122 display->putsxy(display->width-(display->char_width*4),text_top,buf);
123
124 text_top += display->char_height/4;
125
126 gui_scrollbar_draw(display,SLIDER_START,text_top,slider_width,
127 display->char_height/2,
128 max_val[i],0,rgb_val[i],HORIZONTAL);
129 }
130
131 if (display->depth > 1) {
132 display->set_background(background_color);
133 display->set_foreground(text_color);
134 }
135
136 if (text_top + (display->char_height*2) < (LCD_HEIGHT-40-display->char_height))
137 text_top += (display->char_height*2);
138 else text_top += (display->char_height);
139
140 /* Display RGB: #rrggbb */
141 snprintf(buf,sizeof(buf),str(LANG_COLOR_RGB_VALUE),
142 RGB_UNPACK_RED(color),
143 RGB_UNPACK_GREEN(color),
144 RGB_UNPACK_BLUE(color));
145
146 display->putsxy((LCD_WIDTH-(display->char_width*21))/2,text_top,buf);
147
148 if (display->depth > 1) {
149 display->set_foreground(color);
150 display->fillrect(SLIDER_START,LCD_HEIGHT-40,slider_width,35);
151
152 display->set_foreground(LCD_BLACK);
153 display->drawrect(SLIDER_START-1,LCD_HEIGHT-41,slider_width+2,37);
154 }
155
156 display->update();
157}
158
159/***********
160 set_color
161 returns true if USB was inserted, false otherwise
162 color is a pointer to the colour (in native format) to modify
163 ***********/
164bool set_color(struct screen *display,char *title, int* color)
165{
166 int exit = 0, button, slider=0;
167 int rgb_val[3]; /* native depth r,g,b*/;
168 int fgcolor = display->get_foreground();
169 int newcolor = *color;
170 int i;
171
172#if LCD_PIXELFORMAT == RGB565
173 rgb_val[0] = ((*color)&0xf800) >> 11;
174 rgb_val[1] = ((*color)&0x07e0) >> 5;
175 rgb_val[2] = ((*color)&0x001f);
176#elif LCD_PIXELFORMAT == RGB565SWAPPED
177 rgb_val[0] = ((swap16(*color))&0xf800) >> 11;
178 rgb_val[1] = ((swap16(*color))&0x07e0) >> 5;
179 rgb_val[2] = ((swap16(*color))&0x001f);
180#endif
181
182 while (!exit)
183 {
184 /* We need to maintain three versions of the colour:
185
186 rgb_val[3] - the native depth RGB values
187 newcolor - the native format packed colour
188 */
189
190#if LCD_PIXELFORMAT == RGB565
191 newcolor = (rgb_val[0] << 11) | (rgb_val[1] << 5) | (rgb_val[2]);
192#elif LCD_PIXELFORMAT == RGB565SWAPPED
193 newcolor = swap16((rgb_val[0] << 11) | (rgb_val[1] << 5) | (rgb_val[2]));
194#endif
195 FOR_NB_SCREENS(i)
196 draw_screen(&screens[i], title, rgb_val, newcolor, slider);
197
198 button = button_get(true);
199 switch (button)
200 {
201 case SLIDER_UP:
202#ifdef HAVE_LCD_REMOTE
203 case SLIDER_RC_UP:
204#endif
205 slider = (slider+2)%3;
206 break;
207
208 case SLIDER_DOWN:
209#ifdef HAVE_LCD_REMOTE
210 case SLIDER_RC_DOWN:
211#endif
212 slider = (slider+1)%3;
213 break;
214
215 case SLIDER_RIGHT:
216 case SLIDER_RIGHT|BUTTON_REPEAT:
217#ifdef HAVE_LCD_REMOTE
218 case SLIDER_RC_RIGHT:
219 case SLIDER_RC_RIGHT|BUTTON_REPEAT:
220#endif
221 if (rgb_val[slider] < max_val[slider])
222 rgb_val[slider]++;
223 break;
224
225 case SLIDER_LEFT:
226 case SLIDER_LEFT|BUTTON_REPEAT:
227#ifdef HAVE_LCD_REMOTE
228 case SLIDER_RC_LEFT:
229 case SLIDER_RC_LEFT|BUTTON_REPEAT:
230#endif
231 if (rgb_val[slider] > 0)
232 rgb_val[slider]--;
233 break;
234
235 case SLIDER_OK:
236#ifdef HAVE_LCD_REMOTE
237 case SLIDER_RC_OK:
238#endif
239 *color = newcolor;
240 exit = 1;
241 break;
242
243 case SLIDER_CANCEL:
244#ifdef HAVE_LCD_REMOTE
245 case SLIDER_RC_CANCEL:
246#endif
247 exit = 1;
248 break;
249
250 default:
251 if(default_event_handler(button) == SYS_USB_CONNECTED) {
252 display->set_foreground(fgcolor);
253 return true;
254 }
255 break;
256 }
257 }
258 display->set_foreground(fgcolor);
259
260 return false;
261}