Mobile native

[UI Sample] Evas Map Sample Overview

The Evas Map sample demonstrates how to display a rectangle and an image which are applied by the Evas map using EFL Evas map util functions.

The sample uses functions, such as evas_map_util_3d_rotate() for objects to rotate the map around 3 axes in 3D and evas_map_util_3d_perspective() for objects to apply a perspective transform to the map.

The following figure illustrates the main screen of Evas Map.

Figure: Evas Map screen

Evas Map screen

Implementation

The create_base_gui() function creates the window which consists of a green rectangle added using the evas_object_rectangle_add() and evas_object_color_set() functions and an image added using the evas_object_image_filled_add() and evas_object_image_file_set() functions.

The rotate function rotates objects around 3 axes in 3D using the evas_map_util_3d_rotate() function and applies a perspective transform for objects using the evas_map_util_3d_perspective() function. The Evas map is needed to use these functions. So, the evas_map_new() function for creating a map consisting of 4 points and the evas_map_util_points_populate_from_object_full() function for setting the object UV values to the map are used.

// Rotate any Evas object by using Evas map
void
rotate(Evas_Object *obj, double degree)
{
   // Create a map consisting of 4 points
   Evas_Map *map = evas_map_new(4);

   Evas_Coord x, y, w, h;

   // Get the geometry information from the object
   evas_object_geometry_get(obj, &x, &y, &w, &h);

   // Set the object image UV values to map
   evas_map_util_points_populate_from_object_full(map, obj, 0);

   // Rotate by 45 degrees on object's local Y axis
   evas_map_util_3d_rotate(map, 0, degree, 0, x + w / 2, y + h / 2, 0);

   // Set the perspective transform
   evas_map_util_3d_perspective(map, x + w / 2, y + h / 2, 0, 400);

   // Enable the object map
   evas_object_map_enable_set(obj, EINA_TRUE);

   // Apply the new map to object
   evas_object_map_set(obj, map);

   // Free the map resource
   evas_map_free(map);
}

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);

   if (elm_win_wm_rotation_supported_get(ad->win)) 
   {
      int rots[4] = { 0, 90, 180, 270 };
      elm_win_wm_rotation_available_rotations_set(ad->win, (const int *)(&rots), 4);
   }

   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);

   // Conformant
   ad->conform = elm_conformant_add(ad->win);
   elm_win_indicator_mode_set(ad->win, ELM_WIN_INDICATOR_SHOW);
   elm_win_indicator_opacity_set(ad->win, ELM_WIN_INDICATOR_OPAQUE);
   evas_object_size_hint_weight_set(ad->conform, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
   elm_win_resize_object_add(ad->win, ad->conform);
   evas_object_show(ad->conform);

   // Evas map
   Evas *evas = evas_object_evas_get(ad->conform);
   Evas_Object *green_rect = evas_object_rectangle_add(evas);
   evas_object_color_set(green_rect, 0, 255, 0, 255);
   evas_object_move(green_rect, 50, 75);
   evas_object_resize(green_rect, 200, 200);
   rotate(green_rect, 45);
   evas_object_show(green_rect);

   char img_path[PATH_MAX] = { 0, };
   app_get_resource("tizen.png", img_path, PATH_MAX);

   Evas_Object *img = evas_object_image_filled_add(evas);
   evas_object_image_file_set(img, img_path, NULL);
   evas_object_move(img, 100, 325);
   evas_object_resize(img, 356, 96);
   rotate(img, 45);
   evas_object_show(img);

   // Show the window after the base GUI is set up
   evas_object_show(ad->win);
}
Go to top