summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@samsung.com>2020-01-13 15:04:38 -0500
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2020-01-30 17:06:54 +0100
commit28e89a5ac7e556b198dbe7e883d248c12f4844df (patch)
tree5e20cfe4deec26b5e1051e255e80fc920590755b
parent9809cec2210963f6584bed9664929f07748ae2b3 (diff)
efl/gesture: move Point_Data to eo and add methods to fetch it for recognizers
this lets gesture framework track two touch points in order to distinguish between successive presses and e.g., treat a simultaneous two finger tap as a single tap gesture rather than two it also simplifies some internal code and removes most hash lookups Reviewed-by: woochan lee <wc0917.lee@samsung.com> Differential Revision: https://phab.enlightenment.org/D11085
-rw-r--r--src/lib/evas/gesture/efl_canvas_gesture_private.h23
-rw-r--r--src/lib/evas/gesture/efl_canvas_gesture_recognizer_zoom.c20
-rw-r--r--src/lib/evas/gesture/efl_canvas_gesture_touch.c79
-rw-r--r--src/lib/evas/gesture/efl_canvas_gesture_touch.eo23
-rw-r--r--src/lib/evas/gesture/efl_canvas_gesture_types.eot18
5 files changed, 102 insertions, 61 deletions
diff --git a/src/lib/evas/gesture/efl_canvas_gesture_private.h b/src/lib/evas/gesture/efl_canvas_gesture_private.h
index fb24d0f549..e24dea8307 100644
--- a/src/lib/evas/gesture/efl_canvas_gesture_private.h
+++ b/src/lib/evas/gesture/efl_canvas_gesture_private.h
@@ -25,22 +25,13 @@ typedef struct _Efl_Canvas_Gesture_Momentum_Data Efl_Canvas_Gestur
25typedef struct _Efl_Canvas_Gesture_Flick_Data Efl_Canvas_Gesture_Flick_Data; 25typedef struct _Efl_Canvas_Gesture_Flick_Data Efl_Canvas_Gesture_Flick_Data;
26typedef struct _Efl_Canvas_Gesture_Zoom_Data Efl_Canvas_Gesture_Zoom_Data; 26typedef struct _Efl_Canvas_Gesture_Zoom_Data Efl_Canvas_Gesture_Zoom_Data;
27 27
28typedef struct _Pointer_Data
29{
30 struct
31 {
32 Eina_Position2D pos;
33 unsigned int timestamp;
34 } start, prev, cur;
35 int id;
36 Efl_Pointer_Action action;
37} Pointer_Data;
38
39typedef struct _Efl_Canvas_Gesture_Touch_Data 28typedef struct _Efl_Canvas_Gesture_Touch_Data
40{ 29{
41 Efl_Canvas_Gesture_Touch_State state; 30 Efl_Canvas_Gesture_Touch_State state;
42 Eina_Hash *touch_points; 31 Eina_Array *touch_points;
43 int touch_down; 32 int touch_down;
33 Efl_Gesture_Touch_Point_Data *cur_touch;
34 Efl_Gesture_Touch_Point_Data *prev_touch;
44 Eina_Bool multi_touch; 35 Eina_Bool multi_touch;
45 Eo *target; 36 Eo *target;
46} Efl_Canvas_Gesture_Touch_Data; 37} Efl_Canvas_Gesture_Touch_Data;
@@ -115,11 +106,11 @@ struct _Efl_Canvas_Gesture_Recognizer_Flick_Data
115 106
116struct _Efl_Canvas_Gesture_Recognizer_Zoom_Data 107struct _Efl_Canvas_Gesture_Recognizer_Zoom_Data
117{ 108{
118 Pointer_Data zoom_st; 109 Efl_Gesture_Touch_Point_Data zoom_st;
119 Pointer_Data zoom_st1; 110 Efl_Gesture_Touch_Point_Data zoom_st1;
120 111
121 Pointer_Data zoom_mv; 112 Efl_Gesture_Touch_Point_Data zoom_mv;
122 Pointer_Data zoom_mv1; 113 Efl_Gesture_Touch_Point_Data zoom_mv1;
123 114
124 Evas_Coord zoom_base; /* Holds gap between fingers on 115 Evas_Coord zoom_base; /* Holds gap between fingers on
125 * zoom-start */ 116 * zoom-start */
diff --git a/src/lib/evas/gesture/efl_canvas_gesture_recognizer_zoom.c b/src/lib/evas/gesture/efl_canvas_gesture_recognizer_zoom.c
index 0603098539..d88a9c0050 100644
--- a/src/lib/evas/gesture/efl_canvas_gesture_recognizer_zoom.c
+++ b/src/lib/evas/gesture/efl_canvas_gesture_recognizer_zoom.c
@@ -126,8 +126,6 @@ _efl_canvas_gesture_recognizer_zoom_efl_canvas_gesture_recognizer_recognize(Eo *
126 Efl_Object *watched, 126 Efl_Object *watched,
127 Efl_Canvas_Gesture_Touch *event) 127 Efl_Canvas_Gesture_Touch *event)
128{ 128{
129 int id1 = 0;
130 int id2 = 1;
131 Eina_Value *val; 129 Eina_Value *val;
132 unsigned char zoom_finger_enable; 130 unsigned char zoom_finger_enable;
133 unsigned char glayer_continues_enable; 131 unsigned char glayer_continues_enable;
@@ -186,14 +184,14 @@ _efl_canvas_gesture_recognizer_zoom_efl_canvas_gesture_recognizer_recognize(Eo *
186 if (!efl_gesture_touch_multi_touch_get(event)) 184 if (!efl_gesture_touch_multi_touch_get(event))
187 return EFL_GESTURE_RECOGNIZER_RESULT_IGNORE; 185 return EFL_GESTURE_RECOGNIZER_RESULT_IGNORE;
188 186
189 Pointer_Data *p1 = eina_hash_find(td->touch_points, &id1); 187 const Efl_Gesture_Touch_Point_Data *p1 = efl_gesture_touch_data_get(event, 0);
190 Pointer_Data *p2 = eina_hash_find(td->touch_points, &id2); 188 const Efl_Gesture_Touch_Point_Data *p2 = efl_gesture_touch_data_get(event, 1);
191 189
192 memcpy(&pd->zoom_st, p2, sizeof(Pointer_Data)); 190 memcpy(&pd->zoom_st, p2, sizeof(Efl_Gesture_Touch_Point_Data));
193 memcpy(&pd->zoom_st1, p1, sizeof(Pointer_Data)); 191 memcpy(&pd->zoom_st1, p1, sizeof(Efl_Gesture_Touch_Point_Data));
194 192
195 memcpy(&pd->zoom_mv, p2, sizeof(Pointer_Data)); 193 memcpy(&pd->zoom_mv, p2, sizeof(Efl_Gesture_Touch_Point_Data));
196 memcpy(&pd->zoom_mv1, p1, sizeof(Pointer_Data)); 194 memcpy(&pd->zoom_mv1, p1, sizeof(Efl_Gesture_Touch_Point_Data));
197 195
198 int x, y; //Hot spot 196 int x, y; //Hot spot
199 zd->zoom = 1.0; 197 zd->zoom = 1.0;
@@ -212,11 +210,11 @@ _efl_canvas_gesture_recognizer_zoom_efl_canvas_gesture_recognizer_recognize(Eo *
212 return EFL_GESTURE_RECOGNIZER_RESULT_CANCEL; 210 return EFL_GESTURE_RECOGNIZER_RESULT_CANCEL;
213 } 211 }
214 212
215 Pointer_Data *p2 = eina_hash_find(td->touch_points, &id2); 213 const Efl_Gesture_Touch_Point_Data *p2 = efl_gesture_touch_data_get(event, 1);
216 if (p2->id == pd->zoom_mv.id) 214 if (p2->id == pd->zoom_mv.id)
217 memcpy(&pd->zoom_mv, p2, sizeof(Pointer_Data)); 215 memcpy(&pd->zoom_mv, p2, sizeof(Efl_Gesture_Touch_Point_Data));
218 else if (p2->id == pd->zoom_mv1.id) 216 else if (p2->id == pd->zoom_mv1.id)
219 memcpy(&pd->zoom_mv1, p2, sizeof(Pointer_Data)); 217 memcpy(&pd->zoom_mv1, p2, sizeof(Efl_Gesture_Touch_Point_Data));
220 218
221 zd->zoom = _zoom_compute(pd, zd, pd->zoom_mv.cur.pos.x, 219 zd->zoom = _zoom_compute(pd, zd, pd->zoom_mv.cur.pos.x,
222 pd->zoom_mv.cur.pos.y, pd->zoom_mv1.cur.pos.x, 220 pd->zoom_mv.cur.pos.y, pd->zoom_mv1.cur.pos.x,
diff --git a/src/lib/evas/gesture/efl_canvas_gesture_touch.c b/src/lib/evas/gesture/efl_canvas_gesture_touch.c
index 6ddb3be59e..3ed9dfe2b2 100644
--- a/src/lib/evas/gesture/efl_canvas_gesture_touch.c
+++ b/src/lib/evas/gesture/efl_canvas_gesture_touch.c
@@ -6,33 +6,30 @@
6//that are directed to a particular object from the 6//that are directed to a particular object from the
7//first finger down to the last finger up 7//first finger down to the last finger up
8 8
9static void
10_hash_free_cb(Pointer_Data *point)
11{
12 free(point);
13}
14
15static inline void 9static inline void
16_touch_points_reset(Efl_Canvas_Gesture_Touch_Data *pd) 10_touch_points_reset(Efl_Canvas_Gesture_Touch_Data *pd)
17{ 11{
18 eina_hash_free(pd->touch_points); 12 while (eina_array_count(pd->touch_points))
19 pd->touch_points = eina_hash_int32_new(EINA_FREE_CB(_hash_free_cb)); 13 free(eina_array_pop(pd->touch_points));
20 pd->touch_down = 0; 14 pd->touch_down = 0;
15 pd->prev_touch = pd->cur_touch = NULL;
21 pd->state = EFL_GESTURE_TOUCH_STATE_UNKNOWN; 16 pd->state = EFL_GESTURE_TOUCH_STATE_UNKNOWN;
22} 17}
23 18
24EOLIAN static Efl_Object * 19EOLIAN static Efl_Object *
25_efl_canvas_gesture_touch_efl_object_constructor(Eo *obj, Efl_Canvas_Gesture_Touch_Data *pd) 20_efl_canvas_gesture_touch_efl_object_constructor(Eo *obj, Efl_Canvas_Gesture_Touch_Data *pd)
26{ 21{
27 obj = efl_constructor(efl_super(obj, MY_CLASS)); 22 pd->touch_points = eina_array_new(2);
28 _touch_points_reset(pd); 23 EINA_SAFETY_ON_NULL_RETURN_VAL(pd->touch_points, NULL);
29 return obj; 24 return efl_constructor(efl_super(obj, MY_CLASS));
30} 25}
31 26
32EOLIAN static void 27EOLIAN static void
33_efl_canvas_gesture_touch_efl_object_destructor(Eo *obj, Efl_Canvas_Gesture_Touch_Data *pd) 28_efl_canvas_gesture_touch_efl_object_destructor(Eo *obj, Efl_Canvas_Gesture_Touch_Data *pd)
34{ 29{
35 eina_hash_free(pd->touch_points); 30 while (eina_array_count(pd->touch_points))
31 free(eina_array_pop(pd->touch_points));
32 eina_array_free(pd->touch_points);
36 efl_destructor(efl_super(obj, MY_CLASS)); 33 efl_destructor(efl_super(obj, MY_CLASS));
37} 34}
38 35
@@ -51,14 +48,16 @@ _efl_canvas_gesture_touch_point_record(Eo *obj EINA_UNUSED, Efl_Canvas_Gesture_T
51 Efl_Pointer_Action action = pointer_data->action; 48 Efl_Pointer_Action action = pointer_data->action;
52 Eina_Vector2 pos = pointer_data->cur; 49 Eina_Vector2 pos = pointer_data->cur;
53 50
54 Pointer_Data *point = eina_hash_find(pd->touch_points, &id);
55 Eina_Position2D _pos = { pos.x, pos.y }; 51 Eina_Position2D _pos = { pos.x, pos.y };
52 Efl_Gesture_Touch_Point_Data *point = NULL;
53
54 if (eina_array_count(pd->touch_points) >= (unsigned int)id + 1)
55 point = eina_array_data_get(pd->touch_points, id);
56 56
57 if (action == EFL_POINTER_ACTION_DOWN) 57 if (action == EFL_POINTER_ACTION_DOWN)
58 { 58 {
59 pd->touch_down++; 59 pd->touch_down++;
60 //TODO: Need to handle 2 or more case. 60 if (pd->touch_down >= 2)
61 if (pd->touch_down == 2)
62 pd->multi_touch = EINA_TRUE; 61 pd->multi_touch = EINA_TRUE;
63 } 62 }
64 else if ((action == EFL_POINTER_ACTION_UP) || 63 else if ((action == EFL_POINTER_ACTION_UP) ||
@@ -86,18 +85,17 @@ _efl_canvas_gesture_touch_point_record(Eo *obj EINA_UNUSED, Efl_Canvas_Gesture_T
86 //Discard any other event 85 //Discard any other event
87 return; 86 return;
88 } 87 }
89 point = calloc(1, sizeof(Pointer_Data)); 88 point = calloc(1, sizeof(Efl_Gesture_Touch_Point_Data));
90 if (!point) return; 89 if (!point) return;
91 point->start.pos = point->prev.pos = point->cur.pos = _pos; 90 point->start.pos = point->prev.pos = point->cur.pos = _pos;
92 point->start.timestamp = point->prev.timestamp = point->cur.timestamp = timestamp; 91 point->start.timestamp = point->prev.timestamp = point->cur.timestamp = timestamp;
93 point->id = id; 92 point->id = id;
94 93
95 //Add to the hash 94 eina_array_push(pd->touch_points, point);
96 eina_hash_add(pd->touch_points, &id, point);
97 //FIXME: finger_list was broken
98 if (id)
99 pd->multi_touch = EINA_TRUE;
100 } 95 }
96 if (pd->cur_touch != point)
97 pd->prev_touch = pd->cur_touch;
98 pd->cur_touch = point;
101 point->action = action; 99 point->action = action;
102 100
103 if (!id && (action == EFL_POINTER_ACTION_DOWN)) 101 if (!id && (action == EFL_POINTER_ACTION_DOWN))
@@ -124,11 +122,28 @@ _efl_canvas_gesture_touch_multi_touch_get(const Eo *obj EINA_UNUSED, Efl_Canvas_
124 return pd->multi_touch; 122 return pd->multi_touch;
125} 123}
126 124
125EOLIAN static const Efl_Gesture_Touch_Point_Data *
126_efl_canvas_gesture_touch_cur_data_get(const Eo *obj EINA_UNUSED, Efl_Canvas_Gesture_Touch_Data *pd)
127{
128 return pd->cur_touch;
129}
130
131EOLIAN static const Efl_Gesture_Touch_Point_Data *
132_efl_canvas_gesture_touch_prev_data_get(const Eo *obj EINA_UNUSED, Efl_Canvas_Gesture_Touch_Data *pd)
133{
134 return pd->prev_touch;
135}
136
137EOLIAN static const Efl_Gesture_Touch_Point_Data *
138_efl_canvas_gesture_touch_data_get(const Eo *obj EINA_UNUSED, Efl_Canvas_Gesture_Touch_Data *pd, unsigned int id)
139{
140 return eina_array_count(pd->touch_points) >= id + 1 ? eina_array_data_get(pd->touch_points, id) : NULL;
141}
142
127EOLIAN static Eina_Position2D 143EOLIAN static Eina_Position2D
128_efl_canvas_gesture_touch_start_point_get(const Eo *obj EINA_UNUSED, Efl_Canvas_Gesture_Touch_Data *pd) 144_efl_canvas_gesture_touch_start_point_get(const Eo *obj EINA_UNUSED, Efl_Canvas_Gesture_Touch_Data *pd EINA_UNUSED)
129{ 145{
130 int tool = 0; 146 const Efl_Gesture_Touch_Point_Data *point = efl_gesture_touch_data_get(obj, 0);
131 Pointer_Data *point = eina_hash_find(pd->touch_points, &tool);
132 Eina_Position2D vec = { 0, 0 }; 147 Eina_Position2D vec = { 0, 0 };
133 148
134 if (!point) 149 if (!point)
@@ -140,8 +155,7 @@ _efl_canvas_gesture_touch_start_point_get(const Eo *obj EINA_UNUSED, Efl_Canvas_
140EOLIAN static Eina_Position2D 155EOLIAN static Eina_Position2D
141_efl_canvas_gesture_touch_cur_point_get(const Eo *obj EINA_UNUSED, Efl_Canvas_Gesture_Touch_Data *pd) 156_efl_canvas_gesture_touch_cur_point_get(const Eo *obj EINA_UNUSED, Efl_Canvas_Gesture_Touch_Data *pd)
142{ 157{
143 int tool = 0; 158 const Efl_Gesture_Touch_Point_Data *point = pd->cur_touch;
144 Pointer_Data *point = eina_hash_find(pd->touch_points, &tool);
145 Eina_Position2D vec = { 0, 0 }; 159 Eina_Position2D vec = { 0, 0 };
146 160
147 if (!point) 161 if (!point)
@@ -153,8 +167,7 @@ _efl_canvas_gesture_touch_cur_point_get(const Eo *obj EINA_UNUSED, Efl_Canvas_Ge
153EOLIAN static unsigned int 167EOLIAN static unsigned int
154_efl_canvas_gesture_touch_cur_timestamp_get(const Eo *obj EINA_UNUSED, Efl_Canvas_Gesture_Touch_Data *pd) 168_efl_canvas_gesture_touch_cur_timestamp_get(const Eo *obj EINA_UNUSED, Efl_Canvas_Gesture_Touch_Data *pd)
155{ 169{
156 int tool = 0; 170 const Efl_Gesture_Touch_Point_Data *point = pd->cur_touch;
157 Pointer_Data *point = eina_hash_find(pd->touch_points, &tool);
158 171
159 if (!point) 172 if (!point)
160 return 0; 173 return 0;
@@ -165,11 +178,10 @@ _efl_canvas_gesture_touch_cur_timestamp_get(const Eo *obj EINA_UNUSED, Efl_Canva
165EOLIAN static Eina_Vector2 178EOLIAN static Eina_Vector2
166_efl_canvas_gesture_touch_delta(const Eo *obj EINA_UNUSED, Efl_Canvas_Gesture_Touch_Data *pd, int tool) 179_efl_canvas_gesture_touch_delta(const Eo *obj EINA_UNUSED, Efl_Canvas_Gesture_Touch_Data *pd, int tool)
167{ 180{
168 Pointer_Data *point = eina_hash_find(pd->touch_points, &tool); 181 Efl_Gesture_Touch_Point_Data *point = eina_array_count(pd->touch_points) >= (unsigned)tool + 1 ? eina_array_data_get(pd->touch_points, tool) : NULL;
169 Eina_Vector2 vec = { 0, 0 }; 182 Eina_Vector2 vec = { 0, 0 };
170 183
171 if (!point) 184 EINA_SAFETY_ON_NULL_RETURN_VAL(point, vec);
172 return vec;
173 185
174 Eina_Vector2 v1 = { point->cur.pos.x, point->cur.pos.y }; 186 Eina_Vector2 v1 = { point->cur.pos.x, point->cur.pos.y };
175 Eina_Vector2 v2 = { point->prev.pos.x, point->prev.pos.y }; 187 Eina_Vector2 v2 = { point->prev.pos.x, point->prev.pos.y };
@@ -181,11 +193,10 @@ _efl_canvas_gesture_touch_delta(const Eo *obj EINA_UNUSED, Efl_Canvas_Gesture_To
181EOLIAN static Eina_Vector2 193EOLIAN static Eina_Vector2
182_efl_canvas_gesture_touch_distance(const Eo *obj EINA_UNUSED, Efl_Canvas_Gesture_Touch_Data *pd, int tool) 194_efl_canvas_gesture_touch_distance(const Eo *obj EINA_UNUSED, Efl_Canvas_Gesture_Touch_Data *pd, int tool)
183{ 195{
184 Pointer_Data *point = eina_hash_find(pd->touch_points, &tool); 196 Efl_Gesture_Touch_Point_Data *point = eina_array_count(pd->touch_points) >= (unsigned)tool + 1 ? eina_array_data_get(pd->touch_points, tool) : NULL;
185 Eina_Vector2 vec = { 0, 0 }; 197 Eina_Vector2 vec = { 0, 0 };
186 198
187 if (!point) 199 EINA_SAFETY_ON_NULL_RETURN_VAL(point, vec);
188 return vec;
189 200
190 Eina_Vector2 v1 = { point->cur.pos.x, point->cur.pos.y }; 201 Eina_Vector2 v1 = { point->cur.pos.x, point->cur.pos.y };
191 Eina_Vector2 v2 = { point->start.pos.x, point->start.pos.y }; 202 Eina_Vector2 v2 = { point->start.pos.x, point->start.pos.y };
diff --git a/src/lib/evas/gesture/efl_canvas_gesture_touch.eo b/src/lib/evas/gesture/efl_canvas_gesture_touch.eo
index 0425aa7fdc..a12d26d3b9 100644
--- a/src/lib/evas/gesture/efl_canvas_gesture_touch.eo
+++ b/src/lib/evas/gesture/efl_canvas_gesture_touch.eo
@@ -66,6 +66,29 @@ class @beta Efl.Canvas.Gesture_Touch extends Efl.Object
66 return : Efl.Canvas.Gesture_Touch_State; [[touch event state]] 66 return : Efl.Canvas.Gesture_Touch_State; [[touch event state]]
67 } 67 }
68 } 68 }
69 @property cur_data {
70 [[This property holds the data struct of the most recent touch point.]]
71 get {}
72 values {
73 data: const(Efl.Canvas.Gesture_Touch_Point_Data) @by_ref; [[The current data.]]
74 }
75 }
76 @property prev_data {
77 [[This property holds the data struct of the second-most recent touch point.
78 If there is only one touch point active, it will return NULL.
79 ]]
80 get {}
81 values {
82 data: const(Efl.Canvas.Gesture_Touch_Point_Data) @by_ref; [[The previous touch point's data.]]
83 }
84 }
85 data_get @const {
86 [[This fetches the data for a specified touch point.]]
87 params {
88 @in id: uint; [[The id of the touch point to return.]]
89 }
90 return: const(Efl.Canvas.Gesture_Touch_Point_Data) @by_ref; [[The specified data if it exists.]]
91 }
69 /* FIXME: finger_list was broken by design - TODO */ 92 /* FIXME: finger_list was broken by design - TODO */
70 } 93 }
71 implements { 94 implements {
diff --git a/src/lib/evas/gesture/efl_canvas_gesture_types.eot b/src/lib/evas/gesture/efl_canvas_gesture_types.eot
index 8cde6e18a0..600518b31c 100644
--- a/src/lib/evas/gesture/efl_canvas_gesture_types.eot
+++ b/src/lib/evas/gesture/efl_canvas_gesture_types.eot
@@ -1,3 +1,6 @@
1import eina_types;
2import efl_input_types;
3
1enum @beta Efl.Canvas.Gesture_Touch_State 4enum @beta Efl.Canvas.Gesture_Touch_State
2{ 5{
3 [[ This enum type describes the state of a touch event. ]] 6 [[ This enum type describes the state of a touch event. ]]
@@ -44,3 +47,18 @@ enum @beta Efl.Canvas.Gesture_Recognizer_Type
44 flick, 47 flick,
45 zoom, 48 zoom,
46} 49}
50
51struct @beta @c_name(Efl_Gesture_Touch_Point_Info) Efl.Canvas.Gesture_Touch_Point_Info {
52 [[This struct represents the underlying data of a touch point.]]
53 pos: Eina.Position2D; [[The canvas position of the touch point data.]]
54 timestamp: uint; [[The timestamp of the touch point data.]]
55}
56
57struct @beta @c_name(Efl_Gesture_Touch_Point_Data) Efl.Canvas.Gesture_Touch_Point_Data {
58 [[This struct represents the state of a touch point.]]
59 id: int; [[Touch id of the point.]]
60 action: Efl.Pointer.Action; [[The last event with this point.]]
61 start: Efl.Canvas.Gesture_Touch_Point_Info; [[The start data for the touch point.]]
62 prev: Efl.Canvas.Gesture_Touch_Point_Info; [[The previous data for the touch point.]]
63 cur: Efl.Canvas.Gesture_Touch_Point_Info; [[The current data for the touch point.]]
64}