From 76e07a7fd201391b67988681ef3cf6a53d4f22d2 Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Wed, 16 Jun 2021 13:57:49 +0100 Subject: Touchscreen: adjust how bar padding is handled The old way of padding out bars was to just create a bigger touch region, the intent being to make it easier to touch the end of a bar. Unfortunately, this didn't even accomplish that, and caused an annoying offset between the bar graphics and the touch point. New method is to account for padding explicitly and clamp touches in the padding region so they are within the proper touch region. Change-Id: Id39e571fc1b033a4da94f0eb1143a2fc276bab03 --- apps/gui/skin_engine/skin_parser.c | 27 +++++++++++++++------------ apps/gui/skin_engine/skin_touchsupport.c | 12 ++++++++++++ apps/gui/skin_engine/wps_internals.h | 2 ++ 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/apps/gui/skin_engine/skin_parser.c b/apps/gui/skin_engine/skin_parser.c index 7f3f4d62e1..7bcd25d258 100644 --- a/apps/gui/skin_engine/skin_parser.c +++ b/apps/gui/skin_engine/skin_parser.c @@ -1148,7 +1148,6 @@ static int parse_progressbar_tag(struct skin_element* element, { struct touchregion *region = skin_buffer_alloc(sizeof(*region)); struct skin_token_list *item; - int wpad, hpad; if (!region) return 0; @@ -1163,24 +1162,24 @@ static int parse_progressbar_tag(struct skin_element* element, /* try to add some extra space on either end to make pressing the * full bar easier. ~5% on either side */ - wpad = pb->width * 5 / 100; - if (wpad > 10) - wpad = 10; - hpad = pb->height * 5 / 100; - if (hpad > 10) - hpad = 10; - - region->x = pb->x - wpad; + region->wpad = pb->width * 5 / 100; + if (region->wpad > 10) + region->wpad = 10; + region->hpad = pb->height * 5 / 100; + if (region->hpad > 10) + region->hpad = 10; + + region->x = pb->x; if (region->x < 0) region->x = 0; - region->width = pb->width + 2 * wpad; + region->width = pb->width; if (region->x + region->width > curr_vp->vp.x + curr_vp->vp.width) region->width = curr_vp->vp.x + curr_vp->vp.width - region->x; - region->y = pb->y - hpad; + region->y = pb->y; if (region->y < 0) region->y = 0; - region->height = pb->height + 2 * hpad; + region->height = pb->height; if (region->y + region->height > curr_vp->vp.y + curr_vp->vp.height) region->height = curr_vp->vp.y + curr_vp->vp.height - region->y; @@ -1541,6 +1540,10 @@ static int parse_touchregion(struct skin_element *element, /* should probably do some bounds checking here with the viewport... but later */ region->action = ACTION_NONE; + /* padding is only for bars, user defined regions have no need of it */ + region->wpad = 0; + region->hpad = 0; + if (get_param(element, 0)->type == STRING) { region->label = PTRTOSKINOFFSET(skin_buffer, get_param_text(element, 0)); diff --git a/apps/gui/skin_engine/skin_touchsupport.c b/apps/gui/skin_engine/skin_touchsupport.c index b92fd1e83e..045bc809c8 100644 --- a/apps/gui/skin_engine/skin_touchsupport.c +++ b/apps/gui/skin_engine/skin_touchsupport.c @@ -92,6 +92,18 @@ int skin_get_touchaction(struct wps_data *data, int* edge_offset, * are relative to a preceding viewport */ vx = x - wvp->vp.x; vy = y - wvp->vp.y; + + /* project touches in the padding region so they clamp to the + * edge of the region instead */ + if(r->x - r->wpad <= vx && vx < r->x) + vx = r->x; + else if(r->x + r->width <= vx && vx < r->x + r->width + r->wpad) + vx = r->x + r->width - 1; + if(r->y - r->hpad <= vy && vy < r->y) + vy = r->y; + else if(r->y + r->height <= vy && vy < r->y + r->height + r->hpad) + vy = r->y + r->height - 1; + /* now see if the point is inside this region */ if (vx >= r->x && vx < r->x+r->width && vy >= r->y && vy < r->y+r->height) diff --git a/apps/gui/skin_engine/wps_internals.h b/apps/gui/skin_engine/wps_internals.h index dcad598dab..bf368bc4f3 100644 --- a/apps/gui/skin_engine/wps_internals.h +++ b/apps/gui/skin_engine/wps_internals.h @@ -201,6 +201,8 @@ struct touchregion { short int y; /* y-pos */ short int width; /* width */ short int height; /* height */ + short int wpad; /* padding to width */ + short int hpad; /* padding to height */ bool reverse_bar; /* if true 0% is the left or top */ bool allow_while_locked; enum { -- cgit v1.2.3