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