Mercurial > MadButterfly
changeset 22:8fcf2d878ecd
shapes with stroke
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sat, 02 Aug 2008 16:20:15 +0800 |
parents | 83d24300a992 |
children | 56f592f56ff7 |
files | src/X_main.c src/redraw_man.c src/redraw_man.h src/shape_path.c src/shapes.h |
diffstat | 5 files changed, 44 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/src/X_main.c Sat Aug 02 16:06:53 2008 +0800 +++ b/src/X_main.c Sat Aug 02 16:20:15 2008 +0800 @@ -17,6 +17,7 @@ shape_t *path1, *path2; coord_t *coord1, *coord2; paint_t *fill1, *fill2; + paint_t *stroke; int i; redraw_man_init(&rdman, cr); @@ -25,8 +26,10 @@ fill1 = paint_color_new(&rdman, 1, 1, 0, 0.5); fill2 = paint_color_new(&rdman, 0, 1, 1, 0.5); + stroke = paint_color_new(&rdman, 0.4, 0.4, 0.4, 1); path1 = sh_path_new("M 22,89.36218 C -34,-0.63782 39,-9.637817 82,12.36218 C 125,34.36218 142,136.36218 142,136.36218 C 100.66667,125.36218 74.26756,123.42795 22,89.36218 z "); rdman_paint_fill(&rdman, fill1, path1); + rdman_paint_stroke(&rdman, stroke, path1); coord1->matrix[0] = 0.8; coord1->matrix[1] = 0; coord1->matrix[2] = 20; @@ -34,6 +37,7 @@ coord1->matrix[5] = 20; path2 = sh_path_new("M 22,89.36218 C -34,-0.63782 39,-9.637817 82,12.36218 C 125,34.36218 142,136.36218 142,136.36218 C 100.66667,125.36218 74.26756,123.42795 22,89.36218 z "); rdman_paint_fill(&rdman, fill2, path2); + rdman_paint_stroke(&rdman, stroke, path2); coord2->matrix[0] = -0.8; coord2->matrix[1] = 0; coord2->matrix[2] = 180;
--- a/src/redraw_man.c Sat Aug 02 16:06:53 2008 +0800 +++ b/src/redraw_man.c Sat Aug 02 16:20:15 2008 +0800 @@ -460,8 +460,8 @@ * ============================================================ */ -static void fill_shape(redraw_man_t *rdman, shape_t *shape) { - paint_t *fill; +static void draw_shape(redraw_man_t *rdman, shape_t *shape) { + paint_t *fill, *stroke; fill = shape->fill; if(fill) { @@ -477,6 +477,20 @@ #endif /* UNITTEST */ } } + stroke = shape->stroke; + if(stroke) { + stroke->prepare(stroke, rdman->cr); + switch(shape->sh_type) { + case SHT_PATH: + sh_path_stroke(shape, rdman->cr); + break; +#ifdef UNITTEST + default: + /* sh_dummy_fill(shape, rdman->cr); */ + break; +#endif /* UNITTEST */ + } + } } #ifndef UNITTEST @@ -520,7 +534,7 @@ } #endif /* UNITTEST */ -static void fill_shapes_in_areas(redraw_man_t *rdman, +static void draw_shapes_in_areas(redraw_man_t *rdman, int n_areas, area_t **areas) { geo_t *visit_geo; @@ -533,7 +547,7 @@ clean_shape(visit_geo->shape); for(i = 0; i < n_areas; i++) { if(is_overlay(visit_geo->cur_area, areas[i])) { - fill_shape(rdman, visit_geo->shape); + draw_shape(rdman, visit_geo->shape); break; } } @@ -603,7 +617,7 @@ dirty_areas = rdman->dirty_areas; if(n_dirty_areas > 0) { make_clip(rdman, n_dirty_areas, dirty_areas); - fill_shapes_in_areas(rdman, n_dirty_areas, dirty_areas); + draw_shapes_in_areas(rdman, n_dirty_areas, dirty_areas); rdman->n_dirty_areas = 0; reset_clip(rdman); } @@ -623,7 +637,7 @@ geo = STAILQ_NEXT(geo_t, next, geo)) { if(geo->flags & GEF_DIRTY) clean_shape(geo->shape); - fill_shape(rdman, geo->shape); + draw_shape(rdman, geo->shape); } return OK;
--- a/src/redraw_man.h Sat Aug 02 16:06:53 2008 +0800 +++ b/src/redraw_man.h Sat Aug 02 16:20:15 2008 +0800 @@ -79,7 +79,7 @@ } \ shnode_free(rdman, __last); \ } while(0) -#define rdman_paint_fill(rdman, paint, shape) \ +#define _rdman_paint_child(rdman, paint, shape) \ do { \ shnode_t *__node; \ if((shape)->fill != (paint) && \ @@ -88,8 +88,17 @@ STAILQ_INS_TAIL((paint)->members, \ shnode_t, next, __node); \ } \ + } while(0) +#define rdman_paint_fill(rdman, paint, shape) \ + do { \ + _rdman_paint_child(rdman, paint, shape); \ shape->fill = paint; \ } while(0) +#define rdman_paint_stroke(rdman, paint, shape) \ + do { \ + _rdman_paint_child(rdman, paint, shape); \ + shape->stroke = paint; \ + } while(0) extern int rdman_paint_changed(redraw_man_t *rdman, paint_t *paint);
--- a/src/shape_path.c Sat Aug 02 16:06:53 2008 +0800 +++ b/src/shape_path.c Sat Aug 02 16:20:15 2008 +0800 @@ -417,7 +417,7 @@ } } -void sh_path_fill(shape_t *shape, cairo_t *cr) { +static void sh_path_path(shape_t *shape, cairo_t *cr) { sh_path_t *path; int cmd_len; char *cmds, cmd; @@ -536,10 +536,18 @@ break; } } +} +void sh_path_fill(shape_t *shape, cairo_t *cr) { + sh_path_path(shape, cr); cairo_fill(cr); } +void sh_path_stroke(shape_t *shape, cairo_t *cr) { + sh_path_path(shape, cr); + cairo_stroke(cr); +} + #ifdef UNITTEST #include <CUnit/Basic.h>
--- a/src/shapes.h Sat Aug 02 16:06:53 2008 +0800 +++ b/src/shapes.h Sat Aug 02 16:20:15 2008 +0800 @@ -8,5 +8,6 @@ extern shape_t *sh_path_new(char *data); extern void sh_path_transform(shape_t *shape); extern void sh_path_fill(shape_t *shape, cairo_t *cr); +extern void sh_path_stroke(shape_t *shape, cairo_t *cr); #endif /* __SHAPES_H_ */