diff options
| author | Dave Chapman <dave@dchapman.com> | 2006-02-26 02:48:05 +0000 |
|---|---|---|
| committer | Dave Chapman <dave@dchapman.com> | 2006-02-26 02:48:05 +0000 |
| commit | 603f87fe3c0557cb31386fb89c0a49fb72102735 (patch) | |
| tree | fa75366ddf1a1dc293e49ec29b9944d448da6c67 /apps/settings.c | |
| parent | dd2a5294d67266e5cf7b8739d645a2cf6edd7a28 (diff) | |
| download | rockbox-603f87fe3c0557cb31386fb89c0a49fb72102735.zip rockbox-603f87fe3c0557cb31386fb89c0a49fb72102735.tar.gz rockbox-603f87fe3c0557cb31386fb89c0a49fb72102735.tar.bz2 rockbox-603f87fe3c0557cb31386fb89c0a49fb72102735.tar.xz | |
Foreground/Background colour settings. Based on patch #3050 by Jonathan Gordon, extended my me. The principle of the patch is that the three sliders contain the native ranges (currently 0..31, 0..63, 0..31), and the equivalent RGB888 colour is displayed underneath. The config block (and global_settings struct) contain the native value for the fg/bg colours (either RGB565 or RGB565SWAPPED), but the text .cfg files contain the RGB888 value written as 6 hex digits.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@8840 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/settings.c')
| -rw-r--r-- | apps/settings.c | 61 |
1 files changed, 59 insertions, 2 deletions
diff --git a/apps/settings.c b/apps/settings.c index 72939e5..5a42b17 100644 --- a/apps/settings.c +++ b/apps/settings.c @@ -89,7 +89,7 @@ const char rec_base_directory[] = REC_BASE_DIR; #include "dsp.h" #endif -#define CONFIG_BLOCK_VERSION 36 +#define CONFIG_BLOCK_VERSION 37 #define CONFIG_BLOCK_SIZE 512 #define RTC_BLOCK_SIZE 44 @@ -122,7 +122,7 @@ struct bit_entry int default_val; /* min 15 bit */ /* variable name in a .cfg file, NULL if not to be saved */ const char* cfg_name; - /* set of values, or NULL for a numerical value */ + /* set of values, "rgb" for a color, or NULL for a numerical value */ const char* cfg_val; }; @@ -545,6 +545,10 @@ static const struct bit_entry hd_bits[] = {2, S_O(cliplight), 0, "cliplight", "off,main,both,remote" }, #endif /* CONFIG_BACKLIGHT */ #endif /*HAVE_RECORDING*/ +#ifdef HAVE_LCD_COLOR + {LCD_DEPTH,S_O(fg_color),LCD_DEFAULT_FG,"foreground color","rgb"}, + {LCD_DEPTH,S_O(bg_color),LCD_DEFAULT_BG,"background color","rgb"}, +#endif /* If values are just added to the end, no need to bump the version. */ /* new stuff to be added at the end */ @@ -596,6 +600,39 @@ static void set_bits( p[long_index] = (p[long_index] & ~mask) | (value << bit_index); } +#ifdef HAVE_LCD_COLOR +/* + * Helper function to convert a string of 6 hex digits to a native colour + */ + +#define hex2dec(c) (((c) >= '0' && ((c) <= '9')) ? (toupper(c)) - '0' : \ + (toupper(c)) - 'A' + 10) + +int hex_to_rgb(const char* hex) +{ int ok = 1; + int i; + int red, green, blue; + + if (strlen(hex) == 6) { + for (i=0; i < 6; i++ ) { + if (!isxdigit(hex[i])) { + ok=0; + break; + } + } + + if (ok) { + red = (hex2dec(hex[0]) << 4) | hex2dec(hex[1]); + green = (hex2dec(hex[2]) << 4) | hex2dec(hex[3]); + blue = (hex2dec(hex[4]) << 4) | hex2dec(hex[5]); + return LCD_RGBPACK(red,green,blue); + } + } + + return 0; +} +#endif + /* * Calculates the checksum for the config block and returns it */ @@ -1013,6 +1050,8 @@ void settings_apply(void) } else { lcd_set_backdrop(NULL); } + screens[SCREEN_MAIN].set_foreground(global_settings.fg_color); + screens[SCREEN_MAIN].set_background(global_settings.bg_color); #endif #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1) @@ -1225,6 +1264,12 @@ static int load_cfg_table( { /* numerical value, just convert the string */ val = atoi(value); } +#if HAVE_LCD_COLOR + else if (!strncasecmp(p_table[i].cfg_val,"rgb",4)) + { + val = hex_to_rgb(value); + } +#endif else { /* set of string values, find the index */ const char* item; @@ -1410,6 +1455,15 @@ static void save_cfg_table(const struct bit_entry* p_table, int count, int fd) { fdprintf(fd, "%s: %ld\r\n", p_run->cfg_name, value); } +#ifdef HAVE_LCD_COLOR + else if (!strcasecmp(p_run->cfg_val, "rgb")) + { + fdprintf(fd, "%s: %02x%02x%02x\r\n", p_run->cfg_name, + (int)RGB_UNPACK_RED(value), + (int)RGB_UNPACK_GREEN(value), + (int)RGB_UNPACK_BLUE(value)); + } +#endif else /* write as item */ { const char* p = p_run->cfg_val; @@ -1566,6 +1620,9 @@ void settings_reset(void) { global_settings.lang_file[0] = '\0'; #ifdef HAVE_LCD_COLOR global_settings.backdrop_file[0] = '\0'; + + global_settings.fg_color = LCD_DEFAULT_FG; + global_settings.bg_color = LCD_DEFAULT_BG; #endif } |