1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDrawnShape
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "drawn.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include <wx/wxprec.h>
28 #include <wx/wxexpr.h>
39 static void IntToHex(unsigned int dec
, char *buf
);
40 static unsigned long HexToInt(char *buf
);
41 extern char *oglBuffer
;
44 #define gyTYPE_BRUSH 41
45 #define gyTYPE_FONT 42
52 IMPLEMENT_DYNAMIC_CLASS(wxDrawnShape
, wxRectangleShape
)
54 wxDrawnShape::wxDrawnShape():wxRectangleShape(100.0, 50.0)
57 m_currentAngle
= oglDRAWN_ANGLE_0
;
60 wxDrawnShape::~wxDrawnShape()
64 void wxDrawnShape::OnDraw(wxDC
& dc
)
66 // Pass pen and brush in case we have force outline
68 if (m_shadowMode
!= SHADOW_NONE
)
71 m_metafiles
[m_currentAngle
].m_fillBrush
= m_shadowBrush
;
72 m_metafiles
[m_currentAngle
].m_outlinePen
= g_oglTransparentPen
;
73 m_metafiles
[m_currentAngle
].Draw(dc
, m_xpos
+ m_shadowOffsetX
, m_ypos
+ m_shadowOffsetY
);
76 m_metafiles
[m_currentAngle
].m_outlinePen
= m_pen
;
77 m_metafiles
[m_currentAngle
].m_fillBrush
= m_brush
;
78 m_metafiles
[m_currentAngle
].Draw(dc
, m_xpos
, m_ypos
);
81 void wxDrawnShape::SetSize(double w
, double h
, bool recursive
)
83 SetAttachmentSize(w
, h
);
87 if (GetWidth() == 0.0)
89 else scaleX
= w
/GetWidth();
90 if (GetHeight() == 0.0)
92 else scaleY
= h
/GetHeight();
95 for (i
= 0; i
< 4; i
++)
97 if (m_metafiles
[i
].IsValid())
98 m_metafiles
[i
].Scale(scaleX
, scaleY
);
102 SetDefaultRegionSize();
105 void wxDrawnShape::Scale(double sx
, double sy
)
108 for (i
= 0; i
< 4; i
++)
110 if (m_metafiles
[i
].IsValid())
112 m_metafiles
[i
].Scale(sx
, sy
);
113 m_metafiles
[i
].CalculateSize(this);
118 void wxDrawnShape::Translate(double x
, double y
)
121 for (i
= 0; i
< 4; i
++)
123 if (m_metafiles
[i
].IsValid())
125 m_metafiles
[i
].Translate(x
, y
);
126 m_metafiles
[i
].CalculateSize(this);
131 // theta is absolute rotation from the zero position
132 void wxDrawnShape::Rotate(double x
, double y
, double theta
)
134 m_currentAngle
= DetermineMetaFile(theta
);
136 if (m_currentAngle
== 0)
139 if (!m_metafiles
[0].GetRotateable())
142 m_metafiles
[0].Rotate(x
, y
, theta
);
145 double actualTheta
= theta
-m_rotation
;
147 // Rotate attachment points
148 double sinTheta
= (double)sin(actualTheta
);
149 double cosTheta
= (double)cos(actualTheta
);
150 wxNode
*node
= m_attachmentPoints
.First();
153 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->Data();
154 double x1
= point
->m_x
;
155 double y1
= point
->m_y
;
156 point
->m_x
= x1
*cosTheta
- y1
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
157 point
->m_y
= x1
*sinTheta
+ y1
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
162 m_metafiles
[m_currentAngle
].CalculateSize(this);
165 // Which metafile do we use now? Based on current rotation and validity
168 int wxDrawnShape::DetermineMetaFile(double rotation
)
170 double tolerance
= 0.0001;
171 const double pi
= 3.1415926535897932384626433832795 ;
173 double angle2
= pi
/2.0;
175 double angle4
= 3.0*pi
/2.0;
177 int whichMetafile
= 0;
179 if (oglRoughlyEqual(rotation
, angle1
, tolerance
))
183 else if (oglRoughlyEqual(rotation
, angle2
, tolerance
))
187 else if (oglRoughlyEqual(rotation
, angle3
, tolerance
))
191 else if (oglRoughlyEqual(rotation
, angle4
, tolerance
))
196 if ((whichMetafile
> 0) && !m_metafiles
[whichMetafile
].IsValid())
199 return whichMetafile
;
202 void wxDrawnShape::OnDrawOutline(wxDC
& dc
, double x
, double y
, double w
, double h
)
204 if (m_metafiles
[m_currentAngle
].GetOutlineOp() != -1)
206 wxNode
* node
= m_metafiles
[m_currentAngle
].GetOps().Nth(m_metafiles
[m_currentAngle
].GetOutlineOp());
207 wxASSERT (node
!= NULL
);
208 wxDrawOp
* op
= (wxDrawOp
*) node
->Data();
210 if (op
->OnDrawOutline(dc
, x
, y
, w
, h
, m_width
, m_height
))
214 // Default... just use a rectangle
215 wxRectangleShape::OnDrawOutline(dc
, x
, y
, w
, h
);
218 // Get the perimeter point using the special outline op, if there is one,
219 // otherwise use default wxRectangleShape scheme
220 bool wxDrawnShape::GetPerimeterPoint(double x1
, double y1
,
221 double x2
, double y2
,
222 double *x3
, double *y3
)
224 if (m_metafiles
[m_currentAngle
].GetOutlineOp() != -1)
226 wxNode
* node
= m_metafiles
[m_currentAngle
].GetOps().Nth(m_metafiles
[m_currentAngle
].GetOutlineOp());
227 wxASSERT (node
!= NULL
);
228 wxDrawOp
* op
= (wxDrawOp
*) node
->Data();
230 if (op
->GetPerimeterPoint(x1
, y1
, x2
, y2
, x3
, y3
, GetX(), GetY(), GetAttachmentMode()))
234 // Default... just use a rectangle
235 return wxRectangleShape::GetPerimeterPoint(x1
, y1
, x2
, y2
, x3
, y3
);
239 void wxDrawnShape::WriteAttributes(wxExpr
*clause
)
241 wxRectangleShape::WriteAttributes(clause
);
243 clause
->AddAttributeValue("save_metafile", (long)m_saveToFile
);
247 for (i
= 0; i
< 4; i
++)
249 if (m_metafiles
[i
].IsValid())
250 m_metafiles
[i
].WriteAttributes(clause
, i
);
255 void wxDrawnShape::ReadAttributes(wxExpr
*clause
)
257 wxRectangleShape::ReadAttributes(clause
);
259 int iVal
= (int) m_saveToFile
;
260 clause
->AssignAttributeValue("save_metafile", &iVal
);
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(char *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 xoffset
, double 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
.Nth(m_gdiIndex
);
440 wxPen
*pen
= (wxPen
*)node
->Data();
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
.Nth(m_gdiIndex
);
473 wxBrush
*brush
= (wxBrush
*)node
->Data();
480 case DRAWOP_SET_FONT
:
482 wxNode
*node
= m_image
->m_gdiObjects
.Nth(m_gdiIndex
);
485 wxFont
*font
= (wxFont
*)node
->Data();
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
);
522 wxExpr
*wxOpSetGDI::WriteExpr(wxPseudoMetaFile
*image
)
524 wxExpr
*expr
= new wxExpr(PrologList
);
525 expr
->Append(new wxExpr((long)m_op
));
529 case DRAWOP_SET_BRUSH
:
530 case DRAWOP_SET_FONT
:
532 expr
->Append(new wxExpr((long)m_gdiIndex
));
535 case DRAWOP_SET_TEXT_COLOUR
:
536 case DRAWOP_SET_BK_COLOUR
:
538 expr
->Append(new wxExpr((long)m_r
));
539 expr
->Append(new wxExpr((long)m_g
));
540 expr
->Append(new wxExpr((long)m_b
));
543 case DRAWOP_SET_BK_MODE
:
545 expr
->Append(new wxExpr((long)m_mode
));
554 void wxOpSetGDI::ReadExpr(wxPseudoMetaFile
*image
, wxExpr
*expr
)
559 case DRAWOP_SET_BRUSH
:
560 case DRAWOP_SET_FONT
:
562 m_gdiIndex
= (int)expr
->Nth(1)->IntegerValue();
565 case DRAWOP_SET_TEXT_COLOUR
:
566 case DRAWOP_SET_BK_COLOUR
:
568 m_r
= (unsigned char)expr
->Nth(1)->IntegerValue();
569 m_g
= (unsigned char)expr
->Nth(2)->IntegerValue();
570 m_b
= (unsigned char)expr
->Nth(3)->IntegerValue();
573 case DRAWOP_SET_BK_MODE
:
575 m_mode
= (int)expr
->Nth(1)->IntegerValue();
584 * Set/destroy clipping
588 wxOpSetClipping::wxOpSetClipping(int theOp
, double theX1
, double theY1
,
589 double theX2
, double theY2
):wxDrawOp(theOp
)
597 wxDrawOp
*wxOpSetClipping::Copy(wxPseudoMetaFile
*newImage
)
599 wxOpSetClipping
*newOp
= new wxOpSetClipping(m_op
, m_x1
, m_y1
, m_x2
, m_y2
);
603 void wxOpSetClipping::Do(wxDC
& dc
, double xoffset
, double yoffset
)
607 case DRAWOP_SET_CLIPPING_RECT
:
609 dc
.SetClippingRegion(m_x1
+ xoffset
, m_y1
+ yoffset
, m_x2
+ xoffset
, m_y2
+ yoffset
);
612 case DRAWOP_DESTROY_CLIPPING_RECT
:
614 dc
.DestroyClippingRegion();
622 void wxOpSetClipping::Scale(double xScale
, double yScale
)
630 void wxOpSetClipping::Translate(double x
, double y
)
636 wxExpr
*wxOpSetClipping::WriteExpr(wxPseudoMetaFile
*image
)
638 wxExpr
*expr
= new wxExpr(PrologList
);
639 expr
->Append(new wxExpr((long)m_op
));
642 case DRAWOP_SET_CLIPPING_RECT
:
644 expr
->Append(new wxExpr(m_x1
));
645 expr
->Append(new wxExpr(m_y1
));
646 expr
->Append(new wxExpr(m_x2
));
647 expr
->Append(new wxExpr(m_y2
));
656 void wxOpSetClipping::ReadExpr(wxPseudoMetaFile
*image
, wxExpr
*expr
)
660 case DRAWOP_SET_CLIPPING_RECT
:
662 m_x1
= expr
->Nth(1)->RealValue();
663 m_y1
= expr
->Nth(2)->RealValue();
664 m_x2
= expr
->Nth(3)->RealValue();
665 m_y2
= expr
->Nth(4)->RealValue();
674 * Draw line, rectangle, rounded rectangle, ellipse, point, arc, text
678 wxOpDraw::wxOpDraw(int theOp
, double theX1
, double theY1
, double theX2
, double theY2
,
679 double theRadius
, char *s
):wxDrawOp(theOp
)
687 m_radius
= theRadius
;
688 if (s
) m_textString
= copystring(s
);
689 else m_textString
= NULL
;
692 wxOpDraw::~wxOpDraw()
694 if (m_textString
) delete[] m_textString
;
697 wxDrawOp
*wxOpDraw::Copy(wxPseudoMetaFile
*newImage
)
699 wxOpDraw
*newOp
= new wxOpDraw(m_op
, m_x1
, m_y1
, m_x2
, m_y2
, m_radius
, m_textString
);
705 void wxOpDraw::Do(wxDC
& dc
, double xoffset
, double yoffset
)
709 case DRAWOP_DRAW_LINE
:
711 dc
.DrawLine(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
), WXROUND(m_x2
+xoffset
), WXROUND(m_y2
+yoffset
));
714 case DRAWOP_DRAW_RECT
:
716 dc
.DrawRectangle(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
), WXROUND(m_x2
), WXROUND(m_y2
));
719 case DRAWOP_DRAW_ROUNDED_RECT
:
721 dc
.DrawRoundedRectangle(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
), WXROUND(m_x2
), WXROUND(m_y2
), m_radius
);
724 case DRAWOP_DRAW_ELLIPSE
:
726 dc
.DrawEllipse(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
), WXROUND(m_x2
), WXROUND(m_y2
));
729 case DRAWOP_DRAW_ARC
:
731 dc
.DrawArc(WXROUND(m_x2
+xoffset
), WXROUND(m_y2
+yoffset
),
732 WXROUND(m_x3
+xoffset
), WXROUND(m_y3
+yoffset
),
733 WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
));
736 case DRAWOP_DRAW_ELLIPTIC_ARC
:
738 const double pi
= 3.1415926535897932384626433832795 ;
740 // Convert back to degrees
742 WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
),
743 WXROUND(m_x2
), WXROUND(m_y2
),
744 WXROUND(m_x3
*(360.0/(2.0*pi
))), WXROUND(m_y3
*(360.0/(2.0*pi
))));
747 case DRAWOP_DRAW_POINT
:
749 dc
.DrawPoint(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
));
752 case DRAWOP_DRAW_TEXT
:
754 dc
.DrawText(m_textString
, WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
));
762 void wxOpDraw::Scale(double scaleX
, double scaleY
)
769 if (m_op
!= DRAWOP_DRAW_ELLIPTIC_ARC
)
778 void wxOpDraw::Translate(double x
, double y
)
785 case DRAWOP_DRAW_LINE
:
791 case DRAWOP_DRAW_ARC
:
799 case DRAWOP_DRAW_ELLIPTIC_ARC
:
808 void wxOpDraw::Rotate(double x
, double y
, double theta
, double sinTheta
, double cosTheta
)
810 double newX1
= m_x1
*cosTheta
- m_y1
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
811 double newY1
= m_x1
*sinTheta
+ m_y1
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
815 case DRAWOP_DRAW_LINE
:
817 double newX2
= m_x2
*cosTheta
- m_y2
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
818 double newY2
= m_x2
*sinTheta
+ m_y2
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
826 case DRAWOP_DRAW_RECT
:
827 case DRAWOP_DRAW_ROUNDED_RECT
:
828 case DRAWOP_DRAW_ELLIPTIC_ARC
:
830 // Assume only 0, 90, 180, 270 degree rotations.
831 // oldX1, oldY1 represents the top left corner. Find the
832 // bottom right, and rotate that. Then the width/height is the difference
833 // between x/y values.
834 double oldBottomRightX
= m_x1
+ m_x2
;
835 double oldBottomRightY
= m_y1
+ m_y2
;
836 double newBottomRightX
= oldBottomRightX
*cosTheta
- oldBottomRightY
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
837 double newBottomRightY
= oldBottomRightX
*sinTheta
+ oldBottomRightY
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
839 // Now find the new top-left, bottom-right coordinates.
840 double minX
= wxMin(newX1
, newBottomRightX
);
841 double minY
= wxMin(newY1
, newBottomRightY
);
842 double maxX
= wxMax(newX1
, newBottomRightX
);
843 double maxY
= wxMax(newY1
, newBottomRightY
);
847 m_x2
= maxX
- minX
; // width
848 m_y2
= maxY
- minY
; // height
850 if (m_op
== DRAWOP_DRAW_ELLIPTIC_ARC
)
852 // Add rotation to angles
859 case DRAWOP_DRAW_ARC
:
861 double newX2
= m_x2
*cosTheta
- m_y2
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
862 double newY2
= m_x2
*sinTheta
+ m_y2
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
863 double newX3
= m_x3
*cosTheta
- m_y3
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
864 double newY3
= m_x3
*sinTheta
+ m_y3
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
880 wxExpr
*wxOpDraw::WriteExpr(wxPseudoMetaFile
*image
)
882 wxExpr
*expr
= new wxExpr(PrologList
);
883 expr
->Append(new wxExpr((long)m_op
));
886 case DRAWOP_DRAW_LINE
:
887 case DRAWOP_DRAW_RECT
:
888 case DRAWOP_DRAW_ELLIPSE
:
890 expr
->Append(new wxExpr(m_x1
));
891 expr
->Append(new wxExpr(m_y1
));
892 expr
->Append(new wxExpr(m_x2
));
893 expr
->Append(new wxExpr(m_y2
));
896 case DRAWOP_DRAW_ROUNDED_RECT
:
898 expr
->Append(new wxExpr(m_x1
));
899 expr
->Append(new wxExpr(m_y1
));
900 expr
->Append(new wxExpr(m_x2
));
901 expr
->Append(new wxExpr(m_y2
));
902 expr
->Append(new wxExpr(m_radius
));
905 case DRAWOP_DRAW_POINT
:
907 expr
->Append(new wxExpr(m_x1
));
908 expr
->Append(new wxExpr(m_y1
));
911 case DRAWOP_DRAW_TEXT
:
913 expr
->Append(new wxExpr(m_x1
));
914 expr
->Append(new wxExpr(m_y1
));
915 expr
->Append(new wxExpr(PrologString
, m_textString
));
918 case DRAWOP_DRAW_ARC
:
919 case DRAWOP_DRAW_ELLIPTIC_ARC
:
921 expr
->Append(new wxExpr(m_x1
));
922 expr
->Append(new wxExpr(m_y1
));
923 expr
->Append(new wxExpr(m_x2
));
924 expr
->Append(new wxExpr(m_y2
));
925 expr
->Append(new wxExpr(m_x3
));
926 expr
->Append(new wxExpr(m_y3
));
937 void wxOpDraw::ReadExpr(wxPseudoMetaFile
*image
, wxExpr
*expr
)
941 case DRAWOP_DRAW_LINE
:
942 case DRAWOP_DRAW_RECT
:
943 case DRAWOP_DRAW_ELLIPSE
:
945 m_x1
= expr
->Nth(1)->RealValue();
946 m_y1
= expr
->Nth(2)->RealValue();
947 m_x2
= expr
->Nth(3)->RealValue();
948 m_y2
= expr
->Nth(4)->RealValue();
951 case DRAWOP_DRAW_ROUNDED_RECT
:
953 m_x1
= expr
->Nth(1)->RealValue();
954 m_y1
= expr
->Nth(2)->RealValue();
955 m_x2
= expr
->Nth(3)->RealValue();
956 m_y2
= expr
->Nth(4)->RealValue();
957 m_radius
= expr
->Nth(5)->RealValue();
960 case DRAWOP_DRAW_POINT
:
962 m_x1
= expr
->Nth(1)->RealValue();
963 m_y1
= expr
->Nth(2)->RealValue();
966 case DRAWOP_DRAW_TEXT
:
968 m_x1
= expr
->Nth(1)->RealValue();
969 m_y1
= expr
->Nth(2)->RealValue();
970 wxString
str(expr
->Nth(3)->StringValue());
971 m_textString
= copystring((const char*) str
);
974 case DRAWOP_DRAW_ARC
:
975 case DRAWOP_DRAW_ELLIPTIC_ARC
:
977 m_x1
= expr
->Nth(1)->RealValue();
978 m_y1
= expr
->Nth(2)->RealValue();
979 m_x2
= expr
->Nth(3)->RealValue();
980 m_y2
= expr
->Nth(4)->RealValue();
981 m_x3
= expr
->Nth(5)->RealValue();
982 m_y3
= expr
->Nth(6)->RealValue();
993 * Draw polygon, polyline, spline
997 wxOpPolyDraw::wxOpPolyDraw(int theOp
, int n
, wxRealPoint
*thePoints
):wxDrawOp(theOp
)
1000 m_points
= thePoints
;
1003 wxOpPolyDraw::~wxOpPolyDraw()
1008 wxDrawOp
*wxOpPolyDraw::Copy(wxPseudoMetaFile
*newImage
)
1010 wxRealPoint
*newPoints
= new wxRealPoint
[m_noPoints
];
1011 for (int i
= 0; i
< m_noPoints
; i
++)
1013 newPoints
[i
].x
= m_points
[i
].x
;
1014 newPoints
[i
].y
= m_points
[i
].y
;
1016 wxOpPolyDraw
*newOp
= new wxOpPolyDraw(m_op
, m_noPoints
, newPoints
);
1020 void wxOpPolyDraw::Do(wxDC
& dc
, double xoffset
, double yoffset
)
1024 case DRAWOP_DRAW_POLYLINE
:
1026 wxPoint
*actualPoints
= new wxPoint
[m_noPoints
];
1028 for (i
= 0; i
< m_noPoints
; i
++)
1030 actualPoints
[i
].x
= WXROUND(m_points
[i
].x
);
1031 actualPoints
[i
].y
= WXROUND(m_points
[i
].y
);
1034 dc
.DrawLines(m_noPoints
, actualPoints
, WXROUND(xoffset
), WXROUND(yoffset
));
1036 delete[] actualPoints
;
1039 case DRAWOP_DRAW_POLYGON
:
1041 wxPoint
*actualPoints
= new wxPoint
[m_noPoints
];
1043 for (i
= 0; i
< m_noPoints
; i
++)
1045 actualPoints
[i
].x
= WXROUND(m_points
[i
].x
);
1046 actualPoints
[i
].y
= WXROUND(m_points
[i
].y
);
1049 dc
.DrawPolygon(m_noPoints
, actualPoints
, WXROUND(xoffset
), WXROUND(yoffset
));
1051 delete[] actualPoints
;
1054 case DRAWOP_DRAW_SPLINE
:
1056 wxPoint
*actualPoints
= new wxPoint
[m_noPoints
];
1058 for (i
= 0; i
< m_noPoints
; i
++)
1060 actualPoints
[i
].x
= WXROUND(m_points
[i
].x
);
1061 actualPoints
[i
].y
= WXROUND(m_points
[i
].y
);
1064 dc
.DrawSpline(m_noPoints
, actualPoints
); // no offsets in DrawSpline // , xoffset, yoffset);
1066 delete[] actualPoints
;
1075 void wxOpPolyDraw::Scale(double scaleX
, double scaleY
)
1077 for (int i
= 0; i
< m_noPoints
; i
++)
1079 m_points
[i
].x
*= scaleX
;
1080 m_points
[i
].y
*= scaleY
;
1084 void wxOpPolyDraw::Translate(double x
, double y
)
1086 for (int i
= 0; i
< m_noPoints
; i
++)
1093 void wxOpPolyDraw::Rotate(double x
, double y
, double theta
, double sinTheta
, double cosTheta
)
1095 for (int i
= 0; i
< m_noPoints
; i
++)
1097 double x1
= m_points
[i
].x
;
1098 double y1
= m_points
[i
].y
;
1099 m_points
[i
].x
= x1
*cosTheta
- y1
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
1100 m_points
[i
].y
= x1
*sinTheta
+ y1
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
1104 wxExpr
*wxOpPolyDraw::WriteExpr(wxPseudoMetaFile
*image
)
1106 wxExpr
*expr
= new wxExpr(PrologList
);
1107 expr
->Append(new wxExpr((long)m_op
));
1108 expr
->Append(new wxExpr((long)m_noPoints
));
1117 * Store each coordinate pair in a hex string to save space.
1118 * E.g. "1B9080CD". 4 hex digits per coordinate pair.
1122 for (int i
= 0; i
< m_noPoints
; i
++)
1124 long signedX
= (long)(m_points
[i
].x
*100.0);
1125 long signedY
= (long)(m_points
[i
].y
*100.0);
1127 // Scale to 0 -> 64K
1128 long unSignedX
= (long)(signedX
+ 32767.0);
1129 long unSignedY
= (long)(signedY
+ 32767.0);
1131 // IntToHex((unsigned int)signedX, buf2);
1132 // IntToHex((unsigned int)signedY, buf3);
1133 IntToHex((int)unSignedX
, buf2
);
1134 IntToHex((int)unSignedY
, buf3
);
1136 // Don't overrun the buffer
1139 strcat(oglBuffer
, buf2
);
1140 strcat(oglBuffer
, buf3
);
1143 expr
->Append(new wxExpr(PrologString
, oglBuffer
));
1147 void wxOpPolyDraw::ReadExpr(wxPseudoMetaFile
*image
, wxExpr
*expr
)
1149 m_noPoints
= (int)expr
->Nth(1)->IntegerValue();
1154 m_points
= new wxRealPoint
[m_noPoints
];
1157 wxString hexString
= expr
->Nth(2)->StringValue();
1158 while (i
< m_noPoints
)
1160 buf1
[0] = hexString
[bufPtr
];
1161 buf1
[1] = hexString
[bufPtr
+ 1];
1162 buf1
[2] = hexString
[bufPtr
+ 2];
1163 buf1
[3] = hexString
[bufPtr
+ 3];
1166 buf2
[0] = hexString
[bufPtr
+ 4];
1167 buf2
[1] = hexString
[bufPtr
+ 5];
1168 buf2
[2] = hexString
[bufPtr
+ 6];
1169 buf2
[3] = hexString
[bufPtr
+ 7];
1174 // int signedX = (signed int)HexToInt(buf1);
1175 // int signedY = (signed int)HexToInt(buf2);
1176 long unSignedX
= HexToInt(buf1
);
1177 long unSignedY
= HexToInt(buf2
);
1178 // Scale -32K -> +32K
1179 long signedX
= unSignedX
- 32767;
1180 long signedY
= unSignedY
- 32767;
1182 int testX
= (signed int)unSignedX
;
1183 int testY
= (signed int)unSignedY
;
1186 m_points
[i
].x
= (double)(signedX
/ 100.0);
1187 m_points
[i
].y
= (double)(signedY
/ 100.0);
1193 // Draw an outline using the current operation.
1194 bool wxOpPolyDraw::OnDrawOutline(wxDC
& dc
, double x
, double y
, double w
, double h
, double oldW
, double oldH
)
1196 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
1198 // Multiply all points by proportion of new size to old size
1199 double x_proportion
= (double)(fabs(w
/oldW
));
1200 double y_proportion
= (double)(fabs(h
/oldH
));
1203 wxPoint
*intPoints
= new wxPoint
[n
];
1205 for (i
= 0; i
< n
; i
++)
1207 intPoints
[i
].x
= WXROUND (x_proportion
* m_points
[i
].x
);
1208 intPoints
[i
].y
= WXROUND (y_proportion
* m_points
[i
].y
);
1210 dc
.DrawPolygon(n
, intPoints
, x
, y
);
1215 // Assume (x1, y1) is centre of box (most generally, line end at box)
1216 bool wxOpPolyDraw::GetPerimeterPoint(double x1
, double y1
,
1217 double x2
, double y2
,
1218 double *x3
, double *y3
,
1219 double xOffset
, double yOffset
,
1220 bool attachmentMode
)
1224 // First check for situation where the line is vertical,
1225 // and we would want to connect to a point on that vertical --
1226 // oglFindEndForPolyline can't cope with this (the arrow
1227 // gets drawn to the wrong place).
1228 if ((!attachmentMode
) && (x1
== x2
))
1230 // Look for the point we'd be connecting to. This is
1233 for (i
= 0; i
< n
; i
++)
1235 wxRealPoint
*point
= & (m_points
[i
]);
1236 if (point
->x
== 0.0)
1238 if ((y2
> y1
) && (point
->y
> 0.0))
1240 *x3
= point
->x
+ xOffset
;
1241 *y3
= point
->y
+ yOffset
;
1244 else if ((y2
< y1
) && (point
->y
< 0.0))
1246 *x3
= point
->x
+ xOffset
;
1247 *y3
= point
->y
+ yOffset
;
1254 double *xpoints
= new double[n
];
1255 double *ypoints
= new double[n
];
1258 for (i
= 0; i
< n
; i
++)
1260 wxRealPoint
*point
= & (m_points
[i
]);
1261 xpoints
[i
] = point
->x
+ xOffset
;
1262 ypoints
[i
] = point
->y
+ yOffset
;
1265 oglFindEndForPolyline(n
, xpoints
, ypoints
,
1266 x1
, y1
, x2
, y2
, x3
, y3
);
1280 static char hexArray
[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B',
1281 'C', 'D', 'E', 'F' };
1283 // Convert unsigned 16-bit integer to 4-character hex string
1284 static void IntToHex(unsigned int dec
, char *buf
)
1286 int digit1
= (int)(dec
/4096);
1287 int digit2
= (int)((dec
- (digit1
*4096))/256);
1288 int digit3
= (int)((dec
- (digit1
*4096) - (digit2
*256))/16);
1289 int digit4
= dec
- (digit1
*4096 + digit2
*256 + digit3
*16);
1291 buf
[0] = hexArray
[digit1
];
1292 buf
[1] = hexArray
[digit2
];
1293 buf
[2] = hexArray
[digit3
];
1294 buf
[3] = hexArray
[digit4
];
1298 // One hex digit to decimal number
1299 static int HexToInt1(char hex
)
1341 // 4-digit hex string to unsigned integer
1342 static unsigned long HexToInt(char *buf
)
1344 long d1
= (long)(HexToInt1(buf
[0])*4096.0) ;
1345 long d2
= (long)(HexToInt1(buf
[1])*256.0) ;
1346 long d3
= (long)(HexToInt1(buf
[2])*16.0) ;
1347 long d4
= (long)(HexToInt1(buf
[3])) ;
1348 unsigned long n
= (long)(d1
+ d2
+ d3
+ d4
) ;
1353 * wxPseudo meta-file
1357 IMPLEMENT_DYNAMIC_CLASS(wxPseudoMetaFile
, wxObject
)
1359 wxPseudoMetaFile::wxPseudoMetaFile()
1361 m_currentRotation
= 0;
1362 m_rotateable
= TRUE
;
1365 m_outlinePen
= NULL
;
1370 wxPseudoMetaFile::wxPseudoMetaFile(wxPseudoMetaFile
& mf
)
1375 wxPseudoMetaFile::~wxPseudoMetaFile()
1380 void wxPseudoMetaFile::Clear()
1382 wxNode
*node
= m_ops
.First();
1385 wxDrawOp
*op
= (wxDrawOp
*)node
->Data();
1387 node
= node
->Next();
1390 m_gdiObjects
.Clear();
1391 m_outlineColours
.Clear();
1392 m_fillColours
.Clear();
1396 void wxPseudoMetaFile::Draw(wxDC
& dc
, double xoffset
, double yoffset
)
1398 wxNode
*node
= m_ops
.First();
1401 wxDrawOp
*op
= (wxDrawOp
*)node
->Data();
1402 op
->Do(dc
, xoffset
, yoffset
);
1403 node
= node
->Next();
1407 void wxPseudoMetaFile::Scale(double sx
, double sy
)
1409 wxNode
*node
= m_ops
.First();
1412 wxDrawOp
*op
= (wxDrawOp
*)node
->Data();
1414 node
= node
->Next();
1420 void wxPseudoMetaFile::Translate(double x
, double y
)
1422 wxNode
*node
= m_ops
.First();
1425 wxDrawOp
*op
= (wxDrawOp
*)node
->Data();
1426 op
->Translate(x
, y
);
1427 node
= node
->Next();
1431 void wxPseudoMetaFile::Rotate(double x
, double y
, double theta
)
1433 double theta1
= theta
-m_currentRotation
;
1434 if (theta1
== 0.0) return;
1435 double cosTheta
= (double)cos(theta1
);
1436 double sinTheta
= (double)sin(theta1
);
1438 wxNode
*node
= m_ops
.First();
1441 wxDrawOp
*op
= (wxDrawOp
*)node
->Data();
1442 op
->Rotate(x
, y
, theta
, sinTheta
, cosTheta
);
1443 node
= node
->Next();
1445 m_currentRotation
= theta
;
1449 void wxPseudoMetaFile::WriteAttributes(wxExpr
*clause
, int whichAngle
)
1452 widthStr
.Printf("meta_width%d", whichAngle
);
1455 heightStr
.Printf("meta_height%d", whichAngle
);
1457 wxString outlineStr
;
1458 outlineStr
.Printf("outline_op%d", whichAngle
);
1460 wxString rotateableStr
;
1461 rotateableStr
.Printf("meta_rotateable%d", whichAngle
);
1463 // Write width and height
1464 clause
->AddAttributeValue(widthStr
, m_width
);
1465 clause
->AddAttributeValue(heightStr
, m_height
);
1466 clause
->AddAttributeValue(rotateableStr
, (long)m_rotateable
);
1467 clause
->AddAttributeValue(outlineStr
, (long)m_outlineOp
);
1469 // Write GDI objects
1472 wxNode
*node
= m_gdiObjects
.First();
1475 sprintf(buf
, "gdi%d_%d", whichAngle
, i
);
1476 wxObject
*obj
= (wxObject
*)node
->Data();
1477 wxExpr
*expr
= NULL
;
1480 if (obj
->IsKindOf(CLASSINFO(wxPen
)))
1482 wxPen
*thePen
= (wxPen
*)obj
;
1483 expr
= new wxExpr(PrologList
);
1484 expr
->Append(new wxExpr((long)gyTYPE_PEN
));
1485 expr
->Append(new wxExpr((long)thePen
->GetWidth()));
1486 expr
->Append(new wxExpr((long)thePen
->GetStyle()));
1487 expr
->Append(new wxExpr((long)thePen
->GetColour().Red()));
1488 expr
->Append(new wxExpr((long)thePen
->GetColour().Green()));
1489 expr
->Append(new wxExpr((long)thePen
->GetColour().Blue()));
1491 else if (obj
->IsKindOf(CLASSINFO(wxBrush
)))
1493 wxBrush
*theBrush
= (wxBrush
*)obj
;
1494 expr
= new wxExpr(PrologList
);
1495 expr
->Append(new wxExpr((long)gyTYPE_BRUSH
));
1496 expr
->Append(new wxExpr((long)theBrush
->GetStyle()));
1497 expr
->Append(new wxExpr((long)theBrush
->GetColour().Red()));
1498 expr
->Append(new wxExpr((long)theBrush
->GetColour().Green()));
1499 expr
->Append(new wxExpr((long)theBrush
->GetColour().Blue()));
1501 else if (obj
->IsKindOf(CLASSINFO(wxFont
)))
1503 wxFont
*theFont
= (wxFont
*)obj
;
1504 expr
= new wxExpr(PrologList
);
1505 expr
->Append(new wxExpr((long)gyTYPE_FONT
));
1506 expr
->Append(new wxExpr((long)theFont
->GetPointSize()));
1507 expr
->Append(new wxExpr((long)theFont
->GetFamily()));
1508 expr
->Append(new wxExpr((long)theFont
->GetStyle()));
1509 expr
->Append(new wxExpr((long)theFont
->GetWeight()));
1510 expr
->Append(new wxExpr((long)theFont
->GetUnderlined()));
1515 // If no recognised GDI object, append a place holder anyway.
1516 expr
= new wxExpr(PrologList
);
1517 expr
->Append(new wxExpr((long)0));
1522 clause
->AddAttributeValue(buf
, expr
);
1525 node
= node
->Next();
1528 // Write drawing operations
1530 node
= m_ops
.First();
1533 sprintf(buf
, "op%d_%d", whichAngle
, i
);
1534 wxDrawOp
*op
= (wxDrawOp
*)node
->Data();
1535 wxExpr
*expr
= op
->WriteExpr(this);
1538 clause
->AddAttributeValue(buf
, expr
);
1541 node
= node
->Next();
1544 // Write outline and fill GDI op lists (if any)
1545 if (m_outlineColours
.Number() > 0)
1547 wxExpr
*outlineExpr
= new wxExpr(PrologList
);
1548 node
= m_outlineColours
.First();
1551 outlineExpr
->Append(new wxExpr((long)node
->Data()));
1552 node
= node
->Next();
1554 wxString outlineObjectsStr
;
1555 outlineObjectsStr
.Printf("outline_objects%d", whichAngle
);
1557 clause
->AddAttributeValue(outlineObjectsStr
, outlineExpr
);
1559 if (m_fillColours
.Number() > 0)
1561 wxExpr
*fillExpr
= new wxExpr(PrologList
);
1562 node
= m_fillColours
.First();
1565 fillExpr
->Append(new wxExpr((long)node
->Data()));
1566 node
= node
->Next();
1568 wxString fillObjectsStr
;
1569 fillObjectsStr
.Printf("fill_objects%d", whichAngle
);
1571 clause
->AddAttributeValue(fillObjectsStr
, fillExpr
);
1576 void wxPseudoMetaFile::ReadAttributes(wxExpr
*clause
, int whichAngle
)
1579 widthStr
.Printf("meta_width%d", whichAngle
);
1582 heightStr
.Printf("meta_height%d", whichAngle
);
1584 wxString outlineStr
;
1585 outlineStr
.Printf("outline_op%d", whichAngle
);
1587 wxString rotateableStr
;
1588 rotateableStr
.Printf("meta_rotateable%d", whichAngle
);
1590 clause
->GetAttributeValue(widthStr
, m_width
);
1591 clause
->GetAttributeValue(heightStr
, m_height
);
1592 clause
->GetAttributeValue(outlineStr
, m_outlineOp
);
1594 int iVal
= (int) m_rotateable
;
1595 clause
->GetAttributeValue(rotateableStr
, iVal
);
1596 m_rotateable
= (iVal
!= 0);
1601 bool keepGoing
= TRUE
;
1604 sprintf(buf
, "gdi%d_%d", whichAngle
, i
);
1605 wxExpr
*expr
= NULL
;
1606 clause
->GetAttributeValue(buf
, &expr
);
1613 wxExpr
*idExpr
= expr
->Nth(0);
1614 switch (idExpr
->IntegerValue())
1618 int penWidth
= (int)expr
->Nth(1)->IntegerValue();
1619 int penStyle
= (int)expr
->Nth(2)->IntegerValue();
1620 int penRed
= (int)expr
->Nth(3)->IntegerValue();
1621 int penGreen
= (int)expr
->Nth(4)->IntegerValue();
1622 int penBlue
= (int)expr
->Nth(5)->IntegerValue();
1623 wxColour
col(penRed
, penGreen
, penBlue
);
1624 wxPen
*p
= wxThePenList
->FindOrCreatePen(col
, penWidth
, penStyle
);
1627 m_gdiObjects
.Append(p
);
1632 int brushStyle
= (int)expr
->Nth(1)->IntegerValue();
1633 int brushRed
= (int)expr
->Nth(2)->IntegerValue();
1634 int brushGreen
= (int)expr
->Nth(3)->IntegerValue();
1635 int brushBlue
= (int)expr
->Nth(4)->IntegerValue();
1636 wxColour
col(brushRed
, brushGreen
, brushBlue
);
1637 wxBrush
*b
= wxTheBrushList
->FindOrCreateBrush(col
, brushStyle
);
1640 m_gdiObjects
.Append(b
);
1645 int fontPointSize
= (int)expr
->Nth(1)->IntegerValue();
1646 int fontFamily
= (int)expr
->Nth(2)->IntegerValue();
1647 int fontStyle
= (int)expr
->Nth(3)->IntegerValue();
1648 int fontWeight
= (int)expr
->Nth(4)->IntegerValue();
1649 int fontUnderlined
= (int)expr
->Nth(5)->IntegerValue();
1650 m_gdiObjects
.Append(wxTheFontList
->FindOrCreateFont(fontPointSize
,
1651 fontFamily
, fontStyle
, fontWeight
, (fontUnderlined
!= 0)));
1657 m_gdiObjects
.Append(NULL
);
1665 // Now read in the operations
1670 sprintf(buf
, "op%d_%d", whichAngle
, i
);
1671 wxExpr
*expr
= NULL
;
1672 clause
->GetAttributeValue(buf
, &expr
);
1679 wxExpr
*idExpr
= expr
->Nth(0);
1680 int opId
= (int)idExpr
->IntegerValue();
1683 case DRAWOP_SET_PEN
:
1684 case DRAWOP_SET_BRUSH
:
1685 case DRAWOP_SET_FONT
:
1686 case DRAWOP_SET_TEXT_COLOUR
:
1687 case DRAWOP_SET_BK_COLOUR
:
1688 case DRAWOP_SET_BK_MODE
:
1690 wxOpSetGDI
*theOp
= new wxOpSetGDI(opId
, this, 0);
1691 theOp
->ReadExpr(this, expr
);
1692 m_ops
.Append(theOp
);
1696 case DRAWOP_SET_CLIPPING_RECT
:
1697 case DRAWOP_DESTROY_CLIPPING_RECT
:
1699 wxOpSetClipping
*theOp
= new wxOpSetClipping(opId
, 0.0, 0.0, 0.0, 0.0);
1700 theOp
->ReadExpr(this, expr
);
1701 m_ops
.Append(theOp
);
1705 case DRAWOP_DRAW_LINE
:
1706 case DRAWOP_DRAW_RECT
:
1707 case DRAWOP_DRAW_ROUNDED_RECT
:
1708 case DRAWOP_DRAW_ELLIPSE
:
1709 case DRAWOP_DRAW_POINT
:
1710 case DRAWOP_DRAW_ARC
:
1711 case DRAWOP_DRAW_TEXT
:
1713 wxOpDraw
*theOp
= new wxOpDraw(opId
, 0.0, 0.0, 0.0, 0.0);
1714 theOp
->ReadExpr(this, expr
);
1715 m_ops
.Append(theOp
);
1718 case DRAWOP_DRAW_SPLINE
:
1719 case DRAWOP_DRAW_POLYLINE
:
1720 case DRAWOP_DRAW_POLYGON
:
1722 wxOpPolyDraw
*theOp
= new wxOpPolyDraw(opId
, 0, NULL
);
1723 theOp
->ReadExpr(this, expr
);
1724 m_ops
.Append(theOp
);
1734 wxString outlineObjectsStr
;
1735 outlineObjectsStr
.Printf("outline_objects%d", whichAngle
);
1737 // Now read in the list of outline and fill operations, if any
1738 wxExpr
*expr1
= clause
->AttributeValue(outlineObjectsStr
);
1741 wxExpr
*eachExpr
= expr1
->GetFirst();
1744 m_outlineColours
.Append((wxObject
*)eachExpr
->IntegerValue());
1745 eachExpr
= eachExpr
->GetNext();
1749 wxString fillObjectsStr
;
1750 fillObjectsStr
.Printf("fill_objects%d", whichAngle
);
1752 expr1
= clause
->AttributeValue(fillObjectsStr
);
1755 wxExpr
*eachExpr
= expr1
->GetFirst();
1758 m_fillColours
.Append((wxObject
*)eachExpr
->IntegerValue());
1759 eachExpr
= eachExpr
->GetNext();
1765 // Does the copying for this object
1766 void wxPseudoMetaFile::Copy(wxPseudoMetaFile
& copy
)
1770 copy
.m_currentRotation
= m_currentRotation
;
1771 copy
.m_width
= m_width
;
1772 copy
.m_height
= m_height
;
1773 copy
.m_rotateable
= m_rotateable
;
1774 copy
.m_fillBrush
= m_fillBrush
;
1775 copy
.m_outlinePen
= m_outlinePen
;
1776 copy
.m_outlineOp
= m_outlineOp
;
1778 // Copy the GDI objects
1779 wxNode
*node
= m_gdiObjects
.First();
1782 wxObject
*obj
= (wxObject
*)node
->Data();
1783 copy
.m_gdiObjects
.Append(obj
);
1784 node
= node
->Next();
1787 // Copy the operations
1788 node
= m_ops
.First();
1791 wxDrawOp
*op
= (wxDrawOp
*)node
->Data();
1792 copy
.m_ops
.Append(op
->Copy(©
));
1793 node
= node
->Next();
1796 // Copy the outline/fill operations
1797 node
= m_outlineColours
.First();
1800 copy
.m_outlineColours
.Append((wxObject
*)node
->Data());
1801 node
= node
->Next();
1803 node
= m_fillColours
.First();
1806 copy
.m_fillColours
.Append((wxObject
*)node
->Data());
1807 node
= node
->Next();
1812 * Pass size of existing image; scale height to
1813 * fit width and return new width and height.
1817 bool wxPseudoMetaFile::LoadFromMetaFile(char *filename
, double *rwidth
, double *rheight
)
1819 if (!FileExists(filename
))
1822 wxXMetaFile
*metaFile
= new wxXMetaFile
;
1824 if (!metaFile
->ReadFile(filename
))
1833 // Convert from metafile records to wxDrawnShape records
1834 wxNode
*node
= metaFile
->metaRecords
.First();
1837 wxMetaRecord
*record
= (wxMetaRecord
*)node
->Data();
1838 switch (record
->metaFunction
)
1840 case META_SETBKCOLOR
:
1842 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_BK_COLOUR
, this, 0);
1843 op
->m_r
= (unsigned char)record
->param1
;
1844 op
->m_g
= (unsigned char)record
->param2
;
1845 op
->m_b
= (unsigned char)record
->param3
;
1849 case META_SETBKMODE
:
1851 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_BK_MODE
, this, 0, (int)record
->param1
);
1855 case META_SETMAPMODE
:
1859 // case META_SETROP2:
1860 // case META_SETRELABS:
1861 // case META_SETPOLYFILLMODE:
1862 // case META_SETSTRETCHBLTMODE:
1863 // case META_SETTEXTCHAREXTRA:
1864 case META_SETTEXTCOLOR
:
1866 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_TEXT_COLOUR
, this, 0);
1867 op
->m_r
= (unsigned char)record
->param1
;
1868 op
->m_g
= (unsigned char)record
->param2
;
1869 op
->m_b
= (unsigned char)record
->param3
;
1873 // case META_SETTEXTJUSTIFICATION:
1874 // case META_SETWINDOWORG:
1875 // case META_SETWINDOWEXT:
1876 // case META_SETVIEWPORTORG:
1877 // case META_SETVIEWPORTEXT:
1878 // case META_OFFSETWINDOWORG:
1879 // case META_SCALEWINDOWEXT:
1880 // case META_OFFSETVIEWPORTORG:
1881 // case META_SCALEVIEWPORTEXT:
1884 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_LINE
, (double)lastX
, (double)lastY
,
1885 (double)record
->param1
, (double)record
->param2
);
1891 lastX
= (double)record
->param1
;
1892 lastY
= (double)record
->param2
;
1895 case META_EXCLUDECLIPRECT
:
1898 wxMetaRecord *rec = new wxMetaRecord(META_EXCLUDECLIPRECT);
1899 rec->param4 = getshort(handle); // m_y2
1900 rec->param3 = getshort(handle); // x2
1901 rec->param2 = getshort(handle); // y1
1902 rec->param1 = getshort(handle); // x1
1906 case META_INTERSECTCLIPRECT
:
1909 rec->param4 = getshort(handle); // m_y2
1910 rec->param3 = getshort(handle); // x2
1911 rec->param2 = getshort(handle); // y1
1912 rec->param1 = getshort(handle); // x1
1916 // case META_ARC: // DO!!!
1919 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_ELLIPSE
,
1920 (double)record
->param1
, (double)record
->param2
,
1921 (double)(record
->param3
- record
->param1
),
1922 (double)(record
->param4
- record
->param2
));
1926 // case META_FLOODFILL:
1927 // case META_PIE: // DO!!!
1928 case META_RECTANGLE
:
1930 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_RECT
,
1931 (double)record
->param1
, (double)record
->param2
,
1932 (double)(record
->param3
- record
->param1
),
1933 (double)(record
->param4
- record
->param2
));
1937 case META_ROUNDRECT
:
1939 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_ROUNDED_RECT
,
1940 (double)record
->param1
, (double)record
->param2
,
1941 (double)(record
->param3
- record
->param1
),
1942 (double)(record
->param4
- record
->param2
), (double)record
->param5
);
1946 // case META_PATBLT:
1947 // case META_SAVEDC:
1950 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_POINT
,
1951 (double)record
->param1
, (double)record
->param2
,
1954 // SHOULD SET THE COLOUR - SET PEN?
1955 // rec->param3 = getint(handle); // COLORREF
1959 // case META_OFFSETCLIPRGN:
1962 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_TEXT
,
1963 (double)record
->param1
, (double)record
->param2
,
1964 0.0, 0.0, 0.0, record
->stringParam
);
1968 // case META_BITBLT:
1969 // case META_STRETCHBLT:
1972 int n
= (int)record
->param1
;
1973 wxRealPoint
*newPoints
= new wxRealPoint
[n
];
1974 for (int i
= 0; i
< n
; i
++)
1976 newPoints
[i
].x
= record
->points
[i
].x
;
1977 newPoints
[i
].y
= record
->points
[i
].y
;
1980 wxOpPolyDraw
*op
= new wxOpPolyDraw(DRAWOP_DRAW_POLYGON
, n
, newPoints
);
1986 int n
= (int)record
->param1
;
1987 wxRealPoint
*newPoints
= new wxRealPoint
[n
];
1988 for (int i
= 0; i
< n
; i
++)
1990 newPoints
[i
].x
= record
->points
[i
].x
;
1991 newPoints
[i
].y
= record
->points
[i
].y
;
1994 wxOpPolyDraw
*op
= new wxOpPolyDraw(DRAWOP_DRAW_POLYLINE
, n
, newPoints
);
1998 // case META_ESCAPE:
1999 // case META_RESTOREDC:
2000 // case META_FILLREGION:
2001 // case META_FRAMEREGION:
2002 // case META_INVERTREGION:
2003 // case META_PAINTREGION:
2004 // case META_SELECTCLIPREGION: // DO THIS!
2005 case META_SELECTOBJECT
:
2007 // The pen, brush etc. has already been created when the metafile
2008 // was read in, so we don't create it - we set it.
2009 wxNode
*recNode
= metaFile
->gdiObjects
.Nth((int)record
->param2
);
2012 wxMetaRecord
*gdiRec
= (wxMetaRecord
*)recNode
->Data();
2013 if (gdiRec
&& (gdiRec
->param1
!= 0))
2015 wxObject
*obj
= (wxObject
*)gdiRec
->param1
;
2016 if (obj
->IsKindOf(CLASSINFO(wxPen
)))
2018 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_PEN
, this, (int)record
->param2
);
2021 else if (obj
->IsKindOf(CLASSINFO(wxBrush
)))
2023 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_BRUSH
, this, (int)record
->param2
);
2026 else if (obj
->IsKindOf(CLASSINFO(wxFont
)))
2028 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_FONT
, this, (int)record
->param2
);
2035 // case META_SETTEXTALIGN:
2036 // case META_DRAWTEXT:
2038 // case META_SETMAPPERFLAGS:
2039 // case META_EXTTEXTOUT:
2040 // case META_SETDIBTODEV:
2041 // case META_SELECTPALETTE:
2042 // case META_REALIZEPALETTE:
2043 // case META_ANIMATEPALETTE:
2044 // case META_SETPALENTRIES:
2045 // case META_POLYPOLYGON:
2046 // case META_RESIZEPALETTE:
2047 // case META_DIBBITBLT:
2048 // case META_DIBSTRETCHBLT:
2049 case META_DIBCREATEPATTERNBRUSH
:
2052 m_gdiObjects
.Append(NULL
);
2055 // case META_STRETCHDIB:
2056 // case META_EXTFLOODFILL:
2057 // case META_RESETDC:
2058 // case META_STARTDOC:
2059 // case META_STARTPAGE:
2060 // case META_ENDPAGE:
2061 // case META_ABORTDOC:
2062 // case META_ENDDOC:
2063 // case META_DELETEOBJECT: // DO!!
2064 case META_CREATEPALETTE
:
2067 m_gdiObjects
.Append(NULL
);
2070 case META_CREATEBRUSH
:
2073 m_gdiObjects
.Append(NULL
);
2076 case META_CREATEPATTERNBRUSH
:
2079 m_gdiObjects
.Append(NULL
);
2082 case META_CREATEPENINDIRECT
:
2084 // The pen is created when the metafile is read in.
2085 // We keep track of all the GDI objects needed for this
2086 // image so when reading the wxDrawnShape from file,
2087 // we can read in all the GDI objects, then refer
2088 // to them by an index starting from zero thereafter.
2089 m_gdiObjects
.Append((wxObject
*)record
->param1
);
2092 case META_CREATEFONTINDIRECT
:
2094 m_gdiObjects
.Append((wxObject
*)record
->param1
);
2097 case META_CREATEBRUSHINDIRECT
:
2099 // Don't have to do anything here: the pen is created
2100 // when the metafile is read in.
2101 m_gdiObjects
.Append((wxObject
*)record
->param1
);
2104 case META_CREATEBITMAPINDIRECT
:
2107 m_gdiObjects
.Append(NULL
);
2110 case META_CREATEBITMAP
:
2113 m_gdiObjects
.Append(NULL
);
2116 case META_CREATEREGION
:
2119 m_gdiObjects
.Append(NULL
);
2127 node
= node
->Next();
2129 double actualWidth
= (double)fabs(metaFile
->right
- metaFile
->left
);
2130 double actualHeight
= (double)fabs(metaFile
->bottom
- metaFile
->top
);
2132 double initialScaleX
= 1.0;
2133 double initialScaleY
= 1.0;
2135 double xoffset
, yoffset
;
2137 // Translate so origin is at centre of rectangle
2138 if (metaFile
->bottom
> metaFile
->top
)
2139 yoffset
= - (double)((metaFile
->bottom
- metaFile
->top
)/2.0);
2141 yoffset
= - (double)((metaFile
->top
- metaFile
->bottom
)/2.0);
2143 if (metaFile
->right
> metaFile
->left
)
2144 xoffset
= - (double)((metaFile
->right
- metaFile
->left
)/2.0);
2146 xoffset
= - (double)((metaFile
->left
- metaFile
->right
)/2.0);
2148 Translate(xoffset
, yoffset
);
2150 // Scale to a reasonable size (take the width of this wxDrawnShape
2152 if (actualWidth
!= 0.0)
2154 initialScaleX
= (double)((*rwidth
) / actualWidth
);
2155 initialScaleY
= initialScaleX
;
2156 (*rheight
) = initialScaleY
*actualHeight
;
2158 Scale(initialScaleX
, initialScaleY
);
2160 m_width
= (actualWidth
*initialScaleX
);
2161 m_height
= *rheight
;
2167 // Scale to fit size
2168 void wxPseudoMetaFile::ScaleTo(double w
, double h
)
2170 double scaleX
= (double)(w
/m_width
);
2171 double scaleY
= (double)(h
/m_height
);
2174 Scale(scaleX
, scaleY
);
2177 void wxPseudoMetaFile::GetBounds(double *boundMinX
, double *boundMinY
, double *boundMaxX
, double *boundMaxY
)
2179 double maxX
= (double) -99999.9;
2180 double maxY
= (double) -99999.9;
2181 double minX
= (double) 99999.9;
2182 double minY
= (double) 99999.9;
2184 wxNode
*node
= m_ops
.First();
2187 wxDrawOp
*op
= (wxDrawOp
*)node
->Data();
2188 switch (op
->GetOp())
2190 case DRAWOP_DRAW_LINE
:
2191 case DRAWOP_DRAW_RECT
:
2192 case DRAWOP_DRAW_ROUNDED_RECT
:
2193 case DRAWOP_DRAW_ELLIPSE
:
2194 case DRAWOP_DRAW_POINT
:
2195 case DRAWOP_DRAW_TEXT
:
2197 wxOpDraw
*opDraw
= (wxOpDraw
*)op
;
2198 if (opDraw
->m_x1
< minX
) minX
= opDraw
->m_x1
;
2199 if (opDraw
->m_x1
> maxX
) maxX
= opDraw
->m_x1
;
2200 if (opDraw
->m_y1
< minY
) minY
= opDraw
->m_y1
;
2201 if (opDraw
->m_y1
> maxY
) maxY
= opDraw
->m_y1
;
2202 if (op
->GetOp() == DRAWOP_DRAW_LINE
)
2204 if (opDraw
->m_x2
< minX
) minX
= opDraw
->m_x2
;
2205 if (opDraw
->m_x2
> maxX
) maxX
= opDraw
->m_x2
;
2206 if (opDraw
->m_y2
< minY
) minY
= opDraw
->m_y2
;
2207 if (opDraw
->m_y2
> maxY
) maxY
= opDraw
->m_y2
;
2209 else if (op
->GetOp() == DRAWOP_DRAW_RECT
||
2210 op
->GetOp() == DRAWOP_DRAW_ROUNDED_RECT
||
2211 op
->GetOp() == DRAWOP_DRAW_ELLIPSE
)
2213 if ((opDraw
->m_x1
+ opDraw
->m_x2
) < minX
) minX
= (opDraw
->m_x1
+ opDraw
->m_x2
);
2214 if ((opDraw
->m_x1
+ opDraw
->m_x2
) > maxX
) maxX
= (opDraw
->m_x1
+ opDraw
->m_x2
);
2215 if ((opDraw
->m_y1
+ opDraw
->m_y2
) < minY
) minY
= (opDraw
->m_y1
+ opDraw
->m_y2
);
2216 if ((opDraw
->m_y1
+ opDraw
->m_y2
) > maxY
) maxY
= (opDraw
->m_y1
+ opDraw
->m_y2
);
2220 case DRAWOP_DRAW_ARC
:
2222 // TODO: don't yet know how to calculate the bounding box
2223 // for an arc. So pretend it's a line; to get a correct
2224 // bounding box, draw a blank rectangle first, of the correct
2226 wxOpDraw
*opDraw
= (wxOpDraw
*)op
;
2227 if (opDraw
->m_x1
< minX
) minX
= opDraw
->m_x1
;
2228 if (opDraw
->m_x1
> maxX
) maxX
= opDraw
->m_x1
;
2229 if (opDraw
->m_y1
< minY
) minY
= opDraw
->m_y1
;
2230 if (opDraw
->m_y1
> maxY
) maxY
= opDraw
->m_y1
;
2231 if (opDraw
->m_x2
< minX
) minX
= opDraw
->m_x2
;
2232 if (opDraw
->m_x2
> maxX
) maxX
= opDraw
->m_x2
;
2233 if (opDraw
->m_y2
< minY
) minY
= opDraw
->m_y2
;
2234 if (opDraw
->m_y2
> maxY
) maxY
= opDraw
->m_y2
;
2237 case DRAWOP_DRAW_POLYLINE
:
2238 case DRAWOP_DRAW_POLYGON
:
2239 case DRAWOP_DRAW_SPLINE
:
2241 wxOpPolyDraw
*poly
= (wxOpPolyDraw
*)op
;
2242 for (int i
= 0; i
< poly
->m_noPoints
; i
++)
2244 if (poly
->m_points
[i
].x
< minX
) minX
= poly
->m_points
[i
].x
;
2245 if (poly
->m_points
[i
].x
> maxX
) maxX
= poly
->m_points
[i
].x
;
2246 if (poly
->m_points
[i
].y
< minY
) minY
= poly
->m_points
[i
].y
;
2247 if (poly
->m_points
[i
].y
> maxY
) maxY
= poly
->m_points
[i
].y
;
2254 node
= node
->Next();
2262 *w = (double)fabs(maxX - minX);
2263 *h = (double)fabs(maxY - minY);
2267 // Calculate size from current operations
2268 void wxPseudoMetaFile::CalculateSize(wxDrawnShape
* shape
)
2270 double boundMinX
, boundMinY
, boundMaxX
, boundMaxY
;
2272 GetBounds(& boundMinX
, & boundMinY
, & boundMaxX
, & boundMaxY
);
2274 SetSize(boundMaxX
- boundMinX
, boundMaxY
- boundMinY
);
2278 shape
->SetWidth(m_width
);
2279 shape
->SetHeight(m_height
);
2283 // Set of functions for drawing into a pseudo metafile.
2284 // They use integers, but doubles are used internally for accuracy
2287 void wxPseudoMetaFile::DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
)
2289 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_LINE
,
2290 (double) pt1
.x
, (double) pt1
.y
, (double) pt2
.x
, (double) pt2
.y
);
2292 m_ops
.Append(theOp
);
2295 void wxPseudoMetaFile::DrawRectangle(const wxRect
& rect
)
2297 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_RECT
,
2298 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2300 m_ops
.Append(theOp
);
2303 void wxPseudoMetaFile::DrawRoundedRectangle(const wxRect
& rect
, double radius
)
2305 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_ROUNDED_RECT
,
2306 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2308 theOp
->m_radius
= radius
;
2310 m_ops
.Append(theOp
);
2313 void wxPseudoMetaFile::DrawEllipse(const wxRect
& rect
)
2315 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_ELLIPSE
,
2316 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2318 m_ops
.Append(theOp
);
2321 void wxPseudoMetaFile::DrawArc(const wxPoint
& centrePt
, const wxPoint
& startPt
, const wxPoint
& endPt
)
2323 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_ARC
,
2324 (double) centrePt
.x
, (double) centrePt
.y
, (double) startPt
.x
, (double) startPt
.y
);
2326 theOp
->m_x3
= (double) endPt
.x
;
2327 theOp
->m_y3
= (double) endPt
.y
;
2329 m_ops
.Append(theOp
);
2332 void wxPseudoMetaFile::DrawEllipticArc(const wxRect
& rect
, double startAngle
, double endAngle
)
2334 const double pi
= 3.1415926535897932384626433832795 ;
2336 double startAngleRadians
= startAngle
* (pi
*2.0/360.0);
2337 double endAngleRadians
= endAngle
* (pi
*2.0/360.0);
2339 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_ELLIPTIC_ARC
,
2340 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2342 theOp
->m_x3
= startAngleRadians
;
2343 theOp
->m_y3
= endAngleRadians
;
2345 m_ops
.Append(theOp
);
2348 void wxPseudoMetaFile::DrawPoint(const wxPoint
& pt
)
2350 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_POINT
,
2351 (double) pt
.x
, (double) pt
.y
, 0.0, 0.0);
2353 m_ops
.Append(theOp
);
2356 void wxPseudoMetaFile::DrawText(const wxString
& text
, const wxPoint
& pt
)
2358 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_TEXT
,
2359 (double) pt
.x
, (double) pt
.y
, 0.0, 0.0);
2361 theOp
->m_textString
= copystring(text
);
2363 m_ops
.Append(theOp
);
2366 void wxPseudoMetaFile::DrawLines(int n
, wxPoint pts
[])
2368 wxRealPoint
* realPoints
= new wxRealPoint
[n
];
2370 for (i
= 0; i
< n
; i
++)
2372 realPoints
[i
].x
= pts
[i
].x
;
2373 realPoints
[i
].y
= pts
[i
].y
;
2375 wxOpPolyDraw
* theOp
= new wxOpPolyDraw(DRAWOP_DRAW_POLYLINE
, n
, realPoints
);
2376 m_ops
.Append(theOp
);
2379 void wxPseudoMetaFile::DrawPolygon(int n
, wxPoint pts
[], int flags
)
2381 wxRealPoint
* realPoints
= new wxRealPoint
[n
];
2383 for (i
= 0; i
< n
; i
++)
2385 realPoints
[i
].x
= pts
[i
].x
;
2386 realPoints
[i
].y
= pts
[i
].y
;
2388 wxOpPolyDraw
* theOp
= new wxOpPolyDraw(DRAWOP_DRAW_POLYGON
, n
, realPoints
);
2389 m_ops
.Append(theOp
);
2391 if (flags
& oglMETAFLAGS_OUTLINE
)
2392 m_outlineOp
= (m_ops
.Number() - 1);
2395 void wxPseudoMetaFile::DrawSpline(int n
, wxPoint pts
[])
2397 wxRealPoint
* realPoints
= new wxRealPoint
[n
];
2399 for (i
= 0; i
< n
; i
++)
2401 realPoints
[i
].x
= pts
[i
].x
;
2402 realPoints
[i
].y
= pts
[i
].y
;
2404 wxOpPolyDraw
* theOp
= new wxOpPolyDraw(DRAWOP_DRAW_SPLINE
, n
, realPoints
);
2405 m_ops
.Append(theOp
);
2408 void wxPseudoMetaFile::SetClippingRect(const wxRect
& rect
)
2410 wxOpSetClipping
* theOp
= new wxOpSetClipping(DRAWOP_SET_CLIPPING_RECT
,
2411 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2414 void wxPseudoMetaFile::DestroyClippingRect()
2416 wxOpSetClipping
* theOp
= new wxOpSetClipping(DRAWOP_DESTROY_CLIPPING_RECT
,
2417 0.0, 0.0, 0.0, 0.0);
2419 m_ops
.Append(theOp
);
2422 void wxPseudoMetaFile::SetPen(wxPen
* pen
, bool isOutline
)
2424 m_gdiObjects
.Append(pen
);
2425 int n
= m_gdiObjects
.Number();
2427 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_PEN
, this, n
- 1);
2429 m_ops
.Append(theOp
);
2433 m_outlineColours
.Append((wxObject
*) (n
- 1));
2437 void wxPseudoMetaFile::SetBrush(wxBrush
* brush
, bool isFill
)
2439 m_gdiObjects
.Append(brush
);
2440 int n
= m_gdiObjects
.Number();
2442 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_BRUSH
, this, n
- 1);
2444 m_ops
.Append(theOp
);
2448 m_fillColours
.Append((wxObject
*) (n
- 1));
2452 void wxPseudoMetaFile::SetFont(wxFont
* font
)
2454 m_gdiObjects
.Append(font
);
2455 int n
= m_gdiObjects
.Number();
2457 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_FONT
, this, n
- 1);
2459 m_ops
.Append(theOp
);
2462 void wxPseudoMetaFile::SetTextColour(const wxColour
& colour
)
2464 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_TEXT_COLOUR
, this, 0);
2465 theOp
->m_r
= colour
.Red();
2466 theOp
->m_g
= colour
.Green();
2467 theOp
->m_b
= colour
.Blue();
2469 m_ops
.Append(theOp
);
2472 void wxPseudoMetaFile::SetBackgroundColour(const wxColour
& colour
)
2474 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_BK_COLOUR
, this, 0);
2475 theOp
->m_r
= colour
.Red();
2476 theOp
->m_g
= colour
.Green();
2477 theOp
->m_b
= colour
.Blue();
2479 m_ops
.Append(theOp
);
2482 void wxPseudoMetaFile::SetBackgroundMode(int mode
)
2484 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_BK_MODE
, this, 0, mode
);
2486 m_ops
.Append(theOp
);