aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/evas/canvas/evas_vg_gradient_radial.c
blob: d6d62c5857d1b04b3940bc82fe902a807fa40125 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#include "evas_common_private.h"
#include "evas_private.h"

#include "evas_vg_private.h"

#define MY_CLASS EFL_VG_GRADIENT_RADIAL_CLASS

typedef struct _Efl_VG_Gradient_Radial_Data Efl_VG_Gradient_Radial_Data;
struct _Efl_VG_Gradient_Radial_Data
{
   struct {
      double x, y;
   } center, focal;
   double radius;
};

static void
_efl_vg_gradient_radial_efl_gfx_gradient_radial_center_set(Eo *obj EINA_UNUSED,
                                                           Efl_VG_Gradient_Radial_Data *pd,
                                                           double x, double y)
{
   pd->center.x = x;
   pd->center.y = y;

   _efl_vg_base_changed(obj);
}

static void
_efl_vg_gradient_radial_efl_gfx_gradient_radial_center_get(Eo *obj EINA_UNUSED,
                                                           Efl_VG_Gradient_Radial_Data *pd,
                                                           double *x, double *y)
{
   if (x) *x = pd->center.x;
   if (y) *y = pd->center.y;
}

static void
_efl_vg_gradient_radial_efl_gfx_gradient_radial_radius_set(Eo *obj EINA_UNUSED,
                                                           Efl_VG_Gradient_Radial_Data *pd,
                                                           double r)
{
   pd->radius = r;

   _efl_vg_base_changed(obj);
}

static double
_efl_vg_gradient_radial_efl_gfx_gradient_radial_radius_get(Eo *obj EINA_UNUSED,
                                                           Efl_VG_Gradient_Radial_Data *pd)
{
   return pd->radius;
}

static void
_efl_vg_gradient_radial_efl_gfx_gradient_radial_focal_set(Eo *obj EINA_UNUSED,
                                                          Efl_VG_Gradient_Radial_Data *pd,
                                                          double x, double y)
{
   pd->focal.x = x;
   pd->focal.y = y;

   _efl_vg_base_changed(obj);
}

static void
_efl_vg_gradient_radial_efl_gfx_gradient_radial_focal_get(Eo *obj EINA_UNUSED,
                                                          Efl_VG_Gradient_Radial_Data *pd,
                                                          double *x, double *y)
{
   if (x) *x = pd->focal.x;
   if (y) *y = pd->focal.y;
}

static void
_efl_vg_gradient_radial_render_pre(Eo *obj,
                                    Eina_Matrix3 *parent,
                                    Ector_Surface *s,
                                    void *data,
                                    Efl_VG_Base_Data *nd)
{
   Efl_VG_Gradient_Radial_Data *pd = data;
   Efl_VG_Gradient_Data *gd;

   if (!nd->changed) return ;
   nd->changed = EINA_FALSE;

   gd = eo_data_scope_get(obj, EFL_VG_GRADIENT_CLASS);
   EFL_VG_COMPUTE_MATRIX(current, parent, nd);

   if (!nd->renderer)
     {
        eo_do(s, nd->renderer = ector_surface_renderer_factory_new(ECTOR_RENDERER_GENERIC_GRADIENT_RADIAL_MIXIN));
     }

   eo_do(nd->renderer,
         ector_renderer_transformation_set(current),
         ector_renderer_origin_set(nd->x, nd->y),
         ector_renderer_color_set(nd->r, nd->g, nd->b, nd->a),
         ector_renderer_visibility_set(nd->visibility),
         efl_gfx_gradient_stop_set(gd->colors, gd->colors_count),
         efl_gfx_gradient_spread_set(gd->s),
         efl_gfx_gradient_radial_center_set(pd->center.x, pd->center.y),
         efl_gfx_gradient_radial_focal_set(pd->focal.x, pd->focal.y),
         efl_gfx_gradient_radial_radius_set(pd->radius),
         ector_renderer_prepare());
}

static Eo *
_efl_vg_gradient_radial_eo_base_constructor(Eo *obj, Efl_VG_Gradient_Radial_Data *pd)
{
   Efl_VG_Base_Data *nd;

   obj = eo_do_super_ret(obj, MY_CLASS, obj, eo_constructor());

   nd = eo_data_scope_get(obj, EFL_VG_BASE_CLASS);
   nd->render_pre = _efl_vg_gradient_radial_render_pre;
   nd->data = pd;

   return obj;
}

static void
_efl_vg_gradient_radial_eo_base_destructor(Eo *obj,
                                           Efl_VG_Gradient_Radial_Data *pd EINA_UNUSED)
{
   eo_do_super(obj, MY_CLASS, eo_destructor());
}

static void
_efl_vg_gradient_radial_efl_vg_base_bounds_get(Eo *obj, Efl_VG_Gradient_Radial_Data *pd, Eina_Rectangle *r)
{
   Efl_VG_Base_Data *nd;

   nd = eo_data_scope_get(obj, EFL_VG_BASE_CLASS);
   EINA_RECTANGLE_SET(r,
                      nd->x + pd->center.x - pd->radius,
                      nd->y + pd->center.y - pd->radius,
                      pd->radius * 2, pd->radius * 2);
}

static Eina_Bool
_efl_vg_gradient_radial_efl_vg_base_interpolate(Eo *obj,
                                                Efl_VG_Gradient_Radial_Data *pd,
                                                const Efl_VG_Base *from, const Efl_VG_Base *to,
                                                double pos_map)
{
   Efl_VG_Gradient_Radial_Data *fromd, *tod;
   double from_map;
   Eina_Bool r;

   eo_do_super(obj, EFL_VG_GRADIENT_RADIAL_CLASS, r = efl_vg_interpolate(from, to, pos_map));

   if (!r) return EINA_FALSE;

   fromd = eo_data_scope_get(from, EFL_VG_GRADIENT_RADIAL_CLASS);
   tod = eo_data_scope_get(to, EFL_VG_GRADIENT_RADIAL_CLASS);
   from_map = 1.0 - pos_map;

#define INTP(Pd, From, To, Member, From_Map, Pos_Map)   \
   Pd->Member = From->Member * From_Map + To->Member * Pos_Map

   INTP(pd, fromd, tod, focal.x, from_map, pos_map);
   INTP(pd, fromd, tod, focal.y, from_map, pos_map);
   INTP(pd, fromd, tod, center.x, from_map, pos_map);
   INTP(pd, fromd, tod, center.y, from_map, pos_map);
   INTP(pd, fromd, tod, radius, from_map, pos_map);

#undef INTP

   return EINA_TRUE;
}

static void
_efl_vg_gradient_radial_efl_vg_base_dup(Eo *obj,
                                        Efl_VG_Gradient_Radial_Data *pd EINA_UNUSED,
                                        const Efl_VG_Base *from)
{
   Efl_VG_Gradient_Radial_Data *fromd;

   eo_do_super(obj, EFL_VG_GRADIENT_RADIAL_CLASS, efl_vg_dup(from));

   fromd = eo_data_scope_get(from, EFL_VG_GRADIENT_RADIAL_CLASS);

   eo_do(obj,
         efl_gfx_gradient_radial_focal_set(fromd->focal.x, fromd->focal.y),
         efl_gfx_gradient_radial_center_set(fromd->center.x, fromd->center.y),
         efl_gfx_gradient_radial_radius_set(fromd->radius));
}

EAPI void
evas_vg_gradient_radial_center_set(Eo *obj, double x, double y)
{
   eo_do(obj, efl_gfx_gradient_radial_center_set(x, y));
}

EAPI void
evas_vg_gradient_radial_center_get(Eo *obj, double *x, double *y)
{
   eo_do(obj, efl_gfx_gradient_radial_center_get(x, y));
}

EAPI void
evas_vg_gradient_radial_radius_set(Eo *obj, double r)
{
   eo_do(obj, efl_gfx_gradient_radial_radius_set(r));
}

EAPI double
evas_vg_gradient_radial_radius_get(Eo *obj)
{
   double ret;

   return eo_do_ret(obj, ret, efl_gfx_gradient_radial_radius_get());
}

EAPI void
evas_vg_gradient_radial_focal_set(Eo *obj, double x, double y)
{
   eo_do(obj, efl_gfx_gradient_radial_focal_set(x, y));
}

EAPI void
evas_vg_gradient_radial_focal_get(Eo *obj, double *x, double *y)
{
   eo_do(obj, efl_gfx_gradient_radial_focal_get(x, y));
}

#include "efl_vg_gradient_radial.eo.c"