summaryrefslogtreecommitdiff
path: root/apps/gui/skin_engine/skin_touchsupport.c
diff options
context:
space:
mode:
authorJonathan Gordon <rockbox@jdgordon.info>2010-06-21 06:04:19 +0000
committerJonathan Gordon <rockbox@jdgordon.info>2010-06-21 06:04:19 +0000
commita398c2846aa86650aa386a68cb51929477b6aa23 (patch)
tree4fa695ba8ea3a2b0e0c1f1c1ab5ac9ce27430804 /apps/gui/skin_engine/skin_touchsupport.c
parent2b0ef19900295ef4e8da0fa52a13a04ccf76cb65 (diff)
downloadrockbox-a398c2846aa86650aa386a68cb51929477b6aa23.tar.gz
rockbox-a398c2846aa86650aa386a68cb51929477b6aa23.zip
Touchregion support for the Base Skin and FM Skins. display obviously needs to be in stylus mode for this to work. Just about all screens should be mostly useable if your sbs has the next/prev/select/cancel/menu regions defined.
Plenty of room to add new action abilities if they are wanted. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27004 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/gui/skin_engine/skin_touchsupport.c')
-rw-r--r--apps/gui/skin_engine/skin_touchsupport.c116
1 files changed, 116 insertions, 0 deletions
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. */
29void 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 */
43int 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}