summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsubhransu mohanty <sub.mohanty@samsung.com>2017-10-25 20:16:17 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2017-10-25 20:17:20 +0900
commit57ba3318dca35f51a5e2a89367677100bf7b9e49 (patch)
tree6ba6df373ba34e64f44cd559b9d8da21a8b67e87
parentc46f9bec2d15f23c09caf932164f2b00ee5c0903 (diff)
evas/vg: Added align, viewbox and fill_mode property to the vg canvas
Summary: viewbox, fill_mode and align property required to scale the vg tree that we get from the svg file or manually created depending on the vg canvas size. Reviewers: jpeg, cedric Subscribers: jenkins, cedric Differential Revision: https://phab.enlightenment.org/D5358
-rw-r--r--src/lib/evas/canvas/efl_canvas_vg.c152
-rw-r--r--src/lib/evas/canvas/efl_canvas_vg.eo53
-rw-r--r--src/lib/evas/canvas/evas_vg_private.h21
3 files changed, 178 insertions, 48 deletions
diff --git a/src/lib/evas/canvas/efl_canvas_vg.c b/src/lib/evas/canvas/efl_canvas_vg.c
index 55ad5d3b8d..e54875642d 100644
--- a/src/lib/evas/canvas/efl_canvas_vg.c
+++ b/src/lib/evas/canvas/efl_canvas_vg.c
@@ -73,6 +73,52 @@ _evas_vg_tree_changed(void *data, const Efl_Event *event EINA_UNUSED)
73 evas_object_change(obj->object, obj); 73 evas_object_change(obj->object, obj);
74} 74}
75 75
76static void
77_update_vgtree_viewport(Eo *obj, Efl_Canvas_Vg_Data *pd)
78{
79 double vb_w, vb_h, vp_w, vp_h, scale_w, scale_h, scale;
80 Eina_Size2D sz = efl_gfx_size_get(obj);
81 Eina_Matrix3 m;
82
83 eina_matrix3_identity(&m);
84
85 vb_w = pd->viewbox.w;
86 vb_h = pd->viewbox.h;
87 vp_w = sz.w;
88 vp_h = sz.h;
89
90 scale_w = vp_w / vb_w;
91 scale_h = vp_h / vb_h;
92
93 if (pd->fill_mode == EFL_CANVAS_VG_FILL_MODE_STRETCH)
94 { // Fill the viewport and ignore the aspect ratio
95 eina_matrix3_scale(&m, scale_w, scale_h);
96 eina_matrix3_translate(&m, -pd->viewbox.x, -pd->viewbox.y);
97 }
98 else
99 {
100 if (pd->fill_mode == EFL_CANVAS_VG_FILL_MODE_MEET)
101 scale = scale_w < scale_h ? scale_w : scale_h;
102 else // slice
103 scale = scale_w > scale_h ? scale_w : scale_h;
104 eina_matrix3_translate(&m, (vp_w - vb_w * scale) * pd->align_x, (vp_h - vb_h * scale) * pd->align_y);
105 eina_matrix3_scale(&m, scale, scale);
106 eina_matrix3_translate(&m, -pd->viewbox.x, -pd->viewbox.y);
107 }
108
109 efl_vg_transformation_set(pd->root, &m);
110}
111
112static void
113_evas_vg_resize(void *data, const Efl_Event *ev)
114{
115 Efl_Canvas_Vg_Data *pd = data;
116
117 if (eina_rectangle_is_empty(&pd->viewbox.rect))
118 return;
119 _update_vgtree_viewport(ev->object, pd);
120}
121
76/* the actual api call to add a vector graphic object */ 122/* the actual api call to add a vector graphic object */
77EAPI Evas_Object * 123EAPI Evas_Object *
78evas_object_vg_add(Evas *e) 124evas_object_vg_add(Evas *e)
@@ -84,13 +130,13 @@ evas_object_vg_add(Evas *e)
84 return efl_add(MY_CLASS, e, efl_canvas_object_legacy_ctor(efl_added)); 130 return efl_add(MY_CLASS, e, efl_canvas_object_legacy_ctor(efl_added));
85} 131}
86 132
87Efl_VG * 133EOLIAN static Efl_VG *
88_efl_canvas_vg_root_node_get(Eo *obj EINA_UNUSED, Efl_Canvas_Vg_Data *pd) 134_efl_canvas_vg_root_node_get(Eo *obj EINA_UNUSED, Efl_Canvas_Vg_Data *pd)
89{ 135{
90 return pd->vg_tree; 136 return pd->vg_tree;
91} 137}
92 138
93void 139EOLIAN static void
94_efl_canvas_vg_root_node_set(Eo *obj EINA_UNUSED, Efl_Canvas_Vg_Data *pd, Efl_VG *root_node) 140_efl_canvas_vg_root_node_set(Eo *obj EINA_UNUSED, Efl_Canvas_Vg_Data *pd, Efl_VG *root_node)
95{ 141{
96 // if the same root is already set 142 // if the same root is already set
@@ -102,19 +148,84 @@ _efl_canvas_vg_root_node_set(Eo *obj EINA_UNUSED, Efl_Canvas_Vg_Data *pd, Efl_VG
102 efl_parent_set(pd->vg_tree, NULL); 148 efl_parent_set(pd->vg_tree, NULL);
103 149
104 pd->vg_tree = root_node; 150 pd->vg_tree = root_node;
105 151
106 if (pd->vg_tree) 152 if (pd->vg_tree)
107 { 153 {
108 // set the parent so that vg canvas can render it. 154 // set the parent so that vg canvas can render it.
109 efl_parent_set(pd->vg_tree, pd->root); 155 efl_parent_set(pd->vg_tree, pd->root);
110 } 156 }
111 157
112 // force a redraw 158 // force a redraw
113 pd->changed = EINA_TRUE; 159 pd->changed = EINA_TRUE;
114 160
115 evas_object_change(obj, efl_data_scope_get(obj, EFL_CANVAS_OBJECT_CLASS)); 161 evas_object_change(obj, efl_data_scope_get(obj, EFL_CANVAS_OBJECT_CLASS));
116} 162}
117 163
164EOLIAN static void
165_efl_canvas_vg_fill_mode_set(Eo *obj EINA_UNUSED, Efl_Canvas_Vg_Data *pd, Efl_Canvas_Vg_Fill_Mode fill_mode)
166{
167 pd->fill_mode = fill_mode;
168}
169
170EOLIAN static Efl_Canvas_Vg_Fill_Mode
171_efl_canvas_vg_fill_mode_get(Eo *obj EINA_UNUSED, Efl_Canvas_Vg_Data *pd)
172{
173 return pd->fill_mode;
174}
175
176EOLIAN static void
177_efl_canvas_vg_viewbox_set(Eo *obj, Efl_Canvas_Vg_Data *pd, Eina_Rect viewbox)
178{
179 // viewbox should be a valid rectangle
180 if (eina_rectangle_is_empty(&viewbox.rect))
181 {
182 // reset the old viewbox if any
183 if (!eina_rectangle_is_empty(&pd->viewbox.rect))
184 {
185 Eina_Matrix3 m;
186
187 pd->viewbox = EINA_RECT_EMPTY();
188 eina_matrix3_identity(&m);
189 efl_vg_transformation_set(pd->root, &m);
190 // un register the resize callback
191 efl_event_callback_del(obj, EFL_GFX_EVENT_RESIZE, _evas_vg_resize, pd);
192 }
193 return;
194 }
195 // register for resize callback if not done yet
196 if (eina_rectangle_is_empty(&pd->viewbox.rect))
197 efl_event_callback_add(obj, EFL_GFX_EVENT_RESIZE, _evas_vg_resize, pd);
198
199 pd->viewbox = viewbox;
200 _update_vgtree_viewport(obj, pd);
201}
202
203EOLIAN static Eina_Rect
204_efl_canvas_vg_viewbox_get(Eo *obj EINA_UNUSED, Efl_Canvas_Vg_Data *pd)
205{
206 return pd->viewbox;
207}
208
209EOLIAN static void
210_efl_canvas_vg_viewbox_align_set(Eo *obj EINA_UNUSED, Efl_Canvas_Vg_Data *pd, double align_x, double align_y)
211{
212 align_x = align_x < 0 ? 0 : align_x;
213 align_x = align_x > 1 ? 1 : align_x;
214
215 align_y = align_y < 0 ? 0 : align_y;
216 align_y = align_y > 1 ? 1 : align_y;
217
218 pd->align_x = align_x;
219 pd->align_y = align_y;
220}
221
222EOLIAN static void
223_efl_canvas_vg_viewbox_align_get(Eo *obj EINA_UNUSED, Efl_Canvas_Vg_Data *pd, double *align_x, double *align_y)
224{
225 if (align_x) *align_x = pd->align_x;
226 if (align_y) *align_y = pd->align_y;
227}
228
118static void 229static void
119_cleanup_reference(void *data, const Efl_Event *event EINA_UNUSED) 230_cleanup_reference(void *data, const Efl_Event *event EINA_UNUSED)
120{ 231{
@@ -126,7 +237,7 @@ _cleanup_reference(void *data, const Efl_Event *event EINA_UNUSED)
126 efl_unref(renderer); 237 efl_unref(renderer);
127} 238}
128 239
129void 240EOLIAN static void
130_efl_canvas_vg_efl_object_destructor(Eo *eo_obj, Efl_Canvas_Vg_Data *pd) 241_efl_canvas_vg_efl_object_destructor(Eo *eo_obj, Efl_Canvas_Vg_Data *pd)
131{ 242{
132 Evas_Object_Protected_Data *obj; 243 Evas_Object_Protected_Data *obj;
@@ -143,7 +254,7 @@ _efl_canvas_vg_efl_object_destructor(Eo *eo_obj, Efl_Canvas_Vg_Data *pd)
143 efl_destructor(efl_super(eo_obj, MY_CLASS)); 254 efl_destructor(efl_super(eo_obj, MY_CLASS));
144} 255}
145 256
146Eo * 257EOLIAN static Eo *
147_efl_canvas_vg_efl_object_constructor(Eo *eo_obj, Efl_Canvas_Vg_Data *pd) 258_efl_canvas_vg_efl_object_constructor(Eo *eo_obj, Efl_Canvas_Vg_Data *pd)
148{ 259{
149 Evas_Object_Protected_Data *obj = efl_data_scope_get(eo_obj, EFL_CANVAS_OBJECT_CLASS); 260 Evas_Object_Protected_Data *obj = efl_data_scope_get(eo_obj, EFL_CANVAS_OBJECT_CLASS);
@@ -157,7 +268,7 @@ _efl_canvas_vg_efl_object_constructor(Eo *eo_obj, Efl_Canvas_Vg_Data *pd)
157 268
158 /* root node */ 269 /* root node */
159 pd->root = efl_add(EFL_VG_CONTAINER_CLASS, NULL); 270 pd->root = efl_add(EFL_VG_CONTAINER_CLASS, NULL);
160 271
161 eina_array_step_set(&pd->cleanup, sizeof(pd->cleanup), 8); 272 eina_array_step_set(&pd->cleanup, sizeof(pd->cleanup), 8);
162 273
163 efl_event_callback_add(pd->root, EFL_GFX_EVENT_CHANGED, _evas_vg_tree_changed, obj); 274 efl_event_callback_add(pd->root, EFL_GFX_EVENT_CHANGED, _evas_vg_tree_changed, obj);
@@ -428,29 +539,4 @@ _efl_canvas_vg_was_opaque(Evas_Object *eo_obj EINA_UNUSED,
428 return 0; 539 return 0;
429} 540}
430 541
431EOLIAN static Eina_Size2D
432_efl_canvas_vg_efl_gfx_view_view_size_get(Eo *obj EINA_UNUSED, Efl_Canvas_Vg_Data *pd)
433{
434 return EINA_SIZE2D(pd->width, pd->height);
435}
436
437EOLIAN static void
438_efl_canvas_vg_efl_gfx_view_view_size_set(Eo *obj EINA_UNUSED, Efl_Canvas_Vg_Data *pd, Eina_Size2D sz)
439{
440 pd->width = sz.w;
441 pd->height = sz.h;
442}
443
444void
445_efl_canvas_vg_efl_gfx_fill_fill_set(Eo *obj EINA_UNUSED, Efl_Canvas_Vg_Data *pd, Eina_Rect fill)
446{
447 pd->fill = fill;
448}
449
450Eina_Rect
451_efl_canvas_vg_efl_gfx_fill_fill_get(Eo *obj EINA_UNUSED, Efl_Canvas_Vg_Data *pd)
452{
453 return pd->fill;
454}
455
456#include "efl_canvas_vg.eo.c" 542#include "efl_canvas_vg.eo.c"
diff --git a/src/lib/evas/canvas/efl_canvas_vg.eo b/src/lib/evas/canvas/efl_canvas_vg.eo
index 3f4becd056..27826af620 100644
--- a/src/lib/evas/canvas/efl_canvas_vg.eo
+++ b/src/lib/evas/canvas/efl_canvas_vg.eo
@@ -1,9 +1,56 @@
1class Efl.Canvas.Vg (Efl.Canvas.Object, Efl.Gfx.Fill, Efl.Gfx.View) 1enum Efl.Canvas.Vg.Fill_Mode
2{
3 [[Enumeration that defines how viewbox will be filled int the vg canvs's viewport.
4 default Fill_Mode is $none]]
5 none, [[Don't scale the viewbox. Placed it inside viewport taking
6 align property into account]]
7 stretch, [[Scale the viewbox so that it matches
8 the canvas viewport.
9 Aaspect ratio might be changed.]]
10 meet, [[Scale the viewbox
11 so that it fits inside canvas viewport
12 while maintaining the aspect ratio.
13 At least one of the dimensions of the viewbox
14 should be equal to the corresponding dimension
15 of the viewport.]]
16 slice [[Scale the viewbox
17 so that it covers the entire canvas viewport
18 while maintaining the aspect ratio.
19 At least one of the dimensions of the viewbox
20 should be equal to the corresponding
21 dimension of the viewport.]]
22}
23
24class Efl.Canvas.Vg (Efl.Canvas.Object)
2{ 25{
3 [[Efl vector graphics class]] 26 [[Efl vector graphics class]]
4 legacy_prefix: evas_object_vg; 27 legacy_prefix: evas_object_vg;
5 eo_prefix: evas_obj_vg;
6 methods { 28 methods {
29 @property fill_mode {
30 [[Control how the viewbox is mapped to the vg canvas's viewport.]]
31 values {
32 fill_mode: Efl.Canvas.Vg.Fill_Mode; [[Fill mode type]]
33 }
34 }
35 @property viewbox {
36 get {
37 [[Get the current viewbox from the evas_object_vg]]
38 }
39 set {
40 [[Sets the viewbox for the evas vg canvas.
41 viewbox if set should be mapped to the canvas geometry when rendering the vg tree.]]
42 }
43 values {
44 viewbox: Eina.Rect; [[viewbox for the vg canvas]]
45 }
46 }
47 @property viewbox_align {
48 [[Control how the viewbox is positioned inside the viewport.]]
49 values {
50 align_x: double(0); [[Alignment in the horizontal axis (0 <= align_x <= 1).]]
51 align_y: double(0); [[Alignment in the vertical axis (0 <= align_y <= 1).]]
52 }
53 }
7 @property root_node { 54 @property root_node {
8 get { 55 get {
9 [[Get the root node of the evas_object_vg. 56 [[Get the root node of the evas_object_vg.
@@ -26,7 +73,5 @@ class Efl.Canvas.Vg (Efl.Canvas.Object, Efl.Gfx.Fill, Efl.Gfx.View)
26 Efl.Object.constructor; 73 Efl.Object.constructor;
27 Efl.Object.finalize; 74 Efl.Object.finalize;
28 Efl.Object.destructor; 75 Efl.Object.destructor;
29 Efl.Gfx.Fill.fill { get; set; }
30 Efl.Gfx.View.view_size { get; set; }
31 } 76 }
32} 77}
diff --git a/src/lib/evas/canvas/evas_vg_private.h b/src/lib/evas/canvas/evas_vg_private.h
index f45ba0a3ac..d3e151aba1 100644
--- a/src/lib/evas/canvas/evas_vg_private.h
+++ b/src/lib/evas/canvas/evas_vg_private.h
@@ -12,17 +12,16 @@ typedef struct _Efl_Canvas_Vg_Data Efl_Canvas_Vg_Data;
12 12
13struct _Efl_Canvas_Vg_Data 13struct _Efl_Canvas_Vg_Data
14{ 14{
15 void *engine_data; 15 void *engine_data;
16 Efl_VG *root; 16 Efl_VG *root;
17 Efl_VG *vg_tree; 17 Efl_VG *vg_tree;
18 18 Eina_Rect fill;
19 Eina_Rect fill; 19 Eina_Rect viewbox;
20 20 unsigned int width, height;
21 unsigned int width, height; 21 Eina_Array cleanup;
22 22 double align_x, align_y;
23 Eina_Array cleanup; 23 Efl_Canvas_Vg_Fill_Mode fill_mode;
24 24 Eina_Bool changed;
25 Eina_Bool changed;
26}; 25};
27 26
28struct _Efl_VG_Data 27struct _Efl_VG_Data