0022627: Change OCCT memory management defaults
[occt.git] / src / Xw / Xw_draw_image.cxx
CommitLineData
7fd59977 1#define BUC0056 /*GG_300496
2 Protection contre zoom trop grand*/
3
4
5#include <Xw_Extension.h>
6
7 /* ifdef then trace on */
8#ifdef TRACE
9#define TRACE_DRAW_IMAGE
10#endif
11
12/*
13 STATUS Xw_draw_image (awindow,aimage,xc,yc):
14 XW_EXT_WINDOW *awindow
15 XW_EXT_IMAGEDATA *aimage Image structure
16 float xc,yc Image center location in user space
17
18 Draw an image to the window at the required Center location
19 NOTE than current Window position and Size is taken
20
21 returns ERROR if NO Image is defined or Image is outside of the window
22 returns SUCCESS if successful
23
24*/
25
26#ifdef BUC0056
27#define MAXCOORD 32767
28#define MINCOORD -32768
29#endif
30
31static XW_EXT_IMAGE *pimaglist ;
32
33#ifdef XW_PROTOTYPE
34XW_STATUS Xw_draw_image (void* awindow,void* aimage,float xc,float yc)
35#else
36XW_STATUS Xw_draw_image (awindow,aimage,xc,yc)
37void *awindow;
38void *aimage ;
39float xc,yc ;
40#endif /*XW_PROTOTYPE*/
41{
42XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow;
43XW_EXT_IMAGEDATA *pimage = (XW_EXT_IMAGEDATA*)aimage ;
44XW_EXT_BUFFER *pbuffer ;
45//int color,nimage,bindex,x,y,width,height ;
46int nimage,bindex,x,y,width,height ;
47
48 if( !Xw_isdefine_window(pwindow) ) {
49 /*ERROR*Bad EXT_WINDOW Address*/
50 Xw_set_error(24,"Xw_draw_image",pwindow) ;
51 return (XW_ERROR) ;
52 }
53
54 if( !Xw_isdefine_image(pimage) ) {
55 /*ERROR*Bad EXT_IMAGEDATA Address*/
56 Xw_set_error(25,"Xw_draw_image",pimage) ;
57 return (XW_ERROR) ;
58 }
59
60 bindex = _BINDEX ;
61 pbuffer = &_BUFFER(bindex) ;
62 for( pimaglist = pbuffer->pimaglist ; pimaglist ;
63 pimaglist = (XW_EXT_IMAGE*) pimaglist->link ) {
64 if( pimaglist->nimage < MAXIMAGES ) break ;
65 }
66
67 if( !pimaglist ) {
68 pimaglist = Xw_add_image_structure(pbuffer) ;
69 }
70
71//OCC186
72 x = PXPOINT(xc, pwindow->xratio) ;
73 y = PYPOINT(yc, pwindow->attributes.height, pwindow->yratio) ;
74//OCC186
75
76#ifdef BUC0056
77 x = max(min(x,MAXCOORD),MINCOORD);
78 y = max(min(y,MAXCOORD),MINCOORD);
79#endif
80 width = (_ZIMAGE) ? _ZIMAGE->width : _IIMAGE->width ;
81 height = (_ZIMAGE) ? _ZIMAGE->height : _IIMAGE->height ;
82 nimage = pimaglist->nimage ;
83 pimaglist->pimagdata[nimage] = pimage ;
84 pimaglist->rpoints[nimage].x = x ;
85 pimaglist->rpoints[nimage].y = y ;
86 pimaglist->nimage++ ;
87 if( bindex ) {
88 pbuffer->isempty = False ;
89 width = (width+3)/2 ;
90 height = (height+3)/2 ;
91 pbuffer->rxmin = min(pbuffer->rxmin,x-width) ;
92 pbuffer->rymin = min(pbuffer->rymin,y-height) ;
93 pbuffer->rxmax = max(pbuffer->rxmax,x+width) ;
94 pbuffer->rymax = max(pbuffer->rymax,y+height) ;
95 } else {
96 Xw_draw_pixel_images(pwindow,pimaglist,pwindow->qgwind.gccopy,NULL);
97 pimaglist->nimage = 0 ;
98 }
99
100#ifdef TRACE_DRAW_IMAGE
101if( Xw_get_trace() ) {
102 printf (" Xw_draw_image(%lx,%lx,%f,%f)\n",(long ) pwindow,(long ) pimage,xc,yc) ;
103}
104#endif
105
106 return (XW_SUCCESS);
107}
108
109#ifdef XW_PROTOTYPE
110void Xw_draw_pixel_images (XW_EXT_WINDOW* pwindow,XW_EXT_IMAGE* pimaglist,
111 GC gcimag,GC gcline)
112#else
113void Xw_draw_pixel_images (pwindow,pimaglist,gcimag,gcline)
114XW_EXT_WINDOW *pwindow;
115XW_EXT_IMAGE *pimaglist ;
116GC gcimag,gcline ;
117#endif
118{
119XW_EXT_IMAGEDATA *pimage;
120unsigned int width,height;
121XImage *pximage;
122int i,x,y;
123
124 for( i=0 ; i<pimaglist->nimage ; i++ ) {
125 pimage = pimaglist->pimagdata[i] ;
126 pximage = (_ZIMAGE) ? _ZIMAGE : _IIMAGE;
127 width = pximage->width;
128 height = pximage->height;
129 if( pimaglist->isupdated ) {
130 x = pimaglist->upoints[i].x - width/2 ;
131 y = pimaglist->upoints[i].y - height/2 ;
132 } else {
133 x = pimaglist->rpoints[i].x - width/2 ;
134 y = pimaglist->rpoints[i].y - height/2 ;
135 }
136 if( gcimag ) {
137 XPutImage(_DISPLAY,_DRAWABLE,gcimag,pximage,0,0,x,y,width,height) ;
138 }
139 if( gcline ) {
140 XDrawRectangle(_DISPLAY,_DRAWABLE,gcline,x-1,y-1,width+2,height+2) ;
141 }
142 }
143}
144
145#ifdef XW_PROTOTYPE
146XW_EXT_IMAGE* Xw_add_image_structure(XW_EXT_BUFFER* pbuflist )
147#else
148XW_EXT_IMAGE* Xw_add_image_structure(pbuflist )
149XW_EXT_BUFFER *pbuflist ;
150#endif /*XW_PROTOTYPE*/
151/*
152 Create and Insert at end one Extended image structure in the
153 image List
154
155 returns Extended image address if successful
156 or NULL if Bad Allocation
157*/
158{
159XW_EXT_IMAGE *pimage ;
160int i ;
161
162 pimage = (XW_EXT_IMAGE*) Xw_malloc(sizeof(XW_EXT_IMAGE)) ;
163 if( pimage ) {
164 pimage->link = pbuflist->pimaglist ;
165 pimage->isupdated = False ;
166 pimage->nimage = 0 ;
167 for( i=0 ; i<MAXIMAGES ; i++ ) {
168 pimage->pimagdata[i] = NULL ;
169 }
170 pbuflist->pimaglist = pimage ;
171 } else {
172 /*ERROR*EXT_IMAGE Allocation failed*/
173 Xw_set_error(27,"Xw_add_image_structure",NULL) ;
174 }
175
176 return (pimage) ;
177}
178
179#ifdef XW_PROTOTYPE
180XW_STATUS Xw_del_image_structure(XW_EXT_BUFFER* pbuflist)
181#else
182XW_STATUS Xw_del_image_structure(pbuflist)
183XW_EXT_BUFFER *pbuflist ;
184#endif /*XW_PROTOTYPE*/
185/*
186 Remove ALL Extended image structure in the
187 image List
188
189 SUCCESS always
190*/
191{
192XW_EXT_IMAGE *pimag,*qimag ;
193int i ;
194
195 for( pimag = pbuflist->pimaglist ; pimag ; pimag = qimag ) {
196 qimag = (XW_EXT_IMAGE*)pimag->link ;
197 for( i=0 ; i<pimag->nimage ; i++ ) {
198 if( pimag->pimagdata[i] )
199 Xw_del_imagedata_structure(pimag->pimagdata[i]) ;
200 }
201 Xw_free(pimag) ;
202 }
203 pbuflist->pimaglist = NULL ;
204
205 return (XW_SUCCESS) ;
206}