/* Some defaults */
#define ELM_MOUSE_DEVICE 0
-#define ELM_GESTURE_ZOOM_FACTOR 1.0
-#define ELM_GESTURE_ZOOM_WHEEL_FACTOR 0.05
-#define ELM_GESTURE_ROTATION_TOLERANCE 0.034906585 /* Represents 2 DEG */
/* ELM_GESTURE_NEGATIVE_ANGLE - magic number says we didn't compute this yet */
#define ELM_GESTURE_NEGATIVE_ANGLE (-1.0) /* Magic number */
#define ELM_GESTURE_MOMENTUM_TIMEOUT 50
-#define ELM_GESTURE_LINE_ANGLE_TOLERANCE 0.34906585 /* Represents 20 DEG */
-#define FLICK_MAX_MS 60
-#define DBL_CLICK_TIME 400
/* Some Trigo values */
#define RAD_90DEG M_PI_2
#define RAD_180DEG M_PI
#define RAD_270DEG (M_PI_2 * 3)
#define RAD_360DEG (M_PI * 2)
+/* #define DEBUG_GESTURE_LAYER 1 */
static void *
_glayer_bufdup(void *buf, size_t size)
};
typedef struct _Taps_Type Taps_Type;
+struct _Long_Tap_Type
+{
+ Elm_Gesture_Taps_Info info;
+ unsigned int center_x;
+ unsigned int center_y;
+ unsigned int n_taps;
+ Ecore_Timer *timeout; /* When this expires, long tap STARTed */
+ Eina_List *touched;
+};
+typedef struct _Long_Tap_Type Long_Tap_Type;
+
struct _Momentum_Type
{ /* Fields used by _line_test() */
Elm_Gesture_Momentum_Info info;
Evas_Coord_Point line_end;
unsigned int t_st_x; /* Time start on X */
unsigned int t_st_y; /* Time start on Y */
- unsigned int t_end; /* Time end */
+ unsigned int t_end; /* Time end */
int xdir, ydir;
};
typedef struct _Momentum_Type Momentum_Type;
Pointer_Event zoom_mv1;
Evas_Event_Mouse_Wheel *zoom_wheel;
Evas_Coord zoom_base; /* Holds gap between fingers on zoom-start */
- Evas_Coord zoom_tolerance;
+ Evas_Coord zoom_distance_tolerance;
+ Elm_Gesture_Momentum_Info momentum1; /* For continues gesture */
+ Elm_Gesture_Momentum_Info momentum2; /* For continues gesture */
double next_step;
};
typedef struct _Zoom_Type Zoom_Type;
Pointer_Event rotate_mv;
Pointer_Event rotate_st1;
Pointer_Event rotate_mv1;
- double rotate_tolerance;
+ double rotate_angular_tolerance;
double next_step;
+ Elm_Gesture_Momentum_Info momentum1; /* For continues gesture */
+ Elm_Gesture_Momentum_Info momentum2; /* For continues gesture */
};
typedef struct _Rotate_Type Rotate_Type;
Event_History *event_history_list;
int line_min_length;
- Evas_Coord zoom_tolerance;
- Evas_Coord line_tolerance;
- float zoom_wheel_factor; /* mouse wheel zoom steps */
- float factor; /* used for zoom factor */
- double rotate_tolerance;
+ Evas_Coord zoom_distance_tolerance;
+ Evas_Coord line_distance_tolerance;
+ double line_angular_tolerance;
+ double zoom_wheel_factor; /* mouse wheel zoom steps */
+ double zoom_finger_factor; /* used for zoom factor */
+ double rotate_angular_tolerance;
+ unsigned int flick_time_limit_ms;
+ double long_tap_start_timeout;
+ Eina_Bool glayer_continues_enable;
double zoom_step;
double rotate_step;
Ecore_Timer *dbl_timeout; /* When this expires, dbl click/taps ABORTed */
Eina_List *pending; /* List of devices need to refeed *UP event */
Eina_List *touched; /* Information of touched devices */
+ Eina_List *recent_device_event; /* Information of recent pe event of each device */
Eina_Bool repeat_events : 1;
};
static const char *widtype = NULL;
static void _del_hook(Evas_Object *obj);
-static void _event_history_clear(Evas_Object *obj);
+static Eina_Bool _event_history_clear(Evas_Object *obj);
static void _reset_states(Widget_Data *wd);
static void _key_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
static void _key_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info);
* @ingroup Elm_Gesture_Layer
*/
static int
-device_is_touched(const void *data1, const void *data2)
+compare_device(const void *data1, const void *data2)
{ /* Compare the two device numbers */
return (((Pointer_Event *) data1)->device -((Pointer_Event *) data2)->device);
}
static Eina_List *
_add_touched_device(Eina_List *list, Pointer_Event *pe)
{
- if (eina_list_search_unsorted_list(list, device_is_touched, pe))
+ if (eina_list_search_unsorted_list(list, compare_device, pe))
return list;
Pointer_Event *p = malloc(sizeof(Pointer_Event ));
static Eina_List *
_remove_touched_device(Eina_List *list, Pointer_Event *pe)
{
- Pointer_Event *p = eina_list_search_unsorted(list, device_is_touched, pe);
+ Pointer_Event *p = eina_list_search_unsorted(list, compare_device, pe);
if (p)
{
free(p);
}
/* END - Functions to manage touched-device list */
+/* START - Functions to manage recent device event list */
+/* This list holds the recent-event for each device */
+/* it will hold a single recent-event for each device */
+/* We are using those PE events of this list to */
+/* send them later to test funcs to restart gestures */
+/* We only keep DOWN, MOVE events in this list. */
+/* So when no touch this list is empty. */
+/**
+ * @internal
+ *
+ * Recoed Pointer Event in touched device list
+ * Note: This fuction allocates memory for PE event
+ * This memory is released here when device untouched
+ * or in cleanup.
+ * @param list Pointer to touched device list.
+ * @param Pointer_Event Pointer to PE.
+ *
+ * @ingroup Elm_Gesture_Layer
+ */
+static Eina_List *
+_add_recent_device_event(Eina_List *list, Pointer_Event *pe)
+{
+ void *data = eina_list_search_sorted(list, compare_device, pe);
+ Eina_List *l = list;
+ Pointer_Event *p = NULL;
+ if(data) /* First remove recent event for this device */
+ l = eina_list_remove(list, data);
+
+
+ switch(pe->event_type)
+ {
+ case EVAS_CALLBACK_MOUSE_DOWN:
+ case EVAS_CALLBACK_MOUSE_MOVE:
+ case EVAS_CALLBACK_MULTI_DOWN:
+ case EVAS_CALLBACK_MULTI_MOVE:
+ p = malloc(sizeof(Pointer_Event));
+ memcpy(p, pe, sizeof(Pointer_Event)); /* Freed in here or on cleanup */
+ l = eina_list_sorted_insert(l, compare_device, p);
+ break;
+
+ /* Kept those cases for referance */
+ case EVAS_CALLBACK_MOUSE_IN:
+ case EVAS_CALLBACK_MOUSE_OUT:
+ case EVAS_CALLBACK_MOUSE_WHEEL:
+ case EVAS_CALLBACK_MOUSE_UP:
+ case EVAS_CALLBACK_MULTI_UP:
+ case EVAS_CALLBACK_KEY_DOWN:
+ case EVAS_CALLBACK_KEY_UP:
+ break;
+
+ default:
+ return l;
+ }
+
+ return l;
+}
+/* END - Functions to manage recent device event list */
+
/**
* @internal
*
{ /* Mark EVAS_EVENT_FLAG_ON_HOLD on events that are used by gesture layer */
/* ev_flags != EVAS_EVENT_FLAG_NONE means target used event and g-layer */
/* should not refeed this event. */
+ if(!event_info)
+ return; /* This happens when restarting gestures */
+
if ((ev_flags) || (!wd->repeat_events))
{
switch(event_type)
_report_state(Gesture_Info *gesture, void *info)
{ /* We report current state (START, MOVE, END, ABORT), once */
#if defined(DEBUG_GESTURE_LAYER)
- printf("%s reporting gesture=<%d> state=<%d>\n" , __func__, g_type,
+ printf("%s reporting gesture=<%d> state=<%d>\n" , __func__, gesture->g_type,
gesture->state);
#endif
if ((gesture->state != ELM_GESTURE_STATE_UNDEFINED) &&
* we clear history immediately to be ready for input.
*
* @param obj The gesture-layer object.
+ * @return TRUE on event history_clear
*
* @ingroup Elm_Gesture_Layer
*/
-static void
+static Eina_Bool
_clear_if_finished(Evas_Object *obj)
{
Widget_Data *wd = elm_widget_data_get(obj);
- if (!wd) return;
+ if (!wd) return EINA_FALSE;
int i;
/* Clear history if all we have aborted gestures */
// if ((!wd->touched) || (reset_s && !all_undefined))
/* (!wd->touched && reset_s) - don't stop zoom with mouse-wheel */
- if (reset_s && (!eina_list_count(wd->touched) || !all_undefined))
- _event_history_clear(obj);
+ if (reset_s && (!all_undefined))
+ return _event_history_clear(obj);
+
+ return EINA_FALSE;
}
static Eina_Bool
memset(gesture->data, 0, sizeof(Taps_Type));
}
+/* All *test_reset() funcs are called to clear
+ * gesture intermediate data.
+ * This happens when we need to reset our tests.
+ * for example when gesture is detected or all ABORTed. */
+static void
+_n_long_tap_test_reset(Gesture_Info *gesture)
+{
+ if (!gesture)
+ return;
+
+ if (!gesture->data)
+ return;
+
+ Long_Tap_Type *st = gesture->data;
+ if (st->timeout) ecore_timer_del(st->timeout);
+ Eina_List *l;
+ Pointer_Event *p;
+ EINA_LIST_FOREACH(st->touched, l, p)
+ free(p);
+
+ eina_list_free(st->touched);
+ memset(gesture->data, 0, sizeof(Long_Tap_Type));
+}
+
static void
_momentum_test_reset(Gesture_Info *gesture)
{
Widget_Data *wd = elm_widget_data_get(gesture->obj);
Zoom_Type *st = gesture->data;
Pointer_Event pe, pe1;
+ Evas_Modifier_Mask mask = evas_key_modifier_mask_get(
+ evas_object_evas_get(wd->target), "Control");
+ evas_object_key_ungrab(wd->target, "Control_L", mask, 0);
+ evas_object_key_ungrab(wd->target, "Control_R", mask, 0);
pe.timestamp = pe1.timestamp = 0;
- if (eina_list_search_unsorted_list(wd->touched, device_is_touched,
+ if (eina_list_search_unsorted_list(wd->touched, compare_device,
&st->zoom_st))
memcpy(&pe, &st->zoom_st, sizeof(Pointer_Event));
- if (eina_list_search_unsorted_list(wd->touched, device_is_touched,
+ if (eina_list_search_unsorted_list(wd->touched, compare_device,
&st->zoom_st1))
memcpy(&pe1, &st->zoom_st1, sizeof(Pointer_Event));
if (pe1.timestamp && (!pe.timestamp))
memcpy(&st->zoom_st1, &pe1, sizeof(Pointer_Event));
- st->zoom_tolerance = wd->zoom_tolerance;
+ st->zoom_distance_tolerance = wd->zoom_distance_tolerance;
st->info.zoom = 1.0;
}
pe.timestamp = pe1.timestamp = 0;
- if (eina_list_search_unsorted_list(wd->touched, device_is_touched,
+ if (eina_list_search_unsorted_list(wd->touched, compare_device,
&st->rotate_st))
memcpy(&pe, &st->rotate_st, sizeof(Pointer_Event));
- if (eina_list_search_unsorted_list(wd->touched, device_is_touched,
+ if (eina_list_search_unsorted_list(wd->touched, compare_device,
&st->rotate_st1))
memcpy(&pe1, &st->rotate_st1, sizeof(Pointer_Event));
st->info.base_angle = ELM_GESTURE_NEGATIVE_ANGLE;
- st->rotate_tolerance = wd->rotate_tolerance;
+ st->rotate_angular_tolerance = wd->rotate_angular_tolerance;
}
static int
device_in_pending_list(const void *data1, const void *data2)
{ /* Compare the two device numbers */
- return (((int) data1) - ((int) data2));
+ return (((intptr_t) data1) - ((intptr_t) data2));
}
/**
}
if (!eina_list_search_unsorted_list(list, device_in_pending_list,
- (void *) device))
+ (intptr_t*) device))
{
- return eina_list_append(list, (void *) device);
+ return eina_list_append(list, (intptr_t*) device);
}
return list;
}
return eina_list_search_unsorted_list(list, device_in_pending_list,
- (void *) device);
+ (intptr_t *) device);
}
/**
*
* @ingroup Elm_Gesture_Layer
*/
-static void
+static Eina_Bool
_event_history_clear(Evas_Object *obj)
{
Widget_Data *wd = elm_widget_data_get(obj);
- if (!wd) return;
+ if (!wd) return EINA_FALSE;
int i;
Gesture_Info *p;
_reset_states(wd); /* we are ready to start testing for gestures again */
/* Clear all gestures intermediate date */
+ _n_long_tap_test_reset(wd->gesture[ELM_GESTURE_N_LONG_TAPS]);
_dbl_click_test_reset(wd->gesture[ELM_GESTURE_N_TAPS]);
_dbl_click_test_reset(wd->gesture[ELM_GESTURE_N_DOUBLE_TAPS]);
_dbl_click_test_reset(wd->gesture[ELM_GESTURE_N_TRIPLE_TAPS]);
free(t);
}
_register_callbacks(obj);
+ return EINA_TRUE;
}
/**
EINA_LIST_FREE(wd->touched, data)
free(data);
+ EINA_LIST_FREE(wd->recent_device_event, data)
+ free(data);
+
if (!elm_widget_disabled_get(obj))
_unregister_callbacks(obj);
/**
* @internal
*
+ * when this timer expires we START long tap gesture
+ *
+ * @param data The gesture-layer object.
+ * @return cancles callback for this timer.
+ *
+ * @ingroup Elm_Gesture_Layer
+ */
+static Eina_Bool
+_long_tap_timeout(void *data)
+{
+ Gesture_Info *gesture = data;
+ Long_Tap_Type *st = gesture->data;
+ st->timeout = NULL;
+
+ _set_state(gesture, ELM_GESTURE_STATE_START,
+ gesture->data, EINA_FALSE);
+
+ return ECORE_CALLBACK_CANCEL;
+}
+
+/**
+ * @internal
+ *
* This function checks all click/tap and double/triple taps
*
* @param obj The gesture-layer object.
/**
* @internal
*
+ * This function computes center-point for long-tap gesture
+ *
+ * @param st Long Tap gesture info pointer
+ * @param pe The recent input event as stored in pe struct.
+ *
+ * @ingroup Elm_Gesture_Layer
+ */
+static void
+_compute_taps_center(Long_Tap_Type *st, Pointer_Event *pe)
+{
+ if(!eina_list_count(st->touched))
+ return;
+
+ Eina_List *l;
+ Pointer_Event *p;
+ Evas_Coord x = 0, y = 0;
+ EINA_LIST_FOREACH(st->touched, l, p)
+ { /* Accumulate all then take avarage */
+ if (p->device == pe->device)
+ { /* This will take care of values coming from MOVE event */
+ x += pe->x;
+ y += pe->y;
+ }
+ else
+ {
+ x += p->x;
+ y += p->y;
+ }
+ }
+
+ st->info.x = x / eina_list_count(st->touched);
+ st->info.y = y / eina_list_count(st->touched);
+}
+
+/**
+ * @internal
+ *
+ * This function checks N long-tap gesture.
+ *
+ * @param obj The gesture-layer object.
+ * @param pe The recent input event as stored in pe struct.
+ * @param event_info Original input event pointer.
+ * @param event_type Type of original input event.
+ * @param g_type what Gesture we are testing.
+ * @param taps How many click/taps we test for.
+ *
+ * @ingroup Elm_Gesture_Layer
+ */
+static void
+_n_long_tap_test(Evas_Object *obj, Pointer_Event *pe,
+ void *event_info, Evas_Callback_Type event_type,
+ Elm_Gesture_Types g_type)
+{ /* Here we fill Recent_Taps struct and fire-up click/tap timers */
+ Widget_Data *wd = elm_widget_data_get(obj);
+ if (!wd) return;
+
+ if (!pe) /* this happens when unhandled event arrived */
+ return; /* see _make_pointer_event function */
+
+ Gesture_Info *gesture = wd->gesture[g_type];
+ if (!gesture ) return;
+
+ Long_Tap_Type *st = gesture->data;
+ if (!st)
+ { /* Allocated once on first time */
+ st = calloc(1, sizeof(Long_Tap_Type));
+ gesture->data = st;
+ _n_long_tap_test_reset(gesture);
+ }
+
+ Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
+ switch (pe->event_type)
+ {
+ case EVAS_CALLBACK_MULTI_DOWN:
+ case EVAS_CALLBACK_MOUSE_DOWN:
+ if (st->info.n > eina_list_count(st->touched))
+ { /* ABORT: user lifts finger then back before completing gesgure */
+ if (st->timeout) ecore_timer_del(st->timeout);
+ st->timeout = NULL;
+ ev_flag =_set_state(gesture, ELM_GESTURE_STATE_ABORT,
+ &st->info, EINA_FALSE);
+ }
+
+ st->touched = _add_touched_device(st->touched, pe);
+ st->info.n = eina_list_count(st->touched);
+ if ((pe->device == 0) && (eina_list_count(st->touched) == 1))
+ { /* This is the first mouse down we got */
+ st->info.timestamp = pe->timestamp;
+
+ /* To test long tap */
+ /* When this timer expires, gesture STARTED */
+ if (!st->timeout)
+ st->timeout = ecore_timer_add(wd->long_tap_start_timeout, _long_tap_timeout,
+ gesture);
+ }
+
+ consume_event(wd, event_info, event_type, ev_flag);
+ _compute_taps_center(st, pe);
+ break;
+
+ case EVAS_CALLBACK_MULTI_UP:
+ case EVAS_CALLBACK_MOUSE_UP:
+ st->touched = _remove_touched_device(st->touched, pe);
+ if (st->info.n &&
+ ((gesture->state == ELM_GESTURE_STATE_START) ||
+ (gesture->state == ELM_GESTURE_STATE_MOVE)))
+ { /* Report END only for gesture that STARTed */
+ if (eina_list_count(st->touched) == 0)
+ { /* Report END only at last release event */
+ ev_flag =_set_state(gesture, ELM_GESTURE_STATE_END,
+ &st->info, EINA_FALSE);
+ consume_event(wd, event_info, event_type, ev_flag);
+ }
+ }
+ break;
+
+ case EVAS_CALLBACK_MULTI_MOVE:
+ case EVAS_CALLBACK_MOUSE_MOVE:
+ if(st->info.n &&
+ ((gesture->state == ELM_GESTURE_STATE_START) ||
+ (gesture->state == ELM_GESTURE_STATE_MOVE)))
+ { /* Report MOVE only if STARTED */
+ _compute_taps_center(st, pe);
+ /* Report MOVE if gesture started */
+ ev_flag = _set_state(gesture, ELM_GESTURE_STATE_MOVE,
+ &st->info, EINA_TRUE);
+ consume_event(wd, event_info, event_type, ev_flag);
+ }
+ break;
+
+ default:
+ return;
+ }
+}
+
+/**
+ * @internal
+ *
* This function computes momentum for MOMENTUM, LINE and FLICK gestures
* This momentum value will be sent to widget when gesture is completed.
*
return; /* user left a finger on device, do NOT start */
Momentum_Type *st = gesture->data;
+ Elm_Gesture_State state_to_report;
if (!st)
{ /* Allocated once on first time */
st = calloc(1, sizeof(Momentum_Type));
return;
Evas_Event_Flags ev_flag = EVAS_EVENT_FLAG_NONE;
- switch (pe->event_type)
+ switch (event_type)
{
case EVAS_CALLBACK_MOUSE_DOWN:
st->line_st.x = st->line_end.x = pe->x;
/* IGNORE if line info was cleared, like long press, move */
if (!st->t_st_x)
return;
+ state_to_report = ELM_GESTURE_STATE_END;
if ((pe->timestamp - ELM_GESTURE_MOMENTUM_TIMEOUT) > st->t_end)
{
st->line_st.y = pe->y;
st->t_st_y = st->t_st_x = pe->timestamp;
st->xdir = st->ydir = 0;
+ state_to_report = ELM_GESTURE_STATE_ABORT;
}
st->info.x2 = pe->x;
_set_momentum(&st->info, st->line_st.x, st->line_st.y, pe->x, pe->y,
st->t_st_x, st->t_st_y, pe->timestamp);
- ev_flag = _set_state(gesture, ELM_GESTURE_STATE_END, &st->info,
+ ev_flag = _set_state(gesture, state_to_report, &st->info,
EINA_FALSE);
consume_event(wd, event_info, event_type, ev_flag);
if (!st->t_st_x)
return;
+ state_to_report = ELM_GESTURE_STATE_MOVE;
if ((pe->timestamp - ELM_GESTURE_MOMENTUM_TIMEOUT) > st->t_end)
{
/* Too long of a wait, reset all values */
st->info.tx = st->t_st_x;
st->info.ty = st->t_st_y;
st->xdir = st->ydir = 0;
+ state_to_report = ELM_GESTURE_STATE_ABORT;
}
else
{
st->t_end = pe->timestamp;
_set_momentum(&st->info, st->line_st.x, st->line_st.y, pe->x, pe->y,
st->t_st_x, st->t_st_y, pe->timestamp);
- ev_flag = _set_state(gesture, ELM_GESTURE_STATE_MOVE, &st->info,
+ ev_flag = _set_state(gesture, state_to_report, &st->info,
EINA_TRUE);
consume_event(wd, event_info, event_type, ev_flag);
break;
*/
static Eina_Bool
_single_line_process(Elm_Gesture_Line_Info *info, Line_Data *st,
- Pointer_Event *pe)
+ Pointer_Event *pe, Evas_Callback_Type event_type)
{ /* Record events and set momentum for line pointed by st */
if (!pe)
return EINA_FALSE;
- switch (pe->event_type)
+ switch (event_type)
{
case EVAS_CALLBACK_MOUSE_DOWN:
case EVAS_CALLBACK_MULTI_DOWN:
if (!wd) return;
Gesture_Info *gesture = wd->gesture[g_type];
if (!gesture ) return;
-
+/*
if ((gesture->state == ELM_GESTURE_STATE_UNDEFINED) &&
eina_list_count(wd->touched))
- return; /* user left a finger on device, do NOT start */
-
+ return; user left a finger on device, do NOT start
+*/
Line_Type *st = gesture->data;
if (!st)
{
if (!line) /* This may happen on MOVE that comes before DOWN */
return; /* No line-struct to work with, can't continue testing */
-
- if (_single_line_process(&st->info, line, pe)) /* update st with input */
+ if (_single_line_process(&st->info, line, pe, event_type)) /* update st with input */
consume_event(wd, event_info, event_type, EVAS_EVENT_FLAG_NONE);
/* Get direction and magnitude of the line */
#if defined(DEBUG_GESTURE_LAYER)
printf("%s a=<%f> d=<%f>\n", __func__, (a * 57.295779513), d);
#endif
- if ((d > wd->line_tolerance) || (a > ELM_GESTURE_LINE_ANGLE_TOLERANCE))
-// if (a > ELM_GESTURE_LINE_ANGLE_TOLERANCE)
+ if ((d > wd->line_distance_tolerance) || (a > wd->line_angular_tolerance))
{ /* Broke tolerance: abort line and start a new one */
ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT,
&st->info, EINA_FALSE);
consume_event(wd, event_info, event_type, ev_flag);
return;
}
+
+ if (wd->glayer_continues_enable)
+ { /* We may finish line if momentum is zero */
+ /* This is for continues-gesture */
+ if ((!st->info.momentum.mx) && (!st->info.momentum.my))
+ { /* Finish line on zero momentum for continues gesture */
+ line->line_end.x = pe->x;
+ line->line_end.y = pe->y;
+ line->t_end = pe->timestamp;
+ }
+ }
}
else
{ /* Record the line angle as it broke minimum length for line */
st->info.angle = line->line_angle = angle;
}
+
if (line->t_end)
{
if (line->line_angle < 0.0)
if (t_line->line_angle >= 0)
{ /* Compare angle only with lines with direction defined */
if (fabs(base_angle - t_line->line_angle) >
- ELM_GESTURE_LINE_ANGLE_TOLERANCE)
+ wd->line_angular_tolerance)
lines_parallel = EINA_FALSE;
}
}
return;
}
- if ((g_type == ELM_GESTURE_N_FLICKS) && ((tm_end - tm_start) > FLICK_MAX_MS))
+ if ((g_type == ELM_GESTURE_N_FLICKS) && ((tm_end - tm_start) > wd->flick_time_limit_ms))
{ /* We consider FLICK as a fast line.ABORT if take too long to finish */
ev_flag = _set_state(gesture, ELM_GESTURE_STATE_ABORT, &st->info,
EINA_FALSE);
case EVAS_CALLBACK_MULTI_MOVE:
if (started)
{
- ev_flag = _set_state(gesture, ELM_GESTURE_STATE_MOVE,
- &st->info, EINA_TRUE);
- consume_event(wd, event_info, event_type, ev_flag);
+ if (wd->glayer_continues_enable && started == ended)
+ { /* For continues gesture */
+ ev_flag = _set_state(gesture, ELM_GESTURE_STATE_END,
+ &st->info, EINA_FALSE);
+ consume_event(wd, event_info, event_type, ev_flag);
+ }
+ else
+ {
+ ev_flag = _set_state(gesture, ELM_GESTURE_STATE_MOVE,
+ &st->info, EINA_TRUE);
+ consume_event(wd, event_info, event_type, ev_flag);
+ }
}
-
break;
default:
if (st->info.base_angle < 0)
return EINA_FALSE; /* Angle has to be computed first */
- if (st->rotate_tolerance < 0)
+ if (st->rotate_angular_tolerance < 0)
return EINA_TRUE;
- double low = st->info.base_angle - st->rotate_tolerance;
- double high = st->info.base_angle + st->rotate_tolerance;
+ double low = st->info.base_angle - st->rotate_angular_tolerance;
+ double high = st->info.base_angle + st->rotate_angular_tolerance;
double t = st->info.angle;
if (low < 0)
}
#if defined(DEBUG_GESTURE_LAYER)
- printf("%s angle=<%d> low=<%d> high=<%d>\n", __func__, t, low, high);
+ printf("%s angle=<%f> low=<%f> high=<%f>\n", __func__, t, low, high);
#endif
if ((t < low) || (t > high))
{ /* This marks that roation action has started */
- st->rotate_tolerance = ELM_GESTURE_NEGATIVE_ANGLE;
+ st->rotate_angular_tolerance = ELM_GESTURE_NEGATIVE_ANGLE;
st->info.base_angle = st->info.angle; /* Avoid jump in angle value */
return EINA_TRUE;
}
* @ingroup Elm_Gesture_Layer
*/
/* FIXME change float to double */
-static float
+static double
compute_zoom(Zoom_Type *st, Evas_Coord x1, Evas_Coord y1, unsigned int tm1,
- Evas_Coord x2, Evas_Coord y2, unsigned int tm2, float factor)
+ Evas_Coord x2, Evas_Coord y2, unsigned int tm2, double zoom_finger_factor)
{
- float rt = 1.0;
+ double rt = 1.0;
Evas_Coord diam = get_finger_gap_length(x1, y1, x2, y2,
&st->info.x, &st->info.y);
return st->info.zoom;
}
- if (st->zoom_tolerance)
+ if (st->zoom_distance_tolerance)
{ /* zoom tolerance <> ZERO, means zoom action NOT started yet */
- if (diam < (st->zoom_base - st->zoom_tolerance))
+ if (diam < (st->zoom_base - st->zoom_distance_tolerance))
{ /* avoid jump with zoom value when break tolerance */
- st->zoom_base -= st->zoom_tolerance;
- st->zoom_tolerance = 0;
+ st->zoom_base -= st->zoom_distance_tolerance;
+ st->zoom_distance_tolerance = 0;
}
- if (diam > (st->zoom_base + st->zoom_tolerance))
+ if (diam > (st->zoom_base + st->zoom_distance_tolerance))
{ /* avoid jump with zoom value when break tolerance */
- st->zoom_base += st->zoom_tolerance;
- st->zoom_tolerance = 0;
+ st->zoom_base += st->zoom_distance_tolerance;
+ st->zoom_distance_tolerance = 0;
}
return rt;
/* We use factor only on the difference between gap-base */
/* if gap=120, base=100, we get ((120-100)/100)=0.2*factor */
rt = ((1.0) + ((((float) diam - (float) st->zoom_base) /
- (float) st->zoom_base) * factor));
+ (float) st->zoom_base) * zoom_finger_factor));
#if 0
/* Momentum: zoom per second: (NOT YET SUPPORTED) */
}
/* Using mouse wheel with CTRL for zoom */
- if (st->zoom_wheel || (st->zoom_tolerance == 0))
- { /* when (zoom_wheel == NULL) and (zoom_tolerance == 0)
+ if (st->zoom_wheel || (st->zoom_distance_tolerance == 0))
+ { /* when (zoom_wheel == NULL) and (zoom_distance_tolerance == 0)
we continue a zoom gesture */
force = EINA_TRUE;
s = ELM_GESTURE_STATE_MOVE;
}
else
{ /* On first wheel event, report START */
+ Evas_Modifier_Mask mask = evas_key_modifier_mask_get(
+ evas_object_evas_get(wd->target), "Control");
force = EINA_FALSE;
s = ELM_GESTURE_STATE_START;
+ if (!evas_object_key_grab(wd->target, "Control_L", mask, 0, EINA_FALSE))
+ ERR("Failed to Grabbed CTRL_L");
+ if (!evas_object_key_grab(wd->target, "Control_R", mask, 0, EINA_FALSE))
+ ERR("Failed to Grabbed CTRL_R");
}
- st->zoom_tolerance = 0; /* Cancel tolerance */
+ st->zoom_distance_tolerance = 0; /* Cancel tolerance */
st->zoom_wheel = (Evas_Event_Mouse_Wheel *) event_info;
st->info.x = st->zoom_wheel->canvas.x;
st->info.y = st->zoom_wheel->canvas.y;
- if (st->zoom_wheel->z > 0) /* zoom in */
- st->info.zoom += (wd->factor * wd->zoom_wheel_factor);
+ if (st->zoom_wheel->z < 0) /* zoom in */
+ st->info.zoom += (wd->zoom_finger_factor * wd->zoom_wheel_factor);
- if (st->zoom_wheel->z < 0) /* zoom out */
- st->info.zoom -= (wd->factor * wd->zoom_wheel_factor);
+ if (st->zoom_wheel->z > 0) /* zoom out */
+ st->info.zoom -= (wd->zoom_finger_factor * wd->zoom_wheel_factor);
if (st->info.zoom < 0.0)
st->info.zoom = 0.0;
st->info.zoom = compute_zoom(st,
st->zoom_mv.x, st->zoom_mv.y, st->zoom_mv.timestamp,
st->zoom_mv1.x, st->zoom_mv1.y, st->zoom_mv1.timestamp,
- wd->factor);
+ wd->zoom_finger_factor);
break;
}
st->info.zoom = compute_zoom(st,
st->zoom_mv.x, st->zoom_mv.y, st->zoom_mv.timestamp,
st->zoom_st1.x, st->zoom_st1.y, st->zoom_st1.timestamp,
- wd->factor);
+ wd->zoom_finger_factor);
break;
}
st->info.zoom = compute_zoom(st,
st->zoom_mv1.x, st->zoom_mv1.y, st->zoom_mv1.timestamp,
st->zoom_mv.x, st->zoom_mv.y, st->zoom_mv.timestamp,
- wd->factor);
+ wd->zoom_finger_factor);
break;
}
st->info.zoom = compute_zoom(st,
st->zoom_mv1.x, st->zoom_mv1.y, st->zoom_mv1.timestamp,
st->zoom_st.x, st->zoom_st.y, st->zoom_st.timestamp,
- wd->factor);
+ wd->zoom_finger_factor);
break;
}
by _zoom_test_reset() to retain finger-down data */
consume_event(wd, event_info, event_type, ev_flag);
if (((st->zoom_wheel) || (st->zoom_base)) &&
- (st->zoom_tolerance == 0))
+ (st->zoom_distance_tolerance == 0))
{
ev_flag = _set_state(gesture_zoom, ELM_GESTURE_STATE_END,
&st->info, EINA_FALSE);
}
- if (!st->zoom_tolerance)
+ if (!st->zoom_distance_tolerance)
if ((event_type == EVAS_CALLBACK_MOUSE_MOVE) ||
(event_type == EVAS_CALLBACK_MULTI_MOVE))
{
if (d < 0.0)
d = (-d);
+ if (wd->glayer_continues_enable)
+ { /* START For contiunues gesture: compute momentum */
+ _set_momentum(&st->momentum1, st->zoom_st.x, st->zoom_st.y,
+ st->zoom_mv.x, st->zoom_mv.y,st->zoom_st.timestamp, st->zoom_st.timestamp,
+ st->zoom_mv.timestamp);
+
+ _set_momentum(&st->momentum2, st->zoom_st1.x, st->zoom_st1.y,
+ st->zoom_mv1.x, st->zoom_mv1.y,st->zoom_st1.timestamp, st->zoom_st1.timestamp,
+ st->zoom_mv1.timestamp);
+
+ if (!(st->momentum1.mx + st->momentum1.my + st->momentum2.mx + st->momentum2.my))
+ {
+ ev_flag = _set_state(gesture_zoom, ELM_GESTURE_STATE_END,
+ &st->info, EINA_FALSE);
+ return;
+ }
+ } /* END For contiunues gesture: compute momentum */
+
+
if (d >= wd->zoom_step)
{ /* Report move in steps */
st->next_step = st->info.zoom;
consume_event(wd, event_info, event_type, ev_flag);
/* Reset timestamp of finger-up.This is used later
by rotate_test_reset() to retain finger-down data */
- if (st->rotate_tolerance < 0)
+ if (st->rotate_angular_tolerance < 0)
{
ev_flag = _set_state(gesture, ELM_GESTURE_STATE_END,
&st->info, EINA_FALSE);
if (d < 0.0)
d = (-d);
+ if (wd->glayer_continues_enable)
+ { /* START For contiunues gesture: compute momentum */
+ _set_momentum(&st->momentum1, st->rotate_st.x, st->rotate_st.y,
+ st->rotate_mv.x, st->rotate_mv.y,st->rotate_st.timestamp, st->rotate_st.timestamp,
+ st->rotate_mv.timestamp);
+
+ _set_momentum(&st->momentum2, st->rotate_st1.x, st->rotate_st1.y,
+ st->rotate_mv1.x, st->rotate_mv1.y,st->rotate_st1.timestamp, st->rotate_st1.timestamp,
+ st->rotate_mv1.timestamp);
+
+ if (!(st->momentum1.mx + st->momentum1.my + st->momentum2.mx + st->momentum2.my))
+ {
+ ev_flag = _set_state(gesture, ELM_GESTURE_STATE_END,
+ &st->info, EINA_FALSE);
+ return;
+ }
+ } /* END For contiunues gesture: compute momentum */
+
if (d >= wd->rotate_step)
{ /* Report move in steps */
st->next_step = st->info.angle;
/**
* @internal
*
+ * This function restartes line, flick, zoom and rotate gestures
+ * when gesture-layer continues-gestures enabled.
+ * Example of continues-gesture:
+ * When doing a line, user stops moving finger but keeps fingers on touch.
+ * This will cause line-end, then as user continues moving his finger
+ * it re-starts line gesture.
+ * When continue mode is disabled, user has to lift finger from touch
+ * to end a gesture. Them touch-again to start a new one.
+ *
+ * @param data The gesture-layer object.
+ * @param wd gesture layer widget data.
+ * @param states_reset flag that marks gestures were reset in history clear.
+ *
+ * @ingroup Elm_Gesture_Layer
+ */
+void continues_gestures_restart(void *data, Eina_Bool states_reset)
+{
+ Widget_Data *wd = elm_widget_data_get(data);
+ if (!wd) return;
+
+ /* Run through events to restart gestures */
+ Gesture_Info *g;
+ Eina_Bool n_lines, n_flicks, zoom, rotate;
+#if defined(DEBUG_GESTURE_LAYER)
+ int i;
+ printf("Gesture | State | is tested\n");
+ for(i = ELM_GESTURE_N_TAPS; i < ELM_GESTURE_LAST; i++)
+ {
+ g = wd->gesture[i];
+ if(g)
+ printf(" %d %d %d\n", i, g->state, g->test);
+ }
+#endif
+ /* We turn-on flag for finished, aborted, not-started gestures */
+ g = wd->gesture[ELM_GESTURE_N_LINES];
+ n_lines = (g) ? ((states_reset) | ((g->state != ELM_GESTURE_STATE_START)
+ && (g->state != ELM_GESTURE_STATE_MOVE))) : EINA_FALSE;
+ if (n_lines)
+ {
+ _line_test_reset(wd->gesture[ELM_GESTURE_N_LINES]);
+ _set_state(g, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
+ SET_TEST_BIT(g);
+ }
+
+ g = wd->gesture[ELM_GESTURE_N_FLICKS];
+ n_flicks = (g) ? ((states_reset) | ((g->state != ELM_GESTURE_STATE_START)
+ && (g->state != ELM_GESTURE_STATE_MOVE))) : EINA_FALSE;
+ if (n_flicks)
+ {
+ _line_test_reset(wd->gesture[ELM_GESTURE_N_FLICKS]);
+ _set_state(g, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
+ SET_TEST_BIT(g);
+ }
+
+ g = wd->gesture[ELM_GESTURE_ZOOM];
+ zoom = (g) ? ((states_reset) | ((g->state != ELM_GESTURE_STATE_START)
+ && (g->state != ELM_GESTURE_STATE_MOVE))) : EINA_FALSE;
+ if (zoom)
+ {
+ _zoom_test_reset(wd->gesture[ELM_GESTURE_ZOOM]);
+ _set_state(g, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
+ SET_TEST_BIT(g);
+ }
+
+
+ g = wd->gesture[ELM_GESTURE_ROTATE];
+ rotate = (g) ? ((states_reset) | ((g->state != ELM_GESTURE_STATE_START)
+ && (g->state != ELM_GESTURE_STATE_MOVE))) : EINA_FALSE;
+ if (rotate)
+ {
+ _rotate_test_reset(wd->gesture[ELM_GESTURE_ROTATE]);
+ _set_state(g, ELM_GESTURE_STATE_UNDEFINED, NULL, EINA_FALSE);
+ SET_TEST_BIT(g);
+ }
+
+ Eina_List *l;
+ Pointer_Event *p;
+ EINA_LIST_FOREACH(wd->recent_device_event, l, p)
+ { /* Generate a DOWN event */
+ Evas_Callback_Type e_type = p->event_type;
+ if(p->event_type == EVAS_CALLBACK_MULTI_MOVE)
+ e_type = EVAS_CALLBACK_MULTI_DOWN;
+ else
+ if(p->event_type == EVAS_CALLBACK_MOUSE_MOVE)
+ e_type = EVAS_CALLBACK_MOUSE_DOWN;
+
+
+ if (n_lines && (IS_TESTED(ELM_GESTURE_N_LINES)))
+ _n_line_test(data, p, NULL, e_type, ELM_GESTURE_N_LINES);
+
+ if (n_flicks && (IS_TESTED(ELM_GESTURE_N_FLICKS)))
+ _n_line_test(data, p, NULL, e_type, ELM_GESTURE_N_FLICKS);
+
+ if (zoom && (IS_TESTED(ELM_GESTURE_ZOOM)))
+ _zoom_test(data, p, NULL, e_type, ELM_GESTURE_ZOOM);
+
+ if (rotate && (IS_TESTED(ELM_GESTURE_ROTATE)))
+ _rotate_test(data, p, NULL, e_type, ELM_GESTURE_ROTATE);
+ }
+}
+
+/**
+ * @internal
+ *
* This function the core-function where input handling is done.
* Here we get user input and stream it to gesture testing.
* We notify user about any gestures with new state:
if (_make_pointer_event(data, event_info, event_type, &_pe))
pe = &_pe;
+ if (IS_TESTED(ELM_GESTURE_N_LONG_TAPS))
+ _n_long_tap_test(data, pe, event_info, event_type,
+ ELM_GESTURE_N_LONG_TAPS);
+
if (IS_TESTED(ELM_GESTURE_N_TAPS))
_dbl_click_test(data, pe, event_info, event_type,
ELM_GESTURE_N_TAPS, 1);
}
}
+ /* Log event to restart gestures */
+ wd->recent_device_event = _add_recent_device_event(wd->recent_device_event, &_pe);
+
/* we maintain list of touched devices*/
if ((event_type == EVAS_CALLBACK_MOUSE_DOWN) ||
(event_type == EVAS_CALLBACK_MULTI_DOWN))
}
/* Report current states and clear history if needed */
- _clear_if_finished(data);
+ Eina_Bool states_reset = _clear_if_finished(data);
+ if (wd->glayer_continues_enable)
+ continues_gestures_restart(data, states_reset);
}
Elm_Gesture_State cb_type, Elm_Gesture_Event_Cb cb, void *data)
{
Widget_Data *wd = elm_widget_data_get(obj);
+ Gesture_Info *p;
if (!wd) return;
if (!wd->gesture[idx])
wd->gesture[idx] = calloc(1, sizeof(Gesture_Info));
+ if (!wd->gesture[idx]) return;
- Gesture_Info *p = wd->gesture[idx];
+ p = wd->gesture[idx];
p->obj = obj;
p->g_type = idx;
p->fn[cb_type].cb = cb;
elm_widget_disable_hook_set(obj, _disable_hook);
wd->target = NULL;
- wd->line_min_length = wd->zoom_tolerance = elm_finger_size_get();
- wd->line_tolerance = elm_finger_size_get() * 3;
- wd->factor = ELM_GESTURE_ZOOM_FACTOR;
- wd->zoom_wheel_factor = ELM_GESTURE_ZOOM_WHEEL_FACTOR ; /* mouse wheel zoom steps */
- wd->rotate_tolerance = ELM_GESTURE_ROTATION_TOLERANCE;
+ wd->line_min_length =_elm_config->glayer_line_min_length * elm_finger_size_get();
+ wd->zoom_distance_tolerance = _elm_config->glayer_zoom_distance_tolerance * elm_finger_size_get();
+ wd->line_distance_tolerance = _elm_config->glayer_line_distance_tolerance * elm_finger_size_get();
+ wd->zoom_finger_factor = _elm_config->glayer_zoom_finger_factor;
+ wd->zoom_wheel_factor = _elm_config->glayer_zoom_wheel_factor; /* mouse wheel zoom steps */
+ wd->rotate_angular_tolerance = _elm_config->glayer_rotate_angular_tolerance;
+ wd->line_angular_tolerance = _elm_config->glayer_line_angular_tolerance;
+ wd->flick_time_limit_ms = _elm_config->glayer_flick_time_limit_ms;
+ wd->long_tap_start_timeout = _elm_config->glayer_long_tap_start_timeout;
wd->repeat_events = EINA_TRUE;
+ wd->glayer_continues_enable = _elm_config->glayer_continues_enable;
#if defined(DEBUG_GESTURE_LAYER)
printf("size of Gestures = <%d>\n", sizeof(wd->gesture));
+ printf("initial values:\n\tzoom_finger_factor=<%f>\n\tzoom_distance_tolerance=<%d>\n\tline_min_length=<%d>\n\tline_distance_tolerance=<%d>\n\tzoom_wheel_factor=<%f>\n\trotate_angular_tolerance=<%f>\n\twd->line_angular_tolerance=<%f>\n\twd->flick_time_limit_ms=<%d>\n\twd->long_tap_start_timeout=<%f>\n\twd->zoom_step=<%f>\n\twd->rotate_step=<%f>\n\twd->glayer_continues_enable=<%d>\n ", wd->zoom_finger_factor, wd->zoom_distance_tolerance, wd->line_min_length, wd->line_distance_tolerance, wd->zoom_wheel_factor, wd->rotate_angular_tolerance, wd->line_angular_tolerance, wd->flick_time_limit_ms, wd->long_tap_start_timeout, wd->zoom_step, wd->rotate_step, wd->glayer_continues_enable);
#endif
memset(wd->gesture, 0, sizeof(wd->gesture));