diff options
author | Jonathan Gordon <rockbox@jdgordon.info> | 2011-02-28 11:19:59 +0000 |
---|---|---|
committer | Jonathan Gordon <rockbox@jdgordon.info> | 2011-02-28 11:19:59 +0000 |
commit | 156b0bc6146eb69a42189907593f4aa4e45775db (patch) | |
tree | 5280bb9f9116cd0b5b547bf83d6334b6415d7c14 | |
parent | a7fb7366b58e30a876d5754086c8b8f8c99e0654 (diff) |
Add the option of linking the %Tl (last touch) tag to a specific touchregion. Both tags now accept an optional label param as the first param.
%Tl([label,][timeout])
%T([label,] x, y, width, height, action)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29459 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/gui/skin_engine/skin_parser.c | 80 | ||||
-rw-r--r-- | apps/gui/skin_engine/skin_tokens.c | 6 | ||||
-rw-r--r-- | apps/gui/skin_engine/skin_touchsupport.c | 3 | ||||
-rw-r--r-- | apps/gui/skin_engine/wps_internals.h | 7 | ||||
-rw-r--r-- | lib/skin_parser/tag_table.c | 13 |
5 files changed, 96 insertions, 13 deletions
diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c index 31dd89d0bb..261a900cd1 100644 --- a/apps/gui/skin_engine/skin_parser.c +++ b/apps/gui/skin_engine/skin_parser.c @@ -547,6 +547,7 @@ static int parse_logical_if(struct skin_element *element, return 0; } + static int parse_timeout_tag(struct skin_element *element, struct wps_token *token, struct wps_data *wps_data) @@ -562,7 +563,6 @@ static int parse_timeout_tag(struct skin_element *element, case SKIN_TOKEN_BUTTON_VOLUME: case SKIN_TOKEN_TRACK_STARTING: case SKIN_TOKEN_TRACK_ENDING: - case SKIN_TOKEN_LASTTOUCH: val = 10; break; default: @@ -878,6 +878,47 @@ 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) +{ + struct touchregion_lastpress *data = + (struct touchregion_lastpress*)skin_buffer_alloc( + sizeof(struct touchregion_lastpress)); + int i; + if (!data) + return WPS_ERROR_INVALID_PARAM; + data->region = NULL; + data->timeout = 10; + + 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); + else if (element->params[i].type == INTEGER) + data->timeout = element->params[i].data.number; + } + + data->timeout *= TIMEOUT_UNIT; + token->value.data = data; + return 0; +} struct touchaction {const char* s; int action;}; static const struct touchaction touchactions[] = { @@ -917,6 +958,7 @@ static int parse_touchregion(struct skin_element *element, { (void)token; unsigned i, imax; + int p; struct touchregion *region = NULL; const char *action; const char pb_string[] = "progressbar"; @@ -951,15 +993,33 @@ static int parse_touchregion(struct skin_element *element, /* should probably do some bounds checking here with the viewport... but later */ region->action = ACTION_NONE; - region->x = element->params[0].data.number; - region->y = element->params[1].data.number; - region->width = element->params[2].data.number; - region->height = element->params[3].data.number; + + if (element->params[0].type == STRING) + { + region->label = element->params[0].data.text; + p = 1; + /* "[SI]III[SI]|S" is the param list. There MUST be 4 numbers + * followed by at least one string. Verify that here */ + if (element->params_count < 6 || + element->params[4].type != INTEGER) + return WPS_ERROR_INVALID_PARAM; + } + else + { + region->label = NULL; + p = 0; + } + + region->x = element->params[p++].data.number; + region->y = element->params[p++].data.number; + region->width = element->params[p++].data.number; + region->height = element->params[p++].data.number; region->wvp = curr_vp; region->armed = false; region->reverse_bar = false; region->data = NULL; - action = element->params[4].data.text; + region->last_press = 0xffff; + action = element->params[p++].data.text; strcpy(temp, action); action = temp; @@ -996,13 +1056,13 @@ static int parse_touchregion(struct skin_element *element, if (region->action == ACTION_SETTINGS_INC || region->action == ACTION_SETTINGS_DEC) { - if (element->params_count < 6) + if (element->params_count < p+1) { return WPS_ERROR_INVALID_PARAM; } else { - char *name = element->params[5].data.text; + char *name = element->params[p].data.text; int j; /* Find the setting */ for (j=0; j<nb_settings; j++) @@ -1445,7 +1505,6 @@ static int skin_element_callback(struct skin_element* element, void* data) case SKIN_TOKEN_BUTTON_VOLUME: case SKIN_TOKEN_TRACK_STARTING: case SKIN_TOKEN_TRACK_ENDING: - case SKIN_TOKEN_LASTTOUCH: function = parse_timeout_tag; break; #ifdef HAVE_LCD_BITMAP @@ -1499,6 +1558,9 @@ static int skin_element_callback(struct skin_element* element, void* data) case SKIN_TOKEN_TOUCHREGION: function = parse_touchregion; break; + case SKIN_TOKEN_LASTTOUCH: + function = parse_lasttouch; + break; #endif #ifdef HAVE_ALBUMART case SKIN_TOKEN_ALBUMART_DISPLAY: diff --git a/apps/gui/skin_engine/skin_tokens.c b/apps/gui/skin_engine/skin_tokens.c index 1fbe3d714e..cf71014a62 100644 --- a/apps/gui/skin_engine/skin_tokens.c +++ b/apps/gui/skin_engine/skin_tokens.c @@ -1413,8 +1413,12 @@ const char *get_token_value(struct gui_wps *gwps, { #ifdef HAVE_TOUCHSCREEN unsigned int last_touch = touchscreen_last_touch(); + struct touchregion_lastpress *data = token->value.data; + if (data->region) + last_touch = data->region->last_press; + if (last_touch != 0xffff && - TIME_BEFORE(current_tick, token->value.i + last_touch)) + TIME_BEFORE(current_tick, data->timeout + last_touch)) return "t"; #endif } diff --git a/apps/gui/skin_engine/skin_touchsupport.c b/apps/gui/skin_engine/skin_touchsupport.c index 850c1c0647..e5a39cddc5 100644 --- a/apps/gui/skin_engine/skin_touchsupport.c +++ b/apps/gui/skin_engine/skin_touchsupport.c @@ -89,7 +89,10 @@ int skin_get_touchaction(struct wps_data *data, int* edge_offset, *retregion = r; } if (pressed) + { r->armed = true; + r->last_press = current_tick; + } break; default: if (edge_offset) diff --git a/apps/gui/skin_engine/wps_internals.h b/apps/gui/skin_engine/wps_internals.h index 83e94b6f8d..28697c8b69 100644 --- a/apps/gui/skin_engine/wps_internals.h +++ b/apps/gui/skin_engine/wps_internals.h @@ -182,6 +182,7 @@ struct viewport_colour { }; #ifdef HAVE_TOUCHSCREEN struct touchregion { + char* label; /* label to identify this region */ struct skin_viewport* wvp;/* The viewport this region is in */ short int x; /* x-pos */ short int y; /* y-pos */ @@ -201,6 +202,12 @@ struct touchregion { void* data; int value; }; + long last_press; /* last tick this was pressed */ +}; + +struct touchregion_lastpress { + struct touchregion *region; + long timeout; }; #endif diff --git a/lib/skin_parser/tag_table.c b/lib/skin_parser/tag_table.c index 1b7fdbdb64..a4989c1025 100644 --- a/lib/skin_parser/tag_table.c +++ b/lib/skin_parser/tag_table.c @@ -203,11 +203,18 @@ static const struct tag_info legal_tags[] = { SKIN_TOKEN_TRANSLATEDSTRING, "Sx" , "S", SKIN_REFRESH_STATIC }, { SKIN_TOKEN_LANG_IS_RTL, "Sr" , "", SKIN_REFRESH_STATIC }, - { SKIN_TOKEN_LASTTOUCH, "Tl" , "|D", SKIN_REFRESH_DYNAMIC }, - { SKIN_TOKEN_CURRENT_SCREEN, "cs", "", SKIN_REFRESH_DYNAMIC }, - { SKIN_TOKEN_TOUCHREGION, "T" , "IIIIS|S", 0|NOBREAK }, + /* HACK Alert (jdgordon): The next two tags have hacks so we could + * add a S param at the front without breaking old skins. + * [SD]D <- handled by the callback, allows SD or S or D params + * [SI]III[SI]|S -< SIIIIS|S or IIIIS|S + * keep in sync with parse_touchregion() and parse_lasttouch() */ + { SKIN_TOKEN_LASTTOUCH, "Tl" , "|[SD]D", SKIN_REFRESH_DYNAMIC }, + { SKIN_TOKEN_TOUCHREGION, "T" , "[SI]III[SI]|S", 0|NOBREAK }, + { SKIN_TOKEN_HAVE_TOUCH, "Tp", "", FEATURE_TAG }, + { SKIN_TOKEN_CURRENT_SCREEN, "cs", "", SKIN_REFRESH_DYNAMIC }, + { SKIN_TOKEN_HAVE_RECORDING, "Rp" , "", FEATURE_TAG }, { SKIN_TOKEN_IS_RECORDING, "Rr" , "", SKIN_REFRESH_DYNAMIC }, { SKIN_TOKEN_REC_FREQ, "Rf" , "", SKIN_REFRESH_DYNAMIC }, |