Mercurial > MadButterfly
changeset 606:e21eb54c7d9c openvg
Implement radial gradient paint.
- Refactory linear gradient creation function to share code with
radial gradient creation function.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sun, 04 Jul 2010 16:31:39 +0800 |
parents | a8fa4c550fe5 |
children | 51dc49fd34a8 |
files | include/mb_graph_engine_openvg.h src/graph_engine_openvg.c |
diffstat | 2 files changed, 44 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/include/mb_graph_engine_openvg.h Sun Jul 04 15:39:12 2010 +0800 +++ b/include/mb_graph_engine_openvg.h Sun Jul 04 16:31:39 2010 +0800 @@ -19,9 +19,6 @@ #define mbe_image_surface_get_width(surface) (1) #define mbe_image_surface_get_data(surface) ((unsigned char *)NULL) #define mbe_scaled_font_reference(scaled) ((mbe_scaled_font_t *)NULL) -#define mbe_pattern_create_radial(cx0, cy0, radius0, \ - cx1, cy1, radius1, stops, stop_cnt) \ - ((mbe_pattern_t *)NULL) #define mbe_pattern_create_image(img) ((mbe_pattern_t *)NULL) #define mbe_scaled_font_destroy(scaled) #define mbe_font_face_reference(face) ((mbe_font_face_t *)NULL) @@ -136,6 +133,12 @@ extern EGLNativeDisplayType _ge_openvg_disp_id; extern mbe_t *_ge_openvg_current_canvas; +extern mbe_pattern_t *mbe_pattern_create_radial(co_aix cx0, co_aix cy0, + co_aix radius0, + co_aix cx1, co_aix cy1, + co_aix radius1, + grad_stop_t *stops, + int stop_cnt); extern mbe_pattern_t *mbe_pattern_create_linear(co_aix x0, co_aix y0, co_aix x1, co_aix y1, grad_stop_t *stops,
--- a/src/graph_engine_openvg.c Sun Jul 04 15:39:12 2010 +0800 +++ b/src/graph_engine_openvg.c Sun Jul 04 16:31:39 2010 +0800 @@ -13,13 +13,12 @@ (((int)(0xf * b) & 0xf) << 16) | \ ((int)(0xf * a) & 0xf)) -mbe_pattern_t * -mbe_pattern_create_linear(co_aix x0, co_aix y0, - co_aix x1, co_aix y1, - grad_stop_t *stops, int stop_cnt) { +static mbe_pattern_t * +_mbe_pattern_create_gradient(VGfloat *gradient, int grad_len, + int grad_type, + grad_stop_t *stops, int stop_cnt) { VGPaint paint; mbe_pattern_t *pattern; - VGfloat gradient[] = {x0, y0, x1, y1}; static VGfloat *ov_stops = 0; static int max_stop_cnt = 0; VGfloat *cur_ov_stop; @@ -51,8 +50,8 @@ paint = vgCreatePaint(); if(paint == VG_INVALID_HANDLE) return NULL; - vgSetParameteri(paint, VG_PAINT_TYPE, VG_PAINT_TYPE_LINEAR_GRADIENT); - vgSetParameterfv(paint, VG_PAINT_LINEAR_GRADIENT, 4, gradient); + vgSetParameteri(paint, VG_PAINT_TYPE, grad_type); + vgSetParameterfv(paint, VG_PAINT_RADIAL_GRADIENT, grad_len, gradient); vgSetParameterfv(paint, VG_PAINT_COLOR_RAMP_STOPS, 5 * stop_cnt, ov_stops); pattern = O_ALLOC(mbe_pattern_t); @@ -67,6 +66,38 @@ return pattern; } +/* + * \note OpenVG does not support start circle, it supports only focal + * point. It means radius0 is not working. + */ +mbe_pattern_t * +mbe_pattern_create_radial(co_aix cx0, co_aix cy0, + co_aix radius0, + co_aix cx1, co_aix cy1, + co_aix radius1, grad_stop_t *stops, + int stop_cnt) { + mbe_pattern_t *pattern; + VGfloat gradient[] = {cx0, cy0, cx1, cy1, radius1}; + + pattern = _mbe_pattern_create_gradient(gradient, 5, + VG_PAINT_TYPE_RADIAL_GRADIENT, + stops, stop_cnt); + return pattern; +} + +mbe_pattern_t * +mbe_pattern_create_linear(co_aix x0, co_aix y0, + co_aix x1, co_aix y1, + grad_stop_t *stops, int stop_cnt) { + mbe_pattern_t *pattern; + VGfloat gradient[] = {x0, y0, x1, y1}; + + pattern = _mbe_pattern_create_gradient(gradient, 4, + VG_PAINT_TYPE_LINEAR_GRADIENT, + stops, stop_cnt); + return pattern; +} + void mbe_set_source_rgba(mbe_t *canvas, co_comp_t r, co_comp_t g, co_comp_t b, co_comp_t a) {