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