Index: apps/gui/list.c =================================================================== --- apps/gui/list.c (revision 15563) +++ apps/gui/list.c (working copy) @@ -236,7 +236,7 @@ { screen_put_icon(display, 0, 0, gui_list->title_icon); #ifdef HAVE_LCD_BITMAP - text_pos = get_icon_width(display->screen_type)+2; /* pixels */ + text_pos = get_icon_width(gui_list->title_icon, display)+2; /* pixels */ #else text_pos = 1; /* chars */ #endif @@ -286,10 +286,10 @@ text_pos += SCROLLBAR_WIDTH; } if(draw_cursor) - text_pos += get_icon_width(display->screen_type) + 2; + text_pos += get_icon_width(Icon_Cursor, display) + 2; if(draw_icons) - text_pos += get_icon_width(display->screen_type) + 2; + text_pos += get_icon_width(Icon_Cursor, display) + 2; #else draw_cursor = true; if(draw_icons) Index: apps/gui/color_picker.c =================================================================== --- apps/gui/color_picker.c (revision 15563) +++ apps/gui/color_picker.c (working copy) @@ -116,7 +116,7 @@ #define SELECTOR_LR_MARGIN 0 /* Margin between ">" and text */ #define SELECTOR_TB_MARGIN 1 /* Margin on top and bottom of selector */ #define SWATCH_TOP_MARGIN 4 /* Space between last slider and swatch */ -#define SELECTOR_WIDTH get_icon_width(display->screen_type) +#define SELECTOR_WIDTH get_icon_width(Icon_Cursor, display) #define SELECTOR_HEIGHT 8 /* Height of > and < bitmaps */ /* dunno why lcd_set_drawinfo should be left out of struct screen */ @@ -223,7 +223,7 @@ screen_put_iconxy(display, MARGIN_LEFT, top, Icon_Cursor); screen_put_iconxy(display, display->width - MARGIN_RIGHT - - get_icon_width(display->screen_type), + get_icon_width(Icon_Cursor, display), top, Icon_Cursor); } Index: apps/gui/icon.c =================================================================== --- apps/gui/icon.c (revision 15563) +++ apps/gui/icon.c (working copy) @@ -33,6 +33,7 @@ #include #endif + /* These are just the file names, the full path is snprint'ed when used */ #define DEFAULT_VIEWER_BMP "viewers" #define DEFAULT_REMOTE_VIEWER_BMP "remote_viewers" @@ -41,53 +42,102 @@ #define MAX_ICON_HEIGHT 24 #define MAX_ICON_WIDTH 24 +/* various buffers for the loadable sets */ +#define ICON_BUFSIZE (MAX_ICON_HEIGHT * MAX_ICON_WIDTH * LCD_DEPTH/8) +#define MAINSET_SIZE (ICON_BUFSIZE*Icon_Mainset_count) +#define VIEWERSET_SIZE MAINSET_SIZE +static unsigned char mainset[NB_SCREENS][MAINSET_SIZE]; +static unsigned char viewerset[NB_SCREENS][VIEWERSET_SIZE]; -/* We dont actually do anything with these pointers, - but they need to be grouped like this to save code - so storing them as void* is ok. (stops compile warning) */ -static const void * inbuilt_icons[NB_SCREENS] = { - (void*)default_icons -#if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1) - , (void*)remote_default_icons +enum iconset { + iconset_unknown = -1, + iconset_mainicons = 0, + iconset_viewericons, + iconset_statusbar, + iconset_statusbar_numbers, +#ifdef HAVE_RECORDING + iconset_statusbar_recscreen, #endif + iconset_count }; -static const int default_width[NB_SCREENS] = { - BMPWIDTH_default_icons -#if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1) - , BMPWIDTH_remote_default_icons -#endif + +struct iconset_info { + const enum themable_icons first_icon; /* the first icon value this set is for */ + enum themable_icons last_icon; /* the last icon value this set is for */ + /* not const so the count can vary for viewers */ + const void *default_data; /* the default (usually inbuilt) set data */ + const int default_height; /* total height of iconset */ + const int default_width; /* icon width */ + + void *loaded_data; + int max_load_size; + int loaded_height; + int loaded_width; + bool use_loaded_icons; }; -/* height of whole file */ -static const int default_height[NB_SCREENS] = { - BMPHEIGHT_default_icons -#if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1) - , BMPHEIGHT_remote_default_icons +static struct iconset_info iconsets[NB_SCREENS][iconset_count] = { + [SCREEN_MAIN][iconset_mainicons] = + { + Icon_Audio, Icon_Rockbox, + default_icons, BMPHEIGHT_default_icons, BMPWIDTH_default_icons, + &mainset[SCREEN_MAIN], MAINSET_SIZE, 0, 0, false + }, + [SCREEN_MAIN][iconset_viewericons] = + { + Icon_Viewers_placeholder, Icon_Viewers_Last, + NULL, 0, 0, + &viewerset[SCREEN_MAIN], MAINSET_SIZE, 0, 0, false + }, +#if defined(HAVE_REMOTE_LCD) + [SCREEN_REMOTE][iconset_mainicons] = + { + Icon_Audio, Icon_Rockbox, + remote_default_icons, BMPHEIGHT_remote_default_icons, + BMPWIDTH_remote_default_icons, + &mainset[SCREEN_REMOTE], VIEWERSET_SIZE, 0, 0, false + }, + [SCREEN_REMOTE][iconset_viewericons] = + { + Icon_Viewers_placeholder, Icon_Viewers_Last, + NULL, 0, 0, + &viewerset[SCREEN_REMOTE], VIEWERSET_SIZE, 0, 0, false + }, #endif }; - -#define IMG_BUFSIZE (MAX_ICON_HEIGHT * MAX_ICON_WIDTH * \ - Icon_Last_Themeable *LCD_DEPTH/8) -static unsigned char icon_buffer[NB_SCREENS][IMG_BUFSIZE]; -static bool custom_icons_loaded[NB_SCREENS] = {false}; -static struct bitmap user_iconset[NB_SCREENS]; - -static unsigned char viewer_icon_buffer[NB_SCREENS][IMG_BUFSIZE]; -static bool viewer_icons_loaded[NB_SCREENS] = {false}; -static struct bitmap viewer_iconset[NB_SCREENS]; - - -#define ICON_HEIGHT(screen) (!custom_icons_loaded[screen]? \ - default_height[screen] : \ - user_iconset[screen].height) \ - / Icon_Last_Themeable +static enum iconset get_iconset(enum themable_icons icon, + struct screen * display) +{ + int i; + for (i=0;iscreen_type][i].first_icon <= icon && + iconsets[display->screen_type][i].last_icon >= icon) + return i; + } + return iconset_unknown; +} +static void icon_size(enum themable_icons icon, struct screen * display, + int *height, int *width) +{ + int set_count; + struct iconset_info *set = &iconsets[display->screen_type] + [get_iconset(icon, display)]; + set_count = set->last_icon-set->first_icon; + if (set->use_loaded_icons) + { + *height = set->loaded_height/set_count; + *width = set->loaded_width; + } + else + { + *height = set->default_height/set_count; + *width = set->default_width; + } +} -#define ICON_WIDTH(screen) (!custom_icons_loaded[screen]? \ - default_width[screen] : \ - user_iconset[screen].width) - -/* x,y in letters, not pixles */ +/* x,y in letters, not pixels */ void screen_put_icon(struct screen * display, int x, int y, enum themable_icons icon) { @@ -99,14 +149,14 @@ enum themable_icons icon) { int xpos, ypos; - int width, height; - int screen = display->screen_type; + int width, height, icon_h, icon_w; display->getstringsize((unsigned char *)"M", &width, &height); - xpos = x*ICON_WIDTH(screen) + off_x; + icon_size(icon, display, &icon_h, &icon_w); + xpos = x*icon_w + off_x; ypos = y*height + display->getymargin() + off_y; - if ( height > ICON_HEIGHT(screen) )/* center the cursor */ - ypos += (height - ICON_HEIGHT(screen)) / 2; + if ( height > icon_h )/* center the cursor */ + ypos += (height - icon_h) / 2; screen_put_iconxy(display, xpos, ypos, icon); } @@ -115,37 +165,51 @@ int xpos, int ypos, enum themable_icons icon) { const void *data; - int screen = display->screen_type; - int width = ICON_WIDTH(screen); - int height = ICON_HEIGHT(screen); + struct iconset_info *set = &iconsets[display->screen_type] + [get_iconset(icon, display)]; + int height, width, count; screen_bitmap_part_func *draw_func = NULL; - + count = set->last_icon - set->first_icon; if (icon == Icon_NOICON) { + if (set->use_loaded_icons) + { + height = set->loaded_height/count; + width = set->loaded_width; + } + else if (set->default_data != NULL) + { + height = set->default_height/count; + width = set->default_width; + } + else + { + width = 6; height = 8; + } screen_clear_area(display, xpos, ypos, width, height); return; } - else if (icon >= Icon_Last_Themeable) + else { - icon -= Icon_Last_Themeable; - if (!viewer_icons_loaded[screen] || - (global_status.viewer_icon_count*height - > viewer_iconset[screen].height) || - (icon * height > viewer_iconset[screen].height)) + icon -= set->first_icon; + if (set->use_loaded_icons) { + height = set->loaded_height/count; + width = set->loaded_width; + data = set->loaded_data; + } + else if (set->default_data != NULL) + { + height = set->default_height/count; + width = set->default_width; + data = set->default_data; + } + else + { screen_put_iconxy(display, xpos, ypos, Icon_Questionmark); return; } - data = viewer_iconset[screen].data; } - else if (custom_icons_loaded[screen]) - { - data = user_iconset[screen].data; - } - else - { - data = inbuilt_icons[screen]; - } /* add some left padding to the icons if they are on the edge */ if (xpos == 0) xpos++; @@ -156,7 +220,6 @@ else #endif draw_func = display->bitmap_part; - draw_func(data, 0, height * icon, width, xpos, ypos, width, height); } @@ -169,61 +232,31 @@ #endif } -enum Iconset { - Iconset_Mainscreen, - Iconset_Mainscreen_viewers, -#if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1) - Iconset_Remotescreen, - Iconset_Remotescreen_viewers, -#endif -}; -static void load_icons(const char* filename, enum Iconset iconset, - bool allow_disable) +static void load_icons(const char* filename, enum iconset iconset, + enum screen_type display, bool allow_disable) { int size_read; - bool *loaded_ok = NULL; - struct bitmap *bmp = NULL; + struct bitmap bmp; int bmpformat = (FORMAT_NATIVE|FORMAT_DITHER); - - switch (iconset) - { - case Iconset_Mainscreen: - loaded_ok = &custom_icons_loaded[SCREEN_MAIN]; - bmp = &user_iconset[SCREEN_MAIN]; - bmp->data = icon_buffer[SCREEN_MAIN]; - break; - case Iconset_Mainscreen_viewers: - loaded_ok = &viewer_icons_loaded[SCREEN_MAIN]; - bmp = &viewer_iconset[SCREEN_MAIN]; - bmp->data = viewer_icon_buffer[SCREEN_MAIN]; - break; -#if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1) - case Iconset_Remotescreen: - loaded_ok = &custom_icons_loaded[SCREEN_REMOTE]; - bmp = &user_iconset[SCREEN_REMOTE]; - bmp->data = icon_buffer[SCREEN_REMOTE]; - bmpformat |= FORMAT_REMOTE; - break; - case Iconset_Remotescreen_viewers: - loaded_ok = &viewer_icons_loaded[SCREEN_REMOTE]; - bmp = &viewer_iconset[SCREEN_REMOTE]; - bmp->data = viewer_icon_buffer[SCREEN_REMOTE]; - bmpformat |= FORMAT_REMOTE; - break; + struct iconset_info *set = &iconsets[display][iconset]; +#if defined(HAVE_REMOTE_LCD) + if (display == SCREEN_REMOTE) + bmpformat |= FORMAT_REMOTE; #endif - } - - *loaded_ok = false; + bmp.data = set->loaded_data; + set->use_loaded_icons = false; if (!allow_disable || (filename[0] && filename[0] != '-')) { char path[MAX_PATH]; snprintf(path, sizeof(path), "%s/%s.bmp", ICON_DIR, filename); - size_read = read_bmp_file(path, bmp, IMG_BUFSIZE, bmpformat); + size_read = read_bmp_file(path, &bmp, set->max_load_size, bmpformat); if (size_read > 0) { - *loaded_ok = true; + set->use_loaded_icons = true; + set->loaded_height = bmp.height; + set->loaded_width = bmp.width; } } } @@ -231,37 +264,45 @@ void icons_init(void) { - load_icons(global_settings.icon_file, Iconset_Mainscreen, true); + load_icons(global_settings.icon_file, iconset_mainicons, SCREEN_MAIN, true); if (*global_settings.viewers_icon_file) { load_icons(global_settings.viewers_icon_file, - Iconset_Mainscreen_viewers, true); + iconset_viewericons, SCREEN_MAIN, true); read_viewer_theme_file(); } else { - load_icons(DEFAULT_VIEWER_BMP, Iconset_Mainscreen_viewers, false); + load_icons(DEFAULT_VIEWER_BMP, iconset_viewericons, SCREEN_MAIN, false); } #if defined(HAVE_REMOTE_LCD) && (NB_SCREENS > 1) load_icons(global_settings.remote_icon_file, - Iconset_Remotescreen, true); + iconset_mainicons, SCREEN_REMOTE, true); if (*global_settings.remote_viewers_icon_file) { load_icons(global_settings.remote_viewers_icon_file, - Iconset_Remotescreen_viewers, true); + iconset_viewericons, SCREEN_REMOTE, true); } else { load_icons(DEFAULT_REMOTE_VIEWER_BMP, - Iconset_Remotescreen_viewers, false); + iconset_viewericons, SCREEN_REMOTE, false); } #endif } -int get_icon_width(enum screen_type screen_type) +int get_icon_width(enum themable_icons icon, struct screen * screen) { - return ICON_WIDTH(screen_type); + int h,w; + icon_size(icon, screen, &h, &w); + return w; } + +void set_viewer_icon_count(enum screen_type display, int count) +{ + iconsets[display][iconset_viewericons].last_icon = + iconsets[display][iconset_viewericons].first_icon+count; +} Index: apps/gui/icon.h =================================================================== --- apps/gui/icon.h (revision 15563) +++ apps/gui/icon.h (working copy) @@ -66,7 +66,10 @@ Icon_file_view_menu, Icon_EQ, Icon_Rockbox, - Icon_Last_Themeable, + Icon_Mainset_count, + /* set aside a group for the viewers... same amount as the main iconset */ + Icon_Viewers_placeholder, + Icon_Viewers_Last = Icon_Viewers_placeholder+Icon_Mainset_count, }; /* @@ -107,9 +110,13 @@ #ifdef HAVE_LCD_CHARCELLS # define CURSOR_CHAR 0xe10c -# define get_icon_width(a) 6 +# define get_icon_width(i,s) 6 #else -int get_icon_width(enum screen_type screen_type); +int get_icon_width(enum themable_icons icon, struct screen * screen); #endif +#ifdef HAVE_LCD_BITMAP +void set_viewer_icon_count(enum screen_type display, int count); +#endif + #endif /*_GUI_ICON_H_*/ Index: apps/player/icons.c =================================================================== --- apps/player/icons.c (revision 15563) +++ apps/player/icons.c (working copy) @@ -39,8 +39,8 @@ }; static const long icon_unknown = old_Icon_Unknown; -static const long icons[Icon_Last_Themeable] = { - [0 ... Icon_Last_Themeable-1] = 0, +static const long icons[Icon_Mainset_count] = { + [0 ... Icon_Mainset_count-1] = 0, [Icon_Audio] = old_Icon_Audio, [Icon_Folder] = old_Icon_Folder, Index: apps/filetypes.c =================================================================== --- apps/filetypes.c (revision 15563) +++ apps/filetypes.c (working copy) @@ -223,7 +223,7 @@ int number = atoi(icon); if (number > global_status.viewer_icon_count) global_status.viewer_icon_count++; - custom_filetype_icons[i] = Icon_Last_Themeable + number; + custom_filetype_icons[i] = Icon_Viewers_placeholder + number; } break; } @@ -231,6 +231,8 @@ } close(fd); custom_icons_loaded = true; + FOR_NB_SCREENS(i) + set_viewer_icon_count(i, global_status.viewer_icon_count); } #endif @@ -332,7 +334,7 @@ else if (*s == '-') filetypes[filetype_count].icon = Icon_NOICON; else if (*s >= '0' && *s <= '9') - filetypes[filetype_count].icon = Icon_Last_Themeable + atoi(s); + filetypes[filetype_count].icon = Icon_Viewers_placeholder + atoi(s); #else filetypes[filetype_count].icon = Icon_NOICON; #endif