diff options
-rw-r--r-- | apps/gui/quickscreen.c | 18 | ||||
-rw-r--r-- | apps/gui/viewport.c | 9 | ||||
-rw-r--r-- | apps/gui/viewport.h | 4 | ||||
-rw-r--r-- | apps/gui/wps.c | 11 |
4 files changed, 24 insertions, 18 deletions
diff --git a/apps/gui/quickscreen.c b/apps/gui/quickscreen.c index 402b1e2585..863bd54be4 100644 --- a/apps/gui/quickscreen.c +++ b/apps/gui/quickscreen.c @@ -285,15 +285,8 @@ static bool gui_quickscreen_do_button(struct gui_quickscreen * qs, int button) talk_qs_option((struct settings_list *)qs->items[item], false); return true; } -#ifdef HAVE_TOUCHSCREEN -/* figure out which button was pressed... */ -static bool xy_is_within_viewport(int x, int y, const struct viewport *vp) -{ - bool is_x = (x > vp->x && x < (vp->x + vp->width)); - bool is_y = (y > vp->y && y < (vp->y + vp->height)); - return (is_x && is_y); -} +#ifdef HAVE_TOUCHSCREEN static int quickscreen_touchscreen_button(const struct viewport vps[QUICKSCREEN_ITEM_COUNT]) { @@ -301,17 +294,18 @@ static int quickscreen_touchscreen_button(const struct viewport /* only hitting the text counts, everything else is exit */ if (action_get_touchscreen_press(&x, &y) != BUTTON_REL) return ACTION_NONE; - else if (xy_is_within_viewport(x,y,&vps[QUICKSCREEN_TOP])) + else if (viewport_point_within_vp(&vps[QUICKSCREEN_TOP], x, y)) return ACTION_QS_TOP; - else if (xy_is_within_viewport(x,y,&vps[QUICKSCREEN_BOTTOM])) + else if (viewport_point_within_vp(&vps[QUICKSCREEN_BOTTOM], x, y)) return ACTION_QS_DOWN; - else if (xy_is_within_viewport(x,y,&vps[QUICKSCREEN_LEFT])) + else if (viewport_point_within_vp(&vps[QUICKSCREEN_LEFT], x, y)) return ACTION_QS_LEFT; - else if (xy_is_within_viewport(x,y,&vps[QUICKSCREEN_RIGHT])) + else if (viewport_point_within_vp(&vps[QUICKSCREEN_RIGHT], x, y)) return ACTION_QS_RIGHT; return ACTION_STD_CANCEL; } #endif + static bool gui_syncquickscreen_run(struct gui_quickscreen * qs, int button_enter) { int button, i, j; diff --git a/apps/gui/viewport.c b/apps/gui/viewport.c index e05cd78970..63f0b8fc20 100644 --- a/apps/gui/viewport.c +++ b/apps/gui/viewport.c @@ -401,4 +401,13 @@ static unsigned viewport_init_ui_vp(void) return ret; } +#ifdef HAVE_TOUCHSCREEN +/* check if a point (x and y coordinates) are within a viewport */ +bool viewport_point_within_vp(const struct viewport *vp, int x, int y) +{ + bool is_x = (x >= vp->x && x < (vp->x + vp->width)); + bool is_y = (y >= vp->y && y < (vp->y + vp->height)); + return (is_x && is_y); +} +#endif /* HAVE_TOUCHSCREEN */ #endif /* HAVE_LCD_BITMAP */ diff --git a/apps/gui/viewport.h b/apps/gui/viewport.h index 2ed138b365..93b5c70fc3 100644 --- a/apps/gui/viewport.h +++ b/apps/gui/viewport.h @@ -116,6 +116,10 @@ struct viewport* viewport_get_current_vp(void); */ void viewport_set_current_vp(struct viewport* vp); +#ifdef HAVE_TOUCHSCREEN +bool viewport_point_within_vp(const struct viewport *vp, int x, int y); +#endif + #else /* HAVE_LCD_CHARCELL */ #define viewport_set_current_vp(a) #define viewport_get_current_vp() NULL diff --git a/apps/gui/wps.c b/apps/gui/wps.c index 99bc731c7d..f336f77503 100644 --- a/apps/gui/wps.c +++ b/apps/gui/wps.c @@ -601,13 +601,12 @@ int wps_get_touchaction(struct wps_data *data) regions = regions->next; continue; } - /* reposition the touch inside the viewport */ - vx = x - r->wvp->vp.x; - vy = y - r->wvp->vp.y; /* check if it's inside this viewport */ - if (vx >= 0 && vx < r->wvp->vp.x + r->wvp->vp.width && - vy >= 0 && vy < r->wvp->vp.y + r->wvp->vp.height) - { + if (viewport_point_within_vp(&(r->wvp->vp), x, y)) + { /* reposition the touch inside the viewport since touchregions + * are relative to a preceding viewport */ + vx = x - r->wvp->vp.x; + vy = y - r->wvp->vp.y; /* 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) |