summaryrefslogtreecommitdiff
path: root/apps/gui/bitmap
diff options
context:
space:
mode:
authorJonathan Gordon <rockbox@jdgordon.info>2011-09-11 10:44:17 +0000
committerJonathan Gordon <rockbox@jdgordon.info>2011-09-11 10:44:17 +0000
commit3d0317a273a99f277d88c491181ba220db9dd2b0 (patch)
tree53f10f49995065ec24aa5656d5c01dd76b8f88e1 /apps/gui/bitmap
parent93a600fdab817ccfc2c8f9301d9190aed3552ad6 (diff)
downloadrockbox-3d0317a273a99f277d88c491181ba220db9dd2b0.tar.gz
rockbox-3d0317a273a99f277d88c491181ba220db9dd2b0.zip
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
Diffstat (limited to 'apps/gui/bitmap')
-rw-r--r--apps/gui/bitmap/list-skinned.c57
1 files changed, 38 insertions, 19 deletions
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 @@
43#include "appevents.h" 43#include "appevents.h"
44 44
45static struct listitem_viewport_cfg *listcfg[NB_SCREENS] = {NULL}; 45static struct listitem_viewport_cfg *listcfg[NB_SCREENS] = {NULL};
46static const char *current_item_text_ptr; 46struct gui_synclist *current_list;
47static char current_item_text[MAX_PATH]; 47
48static enum themable_icons current_item_icon;
49void skinlist_set_cfg(enum screen_type screen, 48void skinlist_set_cfg(enum screen_type screen,
50 struct listitem_viewport_cfg *cfg) 49 struct listitem_viewport_cfg *cfg)
51{ 50{
@@ -54,7 +53,7 @@ void skinlist_set_cfg(enum screen_type screen,
54 if (listcfg[screen]) 53 if (listcfg[screen])
55 screens[screen].scroll_stop(&listcfg[screen]->selected_item_vp.vp); 54 screens[screen].scroll_stop(&listcfg[screen]->selected_item_vp.vp);
56 listcfg[screen] = cfg; 55 listcfg[screen] = cfg;
57 current_item_text_ptr = ""; 56 current_list = NULL;
58 } 57 }
59} 58}
60 59
@@ -64,15 +63,41 @@ static bool skinlist_is_configured(enum screen_type screen,
64 return (listcfg[screen] != NULL) && 63 return (listcfg[screen] != NULL) &&
65 (!list || (list && list->selected_size == 1)); 64 (!list || (list && list->selected_size == 1));
66} 65}
67 66static int current_drawing_line;
68const char* skinlist_get_item_text(void) 67static int offset_to_item(int offset, bool wrap)
68{
69 int item = current_drawing_line + offset;
70 if (!current_list)
71 return -1;
72 if (item < 0)
73 {
74 if (!wrap)
75 return -1;
76 else
77 item = (item + current_list->nb_items) % current_list->nb_items;
78 }
79 else if (item >= current_list->nb_items && !wrap)
80 return -1;
81 else
82 item = item % current_list->nb_items;
83 return item;
84}
85const char* skinlist_get_item_text(int offset, bool wrap, char* buf, size_t buf_size)
69{ 86{
70 const char* ret = P2STR((unsigned char*)current_item_text_ptr); 87 int item = offset_to_item(offset, wrap);
71 return ret; 88 if (item < 0 || !current_list)
89 return NULL;
90 const char* ret = current_list->callback_get_item_name(
91 item, current_list->data, buf, buf_size);
92 return P2STR((unsigned char*)ret);
72} 93}
73enum themable_icons skinlist_get_item_icon(void) 94
95enum themable_icons skinlist_get_item_icon(int offset, bool wrap)
74{ 96{
75 return current_item_icon; 97 int item = offset_to_item(offset, wrap);
98 if (item < 0 || !current_list || current_list->callback_get_item_icon == NULL)
99 return Icon_NOICON;
100 return current_list->callback_get_item_icon(item, current_list->data);
76} 101}
77 102
78static bool is_selected = false; 103static bool is_selected = false;
@@ -130,6 +155,7 @@ bool skinlist_draw(struct screen *display, struct gui_synclist *list)
130 struct gui_wps wps; 155 struct gui_wps wps;
131 if (!skinlist_is_configured(screen, list)) 156 if (!skinlist_is_configured(screen, list))
132 return false; 157 return false;
158 current_list = list;
133 wps.display = display; 159 wps.display = display;
134 wps.data = listcfg[screen]->data; 160 wps.data = listcfg[screen]->data;
135 display_lines = skinlist_get_line_count(screen, list); 161 display_lines = skinlist_get_line_count(screen, list);
@@ -146,14 +172,9 @@ bool skinlist_draw(struct screen *display, struct gui_synclist *list)
146 struct skin_viewport* skin_viewport; 172 struct skin_viewport* skin_viewport;
147 if (list_start_item+cur_line+1 > list->nb_items) 173 if (list_start_item+cur_line+1 > list->nb_items)
148 break; 174 break;
175 current_drawing_line = list_start_item+cur_line;
149 is_selected = list->show_selection_marker && 176 is_selected = list->show_selection_marker &&
150 list_start_item+cur_line == list->selected_item; 177 list_start_item+cur_line == list->selected_item;
151 current_item_text_ptr = list->callback_get_item_name(
152 list_start_item+cur_line,
153 list->data, current_item_text, MAX_PATH);
154 if (list->callback_get_item_icon != NULL)
155 current_item_icon = list->callback_get_item_icon(
156 list_start_item+cur_line, list->data);
157 178
158 for (viewport = listcfg[screen]->data->tree; 179 for (viewport = listcfg[screen]->data->tree;
159 viewport; 180 viewport;
@@ -219,9 +240,7 @@ bool skinlist_draw(struct screen *display, struct gui_synclist *list)
219 } 240 }
220 display->set_viewport(parent); 241 display->set_viewport(parent);
221 display->update_viewport(); 242 display->update_viewport();
222 current_item_text_ptr = list->callback_get_item_name( 243 current_drawing_line = list->selected_item;
223 list->selected_item,
224 list->data, current_item_text, 2048);
225#if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP) 244#if defined(HAVE_LCD_ENABLE) || defined(HAVE_LCD_SLEEP)
226 /* Abuse the callback to force the sbs to update */ 245 /* Abuse the callback to force the sbs to update */
227 send_event(LCD_EVENT_ACTIVATION, NULL); 246 send_event(LCD_EVENT_ACTIVATION, NULL);