From a17d06ccc3b589cfc5eb92edbea3c09494b1ed48 Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Sat, 5 Sep 2009 23:32:16 +0000 Subject: Improve and simplify touchscreen handling of the quickscreen in absolut mode - and implement handling for the top item. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22637 a1c6a512-1295-4272-9138-f99709370657 --- apps/gui/quickscreen.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'apps') diff --git a/apps/gui/quickscreen.c b/apps/gui/quickscreen.c index 639233b3b1..402b1e2585 100644 --- a/apps/gui/quickscreen.c +++ b/apps/gui/quickscreen.c @@ -286,24 +286,28 @@ static bool gui_quickscreen_do_button(struct gui_quickscreen * qs, int button) return true; } #ifdef HAVE_TOUCHSCREEN -/* figure out which button was pressed... - * top is exit, left/right/botton are the respective actions - */ +/* 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); +} + static int quickscreen_touchscreen_button(const struct viewport vps[QUICKSCREEN_ITEM_COUNT]) { short x,y; + /* only hitting the text counts, everything else is exit */ if (action_get_touchscreen_press(&x, &y) != BUTTON_REL) return ACTION_NONE; - if (y < vps[QUICKSCREEN_LEFT].y) - return ACTION_STD_CANCEL; - else if (y > vps[QUICKSCREEN_LEFT].y + - vps[QUICKSCREEN_LEFT].height) + else if (xy_is_within_viewport(x,y,&vps[QUICKSCREEN_TOP])) + return ACTION_QS_TOP; + else if (xy_is_within_viewport(x,y,&vps[QUICKSCREEN_BOTTOM])) return ACTION_QS_DOWN; - else if (x < vps[QUICKSCREEN_LEFT].x + - vps[QUICKSCREEN_LEFT].width) + else if (xy_is_within_viewport(x,y,&vps[QUICKSCREEN_LEFT])) return ACTION_QS_LEFT; - else if (x >= vps[QUICKSCREEN_RIGHT].x) + else if (xy_is_within_viewport(x,y,&vps[QUICKSCREEN_RIGHT])) return ACTION_QS_RIGHT; return ACTION_STD_CANCEL; } -- cgit v1.2.3