changeset 33:d82749f77108

Fix bug of demo and remove *_fill() and *_stroke(). - logical error in X_main.c.
author Thinker K.F. Li <thinker@branda.to>
date Wed, 06 Aug 2008 00:40:04 +0800
parents 69c8e264890d
children 07c523c799f4
files src/Makefile src/X_main.c src/redraw_man.c src/shape_path.c src/shape_rect.c src/shape_text.c src/shapes.h
diffstat 7 files changed, 52 insertions(+), 56 deletions(-) [+]
line wrap: on
line diff
--- 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`
--- 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);
 	}
--- 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);
 	}
     }
 }
--- 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 <CUnit/Basic.h>
--- /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 <stdio.h>
+#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;
+
--- 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);
-}
--- 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_ */