diff options
Diffstat (limited to 'apps/gui/skin_engine')
-rw-r--r-- | apps/gui/skin_engine/skin_engine.h | 3 | ||||
-rw-r--r-- | apps/gui/skin_engine/skin_touchsupport.c | 116 |
2 files changed, 118 insertions, 1 deletions
diff --git a/apps/gui/skin_engine/skin_engine.h b/apps/gui/skin_engine/skin_engine.h index 380b854d24..69991ab587 100644 --- a/apps/gui/skin_engine/skin_engine.h +++ b/apps/gui/skin_engine/skin_engine.h | |||
@@ -40,7 +40,8 @@ enum skinnable_screens { | |||
40 | 40 | ||
41 | 41 | ||
42 | #ifdef HAVE_TOUCHSCREEN | 42 | #ifdef HAVE_TOUCHSCREEN |
43 | int wps_get_touchaction(struct wps_data *data); | 43 | int skin_get_touchaction(struct wps_data *data, int* edge_offset); |
44 | void skin_disarm_touchregions(struct wps_data *data); | ||
44 | #endif | 45 | #endif |
45 | 46 | ||
46 | /* Do a update_type update of the skinned screen */ | 47 | /* Do a update_type update of the skinned screen */ |
diff --git a/apps/gui/skin_engine/skin_touchsupport.c b/apps/gui/skin_engine/skin_touchsupport.c new file mode 100644 index 0000000000..9c0cda779a --- /dev/null +++ b/apps/gui/skin_engine/skin_touchsupport.c | |||
@@ -0,0 +1,116 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2009 - Jonathan Gordon | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include "config.h" | ||
23 | #include <stdio.h> | ||
24 | #include "action.h" | ||
25 | #include "skin_engine.h" | ||
26 | #include "wps_internals.h" | ||
27 | |||
28 | /** Disarms all touchregions. */ | ||
29 | void skin_disarm_touchregions(struct wps_data *data) | ||
30 | { | ||
31 | struct skin_token_list *regions = data->touchregions; | ||
32 | while (regions) | ||
33 | { | ||
34 | ((struct touchregion *)regions->token->value.data)->armed = false; | ||
35 | regions = regions->next; | ||
36 | } | ||
37 | } | ||
38 | |||
39 | /* Get the touched action. | ||
40 | * egde_offset is a percentage value for the position of the touch | ||
41 | * inside the bar for regions which arnt WPS_TOUCHREGION_ACTION type. | ||
42 | */ | ||
43 | int skin_get_touchaction(struct wps_data *data, int* edge_offset) | ||
44 | { | ||
45 | int returncode = ACTION_NONE; | ||
46 | short x,y; | ||
47 | short vx, vy; | ||
48 | int type = action_get_touchscreen_press(&x, &y); | ||
49 | static int last_action = ACTION_NONE; | ||
50 | struct touchregion *r; | ||
51 | bool repeated = (type == BUTTON_REPEAT); | ||
52 | bool released = (type == BUTTON_REL); | ||
53 | bool pressed = (type == BUTTON_TOUCHSCREEN); | ||
54 | struct skin_token_list *regions = data->touchregions; | ||
55 | |||
56 | while (regions) | ||
57 | { | ||
58 | r = (struct touchregion *)regions->token->value.data; | ||
59 | /* make sure this region's viewport is visible */ | ||
60 | if (r->wvp->hidden_flags&VP_DRAW_HIDDEN) | ||
61 | { | ||
62 | regions = regions->next; | ||
63 | continue; | ||
64 | } | ||
65 | /* check if it's inside this viewport */ | ||
66 | if (viewport_point_within_vp(&(r->wvp->vp), x, y)) | ||
67 | { /* reposition the touch inside the viewport since touchregions | ||
68 | * are relative to a preceding viewport */ | ||
69 | vx = x - r->wvp->vp.x; | ||
70 | vy = y - r->wvp->vp.y; | ||
71 | /* now see if the point is inside this region */ | ||
72 | if (vx >= r->x && vx < r->x+r->width && | ||
73 | vy >= r->y && vy < r->y+r->height) | ||
74 | { | ||
75 | /* reposition the touch within the area */ | ||
76 | vx -= r->x; | ||
77 | vy -= r->y; | ||
78 | |||
79 | |||
80 | switch(r->type) | ||
81 | { | ||
82 | case WPS_TOUCHREGION_ACTION: | ||
83 | if (r->armed && ((repeated && r->repeat) || (released && !r->repeat))) | ||
84 | { | ||
85 | last_action = r->action; | ||
86 | returncode = r->action; | ||
87 | } | ||
88 | if (pressed) | ||
89 | r->armed = true; | ||
90 | break; | ||
91 | default: | ||
92 | if (edge_offset) | ||
93 | { | ||
94 | if(r->width > r->height) | ||
95 | *edge_offset = vx*100/r->width; | ||
96 | else | ||
97 | *edge_offset = vy*100/r->height; | ||
98 | } | ||
99 | returncode = r->type; | ||
100 | break; | ||
101 | } | ||
102 | } | ||
103 | } | ||
104 | regions = regions->next; | ||
105 | } | ||
106 | |||
107 | /* On release, all regions are disarmed. */ | ||
108 | if (released) | ||
109 | skin_disarm_touchregions(data); | ||
110 | |||
111 | if (returncode != ACTION_NONE) | ||
112 | return returncode; | ||
113 | |||
114 | last_action = ACTION_TOUCHSCREEN; | ||
115 | return ACTION_TOUCHSCREEN; | ||
116 | } | ||