[UI Sample] Evas Map Rotation Sample Overview
The Evas Map Rotation sample demonstrates how to rotate a button in 3D using EFL map functions. A map consists of a set of points (currently only 4 are supported). Each of these points contains a set of canvas x and y coordinates that can be used to alter the geometry of the mapped object.
The following figure illustrates the Evas Map Rotation screen.
Figure: Evas Map Rotation screen
Implementation
The create_base_gui() function draws the button in 3D by creating a button and animating it with the ecore_animator_add() function.
#include "evasmaprotation.h" static void create_base_gui(appdata_s *ad) { // Window ad->win = elm_win_util_standard_add(PACKAGE, PACKAGE); elm_win_autodel_set(ad->win, EINA_TRUE); evas_object_smart_callback_add(ad->win, "delete,request", win_delete_request_cb, NULL); eext_object_event_callback_add(ad->win, EEXT_CALLBACK_BACK, win_back_cb, ad); Evas_Object *btn; // Create a button btn = elm_button_add(ad->win); elm_object_text_set(btn, "Evas<br>Map<br> Rotation"); evas_object_move(btn, 100, 100); evas_object_resize(btn, 300, 300); evas_object_show(btn); ecore_animator_add(evas_map_rotation_exam_animator_cb, btn); // Show the window after the base GUI is set up evas_object_show(ad->win); }
The evas_object_geometry_get() function obtains the position of the button. The evas_map_new() function creates an Evas map and the evas_map_util_points_populate_from_object_full() function populates the source and destination map points to match the button. The button is rotated and a perspective transform is applied with the evas_map_util_3d_rotate() and evas_map_util_3d_perspective() functions. The evas_object_map_set() function applies the map to the button object.
Eina_Bool evas_map_rotation_exam_animator_cb(void *data) { static int i = 0; Evas_Map *map; Evas_Object *btn = data; Evas_Coord x, y, w, h; i++; if (i > 360) i = 0; evas_object_geometry_get(btn, &x, &y, &w, &h); // Create an Evas map map = evas_map_new(4); evas_map_util_points_populate_from_object_full(map, btn, 0); evas_map_util_3d_rotate(map, i, 0, 0, x + (w / 2), y + (h / 2), 0); evas_map_util_3d_perspective(map, x + (w / 2), y + (h / 2), 0, 300); // Apply map to button object evas_object_map_set(btn, map); // Free map resource evas_map_free(map); // Enable map feature evas_object_map_enable_set(btn, EINA_TRUE); return ECORE_CALLBACK_RENEW; }