]> git.saurik.com Git - wxWidgets.git/blame - src/os2/dc.cpp
merged in slider validation bug from the 2.2 branch
[wxWidgets.git] / src / os2 / dc.cpp
CommitLineData
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 40static const int VIEWPORT_EXTENT = 1000;
1408104d 41
fb46a9a6
DW
42static const int MM_POINTS = 9;
43static 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
55static inline double DegToRad(double deg) { return (deg * M_PI) / 180.0; }
56
7e99520b
DW
57int 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
74int 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
89int 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
109int 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
134wxDC::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
152wxDC::~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.
160void 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
219void 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
237void 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 252void 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 279bool wxDC::CanDrawBitmap() const
0e320a79 280{
fb46a9a6
DW
281 return TRUE;
282}
0e320a79 283
fb46a9a6 284bool 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
293int wxDC::GetDepth() const
0e320a79 294{
1408104d
DW
295 // TODO:
296 return (1);
297}
0e320a79 298
fb46a9a6
DW
299// ---------------------------------------------------------------------------
300// drawing
301// ---------------------------------------------------------------------------
0e320a79 302
1408104d 303void wxDC::Clear()
0e320a79 304{
445c7bca 305 ::GpiErase(m_hPS);
1408104d 306}
0e320a79 307
51c1d535
DW
308void 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
330bool 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 349void wxDC::DoCrossHair(wxCoord x, wxCoord y)
0e320a79 350{
1408104d
DW
351 // TODO
352}
353
7e99520b
DW
354void 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;
7e99520b
DW
367 ::GpiMove(m_hPS, &vPoint[0]);
368 ::GpiLine(m_hPS, &vPoint[1]);
1408104d
DW
369}
370
51c1d535
DW
371//////////////////////////////////////////////////////////////////////////////
372// Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1)
373// and ending at (x2, y2). The current pen is used for the outline and the
374// current brush for filling the shape. The arc is drawn in an anticlockwise
375// direction from the start point to the end point.
376//////////////////////////////////////////////////////////////////////////////
377void wxDC::DoDrawArc(
378 wxCoord vX1
379, wxCoord vY1
380, wxCoord vX2
381, wxCoord vY2
382, wxCoord vXc
383, wxCoord vYc
384)
1408104d 385{
51c1d535
DW
386 POINTL vPtlPos;
387 POINTL vPtlArc[2]; // Structure for current position
388 int nDx;
389 int nDy;
390 double dRadius;
391 double dAngl1;
392 double dAngl2;
393 double dAnglmid;
394 wxCoord vXm;
395 wxCoord vYm;
396 ARCPARAMS vArcp; // Structure for arc parameters
397
398 if((vX1 == vXc && vY1 == vXc) || (vX2 == vXc && vY2 == vXc))
399 return; // Draw point ??
400 dRadius = 0.5 * ( hypot( (double)(vY1 - vYc)
401 ,(double)(vX1 - vXc)
402 ) +
403 hypot( (double)(vY2 - vYc)
404 ,(double)(vX2 - vXc)
405 )
406 );
407
408 dAngl1 = atan2( (double)(vY1 - vYc)
409 ,(double)(vX1 - vXc)
410 );
411 dAngl2 = atan2( (double)(vY2 - vYc)
412 ,(double)(vX2 - vXc)
413 );
414 if(dAngl2 < dAngl1)
415 dAngl2 += M_PI * 2;
416
417 //
418 // GpiPointArc can't draw full arc
419 //
420 if(dAngl2 == dAngl1 || (vX1 == vX2 && vY1 == vY2) )
421 {
422 //
423 // Medium point
424 //
425 dAnglmid = (dAngl1 + dAngl2)/2. + M_PI;
426 vXm = vXc + dRadius * cos(dAnglmid);
427 vYm = vYc + dRadius * sin(dAnglmid);
428 DoDrawArc( vX1
429 ,vY1
430 ,vXm
431 ,vYm
432 ,vXc
433 ,vYc
434 );
435 DoDrawArc( vXm
436 ,vYm
437 ,vX2
438 ,vY2
439 ,vXc
440 ,vYc
441 );
442 return;
443 }
444
445 //
446 // Medium point
447 //
448 dAnglmid = (dAngl1 + dAngl2)/2.;
449 vXm = vXc + dRadius * cos(dAnglmid);
450 vYm = vYc + dRadius * sin(dAnglmid);
451
452 //
453 // Ellipse main axis (r,q), (p,s) with center at (0,0) */
454 //
455 vArcp.lR = 0;
456 vArcp.lQ = 1;
457 vArcp.lP = 1;
458 vArcp.lS = 0;
459 ::GpiSetArcParams(m_hPS, &vArcp); // Sets parameters to default
460
461 vPtlPos.x = vX1; // Loads x-coordinate
462 vPtlPos.y = vY1; // Loads y-coordinate
463 ::GpiMove(m_hPS, &vPtlPos); // Sets current position
464 vPtlArc[0].x = vXm;
465 vPtlArc[0].y = vYm;
466 vPtlArc[1].x = vX2;
467 vPtlArc[1].y = vY2;
468 ::GpiPointArc(m_hPS, vPtlArc); // Draws the arc
1408104d
DW
469}
470
51c1d535
DW
471void wxDC::DoDrawCheckMark(
472 wxCoord vX1
473, wxCoord vY1
474, wxCoord vWidth
475, wxCoord vHeight
476)
f6bcfd97 477{
51c1d535
DW
478 POINTL vPoint[2];
479
480 vPoint[0].x = vX1;
481 vPoint[0].y = vY1;
482 vPoint[1].x = vX1 + vWidth;
483 vPoint[1].y = vY1 + vHeight;
484
485 ::GpiMove(m_hPS, &vPoint[0]);
486 ::GpiBox( m_hPS // handle to a presentation space
487 ,DRO_OUTLINE // draw the box outline ? or ?
488 ,&vPoint[1] // address of the corner
489 ,0L // horizontal corner radius
490 ,0L // vertical corner radius
491 );
492 if(vWidth > 4 && vHeight > 4)
493 {
494 int nTmp;
495
496 vPoint[0].x += 2; vPoint[0].y += 2;
497 vPoint[1].x -= 2; vPoint[1].y -= 2;
498 ::GpiMove(m_hPS, &vPoint[0]);
499 ::GpiLine(m_hPS, &vPoint[1]);
500 nTmp = vPoint[0].x;
501 vPoint[0].x = vPoint[1].x;
502 vPoint[1].x = nTmp;
503 ::GpiMove(m_hPS, &vPoint[0]);
504 ::GpiLine(m_hPS, &vPoint[1]);
505 }
f6bcfd97
BP
506}
507
51c1d535
DW
508void wxDC::DoDrawPoint(
509 wxCoord vX
510, wxCoord vY
511)
1408104d 512{
51c1d535
DW
513 POINTL vPoint;
514
515 vPoint.x = vX;
516 vPoint.y = vY;
517 ::GpiSetPel(m_hPS, &vPoint);
1408104d
DW
518}
519
51c1d535
DW
520void wxDC::DoDrawPolygon(
521 int n
522, wxPoint vPoints[]
523, wxCoord vXoffset
524, wxCoord vYoffset
525, int nFillStyle
526)
1408104d 527{
51c1d535
DW
528 ULONG ulCount = 1; // Number of polygons.
529 POLYGON vPlgn; // polygon.
530 ULONG flOptions = 0L; // Drawing options.
531
532//////////////////////////////////////////////////////////////////////////////
533// This contains fields of option bits... to draw boundary lines as well as
534// the area interior.
535//
536// Drawing boundary lines:
537// POLYGON_NOBOUNDARY Does not draw boundary lines.
538// POLYGON_BOUNDARY Draws boundary lines (the default).
539//
540// Construction of the area interior:
541// POLYGON_ALTERNATE Constructs interior in alternate mode
542// (the default).
543// POLYGON_WINDING Constructs interior in winding mode.
544//////////////////////////////////////////////////////////////////////////////
545
546 ULONG flModel = 0L; // Drawing model.
547
548//////////////////////////////////////////////////////////////////////////////
549// Drawing model.
550// POLYGON_INCL Fill is inclusive of bottom right (the default).
551// POLYGON_EXCL Fill is exclusive of bottom right.
552// This is provided to aid migration from other graphics models.
553//////////////////////////////////////////////////////////////////////////////
554
555 LONG lHits = 0L; // Correlation/error indicator.
556 POINTL vPoint;
557 int i;
558 int nIsTRANSPARENT = 0;
559 LONG lBorderColor = 0L;
560 LONG lColor = 0L;
561
562 lBorderColor = m_pen.GetColour().GetPixel();
563 lColor = m_brush.GetColour().GetPixel();
564 if(m_brush.GetStyle() == wxTRANSPARENT)
565 nIsTRANSPARENT = 1;
566
567 vPlgn.ulPoints = n;
568 vPlgn.aPointl = (POINTL*) calloc( n + 1
569 ,sizeof(POINTL)
570 ); // well, new will call malloc
571
572 for(i = 0; i < n; i++)
573 {
574 vPlgn.aPointl[i].x = vPoints[i].x; // +xoffset;
575 vPlgn.aPointl[i].y = vPoints[i].y; // +yoffset;
576 }
577 flModel = POLYGON_BOUNDARY;
578 if(nFillStyle == wxWINDING_RULE)
579 flModel |= POLYGON_WINDING;
580 else
581 flModel |= POLYGON_ALTERNATE;
582
583 vPoint.x = vXoffset;
584 vPoint.y = vYoffset;
585
586 ::GpiSetColor(m_hPS, lBorderColor);
587 ::GpiMove(m_hPS, &vPoint);
588 lHits = ::GpiPolygons(m_hPS, ulCount, &vPlgn, flOptions, flModel);
589 free(vPlgn.aPointl);
1408104d
DW
590}
591
51c1d535
DW
592void wxDC::DoDrawLines(
593 int n
594, wxPoint vPoints[]
595, wxCoord vXoffset
596, wxCoord vYoffset
597)
1408104d 598{
51c1d535
DW
599 int i;
600 POINTL vPoint;
601
602 vPoint.x = vPoints[0].x + vXoffset;
603 vPoint.y = vPoints[0].y + vYoffset;
604 ::GpiMove(m_hPS, &vPoint);
605
606 LONG lBorderColor = m_pen.GetColour().GetPixel();
607
608 ::GpiSetColor(m_hPS, lBorderColor);
609 for(i = 1; i < n; i++)
610 {
611 vPoint.x = vPoints[0].x + vXoffset;
612 vPoint.y = vPoints[0].y + vYoffset;
613 ::GpiLine(m_hPS, &vPoint);
614 }
1408104d
DW
615}
616
7e99520b 617void wxDC::DoDrawRectangle(
f44fdfb0 618 wxCoord vX
7e99520b
DW
619, wxCoord vY
620, wxCoord vWidth
621, wxCoord vHeight
622)
1408104d 623{
7e99520b 624 POINTL vPoint[2];
51c1d535
DW
625 LONG lControl;
626 LONG lColor;
627 LONG lBorderColor;
628 int nIsTRANSPARENT = 0;
7e99520b
DW
629
630 vPoint[0].x = vX;
631 vPoint[0].y = vY;
f44fdfb0 632 vPoint[1].x = vX + vWidth;
26ac77db 633 vPoint[1].y = vY - vHeight;
7e99520b 634 ::GpiMove(m_hPS, &vPoint[0]);
51c1d535
DW
635 lColor = m_brush.GetColour().GetPixel();
636 lBorderColor = m_pen.GetColour().GetPixel();
637 if (m_brush.GetStyle() == wxTRANSPARENT)
638 nIsTRANSPARENT = 1;
639 if(lColor == lBorderColor || nIsTRANSPARENT)
640 {
641 lControl = DRO_OUTLINEFILL; //DRO_FILL;
642 if(m_brush.GetStyle() == wxTRANSPARENT)
643 lControl = DRO_OUTLINE;
644
26ac77db 645 ::GpiSetColor(m_hPS, CLR_GREEN);
51c1d535
DW
646 ::GpiBox( m_hPS // handle to a presentation space
647 ,lControl // draw the box outline ? or ?
648 ,&vPoint[1] // address of the corner
649 ,0L // horizontal corner radius
650 ,0L // vertical corner radius
651 );
652 }
653 else
654 {
655 lControl = DRO_OUTLINE;
656 ::GpiSetColor( m_hPS
657 ,lBorderColor
658 );
659 ::GpiBox( m_hPS
660 ,lControl
661 ,&vPoint[1]
662 ,0L
663 ,0L
664 );
665 lControl = DRO_FILL;
666 ::GpiSetColor( m_hPS
667 ,lColor
668 );
669 ::GpiBox( m_hPS
670 ,lControl
671 ,&vPoint[1]
672 ,0L
673 ,0L
674 );
675 }
1408104d
DW
676}
677
7e99520b
DW
678void wxDC::DoDrawRoundedRectangle(
679 wxCoord vX
680, wxCoord vY
681, wxCoord vWidth
682, wxCoord vHeight
683, double dRadius
684)
1408104d 685{
7e99520b 686 POINTL vPoint[2];
51c1d535 687 LONG lControl;
7e99520b
DW
688
689 vPoint[0].x = vX;
690 vPoint[0].y = vY;
691 vPoint[1].x = vX + vWidth;
51c1d535 692 vPoint[1].y = vY + vHeight;
7e99520b 693 ::GpiMove(m_hPS, &vPoint[0]);
51c1d535
DW
694
695 lControl = DRO_OUTLINEFILL; //DRO_FILL;
696 if (m_brush.GetStyle() == wxTRANSPARENT)
697 lControl = DRO_OUTLINE;
f44fdfb0
DW
698 ::GpiBox( m_hPS // handle to a presentation space
699 ,DRO_OUTLINE // draw the box outline ? or ?
700 ,&vPoint[1] // address of the corner
701 ,(LONG)dRadius // horizontal corner radius
702 ,(LONG)dRadius // vertical corner radius
7e99520b 703 );
1408104d
DW
704}
705
51c1d535
DW
706// Draw Ellipse within box (x,y) - (x+width, y+height)
707void wxDC::DoDrawEllipse(
708 wxCoord vX
709, wxCoord vY
710, wxCoord vWidth
711, wxCoord vHeight
712)
1408104d 713{
51c1d535
DW
714 POINTL vPtlPos; // Structure for current position
715 FIXED vFxMult; // Multiplier for ellipse
716 ARCPARAMS vArcp; // Structure for arc parameters
717
718 vArcp.lR = 0;
719 vArcp.lQ = vHeight/2;
720 vArcp.lP = vWidth/2;
721 vArcp.lS = 0;
722 ::GpiSetArcParams( m_hPS
723 ,&vArcp
724 ); // Sets parameters to default
725 vPtlPos.x = vX + vWidth/2; // Loads x-coordinate
726 vPtlPos.y = vY + vHeight/2; // Loads y-coordinate
727 ::GpiMove( m_hPS
728 ,&vPtlPos
729 ); // Sets current position
730 vFxMult = MAKEFIXED(1, 0); /* Sets multiplier */
731
732 //
733 // DRO_FILL, DRO_OTLINEFILL - where to get
734 //
735 ::GpiFullArc( m_hPS
736 ,DRO_OUTLINE
737 ,vFxMult
738 ); // Draws full arc with center at current position
1408104d
DW
739}
740
51c1d535
DW
741void wxDC::DoDrawEllipticArc(
742 wxCoord vX
743, wxCoord vY
744, wxCoord vWidth
745, wxCoord vHeight
746, double dSa
747, double dEa
748)
1408104d 749{
51c1d535
DW
750 POINTL vPtlPos; // Structure for current position
751 FIXED vFxMult; // Multiplier for ellipse
752 ARCPARAMS vArcp; // Structure for arc parameters
753 FIXED vFSa;
754 FIXED vFSweepa; // Start angle, sweep angle
755 double dIntPart;
756 double dFractPart;
757 double dRadius;
758
759 dFractPart = modf(dSa,&dIntPart);
760 vFSa = MAKEFIXED((int)dIntPart, (int)(dFractPart * 0xffff) );
761 dFractPart = modf(dEa - dSa, &dIntPart);
762 vFSweepa = MAKEFIXED((int)dIntPart, (int)(dFractPart * 0xffff) );
763
764 //
765 // Ellipse main axis (r,q), (p,s) with center at (0,0)
766 //
767 vArcp.lR = 0;
768 vArcp.lQ = vHeight/2;
769 vArcp.lP = vWidth/2;
770 vArcp.lS = 0;
771 ::GpiSetArcParams(m_hPS, &vArcp); // Sets parameters to default
772 vPtlPos.x = vX + vWidth/2 * (1. + cos(DegToRad(dSa))); // Loads x-coordinate
773 vPtlPos.y = vY + vHeight/2 * (1. + sin(DegToRad(dSa))); // Loads y-coordinate
774 ::GpiMove(m_hPS, &vPtlPos); // Sets current position
775
776 //
777 // May be not to the center ?
778 //
779 vPtlPos.x = vX + vWidth/2 ; // Loads x-coordinate
780 vPtlPos.y = vY + vHeight/2; // Loads y-coordinate
781 vFxMult = MAKEFIXED(1, 0); // Sets multiplier
782
783 //
784 // DRO_FILL, DRO_OTLINEFILL - where to get
785 //
786 ::GpiPartialArc( m_hPS
787 ,&vPtlPos
788 ,vFxMult
789 ,vFSa
790 ,vFSweepa
791 );
1408104d
DW
792}
793
7cdc2f1e 794void wxDC::DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y)
1408104d 795{
51c1d535 796 // TODO:
1408104d
DW
797}
798
fb46a9a6 799void wxDC::DoDrawBitmap( const wxBitmap &bmp
7cdc2f1e 800 ,wxCoord x, wxCoord y
fb46a9a6
DW
801 ,bool useMask
802 )
1408104d
DW
803{
804 // TODO
805}
806
7e99520b
DW
807void wxDC::DoDrawText(
808 const wxString& rsText
809, wxCoord vX
810, wxCoord vY
811)
1408104d 812{
7e99520b
DW
813 DrawAnyText( rsText
814 ,vX
815 ,vY
816 );
1408104d
DW
817}
818
7e99520b
DW
819void wxDC::DrawAnyText(
820 const wxString& rsText
821, wxCoord vX
822, wxCoord vY
823)
f6bcfd97 824{
7e99520b
DW
825 int nOldBackground = 0;
826 POINTL vPtlStart;
827 LONG lHits;
f6bcfd97 828
7e99520b
DW
829 //
830 // prepare for drawing the text
831 //
832
833 //
834 // Set text color attributes
835 //
836 if (m_textForegroundColour.Ok())
837 {
838 SetTextColor( m_hPS
839 ,(int)m_textForegroundColour.GetPixel()
840 );
841 }
842
843 if (m_textBackgroundColour.Ok())
844 {
845 nOldBackground = SetTextBkColor( m_hPS
846 ,(int)m_textBackgroundColour.GetPixel()
847 );
848 }
849 SetBkMode( m_hPS
850 ,m_backgroundMode
851 );
852 vPtlStart.x = vX;
853 vPtlStart.y = vY;
854
855 lHits = ::GpiCharStringAt( m_hPS
856 ,&vPtlStart
857 ,rsText.length()
858 ,(PCH)rsText.c_str()
859 );
860 if (lHits != GPI_OK)
861 {
862 wxLogLastError(wxT("TextOut"));
863 }
864
865 //
866 // Restore the old parameters (text foreground colour may be left because
867 // it never is set to anything else, but background should remain
868 // transparent even if we just drew an opaque string)
869 //
870 if (m_textBackgroundColour.Ok())
871 SetTextBkColor( m_hPS
872 ,nOldBackground
873 );
874 SetBkMode( m_hPS
875 ,wxTRANSPARENT
876 );
877}
878
879void wxDC::DoDrawRotatedText(
880 const wxString& rsText
881, wxCoord vX
882, wxCoord vY
883, double dAngle
884)
c8ce6bcc 885{
7e99520b
DW
886 if (dAngle == 0.0)
887 {
888 DoDrawText( rsText
889 ,vX
890 ,vY
891 );
892 }
893
c8ce6bcc
DW
894 // TODO:
895 /*
896 if ( angle == 0.0 )
897 {
898 DoDrawText(text, x, y);
899 }
900 else
901 {
902 LOGFONT lf;
903 wxFillLogFont(&lf, &m_font);
904
905 // GDI wants the angle in tenth of degree
906 long angle10 = (long)(angle * 10);
907 lf.lfEscapement = angle10;
908 lf. lfOrientation = angle10;
909
910 HFONT hfont = ::CreateFontIndirect(&lf);
911 if ( !hfont )
912 {
913 wxLogLastError("CreateFont");
914 }
915 else
916 {
917 HFONT hfontOld = ::SelectObject(GetHdc(), hfont);
918
919 DrawAnyText(text, x, y);
920
921 (void)::SelectObject(GetHdc(), hfontOld);
922 }
923
924 // call the bounding box by adding all four vertices of the rectangle
925 // containing the text to it (simpler and probably not slower than
926 // determining which of them is really topmost/leftmost/...)
927 wxCoord w, h;
928 GetTextExtent(text, &w, &h);
929
930 double rad = DegToRad(angle);
931
932 // "upper left" and "upper right"
933 CalcBoundingBox(x, y);
934 CalcBoundingBox(x + w*cos(rad), y - h*sin(rad));
935 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
936
937 // "bottom left" and "bottom right"
938 x += (wxCoord)(h*sin(rad));
939 y += (wxCoord)(h*cos(rad));
940 CalcBoundingBox(x, y);
941 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
942 }
943*/
944}
945
fb46a9a6
DW
946// ---------------------------------------------------------------------------
947// set GDI objects
948// ---------------------------------------------------------------------------
1408104d 949
fb46a9a6 950void wxDC::SetPalette(const wxPalette& palette)
1408104d
DW
951{
952 // TODO
953}
954
f6bcfd97
BP
955void wxDC::SetFont(
956 const wxFont& rFont
957)
1408104d 958{
f6bcfd97
BP
959 //
960 // Set the old object temporarily, in case the assignment deletes an object
961 // that's not yet selected out.
962 //
963 if (m_hOldFont)
964 {
965// ::SelectObject(GetHdc(), (HFONT) m_hOldFont);
966 m_hOldFont = 0;
967 }
968
969 m_font = rFont;
970
971 if (!rFont.Ok())
972 {
973 if (m_hOldFont)
974// ::SelectObject(GetHdc(), (HFONT) m_hOldFont);
975 m_hOldFont = 0;
976 }
977
978 if (m_font.Ok() && m_font.GetResourceHandle())
979 {
980 HFONT hFont = (HFONT)0; //::SelectObject(GetHdc(), (HFONT) m_font.GetResourceHandle());
981 if (hFont == (HFONT) NULL)
982 {
983 wxLogDebug(wxT("::SelectObject failed in wxDC::SetFont."));
984 }
985 if (!m_hOldFont)
986 m_hOldFont = (WXHFONT) hFont;
987 }
1408104d
DW
988}
989
7e99520b
DW
990void wxDC::SetPen(
991 const wxPen& rPen
992)
1408104d 993{
7e99520b
DW
994 wxCHECK_RET( Ok(), wxT("invalid window dc") );
995
996 if (m_pen == rPen)
997 return;
998 m_pen = rPen;
999 if (!m_pen.Ok())
1000 return;
1001
26ac77db
DW
1002 if (m_hOldPen)
1003 m_hOldPen = 0L;
1004 m_pen = rPen;
7e99520b 1005
26ac77db 1006 if (!m_pen.Ok())
7e99520b 1007 {
26ac77db
DW
1008 if (m_hOldPen)
1009 {
1010 m_pen.SetPS((HPS)m_hOldPen);
1011 }
1012 m_hOldPen = 0L;
7e99520b 1013 }
51c1d535 1014
26ac77db 1015 if (m_pen.Ok())
51c1d535 1016 {
26ac77db
DW
1017 if (m_pen.GetResourceHandle())
1018 {
1019 m_pen.SetPS(m_hPS);
1020 if (!m_hOldPen)
1021 m_hOldPen = m_pen.GetPS();
1022 }
51c1d535 1023 }
51c1d535 1024
1408104d 1025}
7e99520b 1026
51c1d535
DW
1027void wxDC::SetBrush(
1028 const wxBrush& rBrush
1029)
1408104d
DW
1030{
1031 // TODO
1032}
1033
fb46a9a6 1034void wxDC::SetBackground(const wxBrush& brush)
1408104d
DW
1035{
1036 // TODO
1037}
1038
7e99520b
DW
1039void wxDC::SetBackgroundMode(
1040 int nMode
1041)
1408104d 1042{
7e99520b 1043 m_backgroundMode = nMode;
1408104d
DW
1044}
1045
fb46a9a6 1046void wxDC::SetLogicalFunction(int function)
1408104d
DW
1047{
1048 // TODO
1049}
1408104d 1050
ce44c50e
DW
1051void wxDC::SetRop(WXHDC dc)
1052{
1053 if (!dc || m_logicalFunction < 0)
1054 return;
1055
1056 int c_rop;
1057 // These may be wrong
1058 switch (m_logicalFunction)
1059 {
1060// TODO: Figure this stuff out
1061 // case wxXOR: c_rop = R2_XORPEN; break;
1062// case wxXOR: c_rop = R2_NOTXORPEN; break;
1063// case wxINVERT: c_rop = R2_NOT; break;
1064// case wxOR_REVERSE: c_rop = R2_MERGEPENNOT; break;
1065// case wxAND_REVERSE: c_rop = R2_MASKPENNOT; break;
1066// case wxCLEAR: c_rop = R2_WHITE; break;
1067// case wxSET: c_rop = R2_BLACK; break;
1068// case wxSRC_INVERT: c_rop = R2_NOTCOPYPEN; break;
1069// case wxOR_INVERT: c_rop = R2_MERGENOTPEN; break;
1070// case wxAND: c_rop = R2_MASKPEN; break;
1071// case wxOR: c_rop = R2_MERGEPEN; break;
1072// case wxAND_INVERT: c_rop = R2_MASKNOTPEN; break;
1073// case wxEQUIV:
1074// case wxNAND:
1075// case wxCOPY:
1076 default:
1077// c_rop = R2_COPYPEN;
1078 break;
1079 }
1080// SetROP2((HDC) dc, c_rop);
1081}
1082
fb46a9a6 1083bool wxDC::StartDoc(const wxString& message)
ce44c50e 1084{
fb46a9a6
DW
1085 // We might be previewing, so return TRUE to let it continue.
1086 return TRUE;
1087}
1088
1089void wxDC::EndDoc()
1090{
1091}
1092
1093void wxDC::StartPage()
1094{
1095}
1096
1097void wxDC::EndPage()
1098{
1099}
1100
1101// ---------------------------------------------------------------------------
1102// text metrics
1103// ---------------------------------------------------------------------------
1104
7cdc2f1e 1105wxCoord wxDC::GetCharHeight() const
fb46a9a6 1106{
05a8bfed
DW
1107 FONTMETRICS vFM; // metrics structure
1108
1109 ::GpiQueryFontMetrics( m_hPS
1110 ,sizeof(FONTMETRICS)
1111 ,&vFM
1112 );
1113 return YDEV2LOGREL(vFM.lXHeight);
fb46a9a6
DW
1114}
1115
7cdc2f1e 1116wxCoord wxDC::GetCharWidth() const
fb46a9a6 1117{
05a8bfed
DW
1118 FONTMETRICS vFM; // metrics structure
1119
1120 ::GpiQueryFontMetrics( m_hPS
1121 ,sizeof(FONTMETRICS)
1122 ,&vFM
1123 );
1124 return XDEV2LOGREL(vFM.lAveCharWidth);
7e99520b
DW
1125}
1126
1127void wxDC::DoGetTextExtent(
1128 const wxString& rsString
1129, wxCoord* pvX
1130, wxCoord* pvY
f44fdfb0 1131, wxCoord* pvDescent
7e99520b
DW
1132, wxCoord* pvExternalLeading
1133, wxFont* pTheFont
1134) const
1135{
1136 POINTL avPoint[TXTBOX_COUNT];
1137 POINTL vPtMin;
1138 POINTL vPtMax;
1139 int i;
1140 int l;
1141 FONTMETRICS vFM; // metrics structure
1142 BOOL bRc;
1143 char* pStr;
1144 ERRORID vErrorCode; // last error id code
1145 wxFont* pFontToUse = (wxFont*)pTheFont;
1146
1147 if (!pFontToUse)
1148 pFontToUse = (wxFont*)&m_font;
1149 l = rsString.length();
1150 pStr = (PCH) rsString.c_str();
fb46a9a6 1151
7e99520b
DW
1152 //
1153 // In world coordinates.
1154 //
1155 bRc = ::GpiQueryTextBox( m_hPS
1156 ,l
1157 ,pStr
1158 ,TXTBOX_COUNT // return maximum information
1159 ,avPoint // array of coordinates points
f44fdfb0 1160 );
7e99520b
DW
1161 if(!bRc)
1162 {
1163 vErrorCode = ::WinGetLastError(wxGetInstance());
1164 }
1165
1166 vPtMin.x = avPoint[0].x;
1167 vPtMax.x = avPoint[0].x;
1168 vPtMin.y = avPoint[0].y;
1169 vPtMax.y = avPoint[0].y;
1170 for (i = 1; i < 4; i++)
1171 {
1172 if(vPtMin.x > avPoint[i].x) vPtMin.x = avPoint[i].x;
1173 if(vPtMin.y > avPoint[i].y) vPtMin.y = avPoint[i].y;
1174 if(vPtMax.x < avPoint[i].x) vPtMax.x = avPoint[i].x;
1175 if(vPtMax.y < avPoint[i].y) vPtMax.y = avPoint[i].y;
1176 }
1177 ::GpiQueryFontMetrics( m_hPS
1178 ,sizeof(FONTMETRICS)
1179 ,&vFM
1180 );
1181
1182 if (pvX)
1183 *pvX = (wxCoord)(vPtMax.x - vPtMin.x + 1);
1184 if (pvY)
1185 *pvY = (wxCoord)(vPtMax.y - vPtMin.y + 1);
1186 if (pvDescent)
1187 *pvDescent = vFM.lMaxDescender;
f44fdfb0 1188 if (pvExternalLeading)
7e99520b 1189 *pvExternalLeading = vFM.lExternalLeading;
fb46a9a6
DW
1190}
1191
1192void wxDC::SetMapMode( int mode )
1193{
1194 // TODO:
1195};
1196
1197void wxDC::SetUserScale(double x, double y)
1198{
1199 m_userScaleX = x;
1200 m_userScaleY = y;
1201
1202 SetMapMode(m_mappingMode);
1203}
1204
1205void wxDC::SetAxisOrientation(bool xLeftRight, bool yBottomUp)
1206{
1207 m_signX = xLeftRight ? 1 : -1;
1208 m_signY = yBottomUp ? -1 : 1;
1209
1210 SetMapMode(m_mappingMode);
1211}
1212
1213void wxDC::SetSystemScale(double x, double y)
1214{
1215 m_scaleX = x;
1216 m_scaleY = y;
1217
1218 SetMapMode(m_mappingMode);
1219}
1220
7cdc2f1e 1221void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y )
fb46a9a6
DW
1222{
1223 // TODO:
1224};
1225
7cdc2f1e 1226void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y )
fb46a9a6 1227{
26ac77db
DW
1228 RECTL vRect;
1229
1230 ::GpiQueryPageViewport( m_hPS
1231 ,&vRect
1232 );
1233 vRect.xLeft += x;
1234 vRect.xRight += x;
1235 vRect.yBottom -= y;
1236 vRect.yTop -= y;
1237 ::GpiSetPageViewport( m_hPS
1238 ,&vRect
1239 );
fb46a9a6
DW
1240};
1241
1242// ---------------------------------------------------------------------------
1243// coordinates transformations
1244// ---------------------------------------------------------------------------
1245
7cdc2f1e 1246wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const
fb46a9a6 1247{
f6bcfd97
BP
1248 return (wxCoord) (((x) - m_deviceOriginX)/(m_logicalScaleX*m_userScaleX*m_signX*m_scaleX) - m_logicalOriginX);
1249}
fb46a9a6 1250
7cdc2f1e 1251wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const
fb46a9a6 1252{
f6bcfd97
BP
1253 return (wxCoord) ((x)/(m_logicalScaleX*m_userScaleX*m_signX*m_scaleX));
1254}
fb46a9a6 1255
7cdc2f1e 1256wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const
fb46a9a6 1257{
f6bcfd97
BP
1258 return (wxCoord) (((y) - m_deviceOriginY)/(m_logicalScaleY*m_userScaleY*m_signY*m_scaleY) - m_logicalOriginY);
1259}
fb46a9a6 1260
7cdc2f1e 1261wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const
fb46a9a6 1262{
f6bcfd97
BP
1263 return (wxCoord) ((y)/(m_logicalScaleY*m_userScaleY*m_signY*m_scaleY));
1264}
fb46a9a6 1265
7cdc2f1e 1266wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const
fb46a9a6 1267{
f6bcfd97
BP
1268 return (wxCoord) ((x - m_logicalOriginX)*m_logicalScaleX*m_userScaleX*m_signX*m_scaleX + m_deviceOriginX);
1269}
fb46a9a6 1270
7cdc2f1e 1271wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const
fb46a9a6 1272{
f6bcfd97
BP
1273 return (wxCoord) (x*m_logicalScaleX*m_userScaleX*m_signX*m_scaleX);
1274}
fb46a9a6 1275
7cdc2f1e 1276wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const
fb46a9a6 1277{
f6bcfd97
BP
1278 return (wxCoord) ((y - m_logicalOriginY)*m_logicalScaleY*m_userScaleY*m_signY*m_scaleY + m_deviceOriginY);
1279}
fb46a9a6 1280
7cdc2f1e 1281wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const
fb46a9a6 1282{
f6bcfd97
BP
1283 return (wxCoord) (y*m_logicalScaleY*m_userScaleY*m_signY*m_scaleY);
1284}
fb46a9a6
DW
1285
1286// ---------------------------------------------------------------------------
1287// bit blit
1288// ---------------------------------------------------------------------------
1289
7cdc2f1e
DW
1290bool wxDC::DoBlit( wxCoord xdest
1291 ,wxCoord ydest
1292 ,wxCoord width
1293 ,wxCoord height
fb46a9a6 1294 ,wxDC *source
7cdc2f1e
DW
1295 ,wxCoord xsrc
1296 ,wxCoord ysrc
fb46a9a6
DW
1297 ,int rop
1298 ,bool useMask
1299 )
1300{
1301 // TODO
1302 return(TRUE);
1303}
1304
1305void wxDC::DoGetSize( int* width, int* height ) const
1306{
1307 // TODO:
1308};
1309
1310void wxDC::DoGetSizeMM( int* width, int* height ) const
1311{
1312 // TODO:
1313};
1314
1315wxSize wxDC::GetPPI() const
1316{
1317 int x = 1;
1318 int y = 1;
1319 // TODO:
1320 return (wxSize(x,y));
1321}
1322
1323void wxDC::SetLogicalScale( double x, double y )
1324{
1325 // TODO:
1326};
1327
1328#if WXWIN_COMPATIBILITY
1329void wxDC::DoGetTextExtent(const wxString& string, float *x, float *y,
1330 float *descent, float *externalLeading,
1331 wxFont *theFont, bool use16bit) const
1332{
7cdc2f1e 1333 wxCoord x1, y1, descent1, externalLeading1;
fb46a9a6
DW
1334 GetTextExtent(string, & x1, & y1, & descent1, & externalLeading1, theFont, use16bit);
1335 *x = x1; *y = y1;
1336 if (descent)
1337 *descent = descent1;
1338 if (externalLeading)
1339 *externalLeading = externalLeading1;
1340}
1341#endif
1342
1343// ---------------------------------------------------------------------------
1344// spline drawing code
1345// ---------------------------------------------------------------------------
1346
1347#if wxUSE_SPLINES
1348
1349class wxSpline: public wxObject
1350{
1351public:
1352 int type;
1353 wxList *points;
1354
1355 wxSpline(wxList *list);
1356 void DeletePoints();
1357
1358 // Doesn't delete points
1359 ~wxSpline();
1360};
1361
1362void wx_draw_open_spline(wxDC *dc, wxSpline *spline);
1363
1364void wx_quadratic_spline(double a1, double b1, double a2, double b2,
1365 double a3, double b3, double a4, double b4);
1366void wx_clear_stack();
1367int wx_spline_pop(double *x1, double *y1, double *x2, double *y2, double *x3,
1368 double *y3, double *x4, double *y4);
1369void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3,
1370 double x4, double y4);
1371static bool wx_spline_add_point(double x, double y);
1372static void wx_spline_draw_point_array(wxDC *dc);
1373wxSpline *wx_make_spline(int x1, int y1, int x2, int y2, int x3, int y3);
1374
1375void wxDC::DoDrawSpline(wxList *list)
1376{
1377 wxSpline spline(list);
1378
1379 wx_draw_open_spline(this, &spline);
1380}
1381
1382wxList wx_spline_point_list;
1383
1384void wx_draw_open_spline(wxDC *dc, wxSpline *spline)
1385{
1386 wxPoint *p;
1387 double cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4;
1388 double x1, y1, x2, y2;
1389
1390 wxNode *node = spline->points->First();
1391 p = (wxPoint *)node->Data();
1392
1393 x1 = p->x;
1394 y1 = p->y;
1395
1396 node = node->Next();
1397 p = (wxPoint *)node->Data();
1398
1399 x2 = p->x;
1400 y2 = p->y;
1401 cx1 = (double)((x1 + x2) / 2);
1402 cy1 = (double)((y1 + y2) / 2);
1403 cx2 = (double)((cx1 + x2) / 2);
1404 cy2 = (double)((cy1 + y2) / 2);
1405
1406 wx_spline_add_point(x1, y1);
1407
1408 while ((node = node->Next()) != NULL)
ce44c50e 1409 {
fb46a9a6
DW
1410 p = (wxPoint *)node->Data();
1411 x1 = x2;
1412 y1 = y2;
1413 x2 = p->x;
1414 y2 = p->y;
1415 cx4 = (double)(x1 + x2) / 2;
1416 cy4 = (double)(y1 + y2) / 2;
1417 cx3 = (double)(x1 + cx4) / 2;
1418 cy3 = (double)(y1 + cy4) / 2;
1419
1420 wx_quadratic_spline(cx1, cy1, cx2, cy2, cx3, cy3, cx4, cy4);
1421
1422 cx1 = cx4;
1423 cy1 = cy4;
1424 cx2 = (double)(cx1 + x2) / 2;
1425 cy2 = (double)(cy1 + y2) / 2;
ce44c50e 1426 }
fb46a9a6
DW
1427
1428 wx_spline_add_point((double)wx_round(cx1), (double)wx_round(cy1));
1429 wx_spline_add_point(x2, y2);
1430
1431 wx_spline_draw_point_array(dc);
1432
ce44c50e
DW
1433}
1434
fb46a9a6
DW
1435/********************* CURVES FOR SPLINES *****************************
1436
1437 The following spline drawing routine is from
1438
1439 "An Algorithm for High-Speed Curve Generation"
1440 by George Merrill Chaikin,
1441 Computer Graphics and Image Processing, 3, Academic Press,
1442 1974, 346-349.
1443
1444 and
1445
1446 "On Chaikin's Algorithm" by R. F. Riesenfeld,
1447 Computer Graphics and Image Processing, 4, Academic Press,
1448 1975, 304-310.
1449
1450***********************************************************************/
1451
1452#define half(z1, z2) ((z1+z2)/2.0)
1453#define THRESHOLD 5
1454
1455/* iterative version */
1456
1457void wx_quadratic_spline(double a1, double b1, double a2, double b2, double a3, double b3, double a4,
1458 double b4)
ce44c50e 1459{
fb46a9a6
DW
1460 register double xmid, ymid;
1461 double x1, y1, x2, y2, x3, y3, x4, y4;
1462
1463 wx_clear_stack();
1464 wx_spline_push(a1, b1, a2, b2, a3, b3, a4, b4);
1465
1466 while (wx_spline_pop(&x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4)) {
1467 xmid = (double)half(x2, x3);
1468 ymid = (double)half(y2, y3);
1469 if (fabs(x1 - xmid) < THRESHOLD && fabs(y1 - ymid) < THRESHOLD &&
1470 fabs(xmid - x4) < THRESHOLD && fabs(ymid - y4) < THRESHOLD) {
1471 wx_spline_add_point((double)wx_round(x1), (double)wx_round(y1));
1472 wx_spline_add_point((double)wx_round(xmid), (double)wx_round(ymid));
1473 } else {
1474 wx_spline_push(xmid, ymid, (double)half(xmid, x3), (double)half(ymid, y3),
1475 (double)half(x3, x4), (double)half(y3, y4), x4, y4);
1476 wx_spline_push(x1, y1, (double)half(x1, x2), (double)half(y1, y2),
1477 (double)half(x2, xmid), (double)half(y2, ymid), xmid, ymid);
ce44c50e 1478 }
ce44c50e 1479 }
fb46a9a6 1480}
ce44c50e 1481
fb46a9a6
DW
1482
1483/* utilities used by spline drawing routines */
1484
1485
1486typedef struct wx_spline_stack_struct {
1487 double x1, y1, x2, y2, x3, y3, x4, y4;
1488}
1489Stack;
1490
1491#define SPLINE_STACK_DEPTH 20
1492static Stack wx_spline_stack[SPLINE_STACK_DEPTH];
1493static Stack *wx_stack_top;
1494static int wx_stack_count;
1495
1496void wx_clear_stack()
1497{
1498 wx_stack_top = wx_spline_stack;
1499 wx_stack_count = 0;
1500}
1501
1502void wx_spline_push(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
1503{
1504 wx_stack_top->x1 = x1;
1505 wx_stack_top->y1 = y1;
1506 wx_stack_top->x2 = x2;
1507 wx_stack_top->y2 = y2;
1508 wx_stack_top->x3 = x3;
1509 wx_stack_top->y3 = y3;
1510 wx_stack_top->x4 = x4;
1511 wx_stack_top->y4 = y4;
1512 wx_stack_top++;
1513 wx_stack_count++;
1514}
1515
1516int wx_spline_pop(double *x1, double *y1, double *x2, double *y2,
1517 double *x3, double *y3, double *x4, double *y4)
1518{
1519 if (wx_stack_count == 0)
1520 return (0);
1521 wx_stack_top--;
1522 wx_stack_count--;
1523 *x1 = wx_stack_top->x1;
1524 *y1 = wx_stack_top->y1;
1525 *x2 = wx_stack_top->x2;
1526 *y2 = wx_stack_top->y2;
1527 *x3 = wx_stack_top->x3;
1528 *y3 = wx_stack_top->y3;
1529 *x4 = wx_stack_top->x4;
1530 *y4 = wx_stack_top->y4;
1531 return (1);
1532}
1533
1534static bool wx_spline_add_point(double x, double y)
1535{
1536 wxPoint *point = new wxPoint;
1537 point->x = (int) x;
1538 point->y = (int) y;
1539 wx_spline_point_list.Append((wxObject*)point);
1540 return TRUE;
1541}
1542
1543static void wx_spline_draw_point_array(wxDC *dc)
1544{
1545 dc->DrawLines(&wx_spline_point_list, 0, 0);
1546 wxNode *node = wx_spline_point_list.First();
1547 while (node)
1548 {
1549 wxPoint *point = (wxPoint *)node->Data();
1550 delete point;
1551 delete node;
1552 node = wx_spline_point_list.First();
1553 }
1554}
1555
1556wxSpline::wxSpline(wxList *list)
1557{
1558 points = list;
1559}
1560
1561wxSpline::~wxSpline()
1562{
1563}
1564
1565void wxSpline::DeletePoints()
1566{
1567 for(wxNode *node = points->First(); node; node = points->First())
1568 {
1569 wxPoint *point = (wxPoint *)node->Data();
1570 delete point;
1571 delete node;
1572 }
1573 delete points;
ce44c50e
DW
1574}
1575
0e320a79 1576
fb46a9a6 1577#endif // wxUSE_SPLINES
0e320a79 1578