summaryrefslogtreecommitdiff
path: root/src/lib/evas/gesture
diff options
context:
space:
mode:
authorsmohanty <smohantty@gmail.com>2017-09-19 16:55:45 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2017-10-19 10:33:12 +0900
commite65f18ef3ec51e2a3e68ea913b5bdb15d4e5435d (patch)
tree002eac8526a6a508fd3d9f24a4f9ea65d57bce0c /src/lib/evas/gesture
parenta4030232427761b1d627b0db2f61859d7a667b57 (diff)
evas/gesture: Added touch accumulator class implementation.
Diffstat (limited to 'src/lib/evas/gesture')
-rw-r--r--src/lib/evas/gesture/efl_gesture_touch.c166
1 files changed, 166 insertions, 0 deletions
diff --git a/src/lib/evas/gesture/efl_gesture_touch.c b/src/lib/evas/gesture/efl_gesture_touch.c
new file mode 100644
index 0000000..57c2705
--- /dev/null
+++ b/src/lib/evas/gesture/efl_gesture_touch.c
@@ -0,0 +1,166 @@
1#include "efl_gesture_private.h"
2
3#define MY_CLASS EFL_GESTURE_TOUCH_CLASS
4
5typedef struct _Pointer_Data
6{
7 struct
8 {
9 double x;
10 double y;
11 double timestamp;
12 } start, prev, cur ;
13 Efl_Pointer_Action action;
14}Pointer_Data;
15
16typedef struct _Efl_Gesture_Touch_Data
17{
18 Efl_Gesture_Touch_State type;
19 Eina_Hash *touch_points;
20 Eina_List *finger_list;
21 Eina_Bool multi_touch;
22 Eo *target;
23} Efl_Gesture_Touch_Data;
24
25
26// This event object accumulates all the touch points
27// that are directed to a particular object from the
28// first finger down to the last finger up
29
30static void _hash_free_cb(Pointer_Data *point)
31{
32 free(point);
33}
34
35EOLIAN static Efl_Object *
36_efl_gesture_touch_efl_object_constructor(Eo *obj, Efl_Gesture_Touch_Data *pd)
37{
38 obj = efl_constructor(efl_super(obj, MY_CLASS));
39 pd->touch_points = eina_hash_int32_new(EINA_FREE_CB(_hash_free_cb));
40
41 return obj;
42}
43
44EOLIAN static void
45_efl_gesture_touch_efl_object_destructor(Eo *obj, Efl_Gesture_Touch_Data *pd)
46{
47 eina_hash_free(pd->touch_points);
48 efl_destructor(efl_super(obj, MY_CLASS));
49}
50
51EOLIAN static Efl_Gesture_Touch_State
52_efl_gesture_touch_state_get(Eo *obj EINA_UNUSED, Efl_Gesture_Touch_Data *pd)
53{
54 return pd->type;
55}
56
57EOLIAN static void
58_efl_gesture_touch_point_record(Eo *obj EINA_UNUSED, Efl_Gesture_Touch_Data *pd,
59 int id, double x, double y, double timestamp, Efl_Pointer_Action action)
60{
61 Pointer_Data *point = eina_hash_find(pd->touch_points, &id);
62 if (point)
63 {
64 // the point already exists. update the cur and prev point
65 point->prev.x = point->cur.x;
66 point->prev.y = point->cur.y;
67 point->prev.timestamp = point->cur.timestamp;
68 point->cur.x = x;
69 point->cur.y = y;
70 point->cur.timestamp = timestamp;
71 }
72 else
73 {
74 // new finger
75 if (!id && (action != EFL_POINTER_ACTION_DOWN))
76 {
77 // discard any other event
78 return;
79 }
80 point = calloc(1, sizeof(Pointer_Data));
81 point->start.x = point->prev.x = point->cur.x = x;
82 point->start.y = point->prev.y = point->cur.y = y;
83 point->start.timestamp = point->prev.timestamp = point->cur.timestamp = timestamp;
84
85 // add to the hash
86 eina_hash_add(pd->touch_points, &id, point);
87 pd->finger_list = eina_list_append(pd->finger_list, &id);
88 if (id)
89 pd->multi_touch = EINA_TRUE;
90 }
91 point->action = action;
92
93 if (!id && (action == EFL_POINTER_ACTION_DOWN))
94 {
95 pd->type = EFL_GESTURE_TOUCH_BEGIN;
96 }
97 else if ((action == EFL_POINTER_ACTION_UP) && (eina_list_count(pd->finger_list) == 1))
98 {
99 pd->type = EFL_GESTURE_TOUCH_END;
100 }
101 else
102 {
103 pd->type = EFL_GESTURE_TOUCH_UPDATE;
104 }
105
106}
107
108EOLIAN static Eina_Bool
109_efl_gesture_touch_multi_touch_get(Eo *obj EINA_UNUSED, Efl_Gesture_Touch_Data *pd)
110{
111 return pd->multi_touch;
112}
113
114EOLIAN static void
115_efl_gesture_touch_start_point(Eo *obj EINA_UNUSED, Efl_Gesture_Touch_Data *pd, double *x, double *y)
116{
117 int tool = 0;
118 Pointer_Data *point = eina_hash_find(pd->touch_points, &tool);
119
120 *x = 0;
121 *y = 0;
122
123 if (point)
124 {
125 *x = point->start.x;
126 *y = point->start.y;
127 }
128}
129
130EOLIAN static void
131_efl_gesture_touch_delta(Eo *obj EINA_UNUSED, Efl_Gesture_Touch_Data *pd, int tool, double *x, double *y)
132{
133 Pointer_Data *point = eina_hash_find(pd->touch_points, &tool);
134
135 *x = 0;
136 *y = 0;
137
138 if (point)
139 {
140 *x = point->cur.x - point->prev.x;
141 *y = point->cur.y - point->prev.y;
142 }
143}
144
145EOLIAN static void
146_efl_gesture_touch_distance(Eo *obj EINA_UNUSED, Efl_Gesture_Touch_Data *pd, int tool, double *x, double *y)
147{
148 Pointer_Data *point = eina_hash_find(pd->touch_points, &tool);
149
150 *x = 0;
151 *y = 0;
152
153 if (point)
154 {
155 *x = point->cur.x - point->start.x;
156 *y = point->cur.y - point->start.y;
157 }
158}
159
160EOLIAN static const Eina_List *
161_efl_gesture_touch_finger_list_get(Eo *obj EINA_UNUSED, Efl_Gesture_Touch_Data *pd)
162{
163 return pd->finger_list;
164}
165
166#include "efl_gesture_touch.eo.c" \ No newline at end of file