summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsmohanty <smohantty@gmail.com>2017-09-21 10:11:53 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2017-10-19 10:33:12 +0900
commitba3afc74a8b03b96c3ea43855b09362d32b47cd2 (patch)
tree8724d09ee3a2151f681d100bb18c168eb4e453d4
parent28869a939508ce30d4102b81635a655eb2514eea (diff)
elementary_test: Added gesture_framework test to the elementary test suit.
-rw-r--r--src/Makefile_Elementary.am1
-rw-r--r--src/bin/elementary/Makefile.am1
-rw-r--r--src/bin/elementary/test.c4
-rw-r--r--src/bin/elementary/test_gesture_framework.c419
4 files changed, 425 insertions, 0 deletions
diff --git a/src/Makefile_Elementary.am b/src/Makefile_Elementary.am
index 4020195635..e7e5f97ddd 100644
--- a/src/Makefile_Elementary.am
+++ b/src/Makefile_Elementary.am
@@ -911,6 +911,7 @@ bin/elementary/test_win_dialog.c \
911bin/elementary/test_win_modal.c \ 911bin/elementary/test_win_modal.c \
912bin/elementary/test_efl_ui_text.c \ 912bin/elementary/test_efl_ui_text.c \
913bin/elementary/test_win_stack.c \ 913bin/elementary/test_win_stack.c \
914bin/elementary/test_gesture_framework.c \
914bin/elementary/test.h 915bin/elementary/test.h
915 916
916bin_elementary_elementary_test_LDADD = @USE_ELEMENTARY_LIBS@ 917bin_elementary_elementary_test_LDADD = @USE_ELEMENTARY_LIBS@
diff --git a/src/bin/elementary/Makefile.am b/src/bin/elementary/Makefile.am
index 63a0bf86b0..df71027a38 100644
--- a/src/bin/elementary/Makefile.am
+++ b/src/bin/elementary/Makefile.am
@@ -148,6 +148,7 @@ test_win_plug.c \
148test_win_state.c \ 148test_win_state.c \
149test_win_wm_rotation.c \ 149test_win_wm_rotation.c \
150test_win_dialog.c \ 150test_win_dialog.c \
151test_gesture_framework.c \
151test.h 152test.h
152 153
153elementary_test_LDADD = $(top_builddir)/src/lib/libelementary.la \ 154elementary_test_LDADD = $(top_builddir)/src/lib/libelementary.la \
diff --git a/src/bin/elementary/test.c b/src/bin/elementary/test.c
index bd22de4ba5..2abfdf8799 100644
--- a/src/bin/elementary/test.c
+++ b/src/bin/elementary/test.c
@@ -339,6 +339,9 @@ void test_efl_anim_repeat(void *data, Evas_Object *obj, void *event_info);
339void test_efl_anim_start_delay(void *data, Evas_Object *obj, void *event_info); 339void test_efl_anim_start_delay(void *data, Evas_Object *obj, void *event_info);
340void test_efl_anim_interpolator(void *data, Evas_Object *obj, void *event_info); 340void test_efl_anim_interpolator(void *data, Evas_Object *obj, void *event_info);
341 341
342void test_gesture_framework(void *data, Evas_Object *obj, void *event_info);
343
344
342Evas_Object *win, *tbx; // TODO: refactoring 345Evas_Object *win, *tbx; // TODO: refactoring
343void *tt; 346void *tt;
344Eina_List *tests; 347Eina_List *tests;
@@ -1082,6 +1085,7 @@ add_tests:
1082 ADD_TEST(NULL, "Evas", "Snapshot", test_evas_snapshot); 1085 ADD_TEST(NULL, "Evas", "Snapshot", test_evas_snapshot);
1083 ADD_TEST(NULL, "Evas", "Map", test_evas_map); 1086 ADD_TEST(NULL, "Evas", "Map", test_evas_map);
1084 ADD_TEST(NULL, "Evas", "Gfx Map", test_efl_gfx_map); 1087 ADD_TEST(NULL, "Evas", "Gfx Map", test_efl_gfx_map);
1088 ADD_TEST(NULL, "Evas", "Gesture", test_gesture_framework);
1085 1089
1086 //------------------------------// 1090 //------------------------------//
1087 ADD_TEST(NULL, "Widgets Disable/Enable", "Box", test_box_disable); 1091 ADD_TEST(NULL, "Widgets Disable/Enable", "Box", test_box_disable);
diff --git a/src/bin/elementary/test_gesture_framework.c b/src/bin/elementary/test_gesture_framework.c
new file mode 100644
index 0000000000..e09bfa1bed
--- /dev/null
+++ b/src/bin/elementary/test_gesture_framework.c
@@ -0,0 +1,419 @@
1#ifdef HAVE_CONFIG_H
2# include "elementary_config.h"
3#endif
4#include <Elementary.h>
5
6#define TAP_NAME "tap"
7#define DOUBLE_TAP_NAME "double_tap"
8#define TRIPLE_TAP_NAME "triple_tap"
9#define LONG_TAP_NAME "long_tap"
10#define FLICK_NAME "flick"
11#define LINE_NAME "line"
12#define MOMENTUM_NAME "momentum"
13#define ROTATE_NAME "rotate"
14#define ZOOM_NAME "zoom"
15
16#define N_GESTURE_TYPE 9
17#define MAX_DOUBLE_TAP 5
18#define MAX_FLICK 5
19#define MAX_LINE 5
20#define MAX_LONG_TAP 5
21#define MAX_MOMENTUM 5
22#define MAX_ROTATE 1
23#define MAX_TAP 5
24#define MAX_TRIPLE_TAP 5
25#define MAX_ZOOM 1
26
27#define TB_PADDING_X 4
28#define TB_PADDING_Y 12
29
30#define BX_PADDING_X 0
31#define BX_PADDING_Y 2
32
33/* Define initial RGBA values for icons */
34#define INI_R 60
35#define INI_G 66
36#define INI_B 64
37#define INI_A 128
38#define COLOR_STEP 4
39
40#define START_COLOR 220, 220, 200, 255
41#define UPDATE_COLOR 255, 255, 0, 255
42#define ABORT_COLOR 255, 0, 0, 255
43#define END_COLOR 0, 255, 0, 255
44
45struct _icon_properties
46{
47 Evas_Object *icon;
48 int r; /* current r */
49 int g;
50 int b;
51 int a;
52
53 const char *name;
54};
55typedef struct _icon_properties icon_properties;
56
57struct _infra_data
58{ /* Some data that is passed aroung between callbacks (replacing globals) */
59 icon_properties *icons;
60 Ecore_Timer *colortimer;
61 char buf[1024];
62 int long_tap_count;
63};
64typedef struct _infra_data infra_data;
65
66static void
67_infra_data_free(infra_data *infra)
68{
69 if (infra)
70 {
71 if (infra->colortimer)
72 ecore_timer_del(infra->colortimer);
73
74 if (infra->icons)
75 free(infra->icons);
76
77 free (infra);
78 }
79}
80
81static infra_data *
82_infra_data_alloc(void)
83{
84 infra_data *infra = malloc(sizeof(infra_data));
85 if (!infra) return NULL;
86
87 infra->icons = calloc(N_GESTURE_TYPE, sizeof(icon_properties ));
88 infra->colortimer = NULL;
89
90 return infra;
91}
92
93static void
94my_win_del(void *data, Evas_Object *obj EINA_UNUSED, void *event_info EINA_UNUSED)
95{ /* called when my_win_main is requested to be deleted */
96 _infra_data_free(data);
97}
98
99static icon_properties *
100_icon_properties_find(icon_properties *icons, char *name)
101{
102 int n;
103
104 for (n = 0; n < N_GESTURE_TYPE; n++)
105 if (!strcmp(icons[n].name, name))
106 return &icons[n];
107
108 return NULL;
109}
110
111static void
112_icon_color_set(icon_properties *i, int r, int g, int b, int a)
113{
114 i->r = r;
115 i->g = g;
116 i->b = b;
117 i->a = a;
118 evas_object_color_set(i->icon, i->r, i->g, i->b, i->a);
119}
120
121static Eina_Bool
122_icon_color_set_cb(void *data)
123{
124#define INC_COLOR(C, NC) \
125 do { \
126 if (abs(i->C - NC) < COLOR_STEP) \
127 i->C = NC; \
128 else \
129 i->C += ((i->C < NC) ? COLOR_STEP : (-COLOR_STEP)); \
130 } while (0)
131
132 int n;
133 icon_properties *icons = data;
134 icon_properties *i;
135
136 for (n = 0; n < N_GESTURE_TYPE; n++)
137 {
138 i = &icons[n];
139
140 INC_COLOR(r,INI_R);
141 INC_COLOR(g,INI_G);
142 INC_COLOR(b,INI_B);
143 INC_COLOR(a,INI_A);
144
145 /* Change Icon color */
146 evas_object_color_set(i->icon, i->r, i->g, i->b, i->a);
147 }
148
149 return ECORE_CALLBACK_RENEW;
150}
151
152static void
153_color_and_icon_set(infra_data *infra, char *name, int n, int max,
154 int r, int g, int b, int a)
155{
156 icon_properties *i;
157 int nn = n;
158 i = _icon_properties_find(infra->icons, name);
159 if (i)
160 {
161 if (n < 1)
162 nn = 1;
163
164 if (n > max)
165 nn = max;
166
167 snprintf(infra->buf, sizeof(infra->buf),
168 "%s/images/g_layer/%s_%d.png", elm_app_data_dir_get(), i->name, nn);
169 elm_image_file_set(i->icon, infra->buf, NULL);
170 _icon_color_set(i, r, g, b, a);
171 }
172}
173
174/* START - Callbacks for gestures */
175static void
176finger_tap_start(void *data , Efl_Gesture *tap)
177{
178 Eina_Vector2 pos = efl_gesture_tap_position_get(tap);
179
180 _color_and_icon_set(data, TAP_NAME, 1, MAX_TAP, START_COLOR);
181 printf("Tap Gesture started x,y=<%f,%f> \n", pos.x, pos.y);
182}
183
184static void
185finger_tap_update(void *data , Efl_Gesture *tap EINA_UNUSED)
186{
187 _color_and_icon_set(data, TAP_NAME, 1, MAX_TAP, UPDATE_COLOR);
188}
189
190static void
191finger_tap_end(void *data , Efl_Gesture *tap)
192{
193 Eina_Vector2 pos = efl_gesture_tap_position_get(tap);
194
195 _color_and_icon_set(data, TAP_NAME, 1, MAX_TAP, END_COLOR);
196 printf("Tap Gesture ended x,y=<%f,%f> \n", pos.x, pos.y);
197}
198
199static void
200finger_tap_abort(void *data , Efl_Gesture *tap EINA_UNUSED)
201{
202 _color_and_icon_set(data, TAP_NAME, 1, MAX_TAP, ABORT_COLOR);
203 printf("Tap Aborted\n");
204}
205
206static void
207tap_gesture_cb(void *data , const Efl_Event *ev)
208{
209 Efl_Gesture *g = ev->info;
210 switch(efl_gesture_state_get(g))
211 {
212 case EFL_GESTURE_STARTED:
213 finger_tap_start(data, g);
214 break;
215 case EFL_GESTURE_UPDATED:
216 finger_tap_update(data, g);
217 break;
218 case EFL_GESTURE_CANCELED:
219 finger_tap_abort(data, g);
220 break;
221 case EFL_GESTURE_FINISHED:
222 finger_tap_end(data, g);
223 break;
224 default:
225 break;
226 }
227}
228
229/* END - Callbacks for gestures */
230
231static Evas_Object *
232create_gesture_box(Evas_Object *win, icon_properties *icons,
233 int idx, const char *name, const char *lb_txt)
234{ /* Creates a box with icon and label, later placed in a table */
235 Evas_Object *lb, *bx = elm_box_add(win);
236 char buf[1024];
237
238 elm_box_padding_set(bx, BX_PADDING_X, BX_PADDING_Y);
239 icons[idx].icon = elm_icon_add(win);
240 icons[idx].name = name;
241 snprintf(buf, sizeof(buf), "%s/images/g_layer/%s_1.png",
242 elm_app_data_dir_get(), icons[idx].name);
243 elm_image_file_set(icons[idx].icon, buf, NULL);
244 elm_image_resizable_set(icons[idx].icon, EINA_FALSE, EINA_FALSE);
245 evas_object_size_hint_align_set(icons[idx].icon, 0.5, 0.5);
246 _icon_color_set(&icons[idx], INI_R, INI_G, INI_B, INI_A);
247 elm_box_pack_end(bx, icons[idx].icon);
248 evas_object_show(icons[idx].icon);
249
250 lb = elm_label_add(win);
251 elm_object_text_set(lb, lb_txt);
252 evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, 0.0);
253 evas_object_size_hint_align_set(lb, 0.5, 0.5);
254 elm_box_pack_end(bx, lb);
255 evas_object_show(lb);
256 evas_object_show(bx);
257
258 return bx;
259}
260
261void
262test_gesture_framework(void *data EINA_UNUSED, Evas_Object *obj EINA_UNUSED,
263 void *event_info EINA_UNUSED)
264{
265 Evas_Object *win, *tb, *lb, *bx;
266 Evas_Object *r; /* Gesture layer transparent object */
267
268 infra_data *infra = _infra_data_alloc();
269
270 win = elm_win_util_standard_add("gesture-layer2", "Gesture Layer 2");
271 elm_win_autodel_set(win, EINA_TRUE);
272 evas_object_smart_callback_add(win, "delete,request", my_win_del, infra);
273
274 /* START - Building icons table */
275 bx = elm_box_add(win);
276 tb = elm_table_add(win);
277 elm_box_pack_end(bx, tb);
278 evas_object_size_hint_weight_set(bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
279 evas_object_size_hint_align_set(tb, 0.5, 0.5);
280 elm_win_resize_object_add(win, bx);
281 evas_object_show(tb);
282 evas_object_show(bx);
283
284 /* Box of Tap icon and label */
285 bx = create_gesture_box(win, infra->icons, 0, TAP_NAME, "Tap");
286 elm_table_pack(tb, bx, 0, 0, 1, 1);
287
288 /* Box of Double Tap icon and label */
289 bx = create_gesture_box(win, infra->icons, 1, DOUBLE_TAP_NAME, "Double Tap");
290 elm_table_pack(tb, bx, 1, 0, 1, 1);
291
292 /* Box of Triple Tap icon and label */
293 bx = create_gesture_box(win, infra->icons, 2, TRIPLE_TAP_NAME, "Triple Tap");
294 elm_table_pack(tb, bx, 2, 0, 1, 1);
295
296 /* Box of Long Tap icon and label */
297 bx = create_gesture_box(win, infra->icons, 3, LONG_TAP_NAME, "Long Tap");
298 elm_table_pack(tb, bx, 3, 0, 1, 1);
299
300 /* Box of Momentum icon and label */
301 bx = create_gesture_box(win, infra->icons, 4, MOMENTUM_NAME, "Momentum");
302 elm_table_pack(tb, bx, 0, 2, 1, 1);
303
304 /* Box of Line icon and label */
305 bx = create_gesture_box(win, infra->icons, 5, LINE_NAME, "Line");
306 elm_table_pack(tb, bx, 1, 2, 1, 1);
307
308 /* Box of Flick icon and label */
309 bx = create_gesture_box(win, infra->icons, 6, FLICK_NAME, "Flick");
310 elm_table_pack(tb, bx, 2, 2, 1, 1);
311
312 /* Box of Zoom icon and label */
313 bx = create_gesture_box(win, infra->icons, 7, ZOOM_NAME, "Zoom");
314 elm_table_pack(tb, bx, 0, 3, 1, 1);
315
316 /* Box of Rotate icon and label */
317 bx = create_gesture_box(win, infra->icons, 8, ROTATE_NAME, "Rotate");
318 elm_table_pack(tb, bx, 1, 3, 1, 1);
319
320 /* Legend of gestures - states */
321 lb = elm_label_add(win);
322 elm_object_text_set(lb, "<b>Gesture States</b>");
323 evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, 0.0);
324 evas_object_size_hint_align_set(lb, EVAS_HINT_FILL, EVAS_HINT_FILL);
325 elm_table_pack(tb, lb, 0, 6, 4, 2);
326 evas_object_show(lb);
327
328 r = evas_object_rectangle_add(evas_object_evas_get(win));
329 evas_object_resize(r, 64, 64);
330 evas_object_color_set(r, INI_R, INI_G, INI_B, INI_A);
331 evas_object_size_hint_weight_set(r, EVAS_HINT_EXPAND, 0.0);
332 evas_object_size_hint_align_set(r, EVAS_HINT_FILL, EVAS_HINT_FILL);
333 elm_table_pack(tb, r, 0, 7, 1, 1);
334 evas_object_show(r);
335
336 lb = elm_label_add(win);
337 elm_object_text_set(lb, "Not Started");
338 evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, 0.0);
339 evas_object_size_hint_align_set(lb, EVAS_HINT_FILL, EVAS_HINT_FILL);
340 elm_table_pack(tb, lb, 1, 7, 3, 1);
341 evas_object_show(lb);
342
343 r = evas_object_rectangle_add(evas_object_evas_get(win));
344 evas_object_resize(r, 64, 64);
345 evas_object_color_set(r, START_COLOR);
346 evas_object_size_hint_weight_set(r, EVAS_HINT_EXPAND, 0.0);
347 evas_object_size_hint_align_set(r, EVAS_HINT_FILL, EVAS_HINT_FILL);
348 elm_table_pack(tb, r, 0, 8, 1, 1);
349 evas_object_show(r);
350
351 lb = elm_label_add(win);
352 elm_object_text_set(lb, "Gesture START");
353 evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, 0.0);
354 evas_object_size_hint_align_set(lb, EVAS_HINT_FILL, EVAS_HINT_FILL);
355 elm_table_pack(tb, lb, 1, 8, 3, 1);
356 evas_object_show(lb);
357
358 r = evas_object_rectangle_add(evas_object_evas_get(win));
359 evas_object_resize(r, 64, 64);
360 evas_object_color_set(r, UPDATE_COLOR);
361 evas_object_size_hint_weight_set(r, EVAS_HINT_EXPAND, 0.0);
362 evas_object_size_hint_align_set(r, EVAS_HINT_FILL, EVAS_HINT_FILL);
363 elm_table_pack(tb, r, 0, 9, 1, 1);
364 evas_object_show(r);
365
366 lb = elm_label_add(win);
367 elm_object_text_set(lb, "Gesture UPDATE");
368 evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, 0.0);
369 evas_object_size_hint_align_set(lb, EVAS_HINT_FILL, EVAS_HINT_FILL);
370 elm_table_pack(tb, lb, 1, 9, 3, 1);
371 evas_object_show(lb);
372
373 r = evas_object_rectangle_add(evas_object_evas_get(win));
374 evas_object_resize(r, 64, 64);
375 evas_object_color_set(r, END_COLOR);
376 evas_object_size_hint_weight_set(r, EVAS_HINT_EXPAND, 0.0);
377 evas_object_size_hint_align_set(r, EVAS_HINT_FILL, EVAS_HINT_FILL);
378 elm_table_pack(tb, r, 0, 10, 1, 1);
379 evas_object_show(r);
380
381 lb = elm_label_add(win);
382 elm_object_text_set(lb, "Gesture END");
383 evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, 0.0);
384 evas_object_size_hint_align_set(lb, EVAS_HINT_FILL, EVAS_HINT_FILL);
385 elm_table_pack(tb, lb, 1, 10, 3, 1);
386 evas_object_show(lb);
387
388 r = evas_object_rectangle_add(evas_object_evas_get(win));
389 evas_object_resize(r, 64, 64);
390 evas_object_color_set(r, ABORT_COLOR);
391 evas_object_size_hint_weight_set(r, EVAS_HINT_EXPAND, 0.0);
392 evas_object_size_hint_align_set(r, EVAS_HINT_FILL, EVAS_HINT_FILL);
393 elm_table_pack(tb, r, 0, 11, 1, 1);
394 evas_object_show(r);
395
396 lb = elm_label_add(win);
397 elm_object_text_set(lb, "Gesture ABORT");
398 evas_object_size_hint_weight_set(lb, EVAS_HINT_EXPAND, 0.0);
399 evas_object_size_hint_align_set(lb, EVAS_HINT_FILL, EVAS_HINT_FILL);
400 elm_table_pack(tb, lb, 1, 11, 3, 1);
401
402 elm_table_padding_set(tb, TB_PADDING_X, TB_PADDING_Y);
403 evas_object_show(lb);
404 /* END - Building icons table */
405
406 r = evas_object_rectangle_add(evas_object_evas_get(win));
407 evas_object_move(r, 250, 300);
408 evas_object_color_set(r, 0, 0, 255, 255);
409 evas_object_resize(r, 70, 70);
410 evas_object_show(r);
411
412 // LISTEN FOR TAP GESTURE
413 efl_event_callback_add(r, EFL_EVENT_GESTURE_TAP, tap_gesture_cb, infra);
414
415 /* Update color state 20 times a second */
416 infra->colortimer = ecore_timer_add(0.05, _icon_color_set_cb, infra->icons);
417
418 evas_object_show(win);
419}