summaryrefslogtreecommitdiff
path: root/src/lib/evas/gesture/efl_canvas_gesture_recognizer_double_tap.c
blob: 1656bb633feb0603a029a25f540ac539fca574bf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
#include "efl_canvas_gesture_private.h"

#define MY_CLASS EFL_CANVAS_GESTURE_RECOGNIZER_DOUBLE_TAP_CLASS

#define TAP_TIME_OUT 0.33

EOLIAN static Efl_Canvas_Gesture *
_efl_canvas_gesture_recognizer_double_tap_efl_canvas_gesture_recognizer_add(Eo *obj, Efl_Canvas_Gesture_Recognizer_Double_Tap_Data *pd EINA_UNUSED, Efl_Object *target EINA_UNUSED)
{
   return efl_add(EFL_CANVAS_GESTURE_DOUBLE_TAP_CLASS, obj);
}

EOLIAN static void
_efl_canvas_gesture_recognizer_double_tap_efl_object_destructor(Eo *obj,
                                                                Efl_Canvas_Gesture_Recognizer_Double_Tap_Data *pd)
{
   if (pd->timeout)
     ecore_timer_del(pd->timeout);

   efl_destructor(efl_super(obj, MY_CLASS));
}

static Eina_Bool
_tap_timeout_cb(void *data)
{
   Efl_Canvas_Gesture_Recognizer_Data *rd;
   Efl_Canvas_Gesture_Recognizer_Double_Tap_Data *pd;

   rd = efl_data_scope_get(data, EFL_CANVAS_GESTURE_RECOGNIZER_CLASS);
   pd = efl_data_scope_get(data, EFL_CANVAS_GESTURE_RECOGNIZER_DOUBLE_TAP_CLASS);

   efl_gesture_state_set(pd->gesture, EFL_GESTURE_CANCELED);
   efl_event_callback_call(pd->target, EFL_EVENT_GESTURE_DOUBLE_TAP, pd->gesture);

   efl_gesture_manager_gesture_clean_up(rd->manager, pd->target, EFL_EVENT_GESTURE_DOUBLE_TAP);

   pd->timeout = NULL;
   pd->tap_count = 0;

   return ECORE_CALLBACK_CANCEL;
}

EOLIAN static Efl_Canvas_Gesture_Recognizer_Result
_efl_canvas_gesture_recognizer_double_tap_efl_canvas_gesture_recognizer_recognize(Eo *obj,
                                                                                  Efl_Canvas_Gesture_Recognizer_Double_Tap_Data *pd,
                                                                                  Efl_Canvas_Gesture *gesture, Efl_Object *watched,
                                                                                  Efl_Canvas_Gesture_Touch *event)
{
   double length;
   double timeout = TAP_TIME_OUT;
   Eina_Position2D pos;
   Eina_Vector2 dist;
   Efl_Canvas_Gesture_Recognizer_Result result = EFL_GESTURE_CANCEL;
   Efl_Canvas_Gesture_Recognizer_Data *rd = efl_data_scope_get(obj, EFL_CANVAS_GESTURE_RECOGNIZER_CLASS);

   pd->target = watched;
   pd->gesture = gesture;

   if (!pd->start_timeout)
     {
        double time;
        Eina_Value *val =  efl_gesture_recognizer_config_get(obj, "glayer_doublee_tap_timeout");

        if (val)
          {
             eina_value_get(val, &time);
             pd->start_timeout = timeout = time;
          }
     }
   else
     timeout = pd->start_timeout;

   switch (efl_gesture_touch_state_get(event))
     {
      case EFL_GESTURE_TOUCH_BEGIN:
           {
              pos = efl_gesture_touch_start_point_get(event);
              efl_gesture_hotspot_set(gesture, pos);

              if (pd->timeout)
                ecore_timer_reset(pd->timeout);
              else
                pd->timeout = ecore_timer_add(timeout, _tap_timeout_cb, obj);

              result = EFL_GESTURE_TRIGGER;

              break;
           }

      case EFL_GESTURE_TOUCH_UPDATE:
           {
              result = EFL_GESTURE_IGNORE;

              if (efl_gesture_state_get(gesture) != EFL_GESTURE_NONE &&
                  !efl_gesture_touch_multi_touch_get(event))
                {
                   dist = efl_gesture_touch_distance(event, 0);
                   length = fabs(dist.x) + fabs(dist.y);

                   if (length > rd->finger_size)
                     {
                        if (pd->timeout)
                          {
                             ecore_timer_del(pd->timeout);
                             pd->timeout = NULL;
                          }

                        result = EFL_GESTURE_CANCEL;

                        pd->tap_count = 0;
                     }
                }

              break;
           }
      case EFL_GESTURE_TOUCH_END:
           {

              if (efl_gesture_state_get(gesture) != EFL_GESTURE_NONE &&
                  !efl_gesture_touch_multi_touch_get(event))
                {
                   dist = efl_gesture_touch_distance(event, 0);
                   length = fabs(dist.x) + fabs(dist.y);

                   if (length <= rd->finger_size)
                     {
                        pd->tap_count++;
                        if (pd->tap_count == 1)
                          {
                             if (pd->timeout)
                               ecore_timer_reset(pd->timeout);

                             result = EFL_GESTURE_TRIGGER;
                          }
                        else
                          {
                             if (pd->timeout)
                               {
                                  ecore_timer_del(pd->timeout);
                                  pd->timeout = NULL;
                               }

                             if (efl_gesture_touch_state_get(event) == EFL_GESTURE_TOUCH_END)
                               result = EFL_GESTURE_FINISH;
                             else
                               result = EFL_GESTURE_TRIGGER;

                             pd->tap_count = 0;
                          }
                     }
                   else
                     {
                        if (pd->timeout)
                          {
                             ecore_timer_del(pd->timeout);
                             pd->timeout = NULL;
                          }

                        result = EFL_GESTURE_CANCEL;

                        pd->tap_count = 0;
                     }
                }

              break;
           }

      default:

        break;
     }

   return result;
}

EOLIAN static double
_efl_canvas_gesture_recognizer_double_tap_timeout_get(const Eo *obj EINA_UNUSED,
                                                      Efl_Canvas_Gesture_Recognizer_Double_Tap_Data *pd)
{
   return pd->start_timeout;
}

EOLIAN static void
_efl_canvas_gesture_recognizer_double_tap_timeout_set(Eo *obj EINA_UNUSED,
                                                      Efl_Canvas_Gesture_Recognizer_Double_Tap_Data *pd,
                                                      double time)
{
   pd->start_timeout = time;
}

#include "efl_canvas_gesture_recognizer_double_tap.eo.c"