diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/action.c | 19 | ||||
-rw-r--r-- | apps/action.h | 24 | ||||
-rw-r--r-- | apps/gui/color_picker.c | 20 |
3 files changed, 49 insertions, 14 deletions
diff --git a/apps/action.c b/apps/action.c index fc10c927e5..2eef7d9d7b 100644 --- a/apps/action.c +++ b/apps/action.c | |||
@@ -37,6 +37,7 @@ | |||
37 | #if defined(HAVE_LCD_BITMAP) && !defined(BOOTLOADER) | 37 | #if defined(HAVE_LCD_BITMAP) && !defined(BOOTLOADER) |
38 | #include "language.h" | 38 | #include "language.h" |
39 | #endif | 39 | #endif |
40 | #include "viewport.h" | ||
40 | 41 | ||
41 | static int last_button = BUTTON_NONE|BUTTON_REL; /* allow the ipod wheel to | 42 | static int last_button = BUTTON_NONE|BUTTON_REL; /* allow the ipod wheel to |
42 | work on startup */ | 43 | work on startup */ |
@@ -386,6 +387,24 @@ int action_get_touchscreen_press(short *x, short *y) | |||
386 | return BUTTON_REPEAT|BUTTON_REL; | 387 | return BUTTON_REPEAT|BUTTON_REL; |
387 | return BUTTON_TOUCHSCREEN; | 388 | return BUTTON_TOUCHSCREEN; |
388 | } | 389 | } |
390 | |||
391 | int action_get_touchscreen_press_in_vp(short *x1, short *y1, struct viewport *vp) | ||
392 | { | ||
393 | short x, y; | ||
394 | int ret; | ||
395 | |||
396 | ret = action_get_touchscreen_press(&x, &y); | ||
397 | |||
398 | if (ret != BUTTON_NONE && viewport_point_within_vp(vp, x, y)) | ||
399 | { | ||
400 | *x1 = x - vp->x; | ||
401 | *y1 = y - vp->y; | ||
402 | return ret; | ||
403 | } | ||
404 | if (ret & BUTTON_TOUCHSCREEN) | ||
405 | return ACTION_UNKNOWN; | ||
406 | return BUTTON_NONE; | ||
407 | } | ||
389 | #endif | 408 | #endif |
390 | 409 | ||
391 | /* Don't let get_action*() return any ACTION_* values untill the current buttons | 410 | /* Don't let get_action*() return any ACTION_* values untill the current buttons |
diff --git a/apps/action.h b/apps/action.h index 24250ef869..8d8e8f50fd 100644 --- a/apps/action.h +++ b/apps/action.h | |||
@@ -22,6 +22,7 @@ | |||
22 | 22 | ||
23 | #include "stdbool.h" | 23 | #include "stdbool.h" |
24 | #include "button.h" | 24 | #include "button.h" |
25 | #include "viewport.h" | ||
25 | 26 | ||
26 | #define TIMEOUT_BLOCK -1 | 27 | #define TIMEOUT_BLOCK -1 |
27 | #define TIMEOUT_NOBLOCK 0 | 28 | #define TIMEOUT_NOBLOCK 0 |
@@ -327,12 +328,25 @@ int get_action_statuscode(int *button); | |||
327 | intptr_t get_action_data(void); | 328 | intptr_t get_action_data(void); |
328 | 329 | ||
329 | #ifdef HAVE_TOUCHSCREEN | 330 | #ifdef HAVE_TOUCHSCREEN |
330 | /* return BUTTON_NONE on error | 331 | /* return BUTTON_NONE on error |
331 | BUTTON_REPEAT if repeated press | 332 | * BUTTON_REPEAT if repeated press |
332 | BUTTON_REL if its a short press | 333 | * BUTTON_REPEAT|BUTTON_REL if release after repeated press |
333 | BUTTON_TOUCHSCREEN otherwise | 334 | * BUTTON_REL if its a short press = release after press |
334 | */ | 335 | * BUTTON_TOUCHSCREEN if press |
336 | */ | ||
335 | int action_get_touchscreen_press(short *x, short *y); | 337 | int action_get_touchscreen_press(short *x, short *y); |
338 | |||
339 | /* | ||
340 | * wrapper action_get_touchscreen_press() | ||
341 | * to filter the touchscreen coordinates through a viewport | ||
342 | * | ||
343 | * returns the action and x1, y1 relative to the viewport if | ||
344 | * the press was within the viewport, | ||
345 | * ACTION_UNKNOWN (and x1, y1 untouched) if the press was outside | ||
346 | * BUTTON_NONE else | ||
347 | * | ||
348 | **/ | ||
349 | int action_get_touchscreen_press_in_vp(short *x1, short *y1, struct viewport *vp); | ||
336 | #endif | 350 | #endif |
337 | 351 | ||
338 | /* Don't let get_action*() return any ACTION_* values untill the current buttons | 352 | /* Don't let get_action*() return any ACTION_* values untill the current buttons |
diff --git a/apps/gui/color_picker.c b/apps/gui/color_picker.c index d70b98c198..75c0612292 100644 --- a/apps/gui/color_picker.c +++ b/apps/gui/color_picker.c | |||
@@ -335,7 +335,7 @@ static int touchscreen_slider(struct screen *display, | |||
335 | { | 335 | { |
336 | short x,y; | 336 | short x,y; |
337 | int text_top, slider_x, slider_width, title_height; | 337 | int text_top, slider_x, slider_width, title_height; |
338 | unsigned button = action_get_touchscreen_press(&x, &y); | 338 | int button; |
339 | bool display_three_rows; | 339 | bool display_three_rows; |
340 | int max_label_width; | 340 | int max_label_width; |
341 | int pressed_slider; | 341 | int pressed_slider; |
@@ -344,16 +344,15 @@ static int touchscreen_slider(struct screen *display, | |||
344 | 344 | ||
345 | viewport_set_defaults(&vp, display->screen_type); | 345 | viewport_set_defaults(&vp, display->screen_type); |
346 | 346 | ||
347 | if (button == BUTTON_NONE) | ||
348 | return ACTION_NONE; | ||
349 | |||
350 | max_label_width = label_get_max_width(display); | 347 | max_label_width = label_get_max_width(display); |
351 | display->getstringsize(title, NULL, &title_height); | 348 | display->getstringsize(title, NULL, &title_height); |
352 | 349 | button = action_get_touchscreen_press_in_vp(&x, &y, &vp); | |
350 | if (button == ACTION_UNKNOWN || button == BUTTON_NONE) | ||
351 | return ACTION_NONE; | ||
353 | /* Get slider positions and top starting position | 352 | /* Get slider positions and top starting position |
354 | * need vp.y here, because of the statusbar, since touchscreen | 353 | * need vp.y here, because of the statusbar, since touchscreen |
355 | * coordinates are absolute */ | 354 | * coordinates are absolute */ |
356 | text_top = vp.y + MARGIN_TOP + title_height + TITLE_MARGIN_BOTTOM + | 355 | text_top = MARGIN_TOP + title_height + TITLE_MARGIN_BOTTOM + |
357 | SELECTOR_TB_MARGIN; | 356 | SELECTOR_TB_MARGIN; |
358 | slider_x = SELECTOR_WIDTH + max_label_width + SLIDER_TEXT_MARGIN; | 357 | slider_x = SELECTOR_WIDTH + max_label_width + SLIDER_TEXT_MARGIN; |
359 | slider_width = vp.width - slider_x*2 - max_label_width; | 358 | slider_width = vp.width - slider_x*2 - max_label_width; |
@@ -376,12 +375,15 @@ static int touchscreen_slider(struct screen *display, | |||
376 | return ACTION_STD_CANCEL; | 375 | return ACTION_STD_CANCEL; |
377 | } | 376 | } |
378 | 377 | ||
379 | pressed_slider = (y - text_top)/line_height; | 378 | vp.y += text_top; |
380 | if (pressed_slider > (display_three_rows?2:0)) | 379 | vp.height = line_height * (display_three_rows ? 3:1); |
381 | { | 380 | if (!viewport_point_within_vp(&vp, x, y)) |
381 | { /* touching the color area means accept */ | ||
382 | if (button == BUTTON_REL) | 382 | if (button == BUTTON_REL) |
383 | return ACTION_STD_OK; | 383 | return ACTION_STD_OK; |
384 | } | 384 | } |
385 | /* y is relative to the original viewport */ | ||
386 | pressed_slider = (y - text_top)/line_height; | ||
385 | if (pressed_slider != *selected_slider) | 387 | if (pressed_slider != *selected_slider) |
386 | *selected_slider = pressed_slider; | 388 | *selected_slider = pressed_slider; |
387 | /* add max_label_width to overcome integer division limits, | 389 | /* add max_label_width to overcome integer division limits, |