forked from enlightenment/efl
tests/gesture: add custom gesture to custom recognizer test
this adds a simple custom gesture implementation with basic motion accumulator properties to verify (and give an example of) the custom gesture capability that can be used by apps alongside custom recognizers Differential Revision: https://phab.enlightenment.org/D11352
This commit is contained in:
parent
76cc9488dd
commit
d481cbe83c
|
@ -0,0 +1,19 @@
|
|||
#include <Efl_Ui.h>
|
||||
#include "custom_gesture.eo.h"
|
||||
#include "custom_gesture.h"
|
||||
#define MY_CLASS CUSTOM_GESTURE_CLASS
|
||||
|
||||
|
||||
EOLIAN static int
|
||||
_custom_gesture_x_delta_get(const Eo *obj EINA_UNUSED, Custom_Gesture_Data *pd)
|
||||
{
|
||||
return pd->x_delta;
|
||||
}
|
||||
|
||||
EOLIAN static int
|
||||
_custom_gesture_y_delta_get(const Eo *obj EINA_UNUSED, Custom_Gesture_Data *pd)
|
||||
{
|
||||
return pd->y_delta;
|
||||
}
|
||||
|
||||
#include "custom_gesture.eo.c"
|
|
@ -0,0 +1,26 @@
|
|||
import eina_types;
|
||||
parse efl_canvas_gesture_recognizer;
|
||||
|
||||
class @beta Custom_Gesture extends Efl.Canvas.Gesture_Custom
|
||||
{
|
||||
[[This is a test class for custom gesture implementations.
|
||||
]]
|
||||
methods {
|
||||
@property x_delta {
|
||||
[[This is the total change in the X coordinate.]]
|
||||
get {
|
||||
}
|
||||
values {
|
||||
val: int; [[The change since the start of the gesture.]]
|
||||
}
|
||||
}
|
||||
@property y_delta {
|
||||
[[This is the total change in the Y coordinate.]]
|
||||
get {
|
||||
}
|
||||
values {
|
||||
val: int; [[The change since the start of the gesture.]]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
#ifndef CUSTOM_GESTURE_H
|
||||
# define CUSTOM_GESTURE_H
|
||||
|
||||
|
||||
typedef struct Custom_Gesture_Data
|
||||
{
|
||||
int x_delta;
|
||||
int y_delta;
|
||||
} Custom_Gesture_Data;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
|
@ -1,5 +1,8 @@
|
|||
#include <Efl_Ui.h>
|
||||
#include "custom_recognizer.eo.h"
|
||||
#include "custom_gesture.eo.h"
|
||||
#include "custom_gesture.h"
|
||||
|
||||
#define MY_CLASS CUSTOM_RECOGNIZER_CLASS
|
||||
|
||||
typedef struct Custom_Recognizer_Data
|
||||
|
@ -7,6 +10,12 @@ typedef struct Custom_Recognizer_Data
|
|||
|
||||
} Custom_Recognizer_Data;
|
||||
|
||||
EOLIAN static const Efl_Class *
|
||||
_custom_recognizer_efl_canvas_gesture_recognizer_type_get(const Eo *obj EINA_UNUSED, Custom_Recognizer_Data *pd EINA_UNUSED)
|
||||
{
|
||||
return CUSTOM_GESTURE_CLASS;
|
||||
}
|
||||
|
||||
EOLIAN static Eo *
|
||||
_custom_recognizer_efl_object_finalize(Eo *obj, Custom_Recognizer_Data *pd EINA_UNUSED)
|
||||
{
|
||||
|
@ -16,14 +25,23 @@ _custom_recognizer_efl_object_finalize(Eo *obj, Custom_Recognizer_Data *pd EINA_
|
|||
|
||||
EOLIAN static Efl_Canvas_Gesture_Recognizer_Result
|
||||
_custom_recognizer_efl_canvas_gesture_recognizer_recognize(Eo *obj EINA_UNUSED, Custom_Recognizer_Data *pd EINA_UNUSED,
|
||||
Efl_Canvas_Gesture *gesture EINA_UNUSED, Efl_Object *watched EINA_UNUSED,
|
||||
Efl_Canvas_Gesture *gesture, Efl_Object *watched EINA_UNUSED,
|
||||
Efl_Canvas_Gesture_Touch *event)
|
||||
{
|
||||
const Efl_Gesture_Touch_Point_Data *data = efl_gesture_touch_current_data_get(event);
|
||||
Custom_Gesture_Data *gd;
|
||||
|
||||
/* ignore multi-touch */
|
||||
if (data->id) return EFL_GESTURE_RECOGNIZER_RESULT_IGNORE;
|
||||
|
||||
switch (efl_gesture_touch_state_get(event))
|
||||
{
|
||||
case EFL_GESTURE_TOUCH_STATE_BEGIN:
|
||||
return EFL_GESTURE_RECOGNIZER_RESULT_TRIGGER;
|
||||
case EFL_GESTURE_TOUCH_STATE_UPDATE:
|
||||
gd = efl_data_scope_get(gesture, CUSTOM_GESTURE_CLASS);
|
||||
gd->x_delta += data->cur.pos.x - data->prev.pos.x;
|
||||
gd->y_delta += data->cur.pos.y - data->prev.pos.y;
|
||||
return EFL_GESTURE_RECOGNIZER_RESULT_TRIGGER;
|
||||
case EFL_GESTURE_TOUCH_STATE_END:
|
||||
return EFL_GESTURE_RECOGNIZER_RESULT_FINISH;
|
||||
|
|
|
@ -6,5 +6,6 @@ class @beta Custom_Recognizer extends Efl.Canvas.Gesture_Recognizer_Custom
|
|||
implements {
|
||||
Efl.Object.finalize;
|
||||
Efl.Canvas.Gesture_Recognizer.recognize;
|
||||
Efl.Canvas.Gesture_Recognizer.type { get; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <Evas_Legacy.h>
|
||||
#include <evas_canvas_eo.h>
|
||||
|
||||
#include "custom_gesture.eo.h"
|
||||
#include "custom_recognizer.eo.h"
|
||||
#include "custom_recognizer2.eo.h"
|
||||
|
||||
|
@ -549,12 +550,24 @@ custom_cb2(void *data EINA_UNUSED , const Efl_Event *ev)
|
|||
count[efl_gesture_state_get(g) - 1]++;
|
||||
}
|
||||
|
||||
static void
|
||||
custom_gesture_cb(void *data EINA_UNUSED , const Efl_Event *ev)
|
||||
{
|
||||
Efl_Canvas_Gesture *g = ev->info;
|
||||
|
||||
Eina_Position2D *delta = data;
|
||||
if (!eina_streq(efl_gesture_custom_gesture_name_get(g), "custom_gesture")) return;
|
||||
delta->x = custom_gesture_x_delta_get(g);
|
||||
delta->y = custom_gesture_y_delta_get(g);
|
||||
}
|
||||
|
||||
EFL_START_TEST(test_efl_ui_gesture_custom)
|
||||
{
|
||||
Eo *rect = setup();
|
||||
Eo *manager = efl_provider_find(rect, EFL_CANVAS_GESTURE_MANAGER_CLASS);
|
||||
Eo *recognizer = efl_add(CUSTOM_RECOGNIZER_CLASS, manager);
|
||||
Eo *recognizer2 = efl_add(CUSTOM_RECOGNIZER2_CLASS, manager);
|
||||
Eina_Position2D delta = {0};
|
||||
|
||||
efl_gesture_manager_recognizer_register(manager, recognizer);
|
||||
efl_gesture_manager_recognizer_register(manager, recognizer2);
|
||||
|
@ -568,6 +581,15 @@ EFL_START_TEST(test_efl_ui_gesture_custom)
|
|||
|
||||
RESET;
|
||||
|
||||
/* verify gesture properties */
|
||||
efl_event_callback_add(rect, EFL_EVENT_GESTURE_CUSTOM, custom_gesture_cb, &delta);
|
||||
drag_object(rect, 0, 0, 75, 30, EINA_FALSE);
|
||||
ck_assert_int_eq(delta.x, 75);
|
||||
ck_assert_int_eq(delta.y, 30);
|
||||
efl_event_callback_del(rect, EFL_EVENT_GESTURE_CUSTOM, custom_gesture_cb, &delta);
|
||||
|
||||
RESET;
|
||||
|
||||
/* verify that we aren't still processing */
|
||||
efl_gesture_manager_recognizer_unregister(manager, recognizer);
|
||||
efl_gesture_manager_recognizer_unregister(manager, recognizer2);
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
priv_eo_files = [
|
||||
'custom_gesture.eo',
|
||||
'custom_recognizer.eo',
|
||||
'custom_recognizer2.eo',
|
||||
'focus_test.eo',
|
||||
|
@ -164,6 +165,7 @@ efl_ui_suite_src = [
|
|||
'efl_ui_test_group_item.c',
|
||||
'efl_ui_test_text.c',
|
||||
'efl_ui_test_vg_animation.c',
|
||||
'custom_gesture.c',
|
||||
'custom_recognizer.c',
|
||||
'custom_recognizer2.c',
|
||||
]
|
||||
|
|
Loading…
Reference in New Issue