EFL migration revision 67547
[framework/uifw/elementary.git] / tests / src / lib / elm_flip.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 typedef struct _Widget_Data Widget_Data;
5 typedef struct _Slice Slice;
6 typedef struct _Vertex2 Vertex2;
7 typedef struct _Vertex3 Vertex3;
8
9 struct _Slice
10 {
11    Evas_Object *obj;
12    double u[4], v[4], x[4], y[4], z[4];
13 };
14
15 struct _Vertex2
16 {
17    double x, y;
18 };
19
20 struct _Vertex3
21 {
22    double x, y, z;
23 };
24
25 struct _Widget_Data
26 {
27    Evas_Object *obj;
28    Ecore_Animator *animator;
29    double start, len;
30    Elm_Flip_Mode mode;
31    Evas_Object *clip;
32    Evas_Object *event[4];
33    struct {
34       Evas_Object *content, *clip;
35    } front, back;
36    Ecore_Job *job;
37    Evas_Coord down_x, down_y, x, y, ox, oy, w, h;
38    Elm_Flip_Interaction intmode;
39    int dir;
40    double    dir_hitsize[4];
41    Eina_Bool dir_enabled[4];
42    int slices_w, slices_h;
43    Slice **slices, **slices2;
44
45    Eina_Bool state : 1;
46    Eina_Bool down : 1;
47    Eina_Bool finish : 1;
48    Eina_Bool started : 1;
49    Eina_Bool backflip : 1;
50    Eina_Bool pageflip : 1;
51 };
52
53 static const char *widtype = NULL;
54 static void _del_hook(Evas_Object *obj);
55 static void _theme_hook(Evas_Object *obj);
56 static void _sizing_eval(Evas_Object *obj);
57 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
58 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
59
60 static void _state_slices_clear(Widget_Data *st);
61 static void _configure(Evas_Object *obj);
62
63 static const char SIG_ANIMATE_BEGIN[] = "animate,begin";
64 static const char SIG_ANIMATE_DONE[] = "animate,done";
65
66 static const Evas_Smart_Cb_Description _signals[] = {
67    {SIG_ANIMATE_BEGIN, ""},
68    {SIG_ANIMATE_DONE, ""},
69    {NULL, NULL}
70 };
71
72 static void
73 _del_hook(Evas_Object *obj)
74 {
75    Widget_Data *wd = elm_widget_data_get(obj);
76    if (!wd) return;
77    if (wd->animator) ecore_animator_del(wd->animator);
78    _state_slices_clear(wd);
79    free(wd);
80 }
81
82 static void
83 _theme_hook(Evas_Object *obj)
84 {
85    Widget_Data *wd = elm_widget_data_get(obj);
86    if (!wd) return;
87    _sizing_eval(obj);
88 }
89
90 static Eina_Bool
91 _elm_flip_focus_next_hook(const Evas_Object *obj, Elm_Focus_Direction dir, Evas_Object **next)
92 {
93    Widget_Data *wd = elm_widget_data_get(obj);
94
95    if (!wd)
96      return EINA_FALSE;
97
98    /* Try Focus cycle in subitem */
99    if (wd->state)
100      return elm_widget_focus_next_get(wd->front.content, dir, next);
101    else
102      return elm_widget_focus_next_get(wd->back.content, dir, next);
103
104 }
105
106 static void
107 _sizing_eval(Evas_Object *obj)
108 {
109    Widget_Data *wd = elm_widget_data_get(obj);
110    Evas_Coord minw = -1, minh = -1, minw2 = -1, minh2 = -1;
111    Evas_Coord maxw = -1, maxh = -1, maxw2 = -1, maxh2 = -1;
112    int fingx = 0, fingy = 0;
113    if (!wd) return;
114    if (wd->front.content)
115      evas_object_size_hint_min_get(wd->front.content, &minw, &minh);
116    if (wd->back.content)
117      evas_object_size_hint_min_get(wd->back.content, &minw2, &minh2);
118    if (wd->front.content)
119      evas_object_size_hint_max_get(wd->front.content, &maxw, &maxh);
120    if (wd->back.content)
121      evas_object_size_hint_max_get(wd->back.content, &maxw2, &maxh2);
122
123    if (minw2 > minw) minw = minw2;
124    if (minh2 > minh) minh = minh2;
125    if ((maxw2 >= 0) && (maxw2 < maxw)) maxw = maxw2;
126    if ((maxh2 >= 0) && (maxh2 < maxh)) maxh = maxh2;
127
128    if (wd->dir_enabled[0]) fingy++;
129    if (wd->dir_enabled[1]) fingy++;
130    if (wd->dir_enabled[2]) fingx++;
131    if (wd->dir_enabled[3]) fingx++;
132
133    elm_coords_finger_size_adjust(fingx, &minw, fingy, &minh);
134
135    evas_object_size_hint_min_set(obj, minw, minh);
136    evas_object_size_hint_max_set(obj, maxw, maxh);
137 }
138
139 static void
140 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
141 {
142    Widget_Data *wd = elm_widget_data_get(data);
143    if (!wd) return;
144    _sizing_eval(data);
145 }
146
147 static void
148 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
149 {
150    Widget_Data *wd = elm_widget_data_get(obj);
151    Evas_Object *sub = event_info;
152    if (!wd) return;
153    if (sub == wd->front.content)
154      {
155         evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
156                                             _changed_size_hints, obj);
157         wd->front.content = NULL;
158         evas_object_hide(wd->front.clip);
159         _sizing_eval(obj);
160      }
161    else if (sub == wd->back.content)
162      {
163         evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
164                                             _changed_size_hints, obj);
165         wd->back.content = NULL;
166         evas_object_hide(wd->back.clip);
167         _sizing_eval(obj);
168      }
169 }
170
171 static Slice *
172 _slice_new(Widget_Data *st __UNUSED__, Evas_Object *obj)
173 {
174    Slice *sl;
175
176    sl = calloc(1, sizeof(Slice));
177    if (!sl) return NULL;
178    sl->obj = evas_object_image_add(evas_object_evas_get(obj));
179    elm_widget_sub_object_add(st->obj, sl->obj);
180    evas_object_clip_set(sl->obj, evas_object_clip_get(st->obj));
181    evas_object_smart_member_add(sl->obj, st->obj);
182    evas_object_image_smooth_scale_set(sl->obj, 0);
183    evas_object_pass_events_set(sl->obj, 1);
184    evas_object_image_source_set(sl->obj, obj);
185    return sl;
186 }
187
188 static void
189 _slice_free(Slice *sl)
190 {
191    evas_object_del(sl->obj);
192    free(sl);
193 }
194
195 static void
196 _slice_apply(Widget_Data *st, Slice *sl,
197              Evas_Coord x __UNUSED__, Evas_Coord y __UNUSED__, Evas_Coord w, Evas_Coord h __UNUSED__,
198              Evas_Coord ox, Evas_Coord oy, Evas_Coord ow, Evas_Coord oh)
199 {
200    Evas_Map *m;
201    int i;
202
203    m = evas_map_new(4);
204    if (!m) return;
205    evas_map_smooth_set(m, 0);
206    for (i = 0; i < 4; i++)
207      {
208         evas_map_point_color_set(m, i, 255, 255, 255, 255);
209         if (st->dir == 0)
210           {
211              int p[4] = { 0, 1, 2, 3 };
212              evas_map_point_coord_set(m, i, ox + sl->x[p[i]], oy + sl->y[p[i]], sl->z[p[i]]);
213              evas_map_point_image_uv_set(m, i, sl->u[p[i]] , sl->v[p[i]]);
214           }
215         else if (st->dir == 1)
216           {
217              int p[4] = { 1, 0, 3, 2 };
218              evas_map_point_coord_set(m, i, ox + (w - sl->x[p[i]]), oy + sl->y[p[i]], sl->z[p[i]]);
219              evas_map_point_image_uv_set(m, i, ow - sl->u[p[i]] , sl->v[p[i]]);
220           }
221         else if (st->dir == 2)
222           {
223              int p[4] = { 1, 0, 3, 2 };
224              evas_map_point_coord_set(m, i, ox + sl->y[p[i]], oy + sl->x[p[i]], sl->z[p[i]]);
225              evas_map_point_image_uv_set(m, i, sl->v[p[i]] , sl->u[p[i]]);
226           }
227         else/* if (st->dir == 3) will be this anyway */
228           {
229              int p[4] = { 0, 1, 2, 3 };
230              evas_map_point_coord_set(m, i, ox + sl->y[p[i]], oy + (w - sl->x[p[i]]), sl->z[p[i]]);
231              evas_map_point_image_uv_set(m, i, sl->v[p[i]] , oh - sl->u[p[i]]);
232           }
233      }
234    evas_object_map_enable_set(sl->obj, EINA_TRUE);
235    evas_object_image_fill_set(sl->obj, 0, 0, ow, oh);
236    evas_object_map_set(sl->obj, m);
237    evas_map_free(m);
238 }
239
240 static void
241 _slice_3d(Widget_Data *st __UNUSED__, Slice *sl, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
242 {
243    Evas_Map *m = (Evas_Map *)evas_object_map_get(sl->obj);
244    int i;
245
246    if (!m) return;
247    // vanishing point is center of page, and focal dist is 1024
248    evas_map_util_3d_perspective(m, x + (w / 2), y + (h / 2), 0, 1024);
249    for (i = 0; i < 4; i++)
250      {
251         Evas_Coord x, y, z;
252         evas_map_point_coord_get(m, i, &x, &y, &z);
253         evas_map_point_coord_set(m, i, x, y, 0);
254      }
255    if (evas_map_util_clockwise_get(m)) evas_object_show(sl->obj);
256    else evas_object_hide(sl->obj);
257    evas_object_map_set(sl->obj, m);
258 }
259
260 static void
261 _slice_light(Widget_Data *st __UNUSED__, Slice *sl, Evas_Coord x, Evas_Coord y, Evas_Coord w, Evas_Coord h)
262 {
263    Evas_Map *m = (Evas_Map *)evas_object_map_get(sl->obj);
264    int i;
265
266    if (!m) return;
267    evas_map_util_3d_lighting(m,
268                              // light position
269                              // (centered over page 10 * h toward camera)
270                              x + (w / 2)  , y + (h / 2)  , -10000,
271                              255, 255, 255, // light color
272                              0 , 0 , 0); // ambient minimum
273    // multiply brightness by 1.2 to make lightish bits all white so we dont
274    // add shading where we could otherwise be pure white
275    for (i = 0; i < 4; i++)
276      {
277         int r, g, b, a;
278
279         evas_map_point_color_get(m, i, &r, &g, &b, &a);
280         r = (double)r * 1.2; if (r > 255) r = 255;
281         g = (double)g * 1.2; if (g > 255) g = 255;
282         b = (double)b * 1.2; if (b > 255) b = 255;
283         evas_map_point_color_set(m, i, r, g, b, a);
284      }
285    evas_object_map_set(sl->obj, m);
286 }
287
288 static void
289 _slice_xyz(Widget_Data *st __UNUSED__, Slice *sl,
290            double x1, double y1, double z1,
291            double x2, double y2, double z2,
292            double x3, double y3, double z3,
293            double x4, double y4, double z4)
294 {
295    sl->x[0] = x1; sl->y[0] = y1; sl->z[0] = z1;
296    sl->x[1] = x2; sl->y[1] = y2; sl->z[1] = z2;
297    sl->x[2] = x3; sl->y[2] = y3; sl->z[2] = z3;
298    sl->x[3] = x4; sl->y[3] = y4; sl->z[3] = z4;
299 }
300
301 static void
302 _slice_uv(Widget_Data *st __UNUSED__, Slice *sl,
303           double u1, double v1,
304           double u2, double v2,
305           double u3, double v3,
306           double u4, double v4)
307 {
308    sl->u[0] = u1; sl->v[0] = v1;
309    sl->u[1] = u2; sl->v[1] = v2;
310    sl->u[2] = u3; sl->v[2] = v3;
311    sl->u[3] = u4; sl->v[3] = v4;
312 }
313
314 static void
315 _deform_point(Vertex2 *vi, Vertex3 *vo, double rho, double theta, double A)
316 {
317    // ^Y
318    // |
319    // |    X
320    // +---->
321    // theta == cone angle (0 -> PI/2)
322    // A     == distance of cone apex from origin
323    // rho   == angle of cone from vertical axis (...-PI/2 to PI/2...)
324    Vertex3  v1;
325    double d, r, b;
326
327    d = sqrt((vi->x * vi->x) + pow(vi->y - A, 2));
328    r = d * sin(theta);
329    b = asin(vi->x / d) / sin(theta);
330
331    v1.x = r * sin(b);
332    v1.y = d + A - (r * (1 - cos(b)) * sin(theta));
333    v1.z = r * (1 - cos(b)) * cos(theta);
334
335    vo->x = (v1.x * cos(rho)) - (v1.z * sin(rho));
336    vo->y = v1.y;
337    vo->z = (v1.x * sin(rho)) + (v1.z * cos(rho));
338 }
339
340 static void
341 _interp_point(Vertex3 *vi1, Vertex3 *vi2, Vertex3 *vo, double v)
342 {
343    vo->x = (v * vi2->x) + ((1.0 - v) * vi1->x);
344    vo->y = (v * vi2->y) + ((1.0 - v) * vi1->y);
345    vo->z = (v * vi2->z) + ((1.0 - v) * vi1->z);
346 }
347
348 static void
349 _state_slices_clear(Widget_Data *st)
350 {
351    int i, j, num;
352
353    if (st->slices)
354      {
355         num = 0;
356         for (j = 0; j < st->slices_h; j++)
357           {
358              for (i = 0; i < st->slices_w; i++)
359                {
360                   if (st->slices[num]) _slice_free(st->slices[num]);
361                   if (st->slices2[num]) _slice_free(st->slices2[num]);
362                   num++;
363                }
364           }
365         free(st->slices);
366         free(st->slices2);
367         st->slices = NULL;
368         st->slices2 = NULL;
369      }
370    st->slices_w = 0;
371    st->slices_h = 0;
372 }
373
374 static int
375 _slice_obj_color_sum(Slice *s, int p, int *r, int *g, int *b, int *a)
376 {
377    Evas_Map *m;
378    int rr = 0, gg = 0, bb = 0, aa = 0;
379
380    if (!s) return 0;
381    m = (Evas_Map *)evas_object_map_get(s->obj);
382    if (!m) return 0;
383    evas_map_point_color_get(m, p, &rr, &gg, &bb, &aa);
384    *r += rr; *g += gg; *b += bb; *a += aa;
385    return 1;
386 }
387
388 static void
389 _slice_obj_color_set(Slice *s, int p, int r, int g, int b, int a)
390 {
391    Evas_Map *m;
392
393    if (!s) return;
394    m = (Evas_Map *)evas_object_map_get(s->obj);
395    if (!m) return;
396    evas_map_point_color_set(m, p, r, g, b, a);
397    evas_object_map_set(s->obj, m);
398 }
399
400 static void
401 _slice_obj_vert_color_merge(Slice *s1, int p1, Slice *s2, int p2,
402                             Slice *s3, int p3, Slice *s4, int p4)
403 {
404    int r = 0, g = 0, b = 0, a = 0, n = 0;
405
406    n += _slice_obj_color_sum(s1, p1, &r, &g, &b, &a);
407    n += _slice_obj_color_sum(s2, p2, &r, &g, &b, &a);
408    n += _slice_obj_color_sum(s3, p3, &r, &g, &b, &a);
409    n += _slice_obj_color_sum(s4, p4, &r, &g, &b, &a);
410
411    if (n < 1) return;
412    r /= n; g /= n; b /= n; a /= n;
413
414    _slice_obj_color_set(s1, p1, r, g, b, a);
415    _slice_obj_color_set(s2, p2, r, g, b, a);
416    _slice_obj_color_set(s3, p3, r, g, b, a);
417    _slice_obj_color_set(s4, p4, r, g, b, a);
418 }
419
420 static int
421 _state_update(Widget_Data *st)
422 {
423    Evas_Coord x1, y1, x2, y2, mx, my;
424    Evas_Coord x, y, w, h, ox, oy, ow, oh;
425    int i, j, num, nn, jump, num2;
426    Slice *sl;
427    double b, minv = 0.0, minva, mgrad;
428    int gx, gy, gszw, gszh, gw, gh, col, row, nw, nh;
429    double rho, A, theta, perc, percm, n, rhol, Al, thetal;
430    Vertex3 *tvo, *tvol;
431    Evas_Object *front, *back;
432
433    st->backflip = 1;
434    if (st->state)
435      {
436         front = st->front.content;
437         back = st->front.content;
438      }
439    else
440      {
441         front = st->back.content;
442         back = st->back.content;
443      }
444
445    evas_object_geometry_get(st->obj, &x, &y, &w, &h);
446    ox = x; oy = y; ow = w; oh = h;
447    x1 = st->down_x;
448    y1 = st->down_y;
449    x2 = st->x;
450    y2 = st->y;
451
452    if (st->dir == 0)
453      {
454         // no nothing. left drag is standard
455      }
456    else if (st->dir == 1)
457      {
458         x1 = (w - 1) - x1;
459         x2 = (w - 1) - x2;
460      }
461    else if (st->dir == 2)
462      {
463         Evas_Coord tmp;
464
465         tmp = x1; x1 = y1; y1 = tmp;
466         tmp = x2; x2 = y2; y2 = tmp;
467         tmp = w; w = h; h = tmp;
468      }
469    else/* if (st->dir == 3) will be this anyway */
470      {
471         Evas_Coord tmp;
472
473         tmp = x1; x1 = y1; y1 = tmp;
474         tmp = x2; x2 = y2; y2 = tmp;
475         tmp = w; w = h; h = tmp;
476         x1 = (w - 1) - x1;
477         x2 = (w - 1) - x2;
478      }
479
480    if (x2 >= x1) x2 = x1 - 1;
481    mx = (x1 + x2) / 2;
482    my = (y1 + y2) / 2;
483
484    if (mx < 0) mx = 0;
485    else if (mx >= w) mx = w - 1;
486    if (my < 0) my = 0;
487    else if (my >= h) my = h - 1;
488
489    mgrad = (double)(y1 - y2) / (double)(x1 - x2);
490
491    if (mx < 1) mx = 1; // quick hack to keep curl line visible
492
493    if (mgrad == 0.0) // special horizontal case
494       mgrad = 0.001; // quick dirty hack for now
495    // else
496      {
497         minv = 1.0 / mgrad;
498         // y = (m * x) + b
499         b = my + (minv * mx);
500      }
501    if ((b >= -5) && (b <= (h + 5)))
502      {
503         if (minv > 0.0) // clamp to h
504           {
505              minv = (double)(h + 5 - my) / (double)(mx);
506              b = my + (minv * mx);
507           }
508         else // clamp to 0
509           {
510              minv = (double)(-5 - my) / (double)(mx);
511              b = my + (minv * mx);
512           }
513      }
514
515    perc = (double)x2 / (double)x1;
516    percm = (double)mx / (double)x1;
517    if (perc < 0.0) perc = 0.0;
518    else if (perc > 1.0) perc = 1.0;
519    if (percm < 0.0) percm = 0.0;
520    else if (percm > 1.0) percm = 1.0;
521
522    minva = atan(minv) / (M_PI / 2);
523    if (minva < 0.0) minva = -minva;
524
525    // A = apex of cone
526    if (b <= 0) A = b;
527    else A = h - b;
528    if (A < -(h * 20)) A = -h * 20;
529    //--//
530    Al = -5;
531
532    // rho = is how much the page is turned
533    n = 1.0 - perc;
534    n = 1.0 - cos(n * M_PI / 2.0);
535    n = n * n;
536    rho = -(n * M_PI);
537    //--//
538    rhol = -(n * M_PI);
539
540    // theta == curliness (how much page culrs in on itself
541    n = sin((1.0 - perc) * M_PI);
542    n = n * 1.2;
543    theta = 7.86 + n;
544    //--//
545    n = sin((1.0 - perc) * M_PI);
546    n = 1.0 - n;
547    n = n * n;
548    n = 1.0 - n;
549    thetal = 7.86 + n;
550
551    nw = 16;
552    nh = 16;
553    gszw = w / nw;
554    gszh = h / nh;
555    if (gszw < 4) gszw = 4;
556    if (gszh < 4) gszh = 4;
557
558    nw = (w + gszw - 1) / gszw;
559    nh = (h + gszh - 1) / gszh;
560    if ((st->slices_w != nw) || (st->slices_h != nh)) _state_slices_clear(st);
561    st->slices_w = nw;
562    st->slices_h = nh;
563    if (!st->slices)
564      {
565         st->slices = calloc(st->slices_w * st->slices_h, sizeof(Slice *));
566         if (!st->slices) return 0;
567         st->slices2 = calloc(st->slices_w * st->slices_h, sizeof(Slice *));
568         if (!st->slices2)
569           {
570              free(st->slices);
571              st->slices = NULL;
572              return 0;
573           }
574      }
575
576    num = (st->slices_w + 1) * (st->slices_h + 1);
577
578    tvo = alloca(sizeof(Vertex3) * num);
579    tvol = alloca(sizeof(Vertex3) * (st->slices_w + 1));
580
581    for (col = 0, gx = 0; gx <= (w + gszw - 1); gx += gszw, col++)
582      {
583         Vertex2 vil;
584
585         vil.x = gx;
586         vil.y = h - ((gx * h) / (w + gszw - 1));
587         _deform_point(&vil, &(tvol[col]), rhol, thetal, Al);
588      }
589
590    n = minva * sin(perc * M_PI);
591    n = n * n;
592
593    num = 0;
594    for (col = 0, gx = 0; gx <= (w + gszw - 1); gx += gszw, col++)
595      {
596         for (gy = 0; gy <= (h + gszh - 1); gy += gszh)
597           {
598              Vertex2 vi;
599              Vertex3 vo, tvo1;
600
601              if (gx > w) vi.x = w;
602              else vi.x = gx;
603              if (gy > h) vi.y = h;
604              else vi.y = gy;
605              _deform_point(&vi, &vo, rho, theta, A);
606              tvo1 = tvol[col];
607              if (gy > h) tvo1.y = h;
608              else tvo1.y = gy;
609              _interp_point(&vo, &tvo1, &(tvo[num]), n);
610              num++;
611           }
612      }
613
614    jump = st->slices_h + 1;
615    for (col = 0, gx = 0; gx < w; gx += gszw, col++)
616      {
617         num = st->slices_h * col;
618         num2 = jump * col;
619
620         gw = gszw;
621         if ((gx + gw) > w) gw = w - gx;
622
623         for (row = 0, gy = 0; gy < h; gy += gszh, row++)
624           {
625              Vertex3 vo[4];
626
627              if (b > 0) nn = num + st->slices_h - row - 1;
628              else nn = num + row;
629
630              gh = gszh;
631              if ((gy + gh) > h) gh = h - gy;
632
633              vo[0] = tvo[num2 + row];
634              vo[1] = tvo[num2 + row + jump];
635              vo[2] = tvo[num2 + row + jump + 1];
636              vo[3] = tvo[num2 + row + 1];
637 #define SWP(a, b) do {typeof(a) vt; vt = (a); (a) = (b); (b) = vt;} while (0)
638              if (b > 0)
639                {
640                   SWP(vo[0], vo[3]);
641                   SWP(vo[1], vo[2]);
642                   vo[0].y = h - vo[0].y;
643                   vo[1].y = h - vo[1].y;
644                   vo[2].y = h - vo[2].y;
645                   vo[3].y = h - vo[3].y;
646                }
647
648              // FRONT
649              sl = st->slices[nn];
650              if (!sl)
651                {
652                   sl = _slice_new(st, front);
653                   st->slices[nn] = sl;
654                }
655              _slice_xyz(st, sl,
656                         vo[0].x, vo[0].y, vo[0].z,
657                         vo[1].x, vo[1].y, vo[1].z,
658                         vo[2].x, vo[2].y, vo[2].z,
659                         vo[3].x, vo[3].y, vo[3].z);
660              if (b <= 0)
661                 _slice_uv(st, sl,
662                           gx,       gy,       gx + gw,  gy,
663                           gx + gw,  gy + gh,  gx,       gy + gh);
664              else
665                 _slice_uv(st, sl,
666                           gx,       h - (gy + gh), gx + gw,  h - (gy + gh),
667                           gx + gw,  h - gy,        gx,       h - gy);
668
669                           // BACK
670              sl = st->slices2[nn];
671              if (!sl)
672                {
673                   sl = _slice_new(st, back);
674                   st->slices2[nn] = sl;
675                }
676
677              _slice_xyz(st, sl,
678                         vo[1].x, vo[1].y, vo[1].z,
679                         vo[0].x, vo[0].y, vo[0].z,
680                         vo[3].x, vo[3].y, vo[3].z,
681                         vo[2].x, vo[2].y, vo[2].z);
682              if (st->backflip)
683                {
684                   if (b <= 0)
685                      _slice_uv(st, sl,
686                                gx + gw, gy,       gx,       gy,
687                                gx,      gy + gh,  gx + gw,  gy + gh);
688                   else
689                      _slice_uv(st, sl,
690                                gx + gw, h - (gy + gh), gx,      h - (gy + gh),
691                                gx,      h - gy,        gx + gw, h - gy);
692                }
693              else
694                {
695                   if (b <= 0)
696                      _slice_uv(st, sl,
697                                w - (gx + gw), gy,       w - (gx),      gy,
698                                w - (gx),      gy + gh,  w - (gx + gw), gy + gh);
699                   else
700                      _slice_uv(st, sl,
701                                w - (gx + gw), h - (gy + gh), w - (gx),      h - (gy + gh),
702                                w - (gx),      h - gy,        w - (gx + gw), h - gy);
703                }
704           }
705      }
706
707    num = 0;
708    for (j = 0; j < st->slices_h; j++)
709      {
710         for (i = 0; i < st->slices_w; i++)
711           {
712              _slice_apply(st, st->slices[num], x, y, w, h, ox, oy, ow, oh);
713              _slice_apply(st, st->slices2[num], x, y, w, h, ox, oy, ow, oh);
714              _slice_light(st, st->slices[num], ox, oy, ow, oh);
715              _slice_light(st, st->slices2[num], ox, oy, ow, oh);
716              num++;
717           }
718      }
719
720    for (i = 0; i <= st->slices_w; i++)
721      {
722         num = i * st->slices_h;
723         for (j = 0; j <= st->slices_h; j++)
724           {
725              Slice *s[4];
726
727              s[0] = s[1] = s[2] = s[3] = NULL;
728              if ((i > 0)            && (j > 0))
729                 s[0] = st->slices[num - 1 - st->slices_h];
730              if ((i < st->slices_w) && (j > 0))
731                 s[1] = st->slices[num - 1];
732              if ((i > 0)            && (j < st->slices_h))
733                 s[2] = st->slices[num - st->slices_h];
734              if ((i < st->slices_w) && (j < st->slices_h))
735                 s[3] = st->slices[num];
736              if (st->dir == 0)
737                 _slice_obj_vert_color_merge(s[0], 2, s[1], 3,
738                                             s[2], 1, s[3], 0);
739              else if (st->dir == 1)
740                 _slice_obj_vert_color_merge(s[0], 3, s[1], 2,
741                                             s[2], 0, s[3], 1);
742              else if (st->dir == 2)
743                 _slice_obj_vert_color_merge(s[0], 3, s[1], 2,
744                                             s[2], 0, s[3], 1);
745              else/* if (st->dir == 3) will be this anyway */
746                 _slice_obj_vert_color_merge(s[0], 2, s[1], 3,
747                                             s[2], 1, s[3], 0);
748              s[0] = s[1] = s[2] = s[3] = NULL;
749              if ((i > 0)            && (j > 0))
750                 s[0] = st->slices2[num - 1 - st->slices_h];
751              if ((i < st->slices_w) && (j > 0))
752                 s[1] = st->slices2[num - 1];
753              if ((i > 0)            && (j < st->slices_h))
754                 s[2] = st->slices2[num - st->slices_h];
755              if ((i < st->slices_w) && (j < st->slices_h))
756                 s[3] = st->slices2[num];
757              if (st->dir == 0)
758                 _slice_obj_vert_color_merge(s[0], 3, s[1], 2,
759                                             s[2], 0, s[3], 1);
760              else if (st->dir == 1)
761                 _slice_obj_vert_color_merge(s[0], 2, s[1], 3,
762                                             s[2], 1, s[3], 0);
763              else if (st->dir == 2)
764                 _slice_obj_vert_color_merge(s[0], 2, s[1], 3,
765                                             s[2], 1, s[3], 0);
766              else/* if (st->dir == 3) will be this anyway */
767                 _slice_obj_vert_color_merge(s[0], 3, s[1], 2,
768                                             s[2], 0, s[3], 1);
769              num++;
770           }
771      }
772
773    num = 0;
774    for (i = 0; i < st->slices_w; i++)
775      {
776         for (j = 0; j < st->slices_h; j++)
777           {
778              _slice_3d(st, st->slices[num], ox, oy, ow, oh);
779              _slice_3d(st, st->slices2[num], ox, oy, ow, oh);
780              num++;
781           }
782      }
783
784    return 1;
785 }
786
787 static void
788 _state_end(Widget_Data *st)
789 {
790    _state_slices_clear(st);
791 }
792
793
794 static void
795 flip_show_hide(Evas_Object *obj)
796 {
797    Widget_Data *wd = elm_widget_data_get(obj);
798    if (elm_flip_front_get(obj))
799      {
800         if (wd->pageflip)
801           {
802              if (wd->front.content)
803                {
804                   evas_object_move(wd->front.content, 4999, 4999);
805                   evas_object_show(wd->front.clip);
806                }
807              else
808                 evas_object_hide(wd->front.clip);
809              if (wd->back.content)
810                 evas_object_show(wd->back.clip);
811              else
812                 evas_object_hide(wd->back.clip);
813           }
814         else
815           {
816              if (wd->front.content)
817                 evas_object_show(wd->front.clip);
818              else
819                 evas_object_hide(wd->front.clip);
820              if (wd->back.content)
821                 evas_object_hide(wd->back.clip);
822              else
823                 evas_object_hide(wd->back.clip);
824           }
825      }
826    else
827      {
828         if (wd->pageflip)
829           {
830              if (wd->front.content)
831                 evas_object_show(wd->front.clip);
832              else
833                 evas_object_hide(wd->front.clip);
834              if (wd->back.content)
835                {
836                   evas_object_move(wd->back.content, 4999, 4999);
837                   evas_object_show(wd->back.clip);
838                }
839              else
840                 evas_object_hide(wd->back.clip);
841           }
842         else
843           {
844              if (wd->front.content)
845                 evas_object_hide(wd->front.clip);
846              else
847                 evas_object_hide(wd->front.clip);
848              if (wd->back.content)
849                 evas_object_show(wd->back.clip);
850              else
851                 evas_object_hide(wd->back.clip);
852           }
853      }
854 }
855
856 static void
857 _flip_do(Evas_Object *obj, double t, Elm_Flip_Mode mode, int lin, int rev)
858 {
859    Evas_Coord x, y, w, h;
860    double p, deg, pp;
861    Evas_Map *mf, *mb;
862    Evas_Coord cx, cy, px, py, foc;
863    int lx, ly, lz, lr, lg, lb, lar, lag, lab;
864    Widget_Data *wd = elm_widget_data_get(obj);
865
866    if (!wd) return;
867
868    mf = evas_map_new(4);
869    evas_map_smooth_set(mf, 0);
870    mb = evas_map_new(4);
871    evas_map_smooth_set(mb, 0);
872
873    if (wd->front.content)
874      {
875         const char *type = evas_object_type_get(wd->front.content);
876
877         // FIXME: only handles filled obj
878         if ((type) && (!strcmp(type, "image")))
879           {
880              int iw, ih;
881              evas_object_image_size_get(wd->front.content, &iw, &ih);
882              evas_object_geometry_get(wd->front.content, &x, &y, &w, &h);
883              evas_map_util_points_populate_from_geometry(mf, x, y, w, h, 0);
884              evas_map_point_image_uv_set(mf, 0, 0, 0);
885              evas_map_point_image_uv_set(mf, 1, iw, 0);
886              evas_map_point_image_uv_set(mf, 2, iw, ih);
887              evas_map_point_image_uv_set(mf, 3, 0, ih);
888           }
889         else
890           {
891              evas_object_geometry_get(wd->front.content, &x, &y, &w, &h);
892              evas_map_util_points_populate_from_geometry(mf, x, y, w, h, 0);
893           }
894      }
895    if (wd->back.content)
896      {
897         const char *type = evas_object_type_get(wd->back.content);
898
899         if ((type) && (!strcmp(type, "image")))
900           {
901              int iw, ih;
902              evas_object_image_size_get(wd->back.content, &iw, &ih);
903              evas_object_geometry_get(wd->back.content, &x, &y, &w, &h);
904              evas_map_util_points_populate_from_geometry(mb, x, y, w, h, 0);
905              evas_map_point_image_uv_set(mb, 0, 0, 0);
906              evas_map_point_image_uv_set(mb, 1, iw, 0);
907              evas_map_point_image_uv_set(mb, 2, iw, ih);
908              evas_map_point_image_uv_set(mb, 3, 0, ih);
909           }
910         else
911           {
912              evas_object_geometry_get(wd->back.content, &x, &y, &w, &h);
913              evas_map_util_points_populate_from_geometry(mb, x, y, w, h, 0);
914           }
915      }
916
917    evas_object_geometry_get(obj, &x, &y, &w, &h);
918
919    cx = x + (w / 2);
920    cy = y + (h / 2);
921
922    px = x + (w / 2);
923    py = y + (h / 2);
924    foc = 2048;
925
926    lx = cx;
927    ly = cy;
928    lz = -10000;
929    lr = 255;
930    lg = 255;
931    lb = 255;
932    lar = 0;
933    lag = 0;
934    lab = 0;
935
936    switch (mode)
937      {
938       case ELM_FLIP_ROTATE_Y_CENTER_AXIS:
939          p = 1.0 - t;
940          pp = p;
941          if (!lin) pp = (p * p);
942          p = 1.0 - pp;
943          if (wd->state) deg = 180.0 * p;
944          else deg = 180 + (180.0 * p);
945          if (rev) deg = -deg;
946          evas_map_util_3d_rotate(mf, 0.0, deg, 0.0, cx, cy, 0);
947          evas_map_util_3d_rotate(mb, 0.0, 180 + deg, 0.0, cx, cy, 0);
948          break;
949       case ELM_FLIP_ROTATE_X_CENTER_AXIS:
950          p = 1.0 - t;
951          pp = p;
952          if (!lin) pp = (p * p);
953          p = 1.0 - pp;
954          if (wd->state) deg = 180.0 * p;
955          else deg = 180 + (180.0 * p);
956          if (rev) deg = -deg;
957          evas_map_util_3d_rotate(mf, deg, 0.0, 0.0, cx, cy, 0);
958          evas_map_util_3d_rotate(mb, 180.0 + deg, 0.0, 0.0, cx, cy, 0);
959          break;
960       case ELM_FLIP_ROTATE_XZ_CENTER_AXIS:
961          p = 1.0 - t;
962          pp = p;
963          if (!lin) pp = (p * p);
964          p = 1.0 - pp;
965          if (wd->state) deg = 180.0 * p;
966          else deg = 180 + (180.0 * p);
967          if (rev) deg = -deg;
968          evas_map_util_3d_rotate(mf, deg, 0.0, deg, cx, cy, 0);
969          evas_map_util_3d_rotate(mb, 180 + deg, 0.0, 180 + deg, cx, cy, 0);
970          break;
971       case ELM_FLIP_ROTATE_YZ_CENTER_AXIS:
972          p = 1.0 - t;
973          pp = p;
974          if (!lin) pp = (p * p);
975          p = 1.0 - pp;
976          if (wd->state) deg = 180.0 * p;
977          else deg = 180 + (180.0 * p);
978          if (rev) deg = -deg;
979          evas_map_util_3d_rotate(mf, 0.0, deg, deg, cx, cy, 0);
980          evas_map_util_3d_rotate(mb, 0.0, 180.0 + deg, 180.0 + deg, cx, cy, 0);
981          break;
982       case ELM_FLIP_CUBE_LEFT:
983          p = 1.0 - t;
984          pp = p;
985          if (!lin) pp = (p * p);
986          p = 1.0 - pp;
987          deg = -90.0 * p;
988          if (wd->state)
989            {
990               evas_map_util_3d_rotate(mf, 0.0, deg, 0.0, cx, cy, w / 2);
991               evas_map_util_3d_rotate(mb, 0.0, deg + 90, 0.0, cx, cy, w / 2);
992            }
993          else
994            {
995               evas_map_util_3d_rotate(mf, 0.0, deg + 90, 0.0, cx, cy, w / 2);
996               evas_map_util_3d_rotate(mb, 0.0, deg, 0.0, cx, cy, w / 2);
997            }
998          break;
999       case ELM_FLIP_CUBE_RIGHT:
1000          p = 1.0 - t;
1001          pp = p;
1002          if (!lin) pp = (p * p);
1003          p = 1.0 - pp;
1004          deg = 90.0 * p;
1005          if (wd->state)
1006            {
1007               evas_map_util_3d_rotate(mf, 0.0, deg, 0.0, cx, cy, w / 2);
1008               evas_map_util_3d_rotate(mb, 0.0, deg - 90, 0.0, cx, cy, w / 2);
1009            }
1010          else
1011            {
1012               evas_map_util_3d_rotate(mf, 0.0, deg - 90, 0.0, cx, cy, w / 2);
1013               evas_map_util_3d_rotate(mb, 0.0, deg, 0.0, cx, cy, w / 2);
1014            }
1015          break;
1016       case ELM_FLIP_CUBE_UP:
1017          p = 1.0 - t;
1018          pp = p;
1019          if (!lin) pp = (p * p);
1020          p = 1.0 - pp;
1021          deg = -90.0 * p;
1022          if (wd->state)
1023            {
1024               evas_map_util_3d_rotate(mf, deg, 0.0, 0.0, cx, cy, h / 2);
1025               evas_map_util_3d_rotate(mb, deg + 90, 0.0, 0.0, cx, cy, h / 2);
1026            }
1027          else
1028            {
1029               evas_map_util_3d_rotate(mf, deg + 90, 0.0, 0.0, cx, cy, h / 2);
1030               evas_map_util_3d_rotate(mb, deg, 0.0, 0.0, cx, cy, h / 2);
1031            }
1032          break;
1033       case ELM_FLIP_CUBE_DOWN:
1034          p = 1.0 - t;
1035          pp = p;
1036          if (!lin) pp = (p * p);
1037          p = 1.0 - pp;
1038          deg = 90.0 * p;
1039          if (wd->state)
1040            {
1041               evas_map_util_3d_rotate(mf, deg, 0.0, 0.0, cx, cy, h / 2);
1042               evas_map_util_3d_rotate(mb, deg - 90, 0.0, 0.0, cx, cy, h / 2);
1043            }
1044          else
1045            {
1046               evas_map_util_3d_rotate(mf, deg - 90, 0.0, 0.0, cx, cy, h / 2);
1047               evas_map_util_3d_rotate(mb, deg, 0.0, 0.0, cx, cy, h / 2);
1048            }
1049          break;
1050       case ELM_FLIP_PAGE_LEFT:
1051         break;
1052       case ELM_FLIP_PAGE_RIGHT:
1053         break;
1054       case ELM_FLIP_PAGE_UP:
1055         break;
1056       case ELM_FLIP_PAGE_DOWN:
1057         break;
1058       default:
1059          break;
1060      }
1061
1062
1063    if (wd->front.content)
1064      {
1065         evas_map_util_3d_lighting(mf, lx, ly, lz, lr, lg, lb, lar, lag, lab);
1066         evas_map_util_3d_perspective(mf, px, py, 0, foc);
1067         evas_object_map_set(wd->front.content, mf);
1068         evas_object_map_enable_set(wd->front.content, 1);
1069         if (evas_map_util_clockwise_get(mf)) evas_object_show(wd->front.clip);
1070         else evas_object_hide(wd->front.clip);
1071      }
1072
1073    if (wd->back.content)
1074      {
1075         evas_map_util_3d_lighting(mb, lx, ly, lz, lr, lg, lb, lar, lag, lab);
1076         evas_map_util_3d_perspective(mb, px, py, 0, foc);
1077         evas_object_map_set(wd->back.content, mb);
1078         evas_object_map_enable_set(wd->back.content, 1);
1079         if (evas_map_util_clockwise_get(mb)) evas_object_show(wd->back.clip);
1080         else evas_object_hide(wd->back.clip);
1081      }
1082
1083    evas_map_free(mf);
1084    evas_map_free(mb);
1085 }
1086
1087 static void
1088 _showhide(Evas_Object *obj)
1089 {
1090    Widget_Data *wd = elm_widget_data_get(obj);
1091    Evas_Coord x, y, w, h;
1092    if (!wd) return;
1093
1094    evas_object_geometry_get(obj, &x, &y, &w, &h);
1095    if (wd->front.content)
1096      {
1097         if ((wd->pageflip) && (wd->state))
1098           {
1099              evas_object_move(wd->front.content, 4999, 4999);
1100           }
1101         else
1102           {
1103              if (!wd->animator)
1104                 evas_object_move(wd->front.content, x, y);
1105           }
1106         evas_object_resize(wd->front.content, w, h);
1107      }
1108    if (wd->back.content)
1109      {
1110         if ((wd->pageflip) && (!wd->state))
1111           {
1112              evas_object_move(wd->back.content, 4999, 4999);
1113           }
1114         else
1115           {
1116              if (!wd->animator)
1117                 evas_object_move(wd->back.content, x, y);
1118           }
1119         evas_object_resize(wd->back.content, w, h);
1120      }
1121
1122 }
1123
1124 static Eina_Bool
1125 _flip(Evas_Object *obj)
1126 {
1127    Widget_Data *wd = elm_widget_data_get(obj);
1128    double t = ecore_loop_time_get() - wd->start;
1129    Evas_Coord w, h;
1130
1131    if (!wd) return ECORE_CALLBACK_CANCEL;
1132    if (!wd->animator) return ECORE_CALLBACK_CANCEL;
1133
1134    t = t / wd->len;
1135    if (t > 1.0) t = 1.0;
1136
1137    evas_object_geometry_get(obj, NULL, NULL, &w, &h);
1138    if (wd->mode == ELM_FLIP_PAGE_LEFT)
1139      {
1140         wd->dir = 0;
1141         wd->started = EINA_TRUE;
1142         wd->pageflip = EINA_TRUE;
1143         wd->down_x = w - 1;
1144         wd->down_y = h / 2;
1145         wd->x = (1.0 - t) * wd->down_x;
1146         wd->y = wd->down_y;
1147         flip_show_hide(obj);
1148         _state_update(wd);
1149      }
1150    else if (wd->mode == ELM_FLIP_PAGE_RIGHT)
1151      {
1152         wd->dir = 1;
1153         wd->started = EINA_TRUE;
1154         wd->pageflip = EINA_TRUE;
1155         wd->down_x = 0;
1156         wd->down_y = h / 2;
1157         wd->x = (t) * w;
1158         wd->y = wd->down_y;
1159         flip_show_hide(obj);
1160         _state_update(wd);
1161      }
1162    else if (wd->mode == ELM_FLIP_PAGE_UP)
1163      {
1164         wd->dir = 2;
1165         wd->started = EINA_TRUE;
1166         wd->pageflip = EINA_TRUE;
1167         wd->down_x = w / 2;
1168         wd->down_y = h - 1;
1169         wd->x = wd->down_x;
1170         wd->y = (1.0 - t) * wd->down_y;
1171         flip_show_hide(obj);
1172         _state_update(wd);
1173      }
1174    else if (wd->mode == ELM_FLIP_PAGE_DOWN)
1175      {
1176         wd->dir = 3;
1177         wd->started = EINA_TRUE;
1178         wd->pageflip = EINA_TRUE;
1179         wd->down_x = w / 2;
1180         wd->down_y = 0;
1181         wd->x = wd->down_x;
1182         wd->y = (t) * h;
1183         flip_show_hide(obj);
1184         _state_update(wd);
1185      }
1186    else
1187       _flip_do(obj, t, wd->mode, 0, 0);
1188
1189    if (t >= 1.0)
1190      {
1191         wd->pageflip = EINA_FALSE;
1192         _state_end(wd);
1193         evas_object_map_enable_set(wd->front.content, 0);
1194         evas_object_map_enable_set(wd->back.content, 0);
1195         // FIXME: hack around evas rendering bug (only fix makes evas bitch-slow
1196         evas_object_resize(wd->front.content, 0, 0);
1197         evas_object_resize(wd->back.content, 0, 0);
1198         evas_smart_objects_calculate(evas_object_evas_get(obj));
1199         // FIXME: end hack
1200         wd->animator = NULL;
1201         wd->state = !wd->state;
1202         _configure(obj);
1203         flip_show_hide(obj);
1204         evas_object_smart_callback_call(obj, SIG_ANIMATE_DONE, NULL);
1205         return ECORE_CALLBACK_CANCEL;
1206      }
1207    return ECORE_CALLBACK_RENEW;
1208 }
1209
1210 static void
1211 _configure(Evas_Object *obj)
1212 {
1213    Widget_Data *wd = elm_widget_data_get(obj);
1214    Evas_Coord x, y, w, h;
1215    Evas_Coord fsize;
1216    if (!wd) return;
1217
1218    _showhide(obj);
1219    evas_object_geometry_get(obj, &x, &y, &w, &h);
1220    // FIXME: manual flip wont get fixed
1221    if (wd->animator) _flip(obj);
1222
1223    if (wd->event[0])
1224      {
1225         fsize = (double)w * wd->dir_hitsize[0];
1226         elm_coords_finger_size_adjust(0, NULL, 1, &fsize);
1227         evas_object_move(wd->event[0], x, y);
1228         evas_object_resize(wd->event[0], w, fsize);
1229      }
1230    if (wd->event[1])
1231      {
1232         fsize = (double)w * wd->dir_hitsize[1];
1233         elm_coords_finger_size_adjust(0, NULL, 1, &fsize);
1234         evas_object_move(wd->event[1], x, y + h - fsize);
1235         evas_object_resize(wd->event[1], w, fsize);
1236      }
1237    if (wd->event[2])
1238      {
1239         fsize = (double)h * wd->dir_hitsize[2];
1240         elm_coords_finger_size_adjust(1, &fsize, 0, NULL);
1241         evas_object_move(wd->event[2], x, y);
1242         evas_object_resize(wd->event[2], fsize, h);
1243      }
1244    if (wd->event[3])
1245      {
1246         fsize = (double)h * wd->dir_hitsize[3];
1247         elm_coords_finger_size_adjust(1, &fsize, 0, NULL);
1248         evas_object_move(wd->event[3], x + w - fsize, y);
1249         evas_object_resize(wd->event[3], fsize, h);
1250      }
1251 }
1252
1253 static void
1254 _move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1255 {
1256    _configure(obj);
1257 }
1258
1259 static void
1260 _resize(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1261 {
1262    _configure(obj);
1263 }
1264
1265 static Eina_Bool
1266 _animate(void *data)
1267 {
1268    return _flip(data);
1269 }
1270
1271 static double
1272 _pos_get(Widget_Data *wd, int *rev, Elm_Flip_Mode *m)
1273 {
1274    Evas_Coord x, y, w, h;
1275    double t = 1.0;
1276
1277    evas_object_geometry_get(wd->obj, &x, &y, &w, &h);
1278    switch (wd->intmode)
1279      {
1280       case ELM_FLIP_INTERACTION_ROTATE:
1281       case ELM_FLIP_INTERACTION_CUBE:
1282           {
1283              if (wd->dir == 0)
1284                {
1285                   if (wd->down_x > 0)
1286                      t = 1.0 - ((double)wd->x / (double)wd->down_x);
1287                   *rev = 1;
1288                }
1289              else if (wd->dir == 1)
1290                {
1291                   if (wd->down_x < w)
1292                      t = 1.0 - ((double)(w - wd->x) / (double)(w - wd->down_x));
1293                }
1294              else if (wd->dir == 2)
1295                {
1296                   if (wd->down_y > 0)
1297                      t = 1.0 - ((double)wd->y / (double)wd->down_y);
1298                }
1299              else if (wd->dir == 3)
1300                {
1301                   if (wd->down_y < h)
1302                      t = 1.0 - ((double)(h - wd->y) / (double)(h - wd->down_y));
1303                   *rev = 1;
1304                }
1305
1306              if (t < 0.0) t = 0.0;
1307              else if (t > 1.0) t = 1.0;
1308
1309              if ((wd->dir == 0) || (wd->dir == 1))
1310                {
1311                   if (wd->intmode == ELM_FLIP_INTERACTION_ROTATE)
1312                      *m = ELM_FLIP_ROTATE_Y_CENTER_AXIS;
1313                   else if (wd->intmode == ELM_FLIP_INTERACTION_CUBE)
1314                     {
1315                        if (*rev)
1316                           *m = ELM_FLIP_CUBE_LEFT;
1317                        else
1318                           *m = ELM_FLIP_CUBE_RIGHT;
1319                     }
1320                }
1321              else
1322                {
1323                   if (wd->intmode == ELM_FLIP_INTERACTION_ROTATE)
1324                      *m = ELM_FLIP_ROTATE_X_CENTER_AXIS;
1325                   else if (wd->intmode == ELM_FLIP_INTERACTION_CUBE)
1326                     {
1327                        if (*rev)
1328                           *m = ELM_FLIP_CUBE_UP;
1329                        else
1330                           *m = ELM_FLIP_CUBE_DOWN;
1331                     }
1332                }
1333           }
1334       default:
1335         break;
1336      }
1337    return t;
1338 }
1339
1340 static Eina_Bool
1341 _event_anim(void *data, double pos)
1342 {
1343    Widget_Data *wd = data;
1344    double p;
1345
1346    p = ecore_animator_pos_map(pos, ECORE_POS_MAP_ACCELERATE, 0.0, 0.0);
1347    if (wd->finish)
1348      {
1349         if (wd->dir == 0)
1350            wd->x = wd->ox * (1.0 - p);
1351         else if (wd->dir == 1)
1352            wd->x = wd->ox + ((wd->w - wd->ox) * p);
1353         else if (wd->dir == 2)
1354            wd->y = wd->oy * (1.0 - p);
1355         else if (wd->dir == 3)
1356            wd->y = wd->oy + ((wd->h - wd->oy) * p);
1357      }
1358    else
1359      {
1360         if (wd->dir == 0)
1361            wd->x = wd->ox + ((wd->w - wd->ox) * p);
1362         else if (wd->dir == 1)
1363            wd->x = wd->ox * (1.0 - p);
1364         else if (wd->dir == 2)
1365            wd->y = wd->oy + ((wd->h - wd->oy) * p);
1366         else if (wd->dir == 3)
1367            wd->y = wd->oy * (1.0 - p);
1368      }
1369    switch (wd->intmode)
1370      {
1371       case ELM_FLIP_INTERACTION_NONE:
1372         break;
1373       case ELM_FLIP_INTERACTION_ROTATE:
1374       case ELM_FLIP_INTERACTION_CUBE:
1375           {
1376              Elm_Flip_Mode m = ELM_FLIP_ROTATE_X_CENTER_AXIS;
1377              int rev = 0;
1378              p = _pos_get(wd, &rev, &m);
1379              _flip_do(wd->obj, p, m, 1, rev);
1380           }
1381         break;
1382       case ELM_FLIP_INTERACTION_PAGE:
1383         wd->pageflip = EINA_TRUE;
1384         _configure(data);
1385         _state_update(wd);
1386         break;
1387       default:
1388         break;
1389      }
1390    if (pos < 1.0) return ECORE_CALLBACK_RENEW;
1391
1392    wd->pageflip = EINA_FALSE;
1393    _state_end(wd);
1394    evas_object_map_enable_set(wd->front.content, 0);
1395    evas_object_map_enable_set(wd->back.content, 0);
1396    // FIXME: hack around evas rendering bug (only fix makes evas bitch-slow
1397    evas_object_resize(wd->front.content, 0, 0);
1398    evas_object_resize(wd->back.content, 0, 0);
1399    evas_smart_objects_calculate(evas_object_evas_get(wd->obj));
1400    // FIXME: end hack
1401    wd->animator = NULL;
1402    if (wd->finish) wd->state = !wd->state;
1403    flip_show_hide(wd->obj);
1404    _configure(wd->obj);
1405    wd->animator = NULL;
1406    evas_object_smart_callback_call(wd->obj, SIG_ANIMATE_DONE, NULL);
1407
1408    return ECORE_CALLBACK_CANCEL;
1409 }
1410
1411 static void
1412 _update_job(void *data)
1413 {
1414    Widget_Data *wd = data;
1415    double p;
1416    Elm_Flip_Mode m = ELM_FLIP_ROTATE_X_CENTER_AXIS;
1417    int rev = 0;
1418
1419    wd->job = NULL;
1420    switch (wd->intmode)
1421      {
1422       case ELM_FLIP_INTERACTION_ROTATE:
1423       case ELM_FLIP_INTERACTION_CUBE:
1424         p = _pos_get(wd, &rev, &m);
1425         _flip_do(wd->obj, p, m, 1, rev);
1426         break;
1427       case ELM_FLIP_INTERACTION_PAGE:
1428         wd->pageflip = EINA_TRUE;
1429         _configure(data);
1430         _state_update(wd);
1431         break;
1432       default:
1433         break;
1434      }
1435 }
1436
1437 static void
1438 _down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1439 {
1440    Evas_Object *fl = data;
1441    Widget_Data *wd = elm_widget_data_get(fl);
1442    Evas_Event_Mouse_Down *ev = event_info;
1443    Evas_Coord x, y, w, h;
1444
1445    if (!wd) return;
1446    if (ev->button != 1) return;
1447    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1448    if (wd->animator)
1449      {
1450         ecore_animator_del(wd->animator);
1451         wd->animator = NULL;
1452      }
1453    wd->down = EINA_TRUE;
1454    wd->started = EINA_FALSE;
1455    evas_object_geometry_get(data, &x, &y, &w, &h);
1456    wd->x = ev->canvas.x - x;
1457    wd->y = ev->canvas.y - y;
1458    wd->w = w;
1459    wd->h = h;
1460    wd->down_x = wd->x;
1461    wd->down_y = wd->y;
1462 }
1463
1464 static void
1465 _up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1466 {
1467    Evas_Object *fl = data;
1468    Widget_Data *wd = elm_widget_data_get(fl);
1469    Evas_Event_Mouse_Up *ev = event_info;
1470    Evas_Coord x, y, w, h;
1471    double tm = 0.5;
1472
1473    if (!wd) return;
1474    if (ev->button != 1) return;
1475    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1476    wd->down = 0;
1477    evas_object_geometry_get(data, &x, &y, &w, &h);
1478    wd->x = ev->canvas.x - x;
1479    wd->y = ev->canvas.y - y;
1480    wd->w = w;
1481    wd->h = h;
1482    wd->ox = wd->x;
1483    wd->oy = wd->y;
1484    if (wd->job)
1485      {
1486         ecore_job_del(wd->job);
1487         wd->job = NULL;
1488      }
1489    wd->finish = EINA_FALSE;
1490    if (wd->dir == 0)
1491      {
1492         tm = (double)wd->x / (double)wd->w;
1493         if (wd->x < (wd->w / 2)) wd->finish = EINA_TRUE;
1494      }
1495    else if (wd->dir == 1)
1496      {
1497         if (wd->x > (wd->w / 2)) wd->finish = EINA_TRUE;
1498         tm = 1.0 - ((double)wd->x / (double)wd->w);
1499      }
1500    else if (wd->dir == 2)
1501      {
1502         if (wd->y < (wd->h / 2)) wd->finish = EINA_TRUE;
1503         tm = (double)wd->y / (double)wd->h;
1504      }
1505    else if (wd->dir == 3)
1506      {
1507         if (wd->y > (wd->h / 2)) wd->finish = EINA_TRUE;
1508         tm = 1.0 - ((double)wd->y / (double)wd->h);
1509      }
1510    if (tm < 0.01) tm = 0.01;
1511    else if (tm > 0.99) tm = 0.99;
1512    if (!wd->finish) tm = 1.0 - tm;
1513    tm *= 1.0; // FIXME: config for anim time
1514    if (wd->animator) ecore_animator_del(wd->animator);
1515    wd->animator = ecore_animator_timeline_add(tm, _event_anim, wd);
1516    _event_anim(wd, 0.0);
1517 }
1518
1519 static void
1520 _move_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1521 {
1522    Evas_Object *fl = data;
1523    Widget_Data *wd = elm_widget_data_get(fl);
1524    Evas_Event_Mouse_Move *ev = event_info;
1525    Evas_Coord x, y, w, h;
1526
1527    if (!wd) return;
1528    if (!wd->down) return;
1529    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1530    evas_object_geometry_get(data, &x, &y, &w, &h);
1531    wd->x = ev->cur.canvas.x - x;
1532    wd->y = ev->cur.canvas.y - y;
1533    wd->w = w;
1534    wd->h = h;
1535    if (!wd->started)
1536      {
1537         Evas_Coord dx, dy;
1538
1539         dx = wd->x - wd->down_x;
1540         dy = wd->y - wd->down_y;
1541         if (((dx * dx) + (dy * dy)) > (_elm_config->finger_size * _elm_config->finger_size / 4))
1542           {
1543              wd->dir = 0;
1544              if      ((wd->x > (w / 2)) && (dx <  0) && (abs(dx) >  abs(dy))) wd->dir = 0; // left
1545              else if ((wd->x < (w / 2)) && (dx >= 0) && (abs(dx) >  abs(dy))) wd->dir = 1; // right
1546              else if ((wd->y > (h / 2)) && (dy <  0) && (abs(dy) >= abs(dx))) wd->dir = 2; // up
1547              else if ((wd->y < (h / 2)) && (dy >= 0) && (abs(dy) >= abs(dx))) wd->dir = 3; // down
1548              wd->started = EINA_TRUE;
1549              if (wd->intmode == ELM_FLIP_INTERACTION_PAGE)
1550                 wd->pageflip = EINA_TRUE;
1551              flip_show_hide(data);
1552              evas_smart_objects_calculate(evas_object_evas_get(data));
1553              _flip(data);
1554              // FIXME: hack around evas rendering bug (only fix makes evas bitch-slow)
1555              evas_object_map_enable_set(wd->front.content, 0);
1556              evas_object_map_enable_set(wd->back.content, 0);
1557 // FIXME: XXX why does this bork interactive flip??
1558 //             evas_object_resize(wd->front.content, 0, 0);
1559 //             evas_object_resize(wd->back.content, 0, 0);
1560              evas_smart_objects_calculate(evas_object_evas_get(data));
1561              _configure(obj);
1562              // FIXME: end hack
1563              evas_object_smart_callback_call(obj, SIG_ANIMATE_BEGIN, NULL);
1564           }
1565         else return;
1566      }
1567    ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1568    if (wd->job) ecore_job_del(wd->job);
1569    wd->job = ecore_job_add(_update_job, wd);
1570 }
1571
1572 EAPI Evas_Object *
1573 elm_flip_add(Evas_Object *parent)
1574 {
1575    Evas_Object *obj;
1576    Evas *e;
1577    Widget_Data *wd;
1578
1579    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1580
1581    ELM_SET_WIDTYPE(widtype, "flip");
1582    elm_widget_type_set(obj, "flip");
1583    elm_widget_sub_object_add(parent, obj);
1584    elm_widget_data_set(obj, wd);
1585    elm_widget_del_hook_set(obj, _del_hook);
1586    elm_widget_theme_hook_set(obj, _theme_hook);
1587    elm_widget_focus_next_hook_set(obj, _elm_flip_focus_next_hook);
1588    elm_widget_can_focus_set(obj, EINA_FALSE);
1589
1590    wd->obj = obj;
1591
1592    wd->clip = evas_object_rectangle_add(e);
1593    evas_object_static_clip_set(wd->clip, 1);
1594    evas_object_color_set(wd->clip, 255, 255, 255, 255);
1595    evas_object_move(wd->clip, -49999, -49999);
1596    evas_object_resize(wd->clip, 99999, 99999);
1597    elm_widget_sub_object_add(obj, wd->clip);
1598    evas_object_clip_set(wd->clip, evas_object_clip_get(obj));
1599    evas_object_smart_member_add(wd->clip, obj);
1600
1601    wd->front.clip = evas_object_rectangle_add(e);
1602    evas_object_static_clip_set(wd->front.clip, 1);
1603    evas_object_data_set(wd->front.clip, "_elm_leaveme", obj);
1604    evas_object_color_set(wd->front.clip, 255, 255, 255, 255);
1605    evas_object_move(wd->front.clip, -49999, -49999);
1606    evas_object_resize(wd->front.clip, 99999, 99999);
1607    elm_widget_sub_object_add(obj, wd->front.clip);
1608    evas_object_smart_member_add(wd->front.clip, obj);
1609    evas_object_clip_set(wd->front.clip, wd->clip);
1610
1611    wd->back.clip = evas_object_rectangle_add(e);
1612    evas_object_static_clip_set(wd->back.clip, 1);
1613    evas_object_data_set(wd->back.clip, "_elm_leaveme", obj);
1614    evas_object_color_set(wd->back.clip, 255, 255, 255, 255);
1615    evas_object_move(wd->back.clip, -49999, -49999);
1616    evas_object_resize(wd->back.clip, 99999, 99999);
1617    elm_widget_sub_object_add(wd->back.clip, obj);
1618    evas_object_smart_member_add(obj, wd->back.clip);
1619    evas_object_clip_set(wd->back.clip, wd->clip);
1620
1621    evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
1622    evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _move, NULL);
1623    evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, NULL);
1624    evas_object_event_callback_add(obj, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1625                                        _changed_size_hints, obj);;
1626
1627    evas_object_smart_callbacks_descriptions_set(obj, _signals);
1628
1629    wd->state = 1;
1630    wd->intmode = ELM_FLIP_INTERACTION_NONE;
1631
1632    _sizing_eval(obj);
1633
1634    return obj;
1635 }
1636
1637 EAPI void
1638 elm_flip_content_front_set(Evas_Object *obj, Evas_Object *content)
1639 {
1640    ELM_CHECK_WIDTYPE(obj, widtype);
1641    Widget_Data *wd = elm_widget_data_get(obj);
1642    int i;
1643    if (!wd) return;
1644    if (wd->front.content == content) return;
1645    if (wd->front.content) evas_object_del(wd->front.content);
1646    wd->front.content = content;
1647    if (content)
1648      {
1649         elm_widget_sub_object_add(obj, content);
1650         evas_object_smart_member_add(content, obj);
1651         evas_object_clip_set(content, wd->front.clip);
1652         evas_object_event_callback_add(content,
1653                                        EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1654                                        _changed_size_hints, obj);
1655         _sizing_eval(obj);
1656      }
1657    // force calc to contents are the right size before transition
1658    evas_smart_objects_calculate(evas_object_evas_get(obj));
1659    flip_show_hide(obj);
1660    _configure(obj);
1661    if (wd->intmode != ELM_FLIP_INTERACTION_NONE)
1662      {
1663         for (i = 0; i < 4; i++) evas_object_raise(wd->event[i]);
1664      }
1665 }
1666
1667 EAPI void
1668 elm_flip_content_back_set(Evas_Object *obj, Evas_Object *content)
1669 {
1670    ELM_CHECK_WIDTYPE(obj, widtype);
1671    Widget_Data *wd = elm_widget_data_get(obj);
1672    int i;
1673    if (!wd) return;
1674    if (wd->back.content == content) return;
1675    if (wd->back.content) evas_object_del(wd->back.content);
1676    wd->back.content = content;
1677    if (content)
1678      {
1679         elm_widget_sub_object_add(obj, content);
1680         evas_object_smart_member_add(content, obj);
1681         evas_object_clip_set(content, wd->back.clip);
1682         evas_object_event_callback_add(content,
1683                                        EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1684                                        _changed_size_hints, obj);
1685         _sizing_eval(obj);
1686      }
1687    // force calc to contents are the right size before transition
1688    evas_smart_objects_calculate(evas_object_evas_get(obj));
1689    flip_show_hide(obj);
1690    _configure(obj);
1691    if (wd->intmode != ELM_FLIP_INTERACTION_NONE)
1692      {
1693         for (i = 0; i < 4; i++) evas_object_raise(wd->event[i]);
1694      }
1695 }
1696
1697 EAPI Evas_Object *
1698 elm_flip_content_front_get(const Evas_Object *obj)
1699 {
1700    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1701    Widget_Data *wd = elm_widget_data_get(obj);
1702    return wd->front.content;
1703 }
1704
1705
1706 EAPI Evas_Object *
1707 elm_flip_content_back_get(const Evas_Object *obj)
1708 {
1709    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1710    Widget_Data *wd = elm_widget_data_get(obj);
1711    return wd->back.content;
1712 }
1713
1714 EAPI Evas_Object *
1715 elm_flip_content_front_unset(Evas_Object *obj)
1716 {
1717    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1718    Widget_Data *wd = elm_widget_data_get(obj);
1719    if (!wd) return NULL;
1720    if (!wd->front.content) return NULL;
1721    Evas_Object *content = wd->front.content;
1722    evas_object_clip_unset(content);
1723    elm_widget_sub_object_del(obj, content);
1724    evas_object_event_callback_del_full(content,
1725                                        EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1726                                        _changed_size_hints, obj);
1727    evas_object_smart_member_del(content);
1728    wd->front.content = NULL;
1729    return content;
1730 }
1731
1732 EAPI Evas_Object *
1733 elm_flip_content_back_unset(Evas_Object *obj)
1734 {
1735    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1736    Widget_Data *wd = elm_widget_data_get(obj);
1737    if (!wd) return NULL;
1738    if (!wd->back.content) return NULL;
1739    Evas_Object *content = wd->back.content;
1740    evas_object_clip_unset(content);
1741    elm_widget_sub_object_del(obj, content);
1742    evas_object_event_callback_del_full(content,
1743                                        EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1744                                        _changed_size_hints, obj);
1745    evas_object_smart_member_del(content);
1746    wd->back.content = NULL;
1747    return content;
1748 }
1749
1750 EAPI Eina_Bool
1751 elm_flip_front_get(const Evas_Object *obj)
1752 {
1753    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1754    Widget_Data *wd = elm_widget_data_get(obj);
1755    if (!wd) return EINA_FALSE;
1756    return wd->state;
1757 }
1758
1759 EAPI void
1760 elm_flip_perspective_set(Evas_Object *obj, Evas_Coord foc __UNUSED__, Evas_Coord x __UNUSED__, Evas_Coord y __UNUSED__)
1761 {
1762    ELM_CHECK_WIDTYPE(obj, widtype);
1763    Widget_Data *wd = elm_widget_data_get(obj);
1764    if (!wd) return;
1765 }
1766
1767 // FIXME: add ambient and lighting control
1768
1769 EAPI void
1770 elm_flip_go(Evas_Object *obj, Elm_Flip_Mode mode)
1771 {
1772    ELM_CHECK_WIDTYPE(obj, widtype);
1773    Widget_Data *wd = elm_widget_data_get(obj);
1774    if (!wd) return;
1775    if (!wd->animator) wd->animator = ecore_animator_add(_animate, obj);
1776    flip_show_hide(obj);
1777    wd->mode = mode;
1778    wd->start = ecore_loop_time_get();
1779    wd->len = 0.5; // FIXME: make config val
1780    if ((wd->mode == ELM_FLIP_PAGE_LEFT) ||
1781        (wd->mode == ELM_FLIP_PAGE_RIGHT) ||
1782        (wd->mode == ELM_FLIP_PAGE_UP) ||
1783        (wd->mode == ELM_FLIP_PAGE_DOWN))
1784       wd->pageflip = EINA_TRUE;
1785    // force calc to contents are the right size before transition
1786    evas_smart_objects_calculate(evas_object_evas_get(obj));
1787    _flip(obj);
1788    // FIXME: hack around evas rendering bug (only fix makes evas bitch-slow)
1789    evas_object_map_enable_set(wd->front.content, 0);
1790    evas_object_map_enable_set(wd->back.content, 0);
1791    evas_object_resize(wd->front.content, 0, 0);
1792    evas_object_resize(wd->back.content, 0, 0);
1793    evas_smart_objects_calculate(evas_object_evas_get(obj));
1794    _configure(obj);
1795    // FIXME: end hack
1796    evas_object_smart_callback_call(obj, SIG_ANIMATE_BEGIN, NULL);
1797 }
1798
1799 EAPI void
1800 elm_flip_interaction_set(Evas_Object *obj, Elm_Flip_Interaction mode)
1801 {
1802    ELM_CHECK_WIDTYPE(obj, widtype);
1803    int i;
1804    Widget_Data *wd = elm_widget_data_get(obj);
1805    if (!wd) return;
1806    if (wd->intmode == mode) return;
1807    wd->intmode = mode;
1808    for (i = 0; i < 4; i++)
1809      {
1810         if (wd->intmode == ELM_FLIP_INTERACTION_NONE)
1811           {
1812              if (wd->event[i])
1813                {
1814                   evas_object_del(wd->event[i]);
1815                   wd->event[i] = NULL;
1816                }
1817           }
1818         else
1819           {
1820              if ((wd->dir_enabled[i]) && (!wd->event[i]))
1821                {
1822                   wd->event[i] = evas_object_rectangle_add(evas_object_evas_get(obj));
1823                   elm_widget_sub_object_add(obj, wd->event[i]);
1824                   evas_object_clip_set(wd->event[i], evas_object_clip_get(obj));
1825                   evas_object_color_set(wd->event[i], 0, 0, 0, 0);
1826                   evas_object_show(wd->event[i]);
1827                   evas_object_smart_member_add(wd->event[i], obj);
1828                   evas_object_event_callback_add(wd->event[i], EVAS_CALLBACK_MOUSE_DOWN, _down_cb, obj);
1829                   evas_object_event_callback_add(wd->event[i], EVAS_CALLBACK_MOUSE_UP, _up_cb, obj);
1830                   evas_object_event_callback_add(wd->event[i], EVAS_CALLBACK_MOUSE_MOVE, _move_cb, obj);
1831                }
1832           }
1833      }
1834    _sizing_eval(obj);
1835    _configure(obj);
1836 }
1837
1838 EAPI Elm_Flip_Interaction
1839 elm_flip_interaction_get(const Evas_Object *obj)
1840 {
1841    ELM_CHECK_WIDTYPE(obj, widtype) ELM_FLIP_INTERACTION_NONE;
1842    Widget_Data *wd = elm_widget_data_get(obj);
1843    if (!wd) return ELM_FLIP_INTERACTION_NONE;
1844    return wd->intmode;
1845 }
1846
1847 EAPI void
1848 elm_flip_interacton_direction_enabled_set(Evas_Object *obj, Elm_Flip_Direction dir, Eina_Bool enabled)
1849 {
1850    ELM_CHECK_WIDTYPE(obj, widtype);
1851    Widget_Data *wd = elm_widget_data_get(obj);
1852    int i = -1;
1853    if (!wd) return;
1854    enabled = !!enabled;
1855    if      (dir == ELM_FLIP_DIRECTION_UP)    i = 0;
1856    else if (dir == ELM_FLIP_DIRECTION_DOWN)  i = 1;
1857    else if (dir == ELM_FLIP_DIRECTION_LEFT)  i = 2;
1858    else if (dir == ELM_FLIP_DIRECTION_RIGHT) i = 3;
1859    if (i < 0) return;
1860    if (wd->dir_enabled[i] == enabled) return;
1861    wd->dir_enabled[i] = enabled;
1862    if (wd->intmode == ELM_FLIP_INTERACTION_NONE) return;
1863    if ((wd->dir_enabled[i]) && (!wd->event[i]))
1864      {
1865         wd->event[i] = evas_object_rectangle_add(evas_object_evas_get(obj));
1866         elm_widget_sub_object_add(obj, wd->event[i]);
1867         evas_object_clip_set(wd->event[i], evas_object_clip_get(obj));
1868         evas_object_color_set(wd->event[i], 0, 0, 0, 0);
1869         evas_object_show(wd->event[i]);
1870         evas_object_smart_member_add(wd->event[i], obj);
1871         evas_object_event_callback_add(wd->event[i], EVAS_CALLBACK_MOUSE_DOWN, _down_cb, obj);
1872         evas_object_event_callback_add(wd->event[i], EVAS_CALLBACK_MOUSE_UP, _up_cb, obj);
1873         evas_object_event_callback_add(wd->event[i], EVAS_CALLBACK_MOUSE_MOVE, _move_cb, obj);
1874      }
1875    else if (!(wd->dir_enabled[i]) && (wd->event[i]))
1876      {
1877         evas_object_del(wd->event[i]);
1878         wd->event[i] = NULL;
1879      }
1880    _sizing_eval(obj);
1881    _configure(obj);
1882 }
1883
1884 EAPI Eina_Bool
1885 elm_flip_interacton_direction_enabled_get(Evas_Object *obj, Elm_Flip_Direction dir)
1886 {
1887    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1888    Widget_Data *wd = elm_widget_data_get(obj);
1889    int i = -1;
1890    if (!wd) return EINA_FALSE;
1891    if      (dir == ELM_FLIP_DIRECTION_UP)    i = 0;
1892    else if (dir == ELM_FLIP_DIRECTION_DOWN)  i = 1;
1893    else if (dir == ELM_FLIP_DIRECTION_LEFT)  i = 2;
1894    else if (dir == ELM_FLIP_DIRECTION_RIGHT) i = 3;
1895    if (i < 0) return EINA_FALSE;
1896    return wd->dir_enabled[i];
1897 }
1898
1899 EAPI void
1900 elm_flip_interacton_direction_hitsize_set(Evas_Object *obj, Elm_Flip_Direction dir, double hitsize)
1901 {
1902    ELM_CHECK_WIDTYPE(obj, widtype);
1903    Widget_Data *wd = elm_widget_data_get(obj);
1904    int i = -1;
1905    if (!wd) return;
1906    if      (dir == ELM_FLIP_DIRECTION_UP)    i = 0;
1907    else if (dir == ELM_FLIP_DIRECTION_DOWN)  i = 1;
1908    else if (dir == ELM_FLIP_DIRECTION_LEFT)  i = 2;
1909    else if (dir == ELM_FLIP_DIRECTION_RIGHT) i = 3;
1910    if (i < 0) return;
1911    if (hitsize < 0.0) hitsize = 0.0;
1912    else if (hitsize > 1.0) hitsize = 1.0;
1913    if (wd->dir_hitsize[i] == hitsize) return;
1914    wd->dir_hitsize[i] = hitsize;
1915    _sizing_eval(obj);
1916    _configure(obj);
1917 }
1918
1919 EAPI double
1920 elm_flip_interacton_direction_hitsize_get(Evas_Object *obj, Elm_Flip_Direction dir)
1921 {
1922    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1923    Widget_Data *wd = elm_widget_data_get(obj);
1924    int i = -1;
1925    if (!wd) return 0.0;
1926    if      (dir == ELM_FLIP_DIRECTION_UP)    i = 0;
1927    else if (dir == ELM_FLIP_DIRECTION_DOWN)  i = 1;
1928    else if (dir == ELM_FLIP_DIRECTION_LEFT)  i = 2;
1929    else if (dir == ELM_FLIP_DIRECTION_RIGHT) i = 3;
1930    if (i < 0) return 0.0;
1931    return wd->dir_hitsize[i];
1932 }