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);
340 wd->back.clip = evas_object_rectangle_add(e);
341 evas_object_color_set(wd->back.clip, 255, 255, 255, 255);
342 evas_object_move(wd->back.clip, -49999, -49999);
343 evas_object_resize(wd->back.clip, 99999, 99999);
344 elm_widget_sub_object_add(wd->back.clip, obj);
345 evas_object_smart_member_add(wd->back.clip, obj);
347 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
348 evas_object_event_callback_add(obj, EVAS_CALLBACK_MOVE, _move, NULL);
349 evas_object_event_callback_add(obj, EVAS_CALLBACK_RESIZE, _resize, NULL);
358 * Set the flip front content
360 * @param obj The flip object
361 * @param content The content to be used in this flip object
366 elm_flip_content_front_set(Evas_Object *obj, Evas_Object *content)
368 ELM_CHECK_WIDTYPE(obj, widtype);
369 Widget_Data *wd = elm_widget_data_get(obj);
371 if (wd->front.content == content) return;
372 if ((wd->front.content != content) && (wd->front.content))
374 evas_object_clip_set(wd->front.content, NULL);
375 elm_widget_sub_object_del(obj, wd->front.content);
376 evas_object_smart_member_del(wd->front.content);
378 wd->front.content = content;
381 elm_widget_sub_object_add(obj, content);
382 evas_object_smart_member_add(content, obj);
383 evas_object_clip_set(content, wd->front.clip);
384 evas_object_event_callback_add(content,
385 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
386 _changed_size_hints, obj);
388 if (!elm_flip_front_get(obj)) evas_object_hide(wd->front.clip);
389 else evas_object_show(wd->front.clip);
392 evas_object_hide(wd->front.clip);
397 * Set the flip back content
399 * @param obj The flip object
400 * @param content The content to be used in this flip object
405 elm_flip_content_back_set(Evas_Object *obj, Evas_Object *content)
407 ELM_CHECK_WIDTYPE(obj, widtype);
408 Widget_Data *wd = elm_widget_data_get(obj);
410 if (wd->back.content == content) return;
411 if ((wd->back.content != content) && (wd->back.content))
413 evas_object_clip_set(wd->back.content, NULL);
414 elm_widget_sub_object_del(obj, wd->back.content);
415 evas_object_smart_member_del(wd->back.content);
417 wd->back.content = content;
420 elm_widget_sub_object_add(obj, content);
421 evas_object_smart_member_add(content, obj);
422 evas_object_clip_set(content, wd->back.clip);
423 evas_object_event_callback_add(content,
424 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
425 _changed_size_hints, obj);
427 if (elm_flip_front_get(obj)) evas_object_hide(wd->back.clip);
428 else evas_object_show(wd->back.clip);
431 evas_object_hide(wd->back.clip);
436 * Get the flip front content
438 * @param obj The flip object
439 * @return The content to be used in this flip object front
444 elm_flip_content_front_get(const Evas_Object *obj)
446 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
447 Widget_Data *wd = elm_widget_data_get(obj);
448 return wd->front.content;
452 * Get the flip back content
454 * @param obj The flip object
455 * @return The content to be used in this flip object back
460 elm_flip_content_back_get(const Evas_Object *obj)
462 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
463 Widget_Data *wd = elm_widget_data_get(obj);
464 return wd->back.content;
468 * Get flip front visibility state
470 * @param obj The flip object
471 * @return If front front is showing or not currently
476 elm_flip_front_get(const Evas_Object *obj)
478 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
479 Widget_Data *wd = elm_widget_data_get(obj);
480 if (!wd) return EINA_FALSE;
485 * Set flip perspective
487 * @param obj The flip object
488 * @param foc The coordinate to set the focus on
489 * @param x The X coordinate
490 * @param y The Y coordinate
492 * NOTE: This function currently does nothing.
497 elm_flip_perspective_set(Evas_Object *obj, Evas_Coord foc __UNUSED__, Evas_Coord x __UNUSED__, Evas_Coord y __UNUSED__)
499 ELM_CHECK_WIDTYPE(obj, widtype);
500 Widget_Data *wd = elm_widget_data_get(obj);
505 * Runs the flip animation
507 * @param obj The flip object
508 * @param mode The mode type. Currently accepted modes are:
510 * ELM_FLIP_ROTATE_Y_CENTER_AXIS
511 * ELM_FLIP_ROTATE_X_CENTER_AXIS
512 * ELM_FLIP_ROTATE_XZ_CENTER_AXIS
513 * ELM_FLIP_ROTATE_YZ_CENTER_AXIS
515 * ELM_FLIP_CUBE_RIGHT
520 elm_flip_go(Evas_Object *obj, Elm_Flip_Mode mode)
522 ELM_CHECK_WIDTYPE(obj, widtype);
523 Widget_Data *wd = elm_widget_data_get(obj);
525 if (!wd->animator) wd->animator = ecore_animator_add(_animate, obj);
527 wd->start = ecore_loop_time_get();