Mercurial > MadButterfly
comparison src/redraw_man.c @ 19:cf6d65398619
More animation demo
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sat, 02 Aug 2008 15:38:54 +0800 |
parents | 0f3baa488a62 |
children | 74d3d5dc9aaa |
comparison
equal
deleted
inserted
replaced
18:0f3baa488a62 | 19:cf6d65398619 |
---|---|
462 | 462 |
463 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; | 464 paint_t *fill; |
465 | 465 |
466 fill = shape->fill; | 466 fill = shape->fill; |
467 if(fill) | 467 if(fill) { |
468 fill->prepare(fill, rdman->cr); | 468 fill->prepare(fill, rdman->cr); |
469 switch(shape->sh_type) { | 469 switch(shape->sh_type) { |
470 case SHT_PATH: | 470 case SHT_PATH: |
471 sh_path_draw(shape, rdman->cr); | 471 sh_path_draw(shape, rdman->cr); |
472 break; | 472 break; |
473 #ifdef UNITTEST | 473 #ifdef UNITTEST |
474 default: | 474 default: |
475 sh_dummy_draw(shape, rdman->cr); | 475 sh_dummy_draw(shape, rdman->cr); |
476 break; | 476 break; |
477 #endif /* UNITTEST */ | 477 #endif /* UNITTEST */ |
478 } | |
478 } | 479 } |
479 } | 480 } |
480 | 481 |
481 #ifndef UNITTEST | 482 #ifndef UNITTEST |
482 static void clean_clip(cairo_t *cr) { | 483 static void clean_clip(cairo_t *cr) { |
717 */ | 718 */ |
718 | 719 |
719 #ifdef UNITTEST | 720 #ifdef UNITTEST |
720 | 721 |
721 #include <CUnit/Basic.h> | 722 #include <CUnit/Basic.h> |
723 #include "paint.h" | |
722 | 724 |
723 struct _sh_dummy { | 725 struct _sh_dummy { |
724 shape_t shape; | 726 shape_t shape; |
725 co_aix x, y; | 727 co_aix x, y; |
726 co_aix w, h; | 728 co_aix w, h; |
777 | 779 |
778 dummy = (sh_dummy_t *)shape; | 780 dummy = (sh_dummy_t *)shape; |
779 dummy->draw_cnt++; | 781 dummy->draw_cnt++; |
780 } | 782 } |
781 | 783 |
784 static void dummy_paint_prepare(paint_t *paint, cairo_t *cr) { | |
785 } | |
786 | |
787 static void dummy_paint_free(paint_t *paint) { | |
788 if(paint) | |
789 free(paint); | |
790 } | |
791 | |
792 paint_t *dummy_paint_new(redraw_man_t *rdman) { | |
793 paint_t *paint; | |
794 | |
795 paint = (paint_t *)malloc(sizeof(paint_t)); | |
796 if(paint == NULL) | |
797 return NULL; | |
798 | |
799 paint_init(paint, dummy_paint_prepare, dummy_paint_free); | |
800 | |
801 return paint; | |
802 } | |
803 | |
782 void test_rdman_find_overlaid_shapes(void) { | 804 void test_rdman_find_overlaid_shapes(void) { |
783 redraw_man_t rdman; | 805 redraw_man_t rdman; |
784 geo_t geo; | 806 geo_t geo; |
785 coord_t *coords[3]; | 807 coord_t *coords[3]; |
786 shape_t *shapes[5]; | 808 shape_t *shapes[5]; |
832 | 854 |
833 void test_rdman_redraw_changed(void) { | 855 void test_rdman_redraw_changed(void) { |
834 coord_t *coords[3]; | 856 coord_t *coords[3]; |
835 shape_t *shapes[3]; | 857 shape_t *shapes[3]; |
836 sh_dummy_t **dummys; | 858 sh_dummy_t **dummys; |
859 paint_t *paint; | |
837 redraw_man_t *rdman; | 860 redraw_man_t *rdman; |
838 redraw_man_t _rdman; | 861 redraw_man_t _rdman; |
839 int i; | 862 int i; |
840 | 863 |
841 dummys = (sh_dummy_t **)shapes; | 864 dummys = (sh_dummy_t **)shapes; |
842 | 865 |
843 rdman = &_rdman; | 866 rdman = &_rdman; |
844 redraw_man_init(rdman, NULL); | 867 redraw_man_init(rdman, NULL); |
868 paint = dummy_paint_new(rdman); | |
845 for(i = 0; i < 3; i++) { | 869 for(i = 0; i < 3; i++) { |
846 shapes[i] = sh_dummy_new(0, 0, 50, 50); | 870 shapes[i] = sh_dummy_new(0, 0, 50, 50); |
871 rdman_paint_fill(rdman, paint, shapes[i]); | |
847 coords[i] = rdman_coord_new(rdman, rdman->root_coord); | 872 coords[i] = rdman_coord_new(rdman, rdman->root_coord); |
848 coords[i]->matrix[2] = 10 + i * 100; | 873 coords[i]->matrix[2] = 10 + i * 100; |
849 coords[i]->matrix[5] = 10 + i * 100; | 874 coords[i]->matrix[5] = 10 + i * 100; |
850 rdman_coord_changed(rdman, coords[i]); | 875 rdman_coord_changed(rdman, coords[i]); |
851 rdman_add_shape(rdman, shapes[i], coords[i]); | 876 rdman_add_shape(rdman, shapes[i], coords[i]); |
861 rdman_redraw_changed(rdman); | 886 rdman_redraw_changed(rdman); |
862 | 887 |
863 CU_ASSERT(dummys[0]->draw_cnt == 1); | 888 CU_ASSERT(dummys[0]->draw_cnt == 1); |
864 CU_ASSERT(dummys[1]->draw_cnt == 2); | 889 CU_ASSERT(dummys[1]->draw_cnt == 2); |
865 CU_ASSERT(dummys[2]->draw_cnt == 2); | 890 CU_ASSERT(dummys[2]->draw_cnt == 2); |
891 | |
892 paint->free(paint); | |
893 redraw_man_destroy(rdman); | |
866 } | 894 } |
867 | 895 |
868 CU_pSuite get_redraw_man_suite(void) { | 896 CU_pSuite get_redraw_man_suite(void) { |
869 CU_pSuite suite; | 897 CU_pSuite suite; |
870 | 898 |