From 9dd2eb49bec19de06c5cfd168a0e4cd4dc44c867 Mon Sep 17 00:00:00 2001 From: Jonathan Gordon Date: Thu, 15 Mar 2012 11:58:38 +1100 Subject: skin_engine: Support percentages for viewport positioning %V(0,50%,75%,50%,-) - make a viewport at x=0, y=half the lcd height, 75% lcd width and the remaining height (the other half) of the lcd. Change-Id: If26ccb65e8dc52c9225f3fd6d7b222d770add0f0 Reviewed-on: http://gerrit.rockbox.org/184 Reviewed-by: Thomas Martitz Tested-by: Thomas Martitz Reviewed-by: Jonathan Gordon --- lib/skin_parser/skin_parser.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'lib/skin_parser/skin_parser.c') diff --git a/lib/skin_parser/skin_parser.c b/lib/skin_parser/skin_parser.c index 748ea5da22..1f4b87a328 100644 --- a/lib/skin_parser/skin_parser.c +++ b/lib/skin_parser/skin_parser.c @@ -568,7 +568,7 @@ static int skin_parse_tag(struct skin_element* element, const char** document) while(*cursor != '\n' && *cursor != '\0' && *cursor != ARGLISTCLOSESYM) { /* Skipping over escaped characters */ - if(*cursor == TAGSYM) + if(*cursor == TAGSYM && *(cursor+1) != ARGLISTSEPARATESYM) { skip_tag(&cursor); } @@ -625,7 +625,7 @@ static int skin_parse_tag(struct skin_element* element, const char** document) * default > decimal/integer > single tag/code > string */ int j=0; - bool canbedefault = false; + bool canbedefault = false, last_char_is_percent = false; bool haspercent = false, number = true, hasdecimal = false; char temp_params[8]; open_square_bracket = tag_args; @@ -644,9 +644,11 @@ static int skin_parse_tag(struct skin_element* element, const char** document) hasdecimal = hasdecimal || (cursor[j] == '.'); number = number && (isdigit(cursor[j]) || (cursor[j] == '.') || - (cursor[j] == '-')); + (cursor[j] == '-') || + (cursor[j] == '%')); j++; } + last_char_is_percent = cursor[j-1] == '%'; type_code = '?'; if (canbedefault && *cursor == DEFAULTSYM && !isdigit(cursor[1])) { @@ -656,6 +658,10 @@ static int skin_parse_tag(struct skin_element* element, const char** document) { type_code = 'd'; } + else if (number && last_char_is_percent && strchr(temp_params, 'p')) + { + type_code = 'p'; + } else if (number && (strchr(temp_params, 'i') || strchr(temp_params, 'd'))) { @@ -707,7 +713,7 @@ static int skin_parse_tag(struct skin_element* element, const char** document) params[i].type = INTEGER; params[i].data.number = scan_int(&cursor); } - else if(tolower(type_code) == 'd') + else if(tolower(type_code) == 'd' || tolower(type_code) == 'p') { int val = 0; bool have_point = false; @@ -731,7 +737,13 @@ static int skin_parse_tag(struct skin_element* element, const char** document) } if (have_tenth == false) val *= 10; - params[i].type = DECIMAL; + if (tolower(type_code) == 'd') + params[i].type = DECIMAL; + else + { + params[i].type = PERCENT; + cursor++; /* skip trailing % sign */ + } params[i].data.number = val; } else if(tolower(type_code) == 's' || tolower(type_code) == 'f') -- cgit v1.2.3