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" |
| 26 | #include "debug.h" |
| 27 | #include "misc.h" |
| 28 | #include "settings.h" |
| 29 | #include "scrollbar.h" |
| 30 | #include "lang.h" |
Zakk Roberts | 87142ab | 2006-03-04 10:55:54 +0000 | [diff] [blame] | 31 | #include "splash.h" |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 32 | #include "action.h" |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 33 | |
| 34 | #define TEXT_MARGIN display->char_width+2 |
| 35 | #define SLIDER_START 20 |
| 36 | |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 37 | static const int max_val[3] = {LCD_MAX_RED,LCD_MAX_GREEN,LCD_MAX_BLUE}; |
| 38 | |
Zakk Roberts | b81f596 | 2006-03-21 02:02:04 +0000 | [diff] [blame] | 39 | static void draw_screen(struct screen *display, char *title, |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 40 | 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 Chapman | 3ea74cc | 2006-07-19 14:31:24 +0000 | [diff] [blame] | 50 | bool display_three_rows = (display->height/6) > display->char_height; |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 51 | |
| 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 Roberts | b81f596 | 2006-03-21 02:02:04 +0000 | [diff] [blame] | 60 | |
Dave Chapman | 3ea74cc | 2006-07-19 14:31:24 +0000 | [diff] [blame] | 61 | text_top = display->char_height*2; |
Dave Chapman | 91d2678 | 2006-07-19 15:07:08 +0000 | [diff] [blame] | 62 | bg_col = background_color; |
Dave Chapman | 3ea74cc | 2006-07-19 14:31:24 +0000 | [diff] [blame] | 63 | for (i=0; i<3 ;i++) |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 64 | { |
Dave Chapman | 3ea74cc | 2006-07-19 14:31:24 +0000 | [diff] [blame] | 65 | if (!display_three_rows) |
| 66 | i = row; |
Zakk Roberts | b81f596 | 2006-03-21 02:02:04 +0000 | [diff] [blame] | 67 | |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 68 | if (i==row) |
| 69 | { |
Dave Chapman | 3ea74cc | 2006-07-19 14:31:24 +0000 | [diff] [blame] | 70 | if ((global_settings.invert_cursor) && (display->depth >2)) |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 71 | { |
| 72 | display->fillrect(0,text_top-1,display->width,display->char_height+2); |
| 73 | bg_col = text_color; |
| 74 | } |
Dave Chapman | 3ea74cc | 2006-07-19 14:31:24 +0000 | [diff] [blame] | 75 | else if (display_three_rows) |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 76 | { |
| 77 | display->putsxy(0,text_top,">"); |
Dave Chapman | 3ea74cc | 2006-07-19 14:31:24 +0000 | [diff] [blame] | 78 | display->putsxy(display->width-display->char_width-2,text_top,"<"); |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 79 | 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 Roberts | b81f596 | 2006-03-21 02:02:04 +0000 | [diff] [blame] | 92 | { |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 93 | if (display->depth > 1) |
Zakk Roberts | b81f596 | 2006-03-21 02:02:04 +0000 | [diff] [blame] | 94 | display->set_foreground(text_color); |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 95 | 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 Roberts | b81f596 | 2006-03-21 02:02:04 +0000 | [diff] [blame] | 106 | |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 107 | text_top += display->char_height/4; |
Zakk Roberts | b81f596 | 2006-03-21 02:02:04 +0000 | [diff] [blame] | 108 | |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 109 | gui_scrollbar_draw(display,SLIDER_START,text_top,slider_width, |
| 110 | display->char_height/2, |
Zakk Roberts | b81f596 | 2006-03-21 02:02:04 +0000 | [diff] [blame] | 111 | max_val[i],0,rgb_val[i],HORIZONTAL); |
Dave Chapman | 3ea74cc | 2006-07-19 14:31:24 +0000 | [diff] [blame] | 112 | if (!display_three_rows) |
| 113 | break; |
| 114 | text_top += display->char_height; |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | if (display->depth > 1) { |
| 118 | display->set_background(background_color); |
| 119 | display->set_foreground(text_color); |
| 120 | } |
| 121 | |
Dave Chapman | 3ea74cc | 2006-07-19 14:31:24 +0000 | [diff] [blame] | 122 | if (text_top + (display->char_height*2) < (display->height-40-display->char_height)) |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 123 | 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 Chapman | 3ea74cc | 2006-07-19 14:31:24 +0000 | [diff] [blame] | 132 | display->putsxy((display->width-(display->char_width*11))/2,text_top,buf); |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 133 | |
| 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 Roberts | b81f596 | 2006-03-21 02:02:04 +0000 | [diff] [blame] | 146 | set_color |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 147 | returns true if USB was inserted, false otherwise |
| 148 | color is a pointer to the colour (in native format) to modify |
Zakk Roberts | 87142ab | 2006-03-04 10:55:54 +0000 | [diff] [blame] | 149 | set banned_color to -1 to allow all |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 150 | ***********/ |
Zakk Roberts | 87142ab | 2006-03-04 10:55:54 +0000 | [diff] [blame] | 151 | bool set_color(struct screen *display,char *title, int* color, int banned_color) |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 152 | { |
| 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 Chapman | 3ea74cc | 2006-07-19 14:31:24 +0000 | [diff] [blame] | 183 | { |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 184 | draw_screen(&screens[i], title, rgb_val, newcolor, slider); |
Dave Chapman | 3ea74cc | 2006-07-19 14:31:24 +0000 | [diff] [blame] | 185 | } |
| 186 | |
Jonathan Gordon | d12f81d | 2006-08-21 07:03:15 +0000 | [diff] [blame] | 187 | button = get_action(CONTEXT_SETTINGS_COLOURCHOOSER,TIMEOUT_BLOCK); |
Zakk Roberts | b81f596 | 2006-03-21 02:02:04 +0000 | [diff] [blame] | 188 | switch (button) |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 189 | { |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 190 | case ACTION_STD_PREV: |
Jonathan Gordon | d12f81d | 2006-08-21 07:03:15 +0000 | [diff] [blame] | 191 | case ACTION_STD_PREVREPEAT: |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 192 | slider = (slider+2)%3; |
| 193 | break; |
| 194 | |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 195 | case ACTION_STD_NEXT: |
Jonathan Gordon | d12f81d | 2006-08-21 07:03:15 +0000 | [diff] [blame] | 196 | case ACTION_STD_NEXTREPEAT: |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 197 | slider = (slider+1)%3; |
| 198 | break; |
| 199 | |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 200 | case ACTION_SETTINGS_INC: |
| 201 | case ACTION_SETTINGS_INCREPEAT: |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 202 | if (rgb_val[slider] < max_val[slider]) |
| 203 | rgb_val[slider]++; |
| 204 | break; |
| 205 | |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 206 | case ACTION_SETTINGS_DEC: |
| 207 | case ACTION_SETTINGS_DECREPEAT: |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 208 | if (rgb_val[slider] > 0) |
| 209 | rgb_val[slider]--; |
| 210 | break; |
Zakk Roberts | b81f596 | 2006-03-21 02:02:04 +0000 | [diff] [blame] | 211 | |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 212 | case ACTION_STD_OK: |
Zakk Roberts | 87142ab | 2006-03-04 10:55:54 +0000 | [diff] [blame] | 213 | if ((banned_color!=-1) && (banned_color == newcolor)) |
| 214 | { |
| 215 | gui_syncsplash(HZ*2,true,str(LANG_COLOR_UNACCEPTABLE)); |
| 216 | break; |
Zakk Roberts | b81f596 | 2006-03-21 02:02:04 +0000 | [diff] [blame] | 217 | } |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 218 | *color = newcolor; |
| 219 | exit = 1; |
| 220 | break; |
| 221 | |
Linus Nielsen Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 222 | case ACTION_STD_CANCEL: |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 223 | 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 Feltzing | 224c0a1 | 2006-08-15 12:27:07 +0000 | [diff] [blame] | 235 | action_signalscreenchange(); |
Dave Chapman | 603f87f | 2006-02-26 02:48:05 +0000 | [diff] [blame] | 236 | return false; |
| 237 | } |