aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/evas/canvas/evas_vg_shape.c
blob: c61b1cf293006f6b1b783db3208f2cf4de0ffccd (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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
#include "evas_common_private.h"
#include "evas_private.h"

#include "evas_vg_private.h"

#define MY_CLASS EFL_VG_SHAPE_CLASS

typedef struct _Efl_VG_Shape_Data Efl_VG_Shape_Data;
struct _Efl_VG_Shape_Data
{
   Efl_VG *fill;

   struct {
      Efl_Gfx_Dash *dash;
      Efl_VG *fill;
      Efl_VG *marker;

      double scale;
      double width;
      double centered; // from 0 to 1

      int r, g, b, a;

      unsigned int dash_count;

      Efl_Gfx_Cap cap;
      Efl_Gfx_Join join;
   } stroke;
};

static void
_efl_vg_shape_efl_vg_base_bounds_get(Eo *obj,
                                    Efl_VG_Shape_Data *pd EINA_UNUSED,
                                    Eina_Rectangle *r)
{
   // FIXME: Use the renderer bounding box when it has been created instead of an estimation
  eo_do(obj, efl_gfx_shape_bounds_get(obj, r));
}

static void
_efl_vg_shape_fill_set(Eo *obj EINA_UNUSED,
                       Efl_VG_Shape_Data *pd,
                       Efl_VG *f)
{
   Efl_VG *tmp = pd->fill;

   pd->fill = eo_ref(f);
   eo_unref(tmp);

   _efl_vg_base_changed(obj);
}

static Efl_VG *
_efl_vg_shape_fill_get(Eo *obj EINA_UNUSED, Efl_VG_Shape_Data *pd)
{
   return pd->fill;
}

static void
_efl_vg_shape_efl_gfx_shape_stroke_scale_set(Eo *obj EINA_UNUSED,
                                             Efl_VG_Shape_Data *pd,
                                             double s)
{
   pd->stroke.scale = s;

   _efl_vg_base_changed(obj);
}

static double
_efl_vg_shape_efl_gfx_shape_stroke_scale_get(Eo *obj EINA_UNUSED,
                                             Efl_VG_Shape_Data *pd)
{
   return pd->stroke.scale;
}

static void
_efl_vg_shape_efl_gfx_shape_stroke_color_set(Eo *obj EINA_UNUSED,
                                             Efl_VG_Shape_Data *pd,
                                             int r, int g, int b, int a)
{
   pd->stroke.r = r;
   pd->stroke.g = g;
   pd->stroke.b = b;
   pd->stroke.a = a;

   _efl_vg_base_changed(obj);
}

static Eina_Bool
_efl_vg_shape_efl_gfx_base_color_part_set(Eo *obj, Efl_VG_Shape_Data *pd,
                                          const char * part,
                                          int r, int g, int b, int a)
{
   Eina_Bool ret;

   if (part && !strcmp(part, "stroke"))
     {
        _efl_vg_shape_efl_gfx_shape_stroke_color_set(obj, pd, r, g, b, a);
        return EINA_TRUE;
     }

   
   ret = eo_super_efl_gfx_color_part_set(EFL_VG_SHAPE_CLASS, obj, part, r, g, b, a);

   return ret;
}

static void
_efl_vg_shape_efl_gfx_shape_stroke_color_get(Eo *obj EINA_UNUSED,
                                             Efl_VG_Shape_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;
}

static Eina_Bool
_efl_vg_shape_efl_gfx_base_color_part_get(Eo *obj, Efl_VG_Shape_Data *pd,
                                          const char * part,
                                          int *r, int *g, int *b, int *a)
{
   Eina_Bool ret;

   if (part && !strcmp(part, "stroke"))
     {
        _efl_vg_shape_efl_gfx_shape_stroke_color_get(obj, pd, r, g, b, a);
        return EINA_TRUE;
     }

   ret = eo_super_efl_gfx_color_part_get(EFL_VG_SHAPE_CLASS, obj, part, r, g, b, a);

   return ret;
}

static void
_efl_vg_shape_stroke_fill_set(Eo *obj EINA_UNUSED,
                              Efl_VG_Shape_Data *pd,
                              Efl_VG *f)
{
   Efl_VG *tmp = pd->fill;

   pd->stroke.fill = eo_ref(f);
   eo_unref(tmp);

   _efl_vg_base_changed(obj);
}

static Efl_VG *
_efl_vg_shape_stroke_fill_get(Eo *obj EINA_UNUSED,
                              Efl_VG_Shape_Data *pd)
{
   return pd->stroke.fill;
}

static void
_efl_vg_shape_efl_gfx_shape_stroke_width_set(Eo *obj EINA_UNUSED,
                                             Efl_VG_Shape_Data *pd,
                                             double w)
{
   pd->stroke.width = w;

   _efl_vg_base_changed(obj);
}

static double
_efl_vg_shape_efl_gfx_shape_stroke_width_get(Eo *obj EINA_UNUSED,
                                             Efl_VG_Shape_Data *pd)
{
   return pd->stroke.width;
}

static void
_efl_vg_shape_efl_gfx_shape_stroke_location_set(Eo *obj EINA_UNUSED,
                                                Efl_VG_Shape_Data *pd,
                                                double centered)
{
   pd->stroke.centered = centered;

   _efl_vg_base_changed(obj);
}

static double
_efl_vg_shape_efl_gfx_shape_stroke_location_get(Eo *obj EINA_UNUSED,
                                                Efl_VG_Shape_Data *pd)
{
   return pd->stroke.centered;
}

static void
_efl_vg_shape_efl_gfx_shape_stroke_dash_set(Eo *obj EINA_UNUSED,
                                            Efl_VG_Shape_Data *pd,
                                            const Efl_Gfx_Dash *dash,
                                            unsigned int length)
{
   free(pd->stroke.dash);
   pd->stroke.dash = NULL;
   pd->stroke.dash_count = 0;

   // check for null or empty dash
   if (!dash || !length) return;

   pd->stroke.dash = malloc(sizeof (Efl_Gfx_Dash) * length);
   if (!pd->stroke.dash) return ;

   memcpy(pd->stroke.dash, dash, sizeof (Efl_Gfx_Dash) * length);
   pd->stroke.dash_count = length;

   _efl_vg_base_changed(obj);
}

static void
_efl_vg_shape_efl_gfx_shape_stroke_dash_get(Eo *obj EINA_UNUSED,
                                            Efl_VG_Shape_Data *pd,
                                            const Efl_Gfx_Dash **dash,
                                            unsigned int *length)
{
   if (dash) *dash = pd->stroke.dash;
   if (length) *length = pd->stroke.dash_count;
}

static void
_efl_vg_shape_stroke_marker_set(Eo *obj EINA_UNUSED,
                                Efl_VG_Shape_Data *pd,
                                Efl_VG_Shape *m)
{
   Efl_VG *tmp = pd->stroke.marker;

   pd->stroke.marker = eo_ref(m);
   eo_unref(tmp);

   _efl_vg_base_changed(obj);
}

static Efl_VG_Shape *
_efl_vg_shape_stroke_marker_get(Eo *obj EINA_UNUSED,
                                Efl_VG_Shape_Data *pd)
{
   return pd->stroke.marker;
}

static void
_efl_vg_shape_efl_gfx_shape_stroke_cap_set(Eo *obj EINA_UNUSED,
                                           Efl_VG_Shape_Data *pd,
                                           Efl_Gfx_Cap c)
{
   pd->stroke.cap = c;

   _efl_vg_base_changed(obj);
}

static Efl_Gfx_Cap
_efl_vg_shape_efl_gfx_shape_stroke_cap_get(Eo *obj EINA_UNUSED,
                                           Efl_VG_Shape_Data *pd)
{
   return pd->stroke.cap;
}

static void
_efl_vg_shape_efl_gfx_shape_stroke_join_set(Eo *obj EINA_UNUSED,
                                            Efl_VG_Shape_Data *pd,
                                            Efl_Gfx_Join j)
{
   pd->stroke.join = j;

   _efl_vg_base_changed(obj);
}

static Efl_Gfx_Join
_efl_vg_shape_efl_gfx_shape_stroke_join_get(Eo *obj EINA_UNUSED,
                                            Efl_VG_Shape_Data *pd)
{
   return pd->stroke.join;
}

static void
_efl_vg_shape_render_pre(Eo *obj EINA_UNUSED,
                         Eina_Matrix3 *parent,
                         Ector_Surface *s,
                         void *data,
                         Efl_VG_Base_Data *nd)
{
   Efl_VG_Shape_Data *pd = data;
   Efl_VG_Base_Data *fill, *stroke_fill, *stroke_marker, *mask;
   double xn = nd->x, yn = nd->y ;

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

   if(parent) eina_matrix3_point_transform(parent, nd->x, nd->y, &xn, &yn);

   EFL_VG_COMPUTE_MATRIX(current, parent, nd);

   fill = _evas_vg_render_pre(pd->fill, s, current);
   stroke_fill = _evas_vg_render_pre(pd->stroke.fill, s, current);
   stroke_marker = _evas_vg_render_pre(pd->stroke.marker, s, current);
   mask = _evas_vg_render_pre(nd->mask, s, current);

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

   eo_do(nd->renderer,
         ector_renderer_transformation_set(nd->renderer, current),
         ector_renderer_origin_set(nd->renderer, xn, yn),
         ector_renderer_color_set(nd->renderer, nd->r, nd->g, nd->b, nd->a),
         ector_renderer_visibility_set(nd->renderer, nd->visibility),
         ector_renderer_mask_set(nd->renderer, mask ? mask->renderer : NULL),
         ector_renderer_shape_fill_set(nd->renderer, fill ? fill->renderer : NULL),
         ector_renderer_shape_stroke_fill_set(nd->renderer, stroke_fill ? stroke_fill->renderer : NULL),
         ector_renderer_shape_stroke_marker_set(nd->renderer, stroke_marker ? stroke_marker->renderer : NULL),
         efl_gfx_shape_dup(nd->renderer, obj),
         ector_renderer_prepare(nd->renderer));
}

static Eo *
_efl_vg_shape_eo_base_constructor(Eo *obj, Efl_VG_Shape_Data *pd)
{
   Efl_VG_Base_Data *nd;

   obj = eo_super_eo_constructor( MY_CLASS, NULL);

   pd->stroke.cap = EFL_GFX_CAP_BUTT;
   pd->stroke.join = EFL_GFX_JOIN_MITER;
   pd->stroke.scale = 1;
   pd->stroke.centered = 0.5;

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

   return obj;
}

static void
_efl_vg_shape_eo_base_destructor(Eo *obj, Efl_VG_Shape_Data *pd EINA_UNUSED)
{
   eo_super_eo_destructor(MY_CLASS, obj);
}

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

   fromd = eo_data_scope_get(from, EFL_VG_SHAPE_CLASS);
   tod = eo_data_scope_get(to, EFL_VG_SHAPE_CLASS);

   r = eo_super_efl_vg_interpolate(MY_CLASS, obj, from, to, pos_map);

   eo_do(obj, r &= efl_gfx_shape_interpolate(obj, from, to, pos_map));

   if (fromd->fill && tod->fill && pd->fill)
     {
        eo_do(pd->fill, r &= efl_vg_interpolate(pd->fill, fromd->fill, tod->fill, pos_map));
     }
   if (fromd->stroke.fill && tod->stroke.fill && pd->stroke.fill)
     {
        eo_do(pd->stroke.fill,
              r &= efl_vg_interpolate(pd->stroke.fill, fromd->stroke.fill, tod->stroke.fill, pos_map));
     }
   if (fromd->stroke.marker && tod->stroke.marker && pd->stroke.marker)
     {
        eo_do(pd->stroke.marker,
              r &= efl_vg_interpolate(pd->stroke.marker, fromd->stroke.marker, tod->stroke.marker, pos_map));
     }

   return r;
}

static void
_efl_vg_shape_efl_vg_base_dup(Eo *obj, Efl_VG_Shape_Data *pd EINA_UNUSED, const Efl_VG_Base *from)
{
   Efl_VG_Shape_Data *fromd;
   Eo *parent;
   Eo *fill = NULL, *stroke_fill = NULL, *stroke_marker = NULL;

   eo_super_efl_vg_dup(MY_CLASS, obj, from);

   eo_do(obj, parent = eo_parent_get(obj));

   fromd = eo_data_scope_get(from, MY_CLASS);

   if (fromd->fill)
     {
        eo_add(fill, eo_class_get(fromd->fill),
                      parent,
                      efl_vg_dup(NULL, fromd->fill));
     }

   if (fromd->stroke.fill)
     {
        eo_add(stroke_fill, eo_class_get(fromd->stroke.fill),
                             parent,
                             efl_vg_dup(NULL, fromd->stroke.fill));
     }

   if (fromd->stroke.marker)
     {
        eo_add(stroke_marker, eo_class_get(fromd->stroke.marker),
                               parent,
                               efl_vg_dup(NULL, fromd->stroke.marker));
     }

   eo_do(obj,
         efl_vg_shape_fill_set(obj, fill),
         efl_vg_shape_stroke_fill_set(obj, stroke_fill),
         efl_vg_shape_stroke_marker_set(obj, stroke_marker),
         efl_gfx_shape_dup(obj, from));
}

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

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

EAPI void
evas_vg_shape_stroke_scale_set(Eo *obj, double s)
{
   eo_do(obj, efl_gfx_shape_stroke_scale_set(obj, s));
}

EAPI void
evas_vg_shape_stroke_color_get(Eo *obj, int *r, int *g, int *b, int *a)
{
   eo_do(obj, efl_gfx_shape_stroke_color_get(obj, r, g, b, a));
}

EAPI void
evas_vg_shape_stroke_color_set(Eo *obj, int r, int g, int b, int a)
{
   eo_do(obj, efl_gfx_shape_stroke_color_set(obj, r, g, b, a));
}

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

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

EAPI void
evas_vg_shape_stroke_width_set(Eo *obj, double w)
{
   eo_do(obj, efl_gfx_shape_stroke_width_set(obj, w));
}

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

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

EAPI void
evas_vg_shape_stroke_location_set(Eo *obj, double centered)
{
   eo_do(obj, efl_gfx_shape_stroke_location_set(obj, centered));
}

EAPI void
evas_vg_shape_stroke_dash_get(Eo *obj, const Efl_Gfx_Dash **dash, unsigned int *length)
{
   eo_do(obj, efl_gfx_shape_stroke_dash_get(obj, dash, length));
}

EAPI void
evas_vg_shape_stroke_dash_set(Eo *obj, const Efl_Gfx_Dash *dash, unsigned int length)
{
   eo_do(obj, efl_gfx_shape_stroke_dash_set(obj, dash, length));
}

EAPI Efl_Gfx_Cap
evas_vg_shape_stroke_cap_get(Eo *obj)
{
   Efl_Gfx_Cap ret;

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

EAPI void
evas_vg_shape_stroke_cap_set(Eo *obj, Efl_Gfx_Cap c)
{
   eo_do(obj, efl_gfx_shape_stroke_cap_set(obj, c));
}

EAPI Efl_Gfx_Join
evas_vg_shape_stroke_join_get(Eo *obj)
{
   Efl_Gfx_Join ret;

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

EAPI void
evas_vg_shape_stroke_join_set(Eo *obj, Efl_Gfx_Join j)
{
   eo_do(obj, efl_gfx_shape_stroke_join_set(obj, j));
}

EAPI void
evas_vg_shape_shape_path_set(Eo *obj, const Efl_Gfx_Path_Command *op, const double *points)
{
   eo_do(obj, efl_gfx_shape_path_set(obj, op, points));
}

EAPI void
evas_vg_shape_shape_path_get(Eo *obj, const Efl_Gfx_Path_Command **op, const double **points)
{
   eo_do(obj, efl_gfx_shape_path_get(obj, op, points));
}

EAPI void
evas_vg_shape_shape_path_length_get(Eo *obj, unsigned int *commands, unsigned int *points)
{
   eo_do(obj, efl_gfx_shape_path_length_get(obj, commands, points));
}

EAPI void
evas_vg_shape_shape_current_get(Eo *obj, double *x, double *y)
{
   eo_do(obj, efl_gfx_shape_current_get(obj, x, y));
}

EAPI void
evas_vg_shape_shape_current_ctrl_get(Eo *obj, double *x, double *y)
{
   eo_do(obj, efl_gfx_shape_current_ctrl_get(obj, x, y));
}

EAPI void
evas_vg_shape_shape_dup(Eo *obj, Eo *dup_from)
{
   eo_do(obj, efl_gfx_shape_dup(obj, dup_from));
}

EAPI void
evas_vg_shape_shape_reset(Eo *obj)
{
   eo_do(obj, efl_gfx_shape_reset(obj));
}

EAPI void
evas_vg_shape_shape_append_move_to(Eo *obj, double x, double y)
{
   eo_do(obj, efl_gfx_shape_append_move_to(obj, x, y));
}

EAPI void
evas_vg_shape_shape_append_line_to(Eo *obj, double x, double y)
{
   eo_do(obj, efl_gfx_shape_append_line_to(obj, x, y));
}

EAPI void
evas_vg_shape_shape_append_quadratic_to(Eo *obj, double x, double y, double ctrl_x, double ctrl_y)
{
   eo_do(obj, efl_gfx_shape_append_quadratic_to(obj, x, y, ctrl_x, ctrl_y));
}

EAPI void
evas_vg_shape_shape_append_squadratic_to(Eo *obj, double x, double y)
{
   eo_do(obj, efl_gfx_shape_append_squadratic_to(obj, x, y));
}

EAPI void
evas_vg_shape_shape_append_cubic_to(Eo *obj, double x, double y, double ctrl_x0, double ctrl_y0, double ctrl_x1, double ctrl_y1)
{
   eo_do(obj, efl_gfx_shape_append_cubic_to(obj, x, y, ctrl_x0, ctrl_y0, ctrl_x1, ctrl_y1));
}

EAPI void
evas_vg_shape_shape_append_scubic_to(Eo *obj, double x, double y, double ctrl_x, double ctrl_y)
{
   eo_do(obj, efl_gfx_shape_append_scubic_to(obj, x, y, ctrl_x, ctrl_y));
}

EAPI void
evas_vg_shape_shape_append_arc_to(Eo *obj, double x, double y, double rx, double ry, double angle, Eina_Bool large_arc, Eina_Bool sweep)
{
   eo_do(obj, efl_gfx_shape_append_arc_to(obj, x, y, rx, ry, angle, large_arc, sweep));
}

EAPI void
evas_vg_shape_shape_append_close(Eo *obj)
{
   eo_do(obj, efl_gfx_shape_append_close(obj));
}

EAPI void
evas_vg_shape_shape_append_circle(Eo *obj, double x, double y, double radius)
{
   eo_do(obj, efl_gfx_shape_append_circle(obj, x, y, radius));
}

EAPI void
evas_vg_shape_shape_append_rect(Eo *obj, double x, double y, double w, double h, double rx, double ry)
{
   eo_do(obj, efl_gfx_shape_append_rect(obj, x, y, w, h, rx, ry));
}

EAPI void
evas_vg_shape_shape_append_svg_path(Eo *obj, const char *svg_path_data)
{
   eo_do(obj, efl_gfx_shape_append_svg_path(obj, svg_path_data));
}

EAPI Eina_Bool
evas_vg_shape_shape_interpolate(Eo *obj, const Eo *from, const Eo *to, double pos_map)
{
   Eina_Bool ret;

   return eo_do_ret(obj, ret, efl_gfx_shape_interpolate(obj, from, to, pos_map));
}

EAPI Eina_Bool
evas_vg_shape_shape_equal_commands(Eo *obj, const Eo *with)
{
   Eina_Bool ret;

   return eo_do_ret(obj, ret, efl_gfx_shape_equal_commands(obj, with));
}

EAPI Efl_VG*
evas_vg_shape_add(Efl_VG *parent)
{
   Eo* o;
   eo_add(o, EFL_VG_SHAPE_CLASS, parent);
   return o;
}

#include "efl_vg_shape.eo.c"