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"
35 static void IntToHex(unsigned int dec
, wxChar
*buf
);
36 static unsigned long HexToInt(wxChar
*buf
);
39 extern wxChar
*oglBuffer
;
42 #define gyTYPE_BRUSH 41
43 #define gyTYPE_FONT 42
50 IMPLEMENT_DYNAMIC_CLASS(wxDrawnShape
, wxRectangleShape
)
52 wxDrawnShape::wxDrawnShape():wxRectangleShape(100.0, 50.0)
55 m_currentAngle
= oglDRAWN_ANGLE_0
;
58 wxDrawnShape::~wxDrawnShape()
62 void wxDrawnShape::OnDraw(wxDC
& dc
)
64 // Pass pen and brush in case we have force outline
66 if (m_shadowMode
!= SHADOW_NONE
)
69 m_metafiles
[m_currentAngle
].m_fillBrush
= m_shadowBrush
;
70 m_metafiles
[m_currentAngle
].m_outlinePen
= g_oglTransparentPen
;
71 m_metafiles
[m_currentAngle
].Draw(dc
, m_xpos
+ m_shadowOffsetX
, m_ypos
+ m_shadowOffsetY
);
74 m_metafiles
[m_currentAngle
].m_outlinePen
= m_pen
;
75 m_metafiles
[m_currentAngle
].m_fillBrush
= m_brush
;
76 m_metafiles
[m_currentAngle
].Draw(dc
, m_xpos
, m_ypos
);
79 void wxDrawnShape::SetSize(double w
, double h
, bool WXUNUSED(recursive
))
81 SetAttachmentSize(w
, h
);
85 if (GetWidth() == 0.0)
87 else scaleX
= w
/GetWidth();
88 if (GetHeight() == 0.0)
90 else scaleY
= h
/GetHeight();
92 for (int i
= 0; i
< 4; i
++)
94 if (m_metafiles
[i
].IsValid())
95 m_metafiles
[i
].Scale(scaleX
, scaleY
);
99 SetDefaultRegionSize();
102 void wxDrawnShape::Scale(double sx
, double sy
)
105 for (i
= 0; i
< 4; i
++)
107 if (m_metafiles
[i
].IsValid())
109 m_metafiles
[i
].Scale(sx
, sy
);
110 m_metafiles
[i
].CalculateSize(this);
115 void wxDrawnShape::Translate(double x
, double y
)
118 for (i
= 0; i
< 4; i
++)
120 if (m_metafiles
[i
].IsValid())
122 m_metafiles
[i
].Translate(x
, y
);
123 m_metafiles
[i
].CalculateSize(this);
128 // theta is absolute rotation from the zero position
129 void wxDrawnShape::Rotate(double x
, double y
, double theta
)
131 m_currentAngle
= DetermineMetaFile(theta
);
133 if (m_currentAngle
== 0)
136 if (!m_metafiles
[0].GetRotateable())
139 m_metafiles
[0].Rotate(x
, y
, theta
);
142 double actualTheta
= theta
-m_rotation
;
144 // Rotate attachment points
145 double sinTheta
= (double)sin(actualTheta
);
146 double cosTheta
= (double)cos(actualTheta
);
147 wxNode
*node
= m_attachmentPoints
.GetFirst();
150 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->GetData();
151 double x1
= point
->m_x
;
152 double y1
= point
->m_y
;
153 point
->m_x
= x1
*cosTheta
- y1
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
154 point
->m_y
= x1
*sinTheta
+ y1
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
155 node
= node
->GetNext();
159 m_metafiles
[m_currentAngle
].CalculateSize(this);
162 // Which metafile do we use now? Based on current rotation and validity
165 int wxDrawnShape::DetermineMetaFile(double rotation
)
167 double tolerance
= 0.0001;
168 const double pi
= M_PI
;
170 double angle2
= pi
/2.0;
172 double angle4
= 3.0*pi
/2.0;
174 int whichMetafile
= 0;
176 if (oglRoughlyEqual(rotation
, angle1
, tolerance
))
180 else if (oglRoughlyEqual(rotation
, angle2
, tolerance
))
184 else if (oglRoughlyEqual(rotation
, angle3
, tolerance
))
188 else if (oglRoughlyEqual(rotation
, angle4
, tolerance
))
193 if ((whichMetafile
> 0) && !m_metafiles
[whichMetafile
].IsValid())
196 return whichMetafile
;
199 void wxDrawnShape::OnDrawOutline(wxDC
& dc
, double x
, double y
, double w
, double h
)
201 if (m_metafiles
[m_currentAngle
].GetOutlineOp() != -1)
203 wxNode
* node
= m_metafiles
[m_currentAngle
].GetOps().Item(m_metafiles
[m_currentAngle
].GetOutlineOp());
204 wxASSERT (node
!= NULL
);
205 wxDrawOp
* op
= (wxDrawOp
*) node
->GetData();
207 if (op
->OnDrawOutline(dc
, x
, y
, w
, h
, m_width
, m_height
))
211 // Default... just use a rectangle
212 wxRectangleShape::OnDrawOutline(dc
, x
, y
, w
, h
);
215 // Get the perimeter point using the special outline op, if there is one,
216 // otherwise use default wxRectangleShape scheme
217 bool wxDrawnShape::GetPerimeterPoint(double x1
, double y1
,
218 double x2
, double y2
,
219 double *x3
, double *y3
)
221 if (m_metafiles
[m_currentAngle
].GetOutlineOp() != -1)
223 wxNode
* node
= m_metafiles
[m_currentAngle
].GetOps().Item(m_metafiles
[m_currentAngle
].GetOutlineOp());
224 wxASSERT (node
!= NULL
);
225 wxDrawOp
* op
= (wxDrawOp
*) node
->GetData();
227 if (op
->GetPerimeterPoint(x1
, y1
, x2
, y2
, x3
, y3
, GetX(), GetY(), GetAttachmentMode()))
231 // Default... just use a rectangle
232 return wxRectangleShape::GetPerimeterPoint(x1
, y1
, x2
, y2
, x3
, y3
);
236 void wxDrawnShape::WriteAttributes(wxExpr
*clause
)
238 wxRectangleShape::WriteAttributes(clause
);
240 clause
->AddAttributeValue(_T("current_angle"), (long)m_currentAngle
);
241 clause
->AddAttributeValue(_T("save_metafile"), (long)m_saveToFile
);
244 for (int i
= 0; i
< 4; i
++)
246 if (m_metafiles
[i
].IsValid())
247 m_metafiles
[i
].WriteAttributes(clause
, i
);
252 void wxDrawnShape::ReadAttributes(wxExpr
*clause
)
254 wxRectangleShape::ReadAttributes(clause
);
256 int iVal
= (int) m_saveToFile
;
257 clause
->GetAttributeValue(_T("save_metafile"), iVal
);
258 clause
->GetAttributeValue(_T("current_angle"), m_currentAngle
);
259 m_saveToFile
= (iVal
!= 0);
263 for (int i
= 0; i
< 4; i
++)
265 m_metafiles
[i
].ReadAttributes(clause
, i
);
271 // Does the copying for this object
272 void wxDrawnShape::Copy(wxShape
& copy
)
274 wxRectangleShape::Copy(copy
);
276 wxASSERT( copy
.IsKindOf(CLASSINFO(wxDrawnShape
)) ) ;
278 wxDrawnShape
& drawnCopy
= (wxDrawnShape
&) copy
;
280 for (int i
= 0; i
< 4; i
++)
282 m_metafiles
[i
].Copy(drawnCopy
.m_metafiles
[i
]);
284 drawnCopy
.m_saveToFile
= m_saveToFile
;
285 drawnCopy
.m_currentAngle
= m_currentAngle
;
288 bool wxDrawnShape::LoadFromMetaFile(const wxString
& filename
)
290 return m_metafiles
[0].LoadFromMetaFile(filename
, &m_width
, &m_height
);
293 // Set of functions for drawing into a pseudo metafile.
294 // They use integers, but doubles are used internally for accuracy
297 void wxDrawnShape::DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
)
299 m_metafiles
[m_currentAngle
].DrawLine(pt1
, pt2
);
302 void wxDrawnShape::DrawRectangle(const wxRect
& rect
)
304 m_metafiles
[m_currentAngle
].DrawRectangle(rect
);
307 void wxDrawnShape::DrawRoundedRectangle(const wxRect
& rect
, double radius
)
309 m_metafiles
[m_currentAngle
].DrawRoundedRectangle(rect
, radius
);
312 void wxDrawnShape::DrawEllipse(const wxRect
& rect
)
314 m_metafiles
[m_currentAngle
].DrawEllipse(rect
);
317 void wxDrawnShape::DrawArc(const wxPoint
& centrePt
, const wxPoint
& startPt
, const wxPoint
& endPt
)
319 m_metafiles
[m_currentAngle
].DrawArc(centrePt
, startPt
, endPt
);
322 void wxDrawnShape::DrawEllipticArc(const wxRect
& rect
, double startAngle
, double endAngle
)
324 m_metafiles
[m_currentAngle
].DrawEllipticArc(rect
, startAngle
, endAngle
);
327 void wxDrawnShape::DrawPoint(const wxPoint
& pt
)
329 m_metafiles
[m_currentAngle
].DrawPoint(pt
);
332 void wxDrawnShape::DrawText(const wxString
& text
, const wxPoint
& pt
)
334 m_metafiles
[m_currentAngle
].DrawText(text
, pt
);
337 void wxDrawnShape::DrawLines(int n
, wxPoint pts
[])
339 m_metafiles
[m_currentAngle
].DrawLines(n
, pts
);
342 void wxDrawnShape::DrawPolygon(int n
, wxPoint pts
[], int flags
)
344 if (flags
& oglMETAFLAGS_ATTACHMENTS
)
348 for (i
= 0; i
< n
; i
++)
349 m_attachmentPoints
.Append(new wxAttachmentPoint(i
, pts
[i
].x
, pts
[i
].y
));
351 m_metafiles
[m_currentAngle
].DrawPolygon(n
, pts
, flags
);
354 void wxDrawnShape::DrawSpline(int n
, wxPoint pts
[])
356 m_metafiles
[m_currentAngle
].DrawSpline(n
, pts
);
359 void wxDrawnShape::SetClippingRect(const wxRect
& rect
)
361 m_metafiles
[m_currentAngle
].SetClippingRect(rect
);
364 void wxDrawnShape::DestroyClippingRect()
366 m_metafiles
[m_currentAngle
].DestroyClippingRect();
369 void wxDrawnShape::SetDrawnPen(wxPen
* pen
, bool isOutline
)
371 m_metafiles
[m_currentAngle
].SetPen(pen
, isOutline
);
374 void wxDrawnShape::SetDrawnBrush(wxBrush
* brush
, bool isFill
)
376 m_metafiles
[m_currentAngle
].SetBrush(brush
, isFill
);
379 void wxDrawnShape::SetDrawnFont(wxFont
* font
)
381 m_metafiles
[m_currentAngle
].SetFont(font
);
384 void wxDrawnShape::SetDrawnTextColour(const wxColour
& colour
)
386 m_metafiles
[m_currentAngle
].SetTextColour(colour
);
389 void wxDrawnShape::SetDrawnBackgroundColour(const wxColour
& colour
)
391 m_metafiles
[m_currentAngle
].SetBackgroundColour(colour
);
394 void wxDrawnShape::SetDrawnBackgroundMode(int mode
)
396 m_metafiles
[m_currentAngle
].SetBackgroundMode(mode
);
401 * Individual operations
406 * Set font, brush, text colour
410 wxOpSetGDI::wxOpSetGDI(int theOp
, wxPseudoMetaFile
*theImage
, int theGdiIndex
, int theMode
):
413 m_gdiIndex
= theGdiIndex
;
418 void wxOpSetGDI::Do(wxDC
& dc
, double WXUNUSED(xoffset
), double WXUNUSED(yoffset
))
424 // Check for overriding this operation for outline
426 if (m_image
->m_outlineColours
.Member((wxObject
*)m_gdiIndex
))
428 if (m_image
->m_outlinePen
)
429 dc
.SetPen(* m_image
->m_outlinePen
);
433 wxNode
*node
= m_image
->m_gdiObjects
.Item(m_gdiIndex
);
436 wxPen
*pen
= (wxPen
*)node
->GetData();
443 case DRAWOP_SET_BRUSH
:
445 // Check for overriding this operation for outline or fill
447 if (m_image
->m_outlineColours
.Member((wxObject
*)m_gdiIndex
))
449 // Need to construct a brush to match the outline pen's colour
450 if (m_image
->m_outlinePen
)
452 wxBrush
*br
= wxTheBrushList
->FindOrCreateBrush(m_image
->m_outlinePen
->GetColour(), wxSOLID
);
457 else if (m_image
->m_fillColours
.Member((wxObject
*)m_gdiIndex
))
459 if (m_image
->m_fillBrush
)
461 dc
.SetBrush(* m_image
->m_fillBrush
);
466 wxNode
*node
= m_image
->m_gdiObjects
.Item(m_gdiIndex
);
469 wxBrush
*brush
= (wxBrush
*)node
->GetData();
471 dc
.SetBrush(* brush
);
476 case DRAWOP_SET_FONT
:
478 wxNode
*node
= m_image
->m_gdiObjects
.Item(m_gdiIndex
);
481 wxFont
*font
= (wxFont
*)node
->GetData();
487 case DRAWOP_SET_TEXT_COLOUR
:
489 wxColour
col(m_r
,m_g
,m_b
);
490 dc
.SetTextForeground(col
);
493 case DRAWOP_SET_BK_COLOUR
:
495 wxColour
col(m_r
,m_g
,m_b
);
496 dc
.SetTextBackground(col
);
499 case DRAWOP_SET_BK_MODE
:
501 dc
.SetBackgroundMode(m_mode
);
509 wxDrawOp
*wxOpSetGDI::Copy(wxPseudoMetaFile
*newImage
)
511 wxOpSetGDI
*newOp
= new wxOpSetGDI(m_op
, newImage
, m_gdiIndex
, m_mode
);
519 wxExpr
*wxOpSetGDI::WriteExpr(wxPseudoMetaFile
*WXUNUSED(image
))
521 wxExpr
*expr
= new wxExpr(wxExprList
);
522 expr
->Append(new wxExpr((long)m_op
));
526 case DRAWOP_SET_BRUSH
:
527 case DRAWOP_SET_FONT
:
529 expr
->Append(new wxExpr((long)m_gdiIndex
));
532 case DRAWOP_SET_TEXT_COLOUR
:
533 case DRAWOP_SET_BK_COLOUR
:
535 expr
->Append(new wxExpr((long)m_r
));
536 expr
->Append(new wxExpr((long)m_g
));
537 expr
->Append(new wxExpr((long)m_b
));
540 case DRAWOP_SET_BK_MODE
:
542 expr
->Append(new wxExpr((long)m_mode
));
551 void wxOpSetGDI::ReadExpr(wxPseudoMetaFile
*WXUNUSED(image
), wxExpr
*expr
)
556 case DRAWOP_SET_BRUSH
:
557 case DRAWOP_SET_FONT
:
559 m_gdiIndex
= (int)expr
->Nth(1)->IntegerValue();
562 case DRAWOP_SET_TEXT_COLOUR
:
563 case DRAWOP_SET_BK_COLOUR
:
565 m_r
= (unsigned char)expr
->Nth(1)->IntegerValue();
566 m_g
= (unsigned char)expr
->Nth(2)->IntegerValue();
567 m_b
= (unsigned char)expr
->Nth(3)->IntegerValue();
570 case DRAWOP_SET_BK_MODE
:
572 m_mode
= (int)expr
->Nth(1)->IntegerValue();
582 * Set/destroy clipping
586 wxOpSetClipping::wxOpSetClipping(int theOp
, double theX1
, double theY1
,
587 double theX2
, double theY2
):wxDrawOp(theOp
)
595 wxDrawOp
*wxOpSetClipping::Copy(wxPseudoMetaFile
*WXUNUSED(newImage
))
597 wxOpSetClipping
*newOp
= new wxOpSetClipping(m_op
, m_x1
, m_y1
, m_x2
, m_y2
);
601 void wxOpSetClipping::Do(wxDC
& dc
, double xoffset
, double yoffset
)
605 case DRAWOP_SET_CLIPPING_RECT
:
607 dc
.SetClippingRegion((long)(m_x1
+ xoffset
), (long)(m_y1
+ yoffset
), (long)(m_x2
+ xoffset
), (long)(m_y2
+ yoffset
));
610 case DRAWOP_DESTROY_CLIPPING_RECT
:
612 dc
.DestroyClippingRegion();
620 void wxOpSetClipping::Scale(double xScale
, double yScale
)
628 void wxOpSetClipping::Translate(double x
, double y
)
635 wxExpr
*wxOpSetClipping::WriteExpr(wxPseudoMetaFile
*WXUNUSED(image
))
637 wxExpr
*expr
= new wxExpr(wxExprList
);
638 expr
->Append(new wxExpr((long)m_op
));
641 case DRAWOP_SET_CLIPPING_RECT
:
643 expr
->Append(new wxExpr(m_x1
));
644 expr
->Append(new wxExpr(m_y1
));
645 expr
->Append(new wxExpr(m_x2
));
646 expr
->Append(new wxExpr(m_y2
));
655 void wxOpSetClipping::ReadExpr(wxPseudoMetaFile
*WXUNUSED(image
), wxExpr
*expr
)
659 case DRAWOP_SET_CLIPPING_RECT
:
661 m_x1
= expr
->Nth(1)->RealValue();
662 m_y1
= expr
->Nth(2)->RealValue();
663 m_x2
= expr
->Nth(3)->RealValue();
664 m_y2
= expr
->Nth(4)->RealValue();
674 * Draw line, rectangle, rounded rectangle, ellipse, point, arc, text
678 wxOpDraw::wxOpDraw(int theOp
, double theX1
, double theY1
, double theX2
, double theY2
,
679 double theRadius
, const wxString
& s
) : wxDrawOp(theOp
)
687 m_radius
= theRadius
;
691 wxOpDraw::~wxOpDraw()
695 wxDrawOp
*wxOpDraw::Copy(wxPseudoMetaFile
*WXUNUSED(newImage
))
697 wxOpDraw
*newOp
= new wxOpDraw(m_op
, m_x1
, m_y1
, m_x2
, m_y2
, m_radius
, m_textString
);
703 void wxOpDraw::Do(wxDC
& dc
, double xoffset
, double yoffset
)
707 case DRAWOP_DRAW_LINE
:
709 dc
.DrawLine(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
), WXROUND(m_x2
+xoffset
), WXROUND(m_y2
+yoffset
));
712 case DRAWOP_DRAW_RECT
:
714 dc
.DrawRectangle(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
), WXROUND(m_x2
), WXROUND(m_y2
));
717 case DRAWOP_DRAW_ROUNDED_RECT
:
719 dc
.DrawRoundedRectangle(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
), WXROUND(m_x2
), WXROUND(m_y2
), m_radius
);
722 case DRAWOP_DRAW_ELLIPSE
:
724 dc
.DrawEllipse(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
), WXROUND(m_x2
), WXROUND(m_y2
));
727 case DRAWOP_DRAW_ARC
:
729 dc
.DrawArc(WXROUND(m_x2
+xoffset
), WXROUND(m_y2
+yoffset
),
730 WXROUND(m_x3
+xoffset
), WXROUND(m_y3
+yoffset
),
731 WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
));
734 case DRAWOP_DRAW_ELLIPTIC_ARC
:
736 const double pi
= M_PI
;
738 // Convert back to degrees
740 WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
),
741 WXROUND(m_x2
), WXROUND(m_y2
),
742 WXROUND(m_x3
*(360.0/(2.0*pi
))), WXROUND(m_y3
*(360.0/(2.0*pi
))));
745 case DRAWOP_DRAW_POINT
:
747 dc
.DrawPoint(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
));
750 case DRAWOP_DRAW_TEXT
:
752 dc
.DrawText(m_textString
, WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
));
760 void wxOpDraw::Scale(double scaleX
, double scaleY
)
767 if (m_op
!= DRAWOP_DRAW_ELLIPTIC_ARC
)
776 void wxOpDraw::Translate(double x
, double y
)
783 case DRAWOP_DRAW_LINE
:
789 case DRAWOP_DRAW_ARC
:
797 case DRAWOP_DRAW_ELLIPTIC_ARC
:
806 void wxOpDraw::Rotate(double x
, double y
, double theta
, double sinTheta
, double cosTheta
)
808 double newX1
= m_x1
*cosTheta
- m_y1
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
809 double newY1
= m_x1
*sinTheta
+ m_y1
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
813 case DRAWOP_DRAW_LINE
:
815 double newX2
= m_x2
*cosTheta
- m_y2
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
816 double newY2
= m_x2
*sinTheta
+ m_y2
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
824 case DRAWOP_DRAW_RECT
:
825 case DRAWOP_DRAW_ROUNDED_RECT
:
826 case DRAWOP_DRAW_ELLIPTIC_ARC
:
828 // Assume only 0, 90, 180, 270 degree rotations.
829 // oldX1, oldY1 represents the top left corner. Find the
830 // bottom right, and rotate that. Then the width/height is the difference
831 // between x/y values.
832 double oldBottomRightX
= m_x1
+ m_x2
;
833 double oldBottomRightY
= m_y1
+ m_y2
;
834 double newBottomRightX
= oldBottomRightX
*cosTheta
- oldBottomRightY
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
835 double newBottomRightY
= oldBottomRightX
*sinTheta
+ oldBottomRightY
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
837 // Now find the new top-left, bottom-right coordinates.
838 double minX
= wxMin(newX1
, newBottomRightX
);
839 double minY
= wxMin(newY1
, newBottomRightY
);
840 double maxX
= wxMax(newX1
, newBottomRightX
);
841 double maxY
= wxMax(newY1
, newBottomRightY
);
845 m_x2
= maxX
- minX
; // width
846 m_y2
= maxY
- minY
; // height
848 if (m_op
== DRAWOP_DRAW_ELLIPTIC_ARC
)
850 // Add rotation to angles
857 case DRAWOP_DRAW_ARC
:
859 double newX2
= m_x2
*cosTheta
- m_y2
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
860 double newY2
= m_x2
*sinTheta
+ m_y2
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
861 double newX3
= m_x3
*cosTheta
- m_y3
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
862 double newY3
= m_x3
*sinTheta
+ m_y3
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
879 wxExpr
*wxOpDraw::WriteExpr(wxPseudoMetaFile
*WXUNUSED(image
))
881 wxExpr
*expr
= new wxExpr(wxExprList
);
882 expr
->Append(new wxExpr((long)m_op
));
885 case DRAWOP_DRAW_LINE
:
886 case DRAWOP_DRAW_RECT
:
887 case DRAWOP_DRAW_ELLIPSE
:
889 expr
->Append(new wxExpr(m_x1
));
890 expr
->Append(new wxExpr(m_y1
));
891 expr
->Append(new wxExpr(m_x2
));
892 expr
->Append(new wxExpr(m_y2
));
895 case DRAWOP_DRAW_ROUNDED_RECT
:
897 expr
->Append(new wxExpr(m_x1
));
898 expr
->Append(new wxExpr(m_y1
));
899 expr
->Append(new wxExpr(m_x2
));
900 expr
->Append(new wxExpr(m_y2
));
901 expr
->Append(new wxExpr(m_radius
));
904 case DRAWOP_DRAW_POINT
:
906 expr
->Append(new wxExpr(m_x1
));
907 expr
->Append(new wxExpr(m_y1
));
910 case DRAWOP_DRAW_TEXT
:
912 expr
->Append(new wxExpr(m_x1
));
913 expr
->Append(new wxExpr(m_y1
));
914 expr
->Append(new wxExpr(wxExprString
, m_textString
));
917 case DRAWOP_DRAW_ARC
:
918 case DRAWOP_DRAW_ELLIPTIC_ARC
:
920 expr
->Append(new wxExpr(m_x1
));
921 expr
->Append(new wxExpr(m_y1
));
922 expr
->Append(new wxExpr(m_x2
));
923 expr
->Append(new wxExpr(m_y2
));
924 expr
->Append(new wxExpr(m_x3
));
925 expr
->Append(new wxExpr(m_y3
));
936 void wxOpDraw::ReadExpr(wxPseudoMetaFile
*WXUNUSED(image
), wxExpr
*expr
)
940 case DRAWOP_DRAW_LINE
:
941 case DRAWOP_DRAW_RECT
:
942 case DRAWOP_DRAW_ELLIPSE
:
944 m_x1
= expr
->Nth(1)->RealValue();
945 m_y1
= expr
->Nth(2)->RealValue();
946 m_x2
= expr
->Nth(3)->RealValue();
947 m_y2
= expr
->Nth(4)->RealValue();
950 case DRAWOP_DRAW_ROUNDED_RECT
:
952 m_x1
= expr
->Nth(1)->RealValue();
953 m_y1
= expr
->Nth(2)->RealValue();
954 m_x2
= expr
->Nth(3)->RealValue();
955 m_y2
= expr
->Nth(4)->RealValue();
956 m_radius
= expr
->Nth(5)->RealValue();
959 case DRAWOP_DRAW_POINT
:
961 m_x1
= expr
->Nth(1)->RealValue();
962 m_y1
= expr
->Nth(2)->RealValue();
965 case DRAWOP_DRAW_TEXT
:
967 m_x1
= expr
->Nth(1)->RealValue();
968 m_y1
= expr
->Nth(2)->RealValue();
969 m_textString
= wxString(expr
->Nth(3)->StringValue());
972 case DRAWOP_DRAW_ARC
:
973 case DRAWOP_DRAW_ELLIPTIC_ARC
:
975 m_x1
= expr
->Nth(1)->RealValue();
976 m_y1
= expr
->Nth(2)->RealValue();
977 m_x2
= expr
->Nth(3)->RealValue();
978 m_y2
= expr
->Nth(4)->RealValue();
979 m_x3
= expr
->Nth(5)->RealValue();
980 m_y3
= expr
->Nth(6)->RealValue();
992 * Draw polygon, polyline, spline
996 wxOpPolyDraw::wxOpPolyDraw(int theOp
, int n
, wxRealPoint
*thePoints
):wxDrawOp(theOp
)
999 m_points
= thePoints
;
1002 wxOpPolyDraw::~wxOpPolyDraw()
1007 wxDrawOp
*wxOpPolyDraw::Copy(wxPseudoMetaFile
*WXUNUSED(newImage
))
1009 wxRealPoint
*newPoints
= new wxRealPoint
[m_noPoints
];
1010 for (int i
= 0; i
< m_noPoints
; i
++)
1012 newPoints
[i
].x
= m_points
[i
].x
;
1013 newPoints
[i
].y
= m_points
[i
].y
;
1015 wxOpPolyDraw
*newOp
= new wxOpPolyDraw(m_op
, m_noPoints
, newPoints
);
1019 void wxOpPolyDraw::Do(wxDC
& dc
, double xoffset
, double yoffset
)
1023 case DRAWOP_DRAW_POLYLINE
:
1025 wxPoint
*actualPoints
= new wxPoint
[m_noPoints
];
1027 for (i
= 0; i
< m_noPoints
; i
++)
1029 actualPoints
[i
].x
= WXROUND(m_points
[i
].x
);
1030 actualPoints
[i
].y
= WXROUND(m_points
[i
].y
);
1033 dc
.DrawLines(m_noPoints
, actualPoints
, WXROUND(xoffset
), WXROUND(yoffset
));
1035 delete[] actualPoints
;
1038 case DRAWOP_DRAW_POLYGON
:
1040 wxPoint
*actualPoints
= new wxPoint
[m_noPoints
];
1042 for (i
= 0; i
< m_noPoints
; i
++)
1044 actualPoints
[i
].x
= WXROUND(m_points
[i
].x
);
1045 actualPoints
[i
].y
= WXROUND(m_points
[i
].y
);
1048 dc
.DrawPolygon(m_noPoints
, actualPoints
, WXROUND(xoffset
), WXROUND(yoffset
));
1050 delete[] actualPoints
;
1053 case DRAWOP_DRAW_SPLINE
:
1055 wxPoint
*actualPoints
= new wxPoint
[m_noPoints
];
1057 for (i
= 0; i
< m_noPoints
; i
++)
1059 actualPoints
[i
].x
= WXROUND(m_points
[i
].x
);
1060 actualPoints
[i
].y
= WXROUND(m_points
[i
].y
);
1063 dc
.DrawSpline(m_noPoints
, actualPoints
); // no offsets in DrawSpline // , xoffset, yoffset);
1065 delete[] actualPoints
;
1073 void wxOpPolyDraw::Scale(double scaleX
, double scaleY
)
1075 for (int i
= 0; i
< m_noPoints
; i
++)
1077 m_points
[i
].x
*= scaleX
;
1078 m_points
[i
].y
*= scaleY
;
1082 void wxOpPolyDraw::Translate(double x
, double y
)
1084 for (int i
= 0; i
< m_noPoints
; i
++)
1091 void wxOpPolyDraw::Rotate(double x
, double y
, double WXUNUSED(theta
), double sinTheta
, double cosTheta
)
1093 for (int i
= 0; i
< m_noPoints
; i
++)
1095 double x1
= m_points
[i
].x
;
1096 double y1
= m_points
[i
].y
;
1097 m_points
[i
].x
= x1
*cosTheta
- y1
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
1098 m_points
[i
].y
= x1
*sinTheta
+ y1
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
1103 wxExpr
*wxOpPolyDraw::WriteExpr(wxPseudoMetaFile
*WXUNUSED(image
))
1105 wxExpr
*expr
= new wxExpr(wxExprList
);
1106 expr
->Append(new wxExpr((long)m_op
));
1107 expr
->Append(new wxExpr((long)m_noPoints
));
1116 * Store each coordinate pair in a hex string to save space.
1117 * E.g. "1B9080CD". 4 hex digits per coordinate pair.
1121 for (int i
= 0; i
< m_noPoints
; i
++)
1123 long signedX
= (long)(m_points
[i
].x
*100.0);
1124 long signedY
= (long)(m_points
[i
].y
*100.0);
1126 // Scale to 0 -> 64K
1127 unsigned int unSignedX
= (unsigned int)(signedX
+ 32767.0);
1128 unsigned int unSignedY
= (unsigned int)(signedY
+ 32767.0);
1130 IntToHex(unSignedX
, buf2
);
1131 IntToHex(unSignedY
, buf3
);
1133 // Don't overrun the buffer
1136 wxStrcat(oglBuffer
, buf2
);
1137 wxStrcat(oglBuffer
, buf3
);
1140 expr
->Append(new wxExpr(wxExprString
, oglBuffer
));
1144 void wxOpPolyDraw::ReadExpr(wxPseudoMetaFile
*WXUNUSED(image
), wxExpr
*expr
)
1146 m_noPoints
= (int)expr
->Nth(1)->IntegerValue();
1151 m_points
= new wxRealPoint
[m_noPoints
];
1154 wxString hexString
= expr
->Nth(2)->StringValue();
1155 while (i
< m_noPoints
)
1157 buf1
[0] = hexString
[(size_t)bufPtr
];
1158 buf1
[1] = hexString
[(size_t)(bufPtr
+ 1)];
1159 buf1
[2] = hexString
[(size_t)(bufPtr
+ 2)];
1160 buf1
[3] = hexString
[(size_t)(bufPtr
+ 3)];
1163 buf2
[0] = hexString
[(size_t)(bufPtr
+ 4)];
1164 buf2
[1] = hexString
[(size_t)(bufPtr
+ 5)];
1165 buf2
[2] = hexString
[(size_t)(bufPtr
+ 6)];
1166 buf2
[3] = hexString
[(size_t)(bufPtr
+ 7)];
1171 // int signedX = (signed int)HexToInt(buf1);
1172 // int signedY = (signed int)HexToInt(buf2);
1173 long unSignedX
= HexToInt(buf1
);
1174 long unSignedY
= HexToInt(buf2
);
1175 // Scale -32K -> +32K
1176 long signedX
= unSignedX
- 32767;
1177 long signedY
= unSignedY
- 32767;
1178 #if defined(__WXMSW__) && 0
1179 int testX
= (signed int)unSignedX
;
1180 int testY
= (signed int)unSignedY
;
1183 m_points
[i
].x
= (double)(signedX
/ 100.0);
1184 m_points
[i
].y
= (double)(signedY
/ 100.0);
1191 // Draw an outline using the current operation.
1192 bool wxOpPolyDraw::OnDrawOutline(wxDC
& dc
, double x
, double y
, double w
, double h
, double oldW
, double oldH
)
1194 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1196 // Multiply all points by proportion of new size to old size
1197 double x_proportion
= (double)(fabs(w
/oldW
));
1198 double y_proportion
= (double)(fabs(h
/oldH
));
1201 wxPoint
*intPoints
= new wxPoint
[n
];
1203 for (i
= 0; i
< n
; i
++)
1205 intPoints
[i
].x
= WXROUND (x_proportion
* m_points
[i
].x
);
1206 intPoints
[i
].y
= WXROUND (y_proportion
* m_points
[i
].y
);
1208 dc
.DrawPolygon(n
, intPoints
, (long) x
, (long) y
);
1213 // Assume (x1, y1) is centre of box (most generally, line end at box)
1214 bool wxOpPolyDraw::GetPerimeterPoint(double x1
, double y1
,
1215 double x2
, double y2
,
1216 double *x3
, double *y3
,
1217 double xOffset
, double yOffset
,
1222 // First check for situation where the line is vertical,
1223 // and we would want to connect to a point on that vertical --
1224 // oglFindEndForPolyline can't cope with this (the arrow
1225 // gets drawn to the wrong place).
1226 if ((attachmentMode
== ATTACHMENT_MODE_NONE
) && (x1
== x2
))
1228 // Look for the point we'd be connecting to. This is
1231 for (i
= 0; i
< n
; i
++)
1233 wxRealPoint
*point
= & (m_points
[i
]);
1234 if (point
->x
== 0.0)
1236 if ((y2
> y1
) && (point
->y
> 0.0))
1238 *x3
= point
->x
+ xOffset
;
1239 *y3
= point
->y
+ yOffset
;
1242 else if ((y2
< y1
) && (point
->y
< 0.0))
1244 *x3
= point
->x
+ xOffset
;
1245 *y3
= point
->y
+ yOffset
;
1252 double *xpoints
= new double[n
];
1253 double *ypoints
= new double[n
];
1255 for (int i
= 0; i
< n
; i
++)
1257 wxRealPoint
*point
= & (m_points
[i
]);
1258 xpoints
[i
] = point
->x
+ xOffset
;
1259 ypoints
[i
] = point
->y
+ yOffset
;
1262 oglFindEndForPolyline(n
, xpoints
, ypoints
,
1263 x1
, y1
, x2
, y2
, x3
, y3
);
1279 static char hexArray
[] = {
1280 _T('0'), _T('1'), _T('2'), _T('3'), _T('4'), _T('5'), _T('6'), _T('7'),
1281 _T('8'), _T('9'), _T('A'), _T('B'), _T('C'), _T('D'), _T('E'), _T('F') };
1283 // Convert unsigned 16-bit integer to 4-character hex string
1284 static void IntToHex(unsigned int dec
, wxChar
*buf
)
1286 int digit1
= (int)(dec
/4096);
1287 int digit2
= (int)((dec
- (digit1
*4096))/256);
1288 int digit3
= (int)((dec
- (digit1
*4096) - (digit2
*256))/16);
1289 int digit4
= dec
- (digit1
*4096 + digit2
*256 + digit3
*16);
1291 buf
[0] = hexArray
[digit1
];
1292 buf
[1] = hexArray
[digit2
];
1293 buf
[2] = hexArray
[digit3
];
1294 buf
[3] = hexArray
[digit4
];
1298 // One hex digit to decimal number
1299 static int HexToInt1(wxChar hex
)
1340 // 4-digit hex string to unsigned integer
1341 static unsigned long HexToInt(wxChar
*buf
)
1343 long d1
= (long)(HexToInt1(buf
[0])*4096.0) ;
1344 long d2
= (long)(HexToInt1(buf
[1])*256.0) ;
1345 long d3
= (long)(HexToInt1(buf
[2])*16.0) ;
1346 long d4
= (long)(HexToInt1(buf
[3])) ;
1347 unsigned long n
= (long)(d1
+ d2
+ d3
+ d4
) ;
1351 #endif // wxUSE_PROLOGIO
1354 * wxPseudo meta-file
1358 IMPLEMENT_DYNAMIC_CLASS(wxPseudoMetaFile
, wxObject
)
1360 wxPseudoMetaFile::wxPseudoMetaFile()
1362 m_currentRotation
= 0;
1363 m_rotateable
= true;
1366 m_outlinePen
= NULL
;
1371 wxPseudoMetaFile::wxPseudoMetaFile(wxPseudoMetaFile
& mf
):wxObject()
1376 wxPseudoMetaFile::~wxPseudoMetaFile()
1381 void wxPseudoMetaFile::Clear()
1383 wxNode
*node
= m_ops
.GetFirst();
1386 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1388 node
= node
->GetNext();
1391 m_gdiObjects
.Clear();
1392 m_outlineColours
.Clear();
1393 m_fillColours
.Clear();
1397 void wxPseudoMetaFile::Draw(wxDC
& dc
, double xoffset
, double yoffset
)
1399 wxNode
*node
= m_ops
.GetFirst();
1402 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1403 op
->Do(dc
, xoffset
, yoffset
);
1404 node
= node
->GetNext();
1408 void wxPseudoMetaFile::Scale(double sx
, double sy
)
1410 wxNode
*node
= m_ops
.GetFirst();
1413 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1415 node
= node
->GetNext();
1421 void wxPseudoMetaFile::Translate(double x
, double y
)
1423 wxNode
*node
= m_ops
.GetFirst();
1426 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1427 op
->Translate(x
, y
);
1428 node
= node
->GetNext();
1432 void wxPseudoMetaFile::Rotate(double x
, double y
, double theta
)
1434 double theta1
= theta
-m_currentRotation
;
1435 if (theta1
== 0.0) return;
1436 double cosTheta
= (double)cos(theta1
);
1437 double sinTheta
= (double)sin(theta1
);
1439 wxNode
*node
= m_ops
.GetFirst();
1442 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1443 op
->Rotate(x
, y
, theta
, sinTheta
, cosTheta
);
1444 node
= node
->GetNext();
1446 m_currentRotation
= theta
;
1450 void wxPseudoMetaFile::WriteAttributes(wxExpr
*clause
, int whichAngle
)
1453 widthStr
.Printf(wxT("meta_width%d"), whichAngle
);
1456 heightStr
.Printf(wxT("meta_height%d"), whichAngle
);
1458 wxString outlineStr
;
1459 outlineStr
.Printf(wxT("outline_op%d"), whichAngle
);
1461 wxString rotateableStr
;
1462 rotateableStr
.Printf(wxT("meta_rotateable%d"), whichAngle
);
1464 // Write width and height
1465 clause
->AddAttributeValue(widthStr
, m_width
);
1466 clause
->AddAttributeValue(heightStr
, m_height
);
1467 clause
->AddAttributeValue(rotateableStr
, (long)m_rotateable
);
1468 clause
->AddAttributeValue(outlineStr
, (long)m_outlineOp
);
1470 // Write GDI objects
1473 wxNode
*node
= m_gdiObjects
.GetFirst();
1476 wxSprintf(buf
, _T("gdi%d_%d"), whichAngle
, i
);
1477 wxObject
*obj
= (wxObject
*)node
->GetData();
1478 wxExpr
*expr
= NULL
;
1481 if (obj
->IsKindOf(CLASSINFO(wxPen
)))
1483 wxPen
*thePen
= (wxPen
*)obj
;
1484 expr
= new wxExpr(wxExprList
);
1485 expr
->Append(new wxExpr((long)gyTYPE_PEN
));
1486 expr
->Append(new wxExpr((long)thePen
->GetWidth()));
1487 expr
->Append(new wxExpr((long)thePen
->GetStyle()));
1488 expr
->Append(new wxExpr((long)thePen
->GetColour().Red()));
1489 expr
->Append(new wxExpr((long)thePen
->GetColour().Green()));
1490 expr
->Append(new wxExpr((long)thePen
->GetColour().Blue()));
1492 else if (obj
->IsKindOf(CLASSINFO(wxBrush
)))
1494 wxBrush
*theBrush
= (wxBrush
*)obj
;
1495 expr
= new wxExpr(wxExprList
);
1496 expr
->Append(new wxExpr((long)gyTYPE_BRUSH
));
1497 expr
->Append(new wxExpr((long)theBrush
->GetStyle()));
1498 expr
->Append(new wxExpr((long)theBrush
->GetColour().Red()));
1499 expr
->Append(new wxExpr((long)theBrush
->GetColour().Green()));
1500 expr
->Append(new wxExpr((long)theBrush
->GetColour().Blue()));
1502 else if (obj
->IsKindOf(CLASSINFO(wxFont
)))
1504 wxFont
*theFont
= (wxFont
*)obj
;
1505 expr
= new wxExpr(wxExprList
);
1506 expr
->Append(new wxExpr((long)gyTYPE_FONT
));
1507 expr
->Append(new wxExpr((long)theFont
->GetPointSize()));
1508 expr
->Append(new wxExpr((long)theFont
->GetFamily()));
1509 expr
->Append(new wxExpr((long)theFont
->GetStyle()));
1510 expr
->Append(new wxExpr((long)theFont
->GetWeight()));
1511 expr
->Append(new wxExpr((long)theFont
->GetUnderlined()));
1516 // If no recognised GDI object, append a place holder anyway.
1517 expr
= new wxExpr(wxExprList
);
1518 expr
->Append(new wxExpr((long)0));
1523 clause
->AddAttributeValue(buf
, expr
);
1526 node
= node
->GetNext();
1529 // Write drawing operations
1531 node
= m_ops
.GetFirst();
1534 wxSprintf(buf
, _T("op%d_%d"), whichAngle
, i
);
1535 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1536 wxExpr
*expr
= op
->WriteExpr(this);
1539 clause
->AddAttributeValue(buf
, expr
);
1542 node
= node
->GetNext();
1545 // Write outline and fill GDI op lists (if any)
1546 if (m_outlineColours
.GetCount() > 0)
1548 wxExpr
*outlineExpr
= new wxExpr(wxExprList
);
1549 node
= m_outlineColours
.GetFirst();
1552 outlineExpr
->Append(new wxExpr((long)node
->GetData()));
1553 node
= node
->GetNext();
1555 wxString outlineObjectsStr
;
1556 outlineObjectsStr
.Printf(wxT("outline_objects%d"), whichAngle
);
1558 clause
->AddAttributeValue(outlineObjectsStr
, outlineExpr
);
1560 if (m_fillColours
.GetCount() > 0)
1562 wxExpr
*fillExpr
= new wxExpr(wxExprList
);
1563 node
= m_fillColours
.GetFirst();
1566 fillExpr
->Append(new wxExpr((long)node
->GetData()));
1567 node
= node
->GetNext();
1569 wxString fillObjectsStr
;
1570 fillObjectsStr
.Printf(wxT("fill_objects%d"), whichAngle
);
1572 clause
->AddAttributeValue(fillObjectsStr
, fillExpr
);
1577 void wxPseudoMetaFile::ReadAttributes(wxExpr
*clause
, int whichAngle
)
1580 widthStr
.Printf(wxT("meta_width%d"), whichAngle
);
1583 heightStr
.Printf(wxT("meta_height%d"), whichAngle
);
1585 wxString outlineStr
;
1586 outlineStr
.Printf(wxT("outline_op%d"), whichAngle
);
1588 wxString rotateableStr
;
1589 rotateableStr
.Printf(wxT("meta_rotateable%d"), whichAngle
);
1591 clause
->GetAttributeValue(widthStr
, m_width
);
1592 clause
->GetAttributeValue(heightStr
, m_height
);
1593 clause
->GetAttributeValue(outlineStr
, m_outlineOp
);
1595 int iVal
= (int) m_rotateable
;
1596 clause
->GetAttributeValue(rotateableStr
, iVal
);
1597 m_rotateable
= (iVal
!= 0);
1602 bool keepGoing
= true;
1605 wxSprintf(buf
, _T("gdi%d_%d"), whichAngle
, i
);
1606 wxExpr
*expr
= NULL
;
1607 clause
->GetAttributeValue(buf
, &expr
);
1614 wxExpr
*idExpr
= expr
->Nth(0);
1615 switch (idExpr
->IntegerValue())
1619 int penWidth
= (int)expr
->Nth(1)->IntegerValue();
1620 int penStyle
= (int)expr
->Nth(2)->IntegerValue();
1621 unsigned char penRed
= (unsigned char)expr
->Nth(3)->IntegerValue();
1622 unsigned char penGreen
= (unsigned char)expr
->Nth(4)->IntegerValue();
1623 unsigned char penBlue
= (unsigned char)expr
->Nth(5)->IntegerValue();
1624 wxColour
col(penRed
, penGreen
, penBlue
);
1625 wxPen
*p
= wxThePenList
->FindOrCreatePen(col
, penWidth
, penStyle
);
1628 m_gdiObjects
.Append(p
);
1633 int brushStyle
= (int)expr
->Nth(1)->IntegerValue();
1634 unsigned char brushRed
= (unsigned char)expr
->Nth(2)->IntegerValue();
1635 unsigned char brushGreen
= (unsigned char)expr
->Nth(3)->IntegerValue();
1636 unsigned char brushBlue
= (unsigned char)expr
->Nth(4)->IntegerValue();
1637 wxColour
col(brushRed
, brushGreen
, brushBlue
);
1638 wxBrush
*b
= wxTheBrushList
->FindOrCreateBrush(col
, brushStyle
);
1641 m_gdiObjects
.Append(b
);
1646 int fontPointSize
= (int)expr
->Nth(1)->IntegerValue();
1647 int fontFamily
= (int)expr
->Nth(2)->IntegerValue();
1648 int fontStyle
= (int)expr
->Nth(3)->IntegerValue();
1649 int fontWeight
= (int)expr
->Nth(4)->IntegerValue();
1650 int fontUnderlined
= (int)expr
->Nth(5)->IntegerValue();
1651 m_gdiObjects
.Append(wxTheFontList
->FindOrCreateFont(fontPointSize
,
1652 fontFamily
, fontStyle
, fontWeight
, (fontUnderlined
!= 0)));
1658 m_gdiObjects
.Append(NULL
);
1666 // Now read in the operations
1671 wxSprintf(buf
, _T("op%d_%d"), whichAngle
, i
);
1672 wxExpr
*expr
= NULL
;
1673 clause
->GetAttributeValue(buf
, &expr
);
1680 wxExpr
*idExpr
= expr
->Nth(0);
1681 int opId
= (int)idExpr
->IntegerValue();
1684 case DRAWOP_SET_PEN
:
1685 case DRAWOP_SET_BRUSH
:
1686 case DRAWOP_SET_FONT
:
1687 case DRAWOP_SET_TEXT_COLOUR
:
1688 case DRAWOP_SET_BK_COLOUR
:
1689 case DRAWOP_SET_BK_MODE
:
1691 wxOpSetGDI
*theOp
= new wxOpSetGDI(opId
, this, 0);
1692 theOp
->ReadExpr(this, expr
);
1693 m_ops
.Append(theOp
);
1697 case DRAWOP_SET_CLIPPING_RECT
:
1698 case DRAWOP_DESTROY_CLIPPING_RECT
:
1700 wxOpSetClipping
*theOp
= new wxOpSetClipping(opId
, 0.0, 0.0, 0.0, 0.0);
1701 theOp
->ReadExpr(this, expr
);
1702 m_ops
.Append(theOp
);
1706 case DRAWOP_DRAW_LINE
:
1707 case DRAWOP_DRAW_RECT
:
1708 case DRAWOP_DRAW_ROUNDED_RECT
:
1709 case DRAWOP_DRAW_ELLIPSE
:
1710 case DRAWOP_DRAW_POINT
:
1711 case DRAWOP_DRAW_ARC
:
1712 case DRAWOP_DRAW_TEXT
:
1714 wxOpDraw
*theOp
= new wxOpDraw(opId
, 0.0, 0.0, 0.0, 0.0);
1715 theOp
->ReadExpr(this, expr
);
1716 m_ops
.Append(theOp
);
1719 case DRAWOP_DRAW_SPLINE
:
1720 case DRAWOP_DRAW_POLYLINE
:
1721 case DRAWOP_DRAW_POLYGON
:
1723 wxOpPolyDraw
*theOp
= new wxOpPolyDraw(opId
, 0, NULL
);
1724 theOp
->ReadExpr(this, expr
);
1725 m_ops
.Append(theOp
);
1735 wxString outlineObjectsStr
;
1736 outlineObjectsStr
.Printf(wxT("outline_objects%d"), whichAngle
);
1738 // Now read in the list of outline and fill operations, if any
1739 wxExpr
*expr1
= clause
->AttributeValue(outlineObjectsStr
);
1742 wxExpr
*eachExpr
= expr1
->GetFirst();
1745 m_outlineColours
.Append((wxObject
*)eachExpr
->IntegerValue());
1746 eachExpr
= eachExpr
->GetNext();
1750 wxString fillObjectsStr
;
1751 fillObjectsStr
.Printf(wxT("fill_objects%d"), whichAngle
);
1753 expr1
= clause
->AttributeValue(fillObjectsStr
);
1756 wxExpr
*eachExpr
= expr1
->GetFirst();
1759 m_fillColours
.Append((wxObject
*)eachExpr
->IntegerValue());
1760 eachExpr
= eachExpr
->GetNext();
1766 // Does the copying for this object
1767 void wxPseudoMetaFile::Copy(wxPseudoMetaFile
& copy
)
1771 copy
.m_currentRotation
= m_currentRotation
;
1772 copy
.m_width
= m_width
;
1773 copy
.m_height
= m_height
;
1774 copy
.m_rotateable
= m_rotateable
;
1775 copy
.m_fillBrush
= m_fillBrush
;
1776 copy
.m_outlinePen
= m_outlinePen
;
1777 copy
.m_outlineOp
= m_outlineOp
;
1779 // Copy the GDI objects
1780 wxNode
*node
= m_gdiObjects
.GetFirst();
1783 wxObject
*obj
= (wxObject
*)node
->GetData();
1784 copy
.m_gdiObjects
.Append(obj
);
1785 node
= node
->GetNext();
1788 // Copy the operations
1789 node
= m_ops
.GetFirst();
1792 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1793 copy
.m_ops
.Append(op
->Copy(©
));
1794 node
= node
->GetNext();
1797 // Copy the outline/fill operations
1798 node
= m_outlineColours
.GetFirst();
1801 copy
.m_outlineColours
.Append((wxObject
*)node
->GetData());
1802 node
= node
->GetNext();
1804 node
= m_fillColours
.GetFirst();
1807 copy
.m_fillColours
.Append((wxObject
*)node
->GetData());
1808 node
= node
->GetNext();
1813 * Pass size of existing image; scale height to
1814 * fit width and return new width and height.
1818 bool wxPseudoMetaFile::LoadFromMetaFile(const wxString
& filename
, double *rwidth
, double *rheight
)
1820 if (!wxFileExists(filename
))
1823 wxXMetaFile
*metaFile
= new wxXMetaFile
;
1825 if (!metaFile
->ReadFile(filename
))
1834 // Convert from metafile records to wxDrawnShape records
1835 wxNode
*node
= metaFile
->metaRecords
.GetFirst();
1838 wxMetaRecord
*record
= (wxMetaRecord
*)node
->GetData();
1839 switch (record
->metaFunction
)
1841 case META_SETBKCOLOR
:
1843 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_BK_COLOUR
, this, 0);
1844 op
->m_r
= (unsigned char)record
->param1
;
1845 op
->m_g
= (unsigned char)record
->param2
;
1846 op
->m_b
= (unsigned char)record
->param3
;
1850 case META_SETBKMODE
:
1852 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_BK_MODE
, this, 0, (int)record
->param1
);
1856 case META_SETMAPMODE
:
1860 // case META_SETROP2:
1861 // case META_SETRELABS:
1862 // case META_SETPOLYFILLMODE:
1863 // case META_SETSTRETCHBLTMODE:
1864 // case META_SETTEXTCHAREXTRA:
1865 case META_SETTEXTCOLOR
:
1867 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_TEXT_COLOUR
, this, 0);
1868 op
->m_r
= (unsigned char)record
->param1
;
1869 op
->m_g
= (unsigned char)record
->param2
;
1870 op
->m_b
= (unsigned char)record
->param3
;
1874 // case META_SETTEXTJUSTIFICATION:
1875 // case META_SETWINDOWORG:
1876 // case META_SETWINDOWEXT:
1877 // case META_SETVIEWPORTORG:
1878 // case META_SETVIEWPORTEXT:
1879 // case META_OFFSETWINDOWORG:
1880 // case META_SCALEWINDOWEXT:
1881 // case META_OFFSETVIEWPORTORG:
1882 // case META_SCALEVIEWPORTEXT:
1885 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_LINE
, (double)lastX
, (double)lastY
,
1886 (double)record
->param1
, (double)record
->param2
);
1892 lastX
= (double)record
->param1
;
1893 lastY
= (double)record
->param2
;
1896 case META_EXCLUDECLIPRECT
:
1899 wxMetaRecord *rec = new wxMetaRecord(META_EXCLUDECLIPRECT);
1900 rec->param4 = getshort(handle); // m_y2
1901 rec->param3 = getshort(handle); // x2
1902 rec->param2 = getshort(handle); // y1
1903 rec->param1 = getshort(handle); // x1
1907 case META_INTERSECTCLIPRECT
:
1910 rec->param4 = getshort(handle); // m_y2
1911 rec->param3 = getshort(handle); // x2
1912 rec->param2 = getshort(handle); // y1
1913 rec->param1 = getshort(handle); // x1
1917 // case META_ARC: // DO!!!
1920 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_ELLIPSE
,
1921 (double)record
->param1
, (double)record
->param2
,
1922 (double)(record
->param3
- record
->param1
),
1923 (double)(record
->param4
- record
->param2
));
1927 // case META_FLOODFILL:
1928 // case META_PIE: // DO!!!
1929 case META_RECTANGLE
:
1931 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_RECT
,
1932 (double)record
->param1
, (double)record
->param2
,
1933 (double)(record
->param3
- record
->param1
),
1934 (double)(record
->param4
- record
->param2
));
1938 case META_ROUNDRECT
:
1940 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_ROUNDED_RECT
,
1941 (double)record
->param1
, (double)record
->param2
,
1942 (double)(record
->param3
- record
->param1
),
1943 (double)(record
->param4
- record
->param2
), (double)record
->param5
);
1947 // case META_PATBLT:
1948 // case META_SAVEDC:
1951 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_POINT
,
1952 (double)record
->param1
, (double)record
->param2
,
1955 // SHOULD SET THE COLOUR - SET PEN?
1956 // rec->param3 = getint(handle); // COLORREF
1960 // case META_OFFSETCLIPRGN:
1963 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_TEXT
,
1964 (double)record
->param1
, (double)record
->param2
,
1965 0.0, 0.0, 0.0, record
->stringParam
);
1969 // case META_BITBLT:
1970 // case META_STRETCHBLT:
1973 int n
= (int)record
->param1
;
1974 wxRealPoint
*newPoints
= new wxRealPoint
[n
];
1975 for (int i
= 0; i
< n
; i
++)
1977 newPoints
[i
].x
= record
->points
[i
].x
;
1978 newPoints
[i
].y
= record
->points
[i
].y
;
1981 wxOpPolyDraw
*op
= new wxOpPolyDraw(DRAWOP_DRAW_POLYGON
, n
, newPoints
);
1987 int n
= (int)record
->param1
;
1988 wxRealPoint
*newPoints
= new wxRealPoint
[n
];
1989 for (int i
= 0; i
< n
; i
++)
1991 newPoints
[i
].x
= record
->points
[i
].x
;
1992 newPoints
[i
].y
= record
->points
[i
].y
;
1995 wxOpPolyDraw
*op
= new wxOpPolyDraw(DRAWOP_DRAW_POLYLINE
, n
, newPoints
);
1999 // case META_ESCAPE:
2000 // case META_RESTOREDC:
2001 // case META_FILLREGION:
2002 // case META_FRAMEREGION:
2003 // case META_INVERTREGION:
2004 // case META_PAINTREGION:
2005 // case META_SELECTCLIPREGION: // DO THIS!
2006 case META_SELECTOBJECT
:
2008 // The pen, brush etc. has already been created when the metafile
2009 // was read in, so we don't create it - we set it.
2010 wxNode
*recNode
= metaFile
->gdiObjects
.Item((int)record
->param2
);
2013 wxMetaRecord
*gdiRec
= (wxMetaRecord
*)recNode
->GetData();
2014 if (gdiRec
&& (gdiRec
->param1
!= 0))
2016 wxObject
*obj
= (wxObject
*)gdiRec
->param1
;
2017 if (obj
->IsKindOf(CLASSINFO(wxPen
)))
2019 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_PEN
, this, (int)record
->param2
);
2022 else if (obj
->IsKindOf(CLASSINFO(wxBrush
)))
2024 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_BRUSH
, this, (int)record
->param2
);
2027 else if (obj
->IsKindOf(CLASSINFO(wxFont
)))
2029 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_FONT
, this, (int)record
->param2
);
2036 // case META_SETTEXTALIGN:
2037 // case META_DRAWTEXT:
2039 // case META_SETMAPPERFLAGS:
2040 // case META_EXTTEXTOUT:
2041 // case META_SETDIBTODEV:
2042 // case META_SELECTPALETTE:
2043 // case META_REALIZEPALETTE:
2044 // case META_ANIMATEPALETTE:
2045 // case META_SETPALENTRIES:
2046 // case META_POLYPOLYGON:
2047 // case META_RESIZEPALETTE:
2048 // case META_DIBBITBLT:
2049 // case META_DIBSTRETCHBLT:
2050 case META_DIBCREATEPATTERNBRUSH
:
2053 m_gdiObjects
.Append(NULL
);
2056 // case META_STRETCHDIB:
2057 // case META_EXTFLOODFILL:
2058 // case META_RESETDC:
2059 // case META_STARTDOC:
2060 // case META_STARTPAGE:
2061 // case META_ENDPAGE:
2062 // case META_ABORTDOC:
2063 // case META_ENDDOC:
2064 // case META_DELETEOBJECT: // DO!!
2065 case META_CREATEPALETTE
:
2068 m_gdiObjects
.Append(NULL
);
2071 case META_CREATEBRUSH
:
2074 m_gdiObjects
.Append(NULL
);
2077 case META_CREATEPATTERNBRUSH
:
2080 m_gdiObjects
.Append(NULL
);
2083 case META_CREATEPENINDIRECT
:
2085 // The pen is created when the metafile is read in.
2086 // We keep track of all the GDI objects needed for this
2087 // image so when reading the wxDrawnShape from file,
2088 // we can read in all the GDI objects, then refer
2089 // to them by an index starting from zero thereafter.
2090 m_gdiObjects
.Append((wxObject
*)record
->param1
);
2093 case META_CREATEFONTINDIRECT
:
2095 m_gdiObjects
.Append((wxObject
*)record
->param1
);
2098 case META_CREATEBRUSHINDIRECT
:
2100 // Don't have to do anything here: the pen is created
2101 // when the metafile is read in.
2102 m_gdiObjects
.Append((wxObject
*)record
->param1
);
2105 case META_CREATEBITMAPINDIRECT
:
2108 m_gdiObjects
.Append(NULL
);
2111 case META_CREATEBITMAP
:
2114 m_gdiObjects
.Append(NULL
);
2117 case META_CREATEREGION
:
2120 m_gdiObjects
.Append(NULL
);
2128 node
= node
->GetNext();
2130 double actualWidth
= (double)fabs(metaFile
->right
- metaFile
->left
);
2131 double actualHeight
= (double)fabs(metaFile
->bottom
- metaFile
->top
);
2133 double initialScaleX
= 1.0;
2134 double initialScaleY
= 1.0;
2136 double xoffset
, yoffset
;
2138 // Translate so origin is at centre of rectangle
2139 if (metaFile
->bottom
> metaFile
->top
)
2140 yoffset
= - (double)((metaFile
->bottom
- metaFile
->top
)/2.0);
2142 yoffset
= - (double)((metaFile
->top
- metaFile
->bottom
)/2.0);
2144 if (metaFile
->right
> metaFile
->left
)
2145 xoffset
= - (double)((metaFile
->right
- metaFile
->left
)/2.0);
2147 xoffset
= - (double)((metaFile
->left
- metaFile
->right
)/2.0);
2149 Translate(xoffset
, yoffset
);
2151 // Scale to a reasonable size (take the width of this wxDrawnShape
2153 if (actualWidth
!= 0.0)
2155 initialScaleX
= (double)((*rwidth
) / actualWidth
);
2156 initialScaleY
= initialScaleX
;
2157 (*rheight
) = initialScaleY
*actualHeight
;
2159 Scale(initialScaleX
, initialScaleY
);
2161 m_width
= (actualWidth
*initialScaleX
);
2162 m_height
= *rheight
;
2168 // Scale to fit size
2169 void wxPseudoMetaFile::ScaleTo(double w
, double h
)
2171 double scaleX
= (double)(w
/m_width
);
2172 double scaleY
= (double)(h
/m_height
);
2175 Scale(scaleX
, scaleY
);
2178 void wxPseudoMetaFile::GetBounds(double *boundMinX
, double *boundMinY
, double *boundMaxX
, double *boundMaxY
)
2180 double maxX
= (double) -99999.9;
2181 double maxY
= (double) -99999.9;
2182 double minX
= (double) 99999.9;
2183 double minY
= (double) 99999.9;
2185 wxNode
*node
= m_ops
.GetFirst();
2188 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
2189 switch (op
->GetOp())
2191 case DRAWOP_DRAW_LINE
:
2192 case DRAWOP_DRAW_RECT
:
2193 case DRAWOP_DRAW_ROUNDED_RECT
:
2194 case DRAWOP_DRAW_ELLIPSE
:
2195 case DRAWOP_DRAW_ELLIPTIC_ARC
:
2196 case DRAWOP_DRAW_POINT
:
2197 case DRAWOP_DRAW_TEXT
:
2199 wxOpDraw
*opDraw
= (wxOpDraw
*)op
;
2200 if (opDraw
->m_x1
< minX
) minX
= opDraw
->m_x1
;
2201 if (opDraw
->m_x1
> maxX
) maxX
= opDraw
->m_x1
;
2202 if (opDraw
->m_y1
< minY
) minY
= opDraw
->m_y1
;
2203 if (opDraw
->m_y1
> maxY
) maxY
= opDraw
->m_y1
;
2204 if (op
->GetOp() == DRAWOP_DRAW_LINE
)
2206 if (opDraw
->m_x2
< minX
) minX
= opDraw
->m_x2
;
2207 if (opDraw
->m_x2
> maxX
) maxX
= opDraw
->m_x2
;
2208 if (opDraw
->m_y2
< minY
) minY
= opDraw
->m_y2
;
2209 if (opDraw
->m_y2
> maxY
) maxY
= opDraw
->m_y2
;
2211 else if (op
->GetOp() == DRAWOP_DRAW_RECT
||
2212 op
->GetOp() == DRAWOP_DRAW_ROUNDED_RECT
||
2213 op
->GetOp() == DRAWOP_DRAW_ELLIPSE
||
2214 op
->GetOp() == DRAWOP_DRAW_ELLIPTIC_ARC
)
2216 if ((opDraw
->m_x1
+ opDraw
->m_x2
) < minX
) minX
= (opDraw
->m_x1
+ opDraw
->m_x2
);
2217 if ((opDraw
->m_x1
+ opDraw
->m_x2
) > maxX
) maxX
= (opDraw
->m_x1
+ opDraw
->m_x2
);
2218 if ((opDraw
->m_y1
+ opDraw
->m_y2
) < minY
) minY
= (opDraw
->m_y1
+ opDraw
->m_y2
);
2219 if ((opDraw
->m_y1
+ opDraw
->m_y2
) > maxY
) maxY
= (opDraw
->m_y1
+ opDraw
->m_y2
);
2223 case DRAWOP_DRAW_ARC
:
2225 // TODO: don't yet know how to calculate the bounding box
2226 // for an arc. So pretend it's a line; to get a correct
2227 // bounding box, draw a blank rectangle first, of the correct
2229 wxOpDraw
*opDraw
= (wxOpDraw
*)op
;
2230 if (opDraw
->m_x1
< minX
) minX
= opDraw
->m_x1
;
2231 if (opDraw
->m_x1
> maxX
) maxX
= opDraw
->m_x1
;
2232 if (opDraw
->m_y1
< minY
) minY
= opDraw
->m_y1
;
2233 if (opDraw
->m_y1
> maxY
) maxY
= opDraw
->m_y1
;
2234 if (opDraw
->m_x2
< minX
) minX
= opDraw
->m_x2
;
2235 if (opDraw
->m_x2
> maxX
) maxX
= opDraw
->m_x2
;
2236 if (opDraw
->m_y2
< minY
) minY
= opDraw
->m_y2
;
2237 if (opDraw
->m_y2
> maxY
) maxY
= opDraw
->m_y2
;
2240 case DRAWOP_DRAW_POLYLINE
:
2241 case DRAWOP_DRAW_POLYGON
:
2242 case DRAWOP_DRAW_SPLINE
:
2244 wxOpPolyDraw
*poly
= (wxOpPolyDraw
*)op
;
2245 for (int i
= 0; i
< poly
->m_noPoints
; i
++)
2247 if (poly
->m_points
[i
].x
< minX
) minX
= poly
->m_points
[i
].x
;
2248 if (poly
->m_points
[i
].x
> maxX
) maxX
= poly
->m_points
[i
].x
;
2249 if (poly
->m_points
[i
].y
< minY
) minY
= poly
->m_points
[i
].y
;
2250 if (poly
->m_points
[i
].y
> maxY
) maxY
= poly
->m_points
[i
].y
;
2257 node
= node
->GetNext();
2265 *w = (double)fabs(maxX - minX);
2266 *h = (double)fabs(maxY - minY);
2270 // Calculate size from current operations
2271 void wxPseudoMetaFile::CalculateSize(wxDrawnShape
* shape
)
2273 double boundMinX
, boundMinY
, boundMaxX
, boundMaxY
;
2275 GetBounds(& boundMinX
, & boundMinY
, & boundMaxX
, & boundMaxY
);
2277 SetSize(boundMaxX
- boundMinX
, boundMaxY
- boundMinY
);
2281 shape
->SetWidth(m_width
);
2282 shape
->SetHeight(m_height
);
2286 // Set of functions for drawing into a pseudo metafile.
2287 // They use integers, but doubles are used internally for accuracy
2290 void wxPseudoMetaFile::DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
)
2292 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_LINE
,
2293 (double) pt1
.x
, (double) pt1
.y
, (double) pt2
.x
, (double) pt2
.y
);
2295 m_ops
.Append(theOp
);
2298 void wxPseudoMetaFile::DrawRectangle(const wxRect
& rect
)
2300 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_RECT
,
2301 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2303 m_ops
.Append(theOp
);
2306 void wxPseudoMetaFile::DrawRoundedRectangle(const wxRect
& rect
, double radius
)
2308 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_ROUNDED_RECT
,
2309 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2311 theOp
->m_radius
= radius
;
2313 m_ops
.Append(theOp
);
2316 void wxPseudoMetaFile::DrawEllipse(const wxRect
& rect
)
2318 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_ELLIPSE
,
2319 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2321 m_ops
.Append(theOp
);
2324 void wxPseudoMetaFile::DrawArc(const wxPoint
& centrePt
, const wxPoint
& startPt
, const wxPoint
& endPt
)
2326 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_ARC
,
2327 (double) centrePt
.x
, (double) centrePt
.y
, (double) startPt
.x
, (double) startPt
.y
);
2329 theOp
->m_x3
= (double) endPt
.x
;
2330 theOp
->m_y3
= (double) endPt
.y
;
2332 m_ops
.Append(theOp
);
2335 void wxPseudoMetaFile::DrawEllipticArc(const wxRect
& rect
, double startAngle
, double endAngle
)
2337 const double pi
= M_PI
;
2339 double startAngleRadians
= startAngle
* (pi
*2.0/360.0);
2340 double endAngleRadians
= endAngle
* (pi
*2.0/360.0);
2342 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_ELLIPTIC_ARC
,
2343 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2345 theOp
->m_x3
= startAngleRadians
;
2346 theOp
->m_y3
= endAngleRadians
;
2348 m_ops
.Append(theOp
);
2351 void wxPseudoMetaFile::DrawPoint(const wxPoint
& pt
)
2353 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_POINT
,
2354 (double) pt
.x
, (double) pt
.y
, 0.0, 0.0);
2356 m_ops
.Append(theOp
);
2359 void wxPseudoMetaFile::DrawText(const wxString
& text
, const wxPoint
& pt
)
2361 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_TEXT
,
2362 (double) pt
.x
, (double) pt
.y
, 0.0, 0.0);
2364 theOp
->m_textString
= text
;
2366 m_ops
.Append(theOp
);
2369 void wxPseudoMetaFile::DrawLines(int n
, wxPoint pts
[])
2371 wxRealPoint
* realPoints
= new wxRealPoint
[n
];
2373 for (i
= 0; i
< n
; i
++)
2375 realPoints
[i
].x
= pts
[i
].x
;
2376 realPoints
[i
].y
= pts
[i
].y
;
2378 wxOpPolyDraw
* theOp
= new wxOpPolyDraw(DRAWOP_DRAW_POLYLINE
, n
, realPoints
);
2379 m_ops
.Append(theOp
);
2382 void wxPseudoMetaFile::DrawPolygon(int n
, wxPoint pts
[], int flags
)
2384 wxRealPoint
* realPoints
= new wxRealPoint
[n
];
2386 for (i
= 0; i
< n
; i
++)
2388 realPoints
[i
].x
= pts
[i
].x
;
2389 realPoints
[i
].y
= pts
[i
].y
;
2391 wxOpPolyDraw
* theOp
= new wxOpPolyDraw(DRAWOP_DRAW_POLYGON
, n
, realPoints
);
2392 m_ops
.Append(theOp
);
2394 if (flags
& oglMETAFLAGS_OUTLINE
)
2395 m_outlineOp
= (m_ops
.GetCount() - 1);
2398 void wxPseudoMetaFile::DrawSpline(int n
, wxPoint pts
[])
2400 wxRealPoint
* realPoints
= new wxRealPoint
[n
];
2402 for (i
= 0; i
< n
; i
++)
2404 realPoints
[i
].x
= pts
[i
].x
;
2405 realPoints
[i
].y
= pts
[i
].y
;
2407 wxOpPolyDraw
* theOp
= new wxOpPolyDraw(DRAWOP_DRAW_SPLINE
, n
, realPoints
);
2408 m_ops
.Append(theOp
);
2411 void wxPseudoMetaFile::SetClippingRect(const wxRect
& rect
)
2413 /* wxOpSetClipping* theOp = */ new wxOpSetClipping(DRAWOP_SET_CLIPPING_RECT
,
2414 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2417 void wxPseudoMetaFile::DestroyClippingRect()
2419 wxOpSetClipping
* theOp
= new wxOpSetClipping(DRAWOP_DESTROY_CLIPPING_RECT
,
2420 0.0, 0.0, 0.0, 0.0);
2422 m_ops
.Append(theOp
);
2425 void wxPseudoMetaFile::SetPen(wxPen
* pen
, bool isOutline
)
2427 m_gdiObjects
.Append(pen
);
2428 int n
= m_gdiObjects
.GetCount();
2430 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_PEN
, this, n
- 1);
2432 m_ops
.Append(theOp
);
2436 m_outlineColours
.Append((wxObject
*) (n
- 1));
2440 void wxPseudoMetaFile::SetBrush(wxBrush
* brush
, bool isFill
)
2442 m_gdiObjects
.Append(brush
);
2443 int n
= m_gdiObjects
.GetCount();
2445 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_BRUSH
, this, n
- 1);
2447 m_ops
.Append(theOp
);
2451 m_fillColours
.Append((wxObject
*) (n
- 1));
2455 void wxPseudoMetaFile::SetFont(wxFont
* font
)
2457 m_gdiObjects
.Append(font
);
2458 int n
= m_gdiObjects
.GetCount();
2460 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_FONT
, this, n
- 1);
2462 m_ops
.Append(theOp
);
2465 void wxPseudoMetaFile::SetTextColour(const wxColour
& colour
)
2467 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_TEXT_COLOUR
, this, 0);
2468 theOp
->m_r
= colour
.Red();
2469 theOp
->m_g
= colour
.Green();
2470 theOp
->m_b
= colour
.Blue();
2472 m_ops
.Append(theOp
);
2475 void wxPseudoMetaFile::SetBackgroundColour(const wxColour
& colour
)
2477 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_BK_COLOUR
, this, 0);
2478 theOp
->m_r
= colour
.Red();
2479 theOp
->m_g
= colour
.Green();
2480 theOp
->m_b
= colour
.Blue();
2482 m_ops
.Append(theOp
);
2485 void wxPseudoMetaFile::SetBackgroundMode(int mode
)
2487 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_BK_MODE
, this, 0, mode
);
2489 m_ops
.Append(theOp
);