# HG changeset patch # User Thinker K.F. Li # Date 1217954404 -28800 # Node ID d82749f771088a1e6d09390e22e630a16077e663 # Parent 69c8e264890db7c151e179b8f79482c493bd2955 Fix bug of demo and remove *_fill() and *_stroke(). - logical error in X_main.c. diff -r 69c8e264890d -r d82749f77108 src/Makefile --- a/src/Makefile Tue Aug 05 18:28:50 2008 +0800 +++ b/src/Makefile Wed Aug 06 00:40:04 2008 +0800 @@ -1,5 +1,5 @@ -SRCS = coord.c geo.c shape_path.c shape_text.c redraw_man.c \ - paint.c event.c tools.c +SRCS = coord.c geo.c shape_path.c shape_text.c shape_rect.c \ + redraw_man.c paint.c event.c tools.c OBJS = ${SRCS:C/(.*)\.c/\1.o/g} TESTCASE_OBJS = ${SRCS:C/(.*)\.c/testcase-\1.o/g} CFLAGS+= -Wall -I/usr/local/include `pkg-config --cflags cairo` diff -r 69c8e264890d -r d82749f77108 src/X_main.c --- a/src/X_main.c Tue Aug 05 18:28:50 2008 +0800 +++ b/src/X_main.c Wed Aug 06 00:40:04 2008 +0800 @@ -16,7 +16,7 @@ void hint_shape(redraw_man_t *rdman, shape_t *shape) { static shape_t *last_shape = NULL; if(last_shape != shape) { - if(last_shape != NULL && last_shape != NULL) { + if(last_shape != NULL && last_shape->stroke != NULL) { last_shape->stroke_width -= 2; rdman_shape_changed(rdman, last_shape); } diff -r 69c8e264890d -r d82749f77108 src/redraw_man.c --- a/src/redraw_man.c Tue Aug 05 18:28:50 2008 +0800 +++ b/src/redraw_man.c Wed Aug 06 00:40:04 2008 +0800 @@ -528,23 +528,42 @@ static void set_shape_stroke_param(shape_t *shape, cairo_t *cr) { cairo_set_line_width(cr, shape->stroke_width); } + +static void fill_path_preserve(redraw_man_t *rdman) { + cairo_fill_preserve(rdman->cr); +} + +static void fill_path(redraw_man_t *rdman) { + cairo_fill(rdman->cr); +} + +static void stroke_path(redraw_man_t *rdman) { + cairo_stroke(rdman->cr); +} #else static void set_shape_stroke_param(shape_t *shape, cairo_t *cr) { } + +static void fill_path_preserve(redraw_man_t *rdman) { +} + +static void fill_path(redraw_man_t *rdman) { +} + +static void stroke_path(redraw_man_t *rdman) { +} #endif static void draw_shape(redraw_man_t *rdman, shape_t *shape) { paint_t *fill, *stroke; - fill = shape->fill; - if(fill) { - fill->prepare(fill, rdman->cr); + if(shape->fill || shape->stroke) { switch(shape->sh_type) { case SHT_PATH: - sh_path_fill(shape, rdman->cr); + sh_path_draw(shape, rdman->cr); break; case SHT_TEXT: - sh_text_fill(shape, rdman->cr); + sh_text_draw(shape, rdman->cr); break; #ifdef UNITTEST default: @@ -552,23 +571,21 @@ break; #endif /* UNITTEST */ } - } - stroke = shape->stroke; - if(stroke) { - stroke->prepare(stroke, rdman->cr); - set_shape_stroke_param(shape, rdman->cr); - switch(shape->sh_type) { - case SHT_PATH: - sh_path_stroke(shape, rdman->cr); - break; - case SHT_TEXT: - sh_text_stroke(shape, rdman->cr); - break; -#ifdef UNITTEST - default: - /* sh_dummy_fill(shape, rdman->cr); */ - break; -#endif /* UNITTEST */ + + fill = shape->fill; + if(shape->fill) { + fill->prepare(fill, rdman->cr); + if(shape->stroke) + fill_path_preserve(rdman); + else + fill_path(rdman); + } + + stroke = shape->stroke; + if(stroke) { + stroke->prepare(stroke, rdman->cr); + set_shape_stroke_param(shape, rdman->cr); + stroke_path(rdman); } } } diff -r 69c8e264890d -r d82749f77108 src/shape_path.c --- a/src/shape_path.c Tue Aug 05 18:28:50 2008 +0800 +++ b/src/shape_path.c Wed Aug 06 00:40:04 2008 +0800 @@ -548,16 +548,6 @@ sh_path_path(shape, cr); } -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 diff -r 69c8e264890d -r d82749f77108 src/shape_rect.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/shape_rect.c Wed Aug 06 00:40:04 2008 +0800 @@ -0,0 +1,10 @@ +#include +#include "mb_types.h" +#include "shapes.h" + +typedef struct _sh_rect { + shape_t shape; + co_aix x, y; + co_aix rx, ry; +} sh_rect_t; + diff -r 69c8e264890d -r d82749f77108 src/shape_text.c --- a/src/shape_text.c Tue Aug 05 18:28:50 2008 +0800 +++ b/src/shape_text.c Wed Aug 06 00:40:04 2008 +0800 @@ -137,17 +137,3 @@ draw_text((sh_text_t *)shape, cr); } -void sh_text_fill(shape_t *shape, cairo_t *cr) { - sh_text_t *text = (sh_text_t *)shape; - - draw_text(text, cr); - cairo_fill(cr); -} - - -void sh_text_stroke(shape_t *shape, cairo_t *cr) { - sh_text_t *text = (sh_text_t *)shape; - - draw_text(text, cr); - cairo_stroke(cr); -} diff -r 69c8e264890d -r d82749f77108 src/shapes.h --- a/src/shapes.h Tue Aug 05 18:28:50 2008 +0800 +++ b/src/shapes.h Wed Aug 06 00:40:04 2008 +0800 @@ -10,19 +10,14 @@ * - *_new() and *_free() * - *_transform() * - *_draw() - * - *_fill() - * - *_stroke() * - struct of shape must include an shape_t as type of first member. */ -/* TODO: remove *_fill() and *_stroke() */ extern void sh_path_free(shape_t *path); extern shape_t *sh_path_new(char *data); extern void sh_path_transform(shape_t *shape); extern void sh_path_draw(shape_t *shape, cairo_t *cr); -extern void sh_path_fill(shape_t *shape, cairo_t *cr); -extern void sh_path_stroke(shape_t *shape, cairo_t *cr); extern void sh_text_free(shape_t *text); @@ -30,8 +25,6 @@ co_aix font_size, cairo_font_face_t *face); extern void sh_text_transform(shape_t *shape); extern void sh_text_draw(shape_t *shape, cairo_t *cr); -extern void sh_text_fill(shape_t *shape, cairo_t *cr); -extern void sh_text_stroke(shape_t *shape, cairo_t *cr); #endif /* __SHAPES_H_ */