]> git.saurik.com Git - wxWidgets.git/blob - src/os2/dc.cpp
3b886b9446c22615f3edfff4f65c0b79110ff8e7
[wxWidgets.git] / src / os2 / dc.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: dc.cpp
3 // Purpose: wxDC class
4 // Author: David Webster
5 // Modified by:
6 // Created: 10/14/99
7 // RCS-ID: $Id$
8 // Copyright: (c) David Webster
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
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"
25 #endif
26
27 #include "wx/dcprint.h"
28
29 #include <string.h>
30 #include <math.h>
31
32 #include "wx/os2/private.h"
33
34 IMPLEMENT_ABSTRACT_CLASS(wxDC, wxObject)
35
36 // ---------------------------------------------------------------------------
37 // constants
38 // ---------------------------------------------------------------------------
39
40 static const int VIEWPORT_EXTENT = 1000;
41
42 static const int MM_POINTS = 9;
43 static const int MM_METRIC = 10;
44
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
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
80 ::GpiQueryAttrs( hPS // presentation-space handle
81 ,PRIM_CHAR // Char primitive.
82 ,CBB_BACK_COLOR // Background color.
83 ,&vCbnd // buffer for attributes.
84 );
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
126 // ===========================================================================
127 // implementation
128 // ===========================================================================
129
130 // ---------------------------------------------------------------------------
131 // wxDC
132 // ---------------------------------------------------------------------------
133
134 wxDC::wxDC(void)
135 {
136 m_pCanvas = NULL;
137
138 m_hOldBitmap = 0;
139 m_hOldPen = 0;
140 m_hOldBrush = 0;
141 m_hOldFont = 0;
142 m_hOldPalette = 0;
143
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
150 }
151
152 wxDC::~wxDC(void)
153 {
154 }
155
156 // This will select current objects out of the DC,
157 // which is what you have to do before deleting the
158 // DC.
159 void wxDC::SelectOldObjects(WXHDC dc)
160 {
161 if (dc)
162 {
163 if (m_hOldBitmap)
164 {
165 // ::SelectObject((HDC) dc, (HBITMAP) m_oldBitmap);
166 if (m_vSelectedBitmap.Ok())
167 {
168 m_vSelectedBitmap.SetSelectedInto(NULL);
169 }
170 }
171 m_hOldBitmap = 0;
172 if (m_hOldPen)
173 {
174 // ::SelectObject((HDC) dc, (HPEN) m_oldPen);
175 }
176 m_hOldPen = 0;
177 if (m_hOldBrush)
178 {
179 // ::SelectObject((HDC) dc, (HBRUSH) m_oldBrush);
180 }
181 m_hOldBrush = 0;
182 if (m_hOldFont)
183 {
184 // ::SelectObject((HDC) dc, (HFONT) m_oldFont);
185 }
186 m_hOldFont = 0;
187 if (m_hOldPalette)
188 {
189 // ::SelectPalette((HDC) dc, (HPALETTE) m_oldPalette, TRUE);
190 }
191 m_hOldPalette = 0;
192 }
193
194 m_brush = wxNullBrush;
195 m_pen = wxNullPen;
196 m_palette = wxNullPalette;
197 m_font = wxNullFont;
198 m_backgroundBrush = wxNullBrush;
199 m_vSelectedBitmap = wxNullBitmap;
200 }
201
202 // ---------------------------------------------------------------------------
203 // clipping
204 // ---------------------------------------------------------------------------
205
206 #define DO_SET_CLIPPING_BOX() \
207 { \
208 RECTL rect; \
209 \
210 ::GpiQueryClipBox(m_hPS, &rect); \
211 \
212 m_clipX1 = (wxCoord) XDEV2LOG(rect.xLeft); \
213 m_clipY1 = (wxCoord) YDEV2LOG(rect.yTop); \
214 m_clipX2 = (wxCoord) XDEV2LOG(rect.xRight); \
215 m_clipY2 = (wxCoord) YDEV2LOG(rect.yBottom); \
216 }
217
218 void wxDC::DoSetClippingRegion(
219 wxCoord x
220 , wxCoord y
221 , wxCoord width
222 , wxCoord height
223 )
224 {
225 RECTL vRect;
226
227 m_clipping = TRUE;
228 vRect.xLeft = XLOG2DEV(x);
229 vRect.yTop = YLOG2DEV(y + height);
230 vRect.xRight = XLOG2DEV(x + width);
231 vRect.yBottom = YLOG2DEV(y);
232 ::GpiIntersectClipRectangle(m_hPS, &vRect);
233 DO_SET_CLIPPING_BOX()
234 } // end of wxDC::DoSetClippingRegion
235
236 void wxDC::DoSetClippingRegionAsRegion(
237 const wxRegion& rRegion
238 )
239 {
240 wxCHECK_RET(rRegion.GetHRGN(), wxT("invalid clipping region"));
241 HRGN hRgnOld;
242
243 m_clipping = TRUE;
244 ::GpiSetClipRegion( m_hPS
245 ,(HRGN)rRegion.GetHRGN()
246 ,&hRgnOld
247 );
248 DO_SET_CLIPPING_BOX()
249 } // end of wxDC::DoSetClippingRegionAsRegion
250
251 void wxDC::DestroyClippingRegion(void)
252 {
253 if (m_clipping && m_hPS)
254 {
255 HRGN hRgnOld;
256 RECTL vRect;
257
258 // TODO: this should restore the previous clipped region
259 // so that OnPaint processing works correctly, and
260 // the update doesn't get destroyed after the first
261 // DestroyClippingRegion
262 vRect.xLeft = XLOG2DEV(0);
263 vRect.yTop = YLOG2DEV(32000);
264 vRect.xRight = XLOG2DEV(32000);
265 vRect.yBottom = YLOG2DEV(0);
266
267 HRGN hRgn = ::GpiCreateRegion(m_hPS, 1, &vRect);
268
269 ::GpiSetClipRegion(m_hPS, hRgn, &hRgnOld);
270 }
271 m_clipping = FALSE;
272 } // end of wxDC::DestroyClippingRegion
273
274 // ---------------------------------------------------------------------------
275 // query capabilities
276 // ---------------------------------------------------------------------------
277
278 bool wxDC::CanDrawBitmap() const
279 {
280 return TRUE;
281 }
282
283 bool wxDC::CanGetTextExtent() const
284 {
285 // What sort of display is it?
286 int technology = 0; // TODO: ::GetDeviceCaps(GetHdc(), TECHNOLOGY);
287
288 // TODO: return (technology == DT_RASDISPLAY) || (technology == DT_RASPRINTER);
289 return FALSE;
290 }
291
292 int wxDC::GetDepth() const
293 {
294 // TODO:
295 return (1);
296 }
297
298 // ---------------------------------------------------------------------------
299 // drawing
300 // ---------------------------------------------------------------------------
301
302 void wxDC::Clear()
303 {
304 ::GpiErase(m_hPS);
305 }
306
307 void wxDC::DoFloodFill(
308 wxCoord vX
309 , wxCoord vY
310 , const wxColour& rCol
311 , int nStyle
312 )
313 {
314 POINTL vPtlPos;
315 LONG lColor;
316 LONG lOptions;
317
318 vPtlPos.x = vX; // Loads x-coordinate
319 vPtlPos.y = vY; // Loads y-coordinate
320 ::GpiMove(m_hPS, &vPtlPos); // Sets current position
321 lColor = rCol.GetPixel();
322 lOptions = FF_BOUNDARY;
323 if(wxFLOOD_SURFACE == nStyle)
324 lOptions = FF_SURFACE;
325
326 ::GpiFloodFill(m_hPS, lOptions, lColor);
327 }
328
329 bool wxDC::DoGetPixel(
330 wxCoord vX
331 , wxCoord vY
332 , wxColour* pCol
333 ) const
334 {
335 POINTL vPoint;
336 LONG lColor;
337
338 vPoint.x = vX;
339 vPoint.y = vY;
340 lColor = ::GpiSetPel(m_hPS, &vPoint);
341 pCol->Set((unsigned long)lColor);
342 if(lColor>= 0)
343 return(TRUE);
344 else
345 return(FALSE);
346 }
347
348 void wxDC::DoCrossHair(wxCoord x, wxCoord y)
349 {
350 // TODO
351 }
352
353 void wxDC::DoDrawLine(
354 wxCoord vX1
355 , wxCoord vY1
356 , wxCoord vX2
357 , wxCoord vY2
358 )
359 {
360 POINTL vPoint[2];
361
362 vPoint[0].x = vX1;
363 vPoint[0].y = vY1;
364 vPoint[1].x = vX2;
365 vPoint[1].y = vY2;
366 ::GpiMove(m_hPS, &vPoint[0]);
367 ::GpiLine(m_hPS, &vPoint[1]);
368 }
369
370 //////////////////////////////////////////////////////////////////////////////
371 // Draws an arc of a circle, centred on (xc, yc), with starting point (x1, y1)
372 // and ending at (x2, y2). The current pen is used for the outline and the
373 // current brush for filling the shape. The arc is drawn in an anticlockwise
374 // direction from the start point to the end point.
375 //////////////////////////////////////////////////////////////////////////////
376 void wxDC::DoDrawArc(
377 wxCoord vX1
378 , wxCoord vY1
379 , wxCoord vX2
380 , wxCoord vY2
381 , wxCoord vXc
382 , wxCoord vYc
383 )
384 {
385 POINTL vPtlPos;
386 POINTL vPtlArc[2]; // Structure for current position
387 int nDx;
388 int nDy;
389 double dRadius;
390 double dAngl1;
391 double dAngl2;
392 double dAnglmid;
393 wxCoord vXm;
394 wxCoord vYm;
395 ARCPARAMS vArcp; // Structure for arc parameters
396
397 if((vX1 == vXc && vY1 == vXc) || (vX2 == vXc && vY2 == vXc))
398 return; // Draw point ??
399 dRadius = 0.5 * ( hypot( (double)(vY1 - vYc)
400 ,(double)(vX1 - vXc)
401 ) +
402 hypot( (double)(vY2 - vYc)
403 ,(double)(vX2 - vXc)
404 )
405 );
406
407 dAngl1 = atan2( (double)(vY1 - vYc)
408 ,(double)(vX1 - vXc)
409 );
410 dAngl2 = atan2( (double)(vY2 - vYc)
411 ,(double)(vX2 - vXc)
412 );
413 if(dAngl2 < dAngl1)
414 dAngl2 += M_PI * 2;
415
416 //
417 // GpiPointArc can't draw full arc
418 //
419 if(dAngl2 == dAngl1 || (vX1 == vX2 && vY1 == vY2) )
420 {
421 //
422 // Medium point
423 //
424 dAnglmid = (dAngl1 + dAngl2)/2. + M_PI;
425 vXm = vXc + dRadius * cos(dAnglmid);
426 vYm = vYc + dRadius * sin(dAnglmid);
427 DoDrawArc( vX1, vY1
428 ,vXm, vYm
429 ,vXc, vYc
430 );
431 DoDrawArc( vXm, vYm
432 ,vX2, vY2
433 ,vXc, vYc
434 );
435 return;
436 }
437
438 //
439 // Medium point
440 //
441 dAnglmid = (dAngl1 + dAngl2)/2.;
442 vXm = vXc + dRadius * cos(dAnglmid);
443 vYm = vYc + dRadius * sin(dAnglmid);
444
445 //
446 // Ellipse main axis (r,q), (p,s) with center at (0,0) */
447 //
448 vArcp.lR = 0;
449 vArcp.lQ = 1;
450 vArcp.lP = 1;
451 vArcp.lS = 0;
452 ::GpiSetArcParams(m_hPS, &vArcp); // Sets parameters to default
453
454 vPtlPos.x = vX1; // Loads x-coordinate
455 vPtlPos.y = vY1; // Loads y-coordinate
456 ::GpiMove(m_hPS, &vPtlPos); // Sets current position
457 vPtlArc[0].x = vXm;
458 vPtlArc[0].y = vYm;
459 vPtlArc[1].x = vX2;
460 vPtlArc[1].y = vY2;
461 ::GpiPointArc(m_hPS, vPtlArc); // Draws the arc
462 }
463
464 void wxDC::DoDrawCheckMark(
465 wxCoord vX1
466 , wxCoord vY1
467 , wxCoord vWidth
468 , wxCoord vHeight
469 )
470 {
471 POINTL vPoint[2];
472
473 vPoint[0].x = vX1;
474 vPoint[0].y = vY1;
475 vPoint[1].x = vX1 + vWidth;
476 vPoint[1].y = vY1 + vHeight;
477
478 ::GpiMove(m_hPS, &vPoint[0]);
479 ::GpiBox( m_hPS // handle to a presentation space
480 ,DRO_OUTLINE // draw the box outline ? or ?
481 ,&vPoint[1] // address of the corner
482 ,0L // horizontal corner radius
483 ,0L // vertical corner radius
484 );
485 if(vWidth > 4 && vHeight > 4)
486 {
487 int nTmp;
488
489 vPoint[0].x += 2; vPoint[0].y += 2;
490 vPoint[1].x -= 2; vPoint[1].y -= 2;
491 ::GpiMove(m_hPS, &vPoint[0]);
492 ::GpiLine(m_hPS, &vPoint[1]);
493 nTmp = vPoint[0].x;
494 vPoint[0].x = vPoint[1].x;
495 vPoint[1].x = nTmp;
496 ::GpiMove(m_hPS, &vPoint[0]);
497 ::GpiLine(m_hPS, &vPoint[1]);
498 }
499 }
500
501 void wxDC::DoDrawPoint(
502 wxCoord vX
503 , wxCoord vY
504 )
505 {
506 POINTL vPoint;
507
508 vPoint.x = vX;
509 vPoint.y = vY;
510 ::GpiSetPel(m_hPS, &vPoint);
511 }
512
513 void wxDC::DoDrawPolygon(
514 int n
515 , wxPoint vPoints[]
516 , wxCoord vXoffset
517 , wxCoord vYoffset
518 , int nFillStyle
519 )
520 {
521 ULONG ulCount = 1; // Number of polygons.
522 POLYGON vPlgn; // polygon.
523 ULONG flOptions = 0L; // Drawing options.
524
525 //////////////////////////////////////////////////////////////////////////////
526 // This contains fields of option bits... to draw boundary lines as well as
527 // the area interior.
528 //
529 // Drawing boundary lines:
530 // POLYGON_NOBOUNDARY Does not draw boundary lines.
531 // POLYGON_BOUNDARY Draws boundary lines (the default).
532 //
533 // Construction of the area interior:
534 // POLYGON_ALTERNATE Constructs interior in alternate mode
535 // (the default).
536 // POLYGON_WINDING Constructs interior in winding mode.
537 //////////////////////////////////////////////////////////////////////////////
538
539 ULONG flModel = 0L; // Drawing model.
540
541 //////////////////////////////////////////////////////////////////////////////
542 // Drawing model.
543 // POLYGON_INCL Fill is inclusive of bottom right (the default).
544 // POLYGON_EXCL Fill is exclusive of bottom right.
545 // This is provided to aid migration from other graphics models.
546 //////////////////////////////////////////////////////////////////////////////
547
548 LONG lHits = 0L; // Correlation/error indicator.
549 POINTL vPoint;
550 int i;
551 int nIsTRANSPARENT = 0;
552 LONG lBorderColor = 0L;
553 LONG lColor = 0L;
554
555 lBorderColor = m_pen.GetColour().GetPixel();
556 lColor = m_brush.GetColour().GetPixel();
557 if(m_brush.GetStyle() == wxTRANSPARENT)
558 nIsTRANSPARENT = 1;
559
560 vPlgn.ulPoints = n;
561 vPlgn.aPointl = (POINTL*) calloc( n + 1
562 ,sizeof(POINTL)
563 ); // well, new will call malloc
564
565 for(i = 0; i < n; i++)
566 {
567 vPlgn.aPointl[i].x = vPoints[i].x; // +xoffset;
568 vPlgn.aPointl[i].y = vPoints[i].y; // +yoffset;
569 }
570 flModel = POLYGON_BOUNDARY;
571 if(nFillStyle == wxWINDING_RULE)
572 flModel |= POLYGON_WINDING;
573 else
574 flModel |= POLYGON_ALTERNATE;
575
576 vPoint.x = vXoffset;
577 vPoint.y = vYoffset;
578
579 ::GpiSetColor(m_hPS, lBorderColor);
580 ::GpiMove(m_hPS, &vPoint);
581 lHits = ::GpiPolygons(m_hPS, ulCount, &vPlgn, flOptions, flModel);
582 free(vPlgn.aPointl);
583 }
584
585 void wxDC::DoDrawLines(
586 int n
587 , wxPoint vPoints[]
588 , wxCoord vXoffset
589 , wxCoord vYoffset
590 )
591 {
592 int i;
593 POINTL vPoint;
594
595 vPoint.x = vPoints[0].x + vXoffset;
596 vPoint.y = vPoints[0].y + vYoffset;
597 ::GpiMove(m_hPS, &vPoint);
598
599 LONG lBorderColor = m_pen.GetColour().GetPixel();
600
601 ::GpiSetColor(m_hPS, lBorderColor);
602 for(i = 1; i < n; i++)
603 {
604 vPoint.x = vPoints[0].x + vXoffset;
605 vPoint.y = vPoints[0].y + vYoffset;
606 ::GpiLine(m_hPS, &vPoint);
607 }
608 }
609
610 void wxDC::DoDrawRectangle(
611 wxCoord vX
612 , wxCoord vY
613 , wxCoord vWidth
614 , wxCoord vHeight
615 )
616 {
617 POINTL vPoint[2];
618 LONG lControl;
619 LONG lColor;
620 LONG lBorderColor;
621 int nIsTRANSPARENT = 0;
622
623 vPoint[0].x = vX;
624 vPoint[0].y = vY;
625 vPoint[1].x = vX + vWidth;
626 vPoint[1].y = vY - vHeight;
627 ::GpiMove(m_hPS, &vPoint[0]);
628 lColor = m_brush.GetColour().GetPixel();
629 lBorderColor = m_pen.GetColour().GetPixel();
630 if (m_brush.GetStyle() == wxTRANSPARENT)
631 nIsTRANSPARENT = 1;
632 if(lColor == lBorderColor || nIsTRANSPARENT)
633 {
634 lControl = DRO_OUTLINEFILL; //DRO_FILL;
635 if(m_brush.GetStyle() == wxTRANSPARENT)
636 lControl = DRO_OUTLINE;
637
638 ::GpiSetColor(m_hPS, CLR_GREEN);
639 ::GpiBox( m_hPS // handle to a presentation space
640 ,lControl // draw the box outline ? or ?
641 ,&vPoint[1] // address of the corner
642 ,0L // horizontal corner radius
643 ,0L // vertical corner radius
644 );
645 }
646 else
647 {
648 lControl = DRO_OUTLINE;
649 ::GpiSetColor( m_hPS
650 ,lBorderColor
651 );
652 ::GpiBox( m_hPS
653 ,lControl
654 ,&vPoint[1]
655 ,0L
656 ,0L
657 );
658 lControl = DRO_FILL;
659 ::GpiSetColor( m_hPS
660 ,lColor
661 );
662 ::GpiBox( m_hPS
663 ,lControl
664 ,&vPoint[1]
665 ,0L
666 ,0L
667 );
668 }
669 }
670
671 void wxDC::DoDrawRoundedRectangle(
672 wxCoord vX
673 , wxCoord vY
674 , wxCoord vWidth
675 , wxCoord vHeight
676 , double dRadius
677 )
678 {
679 POINTL vPoint[2];
680 LONG lControl;
681
682 vPoint[0].x = vX;
683 vPoint[0].y = vY;
684 vPoint[1].x = vX + vWidth;
685 vPoint[1].y = vY + vHeight;
686 ::GpiMove(m_hPS, &vPoint[0]);
687
688 lControl = DRO_OUTLINEFILL; //DRO_FILL;
689 if (m_brush.GetStyle() == wxTRANSPARENT)
690 lControl = DRO_OUTLINE;
691 ::GpiBox( m_hPS // handle to a presentation space
692 ,DRO_OUTLINE // draw the box outline ? or ?
693 ,&vPoint[1] // address of the corner
694 ,(LONG)dRadius // horizontal corner radius
695 ,(LONG)dRadius // vertical corner radius
696 );
697 }
698
699 // Draw Ellipse within box (x,y) - (x+width, y+height)
700 void wxDC::DoDrawEllipse(
701 wxCoord vX
702 , wxCoord vY
703 , wxCoord vWidth
704 , wxCoord vHeight
705 )
706 {
707 POINTL vPtlPos; // Structure for current position
708 FIXED vFxMult; // Multiplier for ellipse
709 ARCPARAMS vArcp; // Structure for arc parameters
710
711 vArcp.lR = 0;
712 vArcp.lQ = vHeight/2;
713 vArcp.lP = vWidth/2;
714 vArcp.lS = 0;
715 ::GpiSetArcParams( m_hPS
716 ,&vArcp
717 ); // Sets parameters to default
718 vPtlPos.x = vX + vWidth/2; // Loads x-coordinate
719 vPtlPos.y = vY + vHeight/2; // Loads y-coordinate
720 ::GpiMove( m_hPS
721 ,&vPtlPos
722 ); // Sets current position
723 vFxMult = MAKEFIXED(1, 0); /* Sets multiplier */
724
725 //
726 // DRO_FILL, DRO_OTLINEFILL - where to get
727 //
728 ::GpiFullArc( m_hPS
729 ,DRO_OUTLINE
730 ,vFxMult
731 ); // Draws full arc with center at current position
732 }
733
734 void wxDC::DoDrawEllipticArc(
735 wxCoord vX
736 , wxCoord vY
737 , wxCoord vWidth
738 , wxCoord vHeight
739 , double dSa
740 , double dEa
741 )
742 {
743 POINTL vPtlPos; // Structure for current position
744 FIXED vFxMult; // Multiplier for ellipse
745 ARCPARAMS vArcp; // Structure for arc parameters
746 FIXED vFSa;
747 FIXED vFSweepa; // Start angle, sweep angle
748 double dIntPart;
749 double dFractPart;
750 double dRadius;
751
752 dFractPart = modf(dSa,&dIntPart);
753 vFSa = MAKEFIXED((int)dIntPart, (int)(dFractPart * 0xffff) );
754 dFractPart = modf(dEa - dSa, &dIntPart);
755 vFSweepa = MAKEFIXED((int)dIntPart, (int)(dFractPart * 0xffff) );
756
757 //
758 // Ellipse main axis (r,q), (p,s) with center at (0,0)
759 //
760 vArcp.lR = 0;
761 vArcp.lQ = vHeight/2;
762 vArcp.lP = vWidth/2;
763 vArcp.lS = 0;
764 ::GpiSetArcParams(m_hPS, &vArcp); // Sets parameters to default
765 vPtlPos.x = vX + vWidth/2 * (1. + cos(DegToRad(dSa))); // Loads x-coordinate
766 vPtlPos.y = vY + vHeight/2 * (1. + sin(DegToRad(dSa))); // Loads y-coordinate
767 ::GpiMove(m_hPS, &vPtlPos); // Sets current position
768
769 //
770 // May be not to the center ?
771 //
772 vPtlPos.x = vX + vWidth/2 ; // Loads x-coordinate
773 vPtlPos.y = vY + vHeight/2; // Loads y-coordinate
774 vFxMult = MAKEFIXED(1, 0); // Sets multiplier
775
776 //
777 // DRO_FILL, DRO_OTLINEFILL - where to get
778 //
779 ::GpiPartialArc( m_hPS
780 ,&vPtlPos
781 ,vFxMult
782 ,vFSa
783 ,vFSweepa
784 );
785 }
786
787 void wxDC::DoDrawIcon(const wxIcon& icon, wxCoord x, wxCoord y)
788 {
789 // TODO:
790 }
791
792 void wxDC::DoDrawBitmap( const wxBitmap &bmp
793 ,wxCoord x, wxCoord y
794 ,bool useMask
795 )
796 {
797 // TODO
798 }
799
800 void wxDC::DoDrawText(
801 const wxString& rsText
802 , wxCoord vX
803 , wxCoord vY
804 )
805 {
806 DrawAnyText( rsText
807 ,vX
808 ,vY
809 );
810 }
811
812 void wxDC::DrawAnyText(
813 const wxString& rsText
814 , wxCoord vX
815 , wxCoord vY
816 )
817 {
818 int nOldBackground = 0;
819 POINTL vPtlStart;
820 LONG lHits;
821
822 //
823 // prepare for drawing the text
824 //
825
826 //
827 // Set text color attributes
828 //
829 if (m_textForegroundColour.Ok())
830 {
831 SetTextColor( m_hPS
832 ,(int)m_textForegroundColour.GetPixel()
833 );
834 }
835
836 if (m_textBackgroundColour.Ok())
837 {
838 nOldBackground = SetTextBkColor( m_hPS
839 ,(int)m_textBackgroundColour.GetPixel()
840 );
841 }
842 SetBkMode( m_hPS
843 ,m_backgroundMode
844 );
845 vPtlStart.x = vX;
846 vPtlStart.y = vY;
847
848 lHits = ::GpiCharStringAt( m_hPS
849 ,&vPtlStart
850 ,rsText.length()
851 ,(PCH)rsText.c_str()
852 );
853 if (lHits != GPI_OK)
854 {
855 wxLogLastError(wxT("TextOut"));
856 }
857
858 //
859 // Restore the old parameters (text foreground colour may be left because
860 // it never is set to anything else, but background should remain
861 // transparent even if we just drew an opaque string)
862 //
863 if (m_textBackgroundColour.Ok())
864 SetTextBkColor( m_hPS
865 ,nOldBackground
866 );
867 SetBkMode( m_hPS
868 ,wxTRANSPARENT
869 );
870 }
871
872 void wxDC::DoDrawRotatedText(
873 const wxString& rsText
874 , wxCoord vX
875 , wxCoord vY
876 , double dAngle
877 )
878 {
879 if (dAngle == 0.0)
880 {
881 DoDrawText( rsText
882 ,vX
883 ,vY
884 );
885 }
886
887 // TODO:
888 /*
889 if ( angle == 0.0 )
890 {
891 DoDrawText(text, x, y);
892 }
893 else
894 {
895 LOGFONT lf;
896 wxFillLogFont(&lf, &m_font);
897
898 // GDI wants the angle in tenth of degree
899 long angle10 = (long)(angle * 10);
900 lf.lfEscapement = angle10;
901 lf. lfOrientation = angle10;
902
903 HFONT hfont = ::CreateFontIndirect(&lf);
904 if ( !hfont )
905 {
906 wxLogLastError("CreateFont");
907 }
908 else
909 {
910 HFONT hfontOld = ::SelectObject(GetHdc(), hfont);
911
912 DrawAnyText(text, x, y);
913
914 (void)::SelectObject(GetHdc(), hfontOld);
915 }
916
917 // call the bounding box by adding all four vertices of the rectangle
918 // containing the text to it (simpler and probably not slower than
919 // determining which of them is really topmost/leftmost/...)
920 wxCoord w, h;
921 GetTextExtent(text, &w, &h);
922
923 double rad = DegToRad(angle);
924
925 // "upper left" and "upper right"
926 CalcBoundingBox(x, y);
927 CalcBoundingBox(x + w*cos(rad), y - h*sin(rad));
928 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
929
930 // "bottom left" and "bottom right"
931 x += (wxCoord)(h*sin(rad));
932 y += (wxCoord)(h*cos(rad));
933 CalcBoundingBox(x, y);
934 CalcBoundingBox(x + h*sin(rad), y + h*cos(rad));
935 }
936 */
937 }
938
939 // ---------------------------------------------------------------------------
940 // set GDI objects
941 // ---------------------------------------------------------------------------
942
943 void wxDC::SetPalette(const wxPalette& palette)
944 {
945 // TODO
946 }
947
948 void wxDC::SetFont(
949 const wxFont& rFont
950 )
951 {
952 //
953 // Set the old object temporarily, in case the assignment deletes an object
954 // that's not yet selected out.
955 //
956 if (m_hOldFont)
957 {
958 m_hOldFont = 0;
959 }
960 m_font = rFont;
961 if (!rFont.Ok())
962 {
963 m_hOldFont = 0;
964 }
965
966 m_font.SetPS(m_hPS); // this will realize the font
967
968 if (m_font.Ok())
969 {
970 HFONT hFont = m_font.GetResourceHandle();
971 if (hFont == (HFONT) NULL)
972 {
973 wxLogDebug(wxT("::SelectObject failed in wxDC::SetFont."));
974 }
975 if (!m_hOldFont)
976 m_hOldFont = (WXHFONT) hFont;
977 }
978 } // end of wxDC::SetFont
979
980 void wxDC::SetPen(
981 const wxPen& rPen
982 )
983 {
984 wxCHECK_RET( Ok(), wxT("invalid window dc") );
985
986 if (m_pen == rPen)
987 return;
988 m_pen = rPen;
989 if (!m_pen.Ok())
990 return;
991
992 if (m_hOldPen)
993 m_hOldPen = 0L;
994 m_pen = rPen;
995
996 if (!m_pen.Ok())
997 {
998 if (m_hOldPen)
999 {
1000 m_pen.SetPS((HPS)m_hOldPen);
1001 }
1002 m_hOldPen = 0L;
1003 }
1004
1005 if (m_pen.Ok())
1006 {
1007 if (m_pen.GetResourceHandle())
1008 {
1009 m_pen.SetPS(m_hPS);
1010 if (!m_hOldPen)
1011 m_hOldPen = m_pen.GetPS();
1012 }
1013 }
1014 }
1015
1016 void wxDC::SetBrush(
1017 const wxBrush& rBrush
1018 )
1019 {
1020 wxCHECK_RET( Ok(), wxT("invalid window dc") );
1021
1022 if (m_brush == rBrush)
1023 return;
1024 m_brush = rBrush;
1025 if (!m_brush.Ok())
1026 return;
1027
1028 if (m_hOldBrush)
1029 m_hOldBrush = 0L;
1030 m_brush = rBrush;
1031
1032 if (!m_brush.Ok())
1033 {
1034 if (m_hOldBrush)
1035 {
1036 m_brush.SetPS((HPS)m_hOldBrush);
1037 }
1038 m_hOldBrush = 0L;
1039 }
1040
1041 if (m_brush.Ok())
1042 {
1043 if (m_brush.GetResourceHandle())
1044 {
1045 m_brush.SetPS(m_hPS);
1046 if (!m_hOldBrush)
1047 m_hOldBrush = m_brush.GetPS();
1048 }
1049 }
1050 } // end of wxDC::SetBrush
1051
1052 void wxDC::SetBackground(const wxBrush& brush)
1053 {
1054 // TODO
1055 }
1056
1057 void wxDC::SetBackgroundMode(
1058 int nMode
1059 )
1060 {
1061 m_backgroundMode = nMode;
1062 }
1063
1064 void wxDC::SetLogicalFunction(int function)
1065 {
1066 // TODO
1067 }
1068
1069 void wxDC::SetRop(WXHDC dc)
1070 {
1071 if (!dc || m_logicalFunction < 0)
1072 return;
1073
1074 int c_rop;
1075 // These may be wrong
1076 switch (m_logicalFunction)
1077 {
1078 // TODO: Figure this stuff out
1079 // case wxXOR: c_rop = R2_XORPEN; break;
1080 // case wxXOR: c_rop = R2_NOTXORPEN; break;
1081 // case wxINVERT: c_rop = R2_NOT; break;
1082 // case wxOR_REVERSE: c_rop = R2_MERGEPENNOT; break;
1083 // case wxAND_REVERSE: c_rop = R2_MASKPENNOT; break;
1084 // case wxCLEAR: c_rop = R2_WHITE; break;
1085 // case wxSET: c_rop = R2_BLACK; break;
1086 // case wxSRC_INVERT: c_rop = R2_NOTCOPYPEN; break;
1087 // case wxOR_INVERT: c_rop = R2_MERGENOTPEN; break;
1088 // case wxAND: c_rop = R2_MASKPEN; break;
1089 // case wxOR: c_rop = R2_MERGEPEN; break;
1090 // case wxAND_INVERT: c_rop = R2_MASKNOTPEN; break;
1091 // case wxEQUIV:
1092 // case wxNAND:
1093 // case wxCOPY:
1094 default:
1095 // c_rop = R2_COPYPEN;
1096 break;
1097 }
1098 // SetROP2((HDC) dc, c_rop);
1099 }
1100
1101 bool wxDC::StartDoc(const wxString& message)
1102 {
1103 // We might be previewing, so return TRUE to let it continue.
1104 return TRUE;
1105 }
1106
1107 void wxDC::EndDoc()
1108 {
1109 }
1110
1111 void wxDC::StartPage()
1112 {
1113 }
1114
1115 void wxDC::EndPage()
1116 {
1117 }
1118
1119 // ---------------------------------------------------------------------------
1120 // text metrics
1121 // ---------------------------------------------------------------------------
1122
1123 wxCoord wxDC::GetCharHeight() const
1124 {
1125 FONTMETRICS vFM; // metrics structure
1126
1127 ::GpiQueryFontMetrics( m_hPS
1128 ,sizeof(FONTMETRICS)
1129 ,&vFM
1130 );
1131 return YDEV2LOGREL(vFM.lXHeight);
1132 }
1133
1134 wxCoord wxDC::GetCharWidth() const
1135 {
1136 FONTMETRICS vFM; // metrics structure
1137
1138 ::GpiQueryFontMetrics( m_hPS
1139 ,sizeof(FONTMETRICS)
1140 ,&vFM
1141 );
1142 return XDEV2LOGREL(vFM.lAveCharWidth);
1143 }
1144
1145 void wxDC::DoGetTextExtent(
1146 const wxString& rsString
1147 , wxCoord* pvX
1148 , wxCoord* pvY
1149 , wxCoord* pvDescent
1150 , wxCoord* pvExternalLeading
1151 , wxFont* pTheFont
1152 ) const
1153 {
1154 POINTL avPoint[TXTBOX_COUNT];
1155 POINTL vPtMin;
1156 POINTL vPtMax;
1157 int i;
1158 int l;
1159 FONTMETRICS vFM; // metrics structure
1160 BOOL bRc;
1161 char* pStr;
1162 ERRORID vErrorCode; // last error id code
1163 wxFont* pFontToUse = (wxFont*)pTheFont;
1164
1165 if (!pFontToUse)
1166 pFontToUse = (wxFont*)&m_font;
1167 l = rsString.length();
1168 pStr = (PCH) rsString.c_str();
1169
1170 //
1171 // In world coordinates.
1172 //
1173 bRc = ::GpiQueryTextBox( m_hPS
1174 ,l
1175 ,pStr
1176 ,TXTBOX_COUNT // return maximum information
1177 ,avPoint // array of coordinates points
1178 );
1179 if(!bRc)
1180 {
1181 vErrorCode = ::WinGetLastError(wxGetInstance());
1182 }
1183
1184 vPtMin.x = avPoint[0].x;
1185 vPtMax.x = avPoint[0].x;
1186 vPtMin.y = avPoint[0].y;
1187 vPtMax.y = avPoint[0].y;
1188 for (i = 1; i < 4; i++)
1189 {
1190 if(vPtMin.x > avPoint[i].x) vPtMin.x = avPoint[i].x;
1191 if(vPtMin.y > avPoint[i].y) vPtMin.y = avPoint[i].y;
1192 if(vPtMax.x < avPoint[i].x) vPtMax.x = avPoint[i].x;
1193 if(vPtMax.y < avPoint[i].y) vPtMax.y = avPoint[i].y;
1194 }
1195 ::GpiQueryFontMetrics( m_hPS
1196 ,sizeof(FONTMETRICS)
1197 ,&vFM
1198 );
1199
1200 if (pvX)
1201 *pvX = (wxCoord)(vPtMax.x - vPtMin.x + 1);
1202 if (pvY)
1203 *pvY = (wxCoord)(vPtMax.y - vPtMin.y + 1);
1204 if (pvDescent)
1205 *pvDescent = vFM.lMaxDescender;
1206 if (pvExternalLeading)
1207 *pvExternalLeading = vFM.lExternalLeading;
1208 }
1209
1210 void wxDC::SetMapMode( int mode )
1211 {
1212 // TODO:
1213 };
1214
1215 void wxDC::SetUserScale(double x, double y)
1216 {
1217 m_userScaleX = x;
1218 m_userScaleY = y;
1219
1220 SetMapMode(m_mappingMode);
1221 }
1222
1223 void wxDC::SetAxisOrientation(bool xLeftRight, bool yBottomUp)
1224 {
1225 m_signX = xLeftRight ? 1 : -1;
1226 m_signY = yBottomUp ? -1 : 1;
1227
1228 SetMapMode(m_mappingMode);
1229 }
1230
1231 void wxDC::SetSystemScale(double x, double y)
1232 {
1233 m_scaleX = x;
1234 m_scaleY = y;
1235
1236 SetMapMode(m_mappingMode);
1237 }
1238
1239 void wxDC::SetLogicalOrigin( wxCoord x, wxCoord y )
1240 {
1241 // TODO:
1242 };
1243
1244 void wxDC::SetDeviceOrigin( wxCoord x, wxCoord y )
1245 {
1246 RECTL vRect;
1247
1248 ::GpiQueryPageViewport( m_hPS
1249 ,&vRect
1250 );
1251 vRect.xLeft += x;
1252 vRect.xRight += x;
1253 vRect.yBottom -= y;
1254 vRect.yTop -= y;
1255 ::GpiSetPageViewport( m_hPS
1256 ,&vRect
1257 );
1258 };
1259
1260 // ---------------------------------------------------------------------------
1261 // coordinates transformations
1262 // ---------------------------------------------------------------------------
1263
1264 wxCoord wxDCBase::DeviceToLogicalX(wxCoord x) const
1265 {
1266 return (wxCoord) (((x) - m_deviceOriginX)/(m_logicalScaleX*m_userScaleX*m_signX*m_scaleX) - m_logicalOriginX);
1267 }
1268
1269 wxCoord wxDCBase::DeviceToLogicalXRel(wxCoord x) const
1270 {
1271 return (wxCoord) ((x)/(m_logicalScaleX*m_userScaleX*m_signX*m_scaleX));
1272 }
1273
1274 wxCoord wxDCBase::DeviceToLogicalY(wxCoord y) const
1275 {
1276 return (wxCoord) (((y) - m_deviceOriginY)/(m_logicalScaleY*m_userScaleY*m_signY*m_scaleY) - m_logicalOriginY);
1277 }
1278
1279 wxCoord wxDCBase::DeviceToLogicalYRel(wxCoord y) const
1280 {
1281 return (wxCoord) ((y)/(m_logicalScaleY*m_userScaleY*m_signY*m_scaleY));
1282 }
1283
1284 wxCoord wxDCBase::LogicalToDeviceX(wxCoord x) const
1285 {
1286 return (wxCoord) ((x - m_logicalOriginX)*m_logicalScaleX*m_userScaleX*m_signX*m_scaleX + m_deviceOriginX);
1287 }
1288
1289 wxCoord wxDCBase::LogicalToDeviceXRel(wxCoord x) const
1290 {
1291 return (wxCoord) (x*m_logicalScaleX*m_userScaleX*m_signX*m_scaleX);
1292 }
1293
1294 wxCoord wxDCBase::LogicalToDeviceY(wxCoord y) const
1295 {
1296 return (wxCoord) ((y - m_logicalOriginY)*m_logicalScaleY*m_userScaleY*m_signY*m_scaleY + m_deviceOriginY);
1297 }
1298
1299 wxCoord wxDCBase::LogicalToDeviceYRel(wxCoord y) const
1300 {
1301 return (wxCoord) (y*m_logicalScaleY*m_userScaleY*m_signY*m_scaleY);
1302 }
1303
1304 // ---------------------------------------------------------------------------
1305 // bit blit
1306 // ---------------------------------------------------------------------------
1307
1308 bool wxDC::DoBlit( wxCoord xdest
1309 ,wxCoord ydest
1310 ,wxCoord width
1311 ,wxCoord height
1312 ,wxDC *source
1313 ,wxCoord xsrc
1314 ,wxCoord ysrc
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 {
1351 wxCoord x1, y1, descent1, externalLeading1;
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)
1427 {
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;
1444 }
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
1451 }
1452
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)
1477 {
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);
1496 }
1497 }
1498 }
1499
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;
1592 }
1593
1594
1595 #endif // wxUSE_SPLINES
1596