1 #define EFL_CANVAS_GESTURE_RECOGNIZER_PROTECTED
2 #include "efl_canvas_gesture_private.h"
3 #define RAD2DEG(x) ((x) * 57.295779513)
4 
5 #define MY_CLASS                                    EFL_CANVAS_GESTURE_RECOGNIZER_CLASS
6 #include "efl_canvas_gesture_recognizer.eo.h"
7 
8 Eina_Value *
_recognizer_config_get(const Eo * obj,const char * name)9 _recognizer_config_get(const Eo *obj, const char *name)
10 {
11    Eo *config = efl_provider_find(obj, EFL_CONFIG_INTERFACE);
12    EINA_SAFETY_ON_NULL_RETURN_VAL(config, NULL);
13    return efl_config_get(config, name);
14 }
15 
16 EOLIAN static Eina_Bool
_efl_canvas_gesture_recognizer_continues_get(const Eo * obj EINA_UNUSED,Efl_Canvas_Gesture_Recognizer_Data * pd)17 _efl_canvas_gesture_recognizer_continues_get(const Eo *obj EINA_UNUSED, Efl_Canvas_Gesture_Recognizer_Data *pd)
18 {
19    return pd->continues;
20 }
21 
22 EOLIAN static void
_efl_canvas_gesture_recognizer_continues_set(Eo * obj EINA_UNUSED,Efl_Canvas_Gesture_Recognizer_Data * pd,Eina_Bool value)23 _efl_canvas_gesture_recognizer_continues_set(Eo *obj EINA_UNUSED, Efl_Canvas_Gesture_Recognizer_Data *pd, Eina_Bool value)
24 {
25    pd->continues = !!value;
26 }
27 
28 int
_direction_get(Evas_Coord xx1,Evas_Coord xx2)29 _direction_get(Evas_Coord xx1, Evas_Coord xx2)
30 {
31    if (xx2 < xx1) return -1;
32    if (xx2 > xx1) return 1;
33 
34    return 0;
35 }
36 
37 Eina_Bool
_event_multi_touch_get(const Efl_Canvas_Gesture_Touch * event)38 _event_multi_touch_get(const Efl_Canvas_Gesture_Touch *event)
39 {
40    return efl_gesture_touch_points_count_get(event) > 1;
41 }
42 
43 
44 double
_angle_get(Evas_Coord xx1,Evas_Coord yy1,Evas_Coord xx2,Evas_Coord yy2)45 _angle_get(Evas_Coord xx1, Evas_Coord yy1, Evas_Coord xx2, Evas_Coord yy2)
46 {
47    double a, xx, yy, rt = (-1);
48 
49    xx = abs(xx2 - xx1);
50    yy = abs(yy2 - yy1);
51 
52    if (((int)xx) && ((int)yy))
53      {
54         rt = a = RAD2DEG(atan(yy / xx));
55         if (xx1 < xx2)
56           {
57              if (yy1 < yy2) rt = 360 - a;
58              else rt = a;
59           }
60         else
61           {
62              if (yy1 < yy2) rt = 180 + a;
63              else rt = 180 - a;
64           }
65      }
66 
67    if (rt < 0) /* Do this only if rt is not set */
68      {
69         if (((int)xx)) /* Horizontal line */
70           {
71              if (xx2 < xx1) rt = 180;
72              else rt = 0.0;
73           }
74         else /* Vertical line */
75           {
76              if (yy2 < yy1) rt = 90;
77              else rt = 270;
78           }
79      }
80 
81    /* Now we want to change from:
82     *                      90                   0
83     * original circle   180   0   We want:  270   90
84     *                     270                 180
85     */
86    rt = 450 - rt;
87    if (rt >= 360) rt -= 360;
88 
89    return rt;
90 }
91 
92 Evas_Coord
_finger_gap_length_get(Evas_Coord xx1,Evas_Coord yy1,Evas_Coord xx2,Evas_Coord yy2,Evas_Coord * x,Evas_Coord * y)93 _finger_gap_length_get(Evas_Coord xx1,
94                        Evas_Coord yy1,
95                        Evas_Coord xx2,
96                        Evas_Coord yy2,
97                        Evas_Coord *x,
98                        Evas_Coord *y)
99 {
100    double a, b, xx, yy, gap;
101    xx = abs(xx2 - xx1);
102    yy = abs(yy2 - yy1);
103    gap = sqrt((xx * xx) + (yy * yy));
104 
105    /* START - Compute zoom center point */
106    /* The triangle defined as follows:
107     *             B
108     *           / |
109     *          /  |
110     *     gap /   | a
111     *        /    |
112     *       A-----C
113     *          b
114     * http://en.wikipedia.org/wiki/Trigonometric_functions
115     *************************************/
116    if (((int)xx) && ((int)yy))
117      {
118         double A = atan((yy / xx));
119         a = (Evas_Coord)((gap / 2) * sin(A));
120         b = (Evas_Coord)((gap / 2) * cos(A));
121         *x = (Evas_Coord)((xx2 > xx1) ? (xx1 + b) : (xx2 + b));
122         *y = (Evas_Coord)((yy2 > yy1) ? (yy1 + a) : (yy2 + a));
123      }
124    else
125      {
126         if ((int)xx) /* horiz line, take half width */
127           {
128              *x = (Evas_Coord)((xx1 + xx2) / 2);
129              *y = (Evas_Coord)(yy1);
130           }
131 
132         if ((int)yy) /* vert line, take half width */
133           {
134              *x = (Evas_Coord)(xx1);
135              *y = (Evas_Coord)((yy1 + yy2) / 2);
136           }
137      }
138    /* END   - Compute zoom center point */
139 
140    return (Evas_Coord)gap;
141 }
142 
143 #include "efl_canvas_gesture_recognizer.eo.c"
144