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
, char *buf
);
38 static unsigned long HexToInt(char *buf
);
39 extern char *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 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("current_angle", (long)m_currentAngle
);
242 clause
->AddAttributeValue("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("save_metafile", iVal
);
260 clause
->GetAttributeValue("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 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
.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
*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
*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
*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
*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
*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
*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
*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
*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
*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
;
1081 void wxOpPolyDraw::Scale(double scaleX
, double scaleY
)
1083 for (int i
= 0; i
< m_noPoints
; i
++)
1085 m_points
[i
].x
*= scaleX
;
1086 m_points
[i
].y
*= scaleY
;
1090 void wxOpPolyDraw::Translate(double x
, double y
)
1092 for (int i
= 0; i
< m_noPoints
; i
++)
1099 void wxOpPolyDraw::Rotate(double x
, double y
, double theta
, double sinTheta
, double cosTheta
)
1101 for (int i
= 0; i
< m_noPoints
; i
++)
1103 double x1
= m_points
[i
].x
;
1104 double y1
= m_points
[i
].y
;
1105 m_points
[i
].x
= x1
*cosTheta
- y1
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
1106 m_points
[i
].y
= x1
*sinTheta
+ y1
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
1111 wxExpr
*wxOpPolyDraw::WriteExpr(wxPseudoMetaFile
*image
)
1113 wxExpr
*expr
= new wxExpr(wxExprList
);
1114 expr
->Append(new wxExpr((long)m_op
));
1115 expr
->Append(new wxExpr((long)m_noPoints
));
1124 * Store each coordinate pair in a hex string to save space.
1125 * E.g. "1B9080CD". 4 hex digits per coordinate pair.
1129 for (int i
= 0; i
< m_noPoints
; i
++)
1131 long signedX
= (long)(m_points
[i
].x
*100.0);
1132 long signedY
= (long)(m_points
[i
].y
*100.0);
1134 // Scale to 0 -> 64K
1135 long unSignedX
= (long)(signedX
+ 32767.0);
1136 long unSignedY
= (long)(signedY
+ 32767.0);
1138 // IntToHex((unsigned int)signedX, buf2);
1139 // IntToHex((unsigned int)signedY, buf3);
1140 IntToHex((int)unSignedX
, buf2
);
1141 IntToHex((int)unSignedY
, buf3
);
1143 // Don't overrun the buffer
1146 strcat(oglBuffer
, buf2
);
1147 strcat(oglBuffer
, buf3
);
1150 expr
->Append(new wxExpr(wxExprString
, oglBuffer
));
1154 void wxOpPolyDraw::ReadExpr(wxPseudoMetaFile
*image
, wxExpr
*expr
)
1156 m_noPoints
= (int)expr
->Nth(1)->IntegerValue();
1161 m_points
= new wxRealPoint
[m_noPoints
];
1164 wxString hexString
= expr
->Nth(2)->StringValue();
1165 while (i
< m_noPoints
)
1167 buf1
[0] = hexString
[(size_t)bufPtr
];
1168 buf1
[1] = hexString
[(size_t)(bufPtr
+ 1)];
1169 buf1
[2] = hexString
[(size_t)(bufPtr
+ 2)];
1170 buf1
[3] = hexString
[(size_t)(bufPtr
+ 3)];
1173 buf2
[0] = hexString
[(size_t)(bufPtr
+ 4)];
1174 buf2
[1] = hexString
[(size_t)(bufPtr
+ 5)];
1175 buf2
[2] = hexString
[(size_t)(bufPtr
+ 6)];
1176 buf2
[3] = hexString
[(size_t)(bufPtr
+ 7)];
1181 // int signedX = (signed int)HexToInt(buf1);
1182 // int signedY = (signed int)HexToInt(buf2);
1183 long unSignedX
= HexToInt(buf1
);
1184 long unSignedY
= HexToInt(buf2
);
1185 // Scale -32K -> +32K
1186 long signedX
= unSignedX
- 32767;
1187 long signedY
= unSignedY
- 32767;
1189 int testX
= (signed int)unSignedX
;
1190 int testY
= (signed int)unSignedY
;
1193 m_points
[i
].x
= (double)(signedX
/ 100.0);
1194 m_points
[i
].y
= (double)(signedY
/ 100.0);
1201 // Draw an outline using the current operation.
1202 bool wxOpPolyDraw::OnDrawOutline(wxDC
& dc
, double x
, double y
, double w
, double h
, double oldW
, double oldH
)
1204 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1206 // Multiply all points by proportion of new size to old size
1207 double x_proportion
= (double)(fabs(w
/oldW
));
1208 double y_proportion
= (double)(fabs(h
/oldH
));
1211 wxPoint
*intPoints
= new wxPoint
[n
];
1213 for (i
= 0; i
< n
; i
++)
1215 intPoints
[i
].x
= WXROUND (x_proportion
* m_points
[i
].x
);
1216 intPoints
[i
].y
= WXROUND (y_proportion
* m_points
[i
].y
);
1218 dc
.DrawPolygon(n
, intPoints
, (long) x
, (long) y
);
1223 // Assume (x1, y1) is centre of box (most generally, line end at box)
1224 bool wxOpPolyDraw::GetPerimeterPoint(double x1
, double y1
,
1225 double x2
, double y2
,
1226 double *x3
, double *y3
,
1227 double xOffset
, double yOffset
,
1232 // First check for situation where the line is vertical,
1233 // and we would want to connect to a point on that vertical --
1234 // oglFindEndForPolyline can't cope with this (the arrow
1235 // gets drawn to the wrong place).
1236 if ((attachmentMode
== ATTACHMENT_MODE_NONE
) && (x1
== x2
))
1238 // Look for the point we'd be connecting to. This is
1241 for (i
= 0; i
< n
; i
++)
1243 wxRealPoint
*point
= & (m_points
[i
]);
1244 if (point
->x
== 0.0)
1246 if ((y2
> y1
) && (point
->y
> 0.0))
1248 *x3
= point
->x
+ xOffset
;
1249 *y3
= point
->y
+ yOffset
;
1252 else if ((y2
< y1
) && (point
->y
< 0.0))
1254 *x3
= point
->x
+ xOffset
;
1255 *y3
= point
->y
+ yOffset
;
1262 double *xpoints
= new double[n
];
1263 double *ypoints
= new double[n
];
1266 for (i
= 0; i
< n
; i
++)
1268 wxRealPoint
*point
= & (m_points
[i
]);
1269 xpoints
[i
] = point
->x
+ xOffset
;
1270 ypoints
[i
] = point
->y
+ yOffset
;
1273 oglFindEndForPolyline(n
, xpoints
, ypoints
,
1274 x1
, y1
, x2
, y2
, x3
, y3
);
1288 static char hexArray
[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B',
1289 'C', 'D', 'E', 'F' };
1291 // Convert unsigned 16-bit integer to 4-character hex string
1292 static void IntToHex(unsigned int dec
, char *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(char hex
)
1349 // 4-digit hex string to unsigned integer
1350 static unsigned long HexToInt(char *buf
)
1352 long d1
= (long)(HexToInt1(buf
[0])*4096.0) ;
1353 long d2
= (long)(HexToInt1(buf
[1])*256.0) ;
1354 long d3
= (long)(HexToInt1(buf
[2])*16.0) ;
1355 long d4
= (long)(HexToInt1(buf
[3])) ;
1356 unsigned long n
= (long)(d1
+ d2
+ d3
+ d4
) ;
1361 * wxPseudo meta-file
1365 IMPLEMENT_DYNAMIC_CLASS(wxPseudoMetaFile
, wxObject
)
1367 wxPseudoMetaFile::wxPseudoMetaFile()
1369 m_currentRotation
= 0;
1370 m_rotateable
= TRUE
;
1373 m_outlinePen
= NULL
;
1378 wxPseudoMetaFile::wxPseudoMetaFile(wxPseudoMetaFile
& mf
)
1383 wxPseudoMetaFile::~wxPseudoMetaFile()
1388 void wxPseudoMetaFile::Clear()
1390 wxNode
*node
= m_ops
.GetFirst();
1393 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1395 node
= node
->GetNext();
1398 m_gdiObjects
.Clear();
1399 m_outlineColours
.Clear();
1400 m_fillColours
.Clear();
1404 void wxPseudoMetaFile::Draw(wxDC
& dc
, double xoffset
, double yoffset
)
1406 wxNode
*node
= m_ops
.GetFirst();
1409 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1410 op
->Do(dc
, xoffset
, yoffset
);
1411 node
= node
->GetNext();
1415 void wxPseudoMetaFile::Scale(double sx
, double sy
)
1417 wxNode
*node
= m_ops
.GetFirst();
1420 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1422 node
= node
->GetNext();
1428 void wxPseudoMetaFile::Translate(double x
, double y
)
1430 wxNode
*node
= m_ops
.GetFirst();
1433 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1434 op
->Translate(x
, y
);
1435 node
= node
->GetNext();
1439 void wxPseudoMetaFile::Rotate(double x
, double y
, double theta
)
1441 double theta1
= theta
-m_currentRotation
;
1442 if (theta1
== 0.0) return;
1443 double cosTheta
= (double)cos(theta1
);
1444 double sinTheta
= (double)sin(theta1
);
1446 wxNode
*node
= m_ops
.GetFirst();
1449 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1450 op
->Rotate(x
, y
, theta
, sinTheta
, cosTheta
);
1451 node
= node
->GetNext();
1453 m_currentRotation
= theta
;
1457 void wxPseudoMetaFile::WriteAttributes(wxExpr
*clause
, int whichAngle
)
1460 widthStr
.Printf(wxT("meta_width%d"), whichAngle
);
1463 heightStr
.Printf(wxT("meta_height%d"), whichAngle
);
1465 wxString outlineStr
;
1466 outlineStr
.Printf(wxT("outline_op%d"), whichAngle
);
1468 wxString rotateableStr
;
1469 rotateableStr
.Printf(wxT("meta_rotateable%d"), whichAngle
);
1471 // Write width and height
1472 clause
->AddAttributeValue(widthStr
, m_width
);
1473 clause
->AddAttributeValue(heightStr
, m_height
);
1474 clause
->AddAttributeValue(rotateableStr
, (long)m_rotateable
);
1475 clause
->AddAttributeValue(outlineStr
, (long)m_outlineOp
);
1477 // Write GDI objects
1480 wxNode
*node
= m_gdiObjects
.GetFirst();
1483 sprintf(buf
, "gdi%d_%d", whichAngle
, i
);
1484 wxObject
*obj
= (wxObject
*)node
->GetData();
1485 wxExpr
*expr
= NULL
;
1488 if (obj
->IsKindOf(CLASSINFO(wxPen
)))
1490 wxPen
*thePen
= (wxPen
*)obj
;
1491 expr
= new wxExpr(wxExprList
);
1492 expr
->Append(new wxExpr((long)gyTYPE_PEN
));
1493 expr
->Append(new wxExpr((long)thePen
->GetWidth()));
1494 expr
->Append(new wxExpr((long)thePen
->GetStyle()));
1495 expr
->Append(new wxExpr((long)thePen
->GetColour().Red()));
1496 expr
->Append(new wxExpr((long)thePen
->GetColour().Green()));
1497 expr
->Append(new wxExpr((long)thePen
->GetColour().Blue()));
1499 else if (obj
->IsKindOf(CLASSINFO(wxBrush
)))
1501 wxBrush
*theBrush
= (wxBrush
*)obj
;
1502 expr
= new wxExpr(wxExprList
);
1503 expr
->Append(new wxExpr((long)gyTYPE_BRUSH
));
1504 expr
->Append(new wxExpr((long)theBrush
->GetStyle()));
1505 expr
->Append(new wxExpr((long)theBrush
->GetColour().Red()));
1506 expr
->Append(new wxExpr((long)theBrush
->GetColour().Green()));
1507 expr
->Append(new wxExpr((long)theBrush
->GetColour().Blue()));
1509 else if (obj
->IsKindOf(CLASSINFO(wxFont
)))
1511 wxFont
*theFont
= (wxFont
*)obj
;
1512 expr
= new wxExpr(wxExprList
);
1513 expr
->Append(new wxExpr((long)gyTYPE_FONT
));
1514 expr
->Append(new wxExpr((long)theFont
->GetPointSize()));
1515 expr
->Append(new wxExpr((long)theFont
->GetFamily()));
1516 expr
->Append(new wxExpr((long)theFont
->GetStyle()));
1517 expr
->Append(new wxExpr((long)theFont
->GetWeight()));
1518 expr
->Append(new wxExpr((long)theFont
->GetUnderlined()));
1523 // If no recognised GDI object, append a place holder anyway.
1524 expr
= new wxExpr(wxExprList
);
1525 expr
->Append(new wxExpr((long)0));
1530 clause
->AddAttributeValue(buf
, expr
);
1533 node
= node
->GetNext();
1536 // Write drawing operations
1538 node
= m_ops
.GetFirst();
1541 sprintf(buf
, "op%d_%d", whichAngle
, i
);
1542 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1543 wxExpr
*expr
= op
->WriteExpr(this);
1546 clause
->AddAttributeValue(buf
, expr
);
1549 node
= node
->GetNext();
1552 // Write outline and fill GDI op lists (if any)
1553 if (m_outlineColours
.GetCount() > 0)
1555 wxExpr
*outlineExpr
= new wxExpr(wxExprList
);
1556 node
= m_outlineColours
.GetFirst();
1559 outlineExpr
->Append(new wxExpr((long)node
->GetData()));
1560 node
= node
->GetNext();
1562 wxString outlineObjectsStr
;
1563 outlineObjectsStr
.Printf(wxT("outline_objects%d"), whichAngle
);
1565 clause
->AddAttributeValue(outlineObjectsStr
, outlineExpr
);
1567 if (m_fillColours
.GetCount() > 0)
1569 wxExpr
*fillExpr
= new wxExpr(wxExprList
);
1570 node
= m_fillColours
.GetFirst();
1573 fillExpr
->Append(new wxExpr((long)node
->GetData()));
1574 node
= node
->GetNext();
1576 wxString fillObjectsStr
;
1577 fillObjectsStr
.Printf(wxT("fill_objects%d"), whichAngle
);
1579 clause
->AddAttributeValue(fillObjectsStr
, fillExpr
);
1584 void wxPseudoMetaFile::ReadAttributes(wxExpr
*clause
, int whichAngle
)
1587 widthStr
.Printf(wxT("meta_width%d"), whichAngle
);
1590 heightStr
.Printf(wxT("meta_height%d"), whichAngle
);
1592 wxString outlineStr
;
1593 outlineStr
.Printf(wxT("outline_op%d"), whichAngle
);
1595 wxString rotateableStr
;
1596 rotateableStr
.Printf(wxT("meta_rotateable%d"), whichAngle
);
1598 clause
->GetAttributeValue(widthStr
, m_width
);
1599 clause
->GetAttributeValue(heightStr
, m_height
);
1600 clause
->GetAttributeValue(outlineStr
, m_outlineOp
);
1602 int iVal
= (int) m_rotateable
;
1603 clause
->GetAttributeValue(rotateableStr
, iVal
);
1604 m_rotateable
= (iVal
!= 0);
1609 bool keepGoing
= TRUE
;
1612 sprintf(buf
, "gdi%d_%d", whichAngle
, i
);
1613 wxExpr
*expr
= NULL
;
1614 clause
->GetAttributeValue(buf
, &expr
);
1621 wxExpr
*idExpr
= expr
->Nth(0);
1622 switch (idExpr
->IntegerValue())
1626 int penWidth
= (int)expr
->Nth(1)->IntegerValue();
1627 int penStyle
= (int)expr
->Nth(2)->IntegerValue();
1628 int penRed
= (int)expr
->Nth(3)->IntegerValue();
1629 int penGreen
= (int)expr
->Nth(4)->IntegerValue();
1630 int penBlue
= (int)expr
->Nth(5)->IntegerValue();
1631 wxColour
col(penRed
, penGreen
, penBlue
);
1632 wxPen
*p
= wxThePenList
->FindOrCreatePen(col
, penWidth
, penStyle
);
1635 m_gdiObjects
.Append(p
);
1640 int brushStyle
= (int)expr
->Nth(1)->IntegerValue();
1641 int brushRed
= (int)expr
->Nth(2)->IntegerValue();
1642 int brushGreen
= (int)expr
->Nth(3)->IntegerValue();
1643 int brushBlue
= (int)expr
->Nth(4)->IntegerValue();
1644 wxColour
col(brushRed
, brushGreen
, brushBlue
);
1645 wxBrush
*b
= wxTheBrushList
->FindOrCreateBrush(col
, brushStyle
);
1648 m_gdiObjects
.Append(b
);
1653 int fontPointSize
= (int)expr
->Nth(1)->IntegerValue();
1654 int fontFamily
= (int)expr
->Nth(2)->IntegerValue();
1655 int fontStyle
= (int)expr
->Nth(3)->IntegerValue();
1656 int fontWeight
= (int)expr
->Nth(4)->IntegerValue();
1657 int fontUnderlined
= (int)expr
->Nth(5)->IntegerValue();
1658 m_gdiObjects
.Append(wxTheFontList
->FindOrCreateFont(fontPointSize
,
1659 fontFamily
, fontStyle
, fontWeight
, (fontUnderlined
!= 0)));
1665 m_gdiObjects
.Append(NULL
);
1673 // Now read in the operations
1678 sprintf(buf
, "op%d_%d", whichAngle
, i
);
1679 wxExpr
*expr
= NULL
;
1680 clause
->GetAttributeValue(buf
, &expr
);
1687 wxExpr
*idExpr
= expr
->Nth(0);
1688 int opId
= (int)idExpr
->IntegerValue();
1691 case DRAWOP_SET_PEN
:
1692 case DRAWOP_SET_BRUSH
:
1693 case DRAWOP_SET_FONT
:
1694 case DRAWOP_SET_TEXT_COLOUR
:
1695 case DRAWOP_SET_BK_COLOUR
:
1696 case DRAWOP_SET_BK_MODE
:
1698 wxOpSetGDI
*theOp
= new wxOpSetGDI(opId
, this, 0);
1699 theOp
->ReadExpr(this, expr
);
1700 m_ops
.Append(theOp
);
1704 case DRAWOP_SET_CLIPPING_RECT
:
1705 case DRAWOP_DESTROY_CLIPPING_RECT
:
1707 wxOpSetClipping
*theOp
= new wxOpSetClipping(opId
, 0.0, 0.0, 0.0, 0.0);
1708 theOp
->ReadExpr(this, expr
);
1709 m_ops
.Append(theOp
);
1713 case DRAWOP_DRAW_LINE
:
1714 case DRAWOP_DRAW_RECT
:
1715 case DRAWOP_DRAW_ROUNDED_RECT
:
1716 case DRAWOP_DRAW_ELLIPSE
:
1717 case DRAWOP_DRAW_POINT
:
1718 case DRAWOP_DRAW_ARC
:
1719 case DRAWOP_DRAW_TEXT
:
1721 wxOpDraw
*theOp
= new wxOpDraw(opId
, 0.0, 0.0, 0.0, 0.0);
1722 theOp
->ReadExpr(this, expr
);
1723 m_ops
.Append(theOp
);
1726 case DRAWOP_DRAW_SPLINE
:
1727 case DRAWOP_DRAW_POLYLINE
:
1728 case DRAWOP_DRAW_POLYGON
:
1730 wxOpPolyDraw
*theOp
= new wxOpPolyDraw(opId
, 0, NULL
);
1731 theOp
->ReadExpr(this, expr
);
1732 m_ops
.Append(theOp
);
1742 wxString outlineObjectsStr
;
1743 outlineObjectsStr
.Printf(wxT("outline_objects%d"), whichAngle
);
1745 // Now read in the list of outline and fill operations, if any
1746 wxExpr
*expr1
= clause
->AttributeValue(outlineObjectsStr
);
1749 wxExpr
*eachExpr
= expr1
->GetFirst();
1752 m_outlineColours
.Append((wxObject
*)eachExpr
->IntegerValue());
1753 eachExpr
= eachExpr
->GetNext();
1757 wxString fillObjectsStr
;
1758 fillObjectsStr
.Printf(wxT("fill_objects%d"), whichAngle
);
1760 expr1
= clause
->AttributeValue(fillObjectsStr
);
1763 wxExpr
*eachExpr
= expr1
->GetFirst();
1766 m_fillColours
.Append((wxObject
*)eachExpr
->IntegerValue());
1767 eachExpr
= eachExpr
->GetNext();
1773 // Does the copying for this object
1774 void wxPseudoMetaFile::Copy(wxPseudoMetaFile
& copy
)
1778 copy
.m_currentRotation
= m_currentRotation
;
1779 copy
.m_width
= m_width
;
1780 copy
.m_height
= m_height
;
1781 copy
.m_rotateable
= m_rotateable
;
1782 copy
.m_fillBrush
= m_fillBrush
;
1783 copy
.m_outlinePen
= m_outlinePen
;
1784 copy
.m_outlineOp
= m_outlineOp
;
1786 // Copy the GDI objects
1787 wxNode
*node
= m_gdiObjects
.GetFirst();
1790 wxObject
*obj
= (wxObject
*)node
->GetData();
1791 copy
.m_gdiObjects
.Append(obj
);
1792 node
= node
->GetNext();
1795 // Copy the operations
1796 node
= m_ops
.GetFirst();
1799 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1800 copy
.m_ops
.Append(op
->Copy(©
));
1801 node
= node
->GetNext();
1804 // Copy the outline/fill operations
1805 node
= m_outlineColours
.GetFirst();
1808 copy
.m_outlineColours
.Append((wxObject
*)node
->GetData());
1809 node
= node
->GetNext();
1811 node
= m_fillColours
.GetFirst();
1814 copy
.m_fillColours
.Append((wxObject
*)node
->GetData());
1815 node
= node
->GetNext();
1820 * Pass size of existing image; scale height to
1821 * fit width and return new width and height.
1825 bool wxPseudoMetaFile::LoadFromMetaFile(const wxString
& filename
, double *rwidth
, double *rheight
)
1827 if (!wxFileExists(filename
))
1830 wxXMetaFile
*metaFile
= new wxXMetaFile
;
1832 if (!metaFile
->ReadFile(filename
))
1841 // Convert from metafile records to wxDrawnShape records
1842 wxNode
*node
= metaFile
->metaRecords
.GetFirst();
1845 wxMetaRecord
*record
= (wxMetaRecord
*)node
->GetData();
1846 switch (record
->metaFunction
)
1848 case META_SETBKCOLOR
:
1850 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_BK_COLOUR
, this, 0);
1851 op
->m_r
= (unsigned char)record
->param1
;
1852 op
->m_g
= (unsigned char)record
->param2
;
1853 op
->m_b
= (unsigned char)record
->param3
;
1857 case META_SETBKMODE
:
1859 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_BK_MODE
, this, 0, (int)record
->param1
);
1863 case META_SETMAPMODE
:
1867 // case META_SETROP2:
1868 // case META_SETRELABS:
1869 // case META_SETPOLYFILLMODE:
1870 // case META_SETSTRETCHBLTMODE:
1871 // case META_SETTEXTCHAREXTRA:
1872 case META_SETTEXTCOLOR
:
1874 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_TEXT_COLOUR
, this, 0);
1875 op
->m_r
= (unsigned char)record
->param1
;
1876 op
->m_g
= (unsigned char)record
->param2
;
1877 op
->m_b
= (unsigned char)record
->param3
;
1881 // case META_SETTEXTJUSTIFICATION:
1882 // case META_SETWINDOWORG:
1883 // case META_SETWINDOWEXT:
1884 // case META_SETVIEWPORTORG:
1885 // case META_SETVIEWPORTEXT:
1886 // case META_OFFSETWINDOWORG:
1887 // case META_SCALEWINDOWEXT:
1888 // case META_OFFSETVIEWPORTORG:
1889 // case META_SCALEVIEWPORTEXT:
1892 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_LINE
, (double)lastX
, (double)lastY
,
1893 (double)record
->param1
, (double)record
->param2
);
1899 lastX
= (double)record
->param1
;
1900 lastY
= (double)record
->param2
;
1903 case META_EXCLUDECLIPRECT
:
1906 wxMetaRecord *rec = new wxMetaRecord(META_EXCLUDECLIPRECT);
1907 rec->param4 = getshort(handle); // m_y2
1908 rec->param3 = getshort(handle); // x2
1909 rec->param2 = getshort(handle); // y1
1910 rec->param1 = getshort(handle); // x1
1914 case META_INTERSECTCLIPRECT
:
1917 rec->param4 = getshort(handle); // m_y2
1918 rec->param3 = getshort(handle); // x2
1919 rec->param2 = getshort(handle); // y1
1920 rec->param1 = getshort(handle); // x1
1924 // case META_ARC: // DO!!!
1927 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_ELLIPSE
,
1928 (double)record
->param1
, (double)record
->param2
,
1929 (double)(record
->param3
- record
->param1
),
1930 (double)(record
->param4
- record
->param2
));
1934 // case META_FLOODFILL:
1935 // case META_PIE: // DO!!!
1936 case META_RECTANGLE
:
1938 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_RECT
,
1939 (double)record
->param1
, (double)record
->param2
,
1940 (double)(record
->param3
- record
->param1
),
1941 (double)(record
->param4
- record
->param2
));
1945 case META_ROUNDRECT
:
1947 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_ROUNDED_RECT
,
1948 (double)record
->param1
, (double)record
->param2
,
1949 (double)(record
->param3
- record
->param1
),
1950 (double)(record
->param4
- record
->param2
), (double)record
->param5
);
1954 // case META_PATBLT:
1955 // case META_SAVEDC:
1958 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_POINT
,
1959 (double)record
->param1
, (double)record
->param2
,
1962 // SHOULD SET THE COLOUR - SET PEN?
1963 // rec->param3 = getint(handle); // COLORREF
1967 // case META_OFFSETCLIPRGN:
1970 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_TEXT
,
1971 (double)record
->param1
, (double)record
->param2
,
1972 0.0, 0.0, 0.0, record
->stringParam
);
1976 // case META_BITBLT:
1977 // case META_STRETCHBLT:
1980 int n
= (int)record
->param1
;
1981 wxRealPoint
*newPoints
= new wxRealPoint
[n
];
1982 for (int i
= 0; i
< n
; i
++)
1984 newPoints
[i
].x
= record
->points
[i
].x
;
1985 newPoints
[i
].y
= record
->points
[i
].y
;
1988 wxOpPolyDraw
*op
= new wxOpPolyDraw(DRAWOP_DRAW_POLYGON
, n
, newPoints
);
1994 int n
= (int)record
->param1
;
1995 wxRealPoint
*newPoints
= new wxRealPoint
[n
];
1996 for (int i
= 0; i
< n
; i
++)
1998 newPoints
[i
].x
= record
->points
[i
].x
;
1999 newPoints
[i
].y
= record
->points
[i
].y
;
2002 wxOpPolyDraw
*op
= new wxOpPolyDraw(DRAWOP_DRAW_POLYLINE
, n
, newPoints
);
2006 // case META_ESCAPE:
2007 // case META_RESTOREDC:
2008 // case META_FILLREGION:
2009 // case META_FRAMEREGION:
2010 // case META_INVERTREGION:
2011 // case META_PAINTREGION:
2012 // case META_SELECTCLIPREGION: // DO THIS!
2013 case META_SELECTOBJECT
:
2015 // The pen, brush etc. has already been created when the metafile
2016 // was read in, so we don't create it - we set it.
2017 wxNode
*recNode
= metaFile
->gdiObjects
.Item((int)record
->param2
);
2020 wxMetaRecord
*gdiRec
= (wxMetaRecord
*)recNode
->GetData();
2021 if (gdiRec
&& (gdiRec
->param1
!= 0))
2023 wxObject
*obj
= (wxObject
*)gdiRec
->param1
;
2024 if (obj
->IsKindOf(CLASSINFO(wxPen
)))
2026 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_PEN
, this, (int)record
->param2
);
2029 else if (obj
->IsKindOf(CLASSINFO(wxBrush
)))
2031 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_BRUSH
, this, (int)record
->param2
);
2034 else if (obj
->IsKindOf(CLASSINFO(wxFont
)))
2036 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_FONT
, this, (int)record
->param2
);
2043 // case META_SETTEXTALIGN:
2044 // case META_DRAWTEXT:
2046 // case META_SETMAPPERFLAGS:
2047 // case META_EXTTEXTOUT:
2048 // case META_SETDIBTODEV:
2049 // case META_SELECTPALETTE:
2050 // case META_REALIZEPALETTE:
2051 // case META_ANIMATEPALETTE:
2052 // case META_SETPALENTRIES:
2053 // case META_POLYPOLYGON:
2054 // case META_RESIZEPALETTE:
2055 // case META_DIBBITBLT:
2056 // case META_DIBSTRETCHBLT:
2057 case META_DIBCREATEPATTERNBRUSH
:
2060 m_gdiObjects
.Append(NULL
);
2063 // case META_STRETCHDIB:
2064 // case META_EXTFLOODFILL:
2065 // case META_RESETDC:
2066 // case META_STARTDOC:
2067 // case META_STARTPAGE:
2068 // case META_ENDPAGE:
2069 // case META_ABORTDOC:
2070 // case META_ENDDOC:
2071 // case META_DELETEOBJECT: // DO!!
2072 case META_CREATEPALETTE
:
2075 m_gdiObjects
.Append(NULL
);
2078 case META_CREATEBRUSH
:
2081 m_gdiObjects
.Append(NULL
);
2084 case META_CREATEPATTERNBRUSH
:
2087 m_gdiObjects
.Append(NULL
);
2090 case META_CREATEPENINDIRECT
:
2092 // The pen is created when the metafile is read in.
2093 // We keep track of all the GDI objects needed for this
2094 // image so when reading the wxDrawnShape from file,
2095 // we can read in all the GDI objects, then refer
2096 // to them by an index starting from zero thereafter.
2097 m_gdiObjects
.Append((wxObject
*)record
->param1
);
2100 case META_CREATEFONTINDIRECT
:
2102 m_gdiObjects
.Append((wxObject
*)record
->param1
);
2105 case META_CREATEBRUSHINDIRECT
:
2107 // Don't have to do anything here: the pen is created
2108 // when the metafile is read in.
2109 m_gdiObjects
.Append((wxObject
*)record
->param1
);
2112 case META_CREATEBITMAPINDIRECT
:
2115 m_gdiObjects
.Append(NULL
);
2118 case META_CREATEBITMAP
:
2121 m_gdiObjects
.Append(NULL
);
2124 case META_CREATEREGION
:
2127 m_gdiObjects
.Append(NULL
);
2135 node
= node
->GetNext();
2137 double actualWidth
= (double)fabs(metaFile
->right
- metaFile
->left
);
2138 double actualHeight
= (double)fabs(metaFile
->bottom
- metaFile
->top
);
2140 double initialScaleX
= 1.0;
2141 double initialScaleY
= 1.0;
2143 double xoffset
, yoffset
;
2145 // Translate so origin is at centre of rectangle
2146 if (metaFile
->bottom
> metaFile
->top
)
2147 yoffset
= - (double)((metaFile
->bottom
- metaFile
->top
)/2.0);
2149 yoffset
= - (double)((metaFile
->top
- metaFile
->bottom
)/2.0);
2151 if (metaFile
->right
> metaFile
->left
)
2152 xoffset
= - (double)((metaFile
->right
- metaFile
->left
)/2.0);
2154 xoffset
= - (double)((metaFile
->left
- metaFile
->right
)/2.0);
2156 Translate(xoffset
, yoffset
);
2158 // Scale to a reasonable size (take the width of this wxDrawnShape
2160 if (actualWidth
!= 0.0)
2162 initialScaleX
= (double)((*rwidth
) / actualWidth
);
2163 initialScaleY
= initialScaleX
;
2164 (*rheight
) = initialScaleY
*actualHeight
;
2166 Scale(initialScaleX
, initialScaleY
);
2168 m_width
= (actualWidth
*initialScaleX
);
2169 m_height
= *rheight
;
2175 // Scale to fit size
2176 void wxPseudoMetaFile::ScaleTo(double w
, double h
)
2178 double scaleX
= (double)(w
/m_width
);
2179 double scaleY
= (double)(h
/m_height
);
2182 Scale(scaleX
, scaleY
);
2185 void wxPseudoMetaFile::GetBounds(double *boundMinX
, double *boundMinY
, double *boundMaxX
, double *boundMaxY
)
2187 double maxX
= (double) -99999.9;
2188 double maxY
= (double) -99999.9;
2189 double minX
= (double) 99999.9;
2190 double minY
= (double) 99999.9;
2192 wxNode
*node
= m_ops
.GetFirst();
2195 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
2196 switch (op
->GetOp())
2198 case DRAWOP_DRAW_LINE
:
2199 case DRAWOP_DRAW_RECT
:
2200 case DRAWOP_DRAW_ROUNDED_RECT
:
2201 case DRAWOP_DRAW_ELLIPSE
:
2202 case DRAWOP_DRAW_POINT
:
2203 case DRAWOP_DRAW_TEXT
:
2205 wxOpDraw
*opDraw
= (wxOpDraw
*)op
;
2206 if (opDraw
->m_x1
< minX
) minX
= opDraw
->m_x1
;
2207 if (opDraw
->m_x1
> maxX
) maxX
= opDraw
->m_x1
;
2208 if (opDraw
->m_y1
< minY
) minY
= opDraw
->m_y1
;
2209 if (opDraw
->m_y1
> maxY
) maxY
= opDraw
->m_y1
;
2210 if (op
->GetOp() == DRAWOP_DRAW_LINE
)
2212 if (opDraw
->m_x2
< minX
) minX
= opDraw
->m_x2
;
2213 if (opDraw
->m_x2
> maxX
) maxX
= opDraw
->m_x2
;
2214 if (opDraw
->m_y2
< minY
) minY
= opDraw
->m_y2
;
2215 if (opDraw
->m_y2
> maxY
) maxY
= opDraw
->m_y2
;
2217 else if (op
->GetOp() == DRAWOP_DRAW_RECT
||
2218 op
->GetOp() == DRAWOP_DRAW_ROUNDED_RECT
||
2219 op
->GetOp() == DRAWOP_DRAW_ELLIPSE
)
2221 if ((opDraw
->m_x1
+ opDraw
->m_x2
) < minX
) minX
= (opDraw
->m_x1
+ opDraw
->m_x2
);
2222 if ((opDraw
->m_x1
+ opDraw
->m_x2
) > maxX
) maxX
= (opDraw
->m_x1
+ opDraw
->m_x2
);
2223 if ((opDraw
->m_y1
+ opDraw
->m_y2
) < minY
) minY
= (opDraw
->m_y1
+ opDraw
->m_y2
);
2224 if ((opDraw
->m_y1
+ opDraw
->m_y2
) > maxY
) maxY
= (opDraw
->m_y1
+ opDraw
->m_y2
);
2228 case DRAWOP_DRAW_ARC
:
2230 // TODO: don't yet know how to calculate the bounding box
2231 // for an arc. So pretend it's a line; to get a correct
2232 // bounding box, draw a blank rectangle first, of the correct
2234 wxOpDraw
*opDraw
= (wxOpDraw
*)op
;
2235 if (opDraw
->m_x1
< minX
) minX
= opDraw
->m_x1
;
2236 if (opDraw
->m_x1
> maxX
) maxX
= opDraw
->m_x1
;
2237 if (opDraw
->m_y1
< minY
) minY
= opDraw
->m_y1
;
2238 if (opDraw
->m_y1
> maxY
) maxY
= opDraw
->m_y1
;
2239 if (opDraw
->m_x2
< minX
) minX
= opDraw
->m_x2
;
2240 if (opDraw
->m_x2
> maxX
) maxX
= opDraw
->m_x2
;
2241 if (opDraw
->m_y2
< minY
) minY
= opDraw
->m_y2
;
2242 if (opDraw
->m_y2
> maxY
) maxY
= opDraw
->m_y2
;
2245 case DRAWOP_DRAW_POLYLINE
:
2246 case DRAWOP_DRAW_POLYGON
:
2247 case DRAWOP_DRAW_SPLINE
:
2249 wxOpPolyDraw
*poly
= (wxOpPolyDraw
*)op
;
2250 for (int i
= 0; i
< poly
->m_noPoints
; i
++)
2252 if (poly
->m_points
[i
].x
< minX
) minX
= poly
->m_points
[i
].x
;
2253 if (poly
->m_points
[i
].x
> maxX
) maxX
= poly
->m_points
[i
].x
;
2254 if (poly
->m_points
[i
].y
< minY
) minY
= poly
->m_points
[i
].y
;
2255 if (poly
->m_points
[i
].y
> maxY
) maxY
= poly
->m_points
[i
].y
;
2262 node
= node
->GetNext();
2270 *w = (double)fabs(maxX - minX);
2271 *h = (double)fabs(maxY - minY);
2275 // Calculate size from current operations
2276 void wxPseudoMetaFile::CalculateSize(wxDrawnShape
* shape
)
2278 double boundMinX
, boundMinY
, boundMaxX
, boundMaxY
;
2280 GetBounds(& boundMinX
, & boundMinY
, & boundMaxX
, & boundMaxY
);
2282 SetSize(boundMaxX
- boundMinX
, boundMaxY
- boundMinY
);
2286 shape
->SetWidth(m_width
);
2287 shape
->SetHeight(m_height
);
2291 // Set of functions for drawing into a pseudo metafile.
2292 // They use integers, but doubles are used internally for accuracy
2295 void wxPseudoMetaFile::DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
)
2297 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_LINE
,
2298 (double) pt1
.x
, (double) pt1
.y
, (double) pt2
.x
, (double) pt2
.y
);
2300 m_ops
.Append(theOp
);
2303 void wxPseudoMetaFile::DrawRectangle(const wxRect
& rect
)
2305 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_RECT
,
2306 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2308 m_ops
.Append(theOp
);
2311 void wxPseudoMetaFile::DrawRoundedRectangle(const wxRect
& rect
, double radius
)
2313 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_ROUNDED_RECT
,
2314 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2316 theOp
->m_radius
= radius
;
2318 m_ops
.Append(theOp
);
2321 void wxPseudoMetaFile::DrawEllipse(const wxRect
& rect
)
2323 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_ELLIPSE
,
2324 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2326 m_ops
.Append(theOp
);
2329 void wxPseudoMetaFile::DrawArc(const wxPoint
& centrePt
, const wxPoint
& startPt
, const wxPoint
& endPt
)
2331 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_ARC
,
2332 (double) centrePt
.x
, (double) centrePt
.y
, (double) startPt
.x
, (double) startPt
.y
);
2334 theOp
->m_x3
= (double) endPt
.x
;
2335 theOp
->m_y3
= (double) endPt
.y
;
2337 m_ops
.Append(theOp
);
2340 void wxPseudoMetaFile::DrawEllipticArc(const wxRect
& rect
, double startAngle
, double endAngle
)
2342 const double pi
= 3.1415926535897932384626433832795 ;
2344 double startAngleRadians
= startAngle
* (pi
*2.0/360.0);
2345 double endAngleRadians
= endAngle
* (pi
*2.0/360.0);
2347 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_ELLIPTIC_ARC
,
2348 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2350 theOp
->m_x3
= startAngleRadians
;
2351 theOp
->m_y3
= endAngleRadians
;
2353 m_ops
.Append(theOp
);
2356 void wxPseudoMetaFile::DrawPoint(const wxPoint
& pt
)
2358 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_POINT
,
2359 (double) pt
.x
, (double) pt
.y
, 0.0, 0.0);
2361 m_ops
.Append(theOp
);
2364 void wxPseudoMetaFile::DrawText(const wxString
& text
, const wxPoint
& pt
)
2366 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_TEXT
,
2367 (double) pt
.x
, (double) pt
.y
, 0.0, 0.0);
2369 theOp
->m_textString
= copystring(text
);
2371 m_ops
.Append(theOp
);
2374 void wxPseudoMetaFile::DrawLines(int n
, wxPoint pts
[])
2376 wxRealPoint
* realPoints
= new wxRealPoint
[n
];
2378 for (i
= 0; i
< n
; i
++)
2380 realPoints
[i
].x
= pts
[i
].x
;
2381 realPoints
[i
].y
= pts
[i
].y
;
2383 wxOpPolyDraw
* theOp
= new wxOpPolyDraw(DRAWOP_DRAW_POLYLINE
, n
, realPoints
);
2384 m_ops
.Append(theOp
);
2387 void wxPseudoMetaFile::DrawPolygon(int n
, wxPoint pts
[], int flags
)
2389 wxRealPoint
* realPoints
= new wxRealPoint
[n
];
2391 for (i
= 0; i
< n
; i
++)
2393 realPoints
[i
].x
= pts
[i
].x
;
2394 realPoints
[i
].y
= pts
[i
].y
;
2396 wxOpPolyDraw
* theOp
= new wxOpPolyDraw(DRAWOP_DRAW_POLYGON
, n
, realPoints
);
2397 m_ops
.Append(theOp
);
2399 if (flags
& oglMETAFLAGS_OUTLINE
)
2400 m_outlineOp
= (m_ops
.GetCount() - 1);
2403 void wxPseudoMetaFile::DrawSpline(int n
, wxPoint pts
[])
2405 wxRealPoint
* realPoints
= new wxRealPoint
[n
];
2407 for (i
= 0; i
< n
; i
++)
2409 realPoints
[i
].x
= pts
[i
].x
;
2410 realPoints
[i
].y
= pts
[i
].y
;
2412 wxOpPolyDraw
* theOp
= new wxOpPolyDraw(DRAWOP_DRAW_SPLINE
, n
, realPoints
);
2413 m_ops
.Append(theOp
);
2416 void wxPseudoMetaFile::SetClippingRect(const wxRect
& rect
)
2418 wxOpSetClipping
* theOp
= new wxOpSetClipping(DRAWOP_SET_CLIPPING_RECT
,
2419 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2422 void wxPseudoMetaFile::DestroyClippingRect()
2424 wxOpSetClipping
* theOp
= new wxOpSetClipping(DRAWOP_DESTROY_CLIPPING_RECT
,
2425 0.0, 0.0, 0.0, 0.0);
2427 m_ops
.Append(theOp
);
2430 void wxPseudoMetaFile::SetPen(wxPen
* pen
, bool isOutline
)
2432 m_gdiObjects
.Append(pen
);
2433 int n
= m_gdiObjects
.GetCount();
2435 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_PEN
, this, n
- 1);
2437 m_ops
.Append(theOp
);
2441 m_outlineColours
.Append((wxObject
*) (n
- 1));
2445 void wxPseudoMetaFile::SetBrush(wxBrush
* brush
, bool isFill
)
2447 m_gdiObjects
.Append(brush
);
2448 int n
= m_gdiObjects
.GetCount();
2450 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_BRUSH
, this, n
- 1);
2452 m_ops
.Append(theOp
);
2456 m_fillColours
.Append((wxObject
*) (n
- 1));
2460 void wxPseudoMetaFile::SetFont(wxFont
* font
)
2462 m_gdiObjects
.Append(font
);
2463 int n
= m_gdiObjects
.GetCount();
2465 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_FONT
, this, n
- 1);
2467 m_ops
.Append(theOp
);
2470 void wxPseudoMetaFile::SetTextColour(const wxColour
& colour
)
2472 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_TEXT_COLOUR
, this, 0);
2473 theOp
->m_r
= colour
.Red();
2474 theOp
->m_g
= colour
.Green();
2475 theOp
->m_b
= colour
.Blue();
2477 m_ops
.Append(theOp
);
2480 void wxPseudoMetaFile::SetBackgroundColour(const wxColour
& colour
)
2482 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_BK_COLOUR
, this, 0);
2483 theOp
->m_r
= colour
.Red();
2484 theOp
->m_g
= colour
.Green();
2485 theOp
->m_b
= colour
.Blue();
2487 m_ops
.Append(theOp
);
2490 void wxPseudoMetaFile::SetBackgroundMode(int mode
)
2492 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_BK_MODE
, this, 0, mode
);
2494 m_ops
.Append(theOp
);