1 #include <Elementary.h>
8 * This holds 2 content objects: one on the front and one on the back. It
9 * allows you to flip from front to back and vice-versa using various effects.
11 * Supported flip types:
12 * ELM_FLIP_ROTATE_Y_CENTER_AXIS
13 * ELM_FLIP_ROTATE_X_CENTER_AXIS
14 * ELM_FLIP_ROTATE_XZ_CENTER_AXIS
15 * ELM_FLIP_ROTATE_YZ_CENTER_AXIS
17 * Signals that you can add callbacks for are:
19 * "animate,done" - when a flip animation is finished
22 typedef struct _Widget_Data Widget_Data;
26 Ecore_Animator *animator;
30 Evas_Object *content, *clip;
35 static const char *widtype = NULL;
36 static void _del_hook(Evas_Object *obj);
37 static void _theme_hook(Evas_Object *obj);
38 static void _sizing_eval(Evas_Object *obj);
39 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
40 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
42 static void _configure(Evas_Object *obj);
45 _del_hook(Evas_Object *obj)
47 Widget_Data *wd = elm_widget_data_get(obj);
49 if (wd->animator) ecore_animator_del(wd->animator);
54 _theme_hook(Evas_Object *obj)
56 Widget_Data *wd = elm_widget_data_get(obj);
62 _sizing_eval(Evas_Object *obj)
64 Widget_Data *wd = elm_widget_data_get(obj);
65 Evas_Coord minw = -1, minh = -1, minw2 = -1, minh2 = -1;
66 Evas_Coord maxw = -1, maxh = -1, maxw2 = -1, maxh2 = -1;
68 if (wd->front.content)
69 evas_object_size_hint_min_get(wd->front.content, &minw, &minh);
71 evas_object_size_hint_min_get(wd->back.content, &minw2, &minh2);
72 if (wd->front.content)
73 evas_object_size_hint_max_get(wd->front.content, &maxw, &maxh);
75 evas_object_size_hint_max_get(wd->back.content, &maxw2, &maxh2);
77 if (minw2 > minw) minw = minw2;
78 if (minh2 > minh) minh = minh2;
79 if ((maxw2 >= 0) && (maxw2 < maxw)) maxw = maxw2;
80 if ((maxh2 >= 0) && (maxh2 < maxh)) maxh = maxh2;
82 evas_object_size_hint_min_set(obj, minw, minh);
83 evas_object_size_hint_max_set(obj, maxw, maxh);
87 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
89 Widget_Data *wd = elm_widget_data_get(data);
95 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
97 Widget_Data *wd = elm_widget_data_get(obj);
98 Evas_Object *sub = event_info;
100 if (sub == wd->front.content)
102 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
103 _changed_size_hints, obj);
104 wd->front.content = NULL;
105 evas_object_hide(wd->front.clip);
108 else if (sub == wd->back.content)
110 evas_object_event_callback_del_full(sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
111 _changed_size_hints, obj);
112 wd->back.content = NULL;
113 evas_object_hide(wd->back.clip);
119 _flip(Evas_Object *obj)
121 Widget_Data *wd = elm_widget_data_get(obj);
122 double t = ecore_loop_time_get() - wd->start;
123 Evas_Coord x, y, w, h;
126 Evas_Coord cx, cy, px, py, foc;
127 int lx, ly, lz, lr, lg, lb, lar, lag, lab;
128 if (!wd->animator) return ECORE_CALLBACK_CANCEL;
130 if (t > 1.0) t = 1.0;
132 if (!wd) return ECORE_CALLBACK_CANCEL;
133 evas_object_geometry_get(obj, &x, &y, &w, &h);
135 mf = evas_map_new(4);
136 evas_map_smooth_set(mf, 0);
137 mb = evas_map_new(4);
138 evas_map_smooth_set(mb, 0);
140 if (wd->front.content)
141 evas_map_util_points_populate_from_object_full(mf, wd->front.content, 0);
142 if (wd->back.content)
143 evas_map_util_points_populate_from_object_full(mb, wd->back.content, 0);
164 case ELM_FLIP_ROTATE_Y_CENTER_AXIS:
167 if (wd->state) deg = 180.0 * p;
168 else deg = 180 + (180.0 * p);
169 evas_map_util_3d_rotate(mf, 0.0, deg, 0.0, cx, cy, 0);
170 evas_map_util_3d_rotate(mb, 0.0, deg + 180.0, 0.0, cx, cy, 0);
172 case ELM_FLIP_ROTATE_X_CENTER_AXIS:
175 if (wd->state) deg = 180.0 * p;
176 else deg = 180 + (180.0 * p);
177 evas_map_util_3d_rotate(mf, deg, 0.0, 0.0, cx, cy, 0);
178 evas_map_util_3d_rotate(mb, deg + 180.0, 0.0, 0.0, cx, cy, 0);
180 case ELM_FLIP_ROTATE_XZ_CENTER_AXIS:
183 if (wd->state) deg = 180.0 * p;
184 else deg = 180 + (180.0 * p);
185 evas_map_util_3d_rotate(mf, deg, 0.0, deg, cx, cy, 0);
186 evas_map_util_3d_rotate(mb, deg + 180.0, 0.0, deg + 180.0, cx, cy, 0);
188 case ELM_FLIP_ROTATE_YZ_CENTER_AXIS:
191 if (wd->state) deg = 180.0 * p;
192 else deg = 180 + (180.0 * p);
193 evas_map_util_3d_rotate(mf, 0.0, deg, deg, cx, cy, 0);
194 evas_map_util_3d_rotate(mb, 0.0, deg + 180.0, deg + 180.0, cx, cy, 0);
196 case ELM_FLIP_CUBE_LEFT:
202 evas_map_util_3d_rotate(mf, 0.0, deg, 0.0, cx, cy, w / 2);
203 evas_map_util_3d_rotate(mb, 0.0, deg + 90, 0.0, cx, cy, w / 2);
207 evas_map_util_3d_rotate(mf, 0.0, deg + 90, 0.0, cx, cy, w / 2);
208 evas_map_util_3d_rotate(mb, 0.0, deg, 0.0, cx, cy, w / 2);
211 case ELM_FLIP_CUBE_RIGHT:
217 evas_map_util_3d_rotate(mf, 0.0, deg, 0.0, cx, cy, w / 2);
218 evas_map_util_3d_rotate(mb, 0.0, deg - 90, 0.0, cx, cy, w / 2);
222 evas_map_util_3d_rotate(mf, 0.0, deg - 90, 0.0, cx, cy, w / 2);
223 evas_map_util_3d_rotate(mb, 0.0, deg, 0.0, cx, cy, w / 2);
232 if (wd->front.content)
234 evas_map_util_3d_lighting(mf, lx, ly, lz, lr, lg, lb, lar, lag, lab);
235 evas_map_util_3d_perspective(mf, px, py, 0, foc);
236 evas_object_map_set(wd->front.content, mf);
237 evas_object_map_enable_set(wd->front.content, 1);
238 if (evas_map_util_clockwise_get(mf)) evas_object_show(wd->front.clip);
239 else evas_object_hide(wd->front.clip);
242 if (wd->back.content)
244 evas_map_util_3d_lighting(mb, lx, ly, lz, lr, lg, lb, lar, lag, lab);
245 evas_map_util_3d_perspective(mb, px, py, 0, foc);
246 evas_object_map_set(wd->back.content, mb);
247 evas_object_map_enable_set(wd->back.content, 1);
248 if (evas_map_util_clockwise_get(mb)) evas_object_show(wd->back.clip);
249 else evas_object_hide(wd->back.clip);
257 evas_object_map_enable_set(wd->front.content, 0);
258 evas_object_map_enable_set(wd->back.content, 0);
260 wd->state = !wd->state;
262 evas_object_smart_callback_call(obj, "animate,done", NULL);
263 return ECORE_CALLBACK_CANCEL;
265 return ECORE_CALLBACK_RENEW;
269 _configure(Evas_Object *obj)
271 Widget_Data *wd = elm_widget_data_get(obj);
272 Evas_Coord x, y, w, h;
274 evas_object_geometry_get(obj, &x, &y, &w, &h);
275 if (wd->front.content)
278 evas_object_move(wd->front.content, x, y);
279 evas_object_resize(wd->front.content, w, h);
281 if (wd->back.content)
284 evas_object_move(wd->back.content, x, y);
285 evas_object_resize(wd->back.content, w, h);
291 _move(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
297 _resize(void *data __UNUSED__, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
309 * Add a new flip to the parent
311 * @param parent The parent object
312 * @return The new object or NULL if it cannot be created
317 elm_flip_add(Evas_Object *parent)
323 wd = ELM_NEW(Widget_Data);
324 e = evas_object_evas_get(parent);
325 obj = elm_widget_add(e);
326 ELM_SET_WIDTYPE(widtype, "flip");
327 elm_widget_type_set(obj, "flip");
328 elm_widget_sub_object_add(parent, obj);
329 elm_widget_data_set(obj, wd);
330 elm_widget_del_hook_set(obj, _del_hook);
331 elm_widget_theme_hook_set(obj, _theme_hook);
333 wd->front.clip = evas_object_rectangle_add(e);
334 evas_object_color_set(wd->front.clip, 255, 255, 255, 255);
335 evas_object_move(wd->front.clip, -49999, -49999);
336 evas_object_resize(wd->front.clip, 99999, 99999);
337 elm_widget_sub_object_add(wd->front.clip, obj);
338 evas_object_smart_member_add(wd->front.clip, obj);
339 evas_object_clip_set(wd->front.clip, evas_object_clip_get(obj));
341 wd->back.clip = evas_object_rectangle_add(e);
342 evas_object_color_set(wd->back.clip, 255, 255, 255, 255);
343 evas_object_move(wd->back.clip, -49999, -49999);
344 evas_object_resize(wd->back.clip, 99999, 99999);
345 elm_widget_sub_object_add(wd->back.clip, obj);
346 evas_object_smart_member_add(wd->back.clip, obj);
347 evas_object_clip_set(wd->back.clip, evas_object_clip_get(obj));
349 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
350 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _move, NULL);
351 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, NULL);
360 * Set the flip front content
362 * @param obj The flip object
363 * @param content The content to be used in this flip object
368 elm_flip_content_front_set(Evas_Object *obj, Evas_Object *content)
370 ELM_CHECK_WIDTYPE(obj, widtype);
371 Widget_Data *wd = elm_widget_data_get(obj);
373 if (wd->front.content == content) return;
374 if ((wd->front.content != content) && (wd->front.content))
376 evas_object_clip_set(wd->front.content, NULL);
377 elm_widget_sub_object_del(obj, wd->front.content);
378 evas_object_smart_member_del(wd->front.content);
380 wd->front.content = content;
383 elm_widget_sub_object_add(obj, content);
384 evas_object_smart_member_add(content, obj);
385 evas_object_clip_set(content, wd->front.clip);
386 evas_object_event_callback_add(content,
387 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
388 _changed_size_hints, obj);
390 if (!elm_flip_front_get(obj)) evas_object_hide(wd->front.clip);
391 else evas_object_show(wd->front.clip);
394 evas_object_hide(wd->front.clip);
399 * Set the flip back content
401 * @param obj The flip object
402 * @param content The content to be used in this flip object
407 elm_flip_content_back_set(Evas_Object *obj, Evas_Object *content)
409 ELM_CHECK_WIDTYPE(obj, widtype);
410 Widget_Data *wd = elm_widget_data_get(obj);
412 if (wd->back.content == content) return;
413 if ((wd->back.content != content) && (wd->back.content))
415 evas_object_clip_set(wd->back.content, NULL);
416 elm_widget_sub_object_del(obj, wd->back.content);
417 evas_object_smart_member_del(wd->back.content);
419 wd->back.content = content;
422 elm_widget_sub_object_add(obj, content);
423 evas_object_smart_member_add(content, obj);
424 evas_object_clip_set(content, wd->back.clip);
425 evas_object_event_callback_add(content,
426 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
427 _changed_size_hints, obj);
429 if (elm_flip_front_get(obj)) evas_object_hide(wd->back.clip);
430 else evas_object_show(wd->back.clip);
433 evas_object_hide(wd->back.clip);
438 * Get the flip front content
440 * @param obj The flip object
441 * @return The content to be used in this flip object front
446 elm_flip_content_front_get(const Evas_Object *obj)
448 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
449 Widget_Data *wd = elm_widget_data_get(obj);
450 return wd->front.content;
454 * Get the flip back content
456 * @param obj The flip object
457 * @return The content to be used in this flip object back
462 elm_flip_content_back_get(const Evas_Object *obj)
464 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
465 Widget_Data *wd = elm_widget_data_get(obj);
466 return wd->back.content;
470 * Get flip front visibility state
472 * @param obj The flip object
473 * @return If front front is showing or not currently
478 elm_flip_front_get(const Evas_Object *obj)
480 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
481 Widget_Data *wd = elm_widget_data_get(obj);
482 if (!wd) return EINA_FALSE;
487 * Set flip perspective
489 * @param obj The flip object
490 * @param foc The coordinate to set the focus on
491 * @param x The X coordinate
492 * @param y The Y coordinate
494 * NOTE: This function currently does nothing.
499 elm_flip_perspective_set(Evas_Object *obj, Evas_Coord foc __UNUSED__, Evas_Coord x __UNUSED__, Evas_Coord y __UNUSED__)
501 ELM_CHECK_WIDTYPE(obj, widtype);
502 Widget_Data *wd = elm_widget_data_get(obj);
507 * Runs the flip animation
509 * @param obj The flip object
510 * @param mode The mode type. Currently accepted modes are:
512 * ELM_FLIP_ROTATE_Y_CENTER_AXIS
513 * ELM_FLIP_ROTATE_X_CENTER_AXIS
514 * ELM_FLIP_ROTATE_XZ_CENTER_AXIS
515 * ELM_FLIP_ROTATE_YZ_CENTER_AXIS
517 * ELM_FLIP_CUBE_RIGHT
522 elm_flip_go(Evas_Object *obj, Elm_Flip_Mode mode)
524 ELM_CHECK_WIDTYPE(obj, widtype);
525 Widget_Data *wd = elm_widget_data_get(obj);
527 if (!wd->animator) wd->animator = ecore_animator_add(_animate, obj);
529 wd->start = ecore_loop_time_get();