]>
Commit | Line | Data |
---|---|---|
0e320a79 DW |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: dc.cpp | |
3 | // Purpose: wxDC class | |
fb46a9a6 | 4 | // Author: David Webster |
0e320a79 | 5 | // Modified by: |
fb46a9a6 | 6 | // Created: 10/14/99 |
0e320a79 | 7 | // RCS-ID: $Id$ |
fb46a9a6 DW |
8 | // Copyright: (c) David Webster |
9 | // Licence: wxWindows licence | |
0e320a79 DW |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
fb46a9a6 DW |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #ifndef WX_PRECOMP | |
16 | #include "wx/window.h" | |
17 | #include "wx/dc.h" | |
18 | #include "wx/utils.h" | |
19 | #include "wx/dialog.h" | |
20 | #include "wx/app.h" | |
21 | #include "wx/bitmap.h" | |
22 | #include "wx/dcmemory.h" | |
23 | #include "wx/log.h" | |
24 | #include "wx/icon.h" | |
0e320a79 DW |
25 | #endif |
26 | ||
fb46a9a6 DW |
27 | #include "wx/dcprint.h" |
28 | ||
29 | #include <string.h> | |
30 | #include <math.h> | |
31 | ||
32 | #include "wx/os2/private.h" | |
0e320a79 | 33 | |
fb46a9a6 | 34 | IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject) |
0e320a79 | 35 | |
fb46a9a6 | 36 | // --------------------------------------------------------------------------- |
0e320a79 | 37 | // constants |
fb46a9a6 | 38 | // --------------------------------------------------------------------------- |
1408104d | 39 | |
fb46a9a6 | 40 | static const int VIEWPORT_EXTENT = 1000; |
1408104d | 41 | |
fb46a9a6 DW |
42 | static const int MM_POINTS = 9; |
43 | static const int MM_METRIC = 10; | |
1408104d | 44 | |
f6bcfd97 BP |
45 | // usually this is defined in math.h |
46 | #ifndef M_PI | |
47 | static const double M_PI = 3.14159265358979323846; | |
48 | #endif // M_PI | |
49 | ||
50 | // --------------------------------------------------------------------------- | |
51 | // private functions | |
52 | // --------------------------------------------------------------------------- | |
53 | ||
54 | // convert degrees to radians | |
55 | static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; } | |
56 | ||
7e99520b DW |
57 | int SetTextColor( |
58 | HPS hPS | |
59 | , int nForegroundColour | |
60 | ) | |
61 | { | |
62 | CHARBUNDLE vCbnd; | |
63 | ||
64 | vCbnd.lColor = nForegroundColour; | |
65 | ::GpiSetAttrs( hPS // presentation-space handle | |
66 | ,PRIM_CHAR // Char primitive. | |
67 | ,CBB_COLOR // sets color. | |
68 | ,0 // | |
69 | ,&vCbnd // buffer for attributes. | |
70 | ); | |
71 | return 0; | |
72 | } | |
73 | ||
74 | int QueryTextBkColor( | |
75 | HPS hPS | |
76 | ) | |
77 | { | |
78 | CHARBUNDLE vCbnd; | |
79 | ||
f44fdfb0 DW |
80 | ::GpiQueryAttrs( hPS // presentation-space handle |
81 | ,PRIM_CHAR // Char primitive. | |
82 | ,CBB_BACK_COLOR // Background color. | |
83 | ,&vCbnd // buffer for attributes. | |
84 | ); | |
7e99520b DW |
85 | return vCbnd.lBackColor; |
86 | } | |
87 | ||
88 | ||
89 | int SetTextBkColor( | |
90 | HPS hPS | |
91 | , int nBackgroundColour | |
92 | ) | |
93 | { | |
94 | CHARBUNDLE vCbnd; | |
95 | int rc; | |
96 | ||
97 | rc = QueryTextBkColor(hPS); | |
98 | ||
99 | vCbnd.lBackColor = nBackgroundColour; | |
100 | ::GpiSetAttrs(hPS, // presentation-space handle | |
101 | PRIM_CHAR, // Char primitive. | |
102 | CBB_BACK_COLOR, // sets color. | |
103 | 0, | |
104 | &vCbnd // buffer for attributes. | |
105 | ); | |
106 | return rc; | |
107 | } | |
108 | ||
109 | int SetBkMode( | |
110 | HPS hPS | |
111 | , int nBackgroundMode | |
112 | ) | |
113 | { | |
114 | if(nBackgroundMode == wxTRANSPARENT) | |
115 | ::GpiSetBackMix( hPS | |
116 | ,BM_LEAVEALONE | |
117 | ); | |
118 | else | |
119 | // the background of the primitive takes over whatever is underneath. | |
120 | ::GpiSetBackMix( hPS | |
121 | ,BM_OVERPAINT | |
122 | ); | |
123 | return 0; | |
124 | } | |
125 | ||
fb46a9a6 DW |
126 | // =========================================================================== |
127 | // implementation | |
128 | // =========================================================================== | |
1408104d | 129 | |
fb46a9a6 | 130 | // --------------------------------------------------------------------------- |
0e320a79 | 131 | // wxDC |
fb46a9a6 | 132 | // --------------------------------------------------------------------------- |
0e320a79 DW |
133 | |
134 | wxDC::wxDC(void) | |
135 | { | |
7e99520b | 136 | m_pCanvas = NULL; |
c3d43472 | 137 | |
7e99520b DW |
138 | m_hOldBitmap = 0; |
139 | m_hOldPen = 0; | |
140 | m_hOldBrush = 0; | |
141 | m_hOldFont = 0; | |
142 | m_hOldPalette = 0; | |
ce44c50e | 143 | |
7e99520b DW |
144 | m_bOwnsDC = FALSE; |
145 | m_hDC = 0; | |
146 | m_nDCCount = 0; | |
147 | m_hOldPS = NULL; | |
148 | m_hPS = NULL; | |
149 | m_bIsPaintTime = FALSE;// True at Paint Time | |
0e320a79 DW |
150 | }; |
151 | ||
152 | wxDC::~wxDC(void) | |
153 | { | |
c3d43472 | 154 | // TODO: |
0e320a79 DW |
155 | }; |
156 | ||
fb46a9a6 DW |
157 | // This will select current objects out of the DC, |
158 | // which is what you have to do before deleting the | |
159 | // DC. | |
160 | void wxDC::SelectOldObjects(WXHDC dc) | |
0e320a79 | 161 | { |
fb46a9a6 DW |
162 | if (dc) |
163 | { | |
f6bcfd97 | 164 | if (m_hOldBitmap) |
fb46a9a6 DW |
165 | { |
166 | // ::SelectObject((HDC) dc, (HBITMAP) m_oldBitmap); | |
f6bcfd97 | 167 | if (m_vSelectedBitmap.Ok()) |
fb46a9a6 | 168 | { |
f6bcfd97 | 169 | m_vSelectedBitmap.SetSelectedInto(NULL); |
fb46a9a6 DW |
170 | } |
171 | } | |
f6bcfd97 BP |
172 | m_hOldBitmap = 0; |
173 | if (m_hOldPen) | |
fb46a9a6 DW |
174 | { |
175 | // ::SelectObject((HDC) dc, (HPEN) m_oldPen); | |
176 | } | |
f6bcfd97 BP |
177 | m_hOldPen = 0; |
178 | if (m_hOldBrush) | |
fb46a9a6 DW |
179 | { |
180 | // ::SelectObject((HDC) dc, (HBRUSH) m_oldBrush); | |
181 | } | |
f6bcfd97 BP |
182 | m_hOldBrush = 0; |
183 | if (m_hOldFont) | |
fb46a9a6 DW |
184 | { |
185 | // ::SelectObject((HDC) dc, (HFONT) m_oldFont); | |
186 | } | |
f6bcfd97 BP |
187 | m_hOldFont = 0; |
188 | if (m_hOldPalette) | |
fb46a9a6 DW |
189 | { |
190 | // ::SelectPalette((HDC) dc, (HPALETTE) m_oldPalette, TRUE); | |
191 | } | |
f6bcfd97 | 192 | m_hOldPalette = 0; |
fb46a9a6 | 193 | } |
0e320a79 | 194 | |
f6bcfd97 BP |
195 | m_brush = wxNullBrush; |
196 | m_pen = wxNullPen; | |
197 | m_palette = wxNullPalette; | |
198 | m_font = wxNullFont; | |
fb46a9a6 | 199 | m_backgroundBrush = wxNullBrush; |
f6bcfd97 | 200 | m_vSelectedBitmap = wxNullBitmap; |
fb46a9a6 | 201 | } |
0e320a79 | 202 | |
fb46a9a6 DW |
203 | // --------------------------------------------------------------------------- |
204 | // clipping | |
205 | // --------------------------------------------------------------------------- | |
0e320a79 | 206 | |
fa5593ac DW |
207 | #define DO_SET_CLIPPING_BOX() \ |
208 | { \ | |
209 | RECTL rect; \ | |
210 | \ | |
211 | ::GpiQueryClipBox(m_hPS, &rect); \ | |
212 | \ | |
213 | m_clipX1 = (wxCoord) XDEV2LOG(rect.xLeft); \ | |
214 | m_clipY1 = (wxCoord) YDEV2LOG(rect.yTop); \ | |
215 | m_clipX2 = (wxCoord) XDEV2LOG(rect.xRight); \ | |
216 | m_clipY2 = (wxCoord) YDEV2LOG(rect.yBottom); \ | |
fb46a9a6 | 217 | } |
0e320a79 | 218 | |
fa5593ac DW |
219 | void wxDC::DoSetClippingRegion( |
220 | wxCoord x | |
221 | , wxCoord y | |
222 | , wxCoord width | |
223 | , wxCoord height | |
224 | ) | |
0e320a79 | 225 | { |
fa5593ac DW |
226 | RECTL vRect; |
227 | ||
228 | m_clipping = TRUE; | |
229 | vRect.xLeft = XLOG2DEV(x); | |
230 | vRect.yTop = YLOG2DEV(y + height); | |
231 | vRect.xRight = XLOG2DEV(x + width); | |
232 | vRect.yBottom = YLOG2DEV(y); | |
233 | ::GpiIntersectClipRectangle(m_hPS, &vRect); | |
234 | DO_SET_CLIPPING_BOX() | |
235 | } // end of wxDC::DoSetClippingRegion | |
236 | ||
237 | void wxDC::DoSetClippingRegionAsRegion( | |
238 | const wxRegion& rRegion | |
239 | ) | |
0e320a79 | 240 | { |
fa5593ac DW |
241 | wxCHECK_RET(rRegion.GetHRGN(), wxT("invalid clipping region")); |
242 | HRGN hRgnOld; | |
243 | ||
244 | m_clipping = TRUE; | |
245 | ::GpiSetClipRegion( m_hPS | |
246 | ,(HRGN)rRegion.GetHRGN() | |
247 | ,&hRgnOld | |
248 | ); | |
249 | DO_SET_CLIPPING_BOX() | |
250 | } // end of wxDC::DoSetClippingRegionAsRegion | |
0e320a79 | 251 | |
fb46a9a6 | 252 | void wxDC::DestroyClippingRegion(void) |
0e320a79 | 253 | { |
fa5593ac DW |
254 | if (m_clipping && m_hPS) |
255 | { | |
256 | HRGN hRgnOld; | |
257 | RECTL vRect; | |
258 | ||
259 | // TODO: this should restore the previous clipped region | |
260 | // so that OnPaint processing works correctly, and | |
261 | // the update doesn't get destroyed after the first | |
262 | // DestroyClippingRegion | |
263 | vRect.xLeft = XLOG2DEV(0); | |
264 | vRect.yTop = YLOG2DEV(32000); | |
265 | vRect.xRight = XLOG2DEV(32000); | |
266 | vRect.yBottom = YLOG2DEV(0); | |
267 | ||
268 | HRGN hRgn = ::GpiCreateRegion(m_hPS, 1, &vRect); | |
269 | ||
270 | ::GpiSetClipRegion(m_hPS, hRgn, &hRgnOld); | |
271 | } | |
272 | m_clipping = FALSE; | |
273 | } // end of wxDC::DestroyClippingRegion | |
0e320a79 | 274 | |
fb46a9a6 DW |
275 | // --------------------------------------------------------------------------- |
276 | // query capabilities | |
277 | // --------------------------------------------------------------------------- | |
0e320a79 | 278 | |
fb46a9a6 | 279 | bool wxDC::CanDrawBitmap() const |
0e320a79 | 280 | { |
fb46a9a6 DW |
281 | return TRUE; |
282 | } | |
0e320a79 | 283 | |
fb46a9a6 | 284 | bool wxDC::CanGetTextExtent() const |
0e320a79 | 285 | { |
fb46a9a6 DW |
286 | // What sort of display is it? |
287 | int technology = 0; // TODO: ::GetDeviceCaps(GetHdc(), TECHNOLOGY); | |
0e320a79 | 288 | |
fb46a9a6 DW |
289 | // TODO: return (technology == DT_RASDISPLAY) || (technology == DT_RASPRINTER); |
290 | return FALSE; | |
291 | } | |
1408104d DW |
292 | |
293 | int wxDC::GetDepth() const | |
0e320a79 | 294 | { |
1408104d DW |
295 | // TODO: |
296 | return (1); | |
297 | } | |
0e320a79 | 298 | |
fb46a9a6 DW |
299 | // --------------------------------------------------------------------------- |
300 | // drawing | |
301 | // --------------------------------------------------------------------------- | |
0e320a79 | 302 | |
1408104d | 303 | void wxDC::Clear() |
0e320a79 | 304 | { |
445c7bca | 305 | ::GpiErase(m_hPS); |
1408104d | 306 | } |
0e320a79 | 307 | |
51c1d535 DW |
308 | void wxDC::DoFloodFill( |
309 | wxCoord vX | |
310 | , wxCoord vY | |
311 | , const wxColour& rCol | |
312 | , int nStyle | |
313 | ) | |
0e320a79 | 314 | { |
51c1d535 DW |
315 | POINTL vPtlPos; |
316 | LONG lColor; | |
317 | LONG lOptions; | |
318 | ||
319 | vPtlPos.x = vX; // Loads x-coordinate | |
320 | vPtlPos.y = vY; // Loads y-coordinate | |
321 | ::GpiMove(m_hPS, &vPtlPos); // Sets current position | |
322 | lColor = rCol.GetPixel(); | |
323 | lOptions = FF_BOUNDARY; | |
324 | if(wxFLOOD_SURFACE == nStyle) | |
325 | lOptions = FF_SURFACE; | |
326 | ||
327 | ::GpiFloodFill(m_hPS, lOptions, lColor); | |
1408104d | 328 | } |
0e320a79 | 329 | |
51c1d535 DW |
330 | bool wxDC::DoGetPixel( |
331 | wxCoord vX | |
332 | , wxCoord vY | |
333 | , wxColour* pCol | |
334 | ) const | |
1408104d | 335 | { |
51c1d535 DW |
336 | POINTL vPoint; |
337 | LONG lColor; | |
338 | ||
339 | vPoint.x = vX; | |
340 | vPoint.y = vY; | |
341 | lColor = ::GpiSetPel(m_hPS, &vPoint); | |
fa5593ac | 342 | pCol->Set((unsigned long)lColor); |
51c1d535 DW |
343 | if(lColor>= 0) |
344 | return(TRUE); | |
6f952627 | 345 | else |
51c1d535 | 346 | return(FALSE); |
1408104d | 347 | } |
0e320a79 | 348 | |
7cdc2f1e | 349 | void wxDC::DoCrossHair(wxCoord x, wxCoord y) |
0e320a79 | 350 | { |
1408104d DW |
351 | // TODO |
352 | } | |
353 | ||
7e99520b DW |
354 | void wxDC::DoDrawLine( |
355 | wxCoord vX1 | |
356 | , wxCoord vY1 | |
357 | , wxCoord vX2 | |
358 | , wxCoord vY2 | |
359 | ) | |
0e320a79 | 360 | { |
7e99520b DW |
361 | POINTL vPoint[2]; |
362 | ||
363 | vPoint[0].x = vX1; | |
364 | vPoint[0].y = vY1; | |
365 | vPoint[1].x = vX2; | |
366 | vPoint[1].y = vY2; | |
367 | // ::GpiSetColor(m_hPS,CLR_RED); //DEbug | |
368 | ::GpiMove(m_hPS, &vPoint[0]); | |
369 | ::GpiLine(m_hPS, &vPoint[1]); | |
1408104d DW |
370 | } |
371 | ||
51c1d535 DW |
372 | ////////////////////////////////////////////////////////////////////////////// |
373 | // Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1) | |
374 | // and ending at (x2, y2). The current pen is used for the outline and the | |
375 | // current brush for filling the shape. The arc is drawn in an anticlockwise | |
376 | // direction from the start point to the end point. | |
377 | ////////////////////////////////////////////////////////////////////////////// | |
378 | void wxDC::DoDrawArc( | |
379 | wxCoord vX1 | |
380 | , wxCoord vY1 | |
381 | , wxCoord vX2 | |
382 | , wxCoord vY2 | |
383 | , wxCoord vXc | |
384 | , wxCoord vYc | |
385 | ) | |
1408104d | 386 | { |
51c1d535 DW |
387 | POINTL vPtlPos; |
388 | POINTL vPtlArc[2]; // Structure for current position | |
389 | int nDx; | |
390 | int nDy; | |
391 | double dRadius; | |
392 | double dAngl1; | |
393 | double dAngl2; | |
394 | double dAnglmid; | |
395 | wxCoord vXm; | |
396 | wxCoord vYm; | |
397 | ARCPARAMS vArcp; // Structure for arc parameters | |
398 | ||
399 | if((vX1 == vXc && vY1 == vXc) || (vX2 == vXc && vY2 == vXc)) | |
400 | return; // Draw point ?? | |
401 | dRadius = 0.5 * ( hypot( (double)(vY1 - vYc) | |
402 | ,(double)(vX1 - vXc) | |
403 | ) + | |
404 | hypot( (double)(vY2 - vYc) | |
405 | ,(double)(vX2 - vXc) | |
406 | ) | |
407 | ); | |
408 | ||
409 | dAngl1 = atan2( (double)(vY1 - vYc) | |
410 | ,(double)(vX1 - vXc) | |
411 | ); | |
412 | dAngl2 = atan2( (double)(vY2 - vYc) | |
413 | ,(double)(vX2 - vXc) | |
414 | ); | |
415 | if(dAngl2 < dAngl1) | |
416 | dAngl2 += M_PI * 2; | |
417 | ||
418 | // | |
419 | // GpiPointArc can't draw full arc | |
420 | // | |
421 | if(dAngl2 == dAngl1 || (vX1 == vX2 && vY1 == vY2) ) | |
422 | { | |
423 | // | |
424 | // Medium point | |
425 | // | |
426 | dAnglmid = (dAngl1 + dAngl2)/2. + M_PI; | |
427 | vXm = vXc + dRadius * cos(dAnglmid); | |
428 | vYm = vYc + dRadius * sin(dAnglmid); | |
429 | DoDrawArc( vX1 | |
430 | ,vY1 | |
431 | ,vXm | |
432 | ,vYm | |
433 | ,vXc | |
434 | ,vYc | |
435 | ); | |
436 | DoDrawArc( vXm | |
437 | ,vYm | |
438 | ,vX2 | |
439 | ,vY2 | |
440 | ,vXc | |
441 | ,vYc | |
442 | ); | |
443 | return; | |
444 | } | |
445 | ||
446 | // | |
447 | // Medium point | |
448 | // | |
449 | dAnglmid = (dAngl1 + dAngl2)/2.; | |
450 | vXm = vXc + dRadius * cos(dAnglmid); | |
451 | vYm = vYc + dRadius * sin(dAnglmid); | |
452 | ||
453 | // | |
454 | // Ellipse main axis (r,q), (p,s) with center at (0,0) */ | |
455 | // | |
456 | vArcp.lR = 0; | |
457 | vArcp.lQ = 1; | |
458 | vArcp.lP = 1; | |
459 | vArcp.lS = 0; | |
460 | ::GpiSetArcParams(m_hPS, &vArcp); // Sets parameters to default | |
461 | ||
462 | vPtlPos.x = vX1; // Loads x-coordinate | |
463 | vPtlPos.y = vY1; // Loads y-coordinate | |
464 | ::GpiMove(m_hPS, &vPtlPos); // Sets current position | |
465 | vPtlArc[0].x = vXm; | |
466 | vPtlArc[0].y = vYm; | |
467 | vPtlArc[1].x = vX2; | |
468 | vPtlArc[1].y = vY2; | |
469 | ::GpiPointArc(m_hPS, vPtlArc); // Draws the arc | |
1408104d DW |
470 | } |
471 | ||
51c1d535 DW |
472 | void wxDC::DoDrawCheckMark( |
473 | wxCoord vX1 | |
474 | , wxCoord vY1 | |
475 | , wxCoord vWidth | |
476 | , wxCoord vHeight | |
477 | ) | |
f6bcfd97 | 478 | { |
51c1d535 DW |
479 | POINTL vPoint[2]; |
480 | ||
481 | vPoint[0].x = vX1; | |
482 | vPoint[0].y = vY1; | |
483 | vPoint[1].x = vX1 + vWidth; | |
484 | vPoint[1].y = vY1 + vHeight; | |
485 | ||
486 | ::GpiMove(m_hPS, &vPoint[0]); | |
487 | ::GpiBox( m_hPS // handle to a presentation space | |
488 | ,DRO_OUTLINE // draw the box outline ? or ? | |
489 | ,&vPoint[1] // address of the corner | |
490 | ,0L // horizontal corner radius | |
491 | ,0L // vertical corner radius | |
492 | ); | |
493 | if(vWidth > 4 && vHeight > 4) | |
494 | { | |
495 | int nTmp; | |
496 | ||
497 | vPoint[0].x += 2; vPoint[0].y += 2; | |
498 | vPoint[1].x -= 2; vPoint[1].y -= 2; | |
499 | ::GpiMove(m_hPS, &vPoint[0]); | |
500 | ::GpiLine(m_hPS, &vPoint[1]); | |
501 | nTmp = vPoint[0].x; | |
502 | vPoint[0].x = vPoint[1].x; | |
503 | vPoint[1].x = nTmp; | |
504 | ::GpiMove(m_hPS, &vPoint[0]); | |
505 | ::GpiLine(m_hPS, &vPoint[1]); | |
506 | } | |
f6bcfd97 BP |
507 | } |
508 | ||
51c1d535 DW |
509 | void wxDC::DoDrawPoint( |
510 | wxCoord vX | |
511 | , wxCoord vY | |
512 | ) | |
1408104d | 513 | { |
51c1d535 DW |
514 | POINTL vPoint; |
515 | ||
516 | vPoint.x = vX; | |
517 | vPoint.y = vY; | |
518 | ::GpiSetPel(m_hPS, &vPoint); | |
1408104d DW |
519 | } |
520 | ||
51c1d535 DW |
521 | void wxDC::DoDrawPolygon( |
522 | int n | |
523 | , wxPoint vPoints[] | |
524 | , wxCoord vXoffset | |
525 | , wxCoord vYoffset | |
526 | , int nFillStyle | |
527 | ) | |
1408104d | 528 | { |
51c1d535 DW |
529 | ULONG ulCount = 1; // Number of polygons. |
530 | POLYGON vPlgn; // polygon. | |
531 | ULONG flOptions = 0L; // Drawing options. | |
532 | ||
533 | ////////////////////////////////////////////////////////////////////////////// | |
534 | // This contains fields of option bits... to draw boundary lines as well as | |
535 | // the area interior. | |
536 | // | |
537 | // Drawing boundary lines: | |
538 | // POLYGON_NOBOUNDARY Does not draw boundary lines. | |
539 | // POLYGON_BOUNDARY Draws boundary lines (the default). | |
540 | // | |
541 | // Construction of the area interior: | |
542 | // POLYGON_ALTERNATE Constructs interior in alternate mode | |
543 | // (the default). | |
544 | // POLYGON_WINDING Constructs interior in winding mode. | |
545 | ////////////////////////////////////////////////////////////////////////////// | |
546 | ||
547 | ULONG flModel = 0L; // Drawing model. | |
548 | ||
549 | ////////////////////////////////////////////////////////////////////////////// | |
550 | // Drawing model. | |
551 | // POLYGON_INCL Fill is inclusive of bottom right (the default). | |
552 | // POLYGON_EXCL Fill is exclusive of bottom right. | |
553 | // This is provided to aid migration from other graphics models. | |
554 | ////////////////////////////////////////////////////////////////////////////// | |
555 | ||
556 | LONG lHits = 0L; // Correlation/error indicator. | |
557 | POINTL vPoint; | |
558 | int i; | |
559 | int nIsTRANSPARENT = 0; | |
560 | LONG lBorderColor = 0L; | |
561 | LONG lColor = 0L; | |
562 | ||
563 | lBorderColor = m_pen.GetColour().GetPixel(); | |
564 | lColor = m_brush.GetColour().GetPixel(); | |
565 | if(m_brush.GetStyle() == wxTRANSPARENT) | |
566 | nIsTRANSPARENT = 1; | |
567 | ||
568 | vPlgn.ulPoints = n; | |
569 | vPlgn.aPointl = (POINTL*) calloc( n + 1 | |
570 | ,sizeof(POINTL) | |
571 | ); // well, new will call malloc | |
572 | ||
573 | for(i = 0; i < n; i++) | |
574 | { | |
575 | vPlgn.aPointl[i].x = vPoints[i].x; // +xoffset; | |
576 | vPlgn.aPointl[i].y = vPoints[i].y; // +yoffset; | |
577 | } | |
578 | flModel = POLYGON_BOUNDARY; | |
579 | if(nFillStyle == wxWINDING_RULE) | |
580 | flModel |= POLYGON_WINDING; | |
581 | else | |
582 | flModel |= POLYGON_ALTERNATE; | |
583 | ||
584 | vPoint.x = vXoffset; | |
585 | vPoint.y = vYoffset; | |
586 | ||
587 | ::GpiSetColor(m_hPS, lBorderColor); | |
588 | ::GpiMove(m_hPS, &vPoint); | |
589 | lHits = ::GpiPolygons(m_hPS, ulCount, &vPlgn, flOptions, flModel); | |
590 | free(vPlgn.aPointl); | |
1408104d DW |
591 | } |
592 | ||
51c1d535 DW |
593 | void wxDC::DoDrawLines( |
594 | int n | |
595 | , wxPoint vPoints[] | |
596 | , wxCoord vXoffset | |
597 | , wxCoord vYoffset | |
598 | ) | |
1408104d | 599 | { |
51c1d535 DW |
600 | int i; |
601 | POINTL vPoint; | |
602 | ||
603 | vPoint.x = vPoints[0].x + vXoffset; | |
604 | vPoint.y = vPoints[0].y + vYoffset; | |
605 | ::GpiMove(m_hPS, &vPoint); | |
606 | ||
607 | LONG lBorderColor = m_pen.GetColour().GetPixel(); | |
608 | ||
609 | ::GpiSetColor(m_hPS, lBorderColor); | |
610 | for(i = 1; i < n; i++) | |
611 | { | |
612 | vPoint.x = vPoints[0].x + vXoffset; | |
613 | vPoint.y = vPoints[0].y + vYoffset; | |
614 | ::GpiLine(m_hPS, &vPoint); | |
615 | } | |
1408104d DW |
616 | } |
617 | ||
7e99520b | 618 | void wxDC::DoDrawRectangle( |
f44fdfb0 | 619 | wxCoord vX |
7e99520b DW |
620 | , wxCoord vY |
621 | , wxCoord vWidth | |
622 | , wxCoord vHeight | |
623 | ) | |
1408104d | 624 | { |
7e99520b | 625 | POINTL vPoint[2]; |
51c1d535 DW |
626 | LONG lControl; |
627 | LONG lColor; | |
628 | LONG lBorderColor; | |
629 | int nIsTRANSPARENT = 0; | |
7e99520b DW |
630 | |
631 | vPoint[0].x = vX; | |
632 | vPoint[0].y = vY; | |
f44fdfb0 DW |
633 | vPoint[1].x = vX + vWidth; |
634 | vPoint[1].y = vY - vHeight; //mustdie !!! ?? | |
7e99520b | 635 | ::GpiMove(m_hPS, &vPoint[0]); |
51c1d535 DW |
636 | lColor = m_brush.GetColour().GetPixel(); |
637 | lBorderColor = m_pen.GetColour().GetPixel(); | |
638 | if (m_brush.GetStyle() == wxTRANSPARENT) | |
639 | nIsTRANSPARENT = 1; | |
640 | if(lColor == lBorderColor || nIsTRANSPARENT) | |
641 | { | |
642 | lControl = DRO_OUTLINEFILL; //DRO_FILL; | |
643 | if(m_brush.GetStyle() == wxTRANSPARENT) | |
644 | lControl = DRO_OUTLINE; | |
645 | ||
646 | //EK ::GpiSetColor(m_hPS,lBorderColor); | |
647 | ::GpiSetColor(m_hPS,CLR_GREEN); | |
648 | ::GpiBox( m_hPS // handle to a presentation space | |
649 | ,lControl // draw the box outline ? or ? | |
650 | ,&vPoint[1] // address of the corner | |
651 | ,0L // horizontal corner radius | |
652 | ,0L // vertical corner radius | |
653 | ); | |
654 | } | |
655 | else | |
656 | { | |
657 | lControl = DRO_OUTLINE; | |
658 | ::GpiSetColor( m_hPS | |
659 | ,lBorderColor | |
660 | ); | |
661 | ::GpiBox( m_hPS | |
662 | ,lControl | |
663 | ,&vPoint[1] | |
664 | ,0L | |
665 | ,0L | |
666 | ); | |
667 | lControl = DRO_FILL; | |
668 | ::GpiSetColor( m_hPS | |
669 | ,lColor | |
670 | ); | |
671 | ::GpiBox( m_hPS | |
672 | ,lControl | |
673 | ,&vPoint[1] | |
674 | ,0L | |
675 | ,0L | |
676 | ); | |
677 | } | |
1408104d DW |
678 | } |
679 | ||
7e99520b DW |
680 | void wxDC::DoDrawRoundedRectangle( |
681 | wxCoord vX | |
682 | , wxCoord vY | |
683 | , wxCoord vWidth | |
684 | , wxCoord vHeight | |
685 | , double dRadius | |
686 | ) | |
1408104d | 687 | { |
7e99520b | 688 | POINTL vPoint[2]; |
51c1d535 | 689 | LONG lControl; |
7e99520b DW |
690 | |
691 | vPoint[0].x = vX; | |
692 | vPoint[0].y = vY; | |
693 | vPoint[1].x = vX + vWidth; | |
51c1d535 | 694 | vPoint[1].y = vY + vHeight; |
7e99520b | 695 | ::GpiMove(m_hPS, &vPoint[0]); |
51c1d535 DW |
696 | |
697 | lControl = DRO_OUTLINEFILL; //DRO_FILL; | |
698 | if (m_brush.GetStyle() == wxTRANSPARENT) | |
699 | lControl = DRO_OUTLINE; | |
f44fdfb0 DW |
700 | ::GpiBox( m_hPS // handle to a presentation space |
701 | ,DRO_OUTLINE // draw the box outline ? or ? | |
702 | ,&vPoint[1] // address of the corner | |
703 | ,(LONG)dRadius // horizontal corner radius | |
704 | ,(LONG)dRadius // vertical corner radius | |
7e99520b | 705 | ); |
1408104d DW |
706 | } |
707 | ||
51c1d535 DW |
708 | // Draw Ellipse within box (x,y) - (x+width, y+height) |
709 | void wxDC::DoDrawEllipse( | |
710 | wxCoord vX | |
711 | , wxCoord vY | |
712 | , wxCoord vWidth | |
713 | , wxCoord vHeight | |
714 | ) | |
1408104d | 715 | { |
51c1d535 DW |
716 | POINTL vPtlPos; // Structure for current position |
717 | FIXED vFxMult; // Multiplier for ellipse | |
718 | ARCPARAMS vArcp; // Structure for arc parameters | |
719 | ||
720 | vArcp.lR = 0; | |
721 | vArcp.lQ = vHeight/2; | |
722 | vArcp.lP = vWidth/2; | |
723 | vArcp.lS = 0; | |
724 | ::GpiSetArcParams( m_hPS | |
725 | ,&vArcp | |
726 | ); // Sets parameters to default | |
727 | vPtlPos.x = vX + vWidth/2; // Loads x-coordinate | |
728 | vPtlPos.y = vY + vHeight/2; // Loads y-coordinate | |
729 | ::GpiMove( m_hPS | |
730 | ,&vPtlPos | |
731 | ); // Sets current position | |
732 | vFxMult = MAKEFIXED(1, 0); /* Sets multiplier */ | |
733 | ||
734 | // | |
735 | // DRO_FILL, DRO_OTLINEFILL - where to get | |
736 | // | |
737 | ::GpiFullArc( m_hPS | |
738 | ,DRO_OUTLINE | |
739 | ,vFxMult | |
740 | ); // Draws full arc with center at current position | |
1408104d DW |
741 | } |
742 | ||
51c1d535 DW |
743 | void wxDC::DoDrawEllipticArc( |
744 | wxCoord vX | |
745 | , wxCoord vY | |
746 | , wxCoord vWidth | |
747 | , wxCoord vHeight | |
748 | , double dSa | |
749 | , double dEa | |
750 | ) | |
1408104d | 751 | { |
51c1d535 DW |
752 | POINTL vPtlPos; // Structure for current position |
753 | FIXED vFxMult; // Multiplier for ellipse | |
754 | ARCPARAMS vArcp; // Structure for arc parameters | |
755 | FIXED vFSa; | |
756 | FIXED vFSweepa; // Start angle, sweep angle | |
757 | double dIntPart; | |
758 | double dFractPart; | |
759 | double dRadius; | |
760 | ||
761 | dFractPart = modf(dSa,&dIntPart); | |
762 | vFSa = MAKEFIXED((int)dIntPart, (int)(dFractPart * 0xffff) ); | |
763 | dFractPart = modf(dEa - dSa, &dIntPart); | |
764 | vFSweepa = MAKEFIXED((int)dIntPart, (int)(dFractPart * 0xffff) ); | |
765 | ||
766 | // | |
767 | // Ellipse main axis (r,q), (p,s) with center at (0,0) | |
768 | // | |
769 | vArcp.lR = 0; | |
770 | vArcp.lQ = vHeight/2; | |
771 | vArcp.lP = vWidth/2; | |
772 | vArcp.lS = 0; | |
773 | ::GpiSetArcParams(m_hPS, &vArcp); // Sets parameters to default | |
774 | vPtlPos.x = vX + vWidth/2 * (1. + cos(DegToRad(dSa))); // Loads x-coordinate | |
775 | vPtlPos.y = vY + vHeight/2 * (1. + sin(DegToRad(dSa))); // Loads y-coordinate | |
776 | ::GpiMove(m_hPS, &vPtlPos); // Sets current position | |
777 | ||
778 | // | |
779 | // May be not to the center ? | |
780 | // | |
781 | vPtlPos.x = vX + vWidth/2 ; // Loads x-coordinate | |
782 | vPtlPos.y = vY + vHeight/2; // Loads y-coordinate | |
783 | vFxMult = MAKEFIXED(1, 0); // Sets multiplier | |
784 | ||
785 | // | |
786 | // DRO_FILL, DRO_OTLINEFILL - where to get | |
787 | // | |
788 | ::GpiPartialArc( m_hPS | |
789 | ,&vPtlPos | |
790 | ,vFxMult | |
791 | ,vFSa | |
792 | ,vFSweepa | |
793 | ); | |
1408104d DW |
794 | } |
795 | ||
7cdc2f1e | 796 | void wxDC::DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y) |
1408104d | 797 | { |
51c1d535 | 798 | // TODO: |
1408104d DW |
799 | } |
800 | ||
fb46a9a6 | 801 | void wxDC::DoDrawBitmap( const wxBitmap &bmp |
7cdc2f1e | 802 | ,wxCoord x, wxCoord y |
fb46a9a6 DW |
803 | ,bool useMask |
804 | ) | |
1408104d DW |
805 | { |
806 | // TODO | |
807 | } | |
808 | ||
7e99520b DW |
809 | void wxDC::DoDrawText( |
810 | const wxString& rsText | |
811 | , wxCoord vX | |
812 | , wxCoord vY | |
813 | ) | |
1408104d | 814 | { |
7e99520b DW |
815 | DrawAnyText( rsText |
816 | ,vX | |
817 | ,vY | |
818 | ); | |
1408104d DW |
819 | } |
820 | ||
7e99520b DW |
821 | void wxDC::DrawAnyText( |
822 | const wxString& rsText | |
823 | , wxCoord vX | |
824 | , wxCoord vY | |
825 | ) | |
f6bcfd97 | 826 | { |
7e99520b DW |
827 | int nOldBackground = 0; |
828 | POINTL vPtlStart; | |
829 | LONG lHits; | |
f6bcfd97 | 830 | |
7e99520b DW |
831 | // |
832 | // prepare for drawing the text | |
833 | // | |
834 | ||
835 | // | |
836 | // Set text color attributes | |
837 | // | |
838 | if (m_textForegroundColour.Ok()) | |
839 | { | |
840 | SetTextColor( m_hPS | |
841 | ,(int)m_textForegroundColour.GetPixel() | |
842 | ); | |
843 | } | |
844 | ||
845 | if (m_textBackgroundColour.Ok()) | |
846 | { | |
847 | nOldBackground = SetTextBkColor( m_hPS | |
848 | ,(int)m_textBackgroundColour.GetPixel() | |
849 | ); | |
850 | } | |
851 | SetBkMode( m_hPS | |
852 | ,m_backgroundMode | |
853 | ); | |
854 | vPtlStart.x = vX; | |
855 | vPtlStart.y = vY; | |
856 | ||
857 | lHits = ::GpiCharStringAt( m_hPS | |
858 | ,&vPtlStart | |
859 | ,rsText.length() | |
860 | ,(PCH)rsText.c_str() | |
861 | ); | |
862 | if (lHits != GPI_OK) | |
863 | { | |
864 | wxLogLastError(wxT("TextOut")); | |
865 | } | |
866 | ||
867 | // | |
868 | // Restore the old parameters (text foreground colour may be left because | |
869 | // it never is set to anything else, but background should remain | |
870 | // transparent even if we just drew an opaque string) | |
871 | // | |
872 | if (m_textBackgroundColour.Ok()) | |
873 | SetTextBkColor( m_hPS | |
874 | ,nOldBackground | |
875 | ); | |
876 | SetBkMode( m_hPS | |
877 | ,wxTRANSPARENT | |
878 | ); | |
879 | } | |
880 | ||
881 | void wxDC::DoDrawRotatedText( | |
882 | const wxString& rsText | |
883 | , wxCoord vX | |
884 | , wxCoord vY | |
885 | , double dAngle | |
886 | ) | |
c8ce6bcc | 887 | { |
7e99520b DW |
888 | if (dAngle == 0.0) |
889 | { | |
890 | DoDrawText( rsText | |
891 | ,vX | |
892 | ,vY | |
893 | ); | |
894 | } | |
895 | ||
c8ce6bcc DW |
896 | // TODO: |
897 | /* | |
898 | if ( angle == 0.0 ) | |
899 | { | |
900 | DoDrawText(text, x, y); | |
901 | } | |
902 | else | |
903 | { | |
904 | LOGFONT lf; | |
905 | wxFillLogFont(&lf, &m_font); | |
906 | ||
907 | // GDI wants the angle in tenth of degree | |
908 | long angle10 = (long)(angle * 10); | |
909 | lf.lfEscapement = angle10; | |
910 | lf. lfOrientation = angle10; | |
911 | ||
912 | HFONT hfont = ::CreateFontIndirect(&lf); | |
913 | if ( !hfont ) | |
914 | { | |
915 | wxLogLastError("CreateFont"); | |
916 | } | |
917 | else | |
918 | { | |
919 | HFONT hfontOld = ::SelectObject(GetHdc(), hfont); | |
920 | ||
921 | DrawAnyText(text, x, y); | |
922 | ||
923 | (void)::SelectObject(GetHdc(), hfontOld); | |
924 | } | |
925 | ||
926 | // call the bounding box by adding all four vertices of the rectangle | |
927 | // containing the text to it (simpler and probably not slower than | |
928 | // determining which of them is really topmost/leftmost/...) | |
929 | wxCoord w, h; | |
930 | GetTextExtent(text, &w, &h); | |
931 | ||
932 | double rad = DegToRad(angle); | |
933 | ||
934 | // "upper left" and "upper right" | |
935 | CalcBoundingBox(x, y); | |
936 | CalcBoundingBox(x + w*cos(rad), y - h*sin(rad)); | |
937 | CalcBoundingBox(x + h*sin(rad), y + h*cos(rad)); | |
938 | ||
939 | // "bottom left" and "bottom right" | |
940 | x += (wxCoord)(h*sin(rad)); | |
941 | y += (wxCoord)(h*cos(rad)); | |
942 | CalcBoundingBox(x, y); | |
943 | CalcBoundingBox(x + h*sin(rad), y + h*cos(rad)); | |
944 | } | |
945 | */ | |
946 | } | |
947 | ||
fb46a9a6 DW |
948 | // --------------------------------------------------------------------------- |
949 | // set GDI objects | |
950 | // --------------------------------------------------------------------------- | |
1408104d | 951 | |
fb46a9a6 | 952 | void wxDC::SetPalette(const wxPalette& palette) |
1408104d DW |
953 | { |
954 | // TODO | |
955 | } | |
956 | ||
f6bcfd97 BP |
957 | void wxDC::SetFont( |
958 | const wxFont& rFont | |
959 | ) | |
1408104d | 960 | { |
f6bcfd97 BP |
961 | // |
962 | // Set the old object temporarily, in case the assignment deletes an object | |
963 | // that's not yet selected out. | |
964 | // | |
965 | if (m_hOldFont) | |
966 | { | |
967 | // ::SelectObject(GetHdc(), (HFONT) m_hOldFont); | |
968 | m_hOldFont = 0; | |
969 | } | |
970 | ||
971 | m_font = rFont; | |
972 | ||
973 | if (!rFont.Ok()) | |
974 | { | |
975 | if (m_hOldFont) | |
976 | // ::SelectObject(GetHdc(), (HFONT) m_hOldFont); | |
977 | m_hOldFont = 0; | |
978 | } | |
979 | ||
980 | if (m_font.Ok() && m_font.GetResourceHandle()) | |
981 | { | |
982 | HFONT hFont = (HFONT)0; //::SelectObject(GetHdc(), (HFONT) m_font.GetResourceHandle()); | |
983 | if (hFont == (HFONT) NULL) | |
984 | { | |
985 | wxLogDebug(wxT("::SelectObject failed in wxDC::SetFont.")); | |
986 | } | |
987 | if (!m_hOldFont) | |
988 | m_hOldFont = (WXHFONT) hFont; | |
989 | } | |
1408104d DW |
990 | } |
991 | ||
7e99520b DW |
992 | void wxDC::SetPen( |
993 | const wxPen& rPen | |
994 | ) | |
1408104d | 995 | { |
7e99520b DW |
996 | wxCHECK_RET( Ok(), wxT("invalid window dc") ); |
997 | ||
998 | if (m_pen == rPen) | |
999 | return; | |
1000 | m_pen = rPen; | |
1001 | if (!m_pen.Ok()) | |
1002 | return; | |
1003 | ||
1004 | int nWidth = m_pen.GetWidth(); | |
1005 | ||
1006 | if (nWidth <= 0) | |
1007 | { | |
1008 | nWidth = 1; | |
1009 | } | |
1010 | else | |
1011 | { | |
1012 | double dW = 0.5 + | |
f44fdfb0 DW |
1013 | ( fabs((double) XLOG2DEVREL(nWidth)) + |
1014 | fabs((double) YLOG2DEVREL(nWidth)) | |
7e99520b DW |
1015 | ) / 2.0; |
1016 | nWidth = (int)dW; | |
1017 | } | |
1018 | wxColour vColor = m_pen.GetColour(); | |
1019 | ||
1020 | ::GpiSetColor( m_hPS | |
1021 | ,vColor.GetPixel() | |
1022 | ); //DEbug ?? | |
51c1d535 DW |
1023 | |
1024 | int nLinetype; | |
1025 | int nStyle = m_pen.GetStyle(); | |
1026 | ||
1027 | nLinetype = LINETYPE_DEFAULT; | |
1028 | switch(nStyle) | |
1029 | { | |
1030 | case wxDOT: | |
1031 | nLinetype = LINETYPE_DOT; | |
1032 | break; | |
1033 | ||
1034 | case wxLONG_DASH: | |
1035 | nLinetype = LINETYPE_LONGDASH; | |
1036 | break; | |
1037 | ||
1038 | case wxSHORT_DASH: | |
1039 | nLinetype = LINETYPE_SHORTDASH; | |
1040 | break; | |
1041 | ||
1042 | case wxDOT_DASH: | |
1043 | nLinetype = LINETYPE_DASHDOT; | |
1044 | break; | |
1045 | ||
1046 | case wxTRANSPARENT: | |
1047 | nLinetype = LINETYPE_INVISIBLE; | |
1048 | break; | |
1049 | ||
1050 | case wxSOLID: | |
1051 | nLinetype = LINETYPE_SOLID; | |
1052 | break; | |
1053 | } | |
1054 | ::GpiSetLineType( m_hPS | |
1055 | ,nLinetype | |
1056 | ); | |
1057 | ||
1058 | nWidth = m_pen.GetWidth(); | |
1059 | ::GpiSetLineWidth( m_hPS | |
1060 | ,MAKEFIXED( nWidth | |
1061 | ,0 | |
1062 | ) | |
1063 | ); | |
1408104d | 1064 | } |
7e99520b | 1065 | |
51c1d535 DW |
1066 | void wxDC::SetBrush( |
1067 | const wxBrush& rBrush | |
1068 | ) | |
1408104d DW |
1069 | { |
1070 | // TODO | |
1071 | } | |
1072 | ||
fb46a9a6 | 1073 | void wxDC::SetBackground(const wxBrush& brush) |
1408104d DW |
1074 | { |
1075 | // TODO | |
1076 | } | |
1077 | ||
7e99520b DW |
1078 | void wxDC::SetBackgroundMode( |
1079 | int nMode | |
1080 | ) | |
1408104d | 1081 | { |
7e99520b | 1082 | m_backgroundMode = nMode; |
1408104d DW |
1083 | } |
1084 | ||
fb46a9a6 | 1085 | void wxDC::SetLogicalFunction(int function) |
1408104d DW |
1086 | { |
1087 | // TODO | |
1088 | } | |
1408104d | 1089 | |
ce44c50e DW |
1090 | void wxDC::SetRop(WXHDC dc) |
1091 | { | |
1092 | if (!dc || m_logicalFunction < 0) | |
1093 | return; | |
1094 | ||
1095 | int c_rop; | |
1096 | // These may be wrong | |
1097 | switch (m_logicalFunction) | |
1098 | { | |
1099 | // TODO: Figure this stuff out | |
1100 | // case wxXOR: c_rop = R2_XORPEN; break; | |
1101 | // case wxXOR: c_rop = R2_NOTXORPEN; break; | |
1102 | // case wxINVERT: c_rop = R2_NOT; break; | |
1103 | // case wxOR_REVERSE: c_rop = R2_MERGEPENNOT; break; | |
1104 | // case wxAND_REVERSE: c_rop = R2_MASKPENNOT; break; | |
1105 | // case wxCLEAR: c_rop = R2_WHITE; break; | |
1106 | // case wxSET: c_rop = R2_BLACK; break; | |
1107 | // case wxSRC_INVERT: c_rop = R2_NOTCOPYPEN; break; | |
1108 | // case wxOR_INVERT: c_rop = R2_MERGENOTPEN; break; | |
1109 | // case wxAND: c_rop = R2_MASKPEN; break; | |
1110 | // case wxOR: c_rop = R2_MERGEPEN; break; | |
1111 | // case wxAND_INVERT: c_rop = R2_MASKNOTPEN; break; | |
1112 | // case wxEQUIV: | |
1113 | // case wxNAND: | |
1114 | // case wxCOPY: | |
1115 | default: | |
1116 | // c_rop = R2_COPYPEN; | |
1117 | break; | |
1118 | } | |
1119 | // SetROP2((HDC) dc, c_rop); | |
1120 | } | |
1121 | ||
fb46a9a6 | 1122 | bool wxDC::StartDoc(const wxString& message) |
ce44c50e | 1123 | { |
fb46a9a6 DW |
1124 | // We might be previewing, so return TRUE to let it continue. |
1125 | return TRUE; | |
1126 | } | |
1127 | ||
1128 | void wxDC::EndDoc() | |
1129 | { | |
1130 | } | |
1131 | ||
1132 | void wxDC::StartPage() | |
1133 | { | |
1134 | } | |
1135 | ||
1136 | void wxDC::EndPage() | |
1137 | { | |
1138 | } | |
1139 | ||
1140 | // --------------------------------------------------------------------------- | |
1141 | // text metrics | |
1142 | // --------------------------------------------------------------------------- | |
1143 | ||
7cdc2f1e | 1144 | wxCoord wxDC::GetCharHeight() const |
fb46a9a6 DW |
1145 | { |
1146 | // TODO | |
7e99520b | 1147 | return(8); |
fb46a9a6 DW |
1148 | } |
1149 | ||
7cdc2f1e | 1150 | wxCoord wxDC::GetCharWidth() const |
fb46a9a6 DW |
1151 | { |
1152 | // TODO | |
7e99520b DW |
1153 | return(8); |
1154 | } | |
1155 | ||
1156 | void wxDC::DoGetTextExtent( | |
1157 | const wxString& rsString | |
1158 | , wxCoord* pvX | |
1159 | , wxCoord* pvY | |
f44fdfb0 | 1160 | , wxCoord* pvDescent |
7e99520b DW |
1161 | , wxCoord* pvExternalLeading |
1162 | , wxFont* pTheFont | |
1163 | ) const | |
1164 | { | |
1165 | POINTL avPoint[TXTBOX_COUNT]; | |
1166 | POINTL vPtMin; | |
1167 | POINTL vPtMax; | |
1168 | int i; | |
1169 | int l; | |
1170 | FONTMETRICS vFM; // metrics structure | |
1171 | BOOL bRc; | |
1172 | char* pStr; | |
1173 | ERRORID vErrorCode; // last error id code | |
1174 | wxFont* pFontToUse = (wxFont*)pTheFont; | |
1175 | ||
1176 | if (!pFontToUse) | |
1177 | pFontToUse = (wxFont*)&m_font; | |
1178 | l = rsString.length(); | |
1179 | pStr = (PCH) rsString.c_str(); | |
fb46a9a6 | 1180 | |
7e99520b DW |
1181 | // |
1182 | // In world coordinates. | |
1183 | // | |
1184 | bRc = ::GpiQueryTextBox( m_hPS | |
1185 | ,l | |
1186 | ,pStr | |
1187 | ,TXTBOX_COUNT // return maximum information | |
1188 | ,avPoint // array of coordinates points | |
f44fdfb0 | 1189 | ); |
7e99520b DW |
1190 | if(!bRc) |
1191 | { | |
1192 | vErrorCode = ::WinGetLastError(wxGetInstance()); | |
1193 | } | |
1194 | ||
1195 | vPtMin.x = avPoint[0].x; | |
1196 | vPtMax.x = avPoint[0].x; | |
1197 | vPtMin.y = avPoint[0].y; | |
1198 | vPtMax.y = avPoint[0].y; | |
1199 | for (i = 1; i < 4; i++) | |
1200 | { | |
1201 | if(vPtMin.x > avPoint[i].x) vPtMin.x = avPoint[i].x; | |
1202 | if(vPtMin.y > avPoint[i].y) vPtMin.y = avPoint[i].y; | |
1203 | if(vPtMax.x < avPoint[i].x) vPtMax.x = avPoint[i].x; | |
1204 | if(vPtMax.y < avPoint[i].y) vPtMax.y = avPoint[i].y; | |
1205 | } | |
1206 | ::GpiQueryFontMetrics( m_hPS | |
1207 | ,sizeof(FONTMETRICS) | |
1208 | ,&vFM | |
1209 | ); | |
1210 | ||
1211 | if (pvX) | |
1212 | *pvX = (wxCoord)(vPtMax.x - vPtMin.x + 1); | |
1213 | if (pvY) | |
1214 | *pvY = (wxCoord)(vPtMax.y - vPtMin.y + 1); | |
1215 | if (pvDescent) | |
1216 | *pvDescent = vFM.lMaxDescender; | |
f44fdfb0 | 1217 | if (pvExternalLeading) |
7e99520b | 1218 | *pvExternalLeading = vFM.lExternalLeading; |
fb46a9a6 DW |
1219 | } |
1220 | ||
1221 | void wxDC::SetMapMode( int mode ) | |
1222 | { | |
1223 | // TODO: | |
1224 | }; | |
1225 | ||
1226 | void wxDC::SetUserScale(double x, double y) | |
1227 | { | |
1228 | m_userScaleX = x; | |
1229 | m_userScaleY = y; | |
1230 | ||
1231 | SetMapMode(m_mappingMode); | |
1232 | } | |
1233 | ||
1234 | void wxDC::SetAxisOrientation(bool xLeftRight, bool yBottomUp) | |
1235 | { | |
1236 | m_signX = xLeftRight ? 1 : -1; | |
1237 | m_signY = yBottomUp ? -1 : 1; | |
1238 | ||
1239 | SetMapMode(m_mappingMode); | |
1240 | } | |
1241 | ||
1242 | void wxDC::SetSystemScale(double x, double y) | |
1243 | { | |
1244 | m_scaleX = x; | |
1245 | m_scaleY = y; | |
1246 | ||
1247 | SetMapMode(m_mappingMode); | |
1248 | } | |
1249 | ||
7cdc2f1e | 1250 | void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y ) |
fb46a9a6 DW |
1251 | { |
1252 | // TODO: | |
1253 | }; | |
1254 | ||
7cdc2f1e | 1255 | void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y ) |
fb46a9a6 DW |
1256 | { |
1257 | // TODO: | |
1258 | }; | |
1259 | ||
1260 | // --------------------------------------------------------------------------- | |
1261 | // coordinates transformations | |
1262 | // --------------------------------------------------------------------------- | |
1263 | ||
7cdc2f1e | 1264 | wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const |
fb46a9a6 | 1265 | { |
f6bcfd97 BP |
1266 | return (wxCoord) (((x) - m_deviceOriginX)/(m_logicalScaleX*m_userScaleX*m_signX*m_scaleX) - m_logicalOriginX); |
1267 | } | |
fb46a9a6 | 1268 | |
7cdc2f1e | 1269 | wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const |
fb46a9a6 | 1270 | { |
f6bcfd97 BP |
1271 | return (wxCoord) ((x)/(m_logicalScaleX*m_userScaleX*m_signX*m_scaleX)); |
1272 | } | |
fb46a9a6 | 1273 | |
7cdc2f1e | 1274 | wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const |
fb46a9a6 | 1275 | { |
f6bcfd97 BP |
1276 | return (wxCoord) (((y) - m_deviceOriginY)/(m_logicalScaleY*m_userScaleY*m_signY*m_scaleY) - m_logicalOriginY); |
1277 | } | |
fb46a9a6 | 1278 | |
7cdc2f1e | 1279 | wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const |
fb46a9a6 | 1280 | { |
f6bcfd97 BP |
1281 | return (wxCoord) ((y)/(m_logicalScaleY*m_userScaleY*m_signY*m_scaleY)); |
1282 | } | |
fb46a9a6 | 1283 | |
7cdc2f1e | 1284 | wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const |
fb46a9a6 | 1285 | { |
f6bcfd97 BP |
1286 | return (wxCoord) ((x - m_logicalOriginX)*m_logicalScaleX*m_userScaleX*m_signX*m_scaleX + m_deviceOriginX); |
1287 | } | |
fb46a9a6 | 1288 | |
7cdc2f1e | 1289 | wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const |
fb46a9a6 | 1290 | { |
f6bcfd97 BP |
1291 | return (wxCoord) (x*m_logicalScaleX*m_userScaleX*m_signX*m_scaleX); |
1292 | } | |
fb46a9a6 | 1293 | |
7cdc2f1e | 1294 | wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const |
fb46a9a6 | 1295 | { |
f6bcfd97 BP |
1296 | return (wxCoord) ((y - m_logicalOriginY)*m_logicalScaleY*m_userScaleY*m_signY*m_scaleY + m_deviceOriginY); |
1297 | } | |
fb46a9a6 | 1298 | |
7cdc2f1e | 1299 | wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const |
fb46a9a6 | 1300 | { |
f6bcfd97 BP |
1301 | return (wxCoord) (y*m_logicalScaleY*m_userScaleY*m_signY*m_scaleY); |
1302 | } | |
fb46a9a6 DW |
1303 | |
1304 | // --------------------------------------------------------------------------- | |
1305 | // bit blit | |
1306 | // --------------------------------------------------------------------------- | |
1307 | ||
7cdc2f1e DW |
1308 | bool wxDC::DoBlit( wxCoord xdest |
1309 | ,wxCoord ydest | |
1310 | ,wxCoord width | |
1311 | ,wxCoord height | |
fb46a9a6 | 1312 | ,wxDC *source |
7cdc2f1e DW |
1313 | ,wxCoord xsrc |
1314 | ,wxCoord ysrc | |
fb46a9a6 DW |
1315 | ,int rop |
1316 | ,bool useMask | |
1317 | ) | |
1318 | { | |
1319 | // TODO | |
1320 | return(TRUE); | |
1321 | } | |
1322 | ||
1323 | void wxDC::DoGetSize( int* width, int* height ) const | |
1324 | { | |
1325 | // TODO: | |
1326 | }; | |
1327 | ||
1328 | void wxDC::DoGetSizeMM( int* width, int* height ) const | |
1329 | { | |
1330 | // TODO: | |
1331 | }; | |
1332 | ||
1333 | wxSize wxDC::GetPPI() const | |
1334 | { | |
1335 | int x = 1; | |
1336 | int y = 1; | |
1337 | // TODO: | |
1338 | return (wxSize(x,y)); | |
1339 | } | |
1340 | ||
1341 | void wxDC::SetLogicalScale( double x, double y ) | |
1342 | { | |
1343 | // TODO: | |
1344 | }; | |
1345 | ||
1346 | #if WXWIN_COMPATIBILITY | |
1347 | void wxDC::DoGetTextExtent(const wxString& string, float *x, float *y, | |
1348 | float *descent, float *externalLeading, | |
1349 | wxFont *theFont, bool use16bit) const | |
1350 | { | |
7cdc2f1e | 1351 | wxCoord x1, y1, descent1, externalLeading1; |
fb46a9a6 DW |
1352 | GetTextExtent(string, & x1, & y1, & descent1, & externalLeading1, theFont, use16bit); |
1353 | *x = x1; *y = y1; | |
1354 | if (descent) | |
1355 | *descent = descent1; | |
1356 | if (externalLeading) | |
1357 | *externalLeading = externalLeading1; | |
1358 | } | |
1359 | #endif | |
1360 | ||
1361 | // --------------------------------------------------------------------------- | |
1362 | // spline drawing code | |
1363 | // --------------------------------------------------------------------------- | |
1364 | ||
1365 | #if wxUSE_SPLINES | |
1366 | ||
1367 | class wxSpline: public wxObject | |
1368 | { | |
1369 | public: | |
1370 | int type; | |
1371 | wxList *points; | |
1372 | ||
1373 | wxSpline(wxList *list); | |
1374 | void DeletePoints(); | |
1375 | ||
1376 | // Doesn't delete points | |
1377 | ~wxSpline(); | |
1378 | }; | |
1379 | ||
1380 | void wx_draw_open_spline(wxDC *dc, wxSpline *spline); | |
1381 | ||
1382 | void wx_quadratic_spline(double a1, double b1, double a2, double b2, | |
1383 | double a3, double b3, double a4, double b4); | |
1384 | void wx_clear_stack(); | |
1385 | int wx_spline_pop(double *x1, double *y1, double *x2, double *y2, double *x3, | |
1386 | double *y3, double *x4, double *y4); | |
1387 | void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3, | |
1388 | double x4, double y4); | |
1389 | static bool wx_spline_add_point(double x, double y); | |
1390 | static void wx_spline_draw_point_array(wxDC *dc); | |
1391 | wxSpline *wx_make_spline(int x1, int y1, int x2, int y2, int x3, int y3); | |
1392 | ||
1393 | void wxDC::DoDrawSpline(wxList *list) | |
1394 | { | |
1395 | wxSpline spline(list); | |
1396 | ||
1397 | wx_draw_open_spline(this, &spline); | |
1398 | } | |
1399 | ||
1400 | wxList wx_spline_point_list; | |
1401 | ||
1402 | void wx_draw_open_spline(wxDC *dc, wxSpline *spline) | |
1403 | { | |
1404 | wxPoint *p; | |
1405 | double cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4; | |
1406 | double x1, y1, x2, y2; | |
1407 | ||
1408 | wxNode *node = spline->points->First(); | |
1409 | p = (wxPoint *)node->Data(); | |
1410 | ||
1411 | x1 = p->x; | |
1412 | y1 = p->y; | |
1413 | ||
1414 | node = node->Next(); | |
1415 | p = (wxPoint *)node->Data(); | |
1416 | ||
1417 | x2 = p->x; | |
1418 | y2 = p->y; | |
1419 | cx1 = (double)((x1 + x2) / 2); | |
1420 | cy1 = (double)((y1 + y2) / 2); | |
1421 | cx2 = (double)((cx1 + x2) / 2); | |
1422 | cy2 = (double)((cy1 + y2) / 2); | |
1423 | ||
1424 | wx_spline_add_point(x1, y1); | |
1425 | ||
1426 | while ((node = node->Next()) != NULL) | |
ce44c50e | 1427 | { |
fb46a9a6 DW |
1428 | p = (wxPoint *)node->Data(); |
1429 | x1 = x2; | |
1430 | y1 = y2; | |
1431 | x2 = p->x; | |
1432 | y2 = p->y; | |
1433 | cx4 = (double)(x1 + x2) / 2; | |
1434 | cy4 = (double)(y1 + y2) / 2; | |
1435 | cx3 = (double)(x1 + cx4) / 2; | |
1436 | cy3 = (double)(y1 + cy4) / 2; | |
1437 | ||
1438 | wx_quadratic_spline(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4); | |
1439 | ||
1440 | cx1 = cx4; | |
1441 | cy1 = cy4; | |
1442 | cx2 = (double)(cx1 + x2) / 2; | |
1443 | cy2 = (double)(cy1 + y2) / 2; | |
ce44c50e | 1444 | } |
fb46a9a6 DW |
1445 | |
1446 | wx_spline_add_point((double)wx_round(cx1), (double)wx_round(cy1)); | |
1447 | wx_spline_add_point(x2, y2); | |
1448 | ||
1449 | wx_spline_draw_point_array(dc); | |
1450 | ||
ce44c50e DW |
1451 | } |
1452 | ||
fb46a9a6 DW |
1453 | /********************* CURVES FOR SPLINES ***************************** |
1454 | ||
1455 | The following spline drawing routine is from | |
1456 | ||
1457 | "An Algorithm for High-Speed Curve Generation" | |
1458 | by George Merrill Chaikin, | |
1459 | Computer Graphics and Image Processing, 3, Academic Press, | |
1460 | 1974, 346-349. | |
1461 | ||
1462 | and | |
1463 | ||
1464 | "On Chaikin's Algorithm" by R. F. Riesenfeld, | |
1465 | Computer Graphics and Image Processing, 4, Academic Press, | |
1466 | 1975, 304-310. | |
1467 | ||
1468 | ***********************************************************************/ | |
1469 | ||
1470 | #define half(z1, z2) ((z1+z2)/2.0) | |
1471 | #define THRESHOLD 5 | |
1472 | ||
1473 | /* iterative version */ | |
1474 | ||
1475 | void wx_quadratic_spline(double a1, double b1, double a2, double b2, double a3, double b3, double a4, | |
1476 | double b4) | |
ce44c50e | 1477 | { |
fb46a9a6 DW |
1478 | register double xmid, ymid; |
1479 | double x1, y1, x2, y2, x3, y3, x4, y4; | |
1480 | ||
1481 | wx_clear_stack(); | |
1482 | wx_spline_push(a1, b1, a2, b2, a3, b3, a4, b4); | |
1483 | ||
1484 | while (wx_spline_pop(&x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4)) { | |
1485 | xmid = (double)half(x2, x3); | |
1486 | ymid = (double)half(y2, y3); | |
1487 | if (fabs(x1 - xmid) < THRESHOLD && fabs(y1 - ymid) < THRESHOLD && | |
1488 | fabs(xmid - x4) < THRESHOLD && fabs(ymid - y4) < THRESHOLD) { | |
1489 | wx_spline_add_point((double)wx_round(x1), (double)wx_round(y1)); | |
1490 | wx_spline_add_point((double)wx_round(xmid), (double)wx_round(ymid)); | |
1491 | } else { | |
1492 | wx_spline_push(xmid, ymid, (double)half(xmid, x3), (double)half(ymid, y3), | |
1493 | (double)half(x3, x4), (double)half(y3, y4), x4, y4); | |
1494 | wx_spline_push(x1, y1, (double)half(x1, x2), (double)half(y1, y2), | |
1495 | (double)half(x2, xmid), (double)half(y2, ymid), xmid, ymid); | |
ce44c50e | 1496 | } |
ce44c50e | 1497 | } |
fb46a9a6 | 1498 | } |
ce44c50e | 1499 | |
fb46a9a6 DW |
1500 | |
1501 | /* utilities used by spline drawing routines */ | |
1502 | ||
1503 | ||
1504 | typedef struct wx_spline_stack_struct { | |
1505 | double x1, y1, x2, y2, x3, y3, x4, y4; | |
1506 | } | |
1507 | Stack; | |
1508 | ||
1509 | #define SPLINE_STACK_DEPTH 20 | |
1510 | static Stack wx_spline_stack[SPLINE_STACK_DEPTH]; | |
1511 | static Stack *wx_stack_top; | |
1512 | static int wx_stack_count; | |
1513 | ||
1514 | void wx_clear_stack() | |
1515 | { | |
1516 | wx_stack_top = wx_spline_stack; | |
1517 | wx_stack_count = 0; | |
1518 | } | |
1519 | ||
1520 | void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4) | |
1521 | { | |
1522 | wx_stack_top->x1 = x1; | |
1523 | wx_stack_top->y1 = y1; | |
1524 | wx_stack_top->x2 = x2; | |
1525 | wx_stack_top->y2 = y2; | |
1526 | wx_stack_top->x3 = x3; | |
1527 | wx_stack_top->y3 = y3; | |
1528 | wx_stack_top->x4 = x4; | |
1529 | wx_stack_top->y4 = y4; | |
1530 | wx_stack_top++; | |
1531 | wx_stack_count++; | |
1532 | } | |
1533 | ||
1534 | int wx_spline_pop(double *x1, double *y1, double *x2, double *y2, | |
1535 | double *x3, double *y3, double *x4, double *y4) | |
1536 | { | |
1537 | if (wx_stack_count == 0) | |
1538 | return (0); | |
1539 | wx_stack_top--; | |
1540 | wx_stack_count--; | |
1541 | *x1 = wx_stack_top->x1; | |
1542 | *y1 = wx_stack_top->y1; | |
1543 | *x2 = wx_stack_top->x2; | |
1544 | *y2 = wx_stack_top->y2; | |
1545 | *x3 = wx_stack_top->x3; | |
1546 | *y3 = wx_stack_top->y3; | |
1547 | *x4 = wx_stack_top->x4; | |
1548 | *y4 = wx_stack_top->y4; | |
1549 | return (1); | |
1550 | } | |
1551 | ||
1552 | static bool wx_spline_add_point(double x, double y) | |
1553 | { | |
1554 | wxPoint *point = new wxPoint; | |
1555 | point->x = (int) x; | |
1556 | point->y = (int) y; | |
1557 | wx_spline_point_list.Append((wxObject*)point); | |
1558 | return TRUE; | |
1559 | } | |
1560 | ||
1561 | static void wx_spline_draw_point_array(wxDC *dc) | |
1562 | { | |
1563 | dc->DrawLines(&wx_spline_point_list, 0, 0); | |
1564 | wxNode *node = wx_spline_point_list.First(); | |
1565 | while (node) | |
1566 | { | |
1567 | wxPoint *point = (wxPoint *)node->Data(); | |
1568 | delete point; | |
1569 | delete node; | |
1570 | node = wx_spline_point_list.First(); | |
1571 | } | |
1572 | } | |
1573 | ||
1574 | wxSpline::wxSpline(wxList *list) | |
1575 | { | |
1576 | points = list; | |
1577 | } | |
1578 | ||
1579 | wxSpline::~wxSpline() | |
1580 | { | |
1581 | } | |
1582 | ||
1583 | void wxSpline::DeletePoints() | |
1584 | { | |
1585 | for(wxNode *node = points->First(); node; node = points->First()) | |
1586 | { | |
1587 | wxPoint *point = (wxPoint *)node->Data(); | |
1588 | delete point; | |
1589 | delete node; | |
1590 | } | |
1591 | delete points; | |
ce44c50e DW |
1592 | } |
1593 | ||
0e320a79 | 1594 | |
fb46a9a6 | 1595 | #endif // wxUSE_SPLINES |
0e320a79 | 1596 |