b311480e |
1 | // Copyright (c) 1999-2012 OPEN CASCADE SAS |
2 | // |
3 | // The content of this file is subject to the Open CASCADE Technology Public |
4 | // License Version 6.5 (the "License"). You may not use the content of this file |
5 | // except in compliance with the License. Please obtain a copy of the License |
6 | // at http://www.opencascade.org and read it completely before using this file. |
7 | // |
8 | // The Initial Developer of the Original Code is Open CASCADE S.A.S., having its |
9 | // main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France. |
10 | // |
11 | // The Original Code and all software distributed under the License is |
12 | // distributed on an "AS IS" basis, without warranty of any kind, and the |
13 | // Initial Developer hereby disclaims all such warranties, including without |
14 | // limitation, any warranties of merchantability, fitness for a particular |
15 | // purpose or non-infringement. Please see the License for the specific terms |
16 | // and conditions governing the rights and limitations under the License. |
17 | |
7fd59977 |
18 | #define BUC0056 /*GG_300496 |
b311480e |
19 | Protection contre zoom trop grand*/ |
7fd59977 |
20 | |
21 | |
22 | #include <Xw_Extension.h> |
23 | |
24 | /* ifdef then trace on */ |
25 | #ifdef TRACE |
26 | #define TRACE_DRAW_IMAGE |
27 | #endif |
28 | |
29 | /* |
30 | STATUS Xw_draw_image (awindow,aimage,xc,yc): |
31 | XW_EXT_WINDOW *awindow |
32 | XW_EXT_IMAGEDATA *aimage Image structure |
33 | float xc,yc Image center location in user space |
34 | |
35 | Draw an image to the window at the required Center location |
36 | NOTE than current Window position and Size is taken |
37 | |
38 | returns ERROR if NO Image is defined or Image is outside of the window |
39 | returns SUCCESS if successful |
40 | |
41 | */ |
42 | |
43 | #ifdef BUC0056 |
44 | #define MAXCOORD 32767 |
45 | #define MINCOORD -32768 |
46 | #endif |
47 | |
48 | static XW_EXT_IMAGE *pimaglist ; |
49 | |
50 | #ifdef XW_PROTOTYPE |
51 | XW_STATUS Xw_draw_image (void* awindow,void* aimage,float xc,float yc) |
52 | #else |
53 | XW_STATUS Xw_draw_image (awindow,aimage,xc,yc) |
54 | void *awindow; |
55 | void *aimage ; |
56 | float xc,yc ; |
57 | #endif /*XW_PROTOTYPE*/ |
58 | { |
59 | XW_EXT_WINDOW *pwindow = (XW_EXT_WINDOW*)awindow; |
60 | XW_EXT_IMAGEDATA *pimage = (XW_EXT_IMAGEDATA*)aimage ; |
61 | XW_EXT_BUFFER *pbuffer ; |
62 | //int color,nimage,bindex,x,y,width,height ; |
63 | int nimage,bindex,x,y,width,height ; |
64 | |
65 | if( !Xw_isdefine_window(pwindow) ) { |
66 | /*ERROR*Bad EXT_WINDOW Address*/ |
67 | Xw_set_error(24,"Xw_draw_image",pwindow) ; |
68 | return (XW_ERROR) ; |
69 | } |
70 | |
71 | if( !Xw_isdefine_image(pimage) ) { |
72 | /*ERROR*Bad EXT_IMAGEDATA Address*/ |
73 | Xw_set_error(25,"Xw_draw_image",pimage) ; |
74 | return (XW_ERROR) ; |
75 | } |
76 | |
77 | bindex = _BINDEX ; |
78 | pbuffer = &_BUFFER(bindex) ; |
79 | for( pimaglist = pbuffer->pimaglist ; pimaglist ; |
80 | pimaglist = (XW_EXT_IMAGE*) pimaglist->link ) { |
81 | if( pimaglist->nimage < MAXIMAGES ) break ; |
82 | } |
83 | |
84 | if( !pimaglist ) { |
85 | pimaglist = Xw_add_image_structure(pbuffer) ; |
86 | } |
87 | |
88 | //OCC186 |
89 | x = PXPOINT(xc, pwindow->xratio) ; |
90 | y = PYPOINT(yc, pwindow->attributes.height, pwindow->yratio) ; |
91 | //OCC186 |
92 | |
93 | #ifdef BUC0056 |
94 | x = max(min(x,MAXCOORD),MINCOORD); |
95 | y = max(min(y,MAXCOORD),MINCOORD); |
96 | #endif |
97 | width = (_ZIMAGE) ? _ZIMAGE->width : _IIMAGE->width ; |
98 | height = (_ZIMAGE) ? _ZIMAGE->height : _IIMAGE->height ; |
99 | nimage = pimaglist->nimage ; |
100 | pimaglist->pimagdata[nimage] = pimage ; |
101 | pimaglist->rpoints[nimage].x = x ; |
102 | pimaglist->rpoints[nimage].y = y ; |
103 | pimaglist->nimage++ ; |
104 | if( bindex ) { |
105 | pbuffer->isempty = False ; |
106 | width = (width+3)/2 ; |
107 | height = (height+3)/2 ; |
108 | pbuffer->rxmin = min(pbuffer->rxmin,x-width) ; |
109 | pbuffer->rymin = min(pbuffer->rymin,y-height) ; |
110 | pbuffer->rxmax = max(pbuffer->rxmax,x+width) ; |
111 | pbuffer->rymax = max(pbuffer->rymax,y+height) ; |
112 | } else { |
113 | Xw_draw_pixel_images(pwindow,pimaglist,pwindow->qgwind.gccopy,NULL); |
114 | pimaglist->nimage = 0 ; |
115 | } |
116 | |
117 | #ifdef TRACE_DRAW_IMAGE |
118 | if( Xw_get_trace() ) { |
119 | printf (" Xw_draw_image(%lx,%lx,%f,%f)\n",(long ) pwindow,(long ) pimage,xc,yc) ; |
120 | } |
121 | #endif |
122 | |
123 | return (XW_SUCCESS); |
124 | } |
125 | |
126 | #ifdef XW_PROTOTYPE |
127 | void Xw_draw_pixel_images (XW_EXT_WINDOW* pwindow,XW_EXT_IMAGE* pimaglist, |
128 | GC gcimag,GC gcline) |
129 | #else |
130 | void Xw_draw_pixel_images (pwindow,pimaglist,gcimag,gcline) |
131 | XW_EXT_WINDOW *pwindow; |
132 | XW_EXT_IMAGE *pimaglist ; |
133 | GC gcimag,gcline ; |
134 | #endif |
135 | { |
136 | XW_EXT_IMAGEDATA *pimage; |
137 | unsigned int width,height; |
138 | XImage *pximage; |
139 | int i,x,y; |
140 | |
141 | for( i=0 ; i<pimaglist->nimage ; i++ ) { |
142 | pimage = pimaglist->pimagdata[i] ; |
143 | pximage = (_ZIMAGE) ? _ZIMAGE : _IIMAGE; |
144 | width = pximage->width; |
145 | height = pximage->height; |
146 | if( pimaglist->isupdated ) { |
147 | x = pimaglist->upoints[i].x - width/2 ; |
148 | y = pimaglist->upoints[i].y - height/2 ; |
149 | } else { |
150 | x = pimaglist->rpoints[i].x - width/2 ; |
151 | y = pimaglist->rpoints[i].y - height/2 ; |
152 | } |
153 | if( gcimag ) { |
154 | XPutImage(_DISPLAY,_DRAWABLE,gcimag,pximage,0,0,x,y,width,height) ; |
155 | } |
156 | if( gcline ) { |
157 | XDrawRectangle(_DISPLAY,_DRAWABLE,gcline,x-1,y-1,width+2,height+2) ; |
158 | } |
159 | } |
160 | } |
161 | |
162 | #ifdef XW_PROTOTYPE |
163 | XW_EXT_IMAGE* Xw_add_image_structure(XW_EXT_BUFFER* pbuflist ) |
164 | #else |
165 | XW_EXT_IMAGE* Xw_add_image_structure(pbuflist ) |
166 | XW_EXT_BUFFER *pbuflist ; |
167 | #endif /*XW_PROTOTYPE*/ |
168 | /* |
169 | Create and Insert at end one Extended image structure in the |
170 | image List |
171 | |
172 | returns Extended image address if successful |
173 | or NULL if Bad Allocation |
174 | */ |
175 | { |
176 | XW_EXT_IMAGE *pimage ; |
177 | int i ; |
178 | |
179 | pimage = (XW_EXT_IMAGE*) Xw_malloc(sizeof(XW_EXT_IMAGE)) ; |
180 | if( pimage ) { |
181 | pimage->link = pbuflist->pimaglist ; |
182 | pimage->isupdated = False ; |
183 | pimage->nimage = 0 ; |
184 | for( i=0 ; i<MAXIMAGES ; i++ ) { |
185 | pimage->pimagdata[i] = NULL ; |
186 | } |
187 | pbuflist->pimaglist = pimage ; |
188 | } else { |
189 | /*ERROR*EXT_IMAGE Allocation failed*/ |
190 | Xw_set_error(27,"Xw_add_image_structure",NULL) ; |
191 | } |
192 | |
193 | return (pimage) ; |
194 | } |
195 | |
196 | #ifdef XW_PROTOTYPE |
197 | XW_STATUS Xw_del_image_structure(XW_EXT_BUFFER* pbuflist) |
198 | #else |
199 | XW_STATUS Xw_del_image_structure(pbuflist) |
200 | XW_EXT_BUFFER *pbuflist ; |
201 | #endif /*XW_PROTOTYPE*/ |
202 | /* |
203 | Remove ALL Extended image structure in the |
204 | image List |
205 | |
206 | SUCCESS always |
207 | */ |
208 | { |
209 | XW_EXT_IMAGE *pimag,*qimag ; |
210 | int i ; |
211 | |
212 | for( pimag = pbuflist->pimaglist ; pimag ; pimag = qimag ) { |
213 | qimag = (XW_EXT_IMAGE*)pimag->link ; |
214 | for( i=0 ; i<pimag->nimage ; i++ ) { |
215 | if( pimag->pimagdata[i] ) |
216 | Xw_del_imagedata_structure(pimag->pimagdata[i]) ; |
217 | } |
218 | Xw_free(pimag) ; |
219 | } |
220 | pbuflist->pimaglist = NULL ; |
221 | |
222 | return (XW_SUCCESS) ; |
223 | } |