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
This commit is contained in:
Aidan MacDonald 2021-06-16 13:57:49 +01:00
parent 02860d67c3
commit 76e07a7fd2
3 changed files with 28 additions and 11 deletions

View file

@ -1148,7 +1148,6 @@ static int parse_progressbar_tag(struct skin_element* element,
{ {
struct touchregion *region = skin_buffer_alloc(sizeof(*region)); struct touchregion *region = skin_buffer_alloc(sizeof(*region));
struct skin_token_list *item; struct skin_token_list *item;
int wpad, hpad;
if (!region) if (!region)
return 0; 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 /* try to add some extra space on either end to make pressing the
* full bar easier. ~5% on either side * full bar easier. ~5% on either side
*/ */
wpad = pb->width * 5 / 100; region->wpad = pb->width * 5 / 100;
if (wpad > 10) if (region->wpad > 10)
wpad = 10; region->wpad = 10;
hpad = pb->height * 5 / 100; region->hpad = pb->height * 5 / 100;
if (hpad > 10) if (region->hpad > 10)
hpad = 10; region->hpad = 10;
region->x = pb->x - wpad; region->x = pb->x;
if (region->x < 0) if (region->x < 0)
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) 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->width = curr_vp->vp.x + curr_vp->vp.width - region->x;
region->y = pb->y - hpad; region->y = pb->y;
if (region->y < 0) if (region->y < 0)
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) 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; 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 */ /* should probably do some bounds checking here with the viewport... but later */
region->action = ACTION_NONE; 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) if (get_param(element, 0)->type == STRING)
{ {
region->label = PTRTOSKINOFFSET(skin_buffer, get_param_text(element, 0)); region->label = PTRTOSKINOFFSET(skin_buffer, get_param_text(element, 0));

View file

@ -92,6 +92,18 @@ int skin_get_touchaction(struct wps_data *data, int* edge_offset,
* are relative to a preceding viewport */ * are relative to a preceding viewport */
vx = x - wvp->vp.x; vx = x - wvp->vp.x;
vy = y - wvp->vp.y; 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 */ /* now see if the point is inside this region */
if (vx >= r->x && vx < r->x+r->width && if (vx >= r->x && vx < r->x+r->width &&
vy >= r->y && vy < r->y+r->height) vy >= r->y && vy < r->y+r->height)

View file

@ -201,6 +201,8 @@ struct touchregion {
short int y; /* y-pos */ short int y; /* y-pos */
short int width; /* width */ short int width; /* width */
short int height; /* height */ 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 reverse_bar; /* if true 0% is the left or top */
bool allow_while_locked; bool allow_while_locked;
enum { enum {