Mercurial > MadButterfly
comparison src/redraw_man.c @ 192:54fdc2a65242
Remove factory from observer APIs.
- Save factory that used to new a subject as subject's attribute.
- Get factory from subject himself instead of passing as an argument.
- It make API of observer more simple and clean.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Tue, 18 Nov 2008 21:42:30 +0800 |
parents | 257af0ed5852 |
children | 45d9a1e2764d |
comparison
equal
deleted
inserted
replaced
191:18f8c3126cdb | 192:54fdc2a65242 |
---|---|
443 | 443 |
444 if(geo != NULL) { | 444 if(geo != NULL) { |
445 geo_detach_coord(geo, shape->coord); | 445 geo_detach_coord(geo, shape->coord); |
446 sh_detach_coord(shape); | 446 sh_detach_coord(shape); |
447 sh_detach_geo(shape); | 447 sh_detach_geo(shape); |
448 subject_free(&rdman->ob_factory, geo->mouse_event); | 448 subject_free(geo->mouse_event); |
449 elmpool_elm_free(rdman->geo_pool, geo); | 449 elmpool_elm_free(rdman->geo_pool, geo); |
450 } | 450 } |
451 STAILQ_REMOVE(rdman->shapes, shape_t, sh_next, shape); | 451 STAILQ_REMOVE(rdman->shapes, shape_t, sh_next, shape); |
452 shape->free(shape); | 452 shape->free(shape); |
453 return OK; | 453 return OK; |
545 add_dirty_coord(rdman, coord); | 545 add_dirty_coord(rdman, coord); |
546 | 546 |
547 return coord; | 547 return coord; |
548 } | 548 } |
549 | 549 |
550 static int rdman_coord_free_postponse(redraw_man_t *rdman, coord_t *coord) { | |
551 int r; | |
552 | |
553 if(coord->flags & COF_FREE) | |
554 return ERR; | |
555 | |
556 coord->flags |= COF_FREE; | |
557 coord_hide(coord); | |
558 if(!(coord->flags & COF_DIRTY)) { | |
559 r = add_dirty_coord(rdman, coord); | |
560 if(r != OK) | |
561 return ERR; | |
562 } | |
563 r = add_free_obj(rdman, coord, (free_func_t)rdman_coord_free); | |
564 if(r != OK) | |
565 return ERR; | |
566 return OK; | |
567 } | |
568 | |
550 /*! \brief Free a coord of a redraw_man_t object. | 569 /*! \brief Free a coord of a redraw_man_t object. |
570 * | |
571 * All children and members should be freed before parent being freed. | |
551 * | 572 * |
552 * \param coord is a coord_t without children and members. | 573 * \param coord is a coord_t without children and members. |
553 * \return 0 for successful, -1 for error. | 574 * \return 0 for successful, -1 for error. |
554 * | 575 * |
555 * \note Removing coords when the rdman is dirty, the removing is postponsed. | 576 * \note Free is postponsed if the coord is dirty or it has children |
577 * or members postponsed for free. | |
556 */ | 578 */ |
557 int rdman_coord_free(redraw_man_t *rdman, coord_t *coord) { | 579 int rdman_coord_free(redraw_man_t *rdman, coord_t *coord) { |
558 coord_t *parent; | 580 coord_t *parent; |
559 coord_t *child; | 581 coord_t *child; |
560 geo_t *member; | 582 geo_t *member; |
561 int r; | 583 int cm_cnt; /* children & members counter */ |
562 | 584 |
563 parent = coord->parent; | 585 parent = coord->parent; |
564 if(parent == NULL) | 586 if(parent == NULL) |
565 return ERR; | 587 return ERR; |
566 | 588 |
567 if(rdman_is_dirty(rdman)) { | 589 cm_cnt = 0; |
568 if(coord->flags & COF_FREE) | 590 FORCHILDREN(coord, child) { |
591 cm_cnt++; | |
592 if(!(child->flags & COF_FREE)) | |
569 return ERR; | 593 return ERR; |
570 | 594 } |
571 FORCHILDREN(coord, child) { | 595 FORMEMBERS(coord, member) { |
572 if(!(child->flags & COF_FREE)) | 596 cm_cnt++; |
573 return ERR; | 597 if(!(member->flags & GEF_FREE)) |
574 } | |
575 FORMEMBERS(coord, member) { | |
576 if(!(member->flags & GEF_FREE)) | |
577 return ERR; | |
578 } | |
579 coord->flags |= COF_FREE; | |
580 coord_hide(coord); | |
581 if(!(coord->flags & COF_DIRTY)) { | |
582 r = add_dirty_coord(rdman, coord); | |
583 if(r != OK) | |
584 return ERR; | |
585 } | |
586 r = add_free_obj(rdman, coord, (free_func_t)rdman_coord_free); | |
587 if(r != OK) | |
588 return ERR; | 598 return ERR; |
589 return OK; | 599 } |
590 } | 600 |
591 | 601 if(cm_cnt || rdman_is_dirty(rdman)) |
592 if(FIRST_MEMBER(coord) != NULL) | 602 return rdman_coord_free_postponse(rdman, coord); |
593 return ERR; | |
594 | |
595 if(FIRST_CHILD(coord) != NULL) | |
596 return ERR; | |
597 | 603 |
598 /* Free canvas (\ref redraw) */ | 604 /* Free canvas (\ref redraw) */ |
599 if(coord->flags & COF_OWN_CANVAS) | 605 if(coord->flags & COF_OWN_CANVAS) |
600 free_canvas(coord->canvas); | 606 free_canvas(coord->canvas); |
601 | 607 |
602 RM_CHILD(parent, coord); | 608 RM_CHILD(parent, coord); |
603 subject_free(&rdman->ob_factory, coord->mouse_event); | 609 subject_free(coord->mouse_event); |
604 elmpool_elm_free(rdman->coord_pool, coord); | 610 elmpool_elm_free(rdman->coord_pool, coord); |
605 rdman->n_coords--; | 611 rdman->n_coords--; |
606 | 612 |
607 return OK; | 613 return OK; |
608 } | 614 } |
1116 int rdman_redraw_changed(redraw_man_t *rdman) { | 1122 int rdman_redraw_changed(redraw_man_t *rdman) { |
1117 int r; | 1123 int r; |
1118 int n_dirty_areas; | 1124 int n_dirty_areas; |
1119 area_t **dirty_areas; | 1125 area_t **dirty_areas; |
1120 event_t event; | 1126 event_t event; |
1121 ob_factory_t *factory; | |
1122 subject_t *redraw; | 1127 subject_t *redraw; |
1123 | 1128 |
1124 r = clean_rdman_dirties(rdman); | 1129 r = clean_rdman_dirties(rdman); |
1125 if(r != OK) | 1130 if(r != OK) |
1126 return ERR; | 1131 return ERR; |
1140 rdman->dirty_areas.num = 0; | 1145 rdman->dirty_areas.num = 0; |
1141 | 1146 |
1142 /* Free postponsed removing */ | 1147 /* Free postponsed removing */ |
1143 free_free_objs(rdman); | 1148 free_free_objs(rdman); |
1144 | 1149 |
1145 factory = rdman_get_ob_factory(rdman); | |
1146 redraw = rdman_get_redraw_subject(rdman); | 1150 redraw = rdman_get_redraw_subject(rdman); |
1147 event.type = EVT_RDMAN_REDRAW; | 1151 event.type = EVT_RDMAN_REDRAW; |
1148 event.tgt = event.cur_tgt = redraw; | 1152 event.tgt = event.cur_tgt = redraw; |
1149 subject_notify(factory, redraw, &event); | 1153 subject_notify(redraw, &event); |
1150 | 1154 |
1151 return OK; | 1155 return OK; |
1152 } | 1156 } |
1153 | 1157 |
1154 /* NOTE: Before redrawing, the canvas/surface must be cleaned. | 1158 /* NOTE: Before redrawing, the canvas/surface must be cleaned. |