summaryrefslogtreecommitdiff
path: root/apps/gui/skin_engine
diff options
context:
space:
mode:
authorJonathan Gordon <rockbox@jdgordon.info>2011-03-07 12:45:45 +0000
committerJonathan Gordon <rockbox@jdgordon.info>2011-03-07 12:45:45 +0000
commit343001b5f86f61a48b8520c9a1eb2790f50a8b27 (patch)
treebc1cf0e7451adb10668e9c1cff90e76cbbf55e3d /apps/gui/skin_engine
parent4cc2cc430c026ce59d089f76c678202d977bad37 (diff)
Merge a bunch of code which is 99% identical so it makes it easier to add more of these later
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29535 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/gui/skin_engine')
-rw-r--r--apps/gui/skin_engine/skin_display.c3
-rw-r--r--apps/gui/skin_engine/skin_engine.c62
-rw-r--r--apps/gui/skin_engine/skin_parser.c60
-rw-r--r--apps/gui/skin_engine/skin_render.c5
-rw-r--r--apps/gui/skin_engine/wps_debug.c2
-rw-r--r--apps/gui/skin_engine/wps_internals.h12
6 files changed, 85 insertions, 59 deletions
diff --git a/apps/gui/skin_engine/skin_display.c b/apps/gui/skin_engine/skin_display.c
index 5d90e14a0e..e5e6389b87 100644
--- a/apps/gui/skin_engine/skin_display.c
+++ b/apps/gui/skin_engine/skin_display.c
@@ -100,8 +100,9 @@ void skin_statusbar_changed(struct gui_wps *skin)
struct wps_data *data = skin->data;
const struct screen *display = skin->display;
const int screen = display->screen_type;
+ struct skin_viewport *svp = skin_find_item(VP_DEFAULT_LABEL, SKIN_FIND_VP, data);
- struct viewport *vp = &find_viewport(VP_DEFAULT_LABEL, false, data)->vp;
+ struct viewport *vp = &svp->vp;
viewport_set_defaults(vp, screen);
if (data->wps_sb_tag)
diff --git a/apps/gui/skin_engine/skin_engine.c b/apps/gui/skin_engine/skin_engine.c
index fbedbb96fd..61a41d9bc3 100644
--- a/apps/gui/skin_engine/skin_engine.c
+++ b/apps/gui/skin_engine/skin_engine.c
@@ -259,3 +259,65 @@ void skin_request_full_update(enum skinnable_screens skin)
FOR_NB_SCREENS(i)
skins[skin][i].needs_full_update = true;
}
+
+
+void *skin_find_item(const char *label, enum skin_find_what what,
+ struct wps_data *data)
+{
+ const char *itemlabel = NULL;
+ union {
+ struct skin_token_list *linkedlist;
+ struct skin_element *vplist;
+ } list;
+ bool isvplist = false;
+ void *ret = NULL;
+ switch (what)
+ {
+ case SKIN_FIND_UIVP:
+ case SKIN_FIND_VP:
+ list.vplist = data->tree;
+ isvplist = true;
+ break;
+ case SKIN_FIND_IMAGE:
+ list.linkedlist = data->images;
+ break;
+#ifdef HAVE_TOUCHSCREEN
+ case SKIN_FIND_TOUCHREGION:
+ list.linkedlist = data->touchregions;
+ break;
+#endif
+ }
+
+ while (list.linkedlist)
+ {
+ bool skip = false;
+ switch (what)
+ {
+ case SKIN_FIND_UIVP:
+ case SKIN_FIND_VP:
+ ret = list.vplist->data;
+ itemlabel = ((struct skin_viewport *)ret)->label;
+ skip = !(((struct skin_viewport *)ret)->is_infovp ==
+ (what==SKIN_FIND_UIVP));
+ break;
+ case SKIN_FIND_IMAGE:
+ ret = list.linkedlist->token->value.data;
+ itemlabel = ((struct gui_img *)ret)->label;
+ break;
+#ifdef HAVE_TOUCHSCREEN
+ case SKIN_FIND_TOUCHREGION:
+ ret = list.linkedlist->token->value.data;
+ itemlabel = ((struct touchregion *)ret)->label;
+ break;
+#endif
+ }
+ if (!skip && itemlabel && !strcmp(itemlabel, label))
+ return ret;
+
+ if (isvplist)
+ list.vplist = list.vplist->next;
+ else
+ list.linkedlist = list.linkedlist->next;
+ }
+ return NULL;
+}
diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c
index d7ecd34a04..9a792ead42 100644
--- a/apps/gui/skin_engine/skin_parser.c
+++ b/apps/gui/skin_engine/skin_parser.c
@@ -115,37 +115,8 @@ static void add_to_ll_chain(struct skin_token_list **list, struct skin_token_lis
}
}
-/* traverse the image linked-list for an image */
-struct gui_img* find_image(const char *label, struct wps_data *data)
-{
- struct skin_token_list *list = data->images;
- while (list)
- {
- struct gui_img *img = (struct gui_img *)list->token->value.data;
- if (!strcmp(img->label,label))
- return img;
- list = list->next;
- }
- return NULL;
-}
-
#endif
-/* traverse the viewport linked list for a viewport */
-struct skin_viewport* find_viewport(const char *label, bool uivp, struct wps_data *data)
-{
- struct skin_element *list = data->tree;
- while (list)
- {
- struct skin_viewport *vp = (struct skin_viewport *)list->data;
- if (vp->label && (vp->is_infovp == uivp) &&
- !strcmp(vp->label, label))
- return vp;
- list = list->next;
- }
- return NULL;
-}
-
#ifdef HAVE_LCD_BITMAP
/* create and init a new wpsll item.
@@ -240,7 +211,7 @@ static int parse_image_display(struct skin_element *element,
label[1] = '\0';
}
/* sanity check */
- img = find_image(label, wps_data);
+ img = skin_find_item(label, SKIN_FIND_IMAGE, wps_data);
if (!img || !id)
{
return WPS_ERROR_INVALID_PARAM;
@@ -298,7 +269,7 @@ static int parse_image_load(struct skin_element *element,
y = element->params[3].data.number;
/* check the image number and load state */
- if(find_image(id, wps_data))
+ if(skin_find_item(id, SKIN_FIND_IMAGE, wps_data))
{
/* Invalid image ID */
return WPS_ERROR_INVALID_PARAM;
@@ -680,7 +651,8 @@ static int parse_progressbar_tag(struct skin_element* element,
{
curr_param++;
param++;
- pb->slider = find_image(param->data.text, wps_data);
+ pb->slider = skin_find_item(param->data.text,
+ SKIN_FIND_IMAGE, wps_data);
}
else /* option needs the next param */
return -1;
@@ -703,7 +675,8 @@ static int parse_progressbar_tag(struct skin_element* element,
{
curr_param++;
param++;
- pb->backdrop = find_image(param->data.text, wps_data);
+ pb->backdrop = skin_find_item(param->data.text,
+ SKIN_FIND_IMAGE, wps_data);
}
else /* option needs the next param */
@@ -725,7 +698,7 @@ static int parse_progressbar_tag(struct skin_element* element,
if (image_filename)
{
- pb->image = find_image(image_filename, wps_data);
+ pb->image = skin_find_item(image_filename, SKIN_FIND_IMAGE, wps_data);
if (!pb->image) /* load later */
{
struct gui_img* img = (struct gui_img*)skin_buffer_alloc(sizeof(struct gui_img));
@@ -878,21 +851,6 @@ static int parse_albumart_load(struct skin_element* element,
#endif /* HAVE_ALBUMART */
#ifdef HAVE_TOUCHSCREEN
-struct touchregion* find_touchregion(const char *label,
- struct wps_data *data)
-{
- struct skin_token_list *list = data->touchregions;
- while (list)
- {
- struct touchregion *tr =
- (struct touchregion *)list->token->value.data;
- if (tr->label && !strcmp(tr->label, label))
- return tr;
- list = list->next;
- }
- return NULL;
-}
-
static int parse_lasttouch(struct skin_element *element,
struct wps_token *token,
struct wps_data *wps_data)
@@ -909,8 +867,8 @@ static int parse_lasttouch(struct skin_element *element,
for (i=0; i<element->params_count; i++)
{
if (element->params[i].type == STRING)
- data->region = find_touchregion(
- element->params[i].data.text, wps_data);
+ data->region = skin_find_item(element->params[i].data.text,
+ SKIN_FIND_TOUCHREGION, wps_data);
else if (element->params[i].type == INTEGER)
data->timeout = element->params[i].data.number;
}
diff --git a/apps/gui/skin_engine/skin_render.c b/apps/gui/skin_engine/skin_render.c
index 424e0c29cc..9fa940dba2 100644
--- a/apps/gui/skin_engine/skin_render.c
+++ b/apps/gui/skin_engine/skin_render.c
@@ -163,7 +163,7 @@ static bool do_non_text_tags(struct gui_wps *gwps, struct skin_draw_info *info,
{
struct image_display *id = token->value.data;
const char* label = id->label;
- struct gui_img *img = find_image(label, data);
+ struct gui_img *img = skin_find_item(label,SKIN_FIND_IMAGE, data);
if (img && img->loaded)
{
if (id->token == NULL)
@@ -281,7 +281,8 @@ static void do_tags_in_hidden_conditional(struct skin_element* branch,
if (token->type == SKIN_TOKEN_IMAGE_PRELOAD_DISPLAY)
{
struct image_display *id = token->value.data;
- struct gui_img *img = find_image(id->label, data);
+ struct gui_img *img = skin_find_item(id->label,
+ SKIN_FIND_IMAGE, data);
clear_image_pos(gwps, img);
}
else if (token->type == SKIN_TOKEN_PEAKMETER)
diff --git a/apps/gui/skin_engine/wps_debug.c b/apps/gui/skin_engine/wps_debug.c
index 2ab7e5ab4e..7f74105c66 100644
--- a/apps/gui/skin_engine/wps_debug.c
+++ b/apps/gui/skin_engine/wps_debug.c
@@ -156,7 +156,7 @@ static char *get_token_desc(struct wps_token *token, char *buf,
{
char subimage = '\0';
char label = token->value.i&0xFF;
- struct gui_img *img = find_image(label, data);
+ struct gui_img *img = skin_find_item(label, SKIN_FIND_IMAGE, data);
if (img && img->num_subimages > 1)
{
int item = token->value.i>>8;
diff --git a/apps/gui/skin_engine/wps_internals.h b/apps/gui/skin_engine/wps_internals.h
index 86d191f687..80303f85b3 100644
--- a/apps/gui/skin_engine/wps_internals.h
+++ b/apps/gui/skin_engine/wps_internals.h
@@ -364,10 +364,14 @@ const char *get_radio_token(struct wps_token *token, int preset_offset,
char *buf, int buf_size, int limit, int *intval);
#endif
-struct gui_img* find_image(const char *label, struct wps_data *data);
-struct skin_viewport* find_viewport(const char *label, bool uivp, struct wps_data *data);
-
-
+enum skin_find_what {
+ SKIN_FIND_VP = 0,
+ SKIN_FIND_UIVP,
+ SKIN_FIND_IMAGE,
+ SKIN_FIND_TOUCHREGION
+};
+void *skin_find_item(const char *label, enum skin_find_what what,
+ struct wps_data *data);
#ifdef SIMULATOR
#define DEBUG_SKIN_ENGINE
extern bool debug_wps;