2015-04-03 07:21:54 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <Eina.h>
|
|
|
|
#include <Ector.h>
|
2015-04-03 07:22:02 -07:00
|
|
|
#include <cairo/Ector_Cairo.h>
|
2015-04-03 07:21:54 -07:00
|
|
|
|
|
|
|
#include "ector_private.h"
|
2015-04-03 07:22:02 -07:00
|
|
|
#include "ector_cairo_private.h"
|
|
|
|
|
|
|
|
static cairo_pattern_t *(*cairo_pattern_create_linear)(double x0, double y0,
|
|
|
|
double x1, double y1) = NULL;
|
|
|
|
static void (*cairo_set_source)(cairo_t *cr, cairo_pattern_t *source) = NULL;
|
|
|
|
static void (*cairo_fill)(cairo_t *cr) = NULL;
|
|
|
|
static void (*cairo_rectangle)(cairo_t *cr,
|
|
|
|
double x, double y,
|
|
|
|
double width, double height) = NULL;
|
|
|
|
static void (*cairo_pattern_add_color_stop_rgba)(cairo_pattern_t *pattern, double offset,
|
|
|
|
double red, double green, double blue, double alpha) = NULL;
|
|
|
|
static void (*cairo_pattern_destroy)(cairo_pattern_t *pattern) = NULL;
|
2015-04-03 07:21:54 -07:00
|
|
|
|
|
|
|
typedef struct _Ector_Renderer_Cairo_Gradient_Linear_Data Ector_Renderer_Cairo_Gradient_Linear_Data;
|
|
|
|
struct _Ector_Renderer_Cairo_Gradient_Linear_Data
|
|
|
|
{
|
2015-04-03 07:22:02 -07:00
|
|
|
Ector_Cairo_Surface_Data *parent;
|
|
|
|
cairo_pattern_t *pat;
|
2015-04-03 07:21:54 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
static Eina_Bool
|
2015-04-03 07:22:02 -07:00
|
|
|
_ector_renderer_cairo_gradient_linear_ector_renderer_generic_base_prepare(Eo *obj,
|
2015-04-03 07:22:14 -07:00
|
|
|
Ector_Renderer_Cairo_Gradient_Linear_Data *pd)
|
2015-04-03 07:21:54 -07:00
|
|
|
{
|
2015-04-03 07:22:02 -07:00
|
|
|
Ector_Renderer_Generic_Gradient_Linear_Data *gld;
|
|
|
|
Ector_Renderer_Generic_Gradient_Data *gd;
|
|
|
|
unsigned int i;
|
|
|
|
|
2015-04-03 07:31:44 -07:00
|
|
|
eo_do_super(obj, ECTOR_RENDERER_CAIRO_GRADIENT_LINEAR_CLASS, ector_renderer_prepare());
|
|
|
|
|
2015-04-03 07:22:02 -07:00
|
|
|
if (pd->pat) return EINA_FALSE;
|
|
|
|
|
2015-04-03 07:31:44 -07:00
|
|
|
gld = eo_data_scope_get(obj, ECTOR_RENDERER_GENERIC_GRADIENT_LINEAR_MIXIN);
|
|
|
|
gd = eo_data_scope_get(obj, ECTOR_RENDERER_GENERIC_GRADIENT_MIXIN);
|
2015-04-03 07:22:02 -07:00
|
|
|
if (!gld || !gd) return EINA_FALSE;
|
|
|
|
|
|
|
|
USE(obj, cairo_pattern_create_linear, EINA_FALSE);
|
|
|
|
USE(obj, cairo_pattern_add_color_stop_rgba, EINA_FALSE);
|
|
|
|
|
|
|
|
pd->pat = cairo_pattern_create_linear(gld->start.x, gld->start.y,
|
|
|
|
gld->end.x, gld->end.y);
|
|
|
|
for (i = 0; i < gd->colors_count; i++)
|
|
|
|
cairo_pattern_add_color_stop_rgba(pd->pat, gd->colors[i].offset,
|
|
|
|
gd->colors[i].r, gd->colors[i].g,
|
|
|
|
gd->colors[i].b, gd->colors[i].a);
|
|
|
|
|
|
|
|
if (!pd->parent)
|
|
|
|
{
|
|
|
|
Eo *parent;
|
|
|
|
|
|
|
|
eo_do(obj, parent = eo_parent_get());
|
|
|
|
if (!parent) return EINA_FALSE;
|
|
|
|
pd->parent = eo_data_xref(parent, ECTOR_CAIRO_SURFACE_CLASS, obj);
|
|
|
|
}
|
|
|
|
|
|
|
|
return EINA_FALSE;
|
2015-04-03 07:21:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
2015-04-03 07:22:02 -07:00
|
|
|
_ector_renderer_cairo_gradient_linear_ector_renderer_generic_base_draw(Eo *obj,
|
|
|
|
Ector_Renderer_Cairo_Gradient_Linear_Data *pd,
|
2015-04-03 07:33:19 -07:00
|
|
|
Ector_Rop op, Eina_Array *clips, unsigned int mul_col)
|
2015-04-03 07:21:54 -07:00
|
|
|
{
|
2015-04-03 07:34:03 -07:00
|
|
|
if (pd->pat) return EINA_FALSE;
|
|
|
|
|
2015-04-03 07:22:02 -07:00
|
|
|
Ector_Renderer_Generic_Gradient_Linear_Data *gld;
|
|
|
|
|
2015-04-03 07:22:07 -07:00
|
|
|
// FIXME: don't ignore clipping !
|
2015-04-03 07:31:44 -07:00
|
|
|
gld = eo_data_scope_get(obj, ECTOR_RENDERER_GENERIC_GRADIENT_LINEAR_MIXIN);
|
2015-04-03 07:31:37 -07:00
|
|
|
if (!pd->pat || !gld) return EINA_FALSE;
|
2015-04-03 07:22:02 -07:00
|
|
|
|
2015-04-03 07:33:19 -07:00
|
|
|
eo_do_super(obj, ECTOR_RENDERER_CAIRO_GRADIENT_LINEAR_CLASS, ector_renderer_draw(op, clips, mul_col));
|
2015-04-03 07:31:44 -07:00
|
|
|
|
2015-04-03 07:22:02 -07:00
|
|
|
USE(obj, cairo_rectangle, EINA_FALSE);
|
2015-04-03 07:31:36 -07:00
|
|
|
USE(obj, cairo_fill, EINA_FALSE);
|
2015-04-03 07:22:02 -07:00
|
|
|
|
2015-04-03 07:31:44 -07:00
|
|
|
cairo_rectangle(pd->parent->cairo, gld->start.x, gld->start.y,
|
2015-04-03 07:22:07 -07:00
|
|
|
gld->end.x - gld->start.x,
|
|
|
|
gld->end.y - gld->start.y);
|
2015-04-03 07:22:02 -07:00
|
|
|
eo_do(obj, ector_renderer_cairo_base_fill());
|
|
|
|
cairo_fill(pd->parent->cairo);
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
2015-04-03 07:21:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
2015-04-03 07:22:02 -07:00
|
|
|
_ector_renderer_cairo_gradient_linear_ector_renderer_cairo_base_fill(Eo *obj,
|
|
|
|
Ector_Renderer_Cairo_Gradient_Linear_Data *pd)
|
2015-04-03 07:21:54 -07:00
|
|
|
{
|
2015-04-03 07:31:37 -07:00
|
|
|
if (!pd->pat) return EINA_FALSE;
|
2015-04-03 07:22:02 -07:00
|
|
|
|
|
|
|
USE(obj, cairo_set_source, EINA_FALSE);
|
|
|
|
|
|
|
|
cairo_set_source(pd->parent->cairo, pd->pat);
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_ector_renderer_cairo_gradient_linear_eo_base_destructor(Eo *obj,
|
|
|
|
Ector_Renderer_Cairo_Gradient_Linear_Data *pd)
|
|
|
|
{
|
|
|
|
Eo *parent;
|
|
|
|
|
|
|
|
USE(obj, cairo_pattern_destroy, );
|
|
|
|
|
|
|
|
if (pd->pat) cairo_pattern_destroy(pd->pat);
|
|
|
|
pd->pat = NULL;
|
|
|
|
|
|
|
|
eo_do(obj, parent = eo_parent_get());
|
|
|
|
eo_data_xunref(parent, pd->parent, obj);
|
|
|
|
|
2015-04-03 07:22:07 -07:00
|
|
|
eo_do_super(obj, ECTOR_RENDERER_CAIRO_GRADIENT_LINEAR_CLASS, eo_destructor());
|
2015-04-03 07:22:02 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-04-03 07:30:42 -07:00
|
|
|
_ector_renderer_cairo_gradient_linear_efl_gfx_gradient_base_stop_set(Eo *obj, Ector_Renderer_Cairo_Gradient_Linear_Data *pd, const Efl_Gfx_Gradient_Stop *colors, unsigned int length)
|
2015-04-03 07:22:02 -07:00
|
|
|
{
|
|
|
|
USE(obj, cairo_pattern_destroy, );
|
|
|
|
|
|
|
|
if (pd->pat) cairo_pattern_destroy(pd->pat);
|
|
|
|
pd->pat = NULL;
|
|
|
|
|
|
|
|
eo_do_super(obj, ECTOR_RENDERER_CAIRO_GRADIENT_LINEAR_CLASS,
|
2015-04-03 07:23:16 -07:00
|
|
|
efl_gfx_gradient_stop_set(colors, length));
|
2015-04-03 07:21:54 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#include "ector_renderer_cairo_gradient_linear.eo.c"
|