summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAidan MacDonald <amachronic@protonmail.com>2021-06-16 13:57:49 +0100
committerAidan MacDonald <amachronic@protonmail.com>2021-06-22 21:37:02 +0100
commit76e07a7fd201391b67988681ef3cf6a53d4f22d2 (patch)
tree5ee68637f7192461f65191617b6413a2c310d52e
parent02860d67c3c2807e3c9fd7d272ce9cc098c052ae (diff)
downloadrockbox-76e07a7fd201391b67988681ef3cf6a53d4f22d2.tar.gz
rockbox-76e07a7fd201391b67988681ef3cf6a53d4f22d2.zip
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
-rw-r--r--apps/gui/skin_engine/skin_parser.c27
-rw-r--r--apps/gui/skin_engine/skin_touchsupport.c12
-rw-r--r--apps/gui/skin_engine/wps_internals.h2
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,
1148 { 1148 {
1149 struct touchregion *region = skin_buffer_alloc(sizeof(*region)); 1149 struct touchregion *region = skin_buffer_alloc(sizeof(*region));
1150 struct skin_token_list *item; 1150 struct skin_token_list *item;
1151 int wpad, hpad;
1152 1151
1153 if (!region) 1152 if (!region)
1154 return 0; 1153 return 0;
@@ -1163,24 +1162,24 @@ static int parse_progressbar_tag(struct skin_element* element,
1163 /* try to add some extra space on either end to make pressing the 1162 /* try to add some extra space on either end to make pressing the
1164 * full bar easier. ~5% on either side 1163 * full bar easier. ~5% on either side
1165 */ 1164 */
1166 wpad = pb->width * 5 / 100; 1165 region->wpad = pb->width * 5 / 100;
1167 if (wpad > 10) 1166 if (region->wpad > 10)
1168 wpad = 10; 1167 region->wpad = 10;
1169 hpad = pb->height * 5 / 100; 1168 region->hpad = pb->height * 5 / 100;
1170 if (hpad > 10) 1169 if (region->hpad > 10)
1171 hpad = 10; 1170 region->hpad = 10;
1172 1171
1173 region->x = pb->x - wpad; 1172 region->x = pb->x;
1174 if (region->x < 0) 1173 if (region->x < 0)
1175 region->x = 0; 1174 region->x = 0;
1176 region->width = pb->width + 2 * wpad; 1175 region->width = pb->width;
1177 if (region->x + region->width > curr_vp->vp.x + curr_vp->vp.width) 1176 if (region->x + region->width > curr_vp->vp.x + curr_vp->vp.width)
1178 region->width = curr_vp->vp.x + curr_vp->vp.width - region->x; 1177 region->width = curr_vp->vp.x + curr_vp->vp.width - region->x;
1179 1178
1180 region->y = pb->y - hpad; 1179 region->y = pb->y;
1181 if (region->y < 0) 1180 if (region->y < 0)
1182 region->y = 0; 1181 region->y = 0;
1183 region->height = pb->height + 2 * hpad; 1182 region->height = pb->height;
1184 if (region->y + region->height > curr_vp->vp.y + curr_vp->vp.height) 1183 if (region->y + region->height > curr_vp->vp.y + curr_vp->vp.height)
1185 region->height = curr_vp->vp.y + curr_vp->vp.height - region->y; 1184 region->height = curr_vp->vp.y + curr_vp->vp.height - region->y;
1186 1185
@@ -1541,6 +1540,10 @@ static int parse_touchregion(struct skin_element *element,
1541 /* should probably do some bounds checking here with the viewport... but later */ 1540 /* should probably do some bounds checking here with the viewport... but later */
1542 region->action = ACTION_NONE; 1541 region->action = ACTION_NONE;
1543 1542
1543 /* padding is only for bars, user defined regions have no need of it */
1544 region->wpad = 0;
1545 region->hpad = 0;
1546
1544 if (get_param(element, 0)->type == STRING) 1547 if (get_param(element, 0)->type == STRING)
1545 { 1548 {
1546 region->label = PTRTOSKINOFFSET(skin_buffer, get_param_text(element, 0)); 1549 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,
92 * are relative to a preceding viewport */ 92 * are relative to a preceding viewport */
93 vx = x - wvp->vp.x; 93 vx = x - wvp->vp.x;
94 vy = y - wvp->vp.y; 94 vy = y - wvp->vp.y;
95
96 /* project touches in the padding region so they clamp to the
97 * edge of the region instead */
98 if(r->x - r->wpad <= vx && vx < r->x)
99 vx = r->x;
100 else if(r->x + r->width <= vx && vx < r->x + r->width + r->wpad)
101 vx = r->x + r->width - 1;
102 if(r->y - r->hpad <= vy && vy < r->y)
103 vy = r->y;
104 else if(r->y + r->height <= vy && vy < r->y + r->height + r->hpad)
105 vy = r->y + r->height - 1;
106
95 /* now see if the point is inside this region */ 107 /* now see if the point is inside this region */
96 if (vx >= r->x && vx < r->x+r->width && 108 if (vx >= r->x && vx < r->x+r->width &&
97 vy >= r->y && vy < r->y+r->height) 109 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 {
201 short int y; /* y-pos */ 201 short int y; /* y-pos */
202 short int width; /* width */ 202 short int width; /* width */
203 short int height; /* height */ 203 short int height; /* height */
204 short int wpad; /* padding to width */
205 short int hpad; /* padding to height */
204 bool reverse_bar; /* if true 0% is the left or top */ 206 bool reverse_bar; /* if true 0% is the left or top */
205 bool allow_while_locked; 207 bool allow_while_locked;
206 enum { 208 enum {