summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Blumenkrantz <zmike@samsung.com>2020-02-19 10:24:04 -0500
committerMarcel Hollerbach <mail@marcel-hollerbach.de>2020-03-03 10:54:28 +0100
commitd300e90d390fc9c764e57dc5806616e43e8db954 (patch)
tree97643567c43cfd6146263ce8146a8fcca3826ef2
parent830cdcf7ea7d45a78f2b08403f9eb5f50f35eeac (diff)
efl/gesture: port 'rotate' gesture from elm to new gesture framework
this is a 1:1 port with minimal changes other than what's necessary to integrate into the new framework Differential Revision: https://phab.enlightenment.org/D11383
-rw-r--r--src/bin/elementary/test_gesture_framework.c48
-rw-r--r--src/lib/evas/Efl_Canvas.h2
-rw-r--r--src/lib/evas/Evas_Eo.h2
-rw-r--r--src/lib/evas/gesture/efl_canvas_gesture_events.eo5
-rw-r--r--src/lib/evas/gesture/efl_canvas_gesture_manager.c9
-rw-r--r--src/lib/evas/gesture/efl_canvas_gesture_private.h28
-rw-r--r--src/lib/evas/gesture/efl_canvas_gesture_recognizer_rotate.c269
-rw-r--r--src/lib/evas/gesture/efl_canvas_gesture_recognizer_rotate.eo12
-rw-r--r--src/lib/evas/gesture/efl_canvas_gesture_rotate.c17
-rw-r--r--src/lib/evas/gesture/efl_canvas_gesture_rotate.eo28
-rw-r--r--src/lib/evas/gesture/meson.build4
11 files changed, 424 insertions, 0 deletions
diff --git a/src/bin/elementary/test_gesture_framework.c b/src/bin/elementary/test_gesture_framework.c
index ff40711cdd..4675604fa3 100644
--- a/src/bin/elementary/test_gesture_framework.c
+++ b/src/bin/elementary/test_gesture_framework.c
@@ -224,6 +224,33 @@ finger_flick_abort(void *data , Efl_Canvas_Gesture *tap EINA_UNUSED)
224} 224}
225 225
226static void 226static void
227finger_rotate_start(void *data , Efl_Canvas_Gesture *tap)
228{
229 Eina_Position2D pos = efl_gesture_hotspot_get(tap);
230
231 _color_and_icon_set(data, ROTATE_NAME, 1, MAX_TAP, START_COLOR);
232 printf("Rotate Gesture started x,y=<%d,%d> \n", pos.x, pos.y);
233}
234
235static void
236finger_rotate_end(void *data , Efl_Canvas_Gesture *tap)
237{
238 Eina_Position2D pos = efl_gesture_hotspot_get(tap);
239 double angle = efl_gesture_rotate_angle_get(tap);
240 double radius = efl_gesture_rotate_radius_get(tap);
241
242 _color_and_icon_set(data, ROTATE_NAME, 1, MAX_TAP, END_COLOR);
243 printf("Rotate Gesture ended x,y=<%d,%d> angle=<%g> radius=<%f>\n", pos.x, pos.y, angle, radius);
244}
245
246static void
247finger_rotate_abort(void *data , Efl_Canvas_Gesture *tap EINA_UNUSED)
248{
249 _color_and_icon_set(data, ROTATE_NAME, 1, MAX_TAP, ABORT_COLOR);
250 printf("Rotate Aborted\n");
251}
252
253static void
227finger_zoom_start(void *data , Efl_Canvas_Gesture *tap) 254finger_zoom_start(void *data , Efl_Canvas_Gesture *tap)
228{ 255{
229 Eina_Position2D pos = efl_gesture_hotspot_get(tap); 256 Eina_Position2D pos = efl_gesture_hotspot_get(tap);
@@ -432,6 +459,26 @@ flick_gesture_cb(void *data , const Efl_Event *ev)
432} 459}
433 460
434static void 461static void
462rotate_gesture_cb(void *data , const Efl_Event *ev)
463{
464 Efl_Canvas_Gesture *g = ev->info;
465 switch(efl_gesture_state_get(g))
466 {
467 case EFL_GESTURE_STATE_STARTED:
468 finger_rotate_start(data, g);
469 break;
470 case EFL_GESTURE_STATE_CANCELED:
471 finger_rotate_abort(data, g);
472 break;
473 case EFL_GESTURE_STATE_FINISHED:
474 finger_rotate_end(data, g);
475 break;
476 default:
477 break;
478 }
479}
480
481static void
435zoom_gesture_cb(void *data , const Efl_Event *ev) 482zoom_gesture_cb(void *data , const Efl_Event *ev)
436{ 483{
437 Efl_Canvas_Gesture *g = ev->info; 484 Efl_Canvas_Gesture *g = ev->info;
@@ -741,6 +788,7 @@ test_gesture_framework(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
741 efl_event_callback_add(target, EFL_EVENT_GESTURE_TRIPLE_TAP, triple_tap_gesture_cb, infra); 788 efl_event_callback_add(target, EFL_EVENT_GESTURE_TRIPLE_TAP, triple_tap_gesture_cb, infra);
742 efl_event_callback_add(target, EFL_EVENT_GESTURE_MOMENTUM, momentum_gesture_cb, infra); 789 efl_event_callback_add(target, EFL_EVENT_GESTURE_MOMENTUM, momentum_gesture_cb, infra);
743 efl_event_callback_add(target, EFL_EVENT_GESTURE_FLICK, flick_gesture_cb, infra); 790 efl_event_callback_add(target, EFL_EVENT_GESTURE_FLICK, flick_gesture_cb, infra);
791 efl_event_callback_add(target, EFL_EVENT_GESTURE_ROTATE, rotate_gesture_cb, infra);
744 efl_event_callback_add(target, EFL_EVENT_GESTURE_ZOOM, zoom_gesture_cb, infra); 792 efl_event_callback_add(target, EFL_EVENT_GESTURE_ZOOM, zoom_gesture_cb, infra);
745 793
746 /* Update color state 20 times a second */ 794 /* Update color state 20 times a second */
diff --git a/src/lib/evas/Efl_Canvas.h b/src/lib/evas/Efl_Canvas.h
index f457acc4bf..55534b17dc 100644
--- a/src/lib/evas/Efl_Canvas.h
+++ b/src/lib/evas/Efl_Canvas.h
@@ -117,10 +117,12 @@ extern "C" {
117#include <gesture/efl_canvas_gesture_recognizer_momentum.eo.h> 117#include <gesture/efl_canvas_gesture_recognizer_momentum.eo.h>
118#include <gesture/efl_canvas_gesture_recognizer_tap.eo.h> 118#include <gesture/efl_canvas_gesture_recognizer_tap.eo.h>
119#include <gesture/efl_canvas_gesture_recognizer_triple_tap.eo.h> 119#include <gesture/efl_canvas_gesture_recognizer_triple_tap.eo.h>
120#include <gesture/efl_canvas_gesture_recognizer_rotate.eo.h>
120#include <gesture/efl_canvas_gesture_recognizer_zoom.eo.h> 121#include <gesture/efl_canvas_gesture_recognizer_zoom.eo.h>
121#include <gesture/efl_canvas_gesture_recognizer_custom.eo.h> 122#include <gesture/efl_canvas_gesture_recognizer_custom.eo.h>
122#include <gesture/efl_canvas_gesture_tap.eo.h> 123#include <gesture/efl_canvas_gesture_tap.eo.h>
123#include <gesture/efl_canvas_gesture_triple_tap.eo.h> 124#include <gesture/efl_canvas_gesture_triple_tap.eo.h>
125#include <gesture/efl_canvas_gesture_rotate.eo.h>
124#include <gesture/efl_canvas_gesture_zoom.eo.h> 126#include <gesture/efl_canvas_gesture_zoom.eo.h>
125#include <gesture/efl_canvas_gesture_custom.eo.h> 127#include <gesture/efl_canvas_gesture_custom.eo.h>
126#include <gesture/efl_canvas_gesture_events.eo.h> 128#include <gesture/efl_canvas_gesture_events.eo.h>
diff --git a/src/lib/evas/Evas_Eo.h b/src/lib/evas/Evas_Eo.h
index 7d25c38874..046f2c55d6 100644
--- a/src/lib/evas/Evas_Eo.h
+++ b/src/lib/evas/Evas_Eo.h
@@ -91,6 +91,7 @@ struct _Efl_Canvas_Object_Animation_Event
91#include "gesture/efl_canvas_gesture_triple_tap.eo.h" 91#include "gesture/efl_canvas_gesture_triple_tap.eo.h"
92#include "gesture/efl_canvas_gesture_momentum.eo.h" 92#include "gesture/efl_canvas_gesture_momentum.eo.h"
93#include "gesture/efl_canvas_gesture_flick.eo.h" 93#include "gesture/efl_canvas_gesture_flick.eo.h"
94#include "gesture/efl_canvas_gesture_rotate.eo.h"
94#include "gesture/efl_canvas_gesture_zoom.eo.h" 95#include "gesture/efl_canvas_gesture_zoom.eo.h"
95#include "gesture/efl_canvas_gesture_custom.eo.h" 96#include "gesture/efl_canvas_gesture_custom.eo.h"
96#include "gesture/efl_canvas_gesture_recognizer.eo.h" 97#include "gesture/efl_canvas_gesture_recognizer.eo.h"
@@ -100,6 +101,7 @@ struct _Efl_Canvas_Object_Animation_Event
100#include "gesture/efl_canvas_gesture_recognizer_triple_tap.eo.h" 101#include "gesture/efl_canvas_gesture_recognizer_triple_tap.eo.h"
101#include "gesture/efl_canvas_gesture_recognizer_momentum.eo.h" 102#include "gesture/efl_canvas_gesture_recognizer_momentum.eo.h"
102#include "gesture/efl_canvas_gesture_recognizer_flick.eo.h" 103#include "gesture/efl_canvas_gesture_recognizer_flick.eo.h"
104#include "gesture/efl_canvas_gesture_recognizer_rotate.eo.h"
103#include "gesture/efl_canvas_gesture_recognizer_zoom.eo.h" 105#include "gesture/efl_canvas_gesture_recognizer_zoom.eo.h"
104#include "gesture/efl_canvas_gesture_recognizer_custom.eo.h" 106#include "gesture/efl_canvas_gesture_recognizer_custom.eo.h"
105#include "gesture/efl_canvas_gesture_manager.eo.h" 107#include "gesture/efl_canvas_gesture_manager.eo.h"
diff --git a/src/lib/evas/gesture/efl_canvas_gesture_events.eo b/src/lib/evas/gesture/efl_canvas_gesture_events.eo
index 01c50a7aa8..6d95e68d4d 100644
--- a/src/lib/evas/gesture/efl_canvas_gesture_events.eo
+++ b/src/lib/evas/gesture/efl_canvas_gesture_events.eo
@@ -38,6 +38,11 @@ interface @beta Efl.Canvas.Gesture_Events
38 holding down a mouse button) with the release occurring before slowing down. 38 holding down a mouse button) with the release occurring before slowing down.
39 ]] 39 ]]
40 40
41 gesture,rotate: Efl.Canvas.Gesture_Rotate; [[Emitted when a Rotate gesture has been detected.
42 A Rotate gesture consists of two fingers touching the screen and performing a motion such that
43 one finger rotates around the other.
44 This gesture cannot be performed with a mouse as it requires more than one pointer.
45 ]]
41 gesture,zoom: Efl.Canvas.Gesture_Zoom; [[Emitted when a Zoom gesture has been detected. 46 gesture,zoom: Efl.Canvas.Gesture_Zoom; [[Emitted when a Zoom gesture has been detected.
42 A Zoom gesture consists of two fingers touching the screen and separating ("zoom in") or 47 A Zoom gesture consists of two fingers touching the screen and separating ("zoom in") or
43 getting closer ("zoom out" or "pinch"). 48 getting closer ("zoom out" or "pinch").
diff --git a/src/lib/evas/gesture/efl_canvas_gesture_manager.c b/src/lib/evas/gesture/efl_canvas_gesture_manager.c
index 5f86e4108c..e33e3f2cb0 100644
--- a/src/lib/evas/gesture/efl_canvas_gesture_manager.c
+++ b/src/lib/evas/gesture/efl_canvas_gesture_manager.c
@@ -53,6 +53,8 @@ _gesture_recognizer_event_type_get(const Efl_Canvas_Gesture_Recognizer *recogniz
53 return EFL_EVENT_GESTURE_MOMENTUM; 53 return EFL_EVENT_GESTURE_MOMENTUM;
54 if (type == EFL_CANVAS_GESTURE_FLICK_CLASS) 54 if (type == EFL_CANVAS_GESTURE_FLICK_CLASS)
55 return EFL_EVENT_GESTURE_FLICK; 55 return EFL_EVENT_GESTURE_FLICK;
56 if (type == EFL_CANVAS_GESTURE_ROTATE_CLASS)
57 return EFL_EVENT_GESTURE_ROTATE;
56 if (type == EFL_CANVAS_GESTURE_ZOOM_CLASS) 58 if (type == EFL_CANVAS_GESTURE_ZOOM_CLASS)
57 return EFL_EVENT_GESTURE_ZOOM; 59 return EFL_EVENT_GESTURE_ZOOM;
58 return EFL_EVENT_GESTURE_CUSTOM; 60 return EFL_EVENT_GESTURE_CUSTOM;
@@ -85,6 +87,7 @@ _update_finger_sizes(Efl_Canvas_Gesture_Manager_Data *pd, int finger_size)
85 Efl_Canvas_Gesture_Recognizer_Triple_Tap_Data *ttd; 87 Efl_Canvas_Gesture_Recognizer_Triple_Tap_Data *ttd;
86 Efl_Canvas_Gesture_Recognizer_Long_Press_Data *ltd; 88 Efl_Canvas_Gesture_Recognizer_Long_Press_Data *ltd;
87 Efl_Canvas_Gesture_Recognizer_Flick_Data *fd; 89 Efl_Canvas_Gesture_Recognizer_Flick_Data *fd;
90 Efl_Canvas_Gesture_Recognizer_Rotate_Data *rd;
88 Efl_Canvas_Gesture_Recognizer_Zoom_Data *zd; 91 Efl_Canvas_Gesture_Recognizer_Zoom_Data *zd;
89 const Efl_Event_Description *type; 92 const Efl_Event_Description *type;
90 93
@@ -113,6 +116,11 @@ _update_finger_sizes(Efl_Canvas_Gesture_Manager_Data *pd, int finger_size)
113 fd = efl_data_scope_get(r, EFL_CANVAS_GESTURE_RECOGNIZER_FLICK_CLASS); 116 fd = efl_data_scope_get(r, EFL_CANVAS_GESTURE_RECOGNIZER_FLICK_CLASS);
114 fd->finger_size = finger_size; 117 fd->finger_size = finger_size;
115 118
119 type = EFL_EVENT_GESTURE_ROTATE;
120 r = eina_hash_find(pd->m_recognizers, &type);
121 rd = efl_data_scope_get(r, EFL_CANVAS_GESTURE_RECOGNIZER_ROTATE_CLASS);
122 rd->finger_size = finger_size;
123
116 type = EFL_EVENT_GESTURE_ZOOM; 124 type = EFL_EVENT_GESTURE_ZOOM;
117 r = eina_hash_find(pd->m_recognizers, &type); 125 r = eina_hash_find(pd->m_recognizers, &type);
118 zd = efl_data_scope_get(r, EFL_CANVAS_GESTURE_RECOGNIZER_ZOOM_CLASS); 126 zd = efl_data_scope_get(r, EFL_CANVAS_GESTURE_RECOGNIZER_ZOOM_CLASS);
@@ -152,6 +160,7 @@ _efl_canvas_gesture_manager_efl_object_constructor(Eo *obj, Efl_Canvas_Gesture_M
152 efl_gesture_manager_recognizer_register(obj, efl_add(EFL_CANVAS_GESTURE_RECOGNIZER_TRIPLE_TAP_CLASS, obj)); 160 efl_gesture_manager_recognizer_register(obj, efl_add(EFL_CANVAS_GESTURE_RECOGNIZER_TRIPLE_TAP_CLASS, obj));
153 efl_gesture_manager_recognizer_register(obj, efl_add(EFL_CANVAS_GESTURE_RECOGNIZER_MOMENTUM_CLASS, obj)); 161 efl_gesture_manager_recognizer_register(obj, efl_add(EFL_CANVAS_GESTURE_RECOGNIZER_MOMENTUM_CLASS, obj));
154 efl_gesture_manager_recognizer_register(obj, efl_add(EFL_CANVAS_GESTURE_RECOGNIZER_FLICK_CLASS, obj)); 162 efl_gesture_manager_recognizer_register(obj, efl_add(EFL_CANVAS_GESTURE_RECOGNIZER_FLICK_CLASS, obj));
163 efl_gesture_manager_recognizer_register(obj, efl_add(EFL_CANVAS_GESTURE_RECOGNIZER_ROTATE_CLASS, obj));
155 efl_gesture_manager_recognizer_register(obj, efl_add(EFL_CANVAS_GESTURE_RECOGNIZER_ZOOM_CLASS, obj)); 164 efl_gesture_manager_recognizer_register(obj, efl_add(EFL_CANVAS_GESTURE_RECOGNIZER_ZOOM_CLASS, obj));
156 _update_finger_sizes(pd, EFL_GESTURE_RECOGNIZER_TYPE_TAP_FINGER_SIZE); 165 _update_finger_sizes(pd, EFL_GESTURE_RECOGNIZER_TYPE_TAP_FINGER_SIZE);
157 166
diff --git a/src/lib/evas/gesture/efl_canvas_gesture_private.h b/src/lib/evas/gesture/efl_canvas_gesture_private.h
index fe8de41d04..7b9b8550b0 100644
--- a/src/lib/evas/gesture/efl_canvas_gesture_private.h
+++ b/src/lib/evas/gesture/efl_canvas_gesture_private.h
@@ -26,12 +26,14 @@ typedef struct _Efl_Canvas_Gesture_Recognizer_Double_Tap_Data Efl_Canvas_Gestur
26typedef struct _Efl_Canvas_Gesture_Recognizer_Triple_Tap_Data Efl_Canvas_Gesture_Recognizer_Triple_Tap_Data; 26typedef struct _Efl_Canvas_Gesture_Recognizer_Triple_Tap_Data Efl_Canvas_Gesture_Recognizer_Triple_Tap_Data;
27typedef struct _Efl_Canvas_Gesture_Recognizer_Momentum_Data Efl_Canvas_Gesture_Recognizer_Momentum_Data; 27typedef struct _Efl_Canvas_Gesture_Recognizer_Momentum_Data Efl_Canvas_Gesture_Recognizer_Momentum_Data;
28typedef struct _Efl_Canvas_Gesture_Recognizer_Flick_Data Efl_Canvas_Gesture_Recognizer_Flick_Data; 28typedef struct _Efl_Canvas_Gesture_Recognizer_Flick_Data Efl_Canvas_Gesture_Recognizer_Flick_Data;
29typedef struct _Efl_Canvas_Gesture_Recognizer_Rotate_Data Efl_Canvas_Gesture_Recognizer_Rotate_Data;
29typedef struct _Efl_Canvas_Gesture_Recognizer_Zoom_Data Efl_Canvas_Gesture_Recognizer_Zoom_Data; 30typedef struct _Efl_Canvas_Gesture_Recognizer_Zoom_Data Efl_Canvas_Gesture_Recognizer_Zoom_Data;
30typedef struct _Efl_Canvas_Gesture_Recognizer_Custom_Data Efl_Canvas_Gesture_Recognizer_Custom_Data; 31typedef struct _Efl_Canvas_Gesture_Recognizer_Custom_Data Efl_Canvas_Gesture_Recognizer_Custom_Data;
31typedef struct _Efl_Canvas_Gesture_Data Efl_Canvas_Gesture_Data; 32typedef struct _Efl_Canvas_Gesture_Data Efl_Canvas_Gesture_Data;
32typedef struct _Efl_Canvas_Gesture_Momentum_Data Efl_Canvas_Gesture_Momentum_Data; 33typedef struct _Efl_Canvas_Gesture_Momentum_Data Efl_Canvas_Gesture_Momentum_Data;
33typedef struct _Efl_Canvas_Gesture_Flick_Data Efl_Canvas_Gesture_Flick_Data; 34typedef struct _Efl_Canvas_Gesture_Flick_Data Efl_Canvas_Gesture_Flick_Data;
34typedef struct _Efl_Canvas_Gesture_Zoom_Data Efl_Canvas_Gesture_Zoom_Data; 35typedef struct _Efl_Canvas_Gesture_Zoom_Data Efl_Canvas_Gesture_Zoom_Data;
36typedef struct _Efl_Canvas_Gesture_Rotate_Data Efl_Canvas_Gesture_Rotate_Data;
35typedef struct _Efl_Canvas_Gesture_Custom_Data Efl_Canvas_Gesture_Custom_Data; 37typedef struct _Efl_Canvas_Gesture_Custom_Data Efl_Canvas_Gesture_Custom_Data;
36 38
37typedef struct _Efl_Canvas_Gesture_Touch_Data 39typedef struct _Efl_Canvas_Gesture_Touch_Data
@@ -114,6 +116,24 @@ struct _Efl_Canvas_Gesture_Recognizer_Flick_Data
114 Eina_Bool touched; 116 Eina_Bool touched;
115}; 117};
116 118
119struct _Efl_Canvas_Gesture_Recognizer_Rotate_Data
120{
121 Efl_Gesture_Touch_Point_Data rotate_st;
122 Efl_Gesture_Touch_Point_Data rotate_st1;
123
124 Efl_Gesture_Touch_Point_Data rotate_mv;
125 Efl_Gesture_Touch_Point_Data rotate_mv1;
126 double rotate_step;
127 double base_angle; /**< Holds start-angle */
128 double prev_momentum; /* Snapshot of momentum 0.01
129 * sec ago */
130 double accum_momentum;
131 double rotate_angular_tolerance;
132 double next_step;
133 unsigned int prev_momentum_tm; /* timestamp of prev_momentum */
134 int finger_size;
135};
136
117struct _Efl_Canvas_Gesture_Recognizer_Zoom_Data 137struct _Efl_Canvas_Gesture_Recognizer_Zoom_Data
118{ 138{
119 Efl_Gesture_Touch_Point_Data zoom_st; 139 Efl_Gesture_Touch_Point_Data zoom_st;
@@ -159,6 +179,14 @@ struct _Efl_Canvas_Gesture_Flick_Data
159 int id; 179 int id;
160}; 180};
161 181
182struct _Efl_Canvas_Gesture_Rotate_Data
183{
184 //Evas_Coord x, y; /**< Holds rotate center point reported to user */
185 double angle; /**< Rotation value: 0.0 means no rotation */
186 double momentum; /**< Rotation momentum: rotation done per second (NOT YET SUPPORTED) */
187 Evas_Coord radius; /**< Holds radius between fingers reported to user */
188};
189
162struct _Efl_Canvas_Gesture_Zoom_Data 190struct _Efl_Canvas_Gesture_Zoom_Data
163{ 191{
164 double radius; 192 double radius;
diff --git a/src/lib/evas/gesture/efl_canvas_gesture_recognizer_rotate.c b/src/lib/evas/gesture/efl_canvas_gesture_recognizer_rotate.c
new file mode 100644
index 0000000000..97fa907767
--- /dev/null
+++ b/src/lib/evas/gesture/efl_canvas_gesture_recognizer_rotate.c
@@ -0,0 +1,269 @@
1#include "efl_canvas_gesture_private.h"
2
3#define NEGATIVE_ANGLE (-1.0) /* Magic number */
4
5#define MY_CLASS EFL_CANVAS_GESTURE_RECOGNIZER_ROTATE_CLASS
6
7static void
8_reset_recognizer(Efl_Canvas_Gesture_Recognizer_Rotate_Data *pd)
9{
10 memset(&pd->rotate_st, 0, sizeof(Efl_Gesture_Touch_Point_Data));
11 memset(&pd->rotate_st1, 0, sizeof(Efl_Gesture_Touch_Point_Data));
12 memset(&pd->rotate_mv, 0, sizeof(Efl_Gesture_Touch_Point_Data));
13 memset(&pd->rotate_mv1, 0, sizeof(Efl_Gesture_Touch_Point_Data));
14 pd->prev_momentum = 0;
15 pd->base_angle = 0;
16 pd->next_step = pd->accum_momentum = 0;
17}
18
19#define memset do not use memset to reset rotate data, use _reset_recognizer
20
21
22static void
23_rotate_properties_get(Efl_Canvas_Gesture_Recognizer_Rotate_Data *pd,
24 Efl_Canvas_Gesture_Rotate_Data *gd,
25 Evas_Coord xx1,
26 Evas_Coord yy1,
27 Evas_Coord xx2,
28 Evas_Coord yy2,
29 double *angle, Eina_Bool started)
30{
31 /* FIXME: Fix momentum computation, it's wrong */
32 double prev_angle = *angle;
33 int x, y;
34 gd->radius = _finger_gap_length_get(xx1, yy1, xx2, yy2, &x, &y) / 2;
35
36 *angle = _angle_get(xx1, yy1, xx2, yy2);
37
38 if (!started) /* Fingers are moving, compute momentum */
39 {
40 unsigned int tm_start =
41 (pd->rotate_st.cur.timestamp > pd->rotate_st1.cur.timestamp)
42 ? pd->rotate_st.cur.timestamp : pd->rotate_st1.cur.timestamp;
43 unsigned int tm_end =
44 (pd->rotate_mv.cur.timestamp > pd->rotate_mv1.cur.timestamp)
45 ? pd->rotate_mv.cur.timestamp : pd->rotate_mv1.cur.timestamp;
46
47 unsigned int tm_total = tm_end - tm_start;
48 if (tm_total) /* Momentum computed as:
49 accumulated rotation angle (deg) divided by time */
50 {
51 double m = 0;
52 if (((prev_angle < 90) && ((*angle) > 270)) ||
53 /* We circle passing ZERO point */
54 ((prev_angle > 270) && ((*angle) < 90)))
55 {
56 prev_angle = (*angle);
57 }
58 else m = prev_angle - (*angle);
59
60 pd->accum_momentum += m;
61
62 if ((tm_end - pd->prev_momentum_tm) < 100)
63 pd->prev_momentum += m;
64 else
65 {
66 if (fabs(pd->prev_momentum) < 0.002)
67 pd->accum_momentum = 0.0; /* reset momentum */
68
69 pd->prev_momentum = 0.0; /* Start again */
70 }
71
72 pd->prev_momentum_tm = tm_end;
73 gd->momentum = (pd->accum_momentum * 1000) / tm_total;
74 }
75 }
76 else
77 gd->momentum = 0;
78}
79
80static Eina_Bool
81_on_rotation_broke_tolerance(Efl_Canvas_Gesture_Recognizer_Rotate_Data *pd, Efl_Canvas_Gesture_Rotate_Data *gd)
82{
83 if (pd->base_angle < 0)
84 return EINA_FALSE; /* Angle has to be computed first */
85
86 if (pd->rotate_angular_tolerance < 0)
87 return EINA_TRUE;
88
89 double low = pd->base_angle - pd->rotate_angular_tolerance;
90 double high = pd->base_angle + pd->rotate_angular_tolerance;
91 double t = gd->angle;
92
93 if (low < 0)
94 {
95 low += 180;
96 high += 180;
97
98 if (t < 180)
99 t += 180;
100 else
101 t -= 180;
102 }
103
104 if (high > 360)
105 {
106 low -= 180;
107 high -= 180;
108
109 if (t < 180)
110 t += 180;
111 else
112 t -= 180;
113 }
114
115 if ((t < low) || (t > high)) /* This marks that rotation action has
116 * started */
117 {
118 pd->rotate_angular_tolerance = NEGATIVE_ANGLE;
119 pd->base_angle = gd->angle; /* Avoid jump in angle value */
120 return EINA_TRUE;
121 }
122
123 return EINA_FALSE;
124}
125
126EOLIAN static const Efl_Class *
127_efl_canvas_gesture_recognizer_rotate_efl_canvas_gesture_recognizer_type_get(const Eo *obj EINA_UNUSED, Efl_Canvas_Gesture_Recognizer_Rotate_Data *pd EINA_UNUSED)
128{
129 return EFL_CANVAS_GESTURE_ROTATE_CLASS;
130}
131
132EOLIAN static Efl_Canvas_Gesture_Recognizer_Result
133_efl_canvas_gesture_recognizer_rotate_efl_canvas_gesture_recognizer_recognize(Eo *obj,
134 Efl_Canvas_Gesture_Recognizer_Rotate_Data *pd,
135 Efl_Canvas_Gesture *gesture,
136 Efl_Object *watched,
137 Efl_Canvas_Gesture_Touch *event)
138{
139 Eina_Value *val;
140 unsigned char glayer_continues_enable;
141 Efl_Canvas_Gesture_Recognizer_Result result = EFL_GESTURE_RECOGNIZER_RESULT_CANCEL;
142 Efl_Canvas_Gesture_Rotate_Data *gd = efl_data_scope_get(gesture, EFL_CANVAS_GESTURE_ROTATE_CLASS);
143 Efl_Canvas_Gesture_Touch_Data *td = efl_data_scope_get(event, EFL_CANVAS_GESTURE_TOUCH_CLASS);
144 Efl_Canvas_Gesture_Recognizer_Data *rd = efl_data_scope_get(obj, EFL_CANVAS_GESTURE_RECOGNIZER_CLASS);
145 const Efl_Gesture_Touch_Point_Data *p1 = efl_gesture_touch_data_get(event, 0);
146 const Efl_Gesture_Touch_Point_Data *p2 = efl_gesture_touch_data_get(event, 1);
147
148 //FIXME: Wheel rotate test first here.
149
150 val = _recognizer_config_get(obj, "glayer_continues_enable");
151 if (val) eina_value_get(val, &glayer_continues_enable);
152 else glayer_continues_enable = 1;
153
154 rd->continues = EINA_TRUE;
155
156 switch (efl_gesture_touch_state_get(event))
157 {
158 case EFL_GESTURE_TOUCH_STATE_UPDATE:
159 {
160 if ((!glayer_continues_enable) && (!pd->rotate_st.cur.timestamp))
161 {
162 return EFL_GESTURE_RECOGNIZER_RESULT_IGNORE;
163 }
164 EINA_FALLTHROUGH;
165 }
166
167 case EFL_GESTURE_TOUCH_STATE_BEGIN:
168 {
169 if (td->touch_down > 2)
170 {
171 _reset_recognizer(pd);
172 if (efl_gesture_state_get(gesture) == EFL_GESTURE_STATE_CANCELED)
173 return EFL_GESTURE_RECOGNIZER_RESULT_IGNORE;
174 return EFL_GESTURE_RECOGNIZER_RESULT_CANCEL;
175 }
176 if (td->touch_down == 1)
177 {
178 return EFL_GESTURE_RECOGNIZER_RESULT_MAYBE;
179 }
180
181 if (!pd->rotate_st.cur.timestamp) /* Now scan touched-devices list
182 * and find other finger */
183 {
184 if (!_event_multi_touch_get(event))
185 return EFL_GESTURE_RECOGNIZER_RESULT_IGNORE;
186 pd->base_angle = NEGATIVE_ANGLE;
187 val = _recognizer_config_get(obj, "glayer_rotate_angular_tolerance");
188 if (val) eina_value_get(val, &pd->rotate_angular_tolerance);
189 else pd->rotate_angular_tolerance = 2.0;
190
191 memcpy(&pd->rotate_st, p2, sizeof(Efl_Gesture_Touch_Point_Data));
192 memcpy(&pd->rotate_st1, p1, sizeof(Efl_Gesture_Touch_Point_Data));
193
194 memcpy(&pd->rotate_mv, p2, sizeof(Efl_Gesture_Touch_Point_Data));
195 memcpy(&pd->rotate_mv1, p1, sizeof(Efl_Gesture_Touch_Point_Data));
196
197 _rotate_properties_get(pd, gd,
198 pd->rotate_st.cur.pos.x, pd->rotate_st.cur.pos.y,
199 pd->rotate_st1.cur.pos.x, pd->rotate_st1.cur.pos.y,
200 &pd->base_angle, EINA_TRUE);
201 if ((efl_gesture_state_get(gesture) != EFL_GESTURE_STATE_STARTED) &&
202 (efl_gesture_state_get(gesture) != EFL_GESTURE_STATE_UPDATED))
203 return EFL_GESTURE_RECOGNIZER_RESULT_TRIGGER;
204
205 return EFL_GESTURE_RECOGNIZER_RESULT_CANCEL;
206 }
207
208 if (p2->id == pd->rotate_mv.id)
209 memcpy(&pd->rotate_mv, p2, sizeof(Efl_Gesture_Touch_Point_Data));
210 else if (p2->id == pd->rotate_mv1.id)
211 memcpy(&pd->rotate_mv1, p2, sizeof(Efl_Gesture_Touch_Point_Data));
212
213 _rotate_properties_get(pd, gd,
214 pd->rotate_mv.cur.pos.x, pd->rotate_mv.cur.pos.y,
215 pd->rotate_mv1.cur.pos.x, pd->rotate_mv1.cur.pos.y,
216 &gd->angle, EINA_FALSE);
217
218 if (_on_rotation_broke_tolerance(pd, gd)) /* Rotation broke
219 * tolerance, report
220 * move */
221 {
222 double d = gd->angle - pd->next_step;
223
224 if (d < 0.0) d = (-d);
225
226 if (d >= pd->rotate_step)
227 {
228 pd->next_step = gd->angle;
229
230 return EFL_GESTURE_RECOGNIZER_RESULT_TRIGGER;
231 }
232 }
233
234 return EFL_GESTURE_RECOGNIZER_RESULT_IGNORE;
235 }
236
237 case EFL_GESTURE_TOUCH_STATE_END:
238 {
239 /* no gesture was started, so no gesture should be detected */
240 if ((td->touch_down == 0) || (!pd->rotate_st.cur.timestamp))
241 {
242 rd->continues = EINA_FALSE;
243
244 _reset_recognizer(pd);
245 efl_gesture_manager_recognizer_cleanup(efl_provider_find(obj, EFL_CANVAS_GESTURE_MANAGER_CLASS), obj, watched);
246
247 return EFL_GESTURE_RECOGNIZER_RESULT_IGNORE;
248 }
249 _reset_recognizer(pd);
250 if (pd->rotate_angular_tolerance < 0)
251 {
252 return EFL_GESTURE_RECOGNIZER_RESULT_FINISH;
253 }
254
255 if (efl_gesture_state_get(gesture) != EFL_GESTURE_STATE_NONE)
256 {
257 return EFL_GESTURE_RECOGNIZER_RESULT_CANCEL;
258 }
259 }
260
261 default:
262
263 break;
264 }
265
266 return result;
267}
268
269#include "efl_canvas_gesture_recognizer_rotate.eo.c"
diff --git a/src/lib/evas/gesture/efl_canvas_gesture_recognizer_rotate.eo b/src/lib/evas/gesture/efl_canvas_gesture_recognizer_rotate.eo
new file mode 100644
index 0000000000..28291b3083
--- /dev/null
+++ b/src/lib/evas/gesture/efl_canvas_gesture_recognizer_rotate.eo
@@ -0,0 +1,12 @@
1class @beta Efl.Canvas.Gesture_Recognizer_Rotate extends Efl.Canvas.Gesture_Recognizer
2{
3 [[This is the recognizer for Rotate gestures.
4 See @Efl.Canvas.Gesture_Rotate and @Efl.Canvas.Gesture_Recognizer.
5 For internal use only.
6 ]]
7 c_prefix: efl_gesture_recognizer_rotate;
8 implements {
9 Efl.Canvas.Gesture_Recognizer.type { get; }
10 Efl.Canvas.Gesture_Recognizer.recognize;
11 }
12}
diff --git a/src/lib/evas/gesture/efl_canvas_gesture_rotate.c b/src/lib/evas/gesture/efl_canvas_gesture_rotate.c
new file mode 100644
index 0000000000..77351236f8
--- /dev/null
+++ b/src/lib/evas/gesture/efl_canvas_gesture_rotate.c
@@ -0,0 +1,17 @@
1#include "efl_canvas_gesture_private.h"
2
3#define MY_CLASS EFL_CANVAS_GESTURE_ROTATE_CLASS
4
5EOLIAN static unsigned int
6_efl_canvas_gesture_rotate_radius_get(const Eo *obj EINA_UNUSED, Efl_Canvas_Gesture_Rotate_Data *pd)
7{
8 return pd->radius;
9}
10
11EOLIAN static double
12_efl_canvas_gesture_rotate_angle_get(const Eo *obj EINA_UNUSED, Efl_Canvas_Gesture_Rotate_Data *pd)
13{
14 return pd->angle;
15}
16
17#include "efl_canvas_gesture_rotate.eo.c"
diff --git a/src/lib/evas/gesture/efl_canvas_gesture_rotate.eo b/src/lib/evas/gesture/efl_canvas_gesture_rotate.eo
new file mode 100644
index 0000000000..8cd35f8661
--- /dev/null
+++ b/src/lib/evas/gesture/efl_canvas_gesture_rotate.eo
@@ -0,0 +1,28 @@
1class @beta Efl.Canvas.Gesture_Rotate extends Efl.Canvas.Gesture
2{
3 [[Rotate gesture class holding state information.
4 See @Efl.Canvas.Gesture to see what this state is and
5 @[Efl.Canvas.Gesture_Events.gesture,rotate] for a description of the Rotate gesture.
6
7 Application developers receive these objects inside a gesture event and do not typically need to create their own.
8 ]]
9 c_prefix: efl_gesture_rotate;
10 methods {
11 @property radius {
12 [[The current radius (i.e. the distance between the two fingers) of the gesture.]]
13 get {
14 }
15 values {
16 radius: uint; [[The radius value in pixels.]]
17 }
18 }
19 @property angle {
20 [[The current angle of rotation for this gesture.]]
21 get {
22 }
23 values {
24 rotate: double; [[The angle of the rotation. $[0.0] means no rotation has occurred.]]
25 }
26 }
27 }
28}
diff --git a/src/lib/evas/gesture/meson.build b/src/lib/evas/gesture/meson.build
index 7c2fc28a31..d57cdd0e94 100644
--- a/src/lib/evas/gesture/meson.build
+++ b/src/lib/evas/gesture/meson.build
@@ -7,6 +7,7 @@ pub_eo_files = [
7 'efl_canvas_gesture_long_press.eo', 7 'efl_canvas_gesture_long_press.eo',
8 'efl_canvas_gesture_momentum.eo', 8 'efl_canvas_gesture_momentum.eo',
9 'efl_canvas_gesture_flick.eo', 9 'efl_canvas_gesture_flick.eo',
10 'efl_canvas_gesture_rotate.eo',
10 'efl_canvas_gesture_zoom.eo', 11 'efl_canvas_gesture_zoom.eo',
11 'efl_canvas_gesture_custom.eo', 12 'efl_canvas_gesture_custom.eo',
12 'efl_canvas_gesture_recognizer.eo', 13 'efl_canvas_gesture_recognizer.eo',
@@ -16,6 +17,7 @@ pub_eo_files = [
16 'efl_canvas_gesture_recognizer_long_press.eo', 17 'efl_canvas_gesture_recognizer_long_press.eo',
17 'efl_canvas_gesture_recognizer_momentum.eo', 18 'efl_canvas_gesture_recognizer_momentum.eo',
18 'efl_canvas_gesture_recognizer_flick.eo', 19 'efl_canvas_gesture_recognizer_flick.eo',
20 'efl_canvas_gesture_recognizer_rotate.eo',
19 'efl_canvas_gesture_recognizer_zoom.eo', 21 'efl_canvas_gesture_recognizer_zoom.eo',
20 'efl_canvas_gesture_recognizer_custom.eo', 22 'efl_canvas_gesture_recognizer_custom.eo',
21 'efl_canvas_gesture_manager.eo', 23 'efl_canvas_gesture_manager.eo',
@@ -71,6 +73,7 @@ evas_src += files([
71 'efl_canvas_gesture_long_press.c', 73 'efl_canvas_gesture_long_press.c',
72 'efl_canvas_gesture_momentum.c', 74 'efl_canvas_gesture_momentum.c',
73 'efl_canvas_gesture_flick.c', 75 'efl_canvas_gesture_flick.c',
76 'efl_canvas_gesture_rotate.c',
74 'efl_canvas_gesture_zoom.c', 77 'efl_canvas_gesture_zoom.c',
75 'efl_canvas_gesture_custom.c', 78 'efl_canvas_gesture_custom.c',
76 'efl_canvas_gesture_recognizer.c', 79 'efl_canvas_gesture_recognizer.c',
@@ -80,6 +83,7 @@ evas_src += files([
80 'efl_canvas_gesture_recognizer_long_press.c', 83 'efl_canvas_gesture_recognizer_long_press.c',
81 'efl_canvas_gesture_recognizer_momentum.c', 84 'efl_canvas_gesture_recognizer_momentum.c',
82 'efl_canvas_gesture_recognizer_flick.c', 85 'efl_canvas_gesture_recognizer_flick.c',
86 'efl_canvas_gesture_recognizer_rotate.c',
83 'efl_canvas_gesture_recognizer_zoom.c', 87 'efl_canvas_gesture_recognizer_zoom.c',
84 'efl_canvas_gesture_recognizer_custom.c', 88 'efl_canvas_gesture_recognizer_custom.c',
85 'efl_canvas_gesture_manager.c', 89 'efl_canvas_gesture_manager.c',