changeset 26:d50f33040de6

Set line width for path. - consider width of line when compute bounding box area.
author Thinker K.F. Li <thinker@branda.to>
date Sun, 03 Aug 2008 13:04:55 +0800
parents 29937c26bb01
children 19c603dd6ff9
files src/X_main.c src/mb_types.h src/redraw_man.c src/shape_path.c
diffstat 4 files changed, 43 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/X_main.c	Sun Aug 03 02:19:32 2008 +0800
+++ b/src/X_main.c	Sun Aug 03 13:04:55 2008 +0800
@@ -70,6 +70,8 @@
 
     for(i = 0; i < 50; i++) {
 	usleep(20000);
+	path1->stroke_width = i / 10;
+	path2->stroke_width = i / 10;
 	coord1->matrix[2] += 1;
 	coord1->matrix[5] += 1;
 	coord2->matrix[2] -= 1;
@@ -94,6 +96,25 @@
 	XFlush(display);
     }
 
+    for(i = 0; i < 4; i++) {
+	usleep(500000);
+	path1->stroke_width -= 1;
+	path2->stroke_width -= 1;
+	rdman_shape_changed(&rdman, path1);
+	rdman_shape_changed(&rdman, path2);
+	rdman_redraw_changed(&rdman);
+	XFlush(display);
+    }
+    for(i = 0; i < 4; i++) {
+	usleep(500000);
+	path1->stroke_width += 1;
+	path2->stroke_width += 1;
+	rdman_shape_changed(&rdman, path1);
+	rdman_shape_changed(&rdman, path2);
+	rdman_redraw_changed(&rdman);
+	XFlush(display);
+    }
+
     fill1->free(fill1);
     fill2->free(fill2);
     redraw_man_destroy(&rdman);
--- a/src/mb_types.h	Sun Aug 03 02:19:32 2008 +0800
+++ b/src/mb_types.h	Sun Aug 03 13:04:55 2008 +0800
@@ -111,6 +111,9 @@
     coord_t *coord;
     shape_t *coord_mem_next;
     paint_t *fill, *stroke;
+    co_aix stroke_width;
+    int stroke_linecap;
+    int stroke_linejoin;
 };
 enum { SHT_UNKNOW, SHT_PATH, SHT_TEXT };
 
--- a/src/redraw_man.c	Sun Aug 03 02:19:32 2008 +0800
+++ b/src/redraw_man.c	Sun Aug 03 13:04:55 2008 +0800
@@ -7,6 +7,9 @@
 #include "tools.h"
 #include "redraw_man.h"
 
+/* NOTE: bounding box should also consider width of stroke.
+ */
+
 #define OK 0
 #define ERR -1
 
@@ -461,6 +464,15 @@
  * ============================================================
  */
 
+#ifndef UNITTEST
+static void set_shape_stroke_param(shape_t *shape, cairo_t *cr) {
+    cairo_set_line_width(cr, shape->stroke_width);
+}
+#else
+static void set_shape_stroke_param(shape_t *shape, cairo_t *cr) {
+}
+#endif
+
 static void draw_shape(redraw_man_t *rdman, shape_t *shape) {
     paint_t *fill, *stroke;
 
@@ -481,6 +493,7 @@
     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);
@@ -496,15 +509,9 @@
 
 #ifndef UNITTEST
 static void clean_canvas(cairo_t *cr) {
-    cairo_pattern_t *pt;
-
-    pt = cairo_get_source(cr);
-    cairo_pattern_reference(pt);
     /* TODO: clean to background color. */
     cairo_set_source_rgb(cr, 0, 0, 0);
     cairo_paint(cr);
-    cairo_set_source(cr, pt);
-    cairo_pattern_destroy(pt);
 }
 
 static void make_clip(cairo_t *cr, int n_dirty_areas,
--- a/src/shape_path.c	Sun Aug 03 02:19:32 2008 +0800
+++ b/src/shape_path.c	Sun Aug 03 13:04:55 2008 +0800
@@ -394,6 +394,7 @@
     sh_path_t *path;
     co_aix *user_args, *dev_args;
     co_aix (*poses)[2];
+    area_t *area;
     int arg_len;
     int i;
 
@@ -414,6 +415,11 @@
     if(path->shape.geo) {
 	poses = (co_aix (*)[2])(path->dev_data + path->cmd_len);
 	geo_from_positions(path->shape.geo, arg_len / 2, poses);
+	area = shape->geo->cur_area;
+	area->x -= shape->stroke_width/2 + 1;
+	area->y -= shape->stroke_width/2 + 1;
+	area->w += shape->stroke_width + 2;
+	area->h += shape->stroke_width + 2;
     }
 }