1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDrawnShape
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx.h".
13 #include "wx/wxprec.h"
24 #include "wx/deprecated/wxexpr.h"
27 #include "wx/ogl/ogl.h"
30 static void IntToHex(unsigned int dec
, wxChar
*buf
);
31 static unsigned long HexToInt(wxChar
*buf
);
34 extern wxChar
*oglBuffer
;
37 #define gyTYPE_BRUSH 41
38 #define gyTYPE_FONT 42
45 IMPLEMENT_DYNAMIC_CLASS(wxDrawnShape
, wxRectangleShape
)
47 wxDrawnShape::wxDrawnShape():wxRectangleShape(100.0, 50.0)
50 m_currentAngle
= oglDRAWN_ANGLE_0
;
53 wxDrawnShape::~wxDrawnShape()
57 void wxDrawnShape::OnDraw(wxDC
& dc
)
59 // Pass pen and brush in case we have force outline
61 if (m_shadowMode
!= SHADOW_NONE
)
64 m_metafiles
[m_currentAngle
].m_fillBrush
= m_shadowBrush
;
65 m_metafiles
[m_currentAngle
].m_outlinePen
= g_oglTransparentPen
;
66 m_metafiles
[m_currentAngle
].Draw(dc
, m_xpos
+ m_shadowOffsetX
, m_ypos
+ m_shadowOffsetY
);
69 m_metafiles
[m_currentAngle
].m_outlinePen
= m_pen
;
70 m_metafiles
[m_currentAngle
].m_fillBrush
= m_brush
;
71 m_metafiles
[m_currentAngle
].Draw(dc
, m_xpos
, m_ypos
);
74 void wxDrawnShape::SetSize(double w
, double h
, bool WXUNUSED(recursive
))
76 SetAttachmentSize(w
, h
);
80 if (GetWidth() == 0.0)
82 else scaleX
= w
/GetWidth();
83 if (GetHeight() == 0.0)
85 else scaleY
= h
/GetHeight();
87 for (int i
= 0; i
< 4; i
++)
89 if (m_metafiles
[i
].IsValid())
90 m_metafiles
[i
].Scale(scaleX
, scaleY
);
94 SetDefaultRegionSize();
97 void wxDrawnShape::Scale(double sx
, double sy
)
100 for (i
= 0; i
< 4; i
++)
102 if (m_metafiles
[i
].IsValid())
104 m_metafiles
[i
].Scale(sx
, sy
);
105 m_metafiles
[i
].CalculateSize(this);
110 void wxDrawnShape::Translate(double x
, double y
)
113 for (i
= 0; i
< 4; i
++)
115 if (m_metafiles
[i
].IsValid())
117 m_metafiles
[i
].Translate(x
, y
);
118 m_metafiles
[i
].CalculateSize(this);
123 // theta is absolute rotation from the zero position
124 void wxDrawnShape::Rotate(double x
, double y
, double theta
)
126 m_currentAngle
= DetermineMetaFile(theta
);
128 if (m_currentAngle
== 0)
131 if (!m_metafiles
[0].GetRotateable())
134 m_metafiles
[0].Rotate(x
, y
, theta
);
137 double actualTheta
= theta
-m_rotation
;
139 // Rotate attachment points
140 double sinTheta
= (double)sin(actualTheta
);
141 double cosTheta
= (double)cos(actualTheta
);
142 wxNode
*node
= m_attachmentPoints
.GetFirst();
145 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->GetData();
146 double x1
= point
->m_x
;
147 double y1
= point
->m_y
;
148 point
->m_x
= x1
*cosTheta
- y1
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
149 point
->m_y
= x1
*sinTheta
+ y1
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
150 node
= node
->GetNext();
154 m_metafiles
[m_currentAngle
].CalculateSize(this);
157 // Which metafile do we use now? Based on current rotation and validity
160 int wxDrawnShape::DetermineMetaFile(double rotation
)
162 double tolerance
= 0.0001;
163 const double pi
= M_PI
;
165 double angle2
= pi
/2.0;
167 double angle4
= 3.0*pi
/2.0;
169 int whichMetafile
= 0;
171 if (oglRoughlyEqual(rotation
, angle1
, tolerance
))
175 else if (oglRoughlyEqual(rotation
, angle2
, tolerance
))
179 else if (oglRoughlyEqual(rotation
, angle3
, tolerance
))
183 else if (oglRoughlyEqual(rotation
, angle4
, tolerance
))
188 if ((whichMetafile
> 0) && !m_metafiles
[whichMetafile
].IsValid())
191 return whichMetafile
;
194 void wxDrawnShape::OnDrawOutline(wxDC
& dc
, double x
, double y
, double w
, double h
)
196 if (m_metafiles
[m_currentAngle
].GetOutlineOp() != -1)
198 wxNode
* node
= m_metafiles
[m_currentAngle
].GetOps().Item(m_metafiles
[m_currentAngle
].GetOutlineOp());
199 wxASSERT (node
!= NULL
);
200 wxDrawOp
* op
= (wxDrawOp
*) node
->GetData();
202 if (op
->OnDrawOutline(dc
, x
, y
, w
, h
, m_width
, m_height
))
206 // Default... just use a rectangle
207 wxRectangleShape::OnDrawOutline(dc
, x
, y
, w
, h
);
210 // Get the perimeter point using the special outline op, if there is one,
211 // otherwise use default wxRectangleShape scheme
212 bool wxDrawnShape::GetPerimeterPoint(double x1
, double y1
,
213 double x2
, double y2
,
214 double *x3
, double *y3
)
216 if (m_metafiles
[m_currentAngle
].GetOutlineOp() != -1)
218 wxNode
* node
= m_metafiles
[m_currentAngle
].GetOps().Item(m_metafiles
[m_currentAngle
].GetOutlineOp());
219 wxASSERT (node
!= NULL
);
220 wxDrawOp
* op
= (wxDrawOp
*) node
->GetData();
222 if (op
->GetPerimeterPoint(x1
, y1
, x2
, y2
, x3
, y3
, GetX(), GetY(), GetAttachmentMode()))
226 // Default... just use a rectangle
227 return wxRectangleShape::GetPerimeterPoint(x1
, y1
, x2
, y2
, x3
, y3
);
231 void wxDrawnShape::WriteAttributes(wxExpr
*clause
)
233 wxRectangleShape::WriteAttributes(clause
);
235 clause
->AddAttributeValue(_T("current_angle"), (long)m_currentAngle
);
236 clause
->AddAttributeValue(_T("save_metafile"), (long)m_saveToFile
);
239 for (int i
= 0; i
< 4; i
++)
241 if (m_metafiles
[i
].IsValid())
242 m_metafiles
[i
].WriteAttributes(clause
, i
);
247 void wxDrawnShape::ReadAttributes(wxExpr
*clause
)
249 wxRectangleShape::ReadAttributes(clause
);
251 int iVal
= (int) m_saveToFile
;
252 clause
->GetAttributeValue(_T("save_metafile"), iVal
);
253 clause
->GetAttributeValue(_T("current_angle"), m_currentAngle
);
254 m_saveToFile
= (iVal
!= 0);
258 for (int i
= 0; i
< 4; i
++)
260 m_metafiles
[i
].ReadAttributes(clause
, i
);
266 // Does the copying for this object
267 void wxDrawnShape::Copy(wxShape
& copy
)
269 wxRectangleShape::Copy(copy
);
271 wxASSERT( copy
.IsKindOf(CLASSINFO(wxDrawnShape
)) ) ;
273 wxDrawnShape
& drawnCopy
= (wxDrawnShape
&) copy
;
275 for (int i
= 0; i
< 4; i
++)
277 m_metafiles
[i
].Copy(drawnCopy
.m_metafiles
[i
]);
279 drawnCopy
.m_saveToFile
= m_saveToFile
;
280 drawnCopy
.m_currentAngle
= m_currentAngle
;
283 bool wxDrawnShape::LoadFromMetaFile(const wxString
& filename
)
285 return m_metafiles
[0].LoadFromMetaFile(filename
, &m_width
, &m_height
);
288 // Set of functions for drawing into a pseudo metafile.
289 // They use integers, but doubles are used internally for accuracy
292 void wxDrawnShape::DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
)
294 m_metafiles
[m_currentAngle
].DrawLine(pt1
, pt2
);
297 void wxDrawnShape::DrawRectangle(const wxRect
& rect
)
299 m_metafiles
[m_currentAngle
].DrawRectangle(rect
);
302 void wxDrawnShape::DrawRoundedRectangle(const wxRect
& rect
, double radius
)
304 m_metafiles
[m_currentAngle
].DrawRoundedRectangle(rect
, radius
);
307 void wxDrawnShape::DrawEllipse(const wxRect
& rect
)
309 m_metafiles
[m_currentAngle
].DrawEllipse(rect
);
312 void wxDrawnShape::DrawArc(const wxPoint
& centrePt
, const wxPoint
& startPt
, const wxPoint
& endPt
)
314 m_metafiles
[m_currentAngle
].DrawArc(centrePt
, startPt
, endPt
);
317 void wxDrawnShape::DrawEllipticArc(const wxRect
& rect
, double startAngle
, double endAngle
)
319 m_metafiles
[m_currentAngle
].DrawEllipticArc(rect
, startAngle
, endAngle
);
322 void wxDrawnShape::DrawPoint(const wxPoint
& pt
)
324 m_metafiles
[m_currentAngle
].DrawPoint(pt
);
327 void wxDrawnShape::DrawText(const wxString
& text
, const wxPoint
& pt
)
329 m_metafiles
[m_currentAngle
].DrawText(text
, pt
);
332 void wxDrawnShape::DrawLines(int n
, wxPoint pts
[])
334 m_metafiles
[m_currentAngle
].DrawLines(n
, pts
);
337 void wxDrawnShape::DrawPolygon(int n
, wxPoint pts
[], int flags
)
339 if (flags
& oglMETAFLAGS_ATTACHMENTS
)
343 for (i
= 0; i
< n
; i
++)
344 m_attachmentPoints
.Append(new wxAttachmentPoint(i
, pts
[i
].x
, pts
[i
].y
));
346 m_metafiles
[m_currentAngle
].DrawPolygon(n
, pts
, flags
);
349 void wxDrawnShape::DrawSpline(int n
, wxPoint pts
[])
351 m_metafiles
[m_currentAngle
].DrawSpline(n
, pts
);
354 void wxDrawnShape::SetClippingRect(const wxRect
& rect
)
356 m_metafiles
[m_currentAngle
].SetClippingRect(rect
);
359 void wxDrawnShape::DestroyClippingRect()
361 m_metafiles
[m_currentAngle
].DestroyClippingRect();
364 void wxDrawnShape::SetDrawnPen(wxPen
* pen
, bool isOutline
)
366 m_metafiles
[m_currentAngle
].SetPen(pen
, isOutline
);
369 void wxDrawnShape::SetDrawnBrush(wxBrush
* brush
, bool isFill
)
371 m_metafiles
[m_currentAngle
].SetBrush(brush
, isFill
);
374 void wxDrawnShape::SetDrawnFont(wxFont
* font
)
376 m_metafiles
[m_currentAngle
].SetFont(font
);
379 void wxDrawnShape::SetDrawnTextColour(const wxColour
& colour
)
381 m_metafiles
[m_currentAngle
].SetTextColour(colour
);
384 void wxDrawnShape::SetDrawnBackgroundColour(const wxColour
& colour
)
386 m_metafiles
[m_currentAngle
].SetBackgroundColour(colour
);
389 void wxDrawnShape::SetDrawnBackgroundMode(int mode
)
391 m_metafiles
[m_currentAngle
].SetBackgroundMode(mode
);
396 * Individual operations
401 * Set font, brush, text colour
405 wxOpSetGDI::wxOpSetGDI(int theOp
, wxPseudoMetaFile
*theImage
, int theGdiIndex
, int theMode
):
408 m_gdiIndex
= theGdiIndex
;
413 void wxOpSetGDI::Do(wxDC
& dc
, double WXUNUSED(xoffset
), double WXUNUSED(yoffset
))
419 // Check for overriding this operation for outline
421 if (m_image
->m_outlineColours
.Member((wxObject
*)m_gdiIndex
))
423 if (m_image
->m_outlinePen
)
424 dc
.SetPen(* m_image
->m_outlinePen
);
428 wxNode
*node
= m_image
->m_gdiObjects
.Item(m_gdiIndex
);
431 wxPen
*pen
= (wxPen
*)node
->GetData();
438 case DRAWOP_SET_BRUSH
:
440 // Check for overriding this operation for outline or fill
442 if (m_image
->m_outlineColours
.Member((wxObject
*)m_gdiIndex
))
444 // Need to construct a brush to match the outline pen's colour
445 if (m_image
->m_outlinePen
)
447 wxBrush
*br
= wxTheBrushList
->FindOrCreateBrush(m_image
->m_outlinePen
->GetColour(), wxSOLID
);
452 else if (m_image
->m_fillColours
.Member((wxObject
*)m_gdiIndex
))
454 if (m_image
->m_fillBrush
)
456 dc
.SetBrush(* m_image
->m_fillBrush
);
461 wxNode
*node
= m_image
->m_gdiObjects
.Item(m_gdiIndex
);
464 wxBrush
*brush
= (wxBrush
*)node
->GetData();
466 dc
.SetBrush(* brush
);
471 case DRAWOP_SET_FONT
:
473 wxNode
*node
= m_image
->m_gdiObjects
.Item(m_gdiIndex
);
476 wxFont
*font
= (wxFont
*)node
->GetData();
482 case DRAWOP_SET_TEXT_COLOUR
:
484 wxColour
col(m_r
,m_g
,m_b
);
485 dc
.SetTextForeground(col
);
488 case DRAWOP_SET_BK_COLOUR
:
490 wxColour
col(m_r
,m_g
,m_b
);
491 dc
.SetTextBackground(col
);
494 case DRAWOP_SET_BK_MODE
:
496 dc
.SetBackgroundMode(m_mode
);
504 wxDrawOp
*wxOpSetGDI::Copy(wxPseudoMetaFile
*newImage
)
506 wxOpSetGDI
*newOp
= new wxOpSetGDI(m_op
, newImage
, m_gdiIndex
, m_mode
);
514 wxExpr
*wxOpSetGDI::WriteExpr(wxPseudoMetaFile
*WXUNUSED(image
))
516 wxExpr
*expr
= new wxExpr(wxExprList
);
517 expr
->Append(new wxExpr((long)m_op
));
521 case DRAWOP_SET_BRUSH
:
522 case DRAWOP_SET_FONT
:
524 expr
->Append(new wxExpr((long)m_gdiIndex
));
527 case DRAWOP_SET_TEXT_COLOUR
:
528 case DRAWOP_SET_BK_COLOUR
:
530 expr
->Append(new wxExpr((long)m_r
));
531 expr
->Append(new wxExpr((long)m_g
));
532 expr
->Append(new wxExpr((long)m_b
));
535 case DRAWOP_SET_BK_MODE
:
537 expr
->Append(new wxExpr((long)m_mode
));
546 void wxOpSetGDI::ReadExpr(wxPseudoMetaFile
*WXUNUSED(image
), wxExpr
*expr
)
551 case DRAWOP_SET_BRUSH
:
552 case DRAWOP_SET_FONT
:
554 m_gdiIndex
= (int)expr
->Nth(1)->IntegerValue();
557 case DRAWOP_SET_TEXT_COLOUR
:
558 case DRAWOP_SET_BK_COLOUR
:
560 m_r
= (unsigned char)expr
->Nth(1)->IntegerValue();
561 m_g
= (unsigned char)expr
->Nth(2)->IntegerValue();
562 m_b
= (unsigned char)expr
->Nth(3)->IntegerValue();
565 case DRAWOP_SET_BK_MODE
:
567 m_mode
= (int)expr
->Nth(1)->IntegerValue();
577 * Set/destroy clipping
581 wxOpSetClipping::wxOpSetClipping(int theOp
, double theX1
, double theY1
,
582 double theX2
, double theY2
):wxDrawOp(theOp
)
590 wxDrawOp
*wxOpSetClipping::Copy(wxPseudoMetaFile
*WXUNUSED(newImage
))
592 wxOpSetClipping
*newOp
= new wxOpSetClipping(m_op
, m_x1
, m_y1
, m_x2
, m_y2
);
596 void wxOpSetClipping::Do(wxDC
& dc
, double xoffset
, double yoffset
)
600 case DRAWOP_SET_CLIPPING_RECT
:
602 dc
.SetClippingRegion((long)(m_x1
+ xoffset
), (long)(m_y1
+ yoffset
), (long)(m_x2
+ xoffset
), (long)(m_y2
+ yoffset
));
605 case DRAWOP_DESTROY_CLIPPING_RECT
:
607 dc
.DestroyClippingRegion();
615 void wxOpSetClipping::Scale(double xScale
, double yScale
)
623 void wxOpSetClipping::Translate(double x
, double y
)
630 wxExpr
*wxOpSetClipping::WriteExpr(wxPseudoMetaFile
*WXUNUSED(image
))
632 wxExpr
*expr
= new wxExpr(wxExprList
);
633 expr
->Append(new wxExpr((long)m_op
));
636 case DRAWOP_SET_CLIPPING_RECT
:
638 expr
->Append(new wxExpr(m_x1
));
639 expr
->Append(new wxExpr(m_y1
));
640 expr
->Append(new wxExpr(m_x2
));
641 expr
->Append(new wxExpr(m_y2
));
650 void wxOpSetClipping::ReadExpr(wxPseudoMetaFile
*WXUNUSED(image
), wxExpr
*expr
)
654 case DRAWOP_SET_CLIPPING_RECT
:
656 m_x1
= expr
->Nth(1)->RealValue();
657 m_y1
= expr
->Nth(2)->RealValue();
658 m_x2
= expr
->Nth(3)->RealValue();
659 m_y2
= expr
->Nth(4)->RealValue();
669 * Draw line, rectangle, rounded rectangle, ellipse, point, arc, text
673 wxOpDraw::wxOpDraw(int theOp
, double theX1
, double theY1
, double theX2
, double theY2
,
674 double theRadius
, const wxString
& s
) : wxDrawOp(theOp
)
682 m_radius
= theRadius
;
686 wxOpDraw::~wxOpDraw()
690 wxDrawOp
*wxOpDraw::Copy(wxPseudoMetaFile
*WXUNUSED(newImage
))
692 wxOpDraw
*newOp
= new wxOpDraw(m_op
, m_x1
, m_y1
, m_x2
, m_y2
, m_radius
, m_textString
);
698 void wxOpDraw::Do(wxDC
& dc
, double xoffset
, double yoffset
)
702 case DRAWOP_DRAW_LINE
:
704 dc
.DrawLine(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
), WXROUND(m_x2
+xoffset
), WXROUND(m_y2
+yoffset
));
707 case DRAWOP_DRAW_RECT
:
709 dc
.DrawRectangle(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
), WXROUND(m_x2
), WXROUND(m_y2
));
712 case DRAWOP_DRAW_ROUNDED_RECT
:
714 dc
.DrawRoundedRectangle(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
), WXROUND(m_x2
), WXROUND(m_y2
), m_radius
);
717 case DRAWOP_DRAW_ELLIPSE
:
719 dc
.DrawEllipse(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
), WXROUND(m_x2
), WXROUND(m_y2
));
722 case DRAWOP_DRAW_ARC
:
724 dc
.DrawArc(WXROUND(m_x2
+xoffset
), WXROUND(m_y2
+yoffset
),
725 WXROUND(m_x3
+xoffset
), WXROUND(m_y3
+yoffset
),
726 WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
));
729 case DRAWOP_DRAW_ELLIPTIC_ARC
:
731 const double pi
= M_PI
;
733 // Convert back to degrees
735 WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
),
736 WXROUND(m_x2
), WXROUND(m_y2
),
737 WXROUND(m_x3
*(360.0/(2.0*pi
))), WXROUND(m_y3
*(360.0/(2.0*pi
))));
740 case DRAWOP_DRAW_POINT
:
742 dc
.DrawPoint(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
));
745 case DRAWOP_DRAW_TEXT
:
747 dc
.DrawText(m_textString
, WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
));
755 void wxOpDraw::Scale(double scaleX
, double scaleY
)
762 if (m_op
!= DRAWOP_DRAW_ELLIPTIC_ARC
)
771 void wxOpDraw::Translate(double x
, double y
)
778 case DRAWOP_DRAW_LINE
:
784 case DRAWOP_DRAW_ARC
:
792 case DRAWOP_DRAW_ELLIPTIC_ARC
:
801 void wxOpDraw::Rotate(double x
, double y
, double theta
, double sinTheta
, double cosTheta
)
803 double newX1
= m_x1
*cosTheta
- m_y1
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
804 double newY1
= m_x1
*sinTheta
+ m_y1
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
808 case DRAWOP_DRAW_LINE
:
810 double newX2
= m_x2
*cosTheta
- m_y2
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
811 double newY2
= m_x2
*sinTheta
+ m_y2
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
819 case DRAWOP_DRAW_RECT
:
820 case DRAWOP_DRAW_ROUNDED_RECT
:
821 case DRAWOP_DRAW_ELLIPTIC_ARC
:
823 // Assume only 0, 90, 180, 270 degree rotations.
824 // oldX1, oldY1 represents the top left corner. Find the
825 // bottom right, and rotate that. Then the width/height is the difference
826 // between x/y values.
827 double oldBottomRightX
= m_x1
+ m_x2
;
828 double oldBottomRightY
= m_y1
+ m_y2
;
829 double newBottomRightX
= oldBottomRightX
*cosTheta
- oldBottomRightY
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
830 double newBottomRightY
= oldBottomRightX
*sinTheta
+ oldBottomRightY
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
832 // Now find the new top-left, bottom-right coordinates.
833 double minX
= wxMin(newX1
, newBottomRightX
);
834 double minY
= wxMin(newY1
, newBottomRightY
);
835 double maxX
= wxMax(newX1
, newBottomRightX
);
836 double maxY
= wxMax(newY1
, newBottomRightY
);
840 m_x2
= maxX
- minX
; // width
841 m_y2
= maxY
- minY
; // height
843 if (m_op
== DRAWOP_DRAW_ELLIPTIC_ARC
)
845 // Add rotation to angles
852 case DRAWOP_DRAW_ARC
:
854 double newX2
= m_x2
*cosTheta
- m_y2
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
855 double newY2
= m_x2
*sinTheta
+ m_y2
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
856 double newX3
= m_x3
*cosTheta
- m_y3
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
857 double newY3
= m_x3
*sinTheta
+ m_y3
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
874 wxExpr
*wxOpDraw::WriteExpr(wxPseudoMetaFile
*WXUNUSED(image
))
876 wxExpr
*expr
= new wxExpr(wxExprList
);
877 expr
->Append(new wxExpr((long)m_op
));
880 case DRAWOP_DRAW_LINE
:
881 case DRAWOP_DRAW_RECT
:
882 case DRAWOP_DRAW_ELLIPSE
:
884 expr
->Append(new wxExpr(m_x1
));
885 expr
->Append(new wxExpr(m_y1
));
886 expr
->Append(new wxExpr(m_x2
));
887 expr
->Append(new wxExpr(m_y2
));
890 case DRAWOP_DRAW_ROUNDED_RECT
:
892 expr
->Append(new wxExpr(m_x1
));
893 expr
->Append(new wxExpr(m_y1
));
894 expr
->Append(new wxExpr(m_x2
));
895 expr
->Append(new wxExpr(m_y2
));
896 expr
->Append(new wxExpr(m_radius
));
899 case DRAWOP_DRAW_POINT
:
901 expr
->Append(new wxExpr(m_x1
));
902 expr
->Append(new wxExpr(m_y1
));
905 case DRAWOP_DRAW_TEXT
:
907 expr
->Append(new wxExpr(m_x1
));
908 expr
->Append(new wxExpr(m_y1
));
909 expr
->Append(new wxExpr(wxExprString
, m_textString
));
912 case DRAWOP_DRAW_ARC
:
913 case DRAWOP_DRAW_ELLIPTIC_ARC
:
915 expr
->Append(new wxExpr(m_x1
));
916 expr
->Append(new wxExpr(m_y1
));
917 expr
->Append(new wxExpr(m_x2
));
918 expr
->Append(new wxExpr(m_y2
));
919 expr
->Append(new wxExpr(m_x3
));
920 expr
->Append(new wxExpr(m_y3
));
931 void wxOpDraw::ReadExpr(wxPseudoMetaFile
*WXUNUSED(image
), wxExpr
*expr
)
935 case DRAWOP_DRAW_LINE
:
936 case DRAWOP_DRAW_RECT
:
937 case DRAWOP_DRAW_ELLIPSE
:
939 m_x1
= expr
->Nth(1)->RealValue();
940 m_y1
= expr
->Nth(2)->RealValue();
941 m_x2
= expr
->Nth(3)->RealValue();
942 m_y2
= expr
->Nth(4)->RealValue();
945 case DRAWOP_DRAW_ROUNDED_RECT
:
947 m_x1
= expr
->Nth(1)->RealValue();
948 m_y1
= expr
->Nth(2)->RealValue();
949 m_x2
= expr
->Nth(3)->RealValue();
950 m_y2
= expr
->Nth(4)->RealValue();
951 m_radius
= expr
->Nth(5)->RealValue();
954 case DRAWOP_DRAW_POINT
:
956 m_x1
= expr
->Nth(1)->RealValue();
957 m_y1
= expr
->Nth(2)->RealValue();
960 case DRAWOP_DRAW_TEXT
:
962 m_x1
= expr
->Nth(1)->RealValue();
963 m_y1
= expr
->Nth(2)->RealValue();
964 m_textString
= wxString(expr
->Nth(3)->StringValue());
967 case DRAWOP_DRAW_ARC
:
968 case DRAWOP_DRAW_ELLIPTIC_ARC
:
970 m_x1
= expr
->Nth(1)->RealValue();
971 m_y1
= expr
->Nth(2)->RealValue();
972 m_x2
= expr
->Nth(3)->RealValue();
973 m_y2
= expr
->Nth(4)->RealValue();
974 m_x3
= expr
->Nth(5)->RealValue();
975 m_y3
= expr
->Nth(6)->RealValue();
987 * Draw polygon, polyline, spline
991 wxOpPolyDraw::wxOpPolyDraw(int theOp
, int n
, wxRealPoint
*thePoints
):wxDrawOp(theOp
)
994 m_points
= thePoints
;
997 wxOpPolyDraw::~wxOpPolyDraw()
1002 wxDrawOp
*wxOpPolyDraw::Copy(wxPseudoMetaFile
*WXUNUSED(newImage
))
1004 wxRealPoint
*newPoints
= new wxRealPoint
[m_noPoints
];
1005 for (int i
= 0; i
< m_noPoints
; i
++)
1007 newPoints
[i
].x
= m_points
[i
].x
;
1008 newPoints
[i
].y
= m_points
[i
].y
;
1010 wxOpPolyDraw
*newOp
= new wxOpPolyDraw(m_op
, m_noPoints
, newPoints
);
1014 void wxOpPolyDraw::Do(wxDC
& dc
, double xoffset
, double yoffset
)
1018 case DRAWOP_DRAW_POLYLINE
:
1020 wxPoint
*actualPoints
= new wxPoint
[m_noPoints
];
1022 for (i
= 0; i
< m_noPoints
; i
++)
1024 actualPoints
[i
].x
= WXROUND(m_points
[i
].x
);
1025 actualPoints
[i
].y
= WXROUND(m_points
[i
].y
);
1028 dc
.DrawLines(m_noPoints
, actualPoints
, WXROUND(xoffset
), WXROUND(yoffset
));
1030 delete[] actualPoints
;
1033 case DRAWOP_DRAW_POLYGON
:
1035 wxPoint
*actualPoints
= new wxPoint
[m_noPoints
];
1037 for (i
= 0; i
< m_noPoints
; i
++)
1039 actualPoints
[i
].x
= WXROUND(m_points
[i
].x
);
1040 actualPoints
[i
].y
= WXROUND(m_points
[i
].y
);
1043 dc
.DrawPolygon(m_noPoints
, actualPoints
, WXROUND(xoffset
), WXROUND(yoffset
));
1045 delete[] actualPoints
;
1048 case DRAWOP_DRAW_SPLINE
:
1050 wxPoint
*actualPoints
= new wxPoint
[m_noPoints
];
1052 for (i
= 0; i
< m_noPoints
; i
++)
1054 actualPoints
[i
].x
= WXROUND(m_points
[i
].x
);
1055 actualPoints
[i
].y
= WXROUND(m_points
[i
].y
);
1058 dc
.DrawSpline(m_noPoints
, actualPoints
); // no offsets in DrawSpline // , xoffset, yoffset);
1060 delete[] actualPoints
;
1068 void wxOpPolyDraw::Scale(double scaleX
, double scaleY
)
1070 for (int i
= 0; i
< m_noPoints
; i
++)
1072 m_points
[i
].x
*= scaleX
;
1073 m_points
[i
].y
*= scaleY
;
1077 void wxOpPolyDraw::Translate(double x
, double y
)
1079 for (int i
= 0; i
< m_noPoints
; i
++)
1086 void wxOpPolyDraw::Rotate(double x
, double y
, double WXUNUSED(theta
), double sinTheta
, double cosTheta
)
1088 for (int i
= 0; i
< m_noPoints
; i
++)
1090 double x1
= m_points
[i
].x
;
1091 double y1
= m_points
[i
].y
;
1092 m_points
[i
].x
= x1
*cosTheta
- y1
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
1093 m_points
[i
].y
= x1
*sinTheta
+ y1
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
1098 wxExpr
*wxOpPolyDraw::WriteExpr(wxPseudoMetaFile
*WXUNUSED(image
))
1100 wxExpr
*expr
= new wxExpr(wxExprList
);
1101 expr
->Append(new wxExpr((long)m_op
));
1102 expr
->Append(new wxExpr((long)m_noPoints
));
1111 * Store each coordinate pair in a hex string to save space.
1112 * E.g. "1B9080CD". 4 hex digits per coordinate pair.
1116 for (int i
= 0; i
< m_noPoints
; i
++)
1118 long signedX
= (long)(m_points
[i
].x
*100.0);
1119 long signedY
= (long)(m_points
[i
].y
*100.0);
1121 // Scale to 0 -> 64K
1122 unsigned int unSignedX
= (unsigned int)(signedX
+ 32767.0);
1123 unsigned int unSignedY
= (unsigned int)(signedY
+ 32767.0);
1125 IntToHex(unSignedX
, buf2
);
1126 IntToHex(unSignedY
, buf3
);
1128 // Don't overrun the buffer
1131 wxStrcat(oglBuffer
, buf2
);
1132 wxStrcat(oglBuffer
, buf3
);
1135 expr
->Append(new wxExpr(wxExprString
, oglBuffer
));
1139 void wxOpPolyDraw::ReadExpr(wxPseudoMetaFile
*WXUNUSED(image
), wxExpr
*expr
)
1141 m_noPoints
= (int)expr
->Nth(1)->IntegerValue();
1146 m_points
= new wxRealPoint
[m_noPoints
];
1149 wxString hexString
= expr
->Nth(2)->StringValue();
1150 while (i
< m_noPoints
)
1152 buf1
[0] = hexString
[(size_t)bufPtr
];
1153 buf1
[1] = hexString
[(size_t)(bufPtr
+ 1)];
1154 buf1
[2] = hexString
[(size_t)(bufPtr
+ 2)];
1155 buf1
[3] = hexString
[(size_t)(bufPtr
+ 3)];
1158 buf2
[0] = hexString
[(size_t)(bufPtr
+ 4)];
1159 buf2
[1] = hexString
[(size_t)(bufPtr
+ 5)];
1160 buf2
[2] = hexString
[(size_t)(bufPtr
+ 6)];
1161 buf2
[3] = hexString
[(size_t)(bufPtr
+ 7)];
1166 // int signedX = (signed int)HexToInt(buf1);
1167 // int signedY = (signed int)HexToInt(buf2);
1168 long unSignedX
= HexToInt(buf1
);
1169 long unSignedY
= HexToInt(buf2
);
1170 // Scale -32K -> +32K
1171 long signedX
= unSignedX
- 32767;
1172 long signedY
= unSignedY
- 32767;
1173 #if defined(__WXMSW__) && 0
1174 int testX
= (signed int)unSignedX
;
1175 int testY
= (signed int)unSignedY
;
1178 m_points
[i
].x
= (double)(signedX
/ 100.0);
1179 m_points
[i
].y
= (double)(signedY
/ 100.0);
1186 // Draw an outline using the current operation.
1187 bool wxOpPolyDraw::OnDrawOutline(wxDC
& dc
, double x
, double y
, double w
, double h
, double oldW
, double oldH
)
1189 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1191 // Multiply all points by proportion of new size to old size
1192 double x_proportion
= (double)(fabs(w
/oldW
));
1193 double y_proportion
= (double)(fabs(h
/oldH
));
1196 wxPoint
*intPoints
= new wxPoint
[n
];
1198 for (i
= 0; i
< n
; i
++)
1200 intPoints
[i
].x
= WXROUND (x_proportion
* m_points
[i
].x
);
1201 intPoints
[i
].y
= WXROUND (y_proportion
* m_points
[i
].y
);
1203 dc
.DrawPolygon(n
, intPoints
, (long) x
, (long) y
);
1208 // Assume (x1, y1) is centre of box (most generally, line end at box)
1209 bool wxOpPolyDraw::GetPerimeterPoint(double x1
, double y1
,
1210 double x2
, double y2
,
1211 double *x3
, double *y3
,
1212 double xOffset
, double yOffset
,
1217 // First check for situation where the line is vertical,
1218 // and we would want to connect to a point on that vertical --
1219 // oglFindEndForPolyline can't cope with this (the arrow
1220 // gets drawn to the wrong place).
1221 if ((attachmentMode
== ATTACHMENT_MODE_NONE
) && (x1
== x2
))
1223 // Look for the point we'd be connecting to. This is
1226 for (i
= 0; i
< n
; i
++)
1228 wxRealPoint
*point
= & (m_points
[i
]);
1229 if (point
->x
== 0.0)
1231 if ((y2
> y1
) && (point
->y
> 0.0))
1233 *x3
= point
->x
+ xOffset
;
1234 *y3
= point
->y
+ yOffset
;
1237 else if ((y2
< y1
) && (point
->y
< 0.0))
1239 *x3
= point
->x
+ xOffset
;
1240 *y3
= point
->y
+ yOffset
;
1247 double *xpoints
= new double[n
];
1248 double *ypoints
= new double[n
];
1250 for (int i
= 0; i
< n
; i
++)
1252 wxRealPoint
*point
= & (m_points
[i
]);
1253 xpoints
[i
] = point
->x
+ xOffset
;
1254 ypoints
[i
] = point
->y
+ yOffset
;
1257 oglFindEndForPolyline(n
, xpoints
, ypoints
,
1258 x1
, y1
, x2
, y2
, x3
, y3
);
1274 static char hexArray
[] = {
1275 _T('0'), _T('1'), _T('2'), _T('3'), _T('4'), _T('5'), _T('6'), _T('7'),
1276 _T('8'), _T('9'), _T('A'), _T('B'), _T('C'), _T('D'), _T('E'), _T('F') };
1278 // Convert unsigned 16-bit integer to 4-character hex string
1279 static void IntToHex(unsigned int dec
, wxChar
*buf
)
1281 int digit1
= (int)(dec
/4096);
1282 int digit2
= (int)((dec
- (digit1
*4096))/256);
1283 int digit3
= (int)((dec
- (digit1
*4096) - (digit2
*256))/16);
1284 int digit4
= dec
- (digit1
*4096 + digit2
*256 + digit3
*16);
1286 buf
[0] = hexArray
[digit1
];
1287 buf
[1] = hexArray
[digit2
];
1288 buf
[2] = hexArray
[digit3
];
1289 buf
[3] = hexArray
[digit4
];
1293 // One hex digit to decimal number
1294 static int HexToInt1(wxChar hex
)
1335 // 4-digit hex string to unsigned integer
1336 static unsigned long HexToInt(wxChar
*buf
)
1338 long d1
= (long)(HexToInt1(buf
[0])*4096.0) ;
1339 long d2
= (long)(HexToInt1(buf
[1])*256.0) ;
1340 long d3
= (long)(HexToInt1(buf
[2])*16.0) ;
1341 long d4
= (long)(HexToInt1(buf
[3])) ;
1342 unsigned long n
= (long)(d1
+ d2
+ d3
+ d4
) ;
1346 #endif // wxUSE_PROLOGIO
1349 * wxPseudo meta-file
1353 IMPLEMENT_DYNAMIC_CLASS(wxPseudoMetaFile
, wxObject
)
1355 wxPseudoMetaFile::wxPseudoMetaFile()
1357 m_currentRotation
= 0;
1358 m_rotateable
= true;
1361 m_outlinePen
= NULL
;
1366 wxPseudoMetaFile::wxPseudoMetaFile(wxPseudoMetaFile
& mf
):wxObject()
1371 wxPseudoMetaFile::~wxPseudoMetaFile()
1376 void wxPseudoMetaFile::Clear()
1378 wxNode
*node
= m_ops
.GetFirst();
1381 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1383 node
= node
->GetNext();
1386 m_gdiObjects
.Clear();
1387 m_outlineColours
.Clear();
1388 m_fillColours
.Clear();
1392 void wxPseudoMetaFile::Draw(wxDC
& dc
, double xoffset
, double yoffset
)
1394 wxNode
*node
= m_ops
.GetFirst();
1397 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1398 op
->Do(dc
, xoffset
, yoffset
);
1399 node
= node
->GetNext();
1403 void wxPseudoMetaFile::Scale(double sx
, double sy
)
1405 wxNode
*node
= m_ops
.GetFirst();
1408 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1410 node
= node
->GetNext();
1416 void wxPseudoMetaFile::Translate(double x
, double y
)
1418 wxNode
*node
= m_ops
.GetFirst();
1421 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1422 op
->Translate(x
, y
);
1423 node
= node
->GetNext();
1427 void wxPseudoMetaFile::Rotate(double x
, double y
, double theta
)
1429 double theta1
= theta
-m_currentRotation
;
1430 if (theta1
== 0.0) return;
1431 double cosTheta
= (double)cos(theta1
);
1432 double sinTheta
= (double)sin(theta1
);
1434 wxNode
*node
= m_ops
.GetFirst();
1437 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1438 op
->Rotate(x
, y
, theta
, sinTheta
, cosTheta
);
1439 node
= node
->GetNext();
1441 m_currentRotation
= theta
;
1445 void wxPseudoMetaFile::WriteAttributes(wxExpr
*clause
, int whichAngle
)
1448 widthStr
.Printf(wxT("meta_width%d"), whichAngle
);
1451 heightStr
.Printf(wxT("meta_height%d"), whichAngle
);
1453 wxString outlineStr
;
1454 outlineStr
.Printf(wxT("outline_op%d"), whichAngle
);
1456 wxString rotateableStr
;
1457 rotateableStr
.Printf(wxT("meta_rotateable%d"), whichAngle
);
1459 // Write width and height
1460 clause
->AddAttributeValue(widthStr
, m_width
);
1461 clause
->AddAttributeValue(heightStr
, m_height
);
1462 clause
->AddAttributeValue(rotateableStr
, (long)m_rotateable
);
1463 clause
->AddAttributeValue(outlineStr
, (long)m_outlineOp
);
1465 // Write GDI objects
1468 wxNode
*node
= m_gdiObjects
.GetFirst();
1471 wxSprintf(buf
, _T("gdi%d_%d"), whichAngle
, i
);
1472 wxObject
*obj
= (wxObject
*)node
->GetData();
1473 wxExpr
*expr
= NULL
;
1476 if (obj
->IsKindOf(CLASSINFO(wxPen
)))
1478 wxPen
*thePen
= (wxPen
*)obj
;
1479 expr
= new wxExpr(wxExprList
);
1480 expr
->Append(new wxExpr((long)gyTYPE_PEN
));
1481 expr
->Append(new wxExpr((long)thePen
->GetWidth()));
1482 expr
->Append(new wxExpr((long)thePen
->GetStyle()));
1483 expr
->Append(new wxExpr((long)thePen
->GetColour().Red()));
1484 expr
->Append(new wxExpr((long)thePen
->GetColour().Green()));
1485 expr
->Append(new wxExpr((long)thePen
->GetColour().Blue()));
1487 else if (obj
->IsKindOf(CLASSINFO(wxBrush
)))
1489 wxBrush
*theBrush
= (wxBrush
*)obj
;
1490 expr
= new wxExpr(wxExprList
);
1491 expr
->Append(new wxExpr((long)gyTYPE_BRUSH
));
1492 expr
->Append(new wxExpr((long)theBrush
->GetStyle()));
1493 expr
->Append(new wxExpr((long)theBrush
->GetColour().Red()));
1494 expr
->Append(new wxExpr((long)theBrush
->GetColour().Green()));
1495 expr
->Append(new wxExpr((long)theBrush
->GetColour().Blue()));
1497 else if (obj
->IsKindOf(CLASSINFO(wxFont
)))
1499 wxFont
*theFont
= (wxFont
*)obj
;
1500 expr
= new wxExpr(wxExprList
);
1501 expr
->Append(new wxExpr((long)gyTYPE_FONT
));
1502 expr
->Append(new wxExpr((long)theFont
->GetPointSize()));
1503 expr
->Append(new wxExpr((long)theFont
->GetFamily()));
1504 expr
->Append(new wxExpr((long)theFont
->GetStyle()));
1505 expr
->Append(new wxExpr((long)theFont
->GetWeight()));
1506 expr
->Append(new wxExpr((long)theFont
->GetUnderlined()));
1511 // If no recognised GDI object, append a place holder anyway.
1512 expr
= new wxExpr(wxExprList
);
1513 expr
->Append(new wxExpr((long)0));
1518 clause
->AddAttributeValue(buf
, expr
);
1521 node
= node
->GetNext();
1524 // Write drawing operations
1526 node
= m_ops
.GetFirst();
1529 wxSprintf(buf
, _T("op%d_%d"), whichAngle
, i
);
1530 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1531 wxExpr
*expr
= op
->WriteExpr(this);
1534 clause
->AddAttributeValue(buf
, expr
);
1537 node
= node
->GetNext();
1540 // Write outline and fill GDI op lists (if any)
1541 if (m_outlineColours
.GetCount() > 0)
1543 wxExpr
*outlineExpr
= new wxExpr(wxExprList
);
1544 node
= m_outlineColours
.GetFirst();
1547 outlineExpr
->Append(new wxExpr((long)node
->GetData()));
1548 node
= node
->GetNext();
1550 wxString outlineObjectsStr
;
1551 outlineObjectsStr
.Printf(wxT("outline_objects%d"), whichAngle
);
1553 clause
->AddAttributeValue(outlineObjectsStr
, outlineExpr
);
1555 if (m_fillColours
.GetCount() > 0)
1557 wxExpr
*fillExpr
= new wxExpr(wxExprList
);
1558 node
= m_fillColours
.GetFirst();
1561 fillExpr
->Append(new wxExpr((long)node
->GetData()));
1562 node
= node
->GetNext();
1564 wxString fillObjectsStr
;
1565 fillObjectsStr
.Printf(wxT("fill_objects%d"), whichAngle
);
1567 clause
->AddAttributeValue(fillObjectsStr
, fillExpr
);
1572 void wxPseudoMetaFile::ReadAttributes(wxExpr
*clause
, int whichAngle
)
1575 widthStr
.Printf(wxT("meta_width%d"), whichAngle
);
1578 heightStr
.Printf(wxT("meta_height%d"), whichAngle
);
1580 wxString outlineStr
;
1581 outlineStr
.Printf(wxT("outline_op%d"), whichAngle
);
1583 wxString rotateableStr
;
1584 rotateableStr
.Printf(wxT("meta_rotateable%d"), whichAngle
);
1586 clause
->GetAttributeValue(widthStr
, m_width
);
1587 clause
->GetAttributeValue(heightStr
, m_height
);
1588 clause
->GetAttributeValue(outlineStr
, m_outlineOp
);
1590 int iVal
= (int) m_rotateable
;
1591 clause
->GetAttributeValue(rotateableStr
, iVal
);
1592 m_rotateable
= (iVal
!= 0);
1597 bool keepGoing
= true;
1600 wxSprintf(buf
, _T("gdi%d_%d"), whichAngle
, i
);
1601 wxExpr
*expr
= NULL
;
1602 clause
->GetAttributeValue(buf
, &expr
);
1609 wxExpr
*idExpr
= expr
->Nth(0);
1610 switch (idExpr
->IntegerValue())
1614 int penWidth
= (int)expr
->Nth(1)->IntegerValue();
1615 int penStyle
= (int)expr
->Nth(2)->IntegerValue();
1616 unsigned char penRed
= (unsigned char)expr
->Nth(3)->IntegerValue();
1617 unsigned char penGreen
= (unsigned char)expr
->Nth(4)->IntegerValue();
1618 unsigned char penBlue
= (unsigned char)expr
->Nth(5)->IntegerValue();
1619 wxColour
col(penRed
, penGreen
, penBlue
);
1620 wxPen
*p
= wxThePenList
->FindOrCreatePen(col
, penWidth
, penStyle
);
1623 m_gdiObjects
.Append(p
);
1628 int brushStyle
= (int)expr
->Nth(1)->IntegerValue();
1629 unsigned char brushRed
= (unsigned char)expr
->Nth(2)->IntegerValue();
1630 unsigned char brushGreen
= (unsigned char)expr
->Nth(3)->IntegerValue();
1631 unsigned char brushBlue
= (unsigned char)expr
->Nth(4)->IntegerValue();
1632 wxColour
col(brushRed
, brushGreen
, brushBlue
);
1633 wxBrush
*b
= wxTheBrushList
->FindOrCreateBrush(col
, brushStyle
);
1636 m_gdiObjects
.Append(b
);
1641 int fontPointSize
= (int)expr
->Nth(1)->IntegerValue();
1642 int fontFamily
= (int)expr
->Nth(2)->IntegerValue();
1643 int fontStyle
= (int)expr
->Nth(3)->IntegerValue();
1644 int fontWeight
= (int)expr
->Nth(4)->IntegerValue();
1645 int fontUnderlined
= (int)expr
->Nth(5)->IntegerValue();
1646 m_gdiObjects
.Append(wxTheFontList
->FindOrCreateFont(fontPointSize
,
1647 fontFamily
, fontStyle
, fontWeight
, (fontUnderlined
!= 0)));
1653 m_gdiObjects
.Append(NULL
);
1661 // Now read in the operations
1666 wxSprintf(buf
, _T("op%d_%d"), whichAngle
, i
);
1667 wxExpr
*expr
= NULL
;
1668 clause
->GetAttributeValue(buf
, &expr
);
1675 wxExpr
*idExpr
= expr
->Nth(0);
1676 int opId
= (int)idExpr
->IntegerValue();
1679 case DRAWOP_SET_PEN
:
1680 case DRAWOP_SET_BRUSH
:
1681 case DRAWOP_SET_FONT
:
1682 case DRAWOP_SET_TEXT_COLOUR
:
1683 case DRAWOP_SET_BK_COLOUR
:
1684 case DRAWOP_SET_BK_MODE
:
1686 wxOpSetGDI
*theOp
= new wxOpSetGDI(opId
, this, 0);
1687 theOp
->ReadExpr(this, expr
);
1688 m_ops
.Append(theOp
);
1692 case DRAWOP_SET_CLIPPING_RECT
:
1693 case DRAWOP_DESTROY_CLIPPING_RECT
:
1695 wxOpSetClipping
*theOp
= new wxOpSetClipping(opId
, 0.0, 0.0, 0.0, 0.0);
1696 theOp
->ReadExpr(this, expr
);
1697 m_ops
.Append(theOp
);
1701 case DRAWOP_DRAW_LINE
:
1702 case DRAWOP_DRAW_RECT
:
1703 case DRAWOP_DRAW_ROUNDED_RECT
:
1704 case DRAWOP_DRAW_ELLIPSE
:
1705 case DRAWOP_DRAW_POINT
:
1706 case DRAWOP_DRAW_ARC
:
1707 case DRAWOP_DRAW_TEXT
:
1709 wxOpDraw
*theOp
= new wxOpDraw(opId
, 0.0, 0.0, 0.0, 0.0);
1710 theOp
->ReadExpr(this, expr
);
1711 m_ops
.Append(theOp
);
1714 case DRAWOP_DRAW_SPLINE
:
1715 case DRAWOP_DRAW_POLYLINE
:
1716 case DRAWOP_DRAW_POLYGON
:
1718 wxOpPolyDraw
*theOp
= new wxOpPolyDraw(opId
, 0, NULL
);
1719 theOp
->ReadExpr(this, expr
);
1720 m_ops
.Append(theOp
);
1730 wxString outlineObjectsStr
;
1731 outlineObjectsStr
.Printf(wxT("outline_objects%d"), whichAngle
);
1733 // Now read in the list of outline and fill operations, if any
1734 wxExpr
*expr1
= clause
->AttributeValue(outlineObjectsStr
);
1737 wxExpr
*eachExpr
= expr1
->GetFirst();
1740 m_outlineColours
.Append((wxObject
*)eachExpr
->IntegerValue());
1741 eachExpr
= eachExpr
->GetNext();
1745 wxString fillObjectsStr
;
1746 fillObjectsStr
.Printf(wxT("fill_objects%d"), whichAngle
);
1748 expr1
= clause
->AttributeValue(fillObjectsStr
);
1751 wxExpr
*eachExpr
= expr1
->GetFirst();
1754 m_fillColours
.Append((wxObject
*)eachExpr
->IntegerValue());
1755 eachExpr
= eachExpr
->GetNext();
1761 // Does the copying for this object
1762 void wxPseudoMetaFile::Copy(wxPseudoMetaFile
& copy
)
1766 copy
.m_currentRotation
= m_currentRotation
;
1767 copy
.m_width
= m_width
;
1768 copy
.m_height
= m_height
;
1769 copy
.m_rotateable
= m_rotateable
;
1770 copy
.m_fillBrush
= m_fillBrush
;
1771 copy
.m_outlinePen
= m_outlinePen
;
1772 copy
.m_outlineOp
= m_outlineOp
;
1774 // Copy the GDI objects
1775 wxNode
*node
= m_gdiObjects
.GetFirst();
1778 wxObject
*obj
= (wxObject
*)node
->GetData();
1779 copy
.m_gdiObjects
.Append(obj
);
1780 node
= node
->GetNext();
1783 // Copy the operations
1784 node
= m_ops
.GetFirst();
1787 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1788 copy
.m_ops
.Append(op
->Copy(©
));
1789 node
= node
->GetNext();
1792 // Copy the outline/fill operations
1793 node
= m_outlineColours
.GetFirst();
1796 copy
.m_outlineColours
.Append((wxObject
*)node
->GetData());
1797 node
= node
->GetNext();
1799 node
= m_fillColours
.GetFirst();
1802 copy
.m_fillColours
.Append((wxObject
*)node
->GetData());
1803 node
= node
->GetNext();
1808 * Pass size of existing image; scale height to
1809 * fit width and return new width and height.
1813 bool wxPseudoMetaFile::LoadFromMetaFile(const wxString
& filename
, double *rwidth
, double *rheight
)
1815 if (!wxFileExists(filename
))
1818 wxXMetaFile
*metaFile
= new wxXMetaFile
;
1820 if (!metaFile
->ReadFile(filename
))
1829 // Convert from metafile records to wxDrawnShape records
1830 wxNode
*node
= metaFile
->metaRecords
.GetFirst();
1833 wxMetaRecord
*record
= (wxMetaRecord
*)node
->GetData();
1834 switch (record
->metaFunction
)
1836 case META_SETBKCOLOR
:
1838 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_BK_COLOUR
, this, 0);
1839 op
->m_r
= (unsigned char)record
->param1
;
1840 op
->m_g
= (unsigned char)record
->param2
;
1841 op
->m_b
= (unsigned char)record
->param3
;
1845 case META_SETBKMODE
:
1847 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_BK_MODE
, this, 0, (int)record
->param1
);
1851 case META_SETMAPMODE
:
1855 // case META_SETROP2:
1856 // case META_SETRELABS:
1857 // case META_SETPOLYFILLMODE:
1858 // case META_SETSTRETCHBLTMODE:
1859 // case META_SETTEXTCHAREXTRA:
1860 case META_SETTEXTCOLOR
:
1862 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_TEXT_COLOUR
, this, 0);
1863 op
->m_r
= (unsigned char)record
->param1
;
1864 op
->m_g
= (unsigned char)record
->param2
;
1865 op
->m_b
= (unsigned char)record
->param3
;
1869 // case META_SETTEXTJUSTIFICATION:
1870 // case META_SETWINDOWORG:
1871 // case META_SETWINDOWEXT:
1872 // case META_SETVIEWPORTORG:
1873 // case META_SETVIEWPORTEXT:
1874 // case META_OFFSETWINDOWORG:
1875 // case META_SCALEWINDOWEXT:
1876 // case META_OFFSETVIEWPORTORG:
1877 // case META_SCALEVIEWPORTEXT:
1880 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_LINE
, (double)lastX
, (double)lastY
,
1881 (double)record
->param1
, (double)record
->param2
);
1887 lastX
= (double)record
->param1
;
1888 lastY
= (double)record
->param2
;
1891 case META_EXCLUDECLIPRECT
:
1894 wxMetaRecord *rec = new wxMetaRecord(META_EXCLUDECLIPRECT);
1895 rec->param4 = getshort(handle); // m_y2
1896 rec->param3 = getshort(handle); // x2
1897 rec->param2 = getshort(handle); // y1
1898 rec->param1 = getshort(handle); // x1
1902 case META_INTERSECTCLIPRECT
:
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_ARC: // DO!!!
1915 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_ELLIPSE
,
1916 (double)record
->param1
, (double)record
->param2
,
1917 (double)(record
->param3
- record
->param1
),
1918 (double)(record
->param4
- record
->param2
));
1922 // case META_FLOODFILL:
1923 // case META_PIE: // DO!!!
1924 case META_RECTANGLE
:
1926 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_RECT
,
1927 (double)record
->param1
, (double)record
->param2
,
1928 (double)(record
->param3
- record
->param1
),
1929 (double)(record
->param4
- record
->param2
));
1933 case META_ROUNDRECT
:
1935 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_ROUNDED_RECT
,
1936 (double)record
->param1
, (double)record
->param2
,
1937 (double)(record
->param3
- record
->param1
),
1938 (double)(record
->param4
- record
->param2
), (double)record
->param5
);
1942 // case META_PATBLT:
1943 // case META_SAVEDC:
1946 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_POINT
,
1947 (double)record
->param1
, (double)record
->param2
,
1950 // SHOULD SET THE COLOUR - SET PEN?
1951 // rec->param3 = getint(handle); // COLORREF
1955 // case META_OFFSETCLIPRGN:
1958 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_TEXT
,
1959 (double)record
->param1
, (double)record
->param2
,
1960 0.0, 0.0, 0.0, record
->stringParam
);
1964 // case META_BITBLT:
1965 // case META_STRETCHBLT:
1968 int n
= (int)record
->param1
;
1969 wxRealPoint
*newPoints
= new wxRealPoint
[n
];
1970 for (int i
= 0; i
< n
; i
++)
1972 newPoints
[i
].x
= record
->points
[i
].x
;
1973 newPoints
[i
].y
= record
->points
[i
].y
;
1976 wxOpPolyDraw
*op
= new wxOpPolyDraw(DRAWOP_DRAW_POLYGON
, n
, newPoints
);
1982 int n
= (int)record
->param1
;
1983 wxRealPoint
*newPoints
= new wxRealPoint
[n
];
1984 for (int i
= 0; i
< n
; i
++)
1986 newPoints
[i
].x
= record
->points
[i
].x
;
1987 newPoints
[i
].y
= record
->points
[i
].y
;
1990 wxOpPolyDraw
*op
= new wxOpPolyDraw(DRAWOP_DRAW_POLYLINE
, n
, newPoints
);
1994 // case META_ESCAPE:
1995 // case META_RESTOREDC:
1996 // case META_FILLREGION:
1997 // case META_FRAMEREGION:
1998 // case META_INVERTREGION:
1999 // case META_PAINTREGION:
2000 // case META_SELECTCLIPREGION: // DO THIS!
2001 case META_SELECTOBJECT
:
2003 // The pen, brush etc. has already been created when the metafile
2004 // was read in, so we don't create it - we set it.
2005 wxNode
*recNode
= metaFile
->gdiObjects
.Item((int)record
->param2
);
2008 wxMetaRecord
*gdiRec
= (wxMetaRecord
*)recNode
->GetData();
2009 if (gdiRec
&& (gdiRec
->param1
!= 0))
2011 wxObject
*obj
= (wxObject
*)gdiRec
->param1
;
2012 if (obj
->IsKindOf(CLASSINFO(wxPen
)))
2014 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_PEN
, this, (int)record
->param2
);
2017 else if (obj
->IsKindOf(CLASSINFO(wxBrush
)))
2019 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_BRUSH
, this, (int)record
->param2
);
2022 else if (obj
->IsKindOf(CLASSINFO(wxFont
)))
2024 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_FONT
, this, (int)record
->param2
);
2031 // case META_SETTEXTALIGN:
2032 // case META_DRAWTEXT:
2034 // case META_SETMAPPERFLAGS:
2035 // case META_EXTTEXTOUT:
2036 // case META_SETDIBTODEV:
2037 // case META_SELECTPALETTE:
2038 // case META_REALIZEPALETTE:
2039 // case META_ANIMATEPALETTE:
2040 // case META_SETPALENTRIES:
2041 // case META_POLYPOLYGON:
2042 // case META_RESIZEPALETTE:
2043 // case META_DIBBITBLT:
2044 // case META_DIBSTRETCHBLT:
2045 case META_DIBCREATEPATTERNBRUSH
:
2048 m_gdiObjects
.Append(NULL
);
2051 // case META_STRETCHDIB:
2052 // case META_EXTFLOODFILL:
2053 // case META_RESETDC:
2054 // case META_STARTDOC:
2055 // case META_STARTPAGE:
2056 // case META_ENDPAGE:
2057 // case META_ABORTDOC:
2058 // case META_ENDDOC:
2059 // case META_DELETEOBJECT: // DO!!
2060 case META_CREATEPALETTE
:
2063 m_gdiObjects
.Append(NULL
);
2066 case META_CREATEBRUSH
:
2069 m_gdiObjects
.Append(NULL
);
2072 case META_CREATEPATTERNBRUSH
:
2075 m_gdiObjects
.Append(NULL
);
2078 case META_CREATEPENINDIRECT
:
2080 // The pen is created when the metafile is read in.
2081 // We keep track of all the GDI objects needed for this
2082 // image so when reading the wxDrawnShape from file,
2083 // we can read in all the GDI objects, then refer
2084 // to them by an index starting from zero thereafter.
2085 m_gdiObjects
.Append((wxObject
*)record
->param1
);
2088 case META_CREATEFONTINDIRECT
:
2090 m_gdiObjects
.Append((wxObject
*)record
->param1
);
2093 case META_CREATEBRUSHINDIRECT
:
2095 // Don't have to do anything here: the pen is created
2096 // when the metafile is read in.
2097 m_gdiObjects
.Append((wxObject
*)record
->param1
);
2100 case META_CREATEBITMAPINDIRECT
:
2103 m_gdiObjects
.Append(NULL
);
2106 case META_CREATEBITMAP
:
2109 m_gdiObjects
.Append(NULL
);
2112 case META_CREATEREGION
:
2115 m_gdiObjects
.Append(NULL
);
2123 node
= node
->GetNext();
2125 double actualWidth
= (double)fabs(metaFile
->right
- metaFile
->left
);
2126 double actualHeight
= (double)fabs(metaFile
->bottom
- metaFile
->top
);
2128 double initialScaleX
= 1.0;
2129 double initialScaleY
= 1.0;
2131 double xoffset
, yoffset
;
2133 // Translate so origin is at centre of rectangle
2134 if (metaFile
->bottom
> metaFile
->top
)
2135 yoffset
= - (double)((metaFile
->bottom
- metaFile
->top
)/2.0);
2137 yoffset
= - (double)((metaFile
->top
- metaFile
->bottom
)/2.0);
2139 if (metaFile
->right
> metaFile
->left
)
2140 xoffset
= - (double)((metaFile
->right
- metaFile
->left
)/2.0);
2142 xoffset
= - (double)((metaFile
->left
- metaFile
->right
)/2.0);
2144 Translate(xoffset
, yoffset
);
2146 // Scale to a reasonable size (take the width of this wxDrawnShape
2148 if (actualWidth
!= 0.0)
2150 initialScaleX
= (double)((*rwidth
) / actualWidth
);
2151 initialScaleY
= initialScaleX
;
2152 (*rheight
) = initialScaleY
*actualHeight
;
2154 Scale(initialScaleX
, initialScaleY
);
2156 m_width
= (actualWidth
*initialScaleX
);
2157 m_height
= *rheight
;
2163 // Scale to fit size
2164 void wxPseudoMetaFile::ScaleTo(double w
, double h
)
2166 double scaleX
= (double)(w
/m_width
);
2167 double scaleY
= (double)(h
/m_height
);
2170 Scale(scaleX
, scaleY
);
2173 void wxPseudoMetaFile::GetBounds(double *boundMinX
, double *boundMinY
, double *boundMaxX
, double *boundMaxY
)
2175 double maxX
= (double) -99999.9;
2176 double maxY
= (double) -99999.9;
2177 double minX
= (double) 99999.9;
2178 double minY
= (double) 99999.9;
2180 wxNode
*node
= m_ops
.GetFirst();
2183 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
2184 switch (op
->GetOp())
2186 case DRAWOP_DRAW_LINE
:
2187 case DRAWOP_DRAW_RECT
:
2188 case DRAWOP_DRAW_ROUNDED_RECT
:
2189 case DRAWOP_DRAW_ELLIPSE
:
2190 case DRAWOP_DRAW_ELLIPTIC_ARC
:
2191 case DRAWOP_DRAW_POINT
:
2192 case DRAWOP_DRAW_TEXT
:
2194 wxOpDraw
*opDraw
= (wxOpDraw
*)op
;
2195 if (opDraw
->m_x1
< minX
) minX
= opDraw
->m_x1
;
2196 if (opDraw
->m_x1
> maxX
) maxX
= opDraw
->m_x1
;
2197 if (opDraw
->m_y1
< minY
) minY
= opDraw
->m_y1
;
2198 if (opDraw
->m_y1
> maxY
) maxY
= opDraw
->m_y1
;
2199 if (op
->GetOp() == DRAWOP_DRAW_LINE
)
2201 if (opDraw
->m_x2
< minX
) minX
= opDraw
->m_x2
;
2202 if (opDraw
->m_x2
> maxX
) maxX
= opDraw
->m_x2
;
2203 if (opDraw
->m_y2
< minY
) minY
= opDraw
->m_y2
;
2204 if (opDraw
->m_y2
> maxY
) maxY
= opDraw
->m_y2
;
2206 else if (op
->GetOp() == DRAWOP_DRAW_RECT
||
2207 op
->GetOp() == DRAWOP_DRAW_ROUNDED_RECT
||
2208 op
->GetOp() == DRAWOP_DRAW_ELLIPSE
||
2209 op
->GetOp() == DRAWOP_DRAW_ELLIPTIC_ARC
)
2211 if ((opDraw
->m_x1
+ opDraw
->m_x2
) < minX
) minX
= (opDraw
->m_x1
+ opDraw
->m_x2
);
2212 if ((opDraw
->m_x1
+ opDraw
->m_x2
) > maxX
) maxX
= (opDraw
->m_x1
+ opDraw
->m_x2
);
2213 if ((opDraw
->m_y1
+ opDraw
->m_y2
) < minY
) minY
= (opDraw
->m_y1
+ opDraw
->m_y2
);
2214 if ((opDraw
->m_y1
+ opDraw
->m_y2
) > maxY
) maxY
= (opDraw
->m_y1
+ opDraw
->m_y2
);
2218 case DRAWOP_DRAW_ARC
:
2220 // TODO: don't yet know how to calculate the bounding box
2221 // for an arc. So pretend it's a line; to get a correct
2222 // bounding box, draw a blank rectangle first, of the correct
2224 wxOpDraw
*opDraw
= (wxOpDraw
*)op
;
2225 if (opDraw
->m_x1
< minX
) minX
= opDraw
->m_x1
;
2226 if (opDraw
->m_x1
> maxX
) maxX
= opDraw
->m_x1
;
2227 if (opDraw
->m_y1
< minY
) minY
= opDraw
->m_y1
;
2228 if (opDraw
->m_y1
> maxY
) maxY
= opDraw
->m_y1
;
2229 if (opDraw
->m_x2
< minX
) minX
= opDraw
->m_x2
;
2230 if (opDraw
->m_x2
> maxX
) maxX
= opDraw
->m_x2
;
2231 if (opDraw
->m_y2
< minY
) minY
= opDraw
->m_y2
;
2232 if (opDraw
->m_y2
> maxY
) maxY
= opDraw
->m_y2
;
2235 case DRAWOP_DRAW_POLYLINE
:
2236 case DRAWOP_DRAW_POLYGON
:
2237 case DRAWOP_DRAW_SPLINE
:
2239 wxOpPolyDraw
*poly
= (wxOpPolyDraw
*)op
;
2240 for (int i
= 0; i
< poly
->m_noPoints
; i
++)
2242 if (poly
->m_points
[i
].x
< minX
) minX
= poly
->m_points
[i
].x
;
2243 if (poly
->m_points
[i
].x
> maxX
) maxX
= poly
->m_points
[i
].x
;
2244 if (poly
->m_points
[i
].y
< minY
) minY
= poly
->m_points
[i
].y
;
2245 if (poly
->m_points
[i
].y
> maxY
) maxY
= poly
->m_points
[i
].y
;
2252 node
= node
->GetNext();
2260 *w = (double)fabs(maxX - minX);
2261 *h = (double)fabs(maxY - minY);
2265 // Calculate size from current operations
2266 void wxPseudoMetaFile::CalculateSize(wxDrawnShape
* shape
)
2268 double boundMinX
, boundMinY
, boundMaxX
, boundMaxY
;
2270 GetBounds(& boundMinX
, & boundMinY
, & boundMaxX
, & boundMaxY
);
2272 SetSize(boundMaxX
- boundMinX
, boundMaxY
- boundMinY
);
2276 shape
->SetWidth(m_width
);
2277 shape
->SetHeight(m_height
);
2281 // Set of functions for drawing into a pseudo metafile.
2282 // They use integers, but doubles are used internally for accuracy
2285 void wxPseudoMetaFile::DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
)
2287 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_LINE
,
2288 (double) pt1
.x
, (double) pt1
.y
, (double) pt2
.x
, (double) pt2
.y
);
2290 m_ops
.Append(theOp
);
2293 void wxPseudoMetaFile::DrawRectangle(const wxRect
& rect
)
2295 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_RECT
,
2296 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2298 m_ops
.Append(theOp
);
2301 void wxPseudoMetaFile::DrawRoundedRectangle(const wxRect
& rect
, double radius
)
2303 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_ROUNDED_RECT
,
2304 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2306 theOp
->m_radius
= radius
;
2308 m_ops
.Append(theOp
);
2311 void wxPseudoMetaFile::DrawEllipse(const wxRect
& rect
)
2313 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_ELLIPSE
,
2314 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2316 m_ops
.Append(theOp
);
2319 void wxPseudoMetaFile::DrawArc(const wxPoint
& centrePt
, const wxPoint
& startPt
, const wxPoint
& endPt
)
2321 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_ARC
,
2322 (double) centrePt
.x
, (double) centrePt
.y
, (double) startPt
.x
, (double) startPt
.y
);
2324 theOp
->m_x3
= (double) endPt
.x
;
2325 theOp
->m_y3
= (double) endPt
.y
;
2327 m_ops
.Append(theOp
);
2330 void wxPseudoMetaFile::DrawEllipticArc(const wxRect
& rect
, double startAngle
, double endAngle
)
2332 const double pi
= M_PI
;
2334 double startAngleRadians
= startAngle
* (pi
*2.0/360.0);
2335 double endAngleRadians
= endAngle
* (pi
*2.0/360.0);
2337 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_ELLIPTIC_ARC
,
2338 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2340 theOp
->m_x3
= startAngleRadians
;
2341 theOp
->m_y3
= endAngleRadians
;
2343 m_ops
.Append(theOp
);
2346 void wxPseudoMetaFile::DrawPoint(const wxPoint
& pt
)
2348 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_POINT
,
2349 (double) pt
.x
, (double) pt
.y
, 0.0, 0.0);
2351 m_ops
.Append(theOp
);
2354 void wxPseudoMetaFile::DrawText(const wxString
& text
, const wxPoint
& pt
)
2356 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_TEXT
,
2357 (double) pt
.x
, (double) pt
.y
, 0.0, 0.0);
2359 theOp
->m_textString
= text
;
2361 m_ops
.Append(theOp
);
2364 void wxPseudoMetaFile::DrawLines(int n
, wxPoint pts
[])
2366 wxRealPoint
* realPoints
= new wxRealPoint
[n
];
2368 for (i
= 0; i
< n
; i
++)
2370 realPoints
[i
].x
= pts
[i
].x
;
2371 realPoints
[i
].y
= pts
[i
].y
;
2373 wxOpPolyDraw
* theOp
= new wxOpPolyDraw(DRAWOP_DRAW_POLYLINE
, n
, realPoints
);
2374 m_ops
.Append(theOp
);
2377 void wxPseudoMetaFile::DrawPolygon(int n
, wxPoint pts
[], int flags
)
2379 wxRealPoint
* realPoints
= new wxRealPoint
[n
];
2381 for (i
= 0; i
< n
; i
++)
2383 realPoints
[i
].x
= pts
[i
].x
;
2384 realPoints
[i
].y
= pts
[i
].y
;
2386 wxOpPolyDraw
* theOp
= new wxOpPolyDraw(DRAWOP_DRAW_POLYGON
, n
, realPoints
);
2387 m_ops
.Append(theOp
);
2389 if (flags
& oglMETAFLAGS_OUTLINE
)
2390 m_outlineOp
= (m_ops
.GetCount() - 1);
2393 void wxPseudoMetaFile::DrawSpline(int n
, wxPoint pts
[])
2395 wxRealPoint
* realPoints
= new wxRealPoint
[n
];
2397 for (i
= 0; i
< n
; i
++)
2399 realPoints
[i
].x
= pts
[i
].x
;
2400 realPoints
[i
].y
= pts
[i
].y
;
2402 wxOpPolyDraw
* theOp
= new wxOpPolyDraw(DRAWOP_DRAW_SPLINE
, n
, realPoints
);
2403 m_ops
.Append(theOp
);
2406 void wxPseudoMetaFile::SetClippingRect(const wxRect
& rect
)
2408 /* wxOpSetClipping* theOp = */ new wxOpSetClipping(DRAWOP_SET_CLIPPING_RECT
,
2409 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2412 void wxPseudoMetaFile::DestroyClippingRect()
2414 wxOpSetClipping
* theOp
= new wxOpSetClipping(DRAWOP_DESTROY_CLIPPING_RECT
,
2415 0.0, 0.0, 0.0, 0.0);
2417 m_ops
.Append(theOp
);
2420 void wxPseudoMetaFile::SetPen(wxPen
* pen
, bool isOutline
)
2422 m_gdiObjects
.Append(pen
);
2423 int n
= m_gdiObjects
.GetCount();
2425 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_PEN
, this, n
- 1);
2427 m_ops
.Append(theOp
);
2431 m_outlineColours
.Append((wxObject
*) (n
- 1));
2435 void wxPseudoMetaFile::SetBrush(wxBrush
* brush
, bool isFill
)
2437 m_gdiObjects
.Append(brush
);
2438 int n
= m_gdiObjects
.GetCount();
2440 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_BRUSH
, this, n
- 1);
2442 m_ops
.Append(theOp
);
2446 m_fillColours
.Append((wxObject
*) (n
- 1));
2450 void wxPseudoMetaFile::SetFont(wxFont
* font
)
2452 m_gdiObjects
.Append(font
);
2453 int n
= m_gdiObjects
.GetCount();
2455 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_FONT
, this, n
- 1);
2457 m_ops
.Append(theOp
);
2460 void wxPseudoMetaFile::SetTextColour(const wxColour
& colour
)
2462 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_TEXT_COLOUR
, this, 0);
2463 theOp
->m_r
= colour
.Red();
2464 theOp
->m_g
= colour
.Green();
2465 theOp
->m_b
= colour
.Blue();
2467 m_ops
.Append(theOp
);
2470 void wxPseudoMetaFile::SetBackgroundColour(const wxColour
& colour
)
2472 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_BK_COLOUR
, this, 0);
2473 theOp
->m_r
= colour
.Red();
2474 theOp
->m_g
= colour
.Green();
2475 theOp
->m_b
= colour
.Blue();
2477 m_ops
.Append(theOp
);
2480 void wxPseudoMetaFile::SetBackgroundMode(int mode
)
2482 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_BK_MODE
, this, 0, mode
);
2484 m_ops
.Append(theOp
);