diff options
author | Jonathan Gordon <rockbox@jdgordon.info> | 2012-03-15 11:58:38 +1100 |
---|---|---|
committer | Jonathan Gordon <rockbox@jdgordon.info> | 2012-07-29 04:24:38 +0200 |
commit | 9dd2eb49bec19de06c5cfd168a0e4cd4dc44c867 (patch) | |
tree | 6dd6681902122f3a002251787f2067a68f0ceaa7 | |
parent | 9a84bcfe4b9821c68322a1a91da9f16d0bd2a4bc (diff) | |
download | rockbox-9dd2eb49bec19de06c5cfd168a0e4cd4dc44c867.tar.gz rockbox-9dd2eb49bec19de06c5cfd168a0e4cd4dc44c867.zip |
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 <kugel@rockbox.org>
Tested-by: Thomas Martitz <kugel@rockbox.org>
Reviewed-by: Jonathan Gordon <rockbox@jdgordon.info>
-rw-r--r-- | apps/gui/skin_engine/skin_parser.c | 8 | ||||
-rw-r--r-- | apps/gui/skin_engine/skin_tokens.c | 1 | ||||
-rw-r--r-- | lib/skin_parser/skin_parser.c | 22 | ||||
-rw-r--r-- | lib/skin_parser/skin_parser.h | 1 | ||||
-rw-r--r-- | lib/skin_parser/tag_table.c | 6 | ||||
-rw-r--r-- | lib/skin_parser/tag_table.h | 3 |
6 files changed, 33 insertions, 8 deletions
diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c index 237e4033e2..01fedba99b 100644 --- a/apps/gui/skin_engine/skin_parser.c +++ b/apps/gui/skin_engine/skin_parser.c | |||
@@ -1995,6 +1995,8 @@ static int convert_viewport(struct wps_data *data, struct skin_element* element) | |||
1995 | skin_vp->vp.x = param->data.number; | 1995 | skin_vp->vp.x = param->data.number; |
1996 | if (param->data.number < 0) | 1996 | if (param->data.number < 0) |
1997 | skin_vp->vp.x += display->lcdwidth; | 1997 | skin_vp->vp.x += display->lcdwidth; |
1998 | else if (param->type == PERCENT) | ||
1999 | skin_vp->vp.x = param->data.number * display->lcdwidth / 1000; | ||
1998 | } | 2000 | } |
1999 | param++; | 2001 | param++; |
2000 | /* y */ | 2002 | /* y */ |
@@ -2003,6 +2005,8 @@ static int convert_viewport(struct wps_data *data, struct skin_element* element) | |||
2003 | skin_vp->vp.y = param->data.number; | 2005 | skin_vp->vp.y = param->data.number; |
2004 | if (param->data.number < 0) | 2006 | if (param->data.number < 0) |
2005 | skin_vp->vp.y += display->lcdheight; | 2007 | skin_vp->vp.y += display->lcdheight; |
2008 | else if (param->type == PERCENT) | ||
2009 | skin_vp->vp.y = param->data.number * display->lcdheight / 1000; | ||
2006 | } | 2010 | } |
2007 | param++; | 2011 | param++; |
2008 | /* width */ | 2012 | /* width */ |
@@ -2011,6 +2015,8 @@ static int convert_viewport(struct wps_data *data, struct skin_element* element) | |||
2011 | skin_vp->vp.width = param->data.number; | 2015 | skin_vp->vp.width = param->data.number; |
2012 | if (param->data.number < 0) | 2016 | if (param->data.number < 0) |
2013 | skin_vp->vp.width = (skin_vp->vp.width + display->lcdwidth) - skin_vp->vp.x; | 2017 | skin_vp->vp.width = (skin_vp->vp.width + display->lcdwidth) - skin_vp->vp.x; |
2018 | else if (param->type == PERCENT) | ||
2019 | skin_vp->vp.width = param->data.number * display->lcdwidth / 1000; | ||
2014 | } | 2020 | } |
2015 | else | 2021 | else |
2016 | { | 2022 | { |
@@ -2023,6 +2029,8 @@ static int convert_viewport(struct wps_data *data, struct skin_element* element) | |||
2023 | skin_vp->vp.height = param->data.number; | 2029 | skin_vp->vp.height = param->data.number; |
2024 | if (param->data.number < 0) | 2030 | if (param->data.number < 0) |
2025 | skin_vp->vp.height = (skin_vp->vp.height + display->lcdheight) - skin_vp->vp.y; | 2031 | skin_vp->vp.height = (skin_vp->vp.height + display->lcdheight) - skin_vp->vp.y; |
2032 | else if (param->type == PERCENT) | ||
2033 | skin_vp->vp.height = param->data.number * display->lcdheight / 1000; | ||
2026 | } | 2034 | } |
2027 | else | 2035 | else |
2028 | { | 2036 | { |
diff --git a/apps/gui/skin_engine/skin_tokens.c b/apps/gui/skin_engine/skin_tokens.c index b550a90073..e58393e19c 100644 --- a/apps/gui/skin_engine/skin_tokens.c +++ b/apps/gui/skin_engine/skin_tokens.c | |||
@@ -761,6 +761,7 @@ static const char* NOINLINE get_lif_token_value(struct gui_wps *gwps, | |||
761 | if (!number_set && out_text && *out_text >= '0' && *out_text <= '9') | 761 | if (!number_set && out_text && *out_text >= '0' && *out_text <= '9') |
762 | a = atoi(out_text); | 762 | a = atoi(out_text); |
763 | /* fall through */ | 763 | /* fall through */ |
764 | case PERCENT: | ||
764 | case DECIMAL: | 765 | case DECIMAL: |
765 | b = lif->operand.data.number; | 766 | b = lif->operand.data.number; |
766 | break; | 767 | break; |
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) | |||
568 | while(*cursor != '\n' && *cursor != '\0' && *cursor != ARGLISTCLOSESYM) | 568 | while(*cursor != '\n' && *cursor != '\0' && *cursor != ARGLISTCLOSESYM) |
569 | { | 569 | { |
570 | /* Skipping over escaped characters */ | 570 | /* Skipping over escaped characters */ |
571 | if(*cursor == TAGSYM) | 571 | if(*cursor == TAGSYM && *(cursor+1) != ARGLISTSEPARATESYM) |
572 | { | 572 | { |
573 | skip_tag(&cursor); | 573 | skip_tag(&cursor); |
574 | } | 574 | } |
@@ -625,7 +625,7 @@ static int skin_parse_tag(struct skin_element* element, const char** document) | |||
625 | * default > decimal/integer > single tag/code > string | 625 | * default > decimal/integer > single tag/code > string |
626 | */ | 626 | */ |
627 | int j=0; | 627 | int j=0; |
628 | bool canbedefault = false; | 628 | bool canbedefault = false, last_char_is_percent = false; |
629 | bool haspercent = false, number = true, hasdecimal = false; | 629 | bool haspercent = false, number = true, hasdecimal = false; |
630 | char temp_params[8]; | 630 | char temp_params[8]; |
631 | open_square_bracket = tag_args; | 631 | open_square_bracket = tag_args; |
@@ -644,9 +644,11 @@ static int skin_parse_tag(struct skin_element* element, const char** document) | |||
644 | hasdecimal = hasdecimal || (cursor[j] == '.'); | 644 | hasdecimal = hasdecimal || (cursor[j] == '.'); |
645 | number = number && (isdigit(cursor[j]) || | 645 | number = number && (isdigit(cursor[j]) || |
646 | (cursor[j] == '.') || | 646 | (cursor[j] == '.') || |
647 | (cursor[j] == '-')); | 647 | (cursor[j] == '-') || |
648 | (cursor[j] == '%')); | ||
648 | j++; | 649 | j++; |
649 | } | 650 | } |
651 | last_char_is_percent = cursor[j-1] == '%'; | ||
650 | type_code = '?'; | 652 | type_code = '?'; |
651 | if (canbedefault && *cursor == DEFAULTSYM && !isdigit(cursor[1])) | 653 | if (canbedefault && *cursor == DEFAULTSYM && !isdigit(cursor[1])) |
652 | { | 654 | { |
@@ -656,6 +658,10 @@ static int skin_parse_tag(struct skin_element* element, const char** document) | |||
656 | { | 658 | { |
657 | type_code = 'd'; | 659 | type_code = 'd'; |
658 | } | 660 | } |
661 | else if (number && last_char_is_percent && strchr(temp_params, 'p')) | ||
662 | { | ||
663 | type_code = 'p'; | ||
664 | } | ||
659 | else if (number && | 665 | else if (number && |
660 | (strchr(temp_params, 'i') || strchr(temp_params, 'd'))) | 666 | (strchr(temp_params, 'i') || strchr(temp_params, 'd'))) |
661 | { | 667 | { |
@@ -707,7 +713,7 @@ static int skin_parse_tag(struct skin_element* element, const char** document) | |||
707 | params[i].type = INTEGER; | 713 | params[i].type = INTEGER; |
708 | params[i].data.number = scan_int(&cursor); | 714 | params[i].data.number = scan_int(&cursor); |
709 | } | 715 | } |
710 | else if(tolower(type_code) == 'd') | 716 | else if(tolower(type_code) == 'd' || tolower(type_code) == 'p') |
711 | { | 717 | { |
712 | int val = 0; | 718 | int val = 0; |
713 | bool have_point = false; | 719 | bool have_point = false; |
@@ -731,7 +737,13 @@ static int skin_parse_tag(struct skin_element* element, const char** document) | |||
731 | } | 737 | } |
732 | if (have_tenth == false) | 738 | if (have_tenth == false) |
733 | val *= 10; | 739 | val *= 10; |
734 | params[i].type = DECIMAL; | 740 | if (tolower(type_code) == 'd') |
741 | params[i].type = DECIMAL; | ||
742 | else | ||
743 | { | ||
744 | params[i].type = PERCENT; | ||
745 | cursor++; /* skip trailing % sign */ | ||
746 | } | ||
735 | params[i].data.number = val; | 747 | params[i].data.number = val; |
736 | } | 748 | } |
737 | else if(tolower(type_code) == 's' || tolower(type_code) == 'f') | 749 | else if(tolower(type_code) == 's' || tolower(type_code) == 'f') |
diff --git a/lib/skin_parser/skin_parser.h b/lib/skin_parser/skin_parser.h index 120112d995..ec51b64c8b 100644 --- a/lib/skin_parser/skin_parser.h +++ b/lib/skin_parser/skin_parser.h | |||
@@ -89,6 +89,7 @@ struct skin_tag_parameter | |||
89 | { | 89 | { |
90 | INTEGER, | 90 | INTEGER, |
91 | DECIMAL, /* stored in data.number as (whole*10)+part */ | 91 | DECIMAL, /* stored in data.number as (whole*10)+part */ |
92 | PERCENT, /* stored in data.number as (whole*10)+part */ | ||
92 | STRING, | 93 | STRING, |
93 | CODE, | 94 | CODE, |
94 | DEFAULT | 95 | DEFAULT |
diff --git a/lib/skin_parser/tag_table.c b/lib/skin_parser/tag_table.c index 76139df04e..ec1476fb80 100644 --- a/lib/skin_parser/tag_table.c +++ b/lib/skin_parser/tag_table.c | |||
@@ -206,9 +206,9 @@ static const struct tag_info legal_tags[] = | |||
206 | { SKIN_TOKEN_VIEWPORT_GRADIENT_SETUP, "Vg" , "SS|s", SKIN_REFRESH_STATIC|NOBREAK }, | 206 | { SKIN_TOKEN_VIEWPORT_GRADIENT_SETUP, "Vg" , "SS|s", SKIN_REFRESH_STATIC|NOBREAK }, |
207 | { SKIN_TOKEN_VIEWPORT_DRAWONBG, "VB" , "", SKIN_REFRESH_STATIC|NOBREAK }, | 207 | { SKIN_TOKEN_VIEWPORT_DRAWONBG, "VB" , "", SKIN_REFRESH_STATIC|NOBREAK }, |
208 | 208 | ||
209 | { SKIN_TOKEN_VIEWPORT_CONDITIONAL, "Vl" , "SIIiii", 0 }, | 209 | { SKIN_TOKEN_VIEWPORT_CONDITIONAL, "Vl" , "S[IP][IP][ip][ip]i", 0 }, |
210 | { SKIN_TOKEN_UIVIEWPORT_LOAD, "Vi" , "sIIiii", 0 }, | 210 | { SKIN_TOKEN_UIVIEWPORT_LOAD, "Vi" , "s[IP][IP][ip][ip]i", 0 }, |
211 | { SKIN_TOKEN_VIEWPORT_LOAD, "V" , "IIiii", 0 }, | 211 | { SKIN_TOKEN_VIEWPORT_LOAD, "V" , "[IP][IP][ip][ip]i", 0 }, |
212 | 212 | ||
213 | { SKIN_TOKEN_IMAGE_BACKDROP, "X" , "f", SKIN_REFRESH_STATIC|NOBREAK }, | 213 | { SKIN_TOKEN_IMAGE_BACKDROP, "X" , "f", SKIN_REFRESH_STATIC|NOBREAK }, |
214 | /* This uses the bar tag params also but the first item can be a string | 214 | /* This uses the bar tag params also but the first item can be a string |
diff --git a/lib/skin_parser/tag_table.h b/lib/skin_parser/tag_table.h index b29c6d79d8..41f7d7dd86 100644 --- a/lib/skin_parser/tag_table.h +++ b/lib/skin_parser/tag_table.h | |||
@@ -304,6 +304,9 @@ enum skin_token_type { | |||
304 | * D - Required decimal | 304 | * D - Required decimal |
305 | * d - Nullable decimal | 305 | * d - Nullable decimal |
306 | * Decimals are stored as (whole*10)+part | 306 | * Decimals are stored as (whole*10)+part |
307 | * P - Required percentage | ||
308 | * p - Nullable percentage | ||
309 | * Percentages pestored as permilles (percent*10 + part) | ||
307 | * S - Required string | 310 | * S - Required string |
308 | * s - Nullable string | 311 | * s - Nullable string |
309 | * F - Required file name | 312 | * F - Required file name |