1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2009 - Jonathan Gordon
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.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
25 #include "skin_engine.h"
26 #include "wps_internals.h"
28 /** Disarms all touchregions. */
29 void skin_disarm_touchregions(struct wps_data
*data
)
31 struct skin_token_list
*regions
= data
->touchregions
;
34 ((struct touchregion
*)regions
->token
->value
.data
)->armed
= false;
35 regions
= regions
->next
;
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.
43 int skin_get_touchaction(struct wps_data
*data
, int* edge_offset
,
44 struct touchregion
**retregion
)
46 int returncode
= ACTION_NONE
;
49 int type
= action_get_touchscreen_press(&x
, &y
);
50 static int last_action
= ACTION_NONE
;
51 struct touchregion
*r
;
52 bool repeated
= (type
== BUTTON_REPEAT
);
53 bool released
= (type
== BUTTON_REL
);
54 bool pressed
= (type
== BUTTON_TOUCHSCREEN
);
55 struct skin_token_list
*regions
= data
->touchregions
;
59 r
= (struct touchregion
*)regions
->token
->value
.data
;
60 /* make sure this region's viewport is visible */
61 if (r
->wvp
->hidden_flags
&VP_DRAW_HIDDEN
)
63 regions
= regions
->next
;
66 /* check if it's inside this viewport */
67 if (viewport_point_within_vp(&(r
->wvp
->vp
), x
, y
))
68 { /* reposition the touch inside the viewport since touchregions
69 * are relative to a preceding viewport */
70 vx
= x
- r
->wvp
->vp
.x
;
71 vy
= y
- r
->wvp
->vp
.y
;
72 /* now see if the point is inside this region */
73 if (vx
>= r
->x
&& vx
< r
->x
+r
->width
&&
74 vy
>= r
->y
&& vy
< r
->y
+r
->height
)
76 /* reposition the touch within the area */
83 case WPS_TOUCHREGION_ACTION
:
84 if (r
->armed
&& ((repeated
&& r
->repeat
) || (released
&& !r
->repeat
)))
86 last_action
= r
->action
;
87 returncode
= r
->action
;
97 if(r
->width
> r
->height
)
98 *edge_offset
= vx
*100/r
->width
;
100 *edge_offset
= vy
*100/r
->height
;
102 *edge_offset
= 100 - *edge_offset
;
104 returncode
= r
->type
;
111 regions
= regions
->next
;
114 /* On release, all regions are disarmed. */
116 skin_disarm_touchregions(data
);
118 if (returncode
!= ACTION_NONE
)
121 last_action
= ACTION_TOUCHSCREEN
;
122 return ACTION_TOUCHSCREEN
;