From b49577b3815d1cd3a657a709c81f1ff7d0c07ae4 Mon Sep 17 00:00:00 2001 From: Jonathan Gordon Date: Mon, 14 Jun 2010 10:00:22 +0000 Subject: [PATCH] some tags need special handling when they are in the wrong branch of a conditional, so go ahead and make that work :p also replace malloc with skin_alloc git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26842 a1c6a512-1295-4272-9138-f99709370657 --- utils/newparser/handle_tags.c | 12 ++++++-- utils/newparser/skin_render.c | 53 +++++++++++++++++++++++++++++++++- utils/newparser/skin_structs.h | 4 +++ 3 files changed, 65 insertions(+), 4 deletions(-) diff --git a/utils/newparser/handle_tags.c b/utils/newparser/handle_tags.c index a725a52396..28c4548549 100644 --- a/utils/newparser/handle_tags.c +++ b/utils/newparser/handle_tags.c @@ -132,7 +132,7 @@ int handle_tree(struct skin *skin, struct skin_element* tree, struct line *line) if (element->tag && next->type == LINE && element->line == next->line) { - struct line *line = (struct line*)malloc(sizeof(struct line)); + struct line *line = (struct line*)skin_alloc(sizeof(struct line)); line->update_mode = 0; line->eat_line_ending = true; next->data = line; @@ -140,7 +140,7 @@ int handle_tree(struct skin *skin, struct skin_element* tree, struct line *line) } else if (element->type == LINE && !element->data) { - struct line *line = (struct line*)malloc(sizeof(struct line)); + struct line *line = (struct line*)skin_alloc(sizeof(struct line)); line->update_mode = 0; line->eat_line_ending = false; element->data = line; @@ -148,11 +148,17 @@ int handle_tree(struct skin *skin, struct skin_element* tree, struct line *line) } else if (element->type == SUBLINES) { - struct subline *subline = malloc(sizeof(struct subline)); + struct subline *subline = skin_alloc(sizeof(struct subline)); subline->current_line = -1; subline->last_change_tick = 0; element->data = subline; } + else if (element->type == CONDITIONAL) + { + struct conditional *cond = skin_alloc(sizeof(struct conditional)); + cond->last_value = element->children_count; + element->data = cond; + } else if (element->type == TAG) { int i; diff --git a/utils/newparser/skin_render.c b/utils/newparser/skin_render.c index f39e6f6c45..d8facb03f6 100644 --- a/utils/newparser/skin_render.c +++ b/utils/newparser/skin_render.c @@ -40,11 +40,55 @@ typedef void (*skin_render_func)(struct skin_element* alternator, void skin_render_alternator(struct skin_element* alternator, char* buf, size_t buf_size, int line_number); +static void do_tags_in_hidden_conditional(struct skin_element* branch) +{ + /* Tags here are ones which need to be "turned off" or cleared + * if they are in a conditional branch which isnt being used */ + if (branch->type == SUBLINES) + { + int i; + for (i=0; ichildren_count; i++) + { + do_tags_in_hidden_conditional(branch->children[i]); + } + } + else if (branch->type == LINE) + { + struct skin_element *child = branch->children[0]; + while (child) + { + if (child->type != TAG) + { + child = child->next; + continue; + } + switch (child->tag->type) + { + case SKIN_TOKEN_PEAKMETER: + /* stop the peak meter */ + break; + case SKIN_TOKEN_ALBUMART_DISPLAY: + /* clear the AA image */ + break; + case SKIN_TOKEN_IMAGE_DISPLAY: + case SKIN_TOKEN_IMAGE_PRELOAD_DISPLAY: + printf("disable image\n"); + /* clear images */ + break; + default: + break; + } + child = child->next; + } + } +} + + /* Draw a LINE element onto the display */ void skin_render_line(struct skin_element* line, char* buf, size_t buf_size, int line_number) { - int value; + int last_value, value; if (line->children_count == 0) return; /* empty line, do nothing */ struct skin_element *child = line->children[0]; @@ -56,9 +100,16 @@ void skin_render_line(struct skin_element* line, switch (child->type) { case CONDITIONAL: + last_value = ((struct conditional*)(child->data))->last_value; value = 0; /* actually get it from the token :p */ if (value >= child->children_count) value = child->children_count-1; + + /* some tags need handling if they are being disabled */ + if (value != last_value && last_value < child->children_count) + do_tags_in_hidden_conditional(child->children[last_value]); + last_value = value; + if (child->children[value]->type == SUBLINES) func = skin_render_alternator; else if (child->children[value]->type == LINE) diff --git a/utils/newparser/skin_structs.h b/utils/newparser/skin_structs.h index 5755120e74..4fc333c500 100644 --- a/utils/newparser/skin_structs.h +++ b/utils/newparser/skin_structs.h @@ -62,5 +62,9 @@ struct subline { unsigned long last_change_tick; }; +struct conditional { + int last_value; +}; + #endif