Mercurial > MadButterfly
changeset 480:e813ac222f48 Android_Skia
Merge add colors into constructor of gradient pattern.
Since we also define color stops for gradient pattern and rear change
it, mbe_pattern_add_color_stop_rgba() is merged into
mb_pattern_create_radial() and mb_pattern_create_linear(). It also
makes porting to graphic engines easier.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sun, 15 Nov 2009 16:21:09 +0800 |
parents | 9a867333018b |
children | 273307d061b7 |
files | include/mb_basic_types.h include/mb_graph_engine_cairo.h include/mb_paint.h src/graph_engine_cairo.c src/paint.c |
diffstat | 5 files changed, 72 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/include/mb_basic_types.h Sun Nov 15 16:21:09 2009 +0800 @@ -0,0 +1,11 @@ +#ifndef __MB_BASIC_TYPES_H_ +#define __MB_BASIC_TYPES_H_ + +typedef float co_aix; +typedef float co_comp_t; +typedef struct _grad_stop { + co_aix offset; + co_comp_t r, g, b, a; +} grad_stop_t; + +#endif /* __MB_BASIC_TYPES_H_ */
--- a/include/mb_graph_engine_cairo.h Sun Nov 15 16:21:09 2009 +0800 +++ b/include/mb_graph_engine_cairo.h Sun Nov 15 16:21:09 2009 +0800 @@ -4,6 +4,7 @@ #include <stdio.h> #include <cairo.h> #include <cairo-xlib.h> +#include "mb_basic_types.h" #include "mb_img_ldr.h" /*! \defgroup mb_ge_cairo MadButterfly Graphic Engine with Cairo @@ -14,7 +15,6 @@ #define MBE_STATUS_SUCCESS CAIRO_STATUS_SUCCESS #define mbe_image_surface_create_from_png cairo_image_surface_create_from_png -#define mbe_pattern_add_color_stop_rgba cairo_pattern_add_color_stop_rgba #define mbe_pattern_create_for_surface cairo_pattern_create_for_surface #define mbe_scaled_font_text_extents cairo_scaled_font_text_extents #define mbe_image_surface_get_stride cairo_image_surface_get_stride @@ -22,8 +22,6 @@ #define mbe_image_surface_get_width cairo_image_surface_get_width #define mbe_image_surface_get_data cairo_image_surface_get_data #define mbe_scaled_font_reference cairo_scaled_font_reference -#define mbe_pattern_create_radial cairo_pattern_create_radial -#define mbe_pattern_create_linear cairo_pattern_create_linear #define mbe_xlib_surface_create cairo_xlib_surface_create #define mbe_scaled_font_destroy cairo_scaled_font_destroy #define mbe_font_face_reference cairo_font_face_reference @@ -65,7 +63,6 @@ typedef cairo_surface_t mbe_surface_t; typedef cairo_pattern_t mbe_pattern_t; typedef cairo_t mbe_t; -typedef float co_aix; #define MB_MATRIX_2_CAIRO(cmtx, mtx) { \ (cmtx).xx = (mtx)[0]; \ @@ -77,10 +74,19 @@ } - extern mbe_font_face_t * mbe_query_font_face(const char *family, int slant, int weight); extern void mbe_free_font_face(mbe_font_face_t *face); +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, + int stop_cnt); static void mbe_pattern_set_matrix(mbe_pattern_t *ptn,
--- a/include/mb_paint.h Sun Nov 15 16:21:09 2009 +0800 +++ b/include/mb_paint.h Sun Nov 15 16:21:09 2009 +0800 @@ -7,8 +7,6 @@ #include "mb_img_ldr.h" #include "mb_tools.h" -typedef float co_comp_t; - extern paint_t *rdman_paint_color_new(redraw_man_t *rdman, co_comp_t r, co_comp_t g, co_comp_t b, co_comp_t a); @@ -30,11 +28,6 @@ #define paint_destroy(_paint) -typedef struct _grad_stop { - co_aix offset; - co_comp_t r, g, b, a; -} grad_stop_t; - extern paint_t *rdman_paint_linear_new(redraw_man_t *rdman, co_aix x1, co_aix y1, co_aix x2, co_aix y2);
--- a/src/graph_engine_cairo.c Sun Nov 15 16:21:09 2009 +0800 +++ b/src/graph_engine_cairo.c Sun Nov 15 16:21:09 2009 +0800 @@ -1,4 +1,5 @@ #include <fontconfig/fontconfig.h> +#include <cairo-ft.h> #include "mb_graph_engine_cairo.h" #include "mb_shapes.h" @@ -108,3 +109,46 @@ mbe_font_face_destroy(face); } +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) { + cairo_pattern_t *ptn; + grad_stop_t *stop; + int i; + + ptn = cairo_pattern_create_radial(cx0, cy0, radius0, + cx1, cy1, radius1); + if(ptn == NULL) + return NULL; + + stop = stops; + for(i = 0; i < stop_cnt; i++) { + cairo_pattern_add_color_stop_rgba(ptn, stop->offset, + stop->r, stop->g, stop->b, stop->a); + stop++; + } + + return ptn; +} + +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) { + cairo_pattern_t *ptn; + grad_stop_t *stop; + int i; + + ptn = cairo_pattern_create_linear(x0, y0, x1, y1); + if(ptn == NULL) + return NULL; + + stop = stops; + for(i = 0; i < stop_cnt; i++) { + cairo_pattern_add_color_stop_rgba(ptn, stop->offset, + stop->r, stop->g, stop->b, stop->a); + stop++; + } + + return ptn; +}
--- a/src/paint.c Sun Nov 15 16:21:09 2009 +0800 +++ b/src/paint.c Sun Nov 15 16:21:09 2009 +0800 @@ -92,13 +92,9 @@ mbe_pattern_destroy(ptn); linear->flags &= ~LIF_DIRTY; ptn = mbe_pattern_create_linear(linear->x1, linear->y1, - linear->x2, linear->y2); - for(i = 0; i < linear->n_stops; i++) { - stop = &linear->stops[i]; - mbe_pattern_add_color_stop_rgba(ptn, stop->offset, - stop->r, stop->g, stop->b, - stop->a); - } + linear->x2, linear->y2, + linear->stops, linear->n_stops); + ASSERT(ptn != NULL); linear->ptn = ptn; } @@ -177,20 +173,15 @@ static void paint_radial_prepare(paint_t *paint, mbe_t *cr) { paint_radial_t *radial = (paint_radial_t *)paint; mbe_pattern_t *ptn; - grad_stop_t *stop; int i; if(radial->flags & RDF_DIRTY) { ptn = mbe_pattern_create_radial(radial->cx, radial->cy, 0, radial->cx, radial->cy, - radial->r); + radial->r, + radial->stops, + radial->n_stops); ASSERT(ptn != NULL); - stop = radial->stops; - for(i = 0; i < radial->n_stops; i++, stop++) { - mbe_pattern_add_color_stop_rgba(ptn, stop->offset, - stop->r, stop->g, - stop->b, stop->a); - } mbe_pattern_destroy(radial->ptn); radial->ptn = ptn; }