Elementary: Flip documentation.
[framework/uifw/elementary.git] / 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)
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    Vertex2 *tvi;
431    Vertex3 *tvo, *tvol;
432    Evas_Object *front, *back;
433
434    st->backflip = 1;
435    if (st->state)
436      {
437         front = st->front.content;
438         back = st->front.content;
439      }
440    else
441      {
442         front = st->back.content;
443         back = st->back.content;
444      }
445
446    evas_object_geometry_get(st->obj, &x, &y, &w, &h);
447    ox = x; oy = y; ow = w; oh = h;
448    x1 = st->down_x;
449    y1 = st->down_y;
450    x2 = st->x;
451    y2 = st->y;
452
453    if (st->dir == 0)
454      {
455         // no nothing. left drag is standard
456      }
457    else if (st->dir == 1)
458      {
459         x1 = (w - 1) - x1;
460         x2 = (w - 1) - x2;
461      }
462    else if (st->dir == 2)
463      {
464         Evas_Coord tmp;
465
466         tmp = x1; x1 = y1; y1 = tmp;
467         tmp = x2; x2 = y2; y2 = tmp;
468         tmp = w; w = h; h = tmp;
469      }
470    else if (st->dir == 3)
471      {
472         Evas_Coord tmp;
473
474         tmp = x1; x1 = y1; y1 = tmp;
475         tmp = x2; x2 = y2; y2 = tmp;
476         tmp = w; w = h; h = tmp;
477         x1 = (w - 1) - x1;
478         x2 = (w - 1) - x2;
479      }
480
481    if (x2 >= x1) x2 = x1 - 1;
482    mx = (x1 + x2) / 2;
483    my = (y1 + y2) / 2;
484
485    if (mx < 0) mx = 0;
486    else if (mx >= w) mx = w - 1;
487    if (my < 0) my = 0;
488    else if (my >= h) my = h - 1;
489
490    mgrad = (double)(y1 - y2) / (double)(x1 - x2);
491
492    if (mx < 1) mx = 1; // quick hack to keep curl line visible
493
494    if (mgrad == 0.0) // special horizontal case
495       mgrad = 0.001; // quick dirty hack for now
496    // else
497      {
498         minv = 1.0 / mgrad;
499         // y = (m * x) + b
500         b = my + (minv * mx);
501      }
502    if ((b >= -5) && (b <= (h + 5)))
503      {
504         if (minv > 0.0) // clamp to h
505           {
506              minv = (double)(h + 5 - my) / (double)(mx);
507              b = my + (minv * mx);
508           }
509         else // clamp to 0
510           {
511              minv = (double)(-5 - my) / (double)(mx);
512              b = my + (minv * mx);
513           }
514      }
515
516    perc = (double)x2 / (double)x1;
517    percm = (double)mx / (double)x1;
518    if (perc < 0.0) perc = 0.0;
519    else if (perc > 1.0) perc = 1.0;
520    if (percm < 0.0) percm = 0.0;
521    else if (percm > 1.0) percm = 1.0;
522
523    minva = atan(minv) / (M_PI / 2);
524    if (minva < 0.0) minva = -minva;
525
526    // A = apex of cone
527    if (b <= 0) A = b;
528    else A = h - b;
529    if (A < -(h * 20)) A = -h * 20;
530    //--//
531    Al = -5;
532
533    // rho = is how much the page is turned
534    n = 1.0 - perc;
535    n = 1.0 - cos(n * M_PI / 2.0);
536    n = n * n;
537    rho = -(n * M_PI);
538    //--//
539    rhol = -(n * M_PI);
540
541    // theta == curliness (how much page culrs in on itself
542    n = sin((1.0 - perc) * M_PI);
543    n = n * 1.2;
544    theta = 7.86 + n;
545    //--//
546    n = sin((1.0 - perc) * M_PI);
547    n = 1.0 - n;
548    n = n * n;
549    n = 1.0 - n;
550    thetal = 7.86 + n;
551
552    nw = 16;
553    nh = 16;
554    if (nw < 1) nw = 1;
555    if (nh < 1) nh = 1;
556    gszw = w / nw;
557    gszh = h / nh;
558    if (gszw < 4) gszw = 4;
559    if (gszh < 4) gszh = 4;
560
561    nw = (w + gszw - 1) / gszw;
562    nh = (h + gszh - 1) / gszh;
563    if ((st->slices_w != nw) || (st->slices_h != nh)) _state_slices_clear(st);
564    st->slices_w = nw;
565    st->slices_h = nh;
566    if (!st->slices)
567      {
568         st->slices = calloc(st->slices_w * st->slices_h, sizeof(Slice *));
569         if (!st->slices) return 0;
570         st->slices2 = calloc(st->slices_w * st->slices_h, sizeof(Slice *));
571         if (!st->slices2)
572           {
573              free(st->slices);
574              st->slices = NULL;
575              return 0;
576           }
577      }
578
579    num = (st->slices_w + 1) * (st->slices_h + 1);
580
581    tvi = alloca(sizeof(Vertex2) * num);
582    tvo = alloca(sizeof(Vertex3) * num);
583    tvol = alloca(sizeof(Vertex3) * (st->slices_w + 1));
584
585    for (col = 0, gx = 0; gx <= (w + gszw - 1); gx += gszw, col++)
586      {
587         Vertex2 vil;
588
589         vil.x = gx;
590         vil.y = h - ((gx * h) / (w + gszw - 1));
591         _deform_point(&vil, &(tvol[col]), rhol, thetal, Al);
592      }
593
594    n = minva * sin(perc * M_PI);
595    n = n * n;
596
597    num = 0;
598    for (col = 0, gx = 0; gx <= (w + gszw - 1); gx += gszw, col++)
599      {
600         for (gy = 0; gy <= (h + gszh - 1); gy += gszh)
601           {
602              Vertex2 vi;
603              Vertex3 vo, tvo1;
604
605              if (gx > w) vi.x = w;
606              else vi.x = gx;
607              if (gy > h) vi.y = h;
608              else vi.y = gy;
609              _deform_point(&vi, &vo, rho, theta, A);
610              tvo1 = tvol[col];
611              if (gy > h) tvo1.y = h;
612              else tvo1.y = gy;
613              _interp_point(&vo, &tvo1, &(tvo[num]), n);
614              num++;
615           }
616      }
617
618    jump = st->slices_h + 1;
619    for (col = 0, gx = 0; gx < w; gx += gszw, col++)
620      {
621         num = st->slices_h * col;
622         num2 = jump * col;
623
624         gw = gszw;
625         if ((gx + gw) > w) gw = w - gx;
626
627         for (row = 0, gy = 0; gy < h; gy += gszh, row++)
628           {
629              Vertex3 vo[4];
630
631              if (b > 0) nn = num + st->slices_h - row - 1;
632              else nn = num + row;
633
634              gh = gszh;
635              if ((gy + gh) > h) gh = h - gy;
636
637              vo[0] = tvo[num2 + row];
638              vo[1] = tvo[num2 + row + jump];
639              vo[2] = tvo[num2 + row + jump + 1];
640              vo[3] = tvo[num2 + row + 1];
641 #define SWP(a, b) do {typeof(a) vt; vt = (a); (a) = (b); (b) = vt;} while (0)
642              if (b > 0)
643                {
644                   SWP(vo[0], vo[3]);
645                   SWP(vo[1], vo[2]);
646                   vo[0].y = h - vo[0].y;
647                   vo[1].y = h - vo[1].y;
648                   vo[2].y = h - vo[2].y;
649                   vo[3].y = h - vo[3].y;
650                }
651
652              // FRONT
653              sl = st->slices[nn];
654              if (!sl)
655                {
656                   sl = _slice_new(st, front);
657                   st->slices[nn] = sl;
658                }
659              _slice_xyz(st, sl,
660                         vo[0].x, vo[0].y, vo[0].z,
661                         vo[1].x, vo[1].y, vo[1].z,
662                         vo[2].x, vo[2].y, vo[2].z,
663                         vo[3].x, vo[3].y, vo[3].z);
664              if (b <= 0)
665                 _slice_uv(st, sl,
666                           gx,       gy,       gx + gw,  gy,
667                           gx + gw,  gy + gh,  gx,       gy + gh);
668              else
669                 _slice_uv(st, sl,
670                           gx,       h - (gy + gh), gx + gw,  h - (gy + gh),
671                           gx + gw,  h - gy,        gx,       h - gy);
672
673                           // BACK
674              sl = st->slices2[nn];
675              if (!sl)
676                {
677                   sl = _slice_new(st, back);
678                   st->slices2[nn] = sl;
679                }
680
681              _slice_xyz(st, sl,
682                         vo[1].x, vo[1].y, vo[1].z,
683                         vo[0].x, vo[0].y, vo[0].z,
684                         vo[3].x, vo[3].y, vo[3].z,
685                         vo[2].x, vo[2].y, vo[2].z);
686              if (st->backflip)
687                {
688                   if (b <= 0)
689                      _slice_uv(st, sl,
690                                gx + gw, gy,       gx,       gy,
691                                gx,      gy + gh,  gx + gw,  gy + gh);
692                   else
693                      _slice_uv(st, sl,
694                                gx + gw, h - (gy + gh), gx,      h - (gy + gh),
695                                gx,      h - gy,        gx + gw, h - gy);
696                }
697              else
698                {
699                   if (b <= 0)
700                      _slice_uv(st, sl,
701                                w - (gx + gw), gy,       w - (gx),      gy,
702                                w - (gx),      gy + gh,  w - (gx + gw), gy + gh);
703                   else
704                      _slice_uv(st, sl,
705                                w - (gx + gw), h - (gy + gh), w - (gx),      h - (gy + gh),
706                                w - (gx),      h - gy,        w - (gx + gw), h - gy);
707                }
708           }
709      }
710
711    num = 0;
712    for (j = 0; j < st->slices_h; j++)
713      {
714         for (i = 0; i < st->slices_w; i++)
715           {
716              _slice_apply(st, st->slices[num], x, y, w, h, ox, oy, ow, oh);
717              _slice_apply(st, st->slices2[num], x, y, w, h, ox, oy, ow, oh);
718              _slice_light(st, st->slices[num], ox, oy, ow, oh);
719              _slice_light(st, st->slices2[num], ox, oy, ow, oh);
720              num++;
721           }
722      }
723
724    for (i = 0; i <= st->slices_w; i++)
725      {
726         num = i * st->slices_h;
727         for (j = 0; j <= st->slices_h; j++)
728           {
729              Slice *s[4];
730
731              s[0] = s[1] = s[2] = s[3] = NULL;
732              if ((i > 0)            && (j > 0))
733                 s[0] = st->slices[num - 1 - st->slices_h];
734              if ((i < st->slices_w) && (j > 0))
735                 s[1] = st->slices[num - 1];
736              if ((i > 0)            && (j < st->slices_h))
737                 s[2] = st->slices[num - st->slices_h];
738              if ((i < st->slices_w) && (j < st->slices_h))
739                 s[3] = st->slices[num];
740              if (st->dir == 0)
741                 _slice_obj_vert_color_merge(s[0], 2, s[1], 3,
742                                             s[2], 1, s[3], 0);
743              else if (st->dir == 1)
744                 _slice_obj_vert_color_merge(s[0], 3, s[1], 2,
745                                             s[2], 0, s[3], 1);
746              else if (st->dir == 2)
747                 _slice_obj_vert_color_merge(s[0], 3, s[1], 2,
748                                             s[2], 0, s[3], 1);
749              else if (st->dir == 3)
750                 _slice_obj_vert_color_merge(s[0], 2, s[1], 3,
751                                             s[2], 1, s[3], 0);
752              s[0] = s[1] = s[2] = s[3] = NULL;
753              if ((i > 0)            && (j > 0))
754                 s[0] = st->slices2[num - 1 - st->slices_h];
755              if ((i < st->slices_w) && (j > 0))
756                 s[1] = st->slices2[num - 1];
757              if ((i > 0)            && (j < st->slices_h))
758                 s[2] = st->slices2[num - st->slices_h];
759              if ((i < st->slices_w) && (j < st->slices_h))
760                 s[3] = st->slices2[num];
761              if (st->dir == 0)
762                 _slice_obj_vert_color_merge(s[0], 3, s[1], 2,
763                                             s[2], 0, s[3], 1);
764              else if (st->dir == 1)
765                 _slice_obj_vert_color_merge(s[0], 2, s[1], 3,
766                                             s[2], 1, s[3], 0);
767              else if (st->dir == 2)
768                 _slice_obj_vert_color_merge(s[0], 2, s[1], 3,
769                                             s[2], 1, s[3], 0);
770              else if (st->dir == 3)
771                 _slice_obj_vert_color_merge(s[0], 3, s[1], 2,
772                                             s[2], 0, s[3], 1);
773              num++;
774           }
775      }
776
777    num = 0;
778    for (i = 0; i < st->slices_w; i++)
779      {
780         for (j = 0; j < st->slices_h; j++)
781           {
782              _slice_3d(st, st->slices[num], ox, oy, ow, oh);
783              _slice_3d(st, st->slices2[num], ox, oy, ow, oh);
784              num++;
785           }
786      }
787
788    return 1;
789 }
790
791 static void
792 _state_end(Widget_Data *st)
793 {
794    _state_slices_clear(st);
795 }
796
797
798 static void
799 flip_show_hide(Evas_Object *obj)
800 {
801    Widget_Data *wd = elm_widget_data_get(obj);
802    if (elm_flip_front_get(obj))
803      {
804         if (wd->pageflip)
805           {
806              if (wd->front.content)
807                {
808                   evas_object_move(wd->front.content, 4999, 4999);
809                   evas_object_show(wd->front.clip);
810                }
811              else
812                 evas_object_hide(wd->front.clip);
813              if (wd->back.content)
814                 evas_object_show(wd->back.clip);
815              else
816                 evas_object_hide(wd->back.clip);
817           }
818         else
819           {
820              if (wd->front.content)
821                 evas_object_show(wd->front.clip);
822              else
823                 evas_object_hide(wd->front.clip);
824              if (wd->back.content)
825                 evas_object_hide(wd->back.clip);
826              else
827                 evas_object_hide(wd->back.clip);
828           }
829      }
830    else
831      {
832         if (wd->pageflip)
833           {
834              if (wd->front.content)
835                 evas_object_show(wd->front.clip);
836              else
837                 evas_object_hide(wd->front.clip);
838              if (wd->back.content)
839                {
840                   evas_object_move(wd->back.content, 4999, 4999);
841                   evas_object_show(wd->back.clip);
842                }
843              else
844                 evas_object_hide(wd->back.clip);
845           }
846         else
847           {
848              if (wd->front.content)
849                 evas_object_hide(wd->front.clip);
850              else
851                 evas_object_hide(wd->front.clip);
852              if (wd->back.content)
853                 evas_object_show(wd->back.clip);
854              else
855                 evas_object_hide(wd->back.clip);
856           }
857      }
858 }
859
860 static void
861 _flip_do(Evas_Object *obj, double t, Elm_Flip_Mode mode, int lin, int rev)
862 {
863    Evas_Coord x, y, w, h;
864    double p, deg, pp;
865    Evas_Map *mf, *mb;
866    Evas_Coord cx, cy, px, py, foc;
867    int lx, ly, lz, lr, lg, lb, lar, lag, lab;
868    Widget_Data *wd = elm_widget_data_get(obj);
869
870    if (!wd) return;
871
872    mf = evas_map_new(4);
873    evas_map_smooth_set(mf, 0);
874    mb = evas_map_new(4);
875    evas_map_smooth_set(mb, 0);
876
877    if (wd->front.content)
878      {
879         const char *type = evas_object_type_get(wd->front.content);
880
881         // FIXME: only handles filled obj
882         if ((type) && (!strcmp(type, "image")))
883           {
884              int iw, ih;
885              evas_object_image_size_get(wd->front.content, &iw, &ih);
886              evas_object_geometry_get(wd->front.content, &x, &y, &w, &h);
887              evas_map_util_points_populate_from_geometry(mf, x, y, w, h, 0);
888              evas_map_point_image_uv_set(mf, 0, 0, 0);
889              evas_map_point_image_uv_set(mf, 1, iw, 0);
890              evas_map_point_image_uv_set(mf, 2, iw, ih);
891              evas_map_point_image_uv_set(mf, 3, 0, ih);
892           }
893         else
894           {
895              evas_object_geometry_get(wd->front.content, &x, &y, &w, &h);
896              evas_map_util_points_populate_from_geometry(mf, x, y, w, h, 0);
897           }
898      }
899    if (wd->back.content)
900      {
901         const char *type = evas_object_type_get(wd->back.content);
902
903         if ((type) && (!strcmp(type, "image")))
904           {
905              int iw, ih;
906              evas_object_image_size_get(wd->back.content, &iw, &ih);
907              evas_object_geometry_get(wd->back.content, &x, &y, &w, &h);
908              evas_map_util_points_populate_from_geometry(mb, x, y, w, h, 0);
909              evas_map_point_image_uv_set(mb, 0, 0, 0);
910              evas_map_point_image_uv_set(mb, 1, iw, 0);
911              evas_map_point_image_uv_set(mb, 2, iw, ih);
912              evas_map_point_image_uv_set(mb, 3, 0, ih);
913           }
914         else
915           {
916              evas_object_geometry_get(wd->back.content, &x, &y, &w, &h);
917              evas_map_util_points_populate_from_geometry(mb, x, y, w, h, 0);
918           }
919      }
920
921    evas_object_geometry_get(obj, &x, &y, &w, &h);
922
923    cx = x + (w / 2);
924    cy = y + (h / 2);
925
926    px = x + (w / 2);
927    py = y + (h / 2);
928    foc = 2048;
929
930    lx = cx;
931    ly = cy;
932    lz = -10000;
933    lr = 255;
934    lg = 255;
935    lb = 255;
936    lar = 0;
937    lag = 0;
938    lab = 0;
939
940    switch (mode)
941      {
942       case ELM_FLIP_ROTATE_Y_CENTER_AXIS:
943          p = 1.0 - t;
944          pp = p;
945          if (!lin) pp = (p * p);
946          p = 1.0 - pp;
947          if (wd->state) deg = 180.0 * p;
948          else deg = 180 + (180.0 * p);
949          if (rev) deg = -deg;
950          evas_map_util_3d_rotate(mf, 0.0, deg, 0.0, cx, cy, 0);
951          evas_map_util_3d_rotate(mb, 0.0, 180 + deg, 0.0, cx, cy, 0);
952          break;
953       case ELM_FLIP_ROTATE_X_CENTER_AXIS:
954          p = 1.0 - t;
955          pp = p;
956          if (!lin) pp = (p * p);
957          p = 1.0 - pp;
958          if (wd->state) deg = 180.0 * p;
959          else deg = 180 + (180.0 * p);
960          if (rev) deg = -deg;
961          evas_map_util_3d_rotate(mf, deg, 0.0, 0.0, cx, cy, 0);
962          evas_map_util_3d_rotate(mb, 180.0 + deg, 0.0, 0.0, cx, cy, 0);
963          break;
964       case ELM_FLIP_ROTATE_XZ_CENTER_AXIS:
965          p = 1.0 - t;
966          pp = p;
967          if (!lin) pp = (p * p);
968          p = 1.0 - pp;
969          if (wd->state) deg = 180.0 * p;
970          else deg = 180 + (180.0 * p);
971          if (rev) deg = -deg;
972          evas_map_util_3d_rotate(mf, deg, 0.0, deg, cx, cy, 0);
973          evas_map_util_3d_rotate(mb, 180 + deg, 0.0, 180 + deg, cx, cy, 0);
974          break;
975       case ELM_FLIP_ROTATE_YZ_CENTER_AXIS:
976          p = 1.0 - t;
977          pp = p;
978          if (!lin) pp = (p * p);
979          p = 1.0 - pp;
980          if (wd->state) deg = 180.0 * p;
981          else deg = 180 + (180.0 * p);
982          if (rev) deg = -deg;
983          evas_map_util_3d_rotate(mf, 0.0, deg, deg, cx, cy, 0);
984          evas_map_util_3d_rotate(mb, 0.0, 180.0 + deg, 180.0 + deg, cx, cy, 0);
985          break;
986       case ELM_FLIP_CUBE_LEFT:
987          p = 1.0 - t;
988          pp = p;
989          if (!lin) pp = (p * p);
990          p = 1.0 - pp;
991          deg = -90.0 * p;
992          if (wd->state)
993            {
994               evas_map_util_3d_rotate(mf, 0.0, deg, 0.0, cx, cy, w / 2);
995               evas_map_util_3d_rotate(mb, 0.0, deg + 90, 0.0, cx, cy, w / 2);
996            }
997          else
998            {
999               evas_map_util_3d_rotate(mf, 0.0, deg + 90, 0.0, cx, cy, w / 2);
1000               evas_map_util_3d_rotate(mb, 0.0, deg, 0.0, cx, cy, w / 2);
1001            }
1002          break;
1003       case ELM_FLIP_CUBE_RIGHT:
1004          p = 1.0 - t;
1005          pp = p;
1006          if (!lin) pp = (p * p);
1007          p = 1.0 - pp;
1008          deg = 90.0 * p;
1009          if (wd->state)
1010            {
1011               evas_map_util_3d_rotate(mf, 0.0, deg, 0.0, cx, cy, w / 2);
1012               evas_map_util_3d_rotate(mb, 0.0, deg - 90, 0.0, cx, cy, w / 2);
1013            }
1014          else
1015            {
1016               evas_map_util_3d_rotate(mf, 0.0, deg - 90, 0.0, cx, cy, w / 2);
1017               evas_map_util_3d_rotate(mb, 0.0, deg, 0.0, cx, cy, w / 2);
1018            }
1019          break;
1020       case ELM_FLIP_CUBE_UP:
1021          p = 1.0 - t;
1022          pp = p;
1023          if (!lin) pp = (p * p);
1024          p = 1.0 - pp;
1025          deg = -90.0 * p;
1026          if (wd->state)
1027            {
1028               evas_map_util_3d_rotate(mf, deg, 0.0, 0.0, cx, cy, h / 2);
1029               evas_map_util_3d_rotate(mb, deg + 90, 0.0, 0.0, cx, cy, h / 2);
1030            }
1031          else
1032            {
1033               evas_map_util_3d_rotate(mf, deg + 90, 0.0, 0.0, cx, cy, h / 2);
1034               evas_map_util_3d_rotate(mb, deg, 0.0, 0.0, cx, cy, h / 2);
1035            }
1036          break;
1037       case ELM_FLIP_CUBE_DOWN:
1038          p = 1.0 - t;
1039          pp = p;
1040          if (!lin) pp = (p * p);
1041          p = 1.0 - pp;
1042          deg = 90.0 * p;
1043          if (wd->state)
1044            {
1045               evas_map_util_3d_rotate(mf, deg, 0.0, 0.0, cx, cy, h / 2);
1046               evas_map_util_3d_rotate(mb, deg - 90, 0.0, 0.0, cx, cy, h / 2);
1047            }
1048          else
1049            {
1050               evas_map_util_3d_rotate(mf, deg - 90, 0.0, 0.0, cx, cy, h / 2);
1051               evas_map_util_3d_rotate(mb, deg, 0.0, 0.0, cx, cy, h / 2);
1052            }
1053          break;
1054       case ELM_FLIP_PAGE_LEFT:
1055         break;
1056       case ELM_FLIP_PAGE_RIGHT:
1057         break;
1058       case ELM_FLIP_PAGE_UP:
1059         break;
1060       case ELM_FLIP_PAGE_DOWN:
1061         break;
1062       default:
1063          break;
1064      }
1065
1066
1067    if (wd->front.content)
1068      {
1069         evas_map_util_3d_lighting(mf, lx, ly, lz, lr, lg, lb, lar, lag, lab);
1070         evas_map_util_3d_perspective(mf, px, py, 0, foc);
1071         evas_object_map_set(wd->front.content, mf);
1072         evas_object_map_enable_set(wd->front.content, 1);
1073         if (evas_map_util_clockwise_get(mf)) evas_object_show(wd->front.clip);
1074         else evas_object_hide(wd->front.clip);
1075      }
1076
1077    if (wd->back.content)
1078      {
1079         evas_map_util_3d_lighting(mb, lx, ly, lz, lr, lg, lb, lar, lag, lab);
1080         evas_map_util_3d_perspective(mb, px, py, 0, foc);
1081         evas_object_map_set(wd->back.content, mb);
1082         evas_object_map_enable_set(wd->back.content, 1);
1083         if (evas_map_util_clockwise_get(mb)) evas_object_show(wd->back.clip);
1084         else evas_object_hide(wd->back.clip);
1085      }
1086
1087    evas_map_free(mf);
1088    evas_map_free(mb);
1089 }
1090
1091 static void
1092 _showhide(Evas_Object *obj)
1093 {
1094    Widget_Data *wd = elm_widget_data_get(obj);
1095    Evas_Coord x, y, w, h;
1096    if (!wd) return;
1097
1098    evas_object_geometry_get(obj, &x, &y, &w, &h);
1099    if (wd->front.content)
1100      {
1101         if ((wd->pageflip) && (wd->state))
1102           {
1103              evas_object_move(wd->front.content, 4999, 4999);
1104           }
1105         else
1106           {
1107              if (!wd->animator)
1108                 evas_object_move(wd->front.content, x, y);
1109           }
1110         evas_object_resize(wd->front.content, w, h);
1111      }
1112    if (wd->back.content)
1113      {
1114         if ((wd->pageflip) && (!wd->state))
1115           {
1116              evas_object_move(wd->back.content, 4999, 4999);
1117           }
1118         else
1119           {
1120              if (!wd->animator)
1121                 evas_object_move(wd->back.content, x, y);
1122           }
1123         evas_object_resize(wd->back.content, w, h);
1124      }
1125
1126 }
1127
1128 static Eina_Bool
1129 _flip(Evas_Object *obj)
1130 {
1131    Widget_Data *wd = elm_widget_data_get(obj);
1132    double t = ecore_loop_time_get() - wd->start;
1133    Evas_Coord w, h;
1134
1135    if (!wd) return ECORE_CALLBACK_CANCEL;
1136    if (!wd->animator) return ECORE_CALLBACK_CANCEL;
1137
1138    t = t / wd->len;
1139    if (t > 1.0) t = 1.0;
1140
1141    evas_object_geometry_get(obj, NULL, NULL, &w, &h);
1142    if (wd->mode == ELM_FLIP_PAGE_LEFT)
1143      {
1144         wd->dir = 0;
1145         wd->started = EINA_TRUE;
1146         wd->pageflip = EINA_TRUE;
1147         wd->down_x = w - 1;
1148         wd->down_y = h / 2;
1149         wd->x = (1.0 - t) * wd->down_x;
1150         wd->y = wd->down_y;
1151         flip_show_hide(obj);
1152         _state_update(wd);
1153      }
1154    else if (wd->mode == ELM_FLIP_PAGE_RIGHT)
1155      {
1156         wd->dir = 1;
1157         wd->started = EINA_TRUE;
1158         wd->pageflip = EINA_TRUE;
1159         wd->down_x = 0;
1160         wd->down_y = h / 2;
1161         wd->x = (t) * w;
1162         wd->y = wd->down_y;
1163         flip_show_hide(obj);
1164         _state_update(wd);
1165      }
1166    else if (wd->mode == ELM_FLIP_PAGE_UP)
1167      {
1168         wd->dir = 2;
1169         wd->started = EINA_TRUE;
1170         wd->pageflip = EINA_TRUE;
1171         wd->down_x = w / 2;
1172         wd->down_y = h - 1;
1173         wd->x = wd->down_x;
1174         wd->y = (1.0 - t) * wd->down_y;
1175         flip_show_hide(obj);
1176         _state_update(wd);
1177      }
1178    else if (wd->mode == ELM_FLIP_PAGE_DOWN)
1179      {
1180         wd->dir = 3;
1181         wd->started = EINA_TRUE;
1182         wd->pageflip = EINA_TRUE;
1183         wd->down_x = w / 2;
1184         wd->down_y = 0;
1185         wd->x = wd->down_x;
1186         wd->y = (t) * h;
1187         flip_show_hide(obj);
1188         _state_update(wd);
1189      }
1190    else
1191       _flip_do(obj, t, wd->mode, 0, 0);
1192
1193    if (t >= 1.0)
1194      {
1195         wd->pageflip = EINA_FALSE;
1196         _state_end(wd);
1197         evas_object_map_enable_set(wd->front.content, 0);
1198         evas_object_map_enable_set(wd->back.content, 0);
1199         // FIXME: hack around evas rendering bug (only fix makes evas bitch-slow
1200         evas_object_resize(wd->front.content, 0, 0);
1201         evas_object_resize(wd->back.content, 0, 0);
1202         evas_smart_objects_calculate(evas_object_evas_get(obj));
1203         // FIXME: end hack
1204         wd->animator = NULL;
1205         wd->state = !wd->state;
1206         _configure(obj);
1207         flip_show_hide(obj);
1208         evas_object_smart_callback_call(obj, SIG_ANIMATE_DONE, NULL);
1209         return ECORE_CALLBACK_CANCEL;
1210      }
1211    return ECORE_CALLBACK_RENEW;
1212 }
1213
1214 static void
1215 _configure(Evas_Object *obj)
1216 {
1217    Widget_Data *wd = elm_widget_data_get(obj);
1218    Evas_Coord x, y, w, h;
1219    Evas_Coord fsize;
1220    if (!wd) return;
1221
1222    _showhide(obj);
1223    evas_object_geometry_get(obj, &x, &y, &w, &h);
1224    // FIXME: manual flip wont get fixed
1225    if (wd->animator) _flip(obj);
1226
1227    if (wd->event[0])
1228      {
1229         fsize = (double)w * wd->dir_hitsize[0];
1230         elm_coords_finger_size_adjust(0, NULL, 1, &fsize);
1231         evas_object_move(wd->event[0], x, y);
1232         evas_object_resize(wd->event[0], w, fsize);
1233      }
1234    if (wd->event[1])
1235      {
1236         fsize = (double)w * wd->dir_hitsize[1];
1237         elm_coords_finger_size_adjust(0, NULL, 1, &fsize);
1238         evas_object_move(wd->event[1], x, y + h - fsize);
1239         evas_object_resize(wd->event[1], w, fsize);
1240      }
1241    if (wd->event[2])
1242      {
1243         fsize = (double)h * wd->dir_hitsize[2];
1244         elm_coords_finger_size_adjust(1, &fsize, 0, NULL);
1245         evas_object_move(wd->event[2], x, y);
1246         evas_object_resize(wd->event[2], fsize, h);
1247      }
1248    if (wd->event[3])
1249      {
1250         fsize = (double)h * wd->dir_hitsize[3];
1251         elm_coords_finger_size_adjust(1, &fsize, 0, NULL);
1252         evas_object_move(wd->event[3], x + w - fsize, y);
1253         evas_object_resize(wd->event[3], fsize, h);
1254      }
1255 }
1256
1257 static void
1258 _move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1259 {
1260    _configure(obj);
1261 }
1262
1263 static void
1264 _resize(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
1265 {
1266    _configure(obj);
1267 }
1268
1269 static Eina_Bool
1270 _animate(void *data)
1271 {
1272    return _flip(data);
1273 }
1274
1275 static double
1276 _pos_get(Widget_Data *wd, int *rev, Elm_Flip_Mode *m)
1277 {
1278    Evas_Coord x, y, w, h;
1279    double t = 1.0;
1280
1281    evas_object_geometry_get(wd->obj, &x, &y, &w, &h);
1282    switch (wd->intmode)
1283      {
1284       case ELM_FLIP_INTERACTION_ROTATE:
1285       case ELM_FLIP_INTERACTION_CUBE:
1286           {
1287              if (wd->dir == 0)
1288                {
1289                   if (wd->down_x > 0)
1290                      t = 1.0 - ((double)wd->x / (double)wd->down_x);
1291                   *rev = 1;
1292                }
1293              else if (wd->dir == 1)
1294                {
1295                   if (wd->down_x < w)
1296                      t = 1.0 - ((double)(w - wd->x) / (double)(w - wd->down_x));
1297                }
1298              else if (wd->dir == 2)
1299                {
1300                   if (wd->down_y > 0)
1301                      t = 1.0 - ((double)wd->y / (double)wd->down_y);
1302                }
1303              else if (wd->dir == 3)
1304                {
1305                   if (wd->down_y < h)
1306                      t = 1.0 - ((double)(h - wd->y) / (double)(h - wd->down_y));
1307                   *rev = 1;
1308                }
1309
1310              if (t < 0.0) t = 0.0;
1311              else if (t > 1.0) t = 1.0;
1312
1313              if ((wd->dir == 0) || (wd->dir == 1))
1314                {
1315                   if (wd->intmode == ELM_FLIP_INTERACTION_ROTATE)
1316                      *m = ELM_FLIP_ROTATE_Y_CENTER_AXIS;
1317                   else if (wd->intmode == ELM_FLIP_INTERACTION_CUBE)
1318                     {
1319                        if (*rev)
1320                           *m = ELM_FLIP_CUBE_LEFT;
1321                        else
1322                           *m = ELM_FLIP_CUBE_RIGHT;
1323                     }
1324                }
1325              else
1326                {
1327                   if (wd->intmode == ELM_FLIP_INTERACTION_ROTATE)
1328                      *m = ELM_FLIP_ROTATE_X_CENTER_AXIS;
1329                   else if (wd->intmode == ELM_FLIP_INTERACTION_CUBE)
1330                     {
1331                        if (*rev)
1332                           *m = ELM_FLIP_CUBE_UP;
1333                        else
1334                           *m = ELM_FLIP_CUBE_DOWN;
1335                     }
1336                }
1337           }
1338       default:
1339         break;
1340      }
1341    return t;
1342 }
1343
1344 static Eina_Bool
1345 _event_anim(void *data, double pos)
1346 {
1347    Widget_Data *wd = data;
1348    double p;
1349
1350    p = ecore_animator_pos_map(pos, ECORE_POS_MAP_ACCELERATE, 0.0, 0.0);
1351    if (wd->finish)
1352      {
1353         if (wd->dir == 0)
1354            wd->x = wd->ox * (1.0 - p);
1355         else if (wd->dir == 1)
1356            wd->x = wd->ox + ((wd->w - wd->ox) * p);
1357         else if (wd->dir == 2)
1358            wd->y = wd->oy * (1.0 - p);
1359         else if (wd->dir == 3)
1360            wd->y = wd->oy + ((wd->h - wd->oy) * p);
1361      }
1362    else
1363      {
1364         if (wd->dir == 0)
1365            wd->x = wd->ox + ((wd->w - wd->ox) * p);
1366         else if (wd->dir == 1)
1367            wd->x = wd->ox * (1.0 - p);
1368         else if (wd->dir == 2)
1369            wd->y = wd->oy + ((wd->h - wd->oy) * p);
1370         else if (wd->dir == 3)
1371            wd->y = wd->oy * (1.0 - p);
1372      }
1373    switch (wd->intmode)
1374      {
1375       case ELM_FLIP_INTERACTION_NONE:
1376         break;
1377       case ELM_FLIP_INTERACTION_ROTATE:
1378       case ELM_FLIP_INTERACTION_CUBE:
1379           {
1380              Elm_Flip_Mode m = ELM_FLIP_ROTATE_X_CENTER_AXIS;
1381              int rev = 0;
1382              p = _pos_get(wd, &rev, &m);
1383              _flip_do(wd->obj, p, m, 1, rev);
1384           }
1385         break;
1386       case ELM_FLIP_INTERACTION_PAGE:
1387         wd->pageflip = EINA_TRUE;
1388         _configure(data);
1389         _state_update(wd);
1390         break;
1391       default:
1392         break;
1393      }
1394    if (pos < 1.0) return ECORE_CALLBACK_RENEW;
1395
1396    wd->pageflip = EINA_FALSE;
1397    _state_end(wd);
1398    evas_object_map_enable_set(wd->front.content, 0);
1399    evas_object_map_enable_set(wd->back.content, 0);
1400    // FIXME: hack around evas rendering bug (only fix makes evas bitch-slow
1401    evas_object_resize(wd->front.content, 0, 0);
1402    evas_object_resize(wd->back.content, 0, 0);
1403    evas_smart_objects_calculate(evas_object_evas_get(wd->obj));
1404    // FIXME: end hack
1405    wd->animator = NULL;
1406    if (wd->finish) wd->state = !wd->state;
1407    flip_show_hide(wd->obj);
1408    _configure(wd->obj);
1409    wd->animator = NULL;
1410    evas_object_smart_callback_call(wd->obj, SIG_ANIMATE_DONE, NULL);
1411
1412    return ECORE_CALLBACK_CANCEL;
1413 }
1414
1415 static void
1416 _update_job(void *data)
1417 {
1418    Widget_Data *wd = data;
1419    double p;
1420    Elm_Flip_Mode m = ELM_FLIP_ROTATE_X_CENTER_AXIS;
1421    int rev = 0;
1422
1423    wd->job = NULL;
1424    switch (wd->intmode)
1425      {
1426       case ELM_FLIP_INTERACTION_ROTATE:
1427       case ELM_FLIP_INTERACTION_CUBE:
1428         p = _pos_get(wd, &rev, &m);
1429         _flip_do(wd->obj, p, m, 1, rev);
1430         break;
1431       case ELM_FLIP_INTERACTION_PAGE:
1432         wd->pageflip = EINA_TRUE;
1433         _configure(data);
1434         _state_update(wd);
1435         break;
1436       default:
1437         break;
1438      }
1439 }
1440
1441 static void
1442 _down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1443 {
1444    Evas_Object *fl = data;
1445    Widget_Data *wd = elm_widget_data_get(fl);
1446    Evas_Event_Mouse_Down *ev = event_info;
1447    Evas_Coord x, y, w, h;
1448
1449    if (!wd) return;
1450    if (ev->button != 1) return;
1451    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1452    if (wd->animator)
1453      {
1454         ecore_animator_del(wd->animator);
1455         wd->animator = NULL;
1456      }
1457    wd->down = EINA_TRUE;
1458    wd->started = EINA_FALSE;
1459    evas_object_geometry_get(data, &x, &y, &w, &h);
1460    wd->x = ev->canvas.x - x;
1461    wd->y = ev->canvas.y - y;
1462    wd->w = w;
1463    wd->h = h;
1464    wd->down_x = wd->x;
1465    wd->down_y = wd->y;
1466 }
1467
1468 static void
1469 _up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1470 {
1471    Evas_Object *fl = data;
1472    Widget_Data *wd = elm_widget_data_get(fl);
1473    Evas_Event_Mouse_Up *ev = event_info;
1474    Evas_Coord x, y, w, h;
1475    double tm = 0.5;
1476
1477    if (!wd) return;
1478    if (ev->button != 1) return;
1479    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1480    wd->down = 0;
1481    evas_object_geometry_get(data, &x, &y, &w, &h);
1482    wd->x = ev->canvas.x - x;
1483    wd->y = ev->canvas.y - y;
1484    wd->w = w;
1485    wd->h = h;
1486    wd->ox = wd->x;
1487    wd->oy = wd->y;
1488    if (wd->job)
1489      {
1490         ecore_job_del(wd->job);
1491         wd->job = NULL;
1492      }
1493    wd->finish = EINA_FALSE;
1494    if (wd->dir == 0)
1495      {
1496         tm = (double)wd->x / (double)wd->w;
1497         if (wd->x < (wd->w / 2)) wd->finish = EINA_TRUE;
1498      }
1499    else if (wd->dir == 1)
1500      {
1501         if (wd->x > (wd->w / 2)) wd->finish = EINA_TRUE;
1502         tm = 1.0 - ((double)wd->x / (double)wd->w);
1503      }
1504    else if (wd->dir == 2)
1505      {
1506         if (wd->y < (wd->h / 2)) wd->finish = EINA_TRUE;
1507         tm = (double)wd->y / (double)wd->h;
1508      }
1509    else if (wd->dir == 3)
1510      {
1511         if (wd->y > (wd->h / 2)) wd->finish = EINA_TRUE;
1512         tm = 1.0 - ((double)wd->y / (double)wd->h);
1513      }
1514    if (tm < 0.01) tm = 0.01;
1515    else if (tm > 0.99) tm = 0.99;
1516    if (!wd->finish) tm = 1.0 - tm;
1517    tm *= 1.0; // FIXME: config for anim time
1518    if (wd->animator) ecore_animator_del(wd->animator);
1519    wd->animator = ecore_animator_timeline_add(tm, _event_anim, wd);
1520    _event_anim(wd, 0.0);
1521 }
1522
1523 static void
1524 _move_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1525 {
1526    Evas_Object *fl = data;
1527    Widget_Data *wd = elm_widget_data_get(fl);
1528    Evas_Event_Mouse_Move *ev = event_info;
1529    Evas_Coord x, y, w, h;
1530
1531    if (!wd) return;
1532    if (!wd->down) return;
1533    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return ;
1534    evas_object_geometry_get(data, &x, &y, &w, &h);
1535    wd->x = ev->cur.canvas.x - x;
1536    wd->y = ev->cur.canvas.y - y;
1537    wd->w = w;
1538    wd->h = h;
1539    if (!wd->started)
1540      {
1541         Evas_Coord dx, dy;
1542
1543         dx = wd->x - wd->down_x;
1544         dy = wd->y - wd->down_y;
1545         if (((dx * dx) + (dy * dy)) > (_elm_config->finger_size * _elm_config->finger_size / 4))
1546           {
1547              wd->dir = 0;
1548              if      ((wd->x > (w / 2)) && (dx <  0) && (abs(dx) >  abs(dy))) wd->dir = 0; // left
1549              else if ((wd->x < (w / 2)) && (dx >= 0) && (abs(dx) >  abs(dy))) wd->dir = 1; // right
1550              else if ((wd->y > (h / 2)) && (dy <  0) && (abs(dy) >= abs(dx))) wd->dir = 2; // up
1551              else if ((wd->y < (h / 2)) && (dy >= 0) && (abs(dy) >= abs(dx))) wd->dir = 3; // down
1552              wd->started = EINA_TRUE;
1553              if (wd->intmode == ELM_FLIP_INTERACTION_PAGE)
1554                 wd->pageflip = EINA_TRUE;
1555              flip_show_hide(data);
1556              evas_smart_objects_calculate(evas_object_evas_get(data));
1557              _flip(data);
1558              // FIXME: hack around evas rendering bug (only fix makes evas bitch-slow)
1559              evas_object_map_enable_set(wd->front.content, 0);
1560              evas_object_map_enable_set(wd->back.content, 0);
1561 // FIXME: XXX why does this bork interactive flip??
1562 //             evas_object_resize(wd->front.content, 0, 0);
1563 //             evas_object_resize(wd->back.content, 0, 0);
1564              evas_smart_objects_calculate(evas_object_evas_get(data));
1565              _configure(obj);
1566              // FIXME: end hack
1567              evas_object_smart_callback_call(obj, SIG_ANIMATE_BEGIN, NULL);
1568           }
1569         else return;
1570      }
1571    ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
1572    if (wd->job) ecore_job_del(wd->job);
1573    wd->job = ecore_job_add(_update_job, wd);
1574 }
1575
1576 EAPI Evas_Object *
1577 elm_flip_add(Evas_Object *parent)
1578 {
1579    Evas_Object *obj;
1580    Evas *e;
1581    Widget_Data *wd;
1582
1583    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1584
1585    ELM_SET_WIDTYPE(widtype, "flip");
1586    elm_widget_type_set(obj, "flip");
1587    elm_widget_sub_object_add(parent, obj);
1588    elm_widget_data_set(obj, wd);
1589    elm_widget_del_hook_set(obj, _del_hook);
1590    elm_widget_theme_hook_set(obj, _theme_hook);
1591    elm_widget_focus_next_hook_set(obj, _elm_flip_focus_next_hook);
1592    elm_widget_can_focus_set(obj, EINA_FALSE);
1593
1594    wd->obj = obj;
1595
1596    wd->clip = evas_object_rectangle_add(e);
1597    evas_object_static_clip_set(wd->clip, 1);
1598    evas_object_color_set(wd->clip, 255, 255, 255, 255);
1599    evas_object_move(wd->clip, -49999, -49999);
1600    evas_object_resize(wd->clip, 99999, 99999);
1601    elm_widget_sub_object_add(obj, wd->clip);
1602    evas_object_clip_set(wd->clip, evas_object_clip_get(obj));
1603    evas_object_smart_member_add(wd->clip, obj);
1604
1605    wd->front.clip = evas_object_rectangle_add(e);
1606    evas_object_static_clip_set(wd->front.clip, 1);
1607    evas_object_data_set(wd->front.clip, "_elm_leaveme", obj);
1608    evas_object_color_set(wd->front.clip, 255, 255, 255, 255);
1609    evas_object_move(wd->front.clip, -49999, -49999);
1610    evas_object_resize(wd->front.clip, 99999, 99999);
1611    elm_widget_sub_object_add(obj, wd->front.clip);
1612    evas_object_smart_member_add(wd->front.clip, obj);
1613    evas_object_clip_set(wd->front.clip, wd->clip);
1614
1615    wd->back.clip = evas_object_rectangle_add(e);
1616    evas_object_static_clip_set(wd->back.clip, 1);
1617    evas_object_data_set(wd->back.clip, "_elm_leaveme", obj);
1618    evas_object_color_set(wd->back.clip, 255, 255, 255, 255);
1619    evas_object_move(wd->back.clip, -49999, -49999);
1620    evas_object_resize(wd->back.clip, 99999, 99999);
1621    elm_widget_sub_object_add(wd->back.clip, obj);
1622    evas_object_smart_member_add(obj, wd->back.clip);
1623    evas_object_clip_set(wd->back.clip, wd->clip);
1624
1625    evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
1626    evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _move, NULL);
1627    evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, NULL);
1628
1629    evas_object_smart_callbacks_descriptions_set(obj, _signals);
1630
1631    wd->state = 1;
1632    wd->intmode = ELM_FLIP_INTERACTION_NONE;
1633
1634    _sizing_eval(obj);
1635
1636    return obj;
1637 }
1638
1639 EAPI void
1640 elm_flip_content_front_set(Evas_Object *obj, Evas_Object *content)
1641 {
1642    ELM_CHECK_WIDTYPE(obj, widtype);
1643    Widget_Data *wd = elm_widget_data_get(obj);
1644    int i;
1645    if (!wd) return;
1646    if (wd->front.content == content) return;
1647    if (wd->front.content) evas_object_del(wd->back.content);
1648    wd->front.content = content;
1649    if (content)
1650      {
1651         elm_widget_sub_object_add(obj, content);
1652         evas_object_smart_member_add(content, obj);
1653         evas_object_clip_set(content, wd->front.clip);
1654         evas_object_event_callback_add(content,
1655                                        EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1656                                        _changed_size_hints, obj);
1657         _sizing_eval(obj);
1658      }
1659    // force calc to contents are the right size before transition
1660    evas_smart_objects_calculate(evas_object_evas_get(obj));
1661    flip_show_hide(obj);
1662    _configure(obj);
1663    if (wd->intmode != ELM_FLIP_INTERACTION_NONE)
1664      {
1665         for (i = 0; i < 4; i++) evas_object_raise(wd->event[i]);
1666      }
1667 }
1668
1669 EAPI void
1670 elm_flip_content_back_set(Evas_Object *obj, Evas_Object *content)
1671 {
1672    ELM_CHECK_WIDTYPE(obj, widtype);
1673    Widget_Data *wd = elm_widget_data_get(obj);
1674    int i;
1675    if (!wd) return;
1676    if (wd->back.content == content) return;
1677    if (wd->back.content) evas_object_del(wd->back.content);
1678    wd->back.content = content;
1679    if (content)
1680      {
1681         elm_widget_sub_object_add(obj, content);
1682         evas_object_smart_member_add(content, obj);
1683         evas_object_clip_set(content, wd->back.clip);
1684         evas_object_event_callback_add(content,
1685                                        EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1686                                        _changed_size_hints, obj);
1687         _sizing_eval(obj);
1688      }
1689    // force calc to contents are the right size before transition
1690    evas_smart_objects_calculate(evas_object_evas_get(obj));
1691    flip_show_hide(obj);
1692    _configure(obj);
1693    if (wd->intmode != ELM_FLIP_INTERACTION_NONE)
1694      {
1695         for (i = 0; i < 4; i++) evas_object_raise(wd->event[i]);
1696      }
1697 }
1698
1699 EAPI Evas_Object *
1700 elm_flip_content_front_get(const Evas_Object *obj)
1701 {
1702    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1703    Widget_Data *wd = elm_widget_data_get(obj);
1704    return wd->front.content;
1705 }
1706
1707
1708 EAPI Evas_Object *
1709 elm_flip_content_back_get(const Evas_Object *obj)
1710 {
1711    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1712    Widget_Data *wd = elm_widget_data_get(obj);
1713    return wd->back.content;
1714 }
1715
1716 EAPI Evas_Object *
1717 elm_flip_content_front_unset(Evas_Object *obj)
1718 {
1719    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1720    Widget_Data *wd = elm_widget_data_get(obj);
1721    if (!wd) return NULL;
1722    if (!wd->front.content) return NULL;
1723    Evas_Object *content = wd->front.content;
1724    evas_object_clip_unset(content);
1725    elm_widget_sub_object_del(obj, content);
1726    evas_object_smart_member_del(content);
1727    wd->front.content = NULL;
1728    return content;
1729 }
1730
1731 EAPI Evas_Object *
1732 elm_flip_content_back_unset(Evas_Object *obj)
1733 {
1734    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1735    Widget_Data *wd = elm_widget_data_get(obj);
1736    if (!wd) return NULL;
1737    if (!wd->back.content) return NULL;
1738    Evas_Object *content = wd->back.content;
1739    evas_object_clip_unset(content);
1740    elm_widget_sub_object_del(obj, content);
1741    evas_object_smart_member_del(content);
1742    wd->back.content = NULL;
1743    return content;
1744 }
1745
1746 EAPI Eina_Bool
1747 elm_flip_front_get(const Evas_Object *obj)
1748 {
1749    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1750    Widget_Data *wd = elm_widget_data_get(obj);
1751    if (!wd) return EINA_FALSE;
1752    return wd->state;
1753 }
1754
1755 EAPI void
1756 elm_flip_perspective_set(Evas_Object *obj, Evas_Coord foc __UNUSED__, Evas_Coord x __UNUSED__, Evas_Coord y __UNUSED__)
1757 {
1758    ELM_CHECK_WIDTYPE(obj, widtype);
1759    Widget_Data *wd = elm_widget_data_get(obj);
1760    if (!wd) return;
1761 }
1762
1763 // FIXME: add ambient and lighting control
1764
1765 EAPI void
1766 elm_flip_go(Evas_Object *obj, Elm_Flip_Mode mode)
1767 {
1768    ELM_CHECK_WIDTYPE(obj, widtype);
1769    Widget_Data *wd = elm_widget_data_get(obj);
1770    if (!wd) return;
1771    if (!wd->animator) wd->animator = ecore_animator_add(_animate, obj);
1772    flip_show_hide(obj);
1773    wd->mode = mode;
1774    wd->start = ecore_loop_time_get();
1775    wd->len = 0.5; // FIXME: make config val
1776    if ((wd->mode == ELM_FLIP_PAGE_LEFT) ||
1777        (wd->mode == ELM_FLIP_PAGE_RIGHT) ||
1778        (wd->mode == ELM_FLIP_PAGE_UP) ||
1779        (wd->mode == ELM_FLIP_PAGE_DOWN))
1780       wd->pageflip = EINA_TRUE;
1781    // force calc to contents are the right size before transition
1782    evas_smart_objects_calculate(evas_object_evas_get(obj));
1783    _flip(obj);
1784    // FIXME: hack around evas rendering bug (only fix makes evas bitch-slow)
1785    evas_object_map_enable_set(wd->front.content, 0);
1786    evas_object_map_enable_set(wd->back.content, 0);
1787    evas_object_resize(wd->front.content, 0, 0);
1788    evas_object_resize(wd->back.content, 0, 0);
1789    evas_smart_objects_calculate(evas_object_evas_get(obj));
1790    _configure(obj);
1791    // FIXME: end hack
1792    evas_object_smart_callback_call(obj, SIG_ANIMATE_BEGIN, NULL);
1793 }
1794
1795 EAPI void
1796 elm_flip_interaction_set(Evas_Object *obj, Elm_Flip_Interaction mode)
1797 {
1798    ELM_CHECK_WIDTYPE(obj, widtype);
1799    int i;
1800    Widget_Data *wd = elm_widget_data_get(obj);
1801    if (!wd) return;
1802    if (wd->intmode == mode) return;
1803    wd->intmode = mode;
1804    for (i = 0; i < 4; i++)
1805      {
1806         if (wd->intmode == ELM_FLIP_INTERACTION_NONE)
1807           {
1808              if (wd->event[i])
1809                {
1810                   evas_object_del(wd->event[i]);
1811                   wd->event[i] = NULL;
1812                }
1813           }
1814         else
1815           {
1816              if ((wd->dir_enabled[i]) && (!wd->event[i]))
1817                {
1818                   wd->event[i] = evas_object_rectangle_add(evas_object_evas_get(obj));
1819                   elm_widget_sub_object_add(obj, wd->event[i]);
1820                   evas_object_clip_set(wd->event[i], evas_object_clip_get(obj));
1821                   evas_object_color_set(wd->event[i], 0, 0, 0, 0);
1822                   evas_object_show(wd->event[i]);
1823                   evas_object_smart_member_add(wd->event[i], obj);
1824                   evas_object_event_callback_add(wd->event[i], EVAS_CALLBACK_MOUSE_DOWN, _down_cb, obj);
1825                   evas_object_event_callback_add(wd->event[i], EVAS_CALLBACK_MOUSE_UP, _up_cb, obj);
1826                   evas_object_event_callback_add(wd->event[i], EVAS_CALLBACK_MOUSE_MOVE, _move_cb, obj);
1827                }
1828           }
1829      }
1830    _sizing_eval(obj);
1831    _configure(obj);
1832 }
1833
1834 EAPI Elm_Flip_Interaction
1835 elm_flip_interaction_get(const Evas_Object *obj)
1836 {
1837    ELM_CHECK_WIDTYPE(obj, widtype) ELM_FLIP_INTERACTION_NONE;
1838    Widget_Data *wd = elm_widget_data_get(obj);
1839    if (!wd) return ELM_FLIP_INTERACTION_NONE;
1840    return wd->intmode;
1841 }
1842
1843 EAPI void
1844 elm_flip_interacton_direction_enabled_set(Evas_Object *obj, Elm_Flip_Direction dir, Eina_Bool enabled)
1845 {
1846    ELM_CHECK_WIDTYPE(obj, widtype);
1847    Widget_Data *wd = elm_widget_data_get(obj);
1848    int i = -1;
1849    if (!wd) return;
1850    enabled = !!enabled;
1851    if      (dir == ELM_FLIP_DIRECTION_UP)    i = 0;
1852    else if (dir == ELM_FLIP_DIRECTION_DOWN)  i = 1;
1853    else if (dir == ELM_FLIP_DIRECTION_LEFT)  i = 2;
1854    else if (dir == ELM_FLIP_DIRECTION_RIGHT) i = 3;
1855    if (i < 0) return;
1856    if (wd->dir_enabled[i] == enabled) return;
1857    wd->dir_enabled[i] = enabled;
1858    if (wd->intmode == ELM_FLIP_INTERACTION_NONE) return;
1859    if ((wd->dir_enabled[i]) && (!wd->event[i]))
1860      {
1861         wd->event[i] = evas_object_rectangle_add(evas_object_evas_get(obj));
1862         elm_widget_sub_object_add(obj, wd->event[i]);
1863         evas_object_clip_set(wd->event[i], evas_object_clip_get(obj));
1864         evas_object_color_set(wd->event[i], 0, 0, 0, 0);
1865         evas_object_show(wd->event[i]);
1866         evas_object_smart_member_add(wd->event[i], obj);
1867         evas_object_event_callback_add(wd->event[i], EVAS_CALLBACK_MOUSE_DOWN, _down_cb, obj);
1868         evas_object_event_callback_add(wd->event[i], EVAS_CALLBACK_MOUSE_UP, _up_cb, obj);
1869         evas_object_event_callback_add(wd->event[i], EVAS_CALLBACK_MOUSE_MOVE, _move_cb, obj);
1870      }
1871    else if (!(wd->dir_enabled[i]) && (wd->event[i]))
1872      {
1873         evas_object_del(wd->event[i]);
1874         wd->event[i] = NULL;
1875      }
1876    _sizing_eval(obj);
1877    _configure(obj);
1878 }
1879
1880 EAPI Eina_Bool
1881 elm_flip_interacton_direction_enabled_get(Evas_Object *obj, Elm_Flip_Direction dir)
1882 {
1883    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1884    Widget_Data *wd = elm_widget_data_get(obj);
1885    int i = -1;
1886    if (!wd) return EINA_FALSE;
1887    if      (dir == ELM_FLIP_DIRECTION_UP)    i = 0;
1888    else if (dir == ELM_FLIP_DIRECTION_DOWN)  i = 1;
1889    else if (dir == ELM_FLIP_DIRECTION_LEFT)  i = 2;
1890    else if (dir == ELM_FLIP_DIRECTION_RIGHT) i = 3;
1891    if (i < 0) return EINA_FALSE;
1892    return wd->dir_enabled[i];
1893 }
1894
1895 EAPI void
1896 elm_flip_interacton_direction_hitsize_set(Evas_Object *obj, Elm_Flip_Direction dir, double hitsize)
1897 {
1898    ELM_CHECK_WIDTYPE(obj, widtype);
1899    Widget_Data *wd = elm_widget_data_get(obj);
1900    int i = -1;
1901    if (!wd) return;
1902    if      (dir == ELM_FLIP_DIRECTION_UP)    i = 0;
1903    else if (dir == ELM_FLIP_DIRECTION_DOWN)  i = 1;
1904    else if (dir == ELM_FLIP_DIRECTION_LEFT)  i = 2;
1905    else if (dir == ELM_FLIP_DIRECTION_RIGHT) i = 3;
1906    if (i < 0) return;
1907    if (hitsize < 0.0) hitsize = 0.0;
1908    else if (hitsize > 1.0) hitsize = 1.0;
1909    if (wd->dir_hitsize[i] == hitsize) return;
1910    wd->dir_hitsize[i] = hitsize;
1911    _sizing_eval(obj);
1912    _configure(obj);
1913 }
1914
1915 EAPI double
1916 elm_flip_interacton_direction_hitsize_get(Evas_Object *obj, Elm_Flip_Direction dir)
1917 {
1918    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1919    Widget_Data *wd = elm_widget_data_get(obj);
1920    int i = -1;
1921    if (!wd) return 0.0;
1922    if      (dir == ELM_FLIP_DIRECTION_UP)    i = 0;
1923    else if (dir == ELM_FLIP_DIRECTION_DOWN)  i = 1;
1924    else if (dir == ELM_FLIP_DIRECTION_LEFT)  i = 2;
1925    else if (dir == ELM_FLIP_DIRECTION_RIGHT) i = 3;
1926    if (i < 0) return 0.0;
1927    return wd->dir_hitsize[i];
1928 }