comparison src/redraw_man.c @ 18:0f3baa488a62

Support solid color paint for fill.
author Thinker K.F. Li <thinker@branda.to>
date Sat, 02 Aug 2008 14:45:42 +0800
parents 41f0907b27ac
children cf6d65398619
comparison
equal deleted inserted replaced
17:41f0907b27ac 18:0f3baa488a62
194 if(rdman->coord_pool == NULL) { 194 if(rdman->coord_pool == NULL) {
195 elmpool_free(rdman->geo_pool); 195 elmpool_free(rdman->geo_pool);
196 return ERR; 196 return ERR;
197 } 197 }
198 198
199 rdman->shnode_pool = elmpool_new(sizeof(shnode_t), 16);
200 if(rdman->shnode_pool == NULL) {
201 elmpool_free(rdman->geo_pool);
202 elmpool_free(rdman->coord_pool);
203 return ERR;
204 }
205
199 rdman->root_coord = elmpool_elm_alloc(rdman->coord_pool); 206 rdman->root_coord = elmpool_elm_alloc(rdman->coord_pool);
200 if(rdman->root_coord == NULL) 207 if(rdman->root_coord == NULL)
201 redraw_man_destroy(rdman); 208 redraw_man_destroy(rdman);
202 rdman->n_coords = 1; 209 rdman->n_coords = 1;
203 coord_init(rdman->root_coord, NULL); 210 coord_init(rdman->root_coord, NULL);
208 } 215 }
209 216
210 void redraw_man_destroy(redraw_man_t *rdman) { 217 void redraw_man_destroy(redraw_man_t *rdman) {
211 elmpool_free(rdman->coord_pool); 218 elmpool_free(rdman->coord_pool);
212 elmpool_free(rdman->geo_pool); 219 elmpool_free(rdman->geo_pool);
220 elmpool_free(rdman->shnode_pool);
213 if(rdman->dirty_coords) 221 if(rdman->dirty_coords)
214 free(rdman->dirty_coords); 222 free(rdman->dirty_coords);
215 if(rdman->dirty_geos) 223 if(rdman->dirty_geos)
216 free(rdman->dirty_geos); 224 free(rdman->dirty_geos);
217 } 225 }
420 } 428 }
421 429
422 return OK; 430 return OK;
423 } 431 }
424 432
433 static int _rdman_shape_changed(redraw_man_t *rdman, shape_t *shape) {
434 geo_t *geo;
435 int r;
436
437 geo = shape->geo;
438
439 if(geo->flags & GEF_DIRTY)
440 return OK;
441
442 r = add_dirty_geo(rdman, geo);
443 if(r == ERR)
444 return ERR;
445 geo->flags |= GEF_DIRTY;
446
447 return OK;
448 }
449
425 /*! \brief Mark a shape is changed. 450 /*! \brief Mark a shape is changed.
426 * 451 *
427 * The geo_t object of a changed shape is mark as dirty and 452 * The geo_t object of a changed shape is mark as dirty and
428 * put into dirty_geos list. 453 * put into dirty_geos list.
429 */ 454 */
430 int rdman_shape_changed(redraw_man_t *rdman, shape_t *shape) { 455 int rdman_shape_changed(redraw_man_t *rdman, shape_t *shape) {
431 geo_t *geo; 456 return _rdman_shape_changed(rdman, shape);
432 int r;
433
434 geo = shape->geo;
435
436 if(geo->flags & GEF_DIRTY)
437 return OK;
438
439 r = add_dirty_geo(rdman, geo);
440 if(r == ERR)
441 return ERR;
442 geo->flags |= GEF_DIRTY;
443
444 return OK;
445 } 457 }
446 458
447 /* Drawing and Redrawing 459 /* Drawing and Redrawing
448 * ============================================================ 460 * ============================================================
449 */ 461 */
450 462
451 static void draw_shape(redraw_man_t *rdman, shape_t *shape) { 463 static void draw_shape(redraw_man_t *rdman, shape_t *shape) {
464 paint_t *fill;
465
466 fill = shape->fill;
467 if(fill)
468 fill->prepare(fill, rdman->cr);
452 switch(shape->sh_type) { 469 switch(shape->sh_type) {
453 case SHT_PATH: 470 case SHT_PATH:
454 sh_path_draw(shape, rdman->cr); 471 sh_path_draw(shape, rdman->cr);
455 break; 472 break;
456 #ifdef UNITTEST 473 #ifdef UNITTEST
606 if(geo->flags & GEF_DIRTY) 623 if(geo->flags & GEF_DIRTY)
607 clean_shape(geo->shape); 624 clean_shape(geo->shape);
608 draw_shape(rdman, geo->shape); 625 draw_shape(rdman, geo->shape);
609 } 626 }
610 627
628 return OK;
629 }
630
631 shnode_t *shnode_new(redraw_man_t *rdman, shape_t *shape) {
632 shnode_t *node;
633
634 node = (shnode_t *)elmpool_elm_alloc(rdman->shnode_pool);
635 if(node) {
636 node->shape = shape;
637 node->next = NULL;
638 }
639 return node;
640 }
641
642 int rdman_paint_changed(redraw_man_t *rdman, paint_t *paint) {
643 shnode_t *node;
644 int r;
645
646 for(node = STAILQ_HEAD(paint->members);
647 node != NULL;
648 node = STAILQ_NEXT(shnode_t, next, node)) {
649 r = _rdman_shape_changed(rdman, node->shape);
650 if(r != OK)
651 return ERR;
652 }
611 return OK; 653 return OK;
612 } 654 }
613 655
614 /* 656 /*
615 * Dirty of geo 657 * Dirty of geo