Efl.Gfx.Vg.Value_Provider: Introduce property change feature of Efl.Ui.Animation_View 54/215154/2
authorJunsuChoi <jsuya.choi@samsung.com>
Wed, 2 Oct 2019 04:21:35 +0000 (13:21 +0900)
committerjunsu choi <jsuya.choi@samsung.com>
Wed, 2 Oct 2019 06:01:20 +0000 (06:01 +0000)
Summary:
Efl.Gfx.Vg.Value_Provider is an object for integrating and managing the properties of vector objects.
These values are dependent on the keypath.
Keypath is the target a specific content or a set of contents that will be updated.
It can include the specific name of the contents, wildcard(*) or Globstar(**).

The valueProvider is borrowed from another library that uses a vector object of type json, such as Efl.Ui.Animation_View
(https://github.com/airbnb/lottie-ios/blob/5fc0e59e0cb85d3586b1d0d1cf4a2c9669b91d15/lottie-swift/src/Public/iOS/AnimatedControl.swift#L50)

This feature should be used with some patches that apply to the vg json loader and Efl.Canvas.Vg.Object.

Test Plan: N/A

Reviewers: Hermet, kimcinoo, smohanty

Reviewed By: Hermet

Subscribers: cedric, #reviewers, #committers

Tags: #efl

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

Change-Id: I2c8423fefecd12da81066943aeba4d7dc883e80f

src/lib/elementary/efl_ui_animation_view.c
src/lib/elementary/efl_ui_animation_view.eo
src/lib/elementary/efl_ui_animation_view_private.h
src/lib/evas/Efl_Canvas.h
src/lib/evas/Evas_Eo.h
src/lib/evas/canvas/efl_gfx_vg_value_provider.c [new file with mode: 0644]
src/lib/evas/canvas/efl_gfx_vg_value_provider.eo [new file with mode: 0644]
src/lib/evas/canvas/efl_gfx_vg_value_provider.h [new file with mode: 0644]
src/lib/evas/canvas/evas_vg_private.h
src/lib/evas/canvas/meson.build

index 5f883c3..4724733 100644 (file)
@@ -236,6 +236,11 @@ EOLIAN static void
 _efl_ui_animation_view_efl_object_destructor(Eo *obj,
                                           Efl_Ui_Animation_View_Data *pd EINA_UNUSED)
 {
+   Efl_Gfx_Vg_Value_Provider *vp;
+   EINA_LIST_FREE(pd->vp_list, vp)
+     efl_unref(vp);
+   eina_list_free(pd->vp_list);
+
    efl_destructor(efl_super(obj, MY_CLASS));
 }
 
@@ -707,6 +712,37 @@ _efl_ui_animation_view_max_frame_get(const Eo *obj EINA_UNUSED, Efl_Ui_Animation
    return pd->max_progress * (evas_object_vg_animated_frame_count_get(pd->vg) - 1);
 }
 
+EOLIAN static void
+_efl_ui_animation_view_value_provider_override(Eo *obj EINA_UNUSED, Efl_Ui_Animation_View_Data *pd, Efl_Gfx_Vg_Value_Provider *value_provider)
+{
+   if (!value_provider) return;
+
+   if (pd->vp_list)
+     {
+        const char *keypath1 = efl_gfx_vg_value_provider_keypath_get(value_provider);
+        if (!keypath1)
+          {
+             ERR("Couldn't override Value Provider(%p). Keypath is NULL.", value_provider);
+             return;
+          }
+        const Eina_List *l;
+        Efl_Gfx_Vg_Value_Provider *_vp;
+        EINA_LIST_FOREACH(pd->vp_list, l, _vp)
+          {
+             const char *keypath2 = efl_gfx_vg_value_provider_keypath_get(_vp);
+             if (!strcmp(keypath1, keypath2))
+               {
+                  pd->vp_list = eina_list_remove(pd->vp_list, _vp);
+                  efl_unref(_vp);
+                  break;
+               }
+          }
+     }
+
+   efl_ref(value_provider);
+   pd->vp_list = eina_list_append(pd->vp_list, value_provider);
+}
+
 EAPI Elm_Animation_View*
 elm_animation_view_add(Evas_Object *parent)
 {
index 474bd76..d079059 100644 (file)
@@ -256,7 +256,21 @@ class @beta Efl.Ui.Animation_View extends Efl.Ui.Widget implements Efl.Gfx.View,
                             ]]
          }
       }
+      value_provider_override{
+         [[Override each value of the animation object.
+           Values can be properties of Efl.Gfx.Vg.Value_provider such as color and matrix information.
 
+           Example:
+           Eo *vp = efl_add(EFL_GFX_VG_VALUE_PROVIDER_CLASS, NULL);
+           @Efl.Gfx.Vg.Value_Provider.keypath.set(vp, "SomeLayer:SomeObject:SomeContents");
+           // Set vp property
+           @.value_provider_override(target_animation_view, vg);
+           See @Efl.Gfx.Vg.Value_Provider
+         ]]
+         params {
+            value_provider: Efl.Gfx.Vg.Value_Provider; [[ Override the values of the animation object. this should have keypath infomation. See @Efl.Gfx.Vg.Value_Provider ]]
+         }
+      }
    }
    implements {
       Efl.Object.constructor;
index 0de9b2a..9199dc7 100644 (file)
@@ -19,6 +19,7 @@ struct _Efl_Ui_Animation_View_Data
    double frame_duration;
    double min_progress;
    double max_progress;
+   Eina_List *vp_list;
 
    Eina_Bool play_back : 1;
    Eina_Bool auto_play : 1;
index 66fe692..cd8bf52 100644 (file)
@@ -81,6 +81,7 @@ extern "C" {
 #include <canvas/efl_canvas_vg_image.eo.h>
 #include <canvas/efl_canvas_vg_object.eo.h>
 #include <canvas/efl_canvas_vg_shape.eo.h>
+#include <canvas/efl_gfx_vg_value_provider.eo.h>
 #include <canvas/efl_gfx_mapping.eo.h>
 
 #include <canvas/efl_input_clickable.eo.h>
index 593c4d9..5f46511 100644 (file)
@@ -439,6 +439,7 @@ typedef void (Evas_Canvas3D_Surface_Func)(Evas_Real *out_x,
 #include "canvas/efl_canvas_proxy.eo.h"
 #include "canvas/efl_gfx_mapping.eo.h"
 
+#include "canvas/efl_gfx_vg_value_provider.eo.h"
 /**
  * @ingroup Evas_Object_VG
  *
diff --git a/src/lib/evas/canvas/efl_gfx_vg_value_provider.c b/src/lib/evas/canvas/efl_gfx_vg_value_provider.c
new file mode 100644 (file)
index 0000000..ccf3349
--- /dev/null
@@ -0,0 +1,129 @@
+#include "efl_gfx_vg_value_provider.h"
+
+#define MY_CLASS EFL_GFX_VG_VALUE_PROVIDER_CLASS
+
+EOLIAN static Eo *
+_efl_gfx_vg_value_provider_efl_object_constructor(Eo *obj,
+                                           Efl_Gfx_Vg_Value_Provider_Data *pd EINA_UNUSED)
+{
+   obj = efl_constructor(efl_super(obj, MY_CLASS));
+
+   pd->flag = EFL_GFX_VG_VALUE_PROVIDER_CHANGE_FLAG_NONE;
+
+   return obj;
+}
+
+EOLIAN static void
+_efl_gfx_vg_value_provider_efl_object_destructor(Eo *obj,
+                                          Efl_Gfx_Vg_Value_Provider_Data *pd EINA_UNUSED)
+{
+   if (pd->keypath) eina_stringshare_del(pd->keypath);
+   efl_destructor(efl_super(obj, MY_CLASS));
+}
+
+EOLIAN void
+_efl_gfx_vg_value_provider_keypath_set(Eo *obj EINA_UNUSED, Efl_Gfx_Vg_Value_Provider_Data *pd, Eina_Stringshare *keypath)
+{
+   if(!keypath) return;
+   eina_stringshare_replace(&pd->keypath, keypath);
+}
+
+EOLIAN Eina_Stringshare*
+_efl_gfx_vg_value_provider_keypath_get(const Eo *obj EINA_UNUSED, Efl_Gfx_Vg_Value_Provider_Data *pd)
+{
+   return pd->keypath;
+}
+
+EOLIAN void
+_efl_gfx_vg_value_provider_transform_set(Eo *obj EINA_UNUSED, Efl_Gfx_Vg_Value_Provider_Data *pd, Eina_Matrix3 *m)
+{
+   if (m)
+     {
+        if (!pd->m)
+          {
+             pd->m = malloc(sizeof (Eina_Matrix3));
+             if (!pd->m) return;
+          }
+        pd->flag = pd->flag | EFL_GFX_VG_VALUE_PROVIDER_CHANGE_FLAG_TRANSFORM_MATRIX;
+        memcpy(pd->m, m, sizeof (Eina_Matrix3));
+     }
+   else
+     {
+        free(pd->m);
+        pd->m = NULL;
+     }
+}
+
+EOLIAN Eina_Matrix3*
+_efl_gfx_vg_value_provider_transform_get(const Eo *obj EINA_UNUSED, Efl_Gfx_Vg_Value_Provider_Data *pd)
+{
+   return pd->m;
+}
+
+EOAPI void
+_efl_gfx_vg_value_provider_fill_color_set(Eo *obj EINA_UNUSED, Efl_Gfx_Vg_Value_Provider_Data *pd, int r, int g, int b, int a)
+{
+   pd->flag = pd->flag | EFL_GFX_VG_VALUE_PROVIDER_CHANGE_FLAG_FILL_COLOR;
+
+   pd->fill.r = r;
+   pd->fill.g = g;
+   pd->fill.b = b;
+   pd->fill.a = a;
+}
+
+EOAPI void
+_efl_gfx_vg_value_provider_fill_color_get(const Eo *obj EINA_UNUSED, Efl_Gfx_Vg_Value_Provider_Data *pd, int *r, int *g, int *b, int *a)
+{
+   if (r) *r = pd->fill.r;
+   if (g) *g = pd->fill.g;
+   if (b) *b = pd->fill.b;
+   if (a) *a = pd->fill.a;
+}
+
+EOAPI void
+_efl_gfx_vg_value_provider_stroke_color_set(Eo *obj EINA_UNUSED, Efl_Gfx_Vg_Value_Provider_Data *pd, int r, int g, int b, int a)
+{
+   pd->flag = pd->flag | EFL_GFX_VG_VALUE_PROVIDER_CHANGE_FLAG_STROKE_COLOR;
+
+   pd->stroke.r = r;
+   pd->stroke.g = g;
+   pd->stroke.b = b;
+   pd->stroke.a = a;
+}
+
+EOAPI void
+_efl_gfx_vg_value_provider_stroke_color_get(const Eo *obj EINA_UNUSED, Efl_Gfx_Vg_Value_Provider_Data *pd, int *r, int *g, int *b, int *a)
+{
+   if (r) *r = pd->stroke.r;
+   if (g) *g = pd->stroke.g;
+   if (b) *b = pd->stroke.b;
+   if (a) *a = pd->stroke.a;
+}
+
+EOAPI void
+_efl_gfx_vg_value_provider_stroke_width_set(Eo *obj EINA_UNUSED, Efl_Gfx_Vg_Value_Provider_Data *pd, double w)
+{
+  if (w < 0) return ;
+
+  pd->flag = pd->flag | EFL_GFX_VG_VALUE_PROVIDER_CHANGE_FLAG_STROKE_WIDTH;
+  pd->stroke.width = w;
+}
+
+EOAPI double
+_efl_gfx_vg_value_provider_stroke_width_get(const Eo *obj EINA_UNUSED, Efl_Gfx_Vg_Value_Provider_Data *pd)
+{
+   return pd->stroke.width;
+}
+
+/* This function only use in internal */
+Efl_Gfx_Vg_Value_Provider_Change_Flag
+efl_gfx_vg_value_provider_changed_flag_get(Eo *obj)
+{
+   EINA_SAFETY_ON_FALSE_RETURN_VAL(efl_isa(obj, MY_CLASS), EFL_GFX_VG_VALUE_PROVIDER_CHANGE_FLAG_NONE);
+   Efl_Gfx_Vg_Value_Provider_Data *pd = efl_data_scope_get(obj, MY_CLASS);
+   if (!pd) return EFL_GFX_VG_VALUE_PROVIDER_CHANGE_FLAG_NONE;
+   return pd->flag;
+}
+
+
+#include "efl_gfx_vg_value_provider.eo.c"
diff --git a/src/lib/evas/canvas/efl_gfx_vg_value_provider.eo b/src/lib/evas/canvas/efl_gfx_vg_value_provider.eo
new file mode 100644 (file)
index 0000000..2e21774
--- /dev/null
@@ -0,0 +1,72 @@
+class @beta Efl.Gfx.Vg.Value_Provider extends Efl.Object
+{
+   [[Efl Vector Value Provider class.
+
+     This class is a set of that contain the value of several properties provided by content.
+     User can use this class to change the properties for the specific content specified by the keypath.
+   ]]
+   methods {
+      @property keypath {
+         [[ Keypath is the target a specific content or a set of contents that will be updated.
+            It can include the specific name of the contents, wildcard(*) or Globstar(**).
+         ]]
+         get {
+         }
+         set {
+         }
+         values {
+            keypath: stringshare; [[ The keypath of contents ]]
+         }
+      }
+      @property transform {
+         [[ User can adjust transform value of the content specified by the keypath. ]]
+         set {
+         }
+         get {
+         }
+         values {
+            m: ptr(Eina.Matrix3); [[ Matrix Value. ]]
+         }
+      }
+      @property fill_color {
+         [[ User can adjust color value of the fill content specified by the keypath. ]]
+         set {
+         }
+         get {
+         }
+         values {
+            r: int; [[ Red color value of fill. ]]
+            g: int; [[ Green color value of fill. ]]
+            b: int; [[ Blue color value of fill. ]]
+            a: int; [[ Alpha value of fill. ]]
+         }
+      }
+      @property stroke_color {
+         [[ User can adjust color value of the stroke content specified by the keypath. ]]
+         set {
+         }
+         get {
+         }
+         values {
+            r: int; [[ Red color value of stroke. ]]
+            g: int; [[ Green color value of stroke. ]]
+            b: int; [[ Blue color value of stroke. ]]
+            a: int; [[ Alpha value of stroke. ]]
+         }
+      }
+      @property stroke_width {
+         [[ User can adjust width value of the stroke content specified by the keypath. ]]
+         set {
+         }
+         get {
+         }
+         values {
+            width: double; [[ Width value of stroke. ]]
+         }
+      }
+   }
+   implements {
+      Efl.Object.constructor;
+      Efl.Object.destructor;
+   }
+}
diff --git a/src/lib/evas/canvas/efl_gfx_vg_value_provider.h b/src/lib/evas/canvas/efl_gfx_vg_value_provider.h
new file mode 100644 (file)
index 0000000..5b4b806
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef EFL_GFX_VG_VALUE_PROVIDER_H
+#define EFL_GFX_VG_VALUE_PROVIDER_H
+
+#include "evas_common_private.h"
+#include "evas_private.h"
+#include "evas_vg_private.h"
+
+struct _Efl_Gfx_Vg_Value_Provider_Data
+{
+   Eo* obj;
+   Efl_Gfx_Vg_Value_Provider_Change_Flag flag;
+
+   Eina_Stringshare *keypath;
+
+   Eina_Matrix3 *m;
+   struct {
+      int r;
+      int g;
+      int b;
+      int a;
+   } fill;
+   struct {
+      int r;
+      int g;
+      int b;
+      int a;
+      double width;
+   } stroke;
+};
+
+typedef struct _Efl_Gfx_Vg_Value_Provider_Data Efl_Gfx_Vg_Value_Provider_Data;
+
+#endif
index 6dcd721..9ec8963 100644 (file)
@@ -9,6 +9,8 @@ typedef struct _Efl_Canvas_Vg_Gradient_Data         Efl_Canvas_Vg_Gradient_Data;
 typedef struct _Efl_Canvas_Vg_Interpolation         Efl_Canvas_Vg_Interpolation;
 typedef struct _Efl_Canvas_Vg_Object_Data           Efl_Canvas_Vg_Object_Data;
 
+typedef enum _Efl_Gfx_Vg_Value_Provider_Change_Flag Efl_Gfx_Vg_Value_Provider_Change_Flag;
+
 typedef struct _Vg_Cache
 {
    Eina_Hash             *vfd_hash;
@@ -128,6 +130,15 @@ struct _Efl_Canvas_Vg_Interpolation
    Eina_Point_3D skew;
 };
 
+enum _Efl_Gfx_Vg_Value_Provider_Change_Flag
+{
+   EFL_GFX_VG_VALUE_PROVIDER_CHANGE_FLAG_NONE = 0,
+   EFL_GFX_VG_VALUE_PROVIDER_CHANGE_FLAG_FILL_COLOR = 2,
+   EFL_GFX_VG_VALUE_PROVIDER_CHANGE_FLAG_STROKE_COLOR = 4,
+   EFL_GFX_VG_VALUE_PROVIDER_CHANGE_FLAG_STROKE_WIDTH = 8,
+   EFL_GFX_VG_VALUE_PROVIDER_CHANGE_FLAG_TRANSFORM_MATRIX = 16
+};
+Efl_Gfx_Vg_Value_Provider_Change_Flag efl_gfx_vg_value_provider_changed_flag_get(Eo *obj);
 
 void                        evas_cache_vg_init(void);
 void                        evas_cache_vg_shutdown(void);
index c306c90..758a8db 100644 (file)
@@ -40,6 +40,7 @@ pub_eo_files = [
   'efl_canvas_text_factory.eo',
   'efl_canvas_rectangle.eo',
   'efl_canvas_object.eo',
+  'efl_gfx_vg_value_provider.eo',
   'efl_canvas_vg_object.eo',
   'efl_canvas_vg_node.eo',
   'efl_canvas_vg_container.eo',
@@ -179,6 +180,7 @@ evas_src += files([
   'efl_canvas_animation_group_parallel.c',
   'efl_canvas_animation_group_sequential.c',
   'efl_canvas_animation_player.c',
+  'efl_gfx_vg_value_provider.c',
   'efl_canvas_vg_object.c',
   'efl_canvas_vg_node.c',
   'efl_canvas_vg_container.c',