edje: Add support for map zoom to use other part center.
authorSubodh Kumar <s7158.kumar@samsung.com>
Fri, 12 Jul 2019 15:58:35 +0000 (11:58 -0400)
committerTaehyub Kim <taehyub.kim@samsung.com>
Wed, 17 Jul 2019 07:20:31 +0000 (16:20 +0900)
Summary:
Current:
In edc, zoom is supposed to happen from object center, there is no way to
change the center of the zoom.

Changes:
Adding support to change the center of zooming just like map rotation by using
other part's center.

@feature

Reviewers: cedric, zmike

Reviewed By: zmike

Subscribers: zmike, cedric, #reviewers, #committers

Tags: #efl

Differential Revision: https://phab.enlightenment.org/D9115

src/bin/edje/edje_cc_handlers.c
src/examples/edje.mk
src/examples/edje/center_zoom.edc [new file with mode: 0644]
src/examples/edje/meson.build
src/lib/edje/edje_calc.c
src/lib/edje/edje_data.c
src/lib/edje/edje_main.c
src/lib/edje/edje_private.h

index 91f6369..d8c287e 100644 (file)
@@ -514,6 +514,7 @@ static void       st_collections_group_parts_part_description_map_perspective_on
 static void       st_collections_group_parts_part_description_map_color(void);
 static void       st_collections_group_parts_part_description_map_zoom_x(void);
 static void       st_collections_group_parts_part_description_map_zoom_y(void);
+static void       st_collections_group_parts_part_description_map_zoom_center(void);
 static void       st_collections_group_parts_part_description_perspective_zplane(void);
 static void       st_collections_group_parts_part_description_perspective_focal(void);
 static void       st_collections_group_parts_part_api(void);
@@ -1060,6 +1061,7 @@ New_Statement_Handler statement_handlers[] =
    {"collections.group.parts.part.description.map.color", st_collections_group_parts_part_description_map_color},
    {"collections.group.parts.part.description.map.zoom.x", st_collections_group_parts_part_description_map_zoom_x},
    {"collections.group.parts.part.description.map.zoom.y", st_collections_group_parts_part_description_map_zoom_y},
+   {"collections.group.parts.part.description.map.zoom.center", st_collections_group_parts_part_description_map_zoom_center},
    {"collections.group.parts.part.description.perspective.zplane", st_collections_group_parts_part_description_perspective_zplane},
    {"collections.group.parts.part.description.perspective.focal", st_collections_group_parts_part_description_perspective_focal},
    {"collections.group.parts.part.description.params.int", st_collections_group_parts_part_description_params_int},
@@ -6547,6 +6549,7 @@ _part_desc_free(Edje_Part_Collection *pc,
    part_lookup_del(pc, &(ed->map.id_persp));
    part_lookup_del(pc, &(ed->map.id_light));
    part_lookup_del(pc, &(ed->map.rot.id_center));
+   part_lookup_del(pc, &(ed->map.zoom.id_center));
 
    switch (ep->type)
      {
@@ -8700,6 +8703,7 @@ ob_collections_group_parts_part_description(void)
   ed->map.id_persp = -1;
   ed->map.id_light = -1;
   ed->map.rot.id_center = -1;
+  ed->map.zoom.id_center = -1;
   ed->map.rot.x = FROM_DOUBLE(0.0);
   ed->map.rot.y = FROM_DOUBLE(0.0);
   ed->map.rot.z = FROM_DOUBLE(0.0);
@@ -8859,6 +8863,7 @@ st_collections_group_parts_part_description_inherit(void)
    data_queue_copied_part_lookup(pc, &parent->map.id_persp, &ed->map.id_persp);
    data_queue_copied_part_lookup(pc, &parent->map.id_light, &ed->map.id_light);
    data_queue_copied_part_lookup(pc, &parent->map.rot.id_center, &ed->map.rot.id_center);
+   data_queue_copied_part_lookup(pc, &parent->map.zoom.id_center, &ed->map.zoom.id_center);
 
    /* make sure all the allocated memory is getting copied, not just
     * referenced
@@ -14704,6 +14709,57 @@ st_collections_group_parts_part_description_map_light(void)
    }
 }
 
+/** @edcsubsection{collections_group_parts_description_map_zoom,
+ *                 Group.Parts.Part.Description.Map.Zoom} */
+
+/**
+    @page edcref
+    @block
+        rotation
+    @context
+    map {
+        ..
+        zoom {
+            center: "name";
+            x: 1.0;
+            y: 1.0;
+        }
+        ..
+    }
+    @description
+        Zooms the part, optionally from the center on another part.
+    @endblock
+
+    @property
+        center
+    @parameters
+        [another part's name]
+    @effect
+        This sets the part that is used as the center of zoom when
+        zooming the part with this description. The part's center point
+        is used as the zoom center when applying zoom from the
+        x and y axes. If no center is given, the parts original center
+        itself is used for the zoom center.
+    @endproperty
+*/
+static void
+st_collections_group_parts_part_description_map_zoom_center(void)
+{
+   Edje_Part_Collection *pc;
+
+   check_arg_count(1);
+
+   pc = eina_list_data_get(eina_list_last(edje_collections));
+
+   {
+      char *name;
+
+      name = parse_str(0);
+      data_queue_part_lookup(pc, name, &(current_desc->map.zoom.id_center));
+      free(name);
+   }
+}
+
 /**
     @page edcref
     @property
index ce4f7af..c9f89b1 100644 (file)
@@ -48,7 +48,8 @@ edje/swallow.edc \
 edje/table.edc \
 edje/text.edc \
 edje/textblock-hyphen.edc \
-edje/toggle_using_filter.edc
+edje/toggle_using_filter.edc \
+edje/center_zoom.edc
 
 MULTISENSE_EDCS = edje/multisense.edc
 if ENABLE_MULTISENSE
diff --git a/src/examples/edje/center_zoom.edc b/src/examples/edje/center_zoom.edc
new file mode 100644 (file)
index 0000000..21d0725
--- /dev/null
@@ -0,0 +1,105 @@
+collections {
+group { name: "center_zoom_example";
+      min: 360 360;
+      max: 360 360;
+      parts {
+         part {
+            name: "bg";
+            type: RECT;
+            description {
+               state: "default" 0.0;
+               color: 0 0 0 255;
+            }
+         }
+         part {
+            name: "center_part";
+            type: RECT;
+            description {
+               state: "default" 0.0;
+               min: 25 25;
+               max: 25 25;
+               rel1.to:"bg";
+               rel2 {
+                  relative: 1.0 0.5;
+                  to: "bg";
+               }
+            }
+         }
+         part {
+            name: "rectangle";
+            type: RECT;
+            description {
+               state: "default" 0.0;
+               color: 0 0 255 128;
+               max: 150 150;
+               rel1 {
+                  to: "bg";
+               }
+               rel2 {
+                  to: "bg";
+               }
+               map {
+                  on: 1;
+                  zoom {
+                     center: "center_part";
+                     x: 0.0;
+                     y: 0.0;
+                  }
+               }
+            }
+            description {
+               state: "zoom" 0.0;
+               inherit: "default" 0.0;  
+               map {
+                  on: 1;
+                  zoom {
+                     center: "center_part";
+                     x: 1;
+                     y: 1;
+                  }
+               }
+            }
+         }
+         part {
+            name: "title";
+            type: TEXT;
+            description {
+               state: "default" 0.0;
+               color: 200 200 200 255;
+               align: 0.5 0.0;
+               rel1.to:"bg";
+               rel2 {
+                  relative: 1.0 0.0;
+                  to: "bg";
+               }
+               text {
+                  text: "Center Zoom Example";
+                  font: "Sans";
+                  size: 16;
+                  min: 1 1;
+               }
+            }
+         }
+         part {
+            name: "event";
+            type: RECT;
+            mouse_events: 1;
+            description {
+               state: "default" 0.0;
+               color: 0 0 0 0;  
+            }
+         }
+      }
+      programs {
+         program {
+            name: "move,bottom";
+            signal: "mouse,up,1";
+            source: "event";
+            action: STATE_SET "zoom" 0.0;
+            transition: LINEAR 1.0;
+            target: "rectangle";
+         }
+      }
+   }
+}
+
index 21910ad..ff57a6e 100644 (file)
@@ -44,6 +44,7 @@ edc_files = [
   'textblock-hyphen.edc',
   'toggle_using_filter.edc',
   'multisense.edc',
+  'center_zoom.edc',
 ]
 
 if (get_option('physics'))
index 6889c0a..d52af71 100644 (file)
@@ -8,8 +8,11 @@ static void                          _edje_part_make_rtl(Edje_Part_Description_C
 static Edje_Part_Description_Common *_edje_get_description_by_orientation(Edje *ed, Edje_Part_Description_Common *src, Edje_Part_Description_Common **dst, unsigned char type);
 
 static void                          _edje_part_recalc_single(Edje *ed, Edje_Real_Part *ep,
-                                                              Edje_Part_Description_Common *desc, Edje_Part_Description_Common *chosen_desc,
-                                                              Edje_Real_Part *center, Edje_Real_Part *light, Edje_Real_Part *persp,
+                                                              Edje_Part_Description_Common *desc,
+                                                              Edje_Part_Description_Common *chosen_desc,
+                                                              Edje_Real_Part *center,
+                                                              Edje_Real_Part *zoom_center,
+                                                              Edje_Real_Part *light, Edje_Real_Part *persp,
                                                               Edje_Real_Part *rel1_to_x, Edje_Real_Part *rel1_to_y,
                                                               Edje_Real_Part *rel2_to_x, Edje_Real_Part *rel2_to_y,
                                                               Edje_Real_Part *clip_to,
@@ -2314,6 +2317,7 @@ static void
 _edje_part_recalc_single_map(Edje *ed,
                              Edje_Real_Part *ep EINA_UNUSED,
                              Edje_Real_Part *center,
+                             Edje_Real_Part *zoom_center,
                              Edje_Real_Part *light,
                              Edje_Real_Part *persp,
                              Edje_Part_Description_Common *desc,
@@ -2328,6 +2332,7 @@ _edje_part_recalc_single_map(Edje *ed,
 
    EINA_COW_CALC_MAP_BEGIN(params, params_write)
    {
+      //rotation center
       if (center)
         {
            params_write->center.x = ed->x + center->x + (center->w / 2);
@@ -2339,6 +2344,17 @@ _edje_part_recalc_single_map(Edje *ed,
            params_write->center.y = ed->y + params->final.y + (params->final.h / 2);
         }
       params_write->center.z = 0;
+      //zoom center
+      if (zoom_center)
+        {
+           params_write->zoom_center.x = ed->x + zoom_center->x + (zoom_center->w / 2);
+           params_write->zoom_center.y = ed->y + zoom_center->y + (zoom_center->h / 2);
+        }
+      else
+        {
+           params_write->zoom_center.x = ed->x + params->final.x + (params->final.w / 2);
+           params_write->zoom_center.y = ed->y + params->final.y + (params->final.h / 2);
+        }
 
       params_write->rotation.x = desc->map.rot.x;
       params_write->rotation.y = desc->map.rot.y;
@@ -2715,6 +2731,7 @@ _edje_part_recalc_single(Edje *ed,
                          Edje_Part_Description_Common *desc,
                          Edje_Part_Description_Common *chosen_desc,
                          Edje_Real_Part *center,
+                         Edje_Real_Part *zoom_center,
                          Edje_Real_Part *light,
                          Edje_Real_Part *persp,
                          Edje_Real_Part *rel1_to_x,
@@ -3120,7 +3137,7 @@ _edje_part_recalc_single(Edje *ed,
         EINA_COW_CALC_PHYSICS_END(params, params_write);
      }
 #endif
-   _edje_part_recalc_single_map(ed, ep, center, light, persp, desc, chosen_desc, params);
+   _edje_part_recalc_single_map(ed, ep, center, zoom_center, light, persp, desc, chosen_desc, params);
 }
 
 static void
@@ -3821,7 +3838,7 @@ _edje_map_prop_set(Evas_Map *map, const Edje_Calc_Params *pf,
    //zoom
    evas_map_util_zoom(map,
                       pf->ext->map->zoom.x, pf->ext->map->zoom.y,
-                      pf->ext->map->center.x, pf->ext->map->center.y);
+                      pf->ext->map->zoom_center.x, pf->ext->map->zoom_center.y);
 
    //rotate
    evas_map_util_3d_rotate(map,
@@ -4059,6 +4076,7 @@ _edje_part_recalc(Edje *ed, Edje_Real_Part *ep, int flags, Edje_Calc_Params *sta
    int statep2 = -1;
    int statecl = -1;
    Edje_Real_Part *center[2] = { NULL, NULL };
+   Edje_Real_Part *zoom_center[2] = { NULL, NULL };
    Edje_Real_Part *light[2] = { NULL, NULL };
    Edje_Real_Part *persp[2] = { NULL, NULL };
    Edje_Real_Part *rp1[4] = { NULL, NULL, NULL, NULL };
@@ -4378,6 +4396,7 @@ _edje_part_recalc(Edje *ed, Edje_Real_Part *ep, int flags, Edje_Calc_Params *sta
    if (ep->param1.description->map.on)
      {
         center[0] = _edje_real_part_state_get(ed, ep, flags, ep->param1.description->map.rot.id_center, &statec1);
+        zoom_center[0] = _edje_real_part_state_get(ed, ep, flags, ep->param1.description->map.zoom.id_center, &statec1);
         light[0] = _edje_real_part_state_get(ed, ep, flags, ep->param1.description->map.id_light, &statel1);
 
         if (chosen_desc->map.persp_on)
@@ -4389,6 +4408,7 @@ _edje_part_recalc(Edje *ed, Edje_Real_Part *ep, int flags, Edje_Calc_Params *sta
    if (ep->param2 && ep->param2->description->map.on)
      {
         center[1] = _edje_real_part_state_get(ed, ep, flags, ep->param2->description->map.rot.id_center, &statec2);
+        zoom_center[1] = _edje_real_part_state_get(ed, ep, flags, ep->param2->description->map.zoom.id_center, &statec2);
         light[1] = _edje_real_part_state_get(ed, ep, flags, ep->param2->description->map.id_light, &statel2);
 
         if (chosen_desc->map.persp_on)
@@ -4424,7 +4444,7 @@ _edje_part_recalc(Edje *ed, Edje_Real_Part *ep, int flags, Edje_Calc_Params *sta
 #endif
         {
            _edje_part_recalc_single(ed, ep, ep->param1.description,
-                                    chosen_desc, center[0], light[0],
+                                    chosen_desc, center[0], zoom_center[0], light[0],
                                     persp[0], rp1[Rel1X], rp1[Rel1Y],
                                     rp1[Rel2X], rp1[Rel2Y], clip1, confine_to,
                                     threshold, p1, mmw, mmh,
@@ -4470,7 +4490,7 @@ _edje_part_recalc(Edje *ed, Edje_Real_Part *ep, int flags, Edje_Calc_Params *sta
 #endif
         {
            _edje_part_recalc_single(ed, ep, ep->param2->description,
-                                    chosen_desc, center[1], light[1],
+                                    chosen_desc, center[1], zoom_center[1], light[1],
                                     persp[1], rp2[Rel1X], rp2[Rel1Y],
                                     rp2[Rel2X], rp2[Rel2Y], clip2, confine_to,
                                     threshold, p2, mmw, mmh,
@@ -4755,6 +4775,8 @@ _edje_part_recalc(Edje *ed, Edje_Real_Part *ep, int flags, Edje_Calc_Params *sta
                 p3_write->center.x = INTP(p1->ext->map->center.x, p2->ext->map->center.x, pos);
                 p3_write->center.y = INTP(p1->ext->map->center.y, p2->ext->map->center.y, pos);
                 p3_write->center.z = INTP(p1->ext->map->center.z, p2->ext->map->center.z, pos);
+                p3_write->zoom_center.x = INTP(p1->ext->map->zoom_center.x, p2->ext->map->zoom_center.x, pos);
+                p3_write->zoom_center.y = INTP(p1->ext->map->zoom_center.y, p2->ext->map->zoom_center.y, pos);
                 p3_write->rotation.x = FFP(p1->ext->map->rotation.x, p2->ext->map->rotation.x, pos);
                 p3_write->rotation.y = FFP(p1->ext->map->rotation.y, p2->ext->map->rotation.y, pos);
                 p3_write->rotation.z = FFP(p1->ext->map->rotation.z, p2->ext->map->rotation.z, pos);
index 3fbecde..b9d5545 100644 (file)
@@ -818,6 +818,7 @@ _edje_edd_init(void)
   EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "map.id_persp", map.id_persp, EET_T_INT);                           \
   EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "map.id_light", map.id_light, EET_T_INT);                           \
   EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "map.rot.id_center", map.rot.id_center, EET_T_INT);                 \
+  EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "map.zoom.id_center", map.zoom.id_center, EET_T_INT);               \
   EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "map.rot.x", map.rot.x, EDJE_T_FLOAT);                              \
   EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "map.rot.y", map.rot.y, EDJE_T_FLOAT);                              \
   EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "map.rot.z", map.rot.z, EDJE_T_FLOAT);                              \
@@ -912,6 +913,7 @@ _edje_edd_init(void)
   EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "map.id_persp", Dec.map.id_persp, EET_T_INT);                           \
   EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "map.id_light", Dec.map.id_light, EET_T_INT);                           \
   EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "map.rot.id_center", Dec.map.rot.id_center, EET_T_INT);                 \
+  EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "map.zoom.id_center", Dec.map.zoom.id_center, EET_T_INT);               \
   EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "map.rot.x", Dec.map.rot.x, EDJE_T_FLOAT);                              \
   EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "map.rot.y", Dec.map.rot.y, EDJE_T_FLOAT);                              \
   EET_DATA_DESCRIPTOR_ADD_BASIC(Edd, Type, "map.rot.z", Dec.map.rot.z, EDJE_T_FLOAT);                              \
index 345175f..e920804 100644 (file)
@@ -16,7 +16,7 @@ Eina_Cow *_edje_calc_params_physics_cow = NULL;
 Edje_Global *_edje_global_obj = NULL;
 
 static const Edje_Calc_Params_Map default_calc_map = {
-   { 0, 0, 0 }, { 0.0, 0.0, 0.0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0.0, 0.0 }, NULL, 0
+   { 0, 0, 0 }, { 0, 0 }, { 0.0, 0.0, 0.0 }, { 0, 0, 0, 0, 0, 0, 0, 0, 0 }, { 0, 0, 0, 0 }, { 0.0, 0.0 }, NULL, 0
 };
 
 static const Edje_Calc_Params_Physics default_calc_physics = {
index f938157..70dfe10 100644 (file)
@@ -1331,6 +1331,7 @@ struct _Edje_Part_Description_Common
       } rot;
       struct {
          FLOAT_T x, y;
+         int id_center;
       } zoom;
       Edje_Map_Color **colors;    /* List of the Edje_Map_Color */
       unsigned int colors_count;
@@ -1877,6 +1878,9 @@ struct _Edje_Calc_Params_Map
       int x, y, z;
    } center; // 12
    struct {
+      int x, y;
+   } zoom_center; // 12
+   struct {
       FLOAT_T x, y, z;
    } rotation; // 24
    struct {