1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDrawnShape
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "drawn.h"
14 #pragma implementation "drawnp.h"
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
29 #include <wx/deprecated/wxexpr.h>
32 #include "wx/ogl/ogl.h"
37 static void IntToHex(unsigned int dec
, wxChar
*buf
);
38 static unsigned long HexToInt(wxChar
*buf
);
39 extern wxChar
*oglBuffer
;
42 #define gyTYPE_BRUSH 41
43 #define gyTYPE_FONT 42
50 IMPLEMENT_DYNAMIC_CLASS(wxDrawnShape
, wxRectangleShape
)
52 wxDrawnShape::wxDrawnShape():wxRectangleShape(100.0, 50.0)
55 m_currentAngle
= oglDRAWN_ANGLE_0
;
58 wxDrawnShape::~wxDrawnShape()
62 void wxDrawnShape::OnDraw(wxDC
& dc
)
64 // Pass pen and brush in case we have force outline
66 if (m_shadowMode
!= SHADOW_NONE
)
69 m_metafiles
[m_currentAngle
].m_fillBrush
= m_shadowBrush
;
70 m_metafiles
[m_currentAngle
].m_outlinePen
= g_oglTransparentPen
;
71 m_metafiles
[m_currentAngle
].Draw(dc
, m_xpos
+ m_shadowOffsetX
, m_ypos
+ m_shadowOffsetY
);
74 m_metafiles
[m_currentAngle
].m_outlinePen
= m_pen
;
75 m_metafiles
[m_currentAngle
].m_fillBrush
= m_brush
;
76 m_metafiles
[m_currentAngle
].Draw(dc
, m_xpos
, m_ypos
);
79 void wxDrawnShape::SetSize(double w
, double h
, bool WXUNUSED(recursive
))
81 SetAttachmentSize(w
, h
);
85 if (GetWidth() == 0.0)
87 else scaleX
= w
/GetWidth();
88 if (GetHeight() == 0.0)
90 else scaleY
= h
/GetHeight();
93 for (i
= 0; i
< 4; i
++)
95 if (m_metafiles
[i
].IsValid())
96 m_metafiles
[i
].Scale(scaleX
, scaleY
);
100 SetDefaultRegionSize();
103 void wxDrawnShape::Scale(double sx
, double sy
)
106 for (i
= 0; i
< 4; i
++)
108 if (m_metafiles
[i
].IsValid())
110 m_metafiles
[i
].Scale(sx
, sy
);
111 m_metafiles
[i
].CalculateSize(this);
116 void wxDrawnShape::Translate(double x
, double y
)
119 for (i
= 0; i
< 4; i
++)
121 if (m_metafiles
[i
].IsValid())
123 m_metafiles
[i
].Translate(x
, y
);
124 m_metafiles
[i
].CalculateSize(this);
129 // theta is absolute rotation from the zero position
130 void wxDrawnShape::Rotate(double x
, double y
, double theta
)
132 m_currentAngle
= DetermineMetaFile(theta
);
134 if (m_currentAngle
== 0)
137 if (!m_metafiles
[0].GetRotateable())
140 m_metafiles
[0].Rotate(x
, y
, theta
);
143 double actualTheta
= theta
-m_rotation
;
145 // Rotate attachment points
146 double sinTheta
= (double)sin(actualTheta
);
147 double cosTheta
= (double)cos(actualTheta
);
148 wxNode
*node
= m_attachmentPoints
.GetFirst();
151 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->GetData();
152 double x1
= point
->m_x
;
153 double y1
= point
->m_y
;
154 point
->m_x
= x1
*cosTheta
- y1
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
155 point
->m_y
= x1
*sinTheta
+ y1
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
156 node
= node
->GetNext();
160 m_metafiles
[m_currentAngle
].CalculateSize(this);
163 // Which metafile do we use now? Based on current rotation and validity
166 int wxDrawnShape::DetermineMetaFile(double rotation
)
168 double tolerance
= 0.0001;
169 const double pi
= 3.1415926535897932384626433832795 ;
171 double angle2
= pi
/2.0;
173 double angle4
= 3.0*pi
/2.0;
175 int whichMetafile
= 0;
177 if (oglRoughlyEqual(rotation
, angle1
, tolerance
))
181 else if (oglRoughlyEqual(rotation
, angle2
, tolerance
))
185 else if (oglRoughlyEqual(rotation
, angle3
, tolerance
))
189 else if (oglRoughlyEqual(rotation
, angle4
, tolerance
))
194 if ((whichMetafile
> 0) && !m_metafiles
[whichMetafile
].IsValid())
197 return whichMetafile
;
200 void wxDrawnShape::OnDrawOutline(wxDC
& dc
, double x
, double y
, double w
, double h
)
202 if (m_metafiles
[m_currentAngle
].GetOutlineOp() != -1)
204 wxNode
* node
= m_metafiles
[m_currentAngle
].GetOps().Item(m_metafiles
[m_currentAngle
].GetOutlineOp());
205 wxASSERT (node
!= NULL
);
206 wxDrawOp
* op
= (wxDrawOp
*) node
->GetData();
208 if (op
->OnDrawOutline(dc
, x
, y
, w
, h
, m_width
, m_height
))
212 // Default... just use a rectangle
213 wxRectangleShape::OnDrawOutline(dc
, x
, y
, w
, h
);
216 // Get the perimeter point using the special outline op, if there is one,
217 // otherwise use default wxRectangleShape scheme
218 bool wxDrawnShape::GetPerimeterPoint(double x1
, double y1
,
219 double x2
, double y2
,
220 double *x3
, double *y3
)
222 if (m_metafiles
[m_currentAngle
].GetOutlineOp() != -1)
224 wxNode
* node
= m_metafiles
[m_currentAngle
].GetOps().Item(m_metafiles
[m_currentAngle
].GetOutlineOp());
225 wxASSERT (node
!= NULL
);
226 wxDrawOp
* op
= (wxDrawOp
*) node
->GetData();
228 if (op
->GetPerimeterPoint(x1
, y1
, x2
, y2
, x3
, y3
, GetX(), GetY(), GetAttachmentMode()))
232 // Default... just use a rectangle
233 return wxRectangleShape::GetPerimeterPoint(x1
, y1
, x2
, y2
, x3
, y3
);
237 void wxDrawnShape::WriteAttributes(wxExpr
*clause
)
239 wxRectangleShape::WriteAttributes(clause
);
241 clause
->AddAttributeValue(_T("current_angle"), (long)m_currentAngle
);
242 clause
->AddAttributeValue(_T("save_metafile"), (long)m_saveToFile
);
246 for (i
= 0; i
< 4; i
++)
248 if (m_metafiles
[i
].IsValid())
249 m_metafiles
[i
].WriteAttributes(clause
, i
);
254 void wxDrawnShape::ReadAttributes(wxExpr
*clause
)
256 wxRectangleShape::ReadAttributes(clause
);
258 int iVal
= (int) m_saveToFile
;
259 clause
->GetAttributeValue(_T("save_metafile"), iVal
);
260 clause
->GetAttributeValue(_T("current_angle"), m_currentAngle
);
261 m_saveToFile
= (iVal
!= 0);
266 for (i
= 0; i
< 4; i
++)
268 m_metafiles
[i
].ReadAttributes(clause
, i
);
274 // Does the copying for this object
275 void wxDrawnShape::Copy(wxShape
& copy
)
277 wxRectangleShape::Copy(copy
);
279 wxASSERT( copy
.IsKindOf(CLASSINFO(wxDrawnShape
)) ) ;
281 wxDrawnShape
& drawnCopy
= (wxDrawnShape
&) copy
;
284 for (i
= 0; i
< 4; i
++)
286 m_metafiles
[i
].Copy(drawnCopy
.m_metafiles
[i
]);
288 drawnCopy
.m_saveToFile
= m_saveToFile
;
289 drawnCopy
.m_currentAngle
= m_currentAngle
;
292 bool wxDrawnShape::LoadFromMetaFile(const wxString
& filename
)
294 return m_metafiles
[0].LoadFromMetaFile(filename
, &m_width
, &m_height
);
297 // Set of functions for drawing into a pseudo metafile.
298 // They use integers, but doubles are used internally for accuracy
301 void wxDrawnShape::DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
)
303 m_metafiles
[m_currentAngle
].DrawLine(pt1
, pt2
);
306 void wxDrawnShape::DrawRectangle(const wxRect
& rect
)
308 m_metafiles
[m_currentAngle
].DrawRectangle(rect
);
311 void wxDrawnShape::DrawRoundedRectangle(const wxRect
& rect
, double radius
)
313 m_metafiles
[m_currentAngle
].DrawRoundedRectangle(rect
, radius
);
316 void wxDrawnShape::DrawEllipse(const wxRect
& rect
)
318 m_metafiles
[m_currentAngle
].DrawEllipse(rect
);
321 void wxDrawnShape::DrawArc(const wxPoint
& centrePt
, const wxPoint
& startPt
, const wxPoint
& endPt
)
323 m_metafiles
[m_currentAngle
].DrawArc(centrePt
, startPt
, endPt
);
326 void wxDrawnShape::DrawEllipticArc(const wxRect
& rect
, double startAngle
, double endAngle
)
328 m_metafiles
[m_currentAngle
].DrawEllipticArc(rect
, startAngle
, endAngle
);
331 void wxDrawnShape::DrawPoint(const wxPoint
& pt
)
333 m_metafiles
[m_currentAngle
].DrawPoint(pt
);
336 void wxDrawnShape::DrawText(const wxString
& text
, const wxPoint
& pt
)
338 m_metafiles
[m_currentAngle
].DrawText(text
, pt
);
341 void wxDrawnShape::DrawLines(int n
, wxPoint pts
[])
343 m_metafiles
[m_currentAngle
].DrawLines(n
, pts
);
346 void wxDrawnShape::DrawPolygon(int n
, wxPoint pts
[], int flags
)
348 if (flags
& oglMETAFLAGS_ATTACHMENTS
)
352 for (i
= 0; i
< n
; i
++)
353 m_attachmentPoints
.Append(new wxAttachmentPoint(i
, pts
[i
].x
, pts
[i
].y
));
355 m_metafiles
[m_currentAngle
].DrawPolygon(n
, pts
, flags
);
358 void wxDrawnShape::DrawSpline(int n
, wxPoint pts
[])
360 m_metafiles
[m_currentAngle
].DrawSpline(n
, pts
);
363 void wxDrawnShape::SetClippingRect(const wxRect
& rect
)
365 m_metafiles
[m_currentAngle
].SetClippingRect(rect
);
368 void wxDrawnShape::DestroyClippingRect()
370 m_metafiles
[m_currentAngle
].DestroyClippingRect();
373 void wxDrawnShape::SetDrawnPen(wxPen
* pen
, bool isOutline
)
375 m_metafiles
[m_currentAngle
].SetPen(pen
, isOutline
);
378 void wxDrawnShape::SetDrawnBrush(wxBrush
* brush
, bool isFill
)
380 m_metafiles
[m_currentAngle
].SetBrush(brush
, isFill
);
383 void wxDrawnShape::SetDrawnFont(wxFont
* font
)
385 m_metafiles
[m_currentAngle
].SetFont(font
);
388 void wxDrawnShape::SetDrawnTextColour(const wxColour
& colour
)
390 m_metafiles
[m_currentAngle
].SetTextColour(colour
);
393 void wxDrawnShape::SetDrawnBackgroundColour(const wxColour
& colour
)
395 m_metafiles
[m_currentAngle
].SetBackgroundColour(colour
);
398 void wxDrawnShape::SetDrawnBackgroundMode(int mode
)
400 m_metafiles
[m_currentAngle
].SetBackgroundMode(mode
);
405 * Individual operations
410 * Set font, brush, text colour
414 wxOpSetGDI::wxOpSetGDI(int theOp
, wxPseudoMetaFile
*theImage
, int theGdiIndex
, int theMode
):
417 m_gdiIndex
= theGdiIndex
;
422 void wxOpSetGDI::Do(wxDC
& dc
, double WXUNUSED(xoffset
), double WXUNUSED(yoffset
))
428 // Check for overriding this operation for outline
430 if (m_image
->m_outlineColours
.Member((wxObject
*)m_gdiIndex
))
432 if (m_image
->m_outlinePen
)
433 dc
.SetPen(* m_image
->m_outlinePen
);
437 wxNode
*node
= m_image
->m_gdiObjects
.Item(m_gdiIndex
);
440 wxPen
*pen
= (wxPen
*)node
->GetData();
447 case DRAWOP_SET_BRUSH
:
449 // Check for overriding this operation for outline or fill
451 if (m_image
->m_outlineColours
.Member((wxObject
*)m_gdiIndex
))
453 // Need to construct a brush to match the outline pen's colour
454 if (m_image
->m_outlinePen
)
456 wxBrush
*br
= wxTheBrushList
->FindOrCreateBrush(m_image
->m_outlinePen
->GetColour(), wxSOLID
);
461 else if (m_image
->m_fillColours
.Member((wxObject
*)m_gdiIndex
))
463 if (m_image
->m_fillBrush
)
465 dc
.SetBrush(* m_image
->m_fillBrush
);
470 wxNode
*node
= m_image
->m_gdiObjects
.Item(m_gdiIndex
);
473 wxBrush
*brush
= (wxBrush
*)node
->GetData();
475 dc
.SetBrush(* brush
);
480 case DRAWOP_SET_FONT
:
482 wxNode
*node
= m_image
->m_gdiObjects
.Item(m_gdiIndex
);
485 wxFont
*font
= (wxFont
*)node
->GetData();
491 case DRAWOP_SET_TEXT_COLOUR
:
493 wxColour
col(m_r
,m_g
,m_b
);
494 dc
.SetTextForeground(col
);
497 case DRAWOP_SET_BK_COLOUR
:
499 wxColour
col(m_r
,m_g
,m_b
);
500 dc
.SetTextBackground(col
);
503 case DRAWOP_SET_BK_MODE
:
505 dc
.SetBackgroundMode(m_mode
);
513 wxDrawOp
*wxOpSetGDI::Copy(wxPseudoMetaFile
*newImage
)
515 wxOpSetGDI
*newOp
= new wxOpSetGDI(m_op
, newImage
, m_gdiIndex
, m_mode
);
523 wxExpr
*wxOpSetGDI::WriteExpr(wxPseudoMetaFile
*WXUNUSED(image
))
525 wxExpr
*expr
= new wxExpr(wxExprList
);
526 expr
->Append(new wxExpr((long)m_op
));
530 case DRAWOP_SET_BRUSH
:
531 case DRAWOP_SET_FONT
:
533 expr
->Append(new wxExpr((long)m_gdiIndex
));
536 case DRAWOP_SET_TEXT_COLOUR
:
537 case DRAWOP_SET_BK_COLOUR
:
539 expr
->Append(new wxExpr((long)m_r
));
540 expr
->Append(new wxExpr((long)m_g
));
541 expr
->Append(new wxExpr((long)m_b
));
544 case DRAWOP_SET_BK_MODE
:
546 expr
->Append(new wxExpr((long)m_mode
));
555 void wxOpSetGDI::ReadExpr(wxPseudoMetaFile
*WXUNUSED(image
), wxExpr
*expr
)
560 case DRAWOP_SET_BRUSH
:
561 case DRAWOP_SET_FONT
:
563 m_gdiIndex
= (int)expr
->Nth(1)->IntegerValue();
566 case DRAWOP_SET_TEXT_COLOUR
:
567 case DRAWOP_SET_BK_COLOUR
:
569 m_r
= (unsigned char)expr
->Nth(1)->IntegerValue();
570 m_g
= (unsigned char)expr
->Nth(2)->IntegerValue();
571 m_b
= (unsigned char)expr
->Nth(3)->IntegerValue();
574 case DRAWOP_SET_BK_MODE
:
576 m_mode
= (int)expr
->Nth(1)->IntegerValue();
586 * Set/destroy clipping
590 wxOpSetClipping::wxOpSetClipping(int theOp
, double theX1
, double theY1
,
591 double theX2
, double theY2
):wxDrawOp(theOp
)
599 wxDrawOp
*wxOpSetClipping::Copy(wxPseudoMetaFile
*WXUNUSED(newImage
))
601 wxOpSetClipping
*newOp
= new wxOpSetClipping(m_op
, m_x1
, m_y1
, m_x2
, m_y2
);
605 void wxOpSetClipping::Do(wxDC
& dc
, double xoffset
, double yoffset
)
609 case DRAWOP_SET_CLIPPING_RECT
:
611 dc
.SetClippingRegion((long)(m_x1
+ xoffset
), (long)(m_y1
+ yoffset
), (long)(m_x2
+ xoffset
), (long)(m_y2
+ yoffset
));
614 case DRAWOP_DESTROY_CLIPPING_RECT
:
616 dc
.DestroyClippingRegion();
624 void wxOpSetClipping::Scale(double xScale
, double yScale
)
632 void wxOpSetClipping::Translate(double x
, double y
)
639 wxExpr
*wxOpSetClipping::WriteExpr(wxPseudoMetaFile
*WXUNUSED(image
))
641 wxExpr
*expr
= new wxExpr(wxExprList
);
642 expr
->Append(new wxExpr((long)m_op
));
645 case DRAWOP_SET_CLIPPING_RECT
:
647 expr
->Append(new wxExpr(m_x1
));
648 expr
->Append(new wxExpr(m_y1
));
649 expr
->Append(new wxExpr(m_x2
));
650 expr
->Append(new wxExpr(m_y2
));
659 void wxOpSetClipping::ReadExpr(wxPseudoMetaFile
*WXUNUSED(image
), wxExpr
*expr
)
663 case DRAWOP_SET_CLIPPING_RECT
:
665 m_x1
= expr
->Nth(1)->RealValue();
666 m_y1
= expr
->Nth(2)->RealValue();
667 m_x2
= expr
->Nth(3)->RealValue();
668 m_y2
= expr
->Nth(4)->RealValue();
678 * Draw line, rectangle, rounded rectangle, ellipse, point, arc, text
682 wxOpDraw::wxOpDraw(int theOp
, double theX1
, double theY1
, double theX2
, double theY2
,
683 double theRadius
, wxChar
*s
) : wxDrawOp(theOp
)
691 m_radius
= theRadius
;
692 if (s
) m_textString
= copystring(s
);
693 else m_textString
= NULL
;
696 wxOpDraw::~wxOpDraw()
698 if (m_textString
) delete[] m_textString
;
701 wxDrawOp
*wxOpDraw::Copy(wxPseudoMetaFile
*WXUNUSED(newImage
))
703 wxOpDraw
*newOp
= new wxOpDraw(m_op
, m_x1
, m_y1
, m_x2
, m_y2
, m_radius
, m_textString
);
709 void wxOpDraw::Do(wxDC
& dc
, double xoffset
, double yoffset
)
713 case DRAWOP_DRAW_LINE
:
715 dc
.DrawLine(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
), WXROUND(m_x2
+xoffset
), WXROUND(m_y2
+yoffset
));
718 case DRAWOP_DRAW_RECT
:
720 dc
.DrawRectangle(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
), WXROUND(m_x2
), WXROUND(m_y2
));
723 case DRAWOP_DRAW_ROUNDED_RECT
:
725 dc
.DrawRoundedRectangle(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
), WXROUND(m_x2
), WXROUND(m_y2
), m_radius
);
728 case DRAWOP_DRAW_ELLIPSE
:
730 dc
.DrawEllipse(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
), WXROUND(m_x2
), WXROUND(m_y2
));
733 case DRAWOP_DRAW_ARC
:
735 dc
.DrawArc(WXROUND(m_x2
+xoffset
), WXROUND(m_y2
+yoffset
),
736 WXROUND(m_x3
+xoffset
), WXROUND(m_y3
+yoffset
),
737 WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
));
740 case DRAWOP_DRAW_ELLIPTIC_ARC
:
742 const double pi
= 3.1415926535897932384626433832795 ;
744 // Convert back to degrees
746 WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
),
747 WXROUND(m_x2
), WXROUND(m_y2
),
748 WXROUND(m_x3
*(360.0/(2.0*pi
))), WXROUND(m_y3
*(360.0/(2.0*pi
))));
751 case DRAWOP_DRAW_POINT
:
753 dc
.DrawPoint(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
));
756 case DRAWOP_DRAW_TEXT
:
758 dc
.DrawText(m_textString
, WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
));
766 void wxOpDraw::Scale(double scaleX
, double scaleY
)
773 if (m_op
!= DRAWOP_DRAW_ELLIPTIC_ARC
)
782 void wxOpDraw::Translate(double x
, double y
)
789 case DRAWOP_DRAW_LINE
:
795 case DRAWOP_DRAW_ARC
:
803 case DRAWOP_DRAW_ELLIPTIC_ARC
:
812 void wxOpDraw::Rotate(double x
, double y
, double theta
, double sinTheta
, double cosTheta
)
814 double newX1
= m_x1
*cosTheta
- m_y1
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
815 double newY1
= m_x1
*sinTheta
+ m_y1
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
819 case DRAWOP_DRAW_LINE
:
821 double newX2
= m_x2
*cosTheta
- m_y2
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
822 double newY2
= m_x2
*sinTheta
+ m_y2
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
830 case DRAWOP_DRAW_RECT
:
831 case DRAWOP_DRAW_ROUNDED_RECT
:
832 case DRAWOP_DRAW_ELLIPTIC_ARC
:
834 // Assume only 0, 90, 180, 270 degree rotations.
835 // oldX1, oldY1 represents the top left corner. Find the
836 // bottom right, and rotate that. Then the width/height is the difference
837 // between x/y values.
838 double oldBottomRightX
= m_x1
+ m_x2
;
839 double oldBottomRightY
= m_y1
+ m_y2
;
840 double newBottomRightX
= oldBottomRightX
*cosTheta
- oldBottomRightY
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
841 double newBottomRightY
= oldBottomRightX
*sinTheta
+ oldBottomRightY
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
843 // Now find the new top-left, bottom-right coordinates.
844 double minX
= wxMin(newX1
, newBottomRightX
);
845 double minY
= wxMin(newY1
, newBottomRightY
);
846 double maxX
= wxMax(newX1
, newBottomRightX
);
847 double maxY
= wxMax(newY1
, newBottomRightY
);
851 m_x2
= maxX
- minX
; // width
852 m_y2
= maxY
- minY
; // height
854 if (m_op
== DRAWOP_DRAW_ELLIPTIC_ARC
)
856 // Add rotation to angles
863 case DRAWOP_DRAW_ARC
:
865 double newX2
= m_x2
*cosTheta
- m_y2
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
866 double newY2
= m_x2
*sinTheta
+ m_y2
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
867 double newX3
= m_x3
*cosTheta
- m_y3
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
868 double newY3
= m_x3
*sinTheta
+ m_y3
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
885 wxExpr
*wxOpDraw::WriteExpr(wxPseudoMetaFile
*WXUNUSED(image
))
887 wxExpr
*expr
= new wxExpr(wxExprList
);
888 expr
->Append(new wxExpr((long)m_op
));
891 case DRAWOP_DRAW_LINE
:
892 case DRAWOP_DRAW_RECT
:
893 case DRAWOP_DRAW_ELLIPSE
:
895 expr
->Append(new wxExpr(m_x1
));
896 expr
->Append(new wxExpr(m_y1
));
897 expr
->Append(new wxExpr(m_x2
));
898 expr
->Append(new wxExpr(m_y2
));
901 case DRAWOP_DRAW_ROUNDED_RECT
:
903 expr
->Append(new wxExpr(m_x1
));
904 expr
->Append(new wxExpr(m_y1
));
905 expr
->Append(new wxExpr(m_x2
));
906 expr
->Append(new wxExpr(m_y2
));
907 expr
->Append(new wxExpr(m_radius
));
910 case DRAWOP_DRAW_POINT
:
912 expr
->Append(new wxExpr(m_x1
));
913 expr
->Append(new wxExpr(m_y1
));
916 case DRAWOP_DRAW_TEXT
:
918 expr
->Append(new wxExpr(m_x1
));
919 expr
->Append(new wxExpr(m_y1
));
920 expr
->Append(new wxExpr(wxExprString
, m_textString
));
923 case DRAWOP_DRAW_ARC
:
924 case DRAWOP_DRAW_ELLIPTIC_ARC
:
926 expr
->Append(new wxExpr(m_x1
));
927 expr
->Append(new wxExpr(m_y1
));
928 expr
->Append(new wxExpr(m_x2
));
929 expr
->Append(new wxExpr(m_y2
));
930 expr
->Append(new wxExpr(m_x3
));
931 expr
->Append(new wxExpr(m_y3
));
942 void wxOpDraw::ReadExpr(wxPseudoMetaFile
*WXUNUSED(image
), wxExpr
*expr
)
946 case DRAWOP_DRAW_LINE
:
947 case DRAWOP_DRAW_RECT
:
948 case DRAWOP_DRAW_ELLIPSE
:
950 m_x1
= expr
->Nth(1)->RealValue();
951 m_y1
= expr
->Nth(2)->RealValue();
952 m_x2
= expr
->Nth(3)->RealValue();
953 m_y2
= expr
->Nth(4)->RealValue();
956 case DRAWOP_DRAW_ROUNDED_RECT
:
958 m_x1
= expr
->Nth(1)->RealValue();
959 m_y1
= expr
->Nth(2)->RealValue();
960 m_x2
= expr
->Nth(3)->RealValue();
961 m_y2
= expr
->Nth(4)->RealValue();
962 m_radius
= expr
->Nth(5)->RealValue();
965 case DRAWOP_DRAW_POINT
:
967 m_x1
= expr
->Nth(1)->RealValue();
968 m_y1
= expr
->Nth(2)->RealValue();
971 case DRAWOP_DRAW_TEXT
:
973 m_x1
= expr
->Nth(1)->RealValue();
974 m_y1
= expr
->Nth(2)->RealValue();
975 wxString
str(expr
->Nth(3)->StringValue());
976 m_textString
= copystring(str
);
979 case DRAWOP_DRAW_ARC
:
980 case DRAWOP_DRAW_ELLIPTIC_ARC
:
982 m_x1
= expr
->Nth(1)->RealValue();
983 m_y1
= expr
->Nth(2)->RealValue();
984 m_x2
= expr
->Nth(3)->RealValue();
985 m_y2
= expr
->Nth(4)->RealValue();
986 m_x3
= expr
->Nth(5)->RealValue();
987 m_y3
= expr
->Nth(6)->RealValue();
999 * Draw polygon, polyline, spline
1003 wxOpPolyDraw::wxOpPolyDraw(int theOp
, int n
, wxRealPoint
*thePoints
):wxDrawOp(theOp
)
1006 m_points
= thePoints
;
1009 wxOpPolyDraw::~wxOpPolyDraw()
1014 wxDrawOp
*wxOpPolyDraw::Copy(wxPseudoMetaFile
*WXUNUSED(newImage
))
1016 wxRealPoint
*newPoints
= new wxRealPoint
[m_noPoints
];
1017 for (int i
= 0; i
< m_noPoints
; i
++)
1019 newPoints
[i
].x
= m_points
[i
].x
;
1020 newPoints
[i
].y
= m_points
[i
].y
;
1022 wxOpPolyDraw
*newOp
= new wxOpPolyDraw(m_op
, m_noPoints
, newPoints
);
1026 void wxOpPolyDraw::Do(wxDC
& dc
, double xoffset
, double yoffset
)
1030 case DRAWOP_DRAW_POLYLINE
:
1032 wxPoint
*actualPoints
= new wxPoint
[m_noPoints
];
1034 for (i
= 0; i
< m_noPoints
; i
++)
1036 actualPoints
[i
].x
= WXROUND(m_points
[i
].x
);
1037 actualPoints
[i
].y
= WXROUND(m_points
[i
].y
);
1040 dc
.DrawLines(m_noPoints
, actualPoints
, WXROUND(xoffset
), WXROUND(yoffset
));
1042 delete[] actualPoints
;
1045 case DRAWOP_DRAW_POLYGON
:
1047 wxPoint
*actualPoints
= new wxPoint
[m_noPoints
];
1049 for (i
= 0; i
< m_noPoints
; i
++)
1051 actualPoints
[i
].x
= WXROUND(m_points
[i
].x
);
1052 actualPoints
[i
].y
= WXROUND(m_points
[i
].y
);
1055 dc
.DrawPolygon(m_noPoints
, actualPoints
, WXROUND(xoffset
), WXROUND(yoffset
));
1057 delete[] actualPoints
;
1060 case DRAWOP_DRAW_SPLINE
:
1062 wxPoint
*actualPoints
= new wxPoint
[m_noPoints
];
1064 for (i
= 0; i
< m_noPoints
; i
++)
1066 actualPoints
[i
].x
= WXROUND(m_points
[i
].x
);
1067 actualPoints
[i
].y
= WXROUND(m_points
[i
].y
);
1070 dc
.DrawSpline(m_noPoints
, actualPoints
); // no offsets in DrawSpline // , xoffset, yoffset);
1072 delete[] actualPoints
;
1080 void wxOpPolyDraw::Scale(double scaleX
, double scaleY
)
1082 for (int i
= 0; i
< m_noPoints
; i
++)
1084 m_points
[i
].x
*= scaleX
;
1085 m_points
[i
].y
*= scaleY
;
1089 void wxOpPolyDraw::Translate(double x
, double y
)
1091 for (int i
= 0; i
< m_noPoints
; i
++)
1098 void wxOpPolyDraw::Rotate(double x
, double y
, double WXUNUSED(theta
), double sinTheta
, double cosTheta
)
1100 for (int i
= 0; i
< m_noPoints
; i
++)
1102 double x1
= m_points
[i
].x
;
1103 double y1
= m_points
[i
].y
;
1104 m_points
[i
].x
= x1
*cosTheta
- y1
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
1105 m_points
[i
].y
= x1
*sinTheta
+ y1
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
1110 wxExpr
*wxOpPolyDraw::WriteExpr(wxPseudoMetaFile
*WXUNUSED(image
))
1112 wxExpr
*expr
= new wxExpr(wxExprList
);
1113 expr
->Append(new wxExpr((long)m_op
));
1114 expr
->Append(new wxExpr((long)m_noPoints
));
1123 * Store each coordinate pair in a hex string to save space.
1124 * E.g. "1B9080CD". 4 hex digits per coordinate pair.
1128 for (int i
= 0; i
< m_noPoints
; i
++)
1130 long signedX
= (long)(m_points
[i
].x
*100.0);
1131 long signedY
= (long)(m_points
[i
].y
*100.0);
1133 // Scale to 0 -> 64K
1134 long unSignedX
= (long)(signedX
+ 32767.0);
1135 long unSignedY
= (long)(signedY
+ 32767.0);
1137 // IntToHex((unsigned int)signedX, buf2);
1138 // IntToHex((unsigned int)signedY, buf3);
1139 IntToHex((int)unSignedX
, buf2
);
1140 IntToHex((int)unSignedY
, buf3
);
1142 // Don't overrun the buffer
1145 wxStrcat(oglBuffer
, buf2
);
1146 wxStrcat(oglBuffer
, buf3
);
1149 expr
->Append(new wxExpr(wxExprString
, oglBuffer
));
1153 void wxOpPolyDraw::ReadExpr(wxPseudoMetaFile
*WXUNUSED(image
), wxExpr
*expr
)
1155 m_noPoints
= (int)expr
->Nth(1)->IntegerValue();
1160 m_points
= new wxRealPoint
[m_noPoints
];
1163 wxString hexString
= expr
->Nth(2)->StringValue();
1164 while (i
< m_noPoints
)
1166 buf1
[0] = hexString
[(size_t)bufPtr
];
1167 buf1
[1] = hexString
[(size_t)(bufPtr
+ 1)];
1168 buf1
[2] = hexString
[(size_t)(bufPtr
+ 2)];
1169 buf1
[3] = hexString
[(size_t)(bufPtr
+ 3)];
1172 buf2
[0] = hexString
[(size_t)(bufPtr
+ 4)];
1173 buf2
[1] = hexString
[(size_t)(bufPtr
+ 5)];
1174 buf2
[2] = hexString
[(size_t)(bufPtr
+ 6)];
1175 buf2
[3] = hexString
[(size_t)(bufPtr
+ 7)];
1180 // int signedX = (signed int)HexToInt(buf1);
1181 // int signedY = (signed int)HexToInt(buf2);
1182 long unSignedX
= HexToInt(buf1
);
1183 long unSignedY
= HexToInt(buf2
);
1184 // Scale -32K -> +32K
1185 long signedX
= unSignedX
- 32767;
1186 long signedY
= unSignedY
- 32767;
1187 #if defined(__WXMSW__) && 0
1188 int testX
= (signed int)unSignedX
;
1189 int testY
= (signed int)unSignedY
;
1192 m_points
[i
].x
= (double)(signedX
/ 100.0);
1193 m_points
[i
].y
= (double)(signedY
/ 100.0);
1200 // Draw an outline using the current operation.
1201 bool wxOpPolyDraw::OnDrawOutline(wxDC
& dc
, double x
, double y
, double w
, double h
, double oldW
, double oldH
)
1203 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1205 // Multiply all points by proportion of new size to old size
1206 double x_proportion
= (double)(fabs(w
/oldW
));
1207 double y_proportion
= (double)(fabs(h
/oldH
));
1210 wxPoint
*intPoints
= new wxPoint
[n
];
1212 for (i
= 0; i
< n
; i
++)
1214 intPoints
[i
].x
= WXROUND (x_proportion
* m_points
[i
].x
);
1215 intPoints
[i
].y
= WXROUND (y_proportion
* m_points
[i
].y
);
1217 dc
.DrawPolygon(n
, intPoints
, (long) x
, (long) y
);
1222 // Assume (x1, y1) is centre of box (most generally, line end at box)
1223 bool wxOpPolyDraw::GetPerimeterPoint(double x1
, double y1
,
1224 double x2
, double y2
,
1225 double *x3
, double *y3
,
1226 double xOffset
, double yOffset
,
1231 // First check for situation where the line is vertical,
1232 // and we would want to connect to a point on that vertical --
1233 // oglFindEndForPolyline can't cope with this (the arrow
1234 // gets drawn to the wrong place).
1235 if ((attachmentMode
== ATTACHMENT_MODE_NONE
) && (x1
== x2
))
1237 // Look for the point we'd be connecting to. This is
1240 for (i
= 0; i
< n
; i
++)
1242 wxRealPoint
*point
= & (m_points
[i
]);
1243 if (point
->x
== 0.0)
1245 if ((y2
> y1
) && (point
->y
> 0.0))
1247 *x3
= point
->x
+ xOffset
;
1248 *y3
= point
->y
+ yOffset
;
1251 else if ((y2
< y1
) && (point
->y
< 0.0))
1253 *x3
= point
->x
+ xOffset
;
1254 *y3
= point
->y
+ yOffset
;
1261 double *xpoints
= new double[n
];
1262 double *ypoints
= new double[n
];
1265 for (i
= 0; i
< n
; i
++)
1267 wxRealPoint
*point
= & (m_points
[i
]);
1268 xpoints
[i
] = point
->x
+ xOffset
;
1269 ypoints
[i
] = point
->y
+ yOffset
;
1272 oglFindEndForPolyline(n
, xpoints
, ypoints
,
1273 x1
, y1
, x2
, y2
, x3
, y3
);
1287 static char hexArray
[] = {
1288 _T('0'), _T('1'), _T('2'), _T('3'), _T('4'), _T('5'), _T('6'), _T('7'),
1289 _T('8'), _T('9'), _T('A'), _T('B'), _T('C'), _T('D'), _T('E'), _T('F') };
1291 // Convert unsigned 16-bit integer to 4-character hex string
1292 static void IntToHex(unsigned int dec
, wxChar
*buf
)
1294 int digit1
= (int)(dec
/4096);
1295 int digit2
= (int)((dec
- (digit1
*4096))/256);
1296 int digit3
= (int)((dec
- (digit1
*4096) - (digit2
*256))/16);
1297 int digit4
= dec
- (digit1
*4096 + digit2
*256 + digit3
*16);
1299 buf
[0] = hexArray
[digit1
];
1300 buf
[1] = hexArray
[digit2
];
1301 buf
[2] = hexArray
[digit3
];
1302 buf
[3] = hexArray
[digit4
];
1306 // One hex digit to decimal number
1307 static int HexToInt1(wxChar hex
)
1344 // handling this default outside switch removes warning under Borland
1353 // 4-digit hex string to unsigned integer
1354 static unsigned long HexToInt(wxChar
*buf
)
1356 long d1
= (long)(HexToInt1(buf
[0])*4096.0) ;
1357 long d2
= (long)(HexToInt1(buf
[1])*256.0) ;
1358 long d3
= (long)(HexToInt1(buf
[2])*16.0) ;
1359 long d4
= (long)(HexToInt1(buf
[3])) ;
1360 unsigned long n
= (long)(d1
+ d2
+ d3
+ d4
) ;
1365 * wxPseudo meta-file
1369 IMPLEMENT_DYNAMIC_CLASS(wxPseudoMetaFile
, wxObject
)
1371 wxPseudoMetaFile::wxPseudoMetaFile()
1373 m_currentRotation
= 0;
1374 m_rotateable
= TRUE
;
1377 m_outlinePen
= NULL
;
1382 wxPseudoMetaFile::wxPseudoMetaFile(wxPseudoMetaFile
& mf
)
1387 wxPseudoMetaFile::~wxPseudoMetaFile()
1392 void wxPseudoMetaFile::Clear()
1394 wxNode
*node
= m_ops
.GetFirst();
1397 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1399 node
= node
->GetNext();
1402 m_gdiObjects
.Clear();
1403 m_outlineColours
.Clear();
1404 m_fillColours
.Clear();
1408 void wxPseudoMetaFile::Draw(wxDC
& dc
, double xoffset
, double yoffset
)
1410 wxNode
*node
= m_ops
.GetFirst();
1413 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1414 op
->Do(dc
, xoffset
, yoffset
);
1415 node
= node
->GetNext();
1419 void wxPseudoMetaFile::Scale(double sx
, double sy
)
1421 wxNode
*node
= m_ops
.GetFirst();
1424 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1426 node
= node
->GetNext();
1432 void wxPseudoMetaFile::Translate(double x
, double y
)
1434 wxNode
*node
= m_ops
.GetFirst();
1437 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1438 op
->Translate(x
, y
);
1439 node
= node
->GetNext();
1443 void wxPseudoMetaFile::Rotate(double x
, double y
, double theta
)
1445 double theta1
= theta
-m_currentRotation
;
1446 if (theta1
== 0.0) return;
1447 double cosTheta
= (double)cos(theta1
);
1448 double sinTheta
= (double)sin(theta1
);
1450 wxNode
*node
= m_ops
.GetFirst();
1453 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1454 op
->Rotate(x
, y
, theta
, sinTheta
, cosTheta
);
1455 node
= node
->GetNext();
1457 m_currentRotation
= theta
;
1461 void wxPseudoMetaFile::WriteAttributes(wxExpr
*clause
, int whichAngle
)
1464 widthStr
.Printf(wxT("meta_width%d"), whichAngle
);
1467 heightStr
.Printf(wxT("meta_height%d"), whichAngle
);
1469 wxString outlineStr
;
1470 outlineStr
.Printf(wxT("outline_op%d"), whichAngle
);
1472 wxString rotateableStr
;
1473 rotateableStr
.Printf(wxT("meta_rotateable%d"), whichAngle
);
1475 // Write width and height
1476 clause
->AddAttributeValue(widthStr
, m_width
);
1477 clause
->AddAttributeValue(heightStr
, m_height
);
1478 clause
->AddAttributeValue(rotateableStr
, (long)m_rotateable
);
1479 clause
->AddAttributeValue(outlineStr
, (long)m_outlineOp
);
1481 // Write GDI objects
1484 wxNode
*node
= m_gdiObjects
.GetFirst();
1487 wxSprintf(buf
, _T("gdi%d_%d"), whichAngle
, i
);
1488 wxObject
*obj
= (wxObject
*)node
->GetData();
1489 wxExpr
*expr
= NULL
;
1492 if (obj
->IsKindOf(CLASSINFO(wxPen
)))
1494 wxPen
*thePen
= (wxPen
*)obj
;
1495 expr
= new wxExpr(wxExprList
);
1496 expr
->Append(new wxExpr((long)gyTYPE_PEN
));
1497 expr
->Append(new wxExpr((long)thePen
->GetWidth()));
1498 expr
->Append(new wxExpr((long)thePen
->GetStyle()));
1499 expr
->Append(new wxExpr((long)thePen
->GetColour().Red()));
1500 expr
->Append(new wxExpr((long)thePen
->GetColour().Green()));
1501 expr
->Append(new wxExpr((long)thePen
->GetColour().Blue()));
1503 else if (obj
->IsKindOf(CLASSINFO(wxBrush
)))
1505 wxBrush
*theBrush
= (wxBrush
*)obj
;
1506 expr
= new wxExpr(wxExprList
);
1507 expr
->Append(new wxExpr((long)gyTYPE_BRUSH
));
1508 expr
->Append(new wxExpr((long)theBrush
->GetStyle()));
1509 expr
->Append(new wxExpr((long)theBrush
->GetColour().Red()));
1510 expr
->Append(new wxExpr((long)theBrush
->GetColour().Green()));
1511 expr
->Append(new wxExpr((long)theBrush
->GetColour().Blue()));
1513 else if (obj
->IsKindOf(CLASSINFO(wxFont
)))
1515 wxFont
*theFont
= (wxFont
*)obj
;
1516 expr
= new wxExpr(wxExprList
);
1517 expr
->Append(new wxExpr((long)gyTYPE_FONT
));
1518 expr
->Append(new wxExpr((long)theFont
->GetPointSize()));
1519 expr
->Append(new wxExpr((long)theFont
->GetFamily()));
1520 expr
->Append(new wxExpr((long)theFont
->GetStyle()));
1521 expr
->Append(new wxExpr((long)theFont
->GetWeight()));
1522 expr
->Append(new wxExpr((long)theFont
->GetUnderlined()));
1527 // If no recognised GDI object, append a place holder anyway.
1528 expr
= new wxExpr(wxExprList
);
1529 expr
->Append(new wxExpr((long)0));
1534 clause
->AddAttributeValue(buf
, expr
);
1537 node
= node
->GetNext();
1540 // Write drawing operations
1542 node
= m_ops
.GetFirst();
1545 wxSprintf(buf
, _T("op%d_%d"), whichAngle
, i
);
1546 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1547 wxExpr
*expr
= op
->WriteExpr(this);
1550 clause
->AddAttributeValue(buf
, expr
);
1553 node
= node
->GetNext();
1556 // Write outline and fill GDI op lists (if any)
1557 if (m_outlineColours
.GetCount() > 0)
1559 wxExpr
*outlineExpr
= new wxExpr(wxExprList
);
1560 node
= m_outlineColours
.GetFirst();
1563 outlineExpr
->Append(new wxExpr((long)node
->GetData()));
1564 node
= node
->GetNext();
1566 wxString outlineObjectsStr
;
1567 outlineObjectsStr
.Printf(wxT("outline_objects%d"), whichAngle
);
1569 clause
->AddAttributeValue(outlineObjectsStr
, outlineExpr
);
1571 if (m_fillColours
.GetCount() > 0)
1573 wxExpr
*fillExpr
= new wxExpr(wxExprList
);
1574 node
= m_fillColours
.GetFirst();
1577 fillExpr
->Append(new wxExpr((long)node
->GetData()));
1578 node
= node
->GetNext();
1580 wxString fillObjectsStr
;
1581 fillObjectsStr
.Printf(wxT("fill_objects%d"), whichAngle
);
1583 clause
->AddAttributeValue(fillObjectsStr
, fillExpr
);
1588 void wxPseudoMetaFile::ReadAttributes(wxExpr
*clause
, int whichAngle
)
1591 widthStr
.Printf(wxT("meta_width%d"), whichAngle
);
1594 heightStr
.Printf(wxT("meta_height%d"), whichAngle
);
1596 wxString outlineStr
;
1597 outlineStr
.Printf(wxT("outline_op%d"), whichAngle
);
1599 wxString rotateableStr
;
1600 rotateableStr
.Printf(wxT("meta_rotateable%d"), whichAngle
);
1602 clause
->GetAttributeValue(widthStr
, m_width
);
1603 clause
->GetAttributeValue(heightStr
, m_height
);
1604 clause
->GetAttributeValue(outlineStr
, m_outlineOp
);
1606 int iVal
= (int) m_rotateable
;
1607 clause
->GetAttributeValue(rotateableStr
, iVal
);
1608 m_rotateable
= (iVal
!= 0);
1613 bool keepGoing
= TRUE
;
1616 wxSprintf(buf
, _T("gdi%d_%d"), whichAngle
, i
);
1617 wxExpr
*expr
= NULL
;
1618 clause
->GetAttributeValue(buf
, &expr
);
1625 wxExpr
*idExpr
= expr
->Nth(0);
1626 switch (idExpr
->IntegerValue())
1630 int penWidth
= (int)expr
->Nth(1)->IntegerValue();
1631 int penStyle
= (int)expr
->Nth(2)->IntegerValue();
1632 int penRed
= (int)expr
->Nth(3)->IntegerValue();
1633 int penGreen
= (int)expr
->Nth(4)->IntegerValue();
1634 int penBlue
= (int)expr
->Nth(5)->IntegerValue();
1635 wxColour
col(penRed
, penGreen
, penBlue
);
1636 wxPen
*p
= wxThePenList
->FindOrCreatePen(col
, penWidth
, penStyle
);
1639 m_gdiObjects
.Append(p
);
1644 int brushStyle
= (int)expr
->Nth(1)->IntegerValue();
1645 int brushRed
= (int)expr
->Nth(2)->IntegerValue();
1646 int brushGreen
= (int)expr
->Nth(3)->IntegerValue();
1647 int brushBlue
= (int)expr
->Nth(4)->IntegerValue();
1648 wxColour
col(brushRed
, brushGreen
, brushBlue
);
1649 wxBrush
*b
= wxTheBrushList
->FindOrCreateBrush(col
, brushStyle
);
1652 m_gdiObjects
.Append(b
);
1657 int fontPointSize
= (int)expr
->Nth(1)->IntegerValue();
1658 int fontFamily
= (int)expr
->Nth(2)->IntegerValue();
1659 int fontStyle
= (int)expr
->Nth(3)->IntegerValue();
1660 int fontWeight
= (int)expr
->Nth(4)->IntegerValue();
1661 int fontUnderlined
= (int)expr
->Nth(5)->IntegerValue();
1662 m_gdiObjects
.Append(wxTheFontList
->FindOrCreateFont(fontPointSize
,
1663 fontFamily
, fontStyle
, fontWeight
, (fontUnderlined
!= 0)));
1669 m_gdiObjects
.Append(NULL
);
1677 // Now read in the operations
1682 wxSprintf(buf
, _T("op%d_%d"), whichAngle
, i
);
1683 wxExpr
*expr
= NULL
;
1684 clause
->GetAttributeValue(buf
, &expr
);
1691 wxExpr
*idExpr
= expr
->Nth(0);
1692 int opId
= (int)idExpr
->IntegerValue();
1695 case DRAWOP_SET_PEN
:
1696 case DRAWOP_SET_BRUSH
:
1697 case DRAWOP_SET_FONT
:
1698 case DRAWOP_SET_TEXT_COLOUR
:
1699 case DRAWOP_SET_BK_COLOUR
:
1700 case DRAWOP_SET_BK_MODE
:
1702 wxOpSetGDI
*theOp
= new wxOpSetGDI(opId
, this, 0);
1703 theOp
->ReadExpr(this, expr
);
1704 m_ops
.Append(theOp
);
1708 case DRAWOP_SET_CLIPPING_RECT
:
1709 case DRAWOP_DESTROY_CLIPPING_RECT
:
1711 wxOpSetClipping
*theOp
= new wxOpSetClipping(opId
, 0.0, 0.0, 0.0, 0.0);
1712 theOp
->ReadExpr(this, expr
);
1713 m_ops
.Append(theOp
);
1717 case DRAWOP_DRAW_LINE
:
1718 case DRAWOP_DRAW_RECT
:
1719 case DRAWOP_DRAW_ROUNDED_RECT
:
1720 case DRAWOP_DRAW_ELLIPSE
:
1721 case DRAWOP_DRAW_POINT
:
1722 case DRAWOP_DRAW_ARC
:
1723 case DRAWOP_DRAW_TEXT
:
1725 wxOpDraw
*theOp
= new wxOpDraw(opId
, 0.0, 0.0, 0.0, 0.0);
1726 theOp
->ReadExpr(this, expr
);
1727 m_ops
.Append(theOp
);
1730 case DRAWOP_DRAW_SPLINE
:
1731 case DRAWOP_DRAW_POLYLINE
:
1732 case DRAWOP_DRAW_POLYGON
:
1734 wxOpPolyDraw
*theOp
= new wxOpPolyDraw(opId
, 0, NULL
);
1735 theOp
->ReadExpr(this, expr
);
1736 m_ops
.Append(theOp
);
1746 wxString outlineObjectsStr
;
1747 outlineObjectsStr
.Printf(wxT("outline_objects%d"), whichAngle
);
1749 // Now read in the list of outline and fill operations, if any
1750 wxExpr
*expr1
= clause
->AttributeValue(outlineObjectsStr
);
1753 wxExpr
*eachExpr
= expr1
->GetFirst();
1756 m_outlineColours
.Append((wxObject
*)eachExpr
->IntegerValue());
1757 eachExpr
= eachExpr
->GetNext();
1761 wxString fillObjectsStr
;
1762 fillObjectsStr
.Printf(wxT("fill_objects%d"), whichAngle
);
1764 expr1
= clause
->AttributeValue(fillObjectsStr
);
1767 wxExpr
*eachExpr
= expr1
->GetFirst();
1770 m_fillColours
.Append((wxObject
*)eachExpr
->IntegerValue());
1771 eachExpr
= eachExpr
->GetNext();
1777 // Does the copying for this object
1778 void wxPseudoMetaFile::Copy(wxPseudoMetaFile
& copy
)
1782 copy
.m_currentRotation
= m_currentRotation
;
1783 copy
.m_width
= m_width
;
1784 copy
.m_height
= m_height
;
1785 copy
.m_rotateable
= m_rotateable
;
1786 copy
.m_fillBrush
= m_fillBrush
;
1787 copy
.m_outlinePen
= m_outlinePen
;
1788 copy
.m_outlineOp
= m_outlineOp
;
1790 // Copy the GDI objects
1791 wxNode
*node
= m_gdiObjects
.GetFirst();
1794 wxObject
*obj
= (wxObject
*)node
->GetData();
1795 copy
.m_gdiObjects
.Append(obj
);
1796 node
= node
->GetNext();
1799 // Copy the operations
1800 node
= m_ops
.GetFirst();
1803 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1804 copy
.m_ops
.Append(op
->Copy(©
));
1805 node
= node
->GetNext();
1808 // Copy the outline/fill operations
1809 node
= m_outlineColours
.GetFirst();
1812 copy
.m_outlineColours
.Append((wxObject
*)node
->GetData());
1813 node
= node
->GetNext();
1815 node
= m_fillColours
.GetFirst();
1818 copy
.m_fillColours
.Append((wxObject
*)node
->GetData());
1819 node
= node
->GetNext();
1824 * Pass size of existing image; scale height to
1825 * fit width and return new width and height.
1829 bool wxPseudoMetaFile::LoadFromMetaFile(const wxString
& filename
, double *rwidth
, double *rheight
)
1831 if (!wxFileExists(filename
))
1834 wxXMetaFile
*metaFile
= new wxXMetaFile
;
1836 if (!metaFile
->ReadFile(filename
))
1845 // Convert from metafile records to wxDrawnShape records
1846 wxNode
*node
= metaFile
->metaRecords
.GetFirst();
1849 wxMetaRecord
*record
= (wxMetaRecord
*)node
->GetData();
1850 switch (record
->metaFunction
)
1852 case META_SETBKCOLOR
:
1854 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_BK_COLOUR
, this, 0);
1855 op
->m_r
= (unsigned char)record
->param1
;
1856 op
->m_g
= (unsigned char)record
->param2
;
1857 op
->m_b
= (unsigned char)record
->param3
;
1861 case META_SETBKMODE
:
1863 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_BK_MODE
, this, 0, (int)record
->param1
);
1867 case META_SETMAPMODE
:
1871 // case META_SETROP2:
1872 // case META_SETRELABS:
1873 // case META_SETPOLYFILLMODE:
1874 // case META_SETSTRETCHBLTMODE:
1875 // case META_SETTEXTCHAREXTRA:
1876 case META_SETTEXTCOLOR
:
1878 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_TEXT_COLOUR
, this, 0);
1879 op
->m_r
= (unsigned char)record
->param1
;
1880 op
->m_g
= (unsigned char)record
->param2
;
1881 op
->m_b
= (unsigned char)record
->param3
;
1885 // case META_SETTEXTJUSTIFICATION:
1886 // case META_SETWINDOWORG:
1887 // case META_SETWINDOWEXT:
1888 // case META_SETVIEWPORTORG:
1889 // case META_SETVIEWPORTEXT:
1890 // case META_OFFSETWINDOWORG:
1891 // case META_SCALEWINDOWEXT:
1892 // case META_OFFSETVIEWPORTORG:
1893 // case META_SCALEVIEWPORTEXT:
1896 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_LINE
, (double)lastX
, (double)lastY
,
1897 (double)record
->param1
, (double)record
->param2
);
1903 lastX
= (double)record
->param1
;
1904 lastY
= (double)record
->param2
;
1907 case META_EXCLUDECLIPRECT
:
1910 wxMetaRecord *rec = new wxMetaRecord(META_EXCLUDECLIPRECT);
1911 rec->param4 = getshort(handle); // m_y2
1912 rec->param3 = getshort(handle); // x2
1913 rec->param2 = getshort(handle); // y1
1914 rec->param1 = getshort(handle); // x1
1918 case META_INTERSECTCLIPRECT
:
1921 rec->param4 = getshort(handle); // m_y2
1922 rec->param3 = getshort(handle); // x2
1923 rec->param2 = getshort(handle); // y1
1924 rec->param1 = getshort(handle); // x1
1928 // case META_ARC: // DO!!!
1931 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_ELLIPSE
,
1932 (double)record
->param1
, (double)record
->param2
,
1933 (double)(record
->param3
- record
->param1
),
1934 (double)(record
->param4
- record
->param2
));
1938 // case META_FLOODFILL:
1939 // case META_PIE: // DO!!!
1940 case META_RECTANGLE
:
1942 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_RECT
,
1943 (double)record
->param1
, (double)record
->param2
,
1944 (double)(record
->param3
- record
->param1
),
1945 (double)(record
->param4
- record
->param2
));
1949 case META_ROUNDRECT
:
1951 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_ROUNDED_RECT
,
1952 (double)record
->param1
, (double)record
->param2
,
1953 (double)(record
->param3
- record
->param1
),
1954 (double)(record
->param4
- record
->param2
), (double)record
->param5
);
1958 // case META_PATBLT:
1959 // case META_SAVEDC:
1962 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_POINT
,
1963 (double)record
->param1
, (double)record
->param2
,
1966 // SHOULD SET THE COLOUR - SET PEN?
1967 // rec->param3 = getint(handle); // COLORREF
1971 // case META_OFFSETCLIPRGN:
1974 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_TEXT
,
1975 (double)record
->param1
, (double)record
->param2
,
1976 0.0, 0.0, 0.0, record
->stringParam
);
1980 // case META_BITBLT:
1981 // case META_STRETCHBLT:
1984 int n
= (int)record
->param1
;
1985 wxRealPoint
*newPoints
= new wxRealPoint
[n
];
1986 for (int i
= 0; i
< n
; i
++)
1988 newPoints
[i
].x
= record
->points
[i
].x
;
1989 newPoints
[i
].y
= record
->points
[i
].y
;
1992 wxOpPolyDraw
*op
= new wxOpPolyDraw(DRAWOP_DRAW_POLYGON
, n
, newPoints
);
1998 int n
= (int)record
->param1
;
1999 wxRealPoint
*newPoints
= new wxRealPoint
[n
];
2000 for (int i
= 0; i
< n
; i
++)
2002 newPoints
[i
].x
= record
->points
[i
].x
;
2003 newPoints
[i
].y
= record
->points
[i
].y
;
2006 wxOpPolyDraw
*op
= new wxOpPolyDraw(DRAWOP_DRAW_POLYLINE
, n
, newPoints
);
2010 // case META_ESCAPE:
2011 // case META_RESTOREDC:
2012 // case META_FILLREGION:
2013 // case META_FRAMEREGION:
2014 // case META_INVERTREGION:
2015 // case META_PAINTREGION:
2016 // case META_SELECTCLIPREGION: // DO THIS!
2017 case META_SELECTOBJECT
:
2019 // The pen, brush etc. has already been created when the metafile
2020 // was read in, so we don't create it - we set it.
2021 wxNode
*recNode
= metaFile
->gdiObjects
.Item((int)record
->param2
);
2024 wxMetaRecord
*gdiRec
= (wxMetaRecord
*)recNode
->GetData();
2025 if (gdiRec
&& (gdiRec
->param1
!= 0))
2027 wxObject
*obj
= (wxObject
*)gdiRec
->param1
;
2028 if (obj
->IsKindOf(CLASSINFO(wxPen
)))
2030 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_PEN
, this, (int)record
->param2
);
2033 else if (obj
->IsKindOf(CLASSINFO(wxBrush
)))
2035 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_BRUSH
, this, (int)record
->param2
);
2038 else if (obj
->IsKindOf(CLASSINFO(wxFont
)))
2040 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_FONT
, this, (int)record
->param2
);
2047 // case META_SETTEXTALIGN:
2048 // case META_DRAWTEXT:
2050 // case META_SETMAPPERFLAGS:
2051 // case META_EXTTEXTOUT:
2052 // case META_SETDIBTODEV:
2053 // case META_SELECTPALETTE:
2054 // case META_REALIZEPALETTE:
2055 // case META_ANIMATEPALETTE:
2056 // case META_SETPALENTRIES:
2057 // case META_POLYPOLYGON:
2058 // case META_RESIZEPALETTE:
2059 // case META_DIBBITBLT:
2060 // case META_DIBSTRETCHBLT:
2061 case META_DIBCREATEPATTERNBRUSH
:
2064 m_gdiObjects
.Append(NULL
);
2067 // case META_STRETCHDIB:
2068 // case META_EXTFLOODFILL:
2069 // case META_RESETDC:
2070 // case META_STARTDOC:
2071 // case META_STARTPAGE:
2072 // case META_ENDPAGE:
2073 // case META_ABORTDOC:
2074 // case META_ENDDOC:
2075 // case META_DELETEOBJECT: // DO!!
2076 case META_CREATEPALETTE
:
2079 m_gdiObjects
.Append(NULL
);
2082 case META_CREATEBRUSH
:
2085 m_gdiObjects
.Append(NULL
);
2088 case META_CREATEPATTERNBRUSH
:
2091 m_gdiObjects
.Append(NULL
);
2094 case META_CREATEPENINDIRECT
:
2096 // The pen is created when the metafile is read in.
2097 // We keep track of all the GDI objects needed for this
2098 // image so when reading the wxDrawnShape from file,
2099 // we can read in all the GDI objects, then refer
2100 // to them by an index starting from zero thereafter.
2101 m_gdiObjects
.Append((wxObject
*)record
->param1
);
2104 case META_CREATEFONTINDIRECT
:
2106 m_gdiObjects
.Append((wxObject
*)record
->param1
);
2109 case META_CREATEBRUSHINDIRECT
:
2111 // Don't have to do anything here: the pen is created
2112 // when the metafile is read in.
2113 m_gdiObjects
.Append((wxObject
*)record
->param1
);
2116 case META_CREATEBITMAPINDIRECT
:
2119 m_gdiObjects
.Append(NULL
);
2122 case META_CREATEBITMAP
:
2125 m_gdiObjects
.Append(NULL
);
2128 case META_CREATEREGION
:
2131 m_gdiObjects
.Append(NULL
);
2139 node
= node
->GetNext();
2141 double actualWidth
= (double)fabs(metaFile
->right
- metaFile
->left
);
2142 double actualHeight
= (double)fabs(metaFile
->bottom
- metaFile
->top
);
2144 double initialScaleX
= 1.0;
2145 double initialScaleY
= 1.0;
2147 double xoffset
, yoffset
;
2149 // Translate so origin is at centre of rectangle
2150 if (metaFile
->bottom
> metaFile
->top
)
2151 yoffset
= - (double)((metaFile
->bottom
- metaFile
->top
)/2.0);
2153 yoffset
= - (double)((metaFile
->top
- metaFile
->bottom
)/2.0);
2155 if (metaFile
->right
> metaFile
->left
)
2156 xoffset
= - (double)((metaFile
->right
- metaFile
->left
)/2.0);
2158 xoffset
= - (double)((metaFile
->left
- metaFile
->right
)/2.0);
2160 Translate(xoffset
, yoffset
);
2162 // Scale to a reasonable size (take the width of this wxDrawnShape
2164 if (actualWidth
!= 0.0)
2166 initialScaleX
= (double)((*rwidth
) / actualWidth
);
2167 initialScaleY
= initialScaleX
;
2168 (*rheight
) = initialScaleY
*actualHeight
;
2170 Scale(initialScaleX
, initialScaleY
);
2172 m_width
= (actualWidth
*initialScaleX
);
2173 m_height
= *rheight
;
2179 // Scale to fit size
2180 void wxPseudoMetaFile::ScaleTo(double w
, double h
)
2182 double scaleX
= (double)(w
/m_width
);
2183 double scaleY
= (double)(h
/m_height
);
2186 Scale(scaleX
, scaleY
);
2189 void wxPseudoMetaFile::GetBounds(double *boundMinX
, double *boundMinY
, double *boundMaxX
, double *boundMaxY
)
2191 double maxX
= (double) -99999.9;
2192 double maxY
= (double) -99999.9;
2193 double minX
= (double) 99999.9;
2194 double minY
= (double) 99999.9;
2196 wxNode
*node
= m_ops
.GetFirst();
2199 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
2200 switch (op
->GetOp())
2202 case DRAWOP_DRAW_LINE
:
2203 case DRAWOP_DRAW_RECT
:
2204 case DRAWOP_DRAW_ROUNDED_RECT
:
2205 case DRAWOP_DRAW_ELLIPSE
:
2206 case DRAWOP_DRAW_POINT
:
2207 case DRAWOP_DRAW_TEXT
:
2209 wxOpDraw
*opDraw
= (wxOpDraw
*)op
;
2210 if (opDraw
->m_x1
< minX
) minX
= opDraw
->m_x1
;
2211 if (opDraw
->m_x1
> maxX
) maxX
= opDraw
->m_x1
;
2212 if (opDraw
->m_y1
< minY
) minY
= opDraw
->m_y1
;
2213 if (opDraw
->m_y1
> maxY
) maxY
= opDraw
->m_y1
;
2214 if (op
->GetOp() == DRAWOP_DRAW_LINE
)
2216 if (opDraw
->m_x2
< minX
) minX
= opDraw
->m_x2
;
2217 if (opDraw
->m_x2
> maxX
) maxX
= opDraw
->m_x2
;
2218 if (opDraw
->m_y2
< minY
) minY
= opDraw
->m_y2
;
2219 if (opDraw
->m_y2
> maxY
) maxY
= opDraw
->m_y2
;
2221 else if (op
->GetOp() == DRAWOP_DRAW_RECT
||
2222 op
->GetOp() == DRAWOP_DRAW_ROUNDED_RECT
||
2223 op
->GetOp() == DRAWOP_DRAW_ELLIPSE
)
2225 if ((opDraw
->m_x1
+ opDraw
->m_x2
) < minX
) minX
= (opDraw
->m_x1
+ opDraw
->m_x2
);
2226 if ((opDraw
->m_x1
+ opDraw
->m_x2
) > maxX
) maxX
= (opDraw
->m_x1
+ opDraw
->m_x2
);
2227 if ((opDraw
->m_y1
+ opDraw
->m_y2
) < minY
) minY
= (opDraw
->m_y1
+ opDraw
->m_y2
);
2228 if ((opDraw
->m_y1
+ opDraw
->m_y2
) > maxY
) maxY
= (opDraw
->m_y1
+ opDraw
->m_y2
);
2232 case DRAWOP_DRAW_ARC
:
2234 // TODO: don't yet know how to calculate the bounding box
2235 // for an arc. So pretend it's a line; to get a correct
2236 // bounding box, draw a blank rectangle first, of the correct
2238 wxOpDraw
*opDraw
= (wxOpDraw
*)op
;
2239 if (opDraw
->m_x1
< minX
) minX
= opDraw
->m_x1
;
2240 if (opDraw
->m_x1
> maxX
) maxX
= opDraw
->m_x1
;
2241 if (opDraw
->m_y1
< minY
) minY
= opDraw
->m_y1
;
2242 if (opDraw
->m_y1
> maxY
) maxY
= opDraw
->m_y1
;
2243 if (opDraw
->m_x2
< minX
) minX
= opDraw
->m_x2
;
2244 if (opDraw
->m_x2
> maxX
) maxX
= opDraw
->m_x2
;
2245 if (opDraw
->m_y2
< minY
) minY
= opDraw
->m_y2
;
2246 if (opDraw
->m_y2
> maxY
) maxY
= opDraw
->m_y2
;
2249 case DRAWOP_DRAW_POLYLINE
:
2250 case DRAWOP_DRAW_POLYGON
:
2251 case DRAWOP_DRAW_SPLINE
:
2253 wxOpPolyDraw
*poly
= (wxOpPolyDraw
*)op
;
2254 for (int i
= 0; i
< poly
->m_noPoints
; i
++)
2256 if (poly
->m_points
[i
].x
< minX
) minX
= poly
->m_points
[i
].x
;
2257 if (poly
->m_points
[i
].x
> maxX
) maxX
= poly
->m_points
[i
].x
;
2258 if (poly
->m_points
[i
].y
< minY
) minY
= poly
->m_points
[i
].y
;
2259 if (poly
->m_points
[i
].y
> maxY
) maxY
= poly
->m_points
[i
].y
;
2266 node
= node
->GetNext();
2274 *w = (double)fabs(maxX - minX);
2275 *h = (double)fabs(maxY - minY);
2279 // Calculate size from current operations
2280 void wxPseudoMetaFile::CalculateSize(wxDrawnShape
* shape
)
2282 double boundMinX
, boundMinY
, boundMaxX
, boundMaxY
;
2284 GetBounds(& boundMinX
, & boundMinY
, & boundMaxX
, & boundMaxY
);
2286 SetSize(boundMaxX
- boundMinX
, boundMaxY
- boundMinY
);
2290 shape
->SetWidth(m_width
);
2291 shape
->SetHeight(m_height
);
2295 // Set of functions for drawing into a pseudo metafile.
2296 // They use integers, but doubles are used internally for accuracy
2299 void wxPseudoMetaFile::DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
)
2301 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_LINE
,
2302 (double) pt1
.x
, (double) pt1
.y
, (double) pt2
.x
, (double) pt2
.y
);
2304 m_ops
.Append(theOp
);
2307 void wxPseudoMetaFile::DrawRectangle(const wxRect
& rect
)
2309 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_RECT
,
2310 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2312 m_ops
.Append(theOp
);
2315 void wxPseudoMetaFile::DrawRoundedRectangle(const wxRect
& rect
, double radius
)
2317 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_ROUNDED_RECT
,
2318 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2320 theOp
->m_radius
= radius
;
2322 m_ops
.Append(theOp
);
2325 void wxPseudoMetaFile::DrawEllipse(const wxRect
& rect
)
2327 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_ELLIPSE
,
2328 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2330 m_ops
.Append(theOp
);
2333 void wxPseudoMetaFile::DrawArc(const wxPoint
& centrePt
, const wxPoint
& startPt
, const wxPoint
& endPt
)
2335 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_ARC
,
2336 (double) centrePt
.x
, (double) centrePt
.y
, (double) startPt
.x
, (double) startPt
.y
);
2338 theOp
->m_x3
= (double) endPt
.x
;
2339 theOp
->m_y3
= (double) endPt
.y
;
2341 m_ops
.Append(theOp
);
2344 void wxPseudoMetaFile::DrawEllipticArc(const wxRect
& rect
, double startAngle
, double endAngle
)
2346 const double pi
= 3.1415926535897932384626433832795 ;
2348 double startAngleRadians
= startAngle
* (pi
*2.0/360.0);
2349 double endAngleRadians
= endAngle
* (pi
*2.0/360.0);
2351 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_ELLIPTIC_ARC
,
2352 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2354 theOp
->m_x3
= startAngleRadians
;
2355 theOp
->m_y3
= endAngleRadians
;
2357 m_ops
.Append(theOp
);
2360 void wxPseudoMetaFile::DrawPoint(const wxPoint
& pt
)
2362 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_POINT
,
2363 (double) pt
.x
, (double) pt
.y
, 0.0, 0.0);
2365 m_ops
.Append(theOp
);
2368 void wxPseudoMetaFile::DrawText(const wxString
& text
, const wxPoint
& pt
)
2370 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_TEXT
,
2371 (double) pt
.x
, (double) pt
.y
, 0.0, 0.0);
2373 theOp
->m_textString
= copystring(text
);
2375 m_ops
.Append(theOp
);
2378 void wxPseudoMetaFile::DrawLines(int n
, wxPoint pts
[])
2380 wxRealPoint
* realPoints
= new wxRealPoint
[n
];
2382 for (i
= 0; i
< n
; i
++)
2384 realPoints
[i
].x
= pts
[i
].x
;
2385 realPoints
[i
].y
= pts
[i
].y
;
2387 wxOpPolyDraw
* theOp
= new wxOpPolyDraw(DRAWOP_DRAW_POLYLINE
, n
, realPoints
);
2388 m_ops
.Append(theOp
);
2391 void wxPseudoMetaFile::DrawPolygon(int n
, wxPoint pts
[], int flags
)
2393 wxRealPoint
* realPoints
= new wxRealPoint
[n
];
2395 for (i
= 0; i
< n
; i
++)
2397 realPoints
[i
].x
= pts
[i
].x
;
2398 realPoints
[i
].y
= pts
[i
].y
;
2400 wxOpPolyDraw
* theOp
= new wxOpPolyDraw(DRAWOP_DRAW_POLYGON
, n
, realPoints
);
2401 m_ops
.Append(theOp
);
2403 if (flags
& oglMETAFLAGS_OUTLINE
)
2404 m_outlineOp
= (m_ops
.GetCount() - 1);
2407 void wxPseudoMetaFile::DrawSpline(int n
, wxPoint pts
[])
2409 wxRealPoint
* realPoints
= new wxRealPoint
[n
];
2411 for (i
= 0; i
< n
; i
++)
2413 realPoints
[i
].x
= pts
[i
].x
;
2414 realPoints
[i
].y
= pts
[i
].y
;
2416 wxOpPolyDraw
* theOp
= new wxOpPolyDraw(DRAWOP_DRAW_SPLINE
, n
, realPoints
);
2417 m_ops
.Append(theOp
);
2420 void wxPseudoMetaFile::SetClippingRect(const wxRect
& rect
)
2422 /* wxOpSetClipping* theOp = */ new wxOpSetClipping(DRAWOP_SET_CLIPPING_RECT
,
2423 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2426 void wxPseudoMetaFile::DestroyClippingRect()
2428 wxOpSetClipping
* theOp
= new wxOpSetClipping(DRAWOP_DESTROY_CLIPPING_RECT
,
2429 0.0, 0.0, 0.0, 0.0);
2431 m_ops
.Append(theOp
);
2434 void wxPseudoMetaFile::SetPen(wxPen
* pen
, bool isOutline
)
2436 m_gdiObjects
.Append(pen
);
2437 int n
= m_gdiObjects
.GetCount();
2439 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_PEN
, this, n
- 1);
2441 m_ops
.Append(theOp
);
2445 m_outlineColours
.Append((wxObject
*) (n
- 1));
2449 void wxPseudoMetaFile::SetBrush(wxBrush
* brush
, bool isFill
)
2451 m_gdiObjects
.Append(brush
);
2452 int n
= m_gdiObjects
.GetCount();
2454 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_BRUSH
, this, n
- 1);
2456 m_ops
.Append(theOp
);
2460 m_fillColours
.Append((wxObject
*) (n
- 1));
2464 void wxPseudoMetaFile::SetFont(wxFont
* font
)
2466 m_gdiObjects
.Append(font
);
2467 int n
= m_gdiObjects
.GetCount();
2469 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_FONT
, this, n
- 1);
2471 m_ops
.Append(theOp
);
2474 void wxPseudoMetaFile::SetTextColour(const wxColour
& colour
)
2476 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_TEXT_COLOUR
, this, 0);
2477 theOp
->m_r
= colour
.Red();
2478 theOp
->m_g
= colour
.Green();
2479 theOp
->m_b
= colour
.Blue();
2481 m_ops
.Append(theOp
);
2484 void wxPseudoMetaFile::SetBackgroundColour(const wxColour
& colour
)
2486 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_BK_COLOUR
, this, 0);
2487 theOp
->m_r
= colour
.Red();
2488 theOp
->m_g
= colour
.Green();
2489 theOp
->m_b
= colour
.Blue();
2491 m_ops
.Append(theOp
);
2494 void wxPseudoMetaFile::SetBackgroundMode(int mode
)
2496 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_BK_MODE
, this, 0, mode
);
2498 m_ops
.Append(theOp
);