7fd59977 |
1 | |
2 | #include <Xw_Extension.h> |
3 | |
4 | /* ifdef then trace on */ |
5 | #ifdef TRACE |
6 | #define TRACE_DEF_TILEMAP |
7 | #endif |
8 | |
9 | /* |
10 | XW_EXT_TILEMAP* Xw_def_tilemap(adisplay,ntile): |
11 | XW_EXT_DISPLAY *adisplay Extended Display structure |
12 | |
13 | int ntile Number of tile cells to be allocated |
14 | |
15 | Create a tilemap extension |
16 | allocate the tile cells in the tilemap as if possible |
17 | depending of the MAXTILE define . |
18 | |
19 | Returns Tilemap extension address if successuful |
20 | or NULL if ERROR |
21 | |
22 | */ |
23 | |
24 | #ifdef XW_PROTOTYPE |
25 | void* Xw_def_tilemap (void* adisplay,int ntile) |
26 | #else |
27 | void* Xw_def_tilemap (adisplay,ntile) |
28 | void *adisplay ; |
29 | int ntile ; |
30 | #endif /*XW_PROTOTYPE*/ |
31 | { |
32 | XW_EXT_DISPLAY *pdisplay = (XW_EXT_DISPLAY*)adisplay ; |
33 | XW_EXT_TILEMAP *ptilemap = NULL ; |
34 | //int i,tile ; |
35 | int i ; |
36 | |
37 | if( !Xw_isdefine_display(pdisplay) ) { |
38 | /*ERROR*Bad EXT_DISPLAY Address*/ |
39 | Xw_set_error(96,"Xw_def_tilemap",pdisplay) ; |
40 | return (NULL) ; |
41 | } |
42 | |
43 | if( !(ptilemap = Xw_add_tilemap_structure(sizeof(XW_EXT_TILEMAP))) ) |
44 | return (NULL) ; |
45 | |
46 | if( ntile <= 0 ) ntile = MAXTILE ; |
47 | |
48 | ptilemap->connexion = pdisplay ; |
49 | ptilemap->maxtile = min(ntile,MAXTILE) ; |
50 | |
51 | for( i=0 ; i<ptilemap->maxtile ; i++ ) { |
52 | ptilemap->tiles[i] = 0 ; |
53 | } |
54 | |
55 | #ifdef TRACE_DEF_TILEMAP |
56 | if( Xw_get_trace() ) { |
57 | printf(" %lx = Xw_def_tilemap(%lx,%d)\n", (long ) ptilemap,(long ) adisplay,ntile) ; |
58 | } |
59 | #endif |
60 | |
61 | return (ptilemap); |
62 | } |
63 | |
64 | static XW_EXT_TILEMAP *PtilemapList =NULL ; |
65 | |
66 | #ifdef XW_PROTOTYPE |
67 | XW_EXT_TILEMAP* Xw_add_tilemap_structure(int size) |
68 | #else |
69 | XW_EXT_TILEMAP* Xw_add_tilemap_structure(size) |
70 | int size ; |
71 | #endif /*XW_PROTOTYPE*/ |
72 | /* |
73 | Create and Insert one Extended tilemap structure in the |
74 | EXtended tilemap List |
75 | |
76 | returns Extended tilemap address if successful |
77 | or NULL if Bad Allocation |
78 | */ |
79 | { |
80 | XW_EXT_TILEMAP *ptilemap = (XW_EXT_TILEMAP*) Xw_malloc(size) ; |
81 | int i ; |
82 | |
83 | if( ptilemap ) { |
84 | ptilemap->type = TILEMAP_TYPE ; |
85 | ptilemap->link = PtilemapList ; |
86 | PtilemapList = ptilemap ; |
87 | ptilemap->connexion = NULL ; |
88 | ptilemap->maxtile = 0 ; |
89 | ptilemap->maxwindow = 0 ; |
90 | for( i=0 ; i<MAXTILE ; i++ ) { |
91 | ptilemap->tiles[i] = 0 ; |
92 | } |
93 | } else { |
94 | /*EXT_TILEMAP allocation failed*/ |
95 | Xw_set_error(17,"Xw_add_tilemap_structure",0) ; |
96 | } |
97 | |
98 | return (ptilemap) ; |
99 | } |
100 | |
101 | #ifdef XW_PROTOTYPE |
102 | XW_STATUS Xw_close_tilemap(void* atilemap) |
103 | #else |
104 | XW_STATUS Xw_close_tilemap(atilemap) |
105 | void* atilemap ; |
106 | #endif /*XW_PROTOTYPE*/ |
107 | { |
108 | XW_EXT_TILEMAP *ptilemap = (XW_EXT_TILEMAP*)atilemap ; |
109 | XW_STATUS status ; |
110 | |
111 | if( !Xw_isdefine_tilemap(ptilemap) ) { |
112 | /*Bad EXT_TILEMAP Address*/ |
113 | Xw_set_error(49,"Xw_close_tilemap",ptilemap) ; |
114 | return (XW_ERROR) ; |
115 | } |
116 | |
117 | status = Xw_del_tilemap_structure(ptilemap) ; |
118 | |
119 | #ifdef TRACE_DEF_TILEMAP |
120 | if( Xw_get_trace() ) { |
121 | printf(" %d = Xw_close_tilemap(%lx)\n",status,(long ) ptilemap) ; |
122 | } |
123 | #endif |
124 | |
125 | return (status) ; |
126 | } |
127 | |
128 | #ifdef XW_PROTOTYPE |
129 | XW_STATUS Xw_del_tilemap_structure(XW_EXT_TILEMAP* atilemap) |
130 | #else |
131 | XW_STATUS Xw_del_tilemap_structure(atilemap) |
132 | XW_EXT_TILEMAP *atilemap; |
133 | #endif /*XW_PROTOTYPE*/ |
134 | /* |
135 | Remove the Extended tilemap address from the Extended List |
136 | |
137 | returns ERROR if the tilemap address is not Found in the list |
138 | returns SUCCESS if successful |
139 | */ |
140 | { |
141 | XW_EXT_TILEMAP *ptilemap = PtilemapList ; |
142 | int i ; |
143 | |
144 | if( !atilemap ) return (XW_ERROR) ; |
145 | |
146 | if( atilemap->maxwindow ) --atilemap->maxwindow ; |
147 | |
148 | if( atilemap->maxwindow ) { |
149 | return (XW_ERROR) ; |
150 | } else { |
151 | for( i=0 ; i<MAXTILE ; i++) { |
152 | if( atilemap->tiles[i] ) XFreePixmap(_PDISPLAY,atilemap->tiles[i]) ; |
153 | } |
154 | |
155 | if( atilemap == ptilemap ) { |
156 | PtilemapList = (XW_EXT_TILEMAP*) atilemap->link ; |
157 | } else { |
158 | for( ; ptilemap ; ptilemap = (XW_EXT_TILEMAP*) ptilemap->link ) { |
159 | if( ptilemap->link == atilemap ) { |
160 | ptilemap->link = atilemap->link ; |
161 | break ; |
162 | } |
163 | } |
164 | } |
165 | Xw_free(atilemap) ; |
166 | } |
167 | return (XW_SUCCESS) ; |
168 | } |