1
0
Fork 0
forked from len0rd/rockbox

Factor out/generalise the function that checks whether a point is within a viewport to, and use it in the wps' touchregion code. This corrects the check that was done there.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22638 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Thomas Martitz 2009-09-05 23:57:09 +00:00
parent a17d06ccc3
commit c17037a802
4 changed files with 24 additions and 18 deletions

View file

@ -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;

View file

@ -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 */

View file

@ -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

View file

@ -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)