Mercurial > MadButterfly
comparison src/shape_path.c @ 159:b90abd31a281
Postponse free of coords, shapes, and paints when the rdman is dirty.
- Life-cycle of shapes and paints are managed by rdman.
- Add redraw_man_t::free_objs to collect objects their freeing are
postonsed.
Know Issue:
- Bullet of tank are not removed from screen when it is go out the range
of the map.
author | Thinker K.F. Li <thinker@branda.to> |
---|---|
date | Sun, 05 Oct 2008 23:32:58 +0800 |
parents | 52f7566777f9 |
children | c7e5b8779bb5 |
comparison
equal
deleted
inserted
replaced
158:c1cdd3fcd28f | 159:b90abd31a281 |
---|---|
2 #include <stdlib.h> | 2 #include <stdlib.h> |
3 #include <ctype.h> | 3 #include <ctype.h> |
4 #include <string.h> | 4 #include <string.h> |
5 #include <cairo.h> | 5 #include <cairo.h> |
6 #include "mb_types.h" | 6 #include "mb_types.h" |
7 #include "redraw_man.h" | |
7 | 8 |
8 /*! \brief Implement respective objects for SVG path tag. | 9 /*! \brief Implement respective objects for SVG path tag. |
9 * | 10 * |
10 * In user_data or dev_data, 0x00 bytes are padding after commands. | 11 * In user_data or dev_data, 0x00 bytes are padding after commands. |
11 * No commands other than 0x00 can resident after 0x00 itself. | 12 * No commands other than 0x00 can resident after 0x00 itself. |
658 return OK; | 659 return OK; |
659 } | 660 } |
660 | 661 |
661 /*! \brief Create a path from value of 'data' of SVG path. | 662 /*! \brief Create a path from value of 'data' of SVG path. |
662 */ | 663 */ |
663 shape_t *sh_path_new(char *data) { | 664 shape_t *rdman_shape_path_new(redraw_man_t *rdman, char *data) { |
664 sh_path_t *path; | 665 sh_path_t *path; |
665 int cmd_cnt, arg_cnt, fix_arg_cnt; | 666 int cmd_cnt, arg_cnt, fix_arg_cnt; |
666 int msz; | 667 int msz; |
667 int r; | 668 int r; |
668 | 669 |
702 return NULL; | 703 return NULL; |
703 } | 704 } |
704 memcpy(path->dev_data, path->user_data, msz); | 705 memcpy(path->dev_data, path->user_data, msz); |
705 | 706 |
706 path->shape.free = sh_path_free; | 707 path->shape.free = sh_path_free; |
708 | |
709 #ifndef UNITTEST | |
710 rdman_shape_man(rdman, (shape_t *)path); | |
711 #endif | |
707 | 712 |
708 return (shape_t *)path; | 713 return (shape_t *)path; |
709 } | 714 } |
710 | 715 |
711 /*! \brief Transform a path from user space to device space. | 716 /*! \brief Transform a path from user space to device space. |
832 | 837 |
833 #ifdef UNITTEST | 838 #ifdef UNITTEST |
834 | 839 |
835 #include <CUnit/Basic.h> | 840 #include <CUnit/Basic.h> |
836 | 841 |
837 void test_sh_path_new(void) { | 842 void test_rdman_shape_path_new(void) { |
838 sh_path_t *path; | 843 sh_path_t *path; |
839 co_aix *args; | 844 co_aix *args; |
840 | 845 |
841 path = (sh_path_t *)sh_path_new("M 33 25l33 55c 33 87 44 22 55 99L33 77z"); | 846 path = (sh_path_t *)rdman_shape_path_new(NULL, "M 33 25l33 55c 33 87 44 22 55 99L33 77z"); |
842 CU_ASSERT(path != NULL); | 847 CU_ASSERT(path != NULL); |
843 CU_ASSERT(path->cmd_len == ((5 + RESERVED_AIXS + 3) & ~0x3)); | 848 CU_ASSERT(path->cmd_len == ((5 + RESERVED_AIXS + 3) & ~0x3)); |
844 CU_ASSERT(path->arg_len == 12); | 849 CU_ASSERT(path->arg_len == 12); |
845 CU_ASSERT(strncmp(path->user_data, "MLCLZ", 5) == 0); | 850 CU_ASSERT(strncmp(path->user_data, "MLCLZ", 5) == 0); |
846 CU_ASSERT(strncmp(path->dev_data, "MLCLZ", 5) == 0); | 851 CU_ASSERT(strncmp(path->dev_data, "MLCLZ", 5) == 0); |
865 sh_path_t *path; | 870 sh_path_t *path; |
866 co_aix *args; | 871 co_aix *args; |
867 coord_t coord; | 872 coord_t coord; |
868 geo_t geo; | 873 geo_t geo; |
869 | 874 |
870 path = (sh_path_t *)sh_path_new("M 33 25l33 55C 33 87 44 22 55 99L33 77z"); | 875 path = (sh_path_t *)rdman_shape_path_new(NULL, "M 33 25l33 55C 33 87 44 22 55 99L33 77z"); |
871 CU_ASSERT(path != NULL); | 876 CU_ASSERT(path != NULL); |
872 CU_ASSERT(path->cmd_len == ((5 + RESERVED_AIXS + 3) & ~0x3)); | 877 CU_ASSERT(path->cmd_len == ((5 + RESERVED_AIXS + 3) & ~0x3)); |
873 CU_ASSERT(path->arg_len == 12); | 878 CU_ASSERT(path->arg_len == 12); |
874 CU_ASSERT(strncmp(path->user_data, "MLCLZ", 5) == 0); | 879 CU_ASSERT(strncmp(path->user_data, "MLCLZ", 5) == 0); |
875 CU_ASSERT(strncmp(path->dev_data, "MLCLZ", 5) == 0); | 880 CU_ASSERT(strncmp(path->dev_data, "MLCLZ", 5) == 0); |
906 | 911 |
907 void test_spaces_head_tail(void) { | 912 void test_spaces_head_tail(void) { |
908 sh_path_t *path; | 913 sh_path_t *path; |
909 | 914 |
910 path = (sh_path_t *) | 915 path = (sh_path_t *) |
911 sh_path_new(" M 33 25l33 55C 33 87 44 22 55 99L33 77z "); | 916 rdman_shape_path_new(NULL, |
917 " M 33 25l33 55C 33 87 44 22 55 99L33 77z "); | |
912 CU_ASSERT(path != NULL); | 918 CU_ASSERT(path != NULL); |
913 sh_path_free((shape_t *)path); | 919 sh_path_free((shape_t *)path); |
914 } | 920 } |
915 | 921 |
916 CU_pSuite get_shape_path_suite(void) { | 922 CU_pSuite get_shape_path_suite(void) { |
917 CU_pSuite suite; | 923 CU_pSuite suite; |
918 | 924 |
919 suite = CU_add_suite("Suite_shape_path", NULL, NULL); | 925 suite = CU_add_suite("Suite_shape_path", NULL, NULL); |
920 CU_ADD_TEST(suite, test_sh_path_new); | 926 CU_ADD_TEST(suite, test_rdman_shape_path_new); |
921 CU_ADD_TEST(suite, test_path_transform); | 927 CU_ADD_TEST(suite, test_path_transform); |
922 | 928 |
923 return suite; | 929 return suite; |
924 } | 930 } |
925 | 931 |