summaryrefslogtreecommitdiff
path: root/src/lib/evas/gesture/efl_canvas_gesture_recognizer_long_tap.c
blob: 8f6773588b66e1babf48c7dafe3870503529e2da (plain) (blame)
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
#include "efl_canvas_gesture_private.h"

#define MY_CLASS EFL_CANVAS_GESTURE_RECOGNIZER_LONG_TAP_CLASS

#define EFL_GESTURE_LONG_TAP_TIME_OUT 1.2

EOLIAN static Efl_Canvas_Gesture *
_efl_canvas_gesture_recognizer_long_tap_efl_canvas_gesture_recognizer_add(Eo *obj,
                                                                          Efl_Canvas_Gesture_Recognizer_Long_Tap_Data *pd EINA_UNUSED,
                                                                          Efl_Object *target EINA_UNUSED)
{
   return efl_add(EFL_CANVAS_GESTURE_LONG_TAP_CLASS, obj);
}

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

   efl_destructor(efl_super(obj, MY_CLASS));
}

static Eina_Bool
_long_tap_timeout_cb(void *data)
{
   Efl_Canvas_Gesture_Recognizer_Long_Tap_Data *pd = data;

   /* FIXME: Needs to propagate this event back to evas! */
   pd->is_timeout = EINA_TRUE;

   efl_gesture_state_set(pd->gesture, EFL_GESTURE_UPDATED);
   efl_event_callback_call(pd->target, EFL_EVENT_GESTURE_LONG_TAP, pd->gesture);

   return ECORE_CALLBACK_RENEW;
}

EOLIAN static Efl_Canvas_Gesture_Recognizer_Result
_efl_canvas_gesture_recognizer_long_tap_efl_canvas_gesture_recognizer_recognize(Eo *obj,
                                                                                Efl_Canvas_Gesture_Recognizer_Long_Tap_Data *pd,
                                                                                Efl_Canvas_Gesture *gesture,
                                                                                Efl_Object *watched,
                                                                                Efl_Canvas_Gesture_Touch *event)
{
   double length; // Manhattan distance
   double timeout = EFL_GESTURE_LONG_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_long_tap_start_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_del(pd->timeout);
             }
           pd->timeout = ecore_timer_add(timeout,
                                         _long_tap_timeout_cb, pd);

           result = EFL_GESTURE_TRIGGER;

           break;
        }

      case EFL_GESTURE_TOUCH_UPDATE:
        {
           dist = efl_gesture_touch_distance(event, 0);
           length = fabs(dist.x) + fabs(dist.y);

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

                result = EFL_GESTURE_CANCEL;
             }
           else
             {
                result = EFL_GESTURE_MAYBE;
             }

           break;
        }

      case EFL_GESTURE_TOUCH_END:
        {
           if (pd->timeout)
             {
                ecore_timer_del(pd->timeout);
                pd->timeout = NULL;
             }

           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->is_timeout)
                  {
                     result = EFL_GESTURE_FINISH;
                  }
                else
                  {
                     result = EFL_GESTURE_CANCEL;
                  }
             }

           break;
        }

      default:

        break;
     }

   return result;
}

EOLIAN static void
_efl_canvas_gesture_recognizer_long_tap_efl_canvas_gesture_recognizer_reset(Eo *obj,
                                                                            Efl_Canvas_Gesture_Recognizer_Long_Tap_Data *pd,
                                                                            Efl_Canvas_Gesture *gesture)
{
   if (pd->timeout)
     {
        ecore_timer_del(pd->timeout);
        pd->timeout = NULL;
     }
   pd->is_timeout = EINA_FALSE;
   efl_gesture_recognizer_reset(efl_super(obj, MY_CLASS), gesture);
}

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

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

#include "efl_canvas_gesture_recognizer_long_tap.eo.c"