summaryrefslogtreecommitdiff
path: root/src/lib/ector/ector_renderer.c
blob: f3b6c9499b660465cc53993f3a4486459705bd04 (plain)
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
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif

#include <Eina.h>
#include <Ector.h>

#include "ector_private.h"

#define MY_CLASS ECTOR_RENDERER_CLASS

static void
_ector_renderer_efl_object_destructor(Eo *obj, Ector_Renderer_Data *pd)
{
   if (pd->m) free(pd->m);
   efl_unref(pd->surface);

   efl_destructor(efl_super(obj, MY_CLASS));
}

static Efl_Object *
_ector_renderer_efl_object_finalize(Eo *obj, Ector_Renderer_Data *pd)
{
   if (!pd->surface)
     {
        CRI("surface is not set yet, go fix your code!");
        return NULL;
     }
   pd->finalized = EINA_TRUE;
   return efl_finalize(efl_super(obj, MY_CLASS));
}

static Ector_Surface *
_ector_renderer_surface_get(Eo *obj EINA_UNUSED, Ector_Renderer_Data *pd)
{
   return pd->surface;
}

static void
_ector_renderer_surface_set(Eo *obj EINA_UNUSED, Ector_Renderer_Data *pd, Ector_Surface *s)
{
   if (pd->finalized)
     {
        CRI("surface_set can be called during object creation only!");
        return;
     }
   pd->surface = efl_xref(s, obj);
}

static void
_ector_renderer_transformation_set(Eo *obj EINA_UNUSED,
                                                Ector_Renderer_Data *pd,
                                                const Eina_Matrix3 *m)
{
   if (!m)
     {
        free(pd->m);
        pd->m = NULL;
     }
   else
     {
        if (!pd->m) pd->m = malloc(sizeof (Eina_Matrix3));
        if (!pd->m) return ;

        memcpy(pd->m, m, sizeof (Eina_Matrix3));
     }
}

static const Eina_Matrix3 *
_ector_renderer_transformation_get(Eo *obj EINA_UNUSED,
                                                Ector_Renderer_Data *pd)
{
   return pd->m;
}

static void
_ector_renderer_origin_set(Eo *obj EINA_UNUSED,
                                        Ector_Renderer_Data *pd,
                                        double x, double y)
{
   pd->origin.x = x;
   pd->origin.y = y;
}

static void
_ector_renderer_origin_get(Eo *obj EINA_UNUSED,
                                        Ector_Renderer_Data *pd,
                                        double *x, double *y)
{
   if (x) *x = pd->origin.x;
   if (y) *y = pd->origin.y;
}

static void
_ector_renderer_visibility_set(Eo *obj EINA_UNUSED,
                                            Ector_Renderer_Data *pd,
                                            Eina_Bool v)
{
   pd->visibility = v;
}

static Eina_Bool
_ector_renderer_visibility_get(Eo *obj EINA_UNUSED,
                                            Ector_Renderer_Data *pd)
{
   return pd->visibility;
}

static void
_ector_renderer_color_set(Eo *obj EINA_UNUSED,
                                       Ector_Renderer_Data *pd,
                                       int r, int g, int b, int a)
{
   pd->color.r = r;
   pd->color.g = g;
   pd->color.b = b;
   pd->color.a = a;
}

static void
_ector_renderer_color_get(Eo *obj EINA_UNUSED,
                                       Ector_Renderer_Data *pd,
                                       int *r, int *g, int *b, int *a)
{
   if (r) *r = pd->color.r;
   if (g) *g = pd->color.g;
   if (b) *b = pd->color.b;
   if (a) *a = pd->color.a;
}

static void
_ector_renderer_mask_set(Eo *obj EINA_UNUSED,
                                      Ector_Renderer_Data *pd,
                                      Ector_Renderer *r)
{
   _efl_refplace(&pd->mask, r);
}

static Ector_Renderer *
_ector_renderer_mask_get(Eo *obj EINA_UNUSED,
                                      Ector_Renderer_Data *pd)
{
   return pd->mask;
}

static void
_ector_renderer_quality_set(Eo *obj EINA_UNUSED,
                                         Ector_Renderer_Data *pd,
                                         Ector_Quality q)
{
   pd->q = q;
}

static Ector_Quality
_ector_renderer_quality_get(Eo *obj EINA_UNUSED,
                                         Ector_Renderer_Data *pd)
{
   return pd->q;
}

static Eina_Bool
_ector_renderer_prepare(Eo *obj EINA_UNUSED,
                                     Ector_Renderer_Data *pd)
{
   if (pd->mask)
     ector_renderer_prepare(pd->mask);

   return EINA_TRUE;
}

static unsigned int
_ector_renderer_crc_get(Eo *obj EINA_UNUSED,
                                     Ector_Renderer_Data *pd)
{
   unsigned int crc;

   crc = eina_crc((void*) &pd->color, sizeof(pd->color), 0xffffffff, EINA_TRUE);
   crc = eina_crc((void*) &pd->q, sizeof(pd->q), crc, EINA_FALSE);
   crc = eina_crc((void*) &pd->origin, sizeof(pd->origin), crc, EINA_FALSE);

   if (pd->m) crc = eina_crc((void*) pd->m, sizeof(Eina_Matrix3), crc, EINA_FALSE);
   if (pd->mask) crc = _renderer_crc_get(pd->mask, crc);

   return crc;
}

#include "ector_renderer.eo.c"