Add a action helper for touchscreen targets to only receive the touchpress coordinates if they're in the passed viewport. Also, fixes the coordinates to be relaitve to the viewport.

Use it in the color picker screen.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@23116 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Thomas Martitz 2009-10-11 20:11:48 +00:00
parent 6cea8c1e1a
commit 891c446302
3 changed files with 49 additions and 14 deletions

View file

@ -37,6 +37,7 @@
#if defined(HAVE_LCD_BITMAP) && !defined(BOOTLOADER)
#include "language.h"
#endif
#include "viewport.h"
static int last_button = BUTTON_NONE|BUTTON_REL; /* allow the ipod wheel to
work on startup */
@ -386,6 +387,24 @@ int action_get_touchscreen_press(short *x, short *y)
return BUTTON_REPEAT|BUTTON_REL;
return BUTTON_TOUCHSCREEN;
}
int action_get_touchscreen_press_in_vp(short *x1, short *y1, struct viewport *vp)
{
short x, y;
int ret;
ret = action_get_touchscreen_press(&x, &y);
if (ret != BUTTON_NONE && viewport_point_within_vp(vp, x, y))
{
*x1 = x - vp->x;
*y1 = y - vp->y;
return ret;
}
if (ret & BUTTON_TOUCHSCREEN)
return ACTION_UNKNOWN;
return BUTTON_NONE;
}
#endif
/* Don't let get_action*() return any ACTION_* values untill the current buttons

View file

@ -22,6 +22,7 @@
#include "stdbool.h"
#include "button.h"
#include "viewport.h"
#define TIMEOUT_BLOCK -1
#define TIMEOUT_NOBLOCK 0
@ -328,11 +329,24 @@ intptr_t get_action_data(void);
#ifdef HAVE_TOUCHSCREEN
/* return BUTTON_NONE on error
BUTTON_REPEAT if repeated press
BUTTON_REL if its a short press
BUTTON_TOUCHSCREEN otherwise
* BUTTON_REPEAT if repeated press
* BUTTON_REPEAT|BUTTON_REL if release after repeated press
* BUTTON_REL if its a short press = release after press
* BUTTON_TOUCHSCREEN if press
*/
int action_get_touchscreen_press(short *x, short *y);
/*
* wrapper action_get_touchscreen_press()
* to filter the touchscreen coordinates through a viewport
*
* returns the action and x1, y1 relative to the viewport if
* the press was within the viewport,
* ACTION_UNKNOWN (and x1, y1 untouched) if the press was outside
* BUTTON_NONE else
*
**/
int action_get_touchscreen_press_in_vp(short *x1, short *y1, struct viewport *vp);
#endif
/* Don't let get_action*() return any ACTION_* values untill the current buttons

View file

@ -335,7 +335,7 @@ static int touchscreen_slider(struct screen *display,
{
short x,y;
int text_top, slider_x, slider_width, title_height;
unsigned button = action_get_touchscreen_press(&x, &y);
int button;
bool display_three_rows;
int max_label_width;
int pressed_slider;
@ -344,16 +344,15 @@ static int touchscreen_slider(struct screen *display,
viewport_set_defaults(&vp, display->screen_type);
if (button == BUTTON_NONE)
return ACTION_NONE;
max_label_width = label_get_max_width(display);
display->getstringsize(title, NULL, &title_height);
button = action_get_touchscreen_press_in_vp(&x, &y, &vp);
if (button == ACTION_UNKNOWN || button == BUTTON_NONE)
return ACTION_NONE;
/* Get slider positions and top starting position
* need vp.y here, because of the statusbar, since touchscreen
* coordinates are absolute */
text_top = vp.y + MARGIN_TOP + title_height + TITLE_MARGIN_BOTTOM +
text_top = MARGIN_TOP + title_height + TITLE_MARGIN_BOTTOM +
SELECTOR_TB_MARGIN;
slider_x = SELECTOR_WIDTH + max_label_width + SLIDER_TEXT_MARGIN;
slider_width = vp.width - slider_x*2 - max_label_width;
@ -376,12 +375,15 @@ static int touchscreen_slider(struct screen *display,
return ACTION_STD_CANCEL;
}
pressed_slider = (y - text_top)/line_height;
if (pressed_slider > (display_three_rows?2:0))
{
vp.y += text_top;
vp.height = line_height * (display_three_rows ? 3:1);
if (!viewport_point_within_vp(&vp, x, y))
{ /* touching the color area means accept */
if (button == BUTTON_REL)
return ACTION_STD_OK;
}
/* y is relative to the original viewport */
pressed_slider = (y - text_top)/line_height;
if (pressed_slider != *selected_slider)
*selected_slider = pressed_slider;
/* add max_label_width to overcome integer division limits,