comparison src/redraw_man.c @ 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
comparison
equal deleted inserted replaced
25:29937c26bb01 26:d50f33040de6
4 #include <cairo.h> 4 #include <cairo.h>
5 #include "mb_types.h" 5 #include "mb_types.h"
6 #include "shapes.h" 6 #include "shapes.h"
7 #include "tools.h" 7 #include "tools.h"
8 #include "redraw_man.h" 8 #include "redraw_man.h"
9
10 /* NOTE: bounding box should also consider width of stroke.
11 */
9 12
10 #define OK 0 13 #define OK 0
11 #define ERR -1 14 #define ERR -1
12 15
13 #define OFFSET(type, field) ((void *)&((type *)NULL)->field - (void *)NULL) 16 #define OFFSET(type, field) ((void *)&((type *)NULL)->field - (void *)NULL)
459 462
460 /* Drawing and Redrawing 463 /* Drawing and Redrawing
461 * ============================================================ 464 * ============================================================
462 */ 465 */
463 466
467 #ifndef UNITTEST
468 static void set_shape_stroke_param(shape_t *shape, cairo_t *cr) {
469 cairo_set_line_width(cr, shape->stroke_width);
470 }
471 #else
472 static void set_shape_stroke_param(shape_t *shape, cairo_t *cr) {
473 }
474 #endif
475
464 static void draw_shape(redraw_man_t *rdman, shape_t *shape) { 476 static void draw_shape(redraw_man_t *rdman, shape_t *shape) {
465 paint_t *fill, *stroke; 477 paint_t *fill, *stroke;
466 478
467 fill = shape->fill; 479 fill = shape->fill;
468 if(fill) { 480 if(fill) {
479 } 491 }
480 } 492 }
481 stroke = shape->stroke; 493 stroke = shape->stroke;
482 if(stroke) { 494 if(stroke) {
483 stroke->prepare(stroke, rdman->cr); 495 stroke->prepare(stroke, rdman->cr);
496 set_shape_stroke_param(shape, rdman->cr);
484 switch(shape->sh_type) { 497 switch(shape->sh_type) {
485 case SHT_PATH: 498 case SHT_PATH:
486 sh_path_stroke(shape, rdman->cr); 499 sh_path_stroke(shape, rdman->cr);
487 break; 500 break;
488 #ifdef UNITTEST 501 #ifdef UNITTEST
494 } 507 }
495 } 508 }
496 509
497 #ifndef UNITTEST 510 #ifndef UNITTEST
498 static void clean_canvas(cairo_t *cr) { 511 static void clean_canvas(cairo_t *cr) {
499 cairo_pattern_t *pt;
500
501 pt = cairo_get_source(cr);
502 cairo_pattern_reference(pt);
503 /* TODO: clean to background color. */ 512 /* TODO: clean to background color. */
504 cairo_set_source_rgb(cr, 0, 0, 0); 513 cairo_set_source_rgb(cr, 0, 0, 0);
505 cairo_paint(cr); 514 cairo_paint(cr);
506 cairo_set_source(cr, pt);
507 cairo_pattern_destroy(pt);
508 } 515 }
509 516
510 static void make_clip(cairo_t *cr, int n_dirty_areas, 517 static void make_clip(cairo_t *cr, int n_dirty_areas,
511 area_t **dirty_areas) { 518 area_t **dirty_areas) {
512 int i; 519 int i;