From 3d0317a273a99f277d88c491181ba220db9dd2b0 Mon Sep 17 00:00:00 2001 From: Jonathan Gordon Date: Sun, 11 Sep 2011 10:44:17 +0000 Subject: Rework how the skin gets the list item text to save some ram. Also allow the %LI and %LT tags to take 2 optional parameters to get a different items text/icon: %LT(offset, nowrap) - get the text for the "being drawn"+offset item (offset being + or -). if the second param is "nowrap" (Without quotes) the text will be blank if the item would need to wrap. Same for the icon e.g: %LT(-1) %LT << %LT(1, nowrap) will display: Four Five << Six (or nothing if Five is the last item) git-svn-id: svn://svn.rockbox.org/rockbox/trunk@30502 a1c6a512-1295-4272-9138-f99709370657 --- apps/gui/bitmap/list-skinned.c | 57 ++++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 19 deletions(-) (limited to 'apps/gui/bitmap/list-skinned.c') diff --git a/apps/gui/bitmap/list-skinned.c b/apps/gui/bitmap/list-skinned.c index 2f3ca2bd2d..5f53784ccc 100644 --- a/apps/gui/bitmap/list-skinned.c +++ b/apps/gui/bitmap/list-skinned.c @@ -43,9 +43,8 @@ #include "appevents.h" static struct listitem_viewport_cfg *listcfg[NB_SCREENS] = {NULL}; -static const char *current_item_text_ptr; -static char current_item_text[MAX_PATH]; -static enum themable_icons current_item_icon; +struct gui_synclist *current_list; + void skinlist_set_cfg(enum screen_type screen, struct listitem_viewport_cfg *cfg) { @@ -54,7 +53,7 @@ void skinlist_set_cfg(enum screen_type screen, if (listcfg[screen]) screens[screen].scroll_stop(&listcfg[screen]->selected_item_vp.vp); listcfg[screen] = cfg; - current_item_text_ptr = ""; + current_list = NULL; } } @@ -64,15 +63,41 @@ static bool skinlist_is_configured(enum screen_type screen, return (listcfg[screen] != NULL) && (!list || (list && list->selected_size == 1)); } - -const char* skinlist_get_item_text(void) +static int current_drawing_line; +static int offset_to_item(int offset, bool wrap) +{ + int item = current_drawing_line + offset; + if (!current_list) + return -1; + if (item < 0) + { + if (!wrap) + return -1; + else + item = (item + current_list->nb_items) % current_list->nb_items; + } + else if (item >= current_list->nb_items && !wrap) + return -1; + else + item = item % current_list->nb_items; + return item; +} +const char* skinlist_get_item_text(int offset, bool wrap, char* buf, size_t buf_size) { - const char* ret = P2STR((unsigned char*)current_item_text_ptr); - return ret; + int item = offset_to_item(offset, wrap); + if (item < 0 || !current_list) + return NULL; + const char* ret = current_list->callback_get_item_name( + item, current_list->data, buf, buf_size); + return P2STR((unsigned char*)ret); } -enum themable_icons skinlist_get_item_icon(void) + +enum themable_icons skinlist_get_item_icon(int offset, bool wrap) { - return current_item_icon; + int item = offset_to_item(offset, wrap); + if (item < 0 || !current_list || current_list->callback_get_item_icon == NULL) + return Icon_NOICON; + return current_list->callback_get_item_icon(item, current_list->data); } static bool is_selected = false; @@ -130,6 +155,7 @@ bool skinlist_draw(struct screen *display, struct gui_synclist *list) struct gui_wps wps; if (!skinlist_is_configured(screen, list)) return false; + current_list = list; wps.display = display; wps.data = listcfg[screen]->data; display_lines = skinlist_get_line_count(screen, list); @@ -146,14 +172,9 @@ bool skinlist_draw(struct screen *display, struct gui_synclist *list) struct skin_viewport* skin_viewport; if (list_start_item+cur_line+1 > list->nb_items) break; + current_drawing_line = list_start_item+cur_line; is_selected = list->show_selection_marker && list_start_item+cur_line == list->selected_item; - current_item_text_ptr = list->callback_get_item_name( - list_start_item+cur_line, - list->data, current_item_text, MAX_PATH); - if (list->callback_get_item_icon != NULL) - current_item_icon = list->callback_get_item_icon( - list_start_item+cur_line, list->data); for (viewport = listcfg[screen]->data->tree; viewport; @@ -219,9 +240,7 @@ bool skinlist_draw(struct screen *display, struct gui_synclist *list) } display->set_viewport(parent); display->update_viewport(); - current_item_text_ptr = list->callback_get_item_name( - list->selected_item, - list->data, current_item_text, 2048); + current_drawing_line = list->selected_item; #if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP) /* Abuse the callback to force the sbs to update */ send_event(LCD_EVENT_ACTIVATION, NULL); -- cgit v1.2.3