aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/ector/cairo/ector_cairo_private.h
blob: b45f2f53f46b6de32c9f720a0c669c8525adf978 (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
#ifndef ECTOR_CAIRO_PRIVATE_H_
# define ECTOR_CAIRO_PRIVATE_H_

typedef void cairo_pattern_t;

typedef struct {
   double xx; double yx;
   double xy; double yy;
   double x0; double y0;
} cairo_matrix_t;

typedef struct _Ector_Cairo_Surface_Data Ector_Cairo_Surface_Data;
typedef struct _Ector_Renderer_Cairo_Base_Data Ector_Renderer_Cairo_Base_Data;

struct _Ector_Cairo_Surface_Data
{
   cairo_t *cairo;
   struct {
      double x, y;
   } current;
};

struct _Ector_Renderer_Cairo_Base_Data
{
   Ector_Cairo_Surface_Data *parent;
   Ector_Renderer_Generic_Base_Data *generic;

   cairo_matrix_t *m;
};

typedef enum _cairo_extend {
    CAIRO_EXTEND_NONE,
    CAIRO_EXTEND_REPEAT,
    CAIRO_EXTEND_REFLECT,
    CAIRO_EXTEND_PAD
} cairo_extend_t;

static inline cairo_extend_t
_ector_cairo_extent_get(Efl_Gfx_Gradient_Spread s)
{
   switch (s)
     {
       case EFL_GFX_GRADIENT_SPREAD_PAD:
          return CAIRO_EXTEND_PAD;
       case EFL_GFX_GRADIENT_SPREAD_REFLECT:
          return CAIRO_EXTEND_REFLECT;
       case EFL_GFX_GRADIENT_SPREAD_REPEAT:
          return CAIRO_EXTEND_REPEAT;
       default:
          return CAIRO_EXTEND_NONE;
     }
}

#define CHECK_CAIRO(Parent) (!(Parent && Parent->cairo))

#define USE(Obj, Sym, Error)                            \
  if (!Sym) Sym = _ector_cairo_symbol_get(Obj, #Sym);   \
  if (!Sym) return Error;

static inline void *
_ector_cairo_symbol_get(Eo *obj, const char *name)
{
   Eo *parent;
   void *sym;

   eo_do(obj, parent = eo_parent_get(obj));
   if (!parent) return NULL;

   eo_do(parent, sym = ector_cairo_surface_symbol_get(parent, name));
   return sym;
}

extern void (*cairo_pattern_add_color_stop_rgba)(cairo_pattern_t *pattern, double offset,
                                                 double red, double green, double blue, double alpha);

static inline void
_ector_renderer_cairo_gradient_prepare(Eo *obj,
                                       cairo_pattern_t *pat,
                                       Ector_Renderer_Generic_Gradient_Data *src,
                                       unsigned int mul_col)
{
   unsigned int i;

   USE(obj, cairo_pattern_add_color_stop_rgba, );

   for (i = 0; i < src->colors_count; i++)
     {
        int r,g,b,a;

        r = ((src->colors[i].r * R_VAL(&mul_col)) >> 8);
        g = ((src->colors[i].g * G_VAL(&mul_col)) >> 8);
        b = ((src->colors[i].b * B_VAL(&mul_col)) >> 8);
        a = ((src->colors[i].a * A_VAL(&mul_col)) >> 8);
        ector_color_argb_unpremul(a, &r, &g, &b);
        cairo_pattern_add_color_stop_rgba(pat, src->colors[i].offset, r/255.0, g/255.0, b/255.0, a/255.0);
     }
}

#endif