# HG changeset patch # User Thinker K.F. Li # Date 1217739895 -28800 # Node ID d50f33040de689e72a9359ea6b015805255a3dc3 # Parent 29937c26bb0117a25dabb0b112ad9acdbe310544 Set line width for path. - consider width of line when compute bounding box area. diff -r 29937c26bb01 -r d50f33040de6 src/X_main.c --- 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); diff -r 29937c26bb01 -r d50f33040de6 src/mb_types.h --- 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 }; diff -r 29937c26bb01 -r d50f33040de6 src/redraw_man.c --- 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, diff -r 29937c26bb01 -r d50f33040de6 src/shape_path.c --- 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; } }