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 // Prolog database stuff
240 char *wxDrawnShape::GetFunctor()
245 void wxDrawnShape::WritePrologAttributes(wxExpr
*clause
)
247 wxRectangleShape::WritePrologAttributes(clause
);
249 clause
->AddAttributeValue("save_metafile", (long)m_saveToFile
);
253 for (i
= 0; i
< 4; i
++)
255 if (m_metafiles
[i
].IsValid())
256 m_metafiles
[i
].WritePrologAttributes(clause
, i
);
261 void wxDrawnShape::ReadPrologAttributes(wxExpr
*clause
)
263 wxRectangleShape::ReadPrologAttributes(clause
);
265 int iVal
= (int) m_saveToFile
;
266 clause
->AssignAttributeValue("save_metafile", &iVal
);
267 m_saveToFile
= (iVal
!= 0);
272 for (i
= 0; i
< 4; i
++)
274 m_metafiles
[i
].ReadPrologAttributes(clause
, i
);
280 // Does the copying for this object
281 void wxDrawnShape::Copy(wxShape
& copy
)
283 wxRectangleShape::Copy(copy
);
285 wxASSERT( copy
.IsKindOf(CLASSINFO(wxDrawnShape
)) ) ;
287 wxDrawnShape
& drawnCopy
= (wxDrawnShape
&) copy
;
290 for (i
= 0; i
< 4; i
++)
292 m_metafiles
[i
].Copy(drawnCopy
.m_metafiles
[i
]);
294 drawnCopy
.m_saveToFile
= m_saveToFile
;
295 drawnCopy
.m_currentAngle
= m_currentAngle
;
298 bool wxDrawnShape::LoadFromMetaFile(char *filename
)
300 return m_metafiles
[0].LoadFromMetaFile(filename
, &m_width
, &m_height
);
303 // Set of functions for drawing into a pseudo metafile.
304 // They use integers, but doubles are used internally for accuracy
307 void wxDrawnShape::DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
)
309 m_metafiles
[m_currentAngle
].DrawLine(pt1
, pt2
);
312 void wxDrawnShape::DrawRectangle(const wxRect
& rect
)
314 m_metafiles
[m_currentAngle
].DrawRectangle(rect
);
317 void wxDrawnShape::DrawRoundedRectangle(const wxRect
& rect
, double radius
)
319 m_metafiles
[m_currentAngle
].DrawRoundedRectangle(rect
, radius
);
322 void wxDrawnShape::DrawEllipse(const wxRect
& rect
)
324 m_metafiles
[m_currentAngle
].DrawEllipse(rect
);
327 void wxDrawnShape::DrawArc(const wxPoint
& centrePt
, const wxPoint
& startPt
, const wxPoint
& endPt
)
329 m_metafiles
[m_currentAngle
].DrawArc(centrePt
, startPt
, endPt
);
332 void wxDrawnShape::DrawEllipticArc(const wxRect
& rect
, double startAngle
, double endAngle
)
334 m_metafiles
[m_currentAngle
].DrawEllipticArc(rect
, startAngle
, endAngle
);
337 void wxDrawnShape::DrawPoint(const wxPoint
& pt
)
339 m_metafiles
[m_currentAngle
].DrawPoint(pt
);
342 void wxDrawnShape::DrawText(const wxString
& text
, const wxPoint
& pt
)
344 m_metafiles
[m_currentAngle
].DrawText(text
, pt
);
347 void wxDrawnShape::DrawLines(int n
, wxPoint pts
[])
349 m_metafiles
[m_currentAngle
].DrawLines(n
, pts
);
352 void wxDrawnShape::DrawPolygon(int n
, wxPoint pts
[], int flags
)
354 if (flags
& oglMETAFLAGS_ATTACHMENTS
)
358 for (i
= 0; i
< n
; i
++)
359 m_attachmentPoints
.Append(new wxAttachmentPoint(i
, pts
[i
].x
, pts
[i
].y
));
361 m_metafiles
[m_currentAngle
].DrawPolygon(n
, pts
, flags
);
364 void wxDrawnShape::DrawSpline(int n
, wxPoint pts
[])
366 m_metafiles
[m_currentAngle
].DrawSpline(n
, pts
);
369 void wxDrawnShape::SetClippingRect(const wxRect
& rect
)
371 m_metafiles
[m_currentAngle
].SetClippingRect(rect
);
374 void wxDrawnShape::DestroyClippingRect()
376 m_metafiles
[m_currentAngle
].DestroyClippingRect();
379 void wxDrawnShape::SetPen(wxPen
* pen
, bool isOutline
)
381 m_metafiles
[m_currentAngle
].SetPen(pen
, isOutline
);
384 void wxDrawnShape::SetBrush(wxBrush
* brush
, bool isFill
)
386 m_metafiles
[m_currentAngle
].SetBrush(brush
, isFill
);
389 void wxDrawnShape::SetFont(wxFont
* font
)
391 m_metafiles
[m_currentAngle
].SetFont(font
);
394 void wxDrawnShape::SetTextColour(const wxColour
& colour
)
396 m_metafiles
[m_currentAngle
].SetTextColour(colour
);
399 void wxDrawnShape::SetBackgroundColour(const wxColour
& colour
)
401 m_metafiles
[m_currentAngle
].SetBackgroundColour(colour
);
404 void wxDrawnShape::SetBackgroundMode(int mode
)
406 m_metafiles
[m_currentAngle
].SetBackgroundMode(mode
);
411 * Individual operations
416 * Set font, brush, text colour
420 wxOpSetGDI::wxOpSetGDI(int theOp
, wxPseudoMetaFile
*theImage
, int theGdiIndex
, int theMode
):
423 m_gdiIndex
= theGdiIndex
;
428 void wxOpSetGDI::Do(wxDC
& dc
, double xoffset
, double yoffset
)
434 // Check for overriding this operation for outline
436 if (m_image
->m_outlineColours
.Member((wxObject
*)m_gdiIndex
))
438 if (m_image
->m_outlinePen
)
439 dc
.SetPen(m_image
->m_outlinePen
);
443 wxNode
*node
= m_image
->m_gdiObjects
.Nth(m_gdiIndex
);
446 wxPen
*pen
= (wxPen
*)node
->Data();
453 case DRAWOP_SET_BRUSH
:
455 // Check for overriding this operation for outline or fill
457 if (m_image
->m_outlineColours
.Member((wxObject
*)m_gdiIndex
))
459 // Need to construct a brush to match the outline pen's colour
460 if (m_image
->m_outlinePen
)
462 wxBrush
*br
= wxTheBrushList
->FindOrCreateBrush(m_image
->m_outlinePen
->GetColour(), wxSOLID
);
467 else if (m_image
->m_fillColours
.Member((wxObject
*)m_gdiIndex
))
469 if (m_image
->m_fillBrush
)
471 dc
.SetBrush(m_image
->m_fillBrush
);
476 wxNode
*node
= m_image
->m_gdiObjects
.Nth(m_gdiIndex
);
479 wxBrush
*brush
= (wxBrush
*)node
->Data();
486 case DRAWOP_SET_FONT
:
488 wxNode
*node
= m_image
->m_gdiObjects
.Nth(m_gdiIndex
);
491 wxFont
*font
= (wxFont
*)node
->Data();
497 case DRAWOP_SET_TEXT_COLOUR
:
499 wxColour
col(m_r
,m_g
,m_b
);
500 dc
.SetTextForeground(col
);
503 case DRAWOP_SET_BK_COLOUR
:
505 wxColour
col(m_r
,m_g
,m_b
);
506 dc
.SetTextBackground(col
);
509 case DRAWOP_SET_BK_MODE
:
511 dc
.SetBackgroundMode(m_mode
);
519 wxDrawOp
*wxOpSetGDI::Copy(wxPseudoMetaFile
*newImage
)
521 wxOpSetGDI
*newOp
= new wxOpSetGDI(m_op
, newImage
, m_gdiIndex
, m_mode
);
528 wxExpr
*wxOpSetGDI::WriteExpr(wxPseudoMetaFile
*image
)
530 wxExpr
*expr
= new wxExpr(PrologList
);
531 expr
->Append(new wxExpr((long)m_op
));
535 case DRAWOP_SET_BRUSH
:
536 case DRAWOP_SET_FONT
:
538 expr
->Append(new wxExpr((long)m_gdiIndex
));
541 case DRAWOP_SET_TEXT_COLOUR
:
542 case DRAWOP_SET_BK_COLOUR
:
544 expr
->Append(new wxExpr((long)m_r
));
545 expr
->Append(new wxExpr((long)m_g
));
546 expr
->Append(new wxExpr((long)m_b
));
549 case DRAWOP_SET_BK_MODE
:
551 expr
->Append(new wxExpr((long)m_mode
));
560 void wxOpSetGDI::ReadExpr(wxPseudoMetaFile
*image
, wxExpr
*expr
)
565 case DRAWOP_SET_BRUSH
:
566 case DRAWOP_SET_FONT
:
568 m_gdiIndex
= (int)expr
->Nth(1)->IntegerValue();
571 case DRAWOP_SET_TEXT_COLOUR
:
572 case DRAWOP_SET_BK_COLOUR
:
574 m_r
= (unsigned char)expr
->Nth(1)->IntegerValue();
575 m_g
= (unsigned char)expr
->Nth(2)->IntegerValue();
576 m_b
= (unsigned char)expr
->Nth(3)->IntegerValue();
579 case DRAWOP_SET_BK_MODE
:
581 m_mode
= (int)expr
->Nth(1)->IntegerValue();
590 * Set/destroy clipping
594 wxOpSetClipping::wxOpSetClipping(int theOp
, double theX1
, double theY1
,
595 double theX2
, double theY2
):wxDrawOp(theOp
)
603 wxDrawOp
*wxOpSetClipping::Copy(wxPseudoMetaFile
*newImage
)
605 wxOpSetClipping
*newOp
= new wxOpSetClipping(m_op
, m_x1
, m_y1
, m_x2
, m_y2
);
609 void wxOpSetClipping::Do(wxDC
& dc
, double xoffset
, double yoffset
)
613 case DRAWOP_SET_CLIPPING_RECT
:
615 dc
.SetClippingRegion(m_x1
+ xoffset
, m_y1
+ yoffset
, m_x2
+ xoffset
, m_y2
+ yoffset
);
618 case DRAWOP_DESTROY_CLIPPING_RECT
:
620 dc
.DestroyClippingRegion();
628 void wxOpSetClipping::Scale(double xScale
, double yScale
)
636 void wxOpSetClipping::Translate(double x
, double y
)
642 wxExpr
*wxOpSetClipping::WriteExpr(wxPseudoMetaFile
*image
)
644 wxExpr
*expr
= new wxExpr(PrologList
);
645 expr
->Append(new wxExpr((long)m_op
));
648 case DRAWOP_SET_CLIPPING_RECT
:
650 expr
->Append(new wxExpr(m_x1
));
651 expr
->Append(new wxExpr(m_y1
));
652 expr
->Append(new wxExpr(m_x2
));
653 expr
->Append(new wxExpr(m_y2
));
662 void wxOpSetClipping::ReadExpr(wxPseudoMetaFile
*image
, wxExpr
*expr
)
666 case DRAWOP_SET_CLIPPING_RECT
:
668 m_x1
= expr
->Nth(1)->RealValue();
669 m_y1
= expr
->Nth(2)->RealValue();
670 m_x2
= expr
->Nth(3)->RealValue();
671 m_y2
= expr
->Nth(4)->RealValue();
680 * Draw line, rectangle, rounded rectangle, ellipse, point, arc, text
684 wxOpDraw::wxOpDraw(int theOp
, double theX1
, double theY1
, double theX2
, double theY2
,
685 double theRadius
, char *s
):wxDrawOp(theOp
)
693 m_radius
= theRadius
;
694 if (s
) m_textString
= copystring(s
);
695 else m_textString
= NULL
;
698 wxOpDraw::~wxOpDraw()
700 if (m_textString
) delete[] m_textString
;
703 wxDrawOp
*wxOpDraw::Copy(wxPseudoMetaFile
*newImage
)
705 wxOpDraw
*newOp
= new wxOpDraw(m_op
, m_x1
, m_y1
, m_x2
, m_y2
, m_radius
, m_textString
);
711 void wxOpDraw::Do(wxDC
& dc
, double xoffset
, double yoffset
)
715 case DRAWOP_DRAW_LINE
:
717 dc
.DrawLine(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
), WXROUND(m_x2
+xoffset
), WXROUND(m_y2
+yoffset
));
720 case DRAWOP_DRAW_RECT
:
722 dc
.DrawRectangle(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
), WXROUND(m_x2
), WXROUND(m_y2
));
725 case DRAWOP_DRAW_ROUNDED_RECT
:
727 dc
.DrawRoundedRectangle(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
), WXROUND(m_x2
), WXROUND(m_y2
), m_radius
);
730 case DRAWOP_DRAW_ELLIPSE
:
732 dc
.DrawEllipse(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
), WXROUND(m_x2
), WXROUND(m_y2
));
735 case DRAWOP_DRAW_ARC
:
737 dc
.DrawArc(WXROUND(m_x2
+xoffset
), WXROUND(m_y2
+yoffset
),
738 WXROUND(m_x3
+xoffset
), WXROUND(m_y3
+yoffset
),
739 WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
));
742 case DRAWOP_DRAW_ELLIPTIC_ARC
:
744 const double pi
= 3.1415926535897932384626433832795 ;
746 // Convert back to degrees
748 WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
),
749 WXROUND(m_x2
), WXROUND(m_y2
),
750 WXROUND(m_x3
*(360.0/(2.0*pi
))), WXROUND(m_y3
*(360.0/(2.0*pi
))));
753 case DRAWOP_DRAW_POINT
:
755 dc
.DrawPoint(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
));
758 case DRAWOP_DRAW_TEXT
:
760 dc
.DrawText(m_textString
, WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
));
768 void wxOpDraw::Scale(double scaleX
, double scaleY
)
775 if (m_op
!= DRAWOP_DRAW_ELLIPTIC_ARC
)
784 void wxOpDraw::Translate(double x
, double y
)
791 case DRAWOP_DRAW_LINE
:
797 case DRAWOP_DRAW_ARC
:
805 case DRAWOP_DRAW_ELLIPTIC_ARC
:
814 void wxOpDraw::Rotate(double x
, double y
, double theta
, double sinTheta
, double cosTheta
)
816 double newX1
= m_x1
*cosTheta
- m_y1
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
817 double newY1
= m_x1
*sinTheta
+ m_y1
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
821 case DRAWOP_DRAW_LINE
:
823 double newX2
= m_x2
*cosTheta
- m_y2
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
824 double newY2
= m_x2
*sinTheta
+ m_y2
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
832 case DRAWOP_DRAW_RECT
:
833 case DRAWOP_DRAW_ROUNDED_RECT
:
834 case DRAWOP_DRAW_ELLIPTIC_ARC
:
836 // Assume only 0, 90, 180, 270 degree rotations.
837 // oldX1, oldY1 represents the top left corner. Find the
838 // bottom right, and rotate that. Then the width/height is the difference
839 // between x/y values.
840 double oldBottomRightX
= m_x1
+ m_x2
;
841 double oldBottomRightY
= m_y1
+ m_y2
;
842 double newBottomRightX
= oldBottomRightX
*cosTheta
- oldBottomRightY
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
843 double newBottomRightY
= oldBottomRightX
*sinTheta
+ oldBottomRightY
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
845 // Now find the new top-left, bottom-right coordinates.
846 double minX
= wxMin(newX1
, newBottomRightX
);
847 double minY
= wxMin(newY1
, newBottomRightY
);
848 double maxX
= wxMax(newX1
, newBottomRightX
);
849 double maxY
= wxMax(newY1
, newBottomRightY
);
853 m_x2
= maxX
- minX
; // width
854 m_y2
= maxY
- minY
; // height
856 if (m_op
== DRAWOP_DRAW_ELLIPTIC_ARC
)
858 // Add rotation to angles
865 case DRAWOP_DRAW_ARC
:
867 double newX2
= m_x2
*cosTheta
- m_y2
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
868 double newY2
= m_x2
*sinTheta
+ m_y2
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
869 double newX3
= m_x3
*cosTheta
- m_y3
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
870 double newY3
= m_x3
*sinTheta
+ m_y3
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
886 wxExpr
*wxOpDraw::WriteExpr(wxPseudoMetaFile
*image
)
888 wxExpr
*expr
= new wxExpr(PrologList
);
889 expr
->Append(new wxExpr((long)m_op
));
892 case DRAWOP_DRAW_LINE
:
893 case DRAWOP_DRAW_RECT
:
894 case DRAWOP_DRAW_ELLIPSE
:
896 expr
->Append(new wxExpr(m_x1
));
897 expr
->Append(new wxExpr(m_y1
));
898 expr
->Append(new wxExpr(m_x2
));
899 expr
->Append(new wxExpr(m_y2
));
902 case DRAWOP_DRAW_ROUNDED_RECT
:
904 expr
->Append(new wxExpr(m_x1
));
905 expr
->Append(new wxExpr(m_y1
));
906 expr
->Append(new wxExpr(m_x2
));
907 expr
->Append(new wxExpr(m_y2
));
908 expr
->Append(new wxExpr(m_radius
));
911 case DRAWOP_DRAW_POINT
:
913 expr
->Append(new wxExpr(m_x1
));
914 expr
->Append(new wxExpr(m_y1
));
917 case DRAWOP_DRAW_TEXT
:
919 expr
->Append(new wxExpr(m_x1
));
920 expr
->Append(new wxExpr(m_y1
));
921 expr
->Append(new wxExpr(PrologString
, m_textString
));
924 case DRAWOP_DRAW_ARC
:
925 case DRAWOP_DRAW_ELLIPTIC_ARC
:
927 expr
->Append(new wxExpr(m_x1
));
928 expr
->Append(new wxExpr(m_y1
));
929 expr
->Append(new wxExpr(m_x2
));
930 expr
->Append(new wxExpr(m_y2
));
931 expr
->Append(new wxExpr(m_x3
));
932 expr
->Append(new wxExpr(m_y3
));
943 void wxOpDraw::ReadExpr(wxPseudoMetaFile
*image
, wxExpr
*expr
)
947 case DRAWOP_DRAW_LINE
:
948 case DRAWOP_DRAW_RECT
:
949 case DRAWOP_DRAW_ELLIPSE
:
951 m_x1
= expr
->Nth(1)->RealValue();
952 m_y1
= expr
->Nth(2)->RealValue();
953 m_x2
= expr
->Nth(3)->RealValue();
954 m_y2
= expr
->Nth(4)->RealValue();
957 case DRAWOP_DRAW_ROUNDED_RECT
:
959 m_x1
= expr
->Nth(1)->RealValue();
960 m_y1
= expr
->Nth(2)->RealValue();
961 m_x2
= expr
->Nth(3)->RealValue();
962 m_y2
= expr
->Nth(4)->RealValue();
963 m_radius
= expr
->Nth(5)->RealValue();
966 case DRAWOP_DRAW_POINT
:
968 m_x1
= expr
->Nth(1)->RealValue();
969 m_y1
= expr
->Nth(2)->RealValue();
972 case DRAWOP_DRAW_TEXT
:
974 m_x1
= expr
->Nth(1)->RealValue();
975 m_y1
= expr
->Nth(2)->RealValue();
976 wxString
str(expr
->Nth(3)->StringValue());
977 m_textString
= copystring((const char*) str
);
980 case DRAWOP_DRAW_ARC
:
981 case DRAWOP_DRAW_ELLIPTIC_ARC
:
983 m_x1
= expr
->Nth(1)->RealValue();
984 m_y1
= expr
->Nth(2)->RealValue();
985 m_x2
= expr
->Nth(3)->RealValue();
986 m_y2
= expr
->Nth(4)->RealValue();
987 m_x3
= expr
->Nth(5)->RealValue();
988 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
;
1110 wxExpr
*wxOpPolyDraw::WriteExpr(wxPseudoMetaFile
*image
)
1112 wxExpr
*expr
= new wxExpr(PrologList
);
1113 expr
->Append(new wxExpr((long)m_op
));
1114 expr
->Append(new wxExpr((long)m_noPoints
));
1123 * Store each coordinate pair in a hex string to save space.
1124 * E.g. "1B9080CD". 4 hex digits per coordinate pair.
1128 for (int i
= 0; i
< m_noPoints
; i
++)
1130 long signedX
= (long)(m_points
[i
].x
*100.0);
1131 long signedY
= (long)(m_points
[i
].y
*100.0);
1133 // Scale to 0 -> 64K
1134 long unSignedX
= (long)(signedX
+ 32767.0);
1135 long unSignedY
= (long)(signedY
+ 32767.0);
1137 // IntToHex((unsigned int)signedX, buf2);
1138 // IntToHex((unsigned int)signedY, buf3);
1139 IntToHex((int)unSignedX
, buf2
);
1140 IntToHex((int)unSignedY
, buf3
);
1142 // Don't overrun the buffer
1145 strcat(oglBuffer
, buf2
);
1146 strcat(oglBuffer
, buf3
);
1149 expr
->Append(new wxExpr(PrologString
, oglBuffer
));
1153 void wxOpPolyDraw::ReadExpr(wxPseudoMetaFile
*image
, wxExpr
*expr
)
1155 m_noPoints
= (int)expr
->Nth(1)->IntegerValue();
1160 m_points
= new wxRealPoint
[m_noPoints
];
1163 wxString hexString
= expr
->Nth(2)->StringValue();
1164 while (i
< m_noPoints
)
1166 buf1
[0] = hexString
[bufPtr
];
1167 buf1
[1] = hexString
[bufPtr
+ 1];
1168 buf1
[2] = hexString
[bufPtr
+ 2];
1169 buf1
[3] = hexString
[bufPtr
+ 3];
1172 buf2
[0] = hexString
[bufPtr
+ 4];
1173 buf2
[1] = hexString
[bufPtr
+ 5];
1174 buf2
[2] = hexString
[bufPtr
+ 6];
1175 buf2
[3] = hexString
[bufPtr
+ 7];
1180 // int signedX = (signed int)HexToInt(buf1);
1181 // int signedY = (signed int)HexToInt(buf2);
1182 long unSignedX
= HexToInt(buf1
);
1183 long unSignedY
= HexToInt(buf2
);
1184 // Scale -32K -> +32K
1185 long signedX
= unSignedX
- 32767;
1186 long signedY
= unSignedY
- 32767;
1188 int testX
= (signed int)unSignedX
;
1189 int testY
= (signed int)unSignedY
;
1192 m_points
[i
].x
= (double)(signedX
/ 100.0);
1193 m_points
[i
].y
= (double)(signedY
/ 100.0);
1199 // Draw an outline using the current operation.
1200 bool wxOpPolyDraw::OnDrawOutline(wxDC
& dc
, double x
, double y
, double w
, double h
, double oldW
, double oldH
)
1202 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
1204 // Multiply all points by proportion of new size to old size
1205 double x_proportion
= (double)(fabs(w
/oldW
));
1206 double y_proportion
= (double)(fabs(h
/oldH
));
1209 wxPoint
*intPoints
= new wxPoint
[n
];
1211 for (i
= 0; i
< n
; i
++)
1213 intPoints
[i
].x
= WXROUND (x_proportion
* m_points
[i
].x
);
1214 intPoints
[i
].y
= WXROUND (y_proportion
* m_points
[i
].y
);
1216 dc
.DrawPolygon(n
, intPoints
, x
, y
);
1221 // Assume (x1, y1) is centre of box (most generally, line end at box)
1222 bool wxOpPolyDraw::GetPerimeterPoint(double x1
, double y1
,
1223 double x2
, double y2
,
1224 double *x3
, double *y3
,
1225 double xOffset
, double yOffset
,
1226 bool attachmentMode
)
1230 // First check for situation where the line is vertical,
1231 // and we would want to connect to a point on that vertical --
1232 // oglFindEndForPolyline can't cope with this (the arrow
1233 // gets drawn to the wrong place).
1234 if ((!attachmentMode
) && (x1
== x2
))
1236 // Look for the point we'd be connecting to. This is
1239 for (i
= 0; i
< n
; i
++)
1241 wxRealPoint
*point
= & (m_points
[i
]);
1242 if (point
->x
== 0.0)
1244 if ((y2
> y1
) && (point
->y
> 0.0))
1246 *x3
= point
->x
+ xOffset
;
1247 *y3
= point
->y
+ yOffset
;
1250 else if ((y2
< y1
) && (point
->y
< 0.0))
1252 *x3
= point
->x
+ xOffset
;
1253 *y3
= point
->y
+ yOffset
;
1260 double *xpoints
= new double[n
];
1261 double *ypoints
= new double[n
];
1264 for (i
= 0; i
< n
; i
++)
1266 wxRealPoint
*point
= & (m_points
[i
]);
1267 xpoints
[i
] = point
->x
+ xOffset
;
1268 ypoints
[i
] = point
->y
+ yOffset
;
1271 oglFindEndForPolyline(n
, xpoints
, ypoints
,
1272 x1
, y1
, x2
, y2
, x3
, y3
);
1286 static char hexArray
[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B',
1287 'C', 'D', 'E', 'F' };
1289 // Convert unsigned 16-bit integer to 4-character hex string
1290 static void IntToHex(unsigned int dec
, char *buf
)
1292 int digit1
= (int)(dec
/4096);
1293 int digit2
= (int)((dec
- (digit1
*4096))/256);
1294 int digit3
= (int)((dec
- (digit1
*4096) - (digit2
*256))/16);
1295 int digit4
= dec
- (digit1
*4096 + digit2
*256 + digit3
*16);
1297 buf
[0] = hexArray
[digit1
];
1298 buf
[1] = hexArray
[digit2
];
1299 buf
[2] = hexArray
[digit3
];
1300 buf
[3] = hexArray
[digit4
];
1304 // One hex digit to decimal number
1305 static int HexToInt1(char hex
)
1347 // 4-digit hex string to unsigned integer
1348 static unsigned long HexToInt(char *buf
)
1350 long d1
= (long)(HexToInt1(buf
[0])*4096.0) ;
1351 long d2
= (long)(HexToInt1(buf
[1])*256.0) ;
1352 long d3
= (long)(HexToInt1(buf
[2])*16.0) ;
1353 long d4
= (long)(HexToInt1(buf
[3])) ;
1354 unsigned long n
= (long)(d1
+ d2
+ d3
+ d4
) ;
1359 * wxPseudo meta-file
1363 IMPLEMENT_DYNAMIC_CLASS(wxPseudoMetaFile
, wxObject
)
1365 wxPseudoMetaFile::wxPseudoMetaFile()
1367 m_currentRotation
= 0;
1368 m_rotateable
= TRUE
;
1371 m_outlinePen
= NULL
;
1376 wxPseudoMetaFile::wxPseudoMetaFile(wxPseudoMetaFile
& mf
)
1381 wxPseudoMetaFile::~wxPseudoMetaFile()
1386 void wxPseudoMetaFile::Clear()
1388 wxNode
*node
= m_ops
.First();
1391 wxDrawOp
*op
= (wxDrawOp
*)node
->Data();
1393 node
= node
->Next();
1396 m_gdiObjects
.Clear();
1397 m_outlineColours
.Clear();
1398 m_fillColours
.Clear();
1402 void wxPseudoMetaFile::Draw(wxDC
& dc
, double xoffset
, double yoffset
)
1404 wxNode
*node
= m_ops
.First();
1407 wxDrawOp
*op
= (wxDrawOp
*)node
->Data();
1408 op
->Do(dc
, xoffset
, yoffset
);
1409 node
= node
->Next();
1413 void wxPseudoMetaFile::Scale(double sx
, double sy
)
1415 wxNode
*node
= m_ops
.First();
1418 wxDrawOp
*op
= (wxDrawOp
*)node
->Data();
1420 node
= node
->Next();
1426 void wxPseudoMetaFile::Translate(double x
, double y
)
1428 wxNode
*node
= m_ops
.First();
1431 wxDrawOp
*op
= (wxDrawOp
*)node
->Data();
1432 op
->Translate(x
, y
);
1433 node
= node
->Next();
1437 void wxPseudoMetaFile::Rotate(double x
, double y
, double theta
)
1439 double theta1
= theta
-m_currentRotation
;
1440 if (theta1
== 0.0) return;
1441 double cosTheta
= (double)cos(theta1
);
1442 double sinTheta
= (double)sin(theta1
);
1444 wxNode
*node
= m_ops
.First();
1447 wxDrawOp
*op
= (wxDrawOp
*)node
->Data();
1448 op
->Rotate(x
, y
, theta
, sinTheta
, cosTheta
);
1449 node
= node
->Next();
1451 m_currentRotation
= theta
;
1455 void wxPseudoMetaFile::WritePrologAttributes(wxExpr
*clause
, int whichAngle
)
1458 widthStr
.Printf("meta_width%d", whichAngle
);
1461 heightStr
.Printf("meta_height%d", whichAngle
);
1463 wxString outlineStr
;
1464 outlineStr
.Printf("outline_op%d", whichAngle
);
1466 wxString rotateableStr
;
1467 rotateableStr
.Printf("meta_rotateable%d", whichAngle
);
1469 // Write width and height
1470 clause
->AddAttributeValue(widthStr
, m_width
);
1471 clause
->AddAttributeValue(heightStr
, m_height
);
1472 clause
->AddAttributeValue(rotateableStr
, (long)m_rotateable
);
1473 clause
->AddAttributeValue(outlineStr
, (long)m_outlineOp
);
1475 // Write GDI objects
1478 wxNode
*node
= m_gdiObjects
.First();
1481 sprintf(buf
, "gdi%d_%d", whichAngle
, i
);
1482 wxObject
*obj
= (wxObject
*)node
->Data();
1483 wxExpr
*expr
= NULL
;
1486 if (obj
->IsKindOf(CLASSINFO(wxPen
)))
1488 wxPen
*thePen
= (wxPen
*)obj
;
1489 expr
= new wxExpr(PrologList
);
1490 expr
->Append(new wxExpr((long)gyTYPE_PEN
));
1491 expr
->Append(new wxExpr((long)thePen
->GetWidth()));
1492 expr
->Append(new wxExpr((long)thePen
->GetStyle()));
1493 expr
->Append(new wxExpr((long)thePen
->GetColour().Red()));
1494 expr
->Append(new wxExpr((long)thePen
->GetColour().Green()));
1495 expr
->Append(new wxExpr((long)thePen
->GetColour().Blue()));
1497 else if (obj
->IsKindOf(CLASSINFO(wxBrush
)))
1499 wxBrush
*theBrush
= (wxBrush
*)obj
;
1500 expr
= new wxExpr(PrologList
);
1501 expr
->Append(new wxExpr((long)gyTYPE_BRUSH
));
1502 expr
->Append(new wxExpr((long)theBrush
->GetStyle()));
1503 expr
->Append(new wxExpr((long)theBrush
->GetColour().Red()));
1504 expr
->Append(new wxExpr((long)theBrush
->GetColour().Green()));
1505 expr
->Append(new wxExpr((long)theBrush
->GetColour().Blue()));
1507 else if (obj
->IsKindOf(CLASSINFO(wxFont
)))
1509 wxFont
*theFont
= (wxFont
*)obj
;
1510 expr
= new wxExpr(PrologList
);
1511 expr
->Append(new wxExpr((long)gyTYPE_FONT
));
1512 expr
->Append(new wxExpr((long)theFont
->GetPointSize()));
1513 expr
->Append(new wxExpr((long)theFont
->GetFamily()));
1514 expr
->Append(new wxExpr((long)theFont
->GetStyle()));
1515 expr
->Append(new wxExpr((long)theFont
->GetWeight()));
1516 expr
->Append(new wxExpr((long)theFont
->GetUnderlined()));
1521 // If no recognised GDI object, append a place holder anyway.
1522 expr
= new wxExpr(PrologList
);
1523 expr
->Append(new wxExpr((long)0));
1528 clause
->AddAttributeValue(buf
, expr
);
1531 node
= node
->Next();
1534 // Write drawing operations
1536 node
= m_ops
.First();
1539 sprintf(buf
, "op%d_%d", whichAngle
, i
);
1540 wxDrawOp
*op
= (wxDrawOp
*)node
->Data();
1541 wxExpr
*expr
= op
->WriteExpr(this);
1544 clause
->AddAttributeValue(buf
, expr
);
1547 node
= node
->Next();
1550 // Write outline and fill GDI op lists (if any)
1551 if (m_outlineColours
.Number() > 0)
1553 wxExpr
*outlineExpr
= new wxExpr(PrologList
);
1554 node
= m_outlineColours
.First();
1557 outlineExpr
->Append(new wxExpr((long)node
->Data()));
1558 node
= node
->Next();
1560 wxString outlineObjectsStr
;
1561 outlineObjectsStr
.Printf("outline_objects%d", whichAngle
);
1563 clause
->AddAttributeValue(outlineObjectsStr
, outlineExpr
);
1565 if (m_fillColours
.Number() > 0)
1567 wxExpr
*fillExpr
= new wxExpr(PrologList
);
1568 node
= m_fillColours
.First();
1571 fillExpr
->Append(new wxExpr((long)node
->Data()));
1572 node
= node
->Next();
1574 wxString fillObjectsStr
;
1575 fillObjectsStr
.Printf("fill_objects%d", whichAngle
);
1577 clause
->AddAttributeValue(fillObjectsStr
, fillExpr
);
1582 void wxPseudoMetaFile::ReadPrologAttributes(wxExpr
*clause
, int whichAngle
)
1585 widthStr
.Printf("meta_width%d", whichAngle
);
1588 heightStr
.Printf("meta_height%d", whichAngle
);
1590 wxString outlineStr
;
1591 outlineStr
.Printf("outline_op%d", whichAngle
);
1593 wxString rotateableStr
;
1594 rotateableStr
.Printf("meta_rotateable%d", whichAngle
);
1596 clause
->GetAttributeValue(widthStr
, m_width
);
1597 clause
->GetAttributeValue(heightStr
, m_height
);
1598 clause
->GetAttributeValue(outlineStr
, m_outlineOp
);
1600 int iVal
= (int) m_rotateable
;
1601 clause
->GetAttributeValue(rotateableStr
, iVal
);
1602 m_rotateable
= (iVal
!= 0);
1607 bool keepGoing
= TRUE
;
1610 sprintf(buf
, "gdi%d_%d", whichAngle
, i
);
1611 wxExpr
*expr
= NULL
;
1612 clause
->GetAttributeValue(buf
, &expr
);
1619 wxExpr
*idExpr
= expr
->Nth(0);
1620 switch (idExpr
->IntegerValue())
1624 int penWidth
= (int)expr
->Nth(1)->IntegerValue();
1625 int penStyle
= (int)expr
->Nth(2)->IntegerValue();
1626 int penRed
= (int)expr
->Nth(3)->IntegerValue();
1627 int penGreen
= (int)expr
->Nth(4)->IntegerValue();
1628 int penBlue
= (int)expr
->Nth(5)->IntegerValue();
1629 wxColour
col(penRed
, penGreen
, penBlue
);
1630 wxPen
*p
= wxThePenList
->FindOrCreatePen(col
, penWidth
, penStyle
);
1633 m_gdiObjects
.Append(p
);
1638 int brushStyle
= (int)expr
->Nth(1)->IntegerValue();
1639 int brushRed
= (int)expr
->Nth(2)->IntegerValue();
1640 int brushGreen
= (int)expr
->Nth(3)->IntegerValue();
1641 int brushBlue
= (int)expr
->Nth(4)->IntegerValue();
1642 wxColour
col(brushRed
, brushGreen
, brushBlue
);
1643 wxBrush
*b
= wxTheBrushList
->FindOrCreateBrush(col
, brushStyle
);
1646 m_gdiObjects
.Append(b
);
1651 int fontPointSize
= (int)expr
->Nth(1)->IntegerValue();
1652 int fontFamily
= (int)expr
->Nth(2)->IntegerValue();
1653 int fontStyle
= (int)expr
->Nth(3)->IntegerValue();
1654 int fontWeight
= (int)expr
->Nth(4)->IntegerValue();
1655 int fontUnderlined
= (int)expr
->Nth(5)->IntegerValue();
1656 m_gdiObjects
.Append(wxTheFontList
->FindOrCreateFont(fontPointSize
,
1657 fontFamily
, fontStyle
, fontWeight
, (fontUnderlined
!= 0)));
1663 m_gdiObjects
.Append(NULL
);
1671 // Now read in the operations
1676 sprintf(buf
, "op%d_%d", whichAngle
, i
);
1677 wxExpr
*expr
= NULL
;
1678 clause
->GetAttributeValue(buf
, &expr
);
1685 wxExpr
*idExpr
= expr
->Nth(0);
1686 int opId
= (int)idExpr
->IntegerValue();
1689 case DRAWOP_SET_PEN
:
1690 case DRAWOP_SET_BRUSH
:
1691 case DRAWOP_SET_FONT
:
1692 case DRAWOP_SET_TEXT_COLOUR
:
1693 case DRAWOP_SET_BK_COLOUR
:
1694 case DRAWOP_SET_BK_MODE
:
1696 wxOpSetGDI
*theOp
= new wxOpSetGDI(opId
, this, 0);
1697 theOp
->ReadExpr(this, expr
);
1698 m_ops
.Append(theOp
);
1702 case DRAWOP_SET_CLIPPING_RECT
:
1703 case DRAWOP_DESTROY_CLIPPING_RECT
:
1705 wxOpSetClipping
*theOp
= new wxOpSetClipping(opId
, 0.0, 0.0, 0.0, 0.0);
1706 theOp
->ReadExpr(this, expr
);
1707 m_ops
.Append(theOp
);
1711 case DRAWOP_DRAW_LINE
:
1712 case DRAWOP_DRAW_RECT
:
1713 case DRAWOP_DRAW_ROUNDED_RECT
:
1714 case DRAWOP_DRAW_ELLIPSE
:
1715 case DRAWOP_DRAW_POINT
:
1716 case DRAWOP_DRAW_ARC
:
1717 case DRAWOP_DRAW_TEXT
:
1719 wxOpDraw
*theOp
= new wxOpDraw(opId
, 0.0, 0.0, 0.0, 0.0);
1720 theOp
->ReadExpr(this, expr
);
1721 m_ops
.Append(theOp
);
1724 case DRAWOP_DRAW_SPLINE
:
1725 case DRAWOP_DRAW_POLYLINE
:
1726 case DRAWOP_DRAW_POLYGON
:
1728 wxOpPolyDraw
*theOp
= new wxOpPolyDraw(opId
, 0, NULL
);
1729 theOp
->ReadExpr(this, expr
);
1730 m_ops
.Append(theOp
);
1740 wxString outlineObjectsStr
;
1741 outlineObjectsStr
.Printf("outline_objects%d", whichAngle
);
1743 // Now read in the list of outline and fill operations, if any
1744 wxExpr
*expr1
= clause
->AttributeValue(outlineObjectsStr
);
1747 wxExpr
*eachExpr
= expr1
->GetFirst();
1750 m_outlineColours
.Append((wxObject
*)eachExpr
->IntegerValue());
1751 eachExpr
= eachExpr
->GetNext();
1755 wxString fillObjectsStr
;
1756 fillObjectsStr
.Printf("fill_objects%d", whichAngle
);
1758 expr1
= clause
->AttributeValue(fillObjectsStr
);
1761 wxExpr
*eachExpr
= expr1
->GetFirst();
1764 m_fillColours
.Append((wxObject
*)eachExpr
->IntegerValue());
1765 eachExpr
= eachExpr
->GetNext();
1771 // Does the copying for this object
1772 void wxPseudoMetaFile::Copy(wxPseudoMetaFile
& copy
)
1776 copy
.m_currentRotation
= m_currentRotation
;
1777 copy
.m_width
= m_width
;
1778 copy
.m_height
= m_height
;
1779 copy
.m_rotateable
= m_rotateable
;
1780 copy
.m_fillBrush
= m_fillBrush
;
1781 copy
.m_outlinePen
= m_outlinePen
;
1782 copy
.m_outlineOp
= m_outlineOp
;
1784 // Copy the GDI objects
1785 wxNode
*node
= m_gdiObjects
.First();
1788 wxObject
*obj
= (wxObject
*)node
->Data();
1789 copy
.m_gdiObjects
.Append(obj
);
1790 node
= node
->Next();
1793 // Copy the operations
1794 node
= m_ops
.First();
1797 wxDrawOp
*op
= (wxDrawOp
*)node
->Data();
1798 copy
.m_ops
.Append(op
->Copy(©
));
1799 node
= node
->Next();
1802 // Copy the outline/fill operations
1803 node
= m_outlineColours
.First();
1806 copy
.m_outlineColours
.Append((wxObject
*)node
->Data());
1807 node
= node
->Next();
1809 node
= m_fillColours
.First();
1812 copy
.m_fillColours
.Append((wxObject
*)node
->Data());
1813 node
= node
->Next();
1818 * Pass size of existing image; scale height to
1819 * fit width and return new width and height.
1823 bool wxPseudoMetaFile::LoadFromMetaFile(char *filename
, double *rwidth
, double *rheight
)
1825 if (!FileExists(filename
))
1828 wxXMetaFile
*metaFile
= new wxXMetaFile
;
1830 if (!metaFile
->ReadFile(filename
))
1839 // Convert from metafile records to wxDrawnShape records
1840 wxNode
*node
= metaFile
->metaRecords
.First();
1843 wxMetaRecord
*record
= (wxMetaRecord
*)node
->Data();
1844 switch (record
->metaFunction
)
1846 case META_SETBKCOLOR
:
1848 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_BK_COLOUR
, this, 0);
1849 op
->m_r
= (unsigned char)record
->param1
;
1850 op
->m_g
= (unsigned char)record
->param2
;
1851 op
->m_b
= (unsigned char)record
->param3
;
1855 case META_SETBKMODE
:
1857 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_BK_MODE
, this, 0, (int)record
->param1
);
1861 case META_SETMAPMODE
:
1865 // case META_SETROP2:
1866 // case META_SETRELABS:
1867 // case META_SETPOLYFILLMODE:
1868 // case META_SETSTRETCHBLTMODE:
1869 // case META_SETTEXTCHAREXTRA:
1870 case META_SETTEXTCOLOR
:
1872 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_TEXT_COLOUR
, this, 0);
1873 op
->m_r
= (unsigned char)record
->param1
;
1874 op
->m_g
= (unsigned char)record
->param2
;
1875 op
->m_b
= (unsigned char)record
->param3
;
1879 // case META_SETTEXTJUSTIFICATION:
1880 // case META_SETWINDOWORG:
1881 // case META_SETWINDOWEXT:
1882 // case META_SETVIEWPORTORG:
1883 // case META_SETVIEWPORTEXT:
1884 // case META_OFFSETWINDOWORG:
1885 // case META_SCALEWINDOWEXT:
1886 // case META_OFFSETVIEWPORTORG:
1887 // case META_SCALEVIEWPORTEXT:
1890 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_LINE
, (double)lastX
, (double)lastY
,
1891 (double)record
->param1
, (double)record
->param2
);
1897 lastX
= (double)record
->param1
;
1898 lastY
= (double)record
->param2
;
1901 case META_EXCLUDECLIPRECT
:
1904 wxMetaRecord *rec = new wxMetaRecord(META_EXCLUDECLIPRECT);
1905 rec->param4 = getshort(handle); // m_y2
1906 rec->param3 = getshort(handle); // x2
1907 rec->param2 = getshort(handle); // y1
1908 rec->param1 = getshort(handle); // x1
1912 case META_INTERSECTCLIPRECT
:
1915 rec->param4 = getshort(handle); // m_y2
1916 rec->param3 = getshort(handle); // x2
1917 rec->param2 = getshort(handle); // y1
1918 rec->param1 = getshort(handle); // x1
1922 // case META_ARC: // DO!!!
1925 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_ELLIPSE
,
1926 (double)record
->param1
, (double)record
->param2
,
1927 (double)(record
->param3
- record
->param1
),
1928 (double)(record
->param4
- record
->param2
));
1932 // case META_FLOODFILL:
1933 // case META_PIE: // DO!!!
1934 case META_RECTANGLE
:
1936 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_RECT
,
1937 (double)record
->param1
, (double)record
->param2
,
1938 (double)(record
->param3
- record
->param1
),
1939 (double)(record
->param4
- record
->param2
));
1943 case META_ROUNDRECT
:
1945 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_ROUNDED_RECT
,
1946 (double)record
->param1
, (double)record
->param2
,
1947 (double)(record
->param3
- record
->param1
),
1948 (double)(record
->param4
- record
->param2
), (double)record
->param5
);
1952 // case META_PATBLT:
1953 // case META_SAVEDC:
1956 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_POINT
,
1957 (double)record
->param1
, (double)record
->param2
,
1960 // SHOULD SET THE COLOUR - SET PEN?
1961 // rec->param3 = getint(handle); // COLORREF
1965 // case META_OFFSETCLIPRGN:
1968 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_TEXT
,
1969 (double)record
->param1
, (double)record
->param2
,
1970 0.0, 0.0, 0.0, record
->stringParam
);
1974 // case META_BITBLT:
1975 // case META_STRETCHBLT:
1978 int n
= (int)record
->param1
;
1979 wxRealPoint
*newPoints
= new wxRealPoint
[n
];
1980 for (int i
= 0; i
< n
; i
++)
1982 newPoints
[i
].x
= record
->points
[i
].x
;
1983 newPoints
[i
].y
= record
->points
[i
].y
;
1986 wxOpPolyDraw
*op
= new wxOpPolyDraw(DRAWOP_DRAW_POLYGON
, n
, newPoints
);
1992 int n
= (int)record
->param1
;
1993 wxRealPoint
*newPoints
= new wxRealPoint
[n
];
1994 for (int i
= 0; i
< n
; i
++)
1996 newPoints
[i
].x
= record
->points
[i
].x
;
1997 newPoints
[i
].y
= record
->points
[i
].y
;
2000 wxOpPolyDraw
*op
= new wxOpPolyDraw(DRAWOP_DRAW_POLYLINE
, n
, newPoints
);
2004 // case META_ESCAPE:
2005 // case META_RESTOREDC:
2006 // case META_FILLREGION:
2007 // case META_FRAMEREGION:
2008 // case META_INVERTREGION:
2009 // case META_PAINTREGION:
2010 // case META_SELECTCLIPREGION: // DO THIS!
2011 case META_SELECTOBJECT
:
2013 // The pen, brush etc. has already been created when the metafile
2014 // was read in, so we don't create it - we set it.
2015 wxNode
*recNode
= metaFile
->gdiObjects
.Nth((int)record
->param2
);
2018 wxMetaRecord
*gdiRec
= (wxMetaRecord
*)recNode
->Data();
2019 if (gdiRec
&& (gdiRec
->param1
!= 0))
2021 wxObject
*obj
= (wxObject
*)gdiRec
->param1
;
2022 if (obj
->IsKindOf(CLASSINFO(wxPen
)))
2024 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_PEN
, this, (int)record
->param2
);
2027 else if (obj
->IsKindOf(CLASSINFO(wxBrush
)))
2029 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_BRUSH
, this, (int)record
->param2
);
2032 else if (obj
->IsKindOf(CLASSINFO(wxFont
)))
2034 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_FONT
, this, (int)record
->param2
);
2041 // case META_SETTEXTALIGN:
2042 // case META_DRAWTEXT:
2044 // case META_SETMAPPERFLAGS:
2045 // case META_EXTTEXTOUT:
2046 // case META_SETDIBTODEV:
2047 // case META_SELECTPALETTE:
2048 // case META_REALIZEPALETTE:
2049 // case META_ANIMATEPALETTE:
2050 // case META_SETPALENTRIES:
2051 // case META_POLYPOLYGON:
2052 // case META_RESIZEPALETTE:
2053 // case META_DIBBITBLT:
2054 // case META_DIBSTRETCHBLT:
2055 case META_DIBCREATEPATTERNBRUSH
:
2058 m_gdiObjects
.Append(NULL
);
2061 // case META_STRETCHDIB:
2062 // case META_EXTFLOODFILL:
2063 // case META_RESETDC:
2064 // case META_STARTDOC:
2065 // case META_STARTPAGE:
2066 // case META_ENDPAGE:
2067 // case META_ABORTDOC:
2068 // case META_ENDDOC:
2069 // case META_DELETEOBJECT: // DO!!
2070 case META_CREATEPALETTE
:
2073 m_gdiObjects
.Append(NULL
);
2076 case META_CREATEBRUSH
:
2079 m_gdiObjects
.Append(NULL
);
2082 case META_CREATEPATTERNBRUSH
:
2085 m_gdiObjects
.Append(NULL
);
2088 case META_CREATEPENINDIRECT
:
2090 // The pen is created when the metafile is read in.
2091 // We keep track of all the GDI objects needed for this
2092 // image so when reading the wxDrawnShape from file,
2093 // we can read in all the GDI objects, then refer
2094 // to them by an index starting from zero thereafter.
2095 m_gdiObjects
.Append((wxObject
*)record
->param1
);
2098 case META_CREATEFONTINDIRECT
:
2100 m_gdiObjects
.Append((wxObject
*)record
->param1
);
2103 case META_CREATEBRUSHINDIRECT
:
2105 // Don't have to do anything here: the pen is created
2106 // when the metafile is read in.
2107 m_gdiObjects
.Append((wxObject
*)record
->param1
);
2110 case META_CREATEBITMAPINDIRECT
:
2113 m_gdiObjects
.Append(NULL
);
2116 case META_CREATEBITMAP
:
2119 m_gdiObjects
.Append(NULL
);
2122 case META_CREATEREGION
:
2125 m_gdiObjects
.Append(NULL
);
2133 node
= node
->Next();
2135 double actualWidth
= (double)fabs(metaFile
->right
- metaFile
->left
);
2136 double actualHeight
= (double)fabs(metaFile
->bottom
- metaFile
->top
);
2138 double initialScaleX
= 1.0;
2139 double initialScaleY
= 1.0;
2141 double xoffset
, yoffset
;
2143 // Translate so origin is at centre of rectangle
2144 if (metaFile
->bottom
> metaFile
->top
)
2145 yoffset
= - (double)((metaFile
->bottom
- metaFile
->top
)/2.0);
2147 yoffset
= - (double)((metaFile
->top
- metaFile
->bottom
)/2.0);
2149 if (metaFile
->right
> metaFile
->left
)
2150 xoffset
= - (double)((metaFile
->right
- metaFile
->left
)/2.0);
2152 xoffset
= - (double)((metaFile
->left
- metaFile
->right
)/2.0);
2154 Translate(xoffset
, yoffset
);
2156 // Scale to a reasonable size (take the width of this wxDrawnShape
2158 if (actualWidth
!= 0.0)
2160 initialScaleX
= (double)((*rwidth
) / actualWidth
);
2161 initialScaleY
= initialScaleX
;
2162 (*rheight
) = initialScaleY
*actualHeight
;
2164 Scale(initialScaleX
, initialScaleY
);
2166 m_width
= (actualWidth
*initialScaleX
);
2167 m_height
= *rheight
;
2173 // Scale to fit size
2174 void wxPseudoMetaFile::ScaleTo(double w
, double h
)
2176 double scaleX
= (double)(w
/m_width
);
2177 double scaleY
= (double)(h
/m_height
);
2180 Scale(scaleX
, scaleY
);
2183 void wxPseudoMetaFile::GetBounds(double *boundMinX
, double *boundMinY
, double *boundMaxX
, double *boundMaxY
)
2185 double maxX
= (double) -99999.9;
2186 double maxY
= (double) -99999.9;
2187 double minX
= (double) 99999.9;
2188 double minY
= (double) 99999.9;
2190 wxNode
*node
= m_ops
.First();
2193 wxDrawOp
*op
= (wxDrawOp
*)node
->Data();
2194 switch (op
->GetOp())
2196 case DRAWOP_DRAW_LINE
:
2197 case DRAWOP_DRAW_RECT
:
2198 case DRAWOP_DRAW_ROUNDED_RECT
:
2199 case DRAWOP_DRAW_ELLIPSE
:
2200 case DRAWOP_DRAW_POINT
:
2201 case DRAWOP_DRAW_TEXT
:
2203 wxOpDraw
*opDraw
= (wxOpDraw
*)op
;
2204 if (opDraw
->m_x1
< minX
) minX
= opDraw
->m_x1
;
2205 if (opDraw
->m_x1
> maxX
) maxX
= opDraw
->m_x1
;
2206 if (opDraw
->m_y1
< minY
) minY
= opDraw
->m_y1
;
2207 if (opDraw
->m_y1
> maxY
) maxY
= opDraw
->m_y1
;
2208 if (op
->GetOp() == DRAWOP_DRAW_LINE
)
2210 if (opDraw
->m_x2
< minX
) minX
= opDraw
->m_x2
;
2211 if (opDraw
->m_x2
> maxX
) maxX
= opDraw
->m_x2
;
2212 if (opDraw
->m_y2
< minY
) minY
= opDraw
->m_y2
;
2213 if (opDraw
->m_y2
> maxY
) maxY
= opDraw
->m_y2
;
2215 else if (op
->GetOp() == DRAWOP_DRAW_RECT
||
2216 op
->GetOp() == DRAWOP_DRAW_ROUNDED_RECT
||
2217 op
->GetOp() == DRAWOP_DRAW_ELLIPSE
)
2219 if ((opDraw
->m_x1
+ opDraw
->m_x2
) < minX
) minX
= (opDraw
->m_x1
+ opDraw
->m_x2
);
2220 if ((opDraw
->m_x1
+ opDraw
->m_x2
) > maxX
) maxX
= (opDraw
->m_x1
+ opDraw
->m_x2
);
2221 if ((opDraw
->m_y1
+ opDraw
->m_y2
) < minY
) minY
= (opDraw
->m_y1
+ opDraw
->m_y2
);
2222 if ((opDraw
->m_y1
+ opDraw
->m_y2
) > maxY
) maxY
= (opDraw
->m_y1
+ opDraw
->m_y2
);
2226 case DRAWOP_DRAW_ARC
:
2228 // TODO: don't yet know how to calculate the bounding box
2229 // for an arc. So pretend it's a line; to get a correct
2230 // bounding box, draw a blank rectangle first, of the correct
2232 wxOpDraw
*opDraw
= (wxOpDraw
*)op
;
2233 if (opDraw
->m_x1
< minX
) minX
= opDraw
->m_x1
;
2234 if (opDraw
->m_x1
> maxX
) maxX
= opDraw
->m_x1
;
2235 if (opDraw
->m_y1
< minY
) minY
= opDraw
->m_y1
;
2236 if (opDraw
->m_y1
> maxY
) maxY
= opDraw
->m_y1
;
2237 if (opDraw
->m_x2
< minX
) minX
= opDraw
->m_x2
;
2238 if (opDraw
->m_x2
> maxX
) maxX
= opDraw
->m_x2
;
2239 if (opDraw
->m_y2
< minY
) minY
= opDraw
->m_y2
;
2240 if (opDraw
->m_y2
> maxY
) maxY
= opDraw
->m_y2
;
2243 case DRAWOP_DRAW_POLYLINE
:
2244 case DRAWOP_DRAW_POLYGON
:
2245 case DRAWOP_DRAW_SPLINE
:
2247 wxOpPolyDraw
*poly
= (wxOpPolyDraw
*)op
;
2248 for (int i
= 0; i
< poly
->m_noPoints
; i
++)
2250 if (poly
->m_points
[i
].x
< minX
) minX
= poly
->m_points
[i
].x
;
2251 if (poly
->m_points
[i
].x
> maxX
) maxX
= poly
->m_points
[i
].x
;
2252 if (poly
->m_points
[i
].y
< minY
) minY
= poly
->m_points
[i
].y
;
2253 if (poly
->m_points
[i
].y
> maxY
) maxY
= poly
->m_points
[i
].y
;
2260 node
= node
->Next();
2268 *w = (double)fabs(maxX - minX);
2269 *h = (double)fabs(maxY - minY);
2273 // Calculate size from current operations
2274 void wxPseudoMetaFile::CalculateSize(wxDrawnShape
* shape
)
2276 double boundMinX
, boundMinY
, boundMaxX
, boundMaxY
;
2278 GetBounds(& boundMinX
, & boundMinY
, & boundMaxX
, & boundMaxY
);
2280 SetSize(boundMaxX
- boundMinX
, boundMaxY
- boundMinY
);
2284 shape
->SetWidth(m_width
);
2285 shape
->SetHeight(m_height
);
2289 // Set of functions for drawing into a pseudo metafile.
2290 // They use integers, but doubles are used internally for accuracy
2293 void wxPseudoMetaFile::DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
)
2295 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_LINE
,
2296 (double) pt1
.x
, (double) pt1
.y
, (double) pt2
.x
, (double) pt2
.y
);
2298 m_ops
.Append(theOp
);
2301 void wxPseudoMetaFile::DrawRectangle(const wxRect
& rect
)
2303 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_RECT
,
2304 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2306 m_ops
.Append(theOp
);
2309 void wxPseudoMetaFile::DrawRoundedRectangle(const wxRect
& rect
, double radius
)
2311 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_ROUNDED_RECT
,
2312 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2314 theOp
->m_radius
= radius
;
2316 m_ops
.Append(theOp
);
2319 void wxPseudoMetaFile::DrawEllipse(const wxRect
& rect
)
2321 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_ELLIPSE
,
2322 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2324 m_ops
.Append(theOp
);
2327 void wxPseudoMetaFile::DrawArc(const wxPoint
& centrePt
, const wxPoint
& startPt
, const wxPoint
& endPt
)
2329 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_ARC
,
2330 (double) centrePt
.x
, (double) centrePt
.y
, (double) startPt
.x
, (double) startPt
.y
);
2332 theOp
->m_x3
= (double) endPt
.x
;
2333 theOp
->m_y3
= (double) endPt
.y
;
2335 m_ops
.Append(theOp
);
2338 void wxPseudoMetaFile::DrawEllipticArc(const wxRect
& rect
, double startAngle
, double endAngle
)
2340 const double pi
= 3.1415926535897932384626433832795 ;
2342 double startAngleRadians
= startAngle
* (pi
*2.0/360.0);
2343 double endAngleRadians
= endAngle
* (pi
*2.0/360.0);
2345 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_ELLIPTIC_ARC
,
2346 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2348 theOp
->m_x3
= startAngleRadians
;
2349 theOp
->m_y3
= endAngleRadians
;
2351 m_ops
.Append(theOp
);
2354 void wxPseudoMetaFile::DrawPoint(const wxPoint
& pt
)
2356 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_POINT
,
2357 (double) pt
.x
, (double) pt
.y
, 0.0, 0.0);
2359 m_ops
.Append(theOp
);
2362 void wxPseudoMetaFile::DrawText(const wxString
& text
, const wxPoint
& pt
)
2364 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_TEXT
,
2365 (double) pt
.x
, (double) pt
.y
, 0.0, 0.0);
2367 theOp
->m_textString
= copystring(text
);
2369 m_ops
.Append(theOp
);
2372 void wxPseudoMetaFile::DrawLines(int n
, wxPoint pts
[])
2374 wxRealPoint
* realPoints
= new wxRealPoint
[n
];
2376 for (i
= 0; i
< n
; i
++)
2378 realPoints
[i
].x
= pts
[i
].x
;
2379 realPoints
[i
].y
= pts
[i
].y
;
2381 wxOpPolyDraw
* theOp
= new wxOpPolyDraw(DRAWOP_DRAW_POLYLINE
, n
, realPoints
);
2382 m_ops
.Append(theOp
);
2385 void wxPseudoMetaFile::DrawPolygon(int n
, wxPoint pts
[], int flags
)
2387 wxRealPoint
* realPoints
= new wxRealPoint
[n
];
2389 for (i
= 0; i
< n
; i
++)
2391 realPoints
[i
].x
= pts
[i
].x
;
2392 realPoints
[i
].y
= pts
[i
].y
;
2394 wxOpPolyDraw
* theOp
= new wxOpPolyDraw(DRAWOP_DRAW_POLYGON
, n
, realPoints
);
2395 m_ops
.Append(theOp
);
2397 if (flags
& oglMETAFLAGS_OUTLINE
)
2398 m_outlineOp
= (m_ops
.Number() - 1);
2401 void wxPseudoMetaFile::DrawSpline(int n
, wxPoint pts
[])
2403 wxRealPoint
* realPoints
= new wxRealPoint
[n
];
2405 for (i
= 0; i
< n
; i
++)
2407 realPoints
[i
].x
= pts
[i
].x
;
2408 realPoints
[i
].y
= pts
[i
].y
;
2410 wxOpPolyDraw
* theOp
= new wxOpPolyDraw(DRAWOP_DRAW_SPLINE
, n
, realPoints
);
2411 m_ops
.Append(theOp
);
2414 void wxPseudoMetaFile::SetClippingRect(const wxRect
& rect
)
2416 wxOpSetClipping
* theOp
= new wxOpSetClipping(DRAWOP_SET_CLIPPING_RECT
,
2417 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2420 void wxPseudoMetaFile::DestroyClippingRect()
2422 wxOpSetClipping
* theOp
= new wxOpSetClipping(DRAWOP_DESTROY_CLIPPING_RECT
,
2423 0.0, 0.0, 0.0, 0.0);
2425 m_ops
.Append(theOp
);
2428 void wxPseudoMetaFile::SetPen(wxPen
* pen
, bool isOutline
)
2430 m_gdiObjects
.Append(pen
);
2431 int n
= m_gdiObjects
.Number();
2433 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_PEN
, this, n
- 1);
2435 m_ops
.Append(theOp
);
2439 m_outlineColours
.Append((wxObject
*) (n
- 1));
2443 void wxPseudoMetaFile::SetBrush(wxBrush
* brush
, bool isFill
)
2445 m_gdiObjects
.Append(brush
);
2446 int n
= m_gdiObjects
.Number();
2448 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_BRUSH
, this, n
- 1);
2450 m_ops
.Append(theOp
);
2454 m_fillColours
.Append((wxObject
*) (n
- 1));
2458 void wxPseudoMetaFile::SetFont(wxFont
* font
)
2460 m_gdiObjects
.Append(font
);
2461 int n
= m_gdiObjects
.Number();
2463 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_FONT
, this, n
- 1);
2465 m_ops
.Append(theOp
);
2468 void wxPseudoMetaFile::SetTextColour(const wxColour
& colour
)
2470 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_TEXT_COLOUR
, this, 0);
2471 theOp
->m_r
= colour
.Red();
2472 theOp
->m_g
= colour
.Green();
2473 theOp
->m_b
= colour
.Blue();
2475 m_ops
.Append(theOp
);
2478 void wxPseudoMetaFile::SetBackgroundColour(const wxColour
& colour
)
2480 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_BK_COLOUR
, this, 0);
2481 theOp
->m_r
= colour
.Red();
2482 theOp
->m_g
= colour
.Green();
2483 theOp
->m_b
= colour
.Blue();
2485 m_ops
.Append(theOp
);
2488 void wxPseudoMetaFile::SetBackgroundMode(int mode
)
2490 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_BK_MODE
, this, 0, mode
);
2492 m_ops
.Append(theOp
);