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/basic.h>
33 #include <wx/ogl/basicp.h>
34 #include <wx/ogl/canvas.h>
35 #include <wx/ogl/mfutils.h>
36 #include <wx/ogl/drawn.h>
37 #include <wx/ogl/drawnp.h>
38 #include <wx/ogl/misc.h>
42 static void IntToHex(unsigned int dec
, char *buf
);
43 static unsigned long HexToInt(char *buf
);
44 extern char *oglBuffer
;
47 #define gyTYPE_BRUSH 41
48 #define gyTYPE_FONT 42
55 IMPLEMENT_DYNAMIC_CLASS(wxDrawnShape
, wxRectangleShape
)
57 wxDrawnShape::wxDrawnShape():wxRectangleShape(100.0, 50.0)
60 m_currentAngle
= oglDRAWN_ANGLE_0
;
63 wxDrawnShape::~wxDrawnShape()
67 void wxDrawnShape::OnDraw(wxDC
& dc
)
69 // Pass pen and brush in case we have force outline
71 if (m_shadowMode
!= SHADOW_NONE
)
74 m_metafiles
[m_currentAngle
].m_fillBrush
= m_shadowBrush
;
75 m_metafiles
[m_currentAngle
].m_outlinePen
= g_oglTransparentPen
;
76 m_metafiles
[m_currentAngle
].Draw(dc
, m_xpos
+ m_shadowOffsetX
, m_ypos
+ m_shadowOffsetY
);
79 m_metafiles
[m_currentAngle
].m_outlinePen
= m_pen
;
80 m_metafiles
[m_currentAngle
].m_fillBrush
= m_brush
;
81 m_metafiles
[m_currentAngle
].Draw(dc
, m_xpos
, m_ypos
);
84 void wxDrawnShape::SetSize(double w
, double h
, bool recursive
)
86 SetAttachmentSize(w
, h
);
90 if (GetWidth() == 0.0)
92 else scaleX
= w
/GetWidth();
93 if (GetHeight() == 0.0)
95 else scaleY
= h
/GetHeight();
98 for (i
= 0; i
< 4; i
++)
100 if (m_metafiles
[i
].IsValid())
101 m_metafiles
[i
].Scale(scaleX
, scaleY
);
105 SetDefaultRegionSize();
108 void wxDrawnShape::Scale(double sx
, double sy
)
111 for (i
= 0; i
< 4; i
++)
113 if (m_metafiles
[i
].IsValid())
115 m_metafiles
[i
].Scale(sx
, sy
);
116 m_metafiles
[i
].CalculateSize(this);
121 void wxDrawnShape::Translate(double x
, double y
)
124 for (i
= 0; i
< 4; i
++)
126 if (m_metafiles
[i
].IsValid())
128 m_metafiles
[i
].Translate(x
, y
);
129 m_metafiles
[i
].CalculateSize(this);
134 // theta is absolute rotation from the zero position
135 void wxDrawnShape::Rotate(double x
, double y
, double theta
)
137 m_currentAngle
= DetermineMetaFile(theta
);
139 if (m_currentAngle
== 0)
142 if (!m_metafiles
[0].GetRotateable())
145 m_metafiles
[0].Rotate(x
, y
, theta
);
148 double actualTheta
= theta
-m_rotation
;
150 // Rotate attachment points
151 double sinTheta
= (double)sin(actualTheta
);
152 double cosTheta
= (double)cos(actualTheta
);
153 wxNode
*node
= m_attachmentPoints
.GetFirst();
156 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->GetData();
157 double x1
= point
->m_x
;
158 double y1
= point
->m_y
;
159 point
->m_x
= x1
*cosTheta
- y1
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
160 point
->m_y
= x1
*sinTheta
+ y1
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
161 node
= node
->GetNext();
165 m_metafiles
[m_currentAngle
].CalculateSize(this);
168 // Which metafile do we use now? Based on current rotation and validity
171 int wxDrawnShape::DetermineMetaFile(double rotation
)
173 double tolerance
= 0.0001;
174 const double pi
= 3.1415926535897932384626433832795 ;
176 double angle2
= pi
/2.0;
178 double angle4
= 3.0*pi
/2.0;
180 int whichMetafile
= 0;
182 if (oglRoughlyEqual(rotation
, angle1
, tolerance
))
186 else if (oglRoughlyEqual(rotation
, angle2
, tolerance
))
190 else if (oglRoughlyEqual(rotation
, angle3
, tolerance
))
194 else if (oglRoughlyEqual(rotation
, angle4
, tolerance
))
199 if ((whichMetafile
> 0) && !m_metafiles
[whichMetafile
].IsValid())
202 return whichMetafile
;
205 void wxDrawnShape::OnDrawOutline(wxDC
& dc
, double x
, double y
, double w
, double h
)
207 if (m_metafiles
[m_currentAngle
].GetOutlineOp() != -1)
209 wxNode
* node
= m_metafiles
[m_currentAngle
].GetOps().Item(m_metafiles
[m_currentAngle
].GetOutlineOp());
210 wxASSERT (node
!= NULL
);
211 wxDrawOp
* op
= (wxDrawOp
*) node
->GetData();
213 if (op
->OnDrawOutline(dc
, x
, y
, w
, h
, m_width
, m_height
))
217 // Default... just use a rectangle
218 wxRectangleShape::OnDrawOutline(dc
, x
, y
, w
, h
);
221 // Get the perimeter point using the special outline op, if there is one,
222 // otherwise use default wxRectangleShape scheme
223 bool wxDrawnShape::GetPerimeterPoint(double x1
, double y1
,
224 double x2
, double y2
,
225 double *x3
, double *y3
)
227 if (m_metafiles
[m_currentAngle
].GetOutlineOp() != -1)
229 wxNode
* node
= m_metafiles
[m_currentAngle
].GetOps().Item(m_metafiles
[m_currentAngle
].GetOutlineOp());
230 wxASSERT (node
!= NULL
);
231 wxDrawOp
* op
= (wxDrawOp
*) node
->GetData();
233 if (op
->GetPerimeterPoint(x1
, y1
, x2
, y2
, x3
, y3
, GetX(), GetY(), GetAttachmentMode()))
237 // Default... just use a rectangle
238 return wxRectangleShape::GetPerimeterPoint(x1
, y1
, x2
, y2
, x3
, y3
);
242 void wxDrawnShape::WriteAttributes(wxExpr
*clause
)
244 wxRectangleShape::WriteAttributes(clause
);
246 clause
->AddAttributeValue("current_angle", (long)m_currentAngle
);
247 clause
->AddAttributeValue("save_metafile", (long)m_saveToFile
);
251 for (i
= 0; i
< 4; i
++)
253 if (m_metafiles
[i
].IsValid())
254 m_metafiles
[i
].WriteAttributes(clause
, i
);
259 void wxDrawnShape::ReadAttributes(wxExpr
*clause
)
261 wxRectangleShape::ReadAttributes(clause
);
263 int iVal
= (int) m_saveToFile
;
264 clause
->GetAttributeValue("save_metafile", iVal
);
265 clause
->GetAttributeValue("current_angle", m_currentAngle
);
266 m_saveToFile
= (iVal
!= 0);
271 for (i
= 0; i
< 4; i
++)
273 m_metafiles
[i
].ReadAttributes(clause
, i
);
279 // Does the copying for this object
280 void wxDrawnShape::Copy(wxShape
& copy
)
282 wxRectangleShape::Copy(copy
);
284 wxASSERT( copy
.IsKindOf(CLASSINFO(wxDrawnShape
)) ) ;
286 wxDrawnShape
& drawnCopy
= (wxDrawnShape
&) copy
;
289 for (i
= 0; i
< 4; i
++)
291 m_metafiles
[i
].Copy(drawnCopy
.m_metafiles
[i
]);
293 drawnCopy
.m_saveToFile
= m_saveToFile
;
294 drawnCopy
.m_currentAngle
= m_currentAngle
;
297 bool wxDrawnShape::LoadFromMetaFile(const wxString
& filename
)
299 return m_metafiles
[0].LoadFromMetaFile(filename
, &m_width
, &m_height
);
302 // Set of functions for drawing into a pseudo metafile.
303 // They use integers, but doubles are used internally for accuracy
306 void wxDrawnShape::DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
)
308 m_metafiles
[m_currentAngle
].DrawLine(pt1
, pt2
);
311 void wxDrawnShape::DrawRectangle(const wxRect
& rect
)
313 m_metafiles
[m_currentAngle
].DrawRectangle(rect
);
316 void wxDrawnShape::DrawRoundedRectangle(const wxRect
& rect
, double radius
)
318 m_metafiles
[m_currentAngle
].DrawRoundedRectangle(rect
, radius
);
321 void wxDrawnShape::DrawEllipse(const wxRect
& rect
)
323 m_metafiles
[m_currentAngle
].DrawEllipse(rect
);
326 void wxDrawnShape::DrawArc(const wxPoint
& centrePt
, const wxPoint
& startPt
, const wxPoint
& endPt
)
328 m_metafiles
[m_currentAngle
].DrawArc(centrePt
, startPt
, endPt
);
331 void wxDrawnShape::DrawEllipticArc(const wxRect
& rect
, double startAngle
, double endAngle
)
333 m_metafiles
[m_currentAngle
].DrawEllipticArc(rect
, startAngle
, endAngle
);
336 void wxDrawnShape::DrawPoint(const wxPoint
& pt
)
338 m_metafiles
[m_currentAngle
].DrawPoint(pt
);
341 void wxDrawnShape::DrawText(const wxString
& text
, const wxPoint
& pt
)
343 m_metafiles
[m_currentAngle
].DrawText(text
, pt
);
346 void wxDrawnShape::DrawLines(int n
, wxPoint pts
[])
348 m_metafiles
[m_currentAngle
].DrawLines(n
, pts
);
351 void wxDrawnShape::DrawPolygon(int n
, wxPoint pts
[], int flags
)
353 if (flags
& oglMETAFLAGS_ATTACHMENTS
)
357 for (i
= 0; i
< n
; i
++)
358 m_attachmentPoints
.Append(new wxAttachmentPoint(i
, pts
[i
].x
, pts
[i
].y
));
360 m_metafiles
[m_currentAngle
].DrawPolygon(n
, pts
, flags
);
363 void wxDrawnShape::DrawSpline(int n
, wxPoint pts
[])
365 m_metafiles
[m_currentAngle
].DrawSpline(n
, pts
);
368 void wxDrawnShape::SetClippingRect(const wxRect
& rect
)
370 m_metafiles
[m_currentAngle
].SetClippingRect(rect
);
373 void wxDrawnShape::DestroyClippingRect()
375 m_metafiles
[m_currentAngle
].DestroyClippingRect();
378 void wxDrawnShape::SetDrawnPen(wxPen
* pen
, bool isOutline
)
380 m_metafiles
[m_currentAngle
].SetPen(pen
, isOutline
);
383 void wxDrawnShape::SetDrawnBrush(wxBrush
* brush
, bool isFill
)
385 m_metafiles
[m_currentAngle
].SetBrush(brush
, isFill
);
388 void wxDrawnShape::SetDrawnFont(wxFont
* font
)
390 m_metafiles
[m_currentAngle
].SetFont(font
);
393 void wxDrawnShape::SetDrawnTextColour(const wxColour
& colour
)
395 m_metafiles
[m_currentAngle
].SetTextColour(colour
);
398 void wxDrawnShape::SetDrawnBackgroundColour(const wxColour
& colour
)
400 m_metafiles
[m_currentAngle
].SetBackgroundColour(colour
);
403 void wxDrawnShape::SetDrawnBackgroundMode(int mode
)
405 m_metafiles
[m_currentAngle
].SetBackgroundMode(mode
);
410 * Individual operations
415 * Set font, brush, text colour
419 wxOpSetGDI::wxOpSetGDI(int theOp
, wxPseudoMetaFile
*theImage
, int theGdiIndex
, int theMode
):
422 m_gdiIndex
= theGdiIndex
;
427 void wxOpSetGDI::Do(wxDC
& dc
, double xoffset
, double yoffset
)
433 // Check for overriding this operation for outline
435 if (m_image
->m_outlineColours
.Member((wxObject
*)m_gdiIndex
))
437 if (m_image
->m_outlinePen
)
438 dc
.SetPen(* m_image
->m_outlinePen
);
442 wxNode
*node
= m_image
->m_gdiObjects
.Item(m_gdiIndex
);
445 wxPen
*pen
= (wxPen
*)node
->GetData();
452 case DRAWOP_SET_BRUSH
:
454 // Check for overriding this operation for outline or fill
456 if (m_image
->m_outlineColours
.Member((wxObject
*)m_gdiIndex
))
458 // Need to construct a brush to match the outline pen's colour
459 if (m_image
->m_outlinePen
)
461 wxBrush
*br
= wxTheBrushList
->FindOrCreateBrush(m_image
->m_outlinePen
->GetColour(), wxSOLID
);
466 else if (m_image
->m_fillColours
.Member((wxObject
*)m_gdiIndex
))
468 if (m_image
->m_fillBrush
)
470 dc
.SetBrush(* m_image
->m_fillBrush
);
475 wxNode
*node
= m_image
->m_gdiObjects
.Item(m_gdiIndex
);
478 wxBrush
*brush
= (wxBrush
*)node
->GetData();
480 dc
.SetBrush(* brush
);
485 case DRAWOP_SET_FONT
:
487 wxNode
*node
= m_image
->m_gdiObjects
.Item(m_gdiIndex
);
490 wxFont
*font
= (wxFont
*)node
->GetData();
496 case DRAWOP_SET_TEXT_COLOUR
:
498 wxColour
col(m_r
,m_g
,m_b
);
499 dc
.SetTextForeground(col
);
502 case DRAWOP_SET_BK_COLOUR
:
504 wxColour
col(m_r
,m_g
,m_b
);
505 dc
.SetTextBackground(col
);
508 case DRAWOP_SET_BK_MODE
:
510 dc
.SetBackgroundMode(m_mode
);
518 wxDrawOp
*wxOpSetGDI::Copy(wxPseudoMetaFile
*newImage
)
520 wxOpSetGDI
*newOp
= new wxOpSetGDI(m_op
, newImage
, m_gdiIndex
, m_mode
);
528 wxExpr
*wxOpSetGDI::WriteExpr(wxPseudoMetaFile
*image
)
530 wxExpr
*expr
= new wxExpr(wxExprList
);
531 expr
->Append(new wxExpr((long)m_op
));
535 case DRAWOP_SET_BRUSH
:
536 case DRAWOP_SET_FONT
:
538 expr
->Append(new wxExpr((long)m_gdiIndex
));
541 case DRAWOP_SET_TEXT_COLOUR
:
542 case DRAWOP_SET_BK_COLOUR
:
544 expr
->Append(new wxExpr((long)m_r
));
545 expr
->Append(new wxExpr((long)m_g
));
546 expr
->Append(new wxExpr((long)m_b
));
549 case DRAWOP_SET_BK_MODE
:
551 expr
->Append(new wxExpr((long)m_mode
));
560 void wxOpSetGDI::ReadExpr(wxPseudoMetaFile
*image
, wxExpr
*expr
)
565 case DRAWOP_SET_BRUSH
:
566 case DRAWOP_SET_FONT
:
568 m_gdiIndex
= (int)expr
->Nth(1)->IntegerValue();
571 case DRAWOP_SET_TEXT_COLOUR
:
572 case DRAWOP_SET_BK_COLOUR
:
574 m_r
= (unsigned char)expr
->Nth(1)->IntegerValue();
575 m_g
= (unsigned char)expr
->Nth(2)->IntegerValue();
576 m_b
= (unsigned char)expr
->Nth(3)->IntegerValue();
579 case DRAWOP_SET_BK_MODE
:
581 m_mode
= (int)expr
->Nth(1)->IntegerValue();
591 * Set/destroy clipping
595 wxOpSetClipping::wxOpSetClipping(int theOp
, double theX1
, double theY1
,
596 double theX2
, double theY2
):wxDrawOp(theOp
)
604 wxDrawOp
*wxOpSetClipping::Copy(wxPseudoMetaFile
*newImage
)
606 wxOpSetClipping
*newOp
= new wxOpSetClipping(m_op
, m_x1
, m_y1
, m_x2
, m_y2
);
610 void wxOpSetClipping::Do(wxDC
& dc
, double xoffset
, double yoffset
)
614 case DRAWOP_SET_CLIPPING_RECT
:
616 dc
.SetClippingRegion((long)(m_x1
+ xoffset
), (long)(m_y1
+ yoffset
), (long)(m_x2
+ xoffset
), (long)(m_y2
+ yoffset
));
619 case DRAWOP_DESTROY_CLIPPING_RECT
:
621 dc
.DestroyClippingRegion();
629 void wxOpSetClipping::Scale(double xScale
, double yScale
)
637 void wxOpSetClipping::Translate(double x
, double y
)
644 wxExpr
*wxOpSetClipping::WriteExpr(wxPseudoMetaFile
*image
)
646 wxExpr
*expr
= new wxExpr(wxExprList
);
647 expr
->Append(new wxExpr((long)m_op
));
650 case DRAWOP_SET_CLIPPING_RECT
:
652 expr
->Append(new wxExpr(m_x1
));
653 expr
->Append(new wxExpr(m_y1
));
654 expr
->Append(new wxExpr(m_x2
));
655 expr
->Append(new wxExpr(m_y2
));
664 void wxOpSetClipping::ReadExpr(wxPseudoMetaFile
*image
, wxExpr
*expr
)
668 case DRAWOP_SET_CLIPPING_RECT
:
670 m_x1
= expr
->Nth(1)->RealValue();
671 m_y1
= expr
->Nth(2)->RealValue();
672 m_x2
= expr
->Nth(3)->RealValue();
673 m_y2
= expr
->Nth(4)->RealValue();
683 * Draw line, rectangle, rounded rectangle, ellipse, point, arc, text
687 wxOpDraw::wxOpDraw(int theOp
, double theX1
, double theY1
, double theX2
, double theY2
,
688 double theRadius
, wxChar
*s
) : wxDrawOp(theOp
)
696 m_radius
= theRadius
;
697 if (s
) m_textString
= copystring(s
);
698 else m_textString
= NULL
;
701 wxOpDraw::~wxOpDraw()
703 if (m_textString
) delete[] m_textString
;
706 wxDrawOp
*wxOpDraw::Copy(wxPseudoMetaFile
*newImage
)
708 wxOpDraw
*newOp
= new wxOpDraw(m_op
, m_x1
, m_y1
, m_x2
, m_y2
, m_radius
, m_textString
);
714 void wxOpDraw::Do(wxDC
& dc
, double xoffset
, double yoffset
)
718 case DRAWOP_DRAW_LINE
:
720 dc
.DrawLine(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
), WXROUND(m_x2
+xoffset
), WXROUND(m_y2
+yoffset
));
723 case DRAWOP_DRAW_RECT
:
725 dc
.DrawRectangle(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
), WXROUND(m_x2
), WXROUND(m_y2
));
728 case DRAWOP_DRAW_ROUNDED_RECT
:
730 dc
.DrawRoundedRectangle(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
), WXROUND(m_x2
), WXROUND(m_y2
), m_radius
);
733 case DRAWOP_DRAW_ELLIPSE
:
735 dc
.DrawEllipse(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
), WXROUND(m_x2
), WXROUND(m_y2
));
738 case DRAWOP_DRAW_ARC
:
740 dc
.DrawArc(WXROUND(m_x2
+xoffset
), WXROUND(m_y2
+yoffset
),
741 WXROUND(m_x3
+xoffset
), WXROUND(m_y3
+yoffset
),
742 WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
));
745 case DRAWOP_DRAW_ELLIPTIC_ARC
:
747 const double pi
= 3.1415926535897932384626433832795 ;
749 // Convert back to degrees
751 WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
),
752 WXROUND(m_x2
), WXROUND(m_y2
),
753 WXROUND(m_x3
*(360.0/(2.0*pi
))), WXROUND(m_y3
*(360.0/(2.0*pi
))));
756 case DRAWOP_DRAW_POINT
:
758 dc
.DrawPoint(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
));
761 case DRAWOP_DRAW_TEXT
:
763 dc
.DrawText(m_textString
, WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
));
771 void wxOpDraw::Scale(double scaleX
, double scaleY
)
778 if (m_op
!= DRAWOP_DRAW_ELLIPTIC_ARC
)
787 void wxOpDraw::Translate(double x
, double y
)
794 case DRAWOP_DRAW_LINE
:
800 case DRAWOP_DRAW_ARC
:
808 case DRAWOP_DRAW_ELLIPTIC_ARC
:
817 void wxOpDraw::Rotate(double x
, double y
, double theta
, double sinTheta
, double cosTheta
)
819 double newX1
= m_x1
*cosTheta
- m_y1
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
820 double newY1
= m_x1
*sinTheta
+ m_y1
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
824 case DRAWOP_DRAW_LINE
:
826 double newX2
= m_x2
*cosTheta
- m_y2
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
827 double newY2
= m_x2
*sinTheta
+ m_y2
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
835 case DRAWOP_DRAW_RECT
:
836 case DRAWOP_DRAW_ROUNDED_RECT
:
837 case DRAWOP_DRAW_ELLIPTIC_ARC
:
839 // Assume only 0, 90, 180, 270 degree rotations.
840 // oldX1, oldY1 represents the top left corner. Find the
841 // bottom right, and rotate that. Then the width/height is the difference
842 // between x/y values.
843 double oldBottomRightX
= m_x1
+ m_x2
;
844 double oldBottomRightY
= m_y1
+ m_y2
;
845 double newBottomRightX
= oldBottomRightX
*cosTheta
- oldBottomRightY
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
846 double newBottomRightY
= oldBottomRightX
*sinTheta
+ oldBottomRightY
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
848 // Now find the new top-left, bottom-right coordinates.
849 double minX
= wxMin(newX1
, newBottomRightX
);
850 double minY
= wxMin(newY1
, newBottomRightY
);
851 double maxX
= wxMax(newX1
, newBottomRightX
);
852 double maxY
= wxMax(newY1
, newBottomRightY
);
856 m_x2
= maxX
- minX
; // width
857 m_y2
= maxY
- minY
; // height
859 if (m_op
== DRAWOP_DRAW_ELLIPTIC_ARC
)
861 // Add rotation to angles
868 case DRAWOP_DRAW_ARC
:
870 double newX2
= m_x2
*cosTheta
- m_y2
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
871 double newY2
= m_x2
*sinTheta
+ m_y2
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
872 double newX3
= m_x3
*cosTheta
- m_y3
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
873 double newY3
= m_x3
*sinTheta
+ m_y3
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
890 wxExpr
*wxOpDraw::WriteExpr(wxPseudoMetaFile
*image
)
892 wxExpr
*expr
= new wxExpr(wxExprList
);
893 expr
->Append(new wxExpr((long)m_op
));
896 case DRAWOP_DRAW_LINE
:
897 case DRAWOP_DRAW_RECT
:
898 case DRAWOP_DRAW_ELLIPSE
:
900 expr
->Append(new wxExpr(m_x1
));
901 expr
->Append(new wxExpr(m_y1
));
902 expr
->Append(new wxExpr(m_x2
));
903 expr
->Append(new wxExpr(m_y2
));
906 case DRAWOP_DRAW_ROUNDED_RECT
:
908 expr
->Append(new wxExpr(m_x1
));
909 expr
->Append(new wxExpr(m_y1
));
910 expr
->Append(new wxExpr(m_x2
));
911 expr
->Append(new wxExpr(m_y2
));
912 expr
->Append(new wxExpr(m_radius
));
915 case DRAWOP_DRAW_POINT
:
917 expr
->Append(new wxExpr(m_x1
));
918 expr
->Append(new wxExpr(m_y1
));
921 case DRAWOP_DRAW_TEXT
:
923 expr
->Append(new wxExpr(m_x1
));
924 expr
->Append(new wxExpr(m_y1
));
925 expr
->Append(new wxExpr(wxExprString
, m_textString
));
928 case DRAWOP_DRAW_ARC
:
929 case DRAWOP_DRAW_ELLIPTIC_ARC
:
931 expr
->Append(new wxExpr(m_x1
));
932 expr
->Append(new wxExpr(m_y1
));
933 expr
->Append(new wxExpr(m_x2
));
934 expr
->Append(new wxExpr(m_y2
));
935 expr
->Append(new wxExpr(m_x3
));
936 expr
->Append(new wxExpr(m_y3
));
947 void wxOpDraw::ReadExpr(wxPseudoMetaFile
*image
, wxExpr
*expr
)
951 case DRAWOP_DRAW_LINE
:
952 case DRAWOP_DRAW_RECT
:
953 case DRAWOP_DRAW_ELLIPSE
:
955 m_x1
= expr
->Nth(1)->RealValue();
956 m_y1
= expr
->Nth(2)->RealValue();
957 m_x2
= expr
->Nth(3)->RealValue();
958 m_y2
= expr
->Nth(4)->RealValue();
961 case DRAWOP_DRAW_ROUNDED_RECT
:
963 m_x1
= expr
->Nth(1)->RealValue();
964 m_y1
= expr
->Nth(2)->RealValue();
965 m_x2
= expr
->Nth(3)->RealValue();
966 m_y2
= expr
->Nth(4)->RealValue();
967 m_radius
= expr
->Nth(5)->RealValue();
970 case DRAWOP_DRAW_POINT
:
972 m_x1
= expr
->Nth(1)->RealValue();
973 m_y1
= expr
->Nth(2)->RealValue();
976 case DRAWOP_DRAW_TEXT
:
978 m_x1
= expr
->Nth(1)->RealValue();
979 m_y1
= expr
->Nth(2)->RealValue();
980 wxString
str(expr
->Nth(3)->StringValue());
981 m_textString
= copystring(str
);
984 case DRAWOP_DRAW_ARC
:
985 case DRAWOP_DRAW_ELLIPTIC_ARC
:
987 m_x1
= expr
->Nth(1)->RealValue();
988 m_y1
= expr
->Nth(2)->RealValue();
989 m_x2
= expr
->Nth(3)->RealValue();
990 m_y2
= expr
->Nth(4)->RealValue();
991 m_x3
= expr
->Nth(5)->RealValue();
992 m_y3
= expr
->Nth(6)->RealValue();
1004 * Draw polygon, polyline, spline
1008 wxOpPolyDraw::wxOpPolyDraw(int theOp
, int n
, wxRealPoint
*thePoints
):wxDrawOp(theOp
)
1011 m_points
= thePoints
;
1014 wxOpPolyDraw::~wxOpPolyDraw()
1019 wxDrawOp
*wxOpPolyDraw::Copy(wxPseudoMetaFile
*newImage
)
1021 wxRealPoint
*newPoints
= new wxRealPoint
[m_noPoints
];
1022 for (int i
= 0; i
< m_noPoints
; i
++)
1024 newPoints
[i
].x
= m_points
[i
].x
;
1025 newPoints
[i
].y
= m_points
[i
].y
;
1027 wxOpPolyDraw
*newOp
= new wxOpPolyDraw(m_op
, m_noPoints
, newPoints
);
1031 void wxOpPolyDraw::Do(wxDC
& dc
, double xoffset
, double yoffset
)
1035 case DRAWOP_DRAW_POLYLINE
:
1037 wxPoint
*actualPoints
= new wxPoint
[m_noPoints
];
1039 for (i
= 0; i
< m_noPoints
; i
++)
1041 actualPoints
[i
].x
= WXROUND(m_points
[i
].x
);
1042 actualPoints
[i
].y
= WXROUND(m_points
[i
].y
);
1045 dc
.DrawLines(m_noPoints
, actualPoints
, WXROUND(xoffset
), WXROUND(yoffset
));
1047 delete[] actualPoints
;
1050 case DRAWOP_DRAW_POLYGON
:
1052 wxPoint
*actualPoints
= new wxPoint
[m_noPoints
];
1054 for (i
= 0; i
< m_noPoints
; i
++)
1056 actualPoints
[i
].x
= WXROUND(m_points
[i
].x
);
1057 actualPoints
[i
].y
= WXROUND(m_points
[i
].y
);
1060 dc
.DrawPolygon(m_noPoints
, actualPoints
, WXROUND(xoffset
), WXROUND(yoffset
));
1062 delete[] actualPoints
;
1065 case DRAWOP_DRAW_SPLINE
:
1067 wxPoint
*actualPoints
= new wxPoint
[m_noPoints
];
1069 for (i
= 0; i
< m_noPoints
; i
++)
1071 actualPoints
[i
].x
= WXROUND(m_points
[i
].x
);
1072 actualPoints
[i
].y
= WXROUND(m_points
[i
].y
);
1075 dc
.DrawSpline(m_noPoints
, actualPoints
); // no offsets in DrawSpline // , xoffset, yoffset);
1077 delete[] actualPoints
;
1086 void wxOpPolyDraw::Scale(double scaleX
, double scaleY
)
1088 for (int i
= 0; i
< m_noPoints
; i
++)
1090 m_points
[i
].x
*= scaleX
;
1091 m_points
[i
].y
*= scaleY
;
1095 void wxOpPolyDraw::Translate(double x
, double y
)
1097 for (int i
= 0; i
< m_noPoints
; i
++)
1104 void wxOpPolyDraw::Rotate(double x
, double y
, double theta
, double sinTheta
, double cosTheta
)
1106 for (int i
= 0; i
< m_noPoints
; i
++)
1108 double x1
= m_points
[i
].x
;
1109 double y1
= m_points
[i
].y
;
1110 m_points
[i
].x
= x1
*cosTheta
- y1
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
1111 m_points
[i
].y
= x1
*sinTheta
+ y1
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
1116 wxExpr
*wxOpPolyDraw::WriteExpr(wxPseudoMetaFile
*image
)
1118 wxExpr
*expr
= new wxExpr(wxExprList
);
1119 expr
->Append(new wxExpr((long)m_op
));
1120 expr
->Append(new wxExpr((long)m_noPoints
));
1129 * Store each coordinate pair in a hex string to save space.
1130 * E.g. "1B9080CD". 4 hex digits per coordinate pair.
1134 for (int i
= 0; i
< m_noPoints
; i
++)
1136 long signedX
= (long)(m_points
[i
].x
*100.0);
1137 long signedY
= (long)(m_points
[i
].y
*100.0);
1139 // Scale to 0 -> 64K
1140 long unSignedX
= (long)(signedX
+ 32767.0);
1141 long unSignedY
= (long)(signedY
+ 32767.0);
1143 // IntToHex((unsigned int)signedX, buf2);
1144 // IntToHex((unsigned int)signedY, buf3);
1145 IntToHex((int)unSignedX
, buf2
);
1146 IntToHex((int)unSignedY
, buf3
);
1148 // Don't overrun the buffer
1151 strcat(oglBuffer
, buf2
);
1152 strcat(oglBuffer
, buf3
);
1155 expr
->Append(new wxExpr(wxExprString
, oglBuffer
));
1159 void wxOpPolyDraw::ReadExpr(wxPseudoMetaFile
*image
, wxExpr
*expr
)
1161 m_noPoints
= (int)expr
->Nth(1)->IntegerValue();
1166 m_points
= new wxRealPoint
[m_noPoints
];
1169 wxString hexString
= expr
->Nth(2)->StringValue();
1170 while (i
< m_noPoints
)
1172 buf1
[0] = hexString
[(size_t)bufPtr
];
1173 buf1
[1] = hexString
[(size_t)(bufPtr
+ 1)];
1174 buf1
[2] = hexString
[(size_t)(bufPtr
+ 2)];
1175 buf1
[3] = hexString
[(size_t)(bufPtr
+ 3)];
1178 buf2
[0] = hexString
[(size_t)(bufPtr
+ 4)];
1179 buf2
[1] = hexString
[(size_t)(bufPtr
+ 5)];
1180 buf2
[2] = hexString
[(size_t)(bufPtr
+ 6)];
1181 buf2
[3] = hexString
[(size_t)(bufPtr
+ 7)];
1186 // int signedX = (signed int)HexToInt(buf1);
1187 // int signedY = (signed int)HexToInt(buf2);
1188 long unSignedX
= HexToInt(buf1
);
1189 long unSignedY
= HexToInt(buf2
);
1190 // Scale -32K -> +32K
1191 long signedX
= unSignedX
- 32767;
1192 long signedY
= unSignedY
- 32767;
1194 int testX
= (signed int)unSignedX
;
1195 int testY
= (signed int)unSignedY
;
1198 m_points
[i
].x
= (double)(signedX
/ 100.0);
1199 m_points
[i
].y
= (double)(signedY
/ 100.0);
1206 // Draw an outline using the current operation.
1207 bool wxOpPolyDraw::OnDrawOutline(wxDC
& dc
, double x
, double y
, double w
, double h
, double oldW
, double oldH
)
1209 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1211 // Multiply all points by proportion of new size to old size
1212 double x_proportion
= (double)(fabs(w
/oldW
));
1213 double y_proportion
= (double)(fabs(h
/oldH
));
1216 wxPoint
*intPoints
= new wxPoint
[n
];
1218 for (i
= 0; i
< n
; i
++)
1220 intPoints
[i
].x
= WXROUND (x_proportion
* m_points
[i
].x
);
1221 intPoints
[i
].y
= WXROUND (y_proportion
* m_points
[i
].y
);
1223 dc
.DrawPolygon(n
, intPoints
, (long) x
, (long) y
);
1228 // Assume (x1, y1) is centre of box (most generally, line end at box)
1229 bool wxOpPolyDraw::GetPerimeterPoint(double x1
, double y1
,
1230 double x2
, double y2
,
1231 double *x3
, double *y3
,
1232 double xOffset
, double yOffset
,
1237 // First check for situation where the line is vertical,
1238 // and we would want to connect to a point on that vertical --
1239 // oglFindEndForPolyline can't cope with this (the arrow
1240 // gets drawn to the wrong place).
1241 if ((attachmentMode
== ATTACHMENT_MODE_NONE
) && (x1
== x2
))
1243 // Look for the point we'd be connecting to. This is
1246 for (i
= 0; i
< n
; i
++)
1248 wxRealPoint
*point
= & (m_points
[i
]);
1249 if (point
->x
== 0.0)
1251 if ((y2
> y1
) && (point
->y
> 0.0))
1253 *x3
= point
->x
+ xOffset
;
1254 *y3
= point
->y
+ yOffset
;
1257 else if ((y2
< y1
) && (point
->y
< 0.0))
1259 *x3
= point
->x
+ xOffset
;
1260 *y3
= point
->y
+ yOffset
;
1267 double *xpoints
= new double[n
];
1268 double *ypoints
= new double[n
];
1271 for (i
= 0; i
< n
; i
++)
1273 wxRealPoint
*point
= & (m_points
[i
]);
1274 xpoints
[i
] = point
->x
+ xOffset
;
1275 ypoints
[i
] = point
->y
+ yOffset
;
1278 oglFindEndForPolyline(n
, xpoints
, ypoints
,
1279 x1
, y1
, x2
, y2
, x3
, y3
);
1293 static char hexArray
[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B',
1294 'C', 'D', 'E', 'F' };
1296 // Convert unsigned 16-bit integer to 4-character hex string
1297 static void IntToHex(unsigned int dec
, char *buf
)
1299 int digit1
= (int)(dec
/4096);
1300 int digit2
= (int)((dec
- (digit1
*4096))/256);
1301 int digit3
= (int)((dec
- (digit1
*4096) - (digit2
*256))/16);
1302 int digit4
= dec
- (digit1
*4096 + digit2
*256 + digit3
*16);
1304 buf
[0] = hexArray
[digit1
];
1305 buf
[1] = hexArray
[digit2
];
1306 buf
[2] = hexArray
[digit3
];
1307 buf
[3] = hexArray
[digit4
];
1311 // One hex digit to decimal number
1312 static int HexToInt1(char hex
)
1354 // 4-digit hex string to unsigned integer
1355 static unsigned long HexToInt(char *buf
)
1357 long d1
= (long)(HexToInt1(buf
[0])*4096.0) ;
1358 long d2
= (long)(HexToInt1(buf
[1])*256.0) ;
1359 long d3
= (long)(HexToInt1(buf
[2])*16.0) ;
1360 long d4
= (long)(HexToInt1(buf
[3])) ;
1361 unsigned long n
= (long)(d1
+ d2
+ d3
+ d4
) ;
1366 * wxPseudo meta-file
1370 IMPLEMENT_DYNAMIC_CLASS(wxPseudoMetaFile
, wxObject
)
1372 wxPseudoMetaFile::wxPseudoMetaFile()
1374 m_currentRotation
= 0;
1375 m_rotateable
= TRUE
;
1378 m_outlinePen
= NULL
;
1383 wxPseudoMetaFile::wxPseudoMetaFile(wxPseudoMetaFile
& mf
)
1388 wxPseudoMetaFile::~wxPseudoMetaFile()
1393 void wxPseudoMetaFile::Clear()
1395 wxNode
*node
= m_ops
.GetFirst();
1398 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1400 node
= node
->GetNext();
1403 m_gdiObjects
.Clear();
1404 m_outlineColours
.Clear();
1405 m_fillColours
.Clear();
1409 void wxPseudoMetaFile::Draw(wxDC
& dc
, double xoffset
, double yoffset
)
1411 wxNode
*node
= m_ops
.GetFirst();
1414 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1415 op
->Do(dc
, xoffset
, yoffset
);
1416 node
= node
->GetNext();
1420 void wxPseudoMetaFile::Scale(double sx
, double sy
)
1422 wxNode
*node
= m_ops
.GetFirst();
1425 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1427 node
= node
->GetNext();
1433 void wxPseudoMetaFile::Translate(double x
, double y
)
1435 wxNode
*node
= m_ops
.GetFirst();
1438 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1439 op
->Translate(x
, y
);
1440 node
= node
->GetNext();
1444 void wxPseudoMetaFile::Rotate(double x
, double y
, double theta
)
1446 double theta1
= theta
-m_currentRotation
;
1447 if (theta1
== 0.0) return;
1448 double cosTheta
= (double)cos(theta1
);
1449 double sinTheta
= (double)sin(theta1
);
1451 wxNode
*node
= m_ops
.GetFirst();
1454 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1455 op
->Rotate(x
, y
, theta
, sinTheta
, cosTheta
);
1456 node
= node
->GetNext();
1458 m_currentRotation
= theta
;
1462 void wxPseudoMetaFile::WriteAttributes(wxExpr
*clause
, int whichAngle
)
1465 widthStr
.Printf(wxT("meta_width%d"), whichAngle
);
1468 heightStr
.Printf(wxT("meta_height%d"), whichAngle
);
1470 wxString outlineStr
;
1471 outlineStr
.Printf(wxT("outline_op%d"), whichAngle
);
1473 wxString rotateableStr
;
1474 rotateableStr
.Printf(wxT("meta_rotateable%d"), whichAngle
);
1476 // Write width and height
1477 clause
->AddAttributeValue(widthStr
, m_width
);
1478 clause
->AddAttributeValue(heightStr
, m_height
);
1479 clause
->AddAttributeValue(rotateableStr
, (long)m_rotateable
);
1480 clause
->AddAttributeValue(outlineStr
, (long)m_outlineOp
);
1482 // Write GDI objects
1485 wxNode
*node
= m_gdiObjects
.GetFirst();
1488 sprintf(buf
, "gdi%d_%d", whichAngle
, i
);
1489 wxObject
*obj
= (wxObject
*)node
->GetData();
1490 wxExpr
*expr
= NULL
;
1493 if (obj
->IsKindOf(CLASSINFO(wxPen
)))
1495 wxPen
*thePen
= (wxPen
*)obj
;
1496 expr
= new wxExpr(wxExprList
);
1497 expr
->Append(new wxExpr((long)gyTYPE_PEN
));
1498 expr
->Append(new wxExpr((long)thePen
->GetWidth()));
1499 expr
->Append(new wxExpr((long)thePen
->GetStyle()));
1500 expr
->Append(new wxExpr((long)thePen
->GetColour().Red()));
1501 expr
->Append(new wxExpr((long)thePen
->GetColour().Green()));
1502 expr
->Append(new wxExpr((long)thePen
->GetColour().Blue()));
1504 else if (obj
->IsKindOf(CLASSINFO(wxBrush
)))
1506 wxBrush
*theBrush
= (wxBrush
*)obj
;
1507 expr
= new wxExpr(wxExprList
);
1508 expr
->Append(new wxExpr((long)gyTYPE_BRUSH
));
1509 expr
->Append(new wxExpr((long)theBrush
->GetStyle()));
1510 expr
->Append(new wxExpr((long)theBrush
->GetColour().Red()));
1511 expr
->Append(new wxExpr((long)theBrush
->GetColour().Green()));
1512 expr
->Append(new wxExpr((long)theBrush
->GetColour().Blue()));
1514 else if (obj
->IsKindOf(CLASSINFO(wxFont
)))
1516 wxFont
*theFont
= (wxFont
*)obj
;
1517 expr
= new wxExpr(wxExprList
);
1518 expr
->Append(new wxExpr((long)gyTYPE_FONT
));
1519 expr
->Append(new wxExpr((long)theFont
->GetPointSize()));
1520 expr
->Append(new wxExpr((long)theFont
->GetFamily()));
1521 expr
->Append(new wxExpr((long)theFont
->GetStyle()));
1522 expr
->Append(new wxExpr((long)theFont
->GetWeight()));
1523 expr
->Append(new wxExpr((long)theFont
->GetUnderlined()));
1528 // If no recognised GDI object, append a place holder anyway.
1529 expr
= new wxExpr(wxExprList
);
1530 expr
->Append(new wxExpr((long)0));
1535 clause
->AddAttributeValue(buf
, expr
);
1538 node
= node
->GetNext();
1541 // Write drawing operations
1543 node
= m_ops
.GetFirst();
1546 sprintf(buf
, "op%d_%d", whichAngle
, i
);
1547 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1548 wxExpr
*expr
= op
->WriteExpr(this);
1551 clause
->AddAttributeValue(buf
, expr
);
1554 node
= node
->GetNext();
1557 // Write outline and fill GDI op lists (if any)
1558 if (m_outlineColours
.GetCount() > 0)
1560 wxExpr
*outlineExpr
= new wxExpr(wxExprList
);
1561 node
= m_outlineColours
.GetFirst();
1564 outlineExpr
->Append(new wxExpr((long)node
->GetData()));
1565 node
= node
->GetNext();
1567 wxString outlineObjectsStr
;
1568 outlineObjectsStr
.Printf(wxT("outline_objects%d"), whichAngle
);
1570 clause
->AddAttributeValue(outlineObjectsStr
, outlineExpr
);
1572 if (m_fillColours
.GetCount() > 0)
1574 wxExpr
*fillExpr
= new wxExpr(wxExprList
);
1575 node
= m_fillColours
.GetFirst();
1578 fillExpr
->Append(new wxExpr((long)node
->GetData()));
1579 node
= node
->GetNext();
1581 wxString fillObjectsStr
;
1582 fillObjectsStr
.Printf(wxT("fill_objects%d"), whichAngle
);
1584 clause
->AddAttributeValue(fillObjectsStr
, fillExpr
);
1589 void wxPseudoMetaFile::ReadAttributes(wxExpr
*clause
, int whichAngle
)
1592 widthStr
.Printf(wxT("meta_width%d"), whichAngle
);
1595 heightStr
.Printf(wxT("meta_height%d"), whichAngle
);
1597 wxString outlineStr
;
1598 outlineStr
.Printf(wxT("outline_op%d"), whichAngle
);
1600 wxString rotateableStr
;
1601 rotateableStr
.Printf(wxT("meta_rotateable%d"), whichAngle
);
1603 clause
->GetAttributeValue(widthStr
, m_width
);
1604 clause
->GetAttributeValue(heightStr
, m_height
);
1605 clause
->GetAttributeValue(outlineStr
, m_outlineOp
);
1607 int iVal
= (int) m_rotateable
;
1608 clause
->GetAttributeValue(rotateableStr
, iVal
);
1609 m_rotateable
= (iVal
!= 0);
1614 bool keepGoing
= TRUE
;
1617 sprintf(buf
, "gdi%d_%d", whichAngle
, i
);
1618 wxExpr
*expr
= NULL
;
1619 clause
->GetAttributeValue(buf
, &expr
);
1626 wxExpr
*idExpr
= expr
->Nth(0);
1627 switch (idExpr
->IntegerValue())
1631 int penWidth
= (int)expr
->Nth(1)->IntegerValue();
1632 int penStyle
= (int)expr
->Nth(2)->IntegerValue();
1633 int penRed
= (int)expr
->Nth(3)->IntegerValue();
1634 int penGreen
= (int)expr
->Nth(4)->IntegerValue();
1635 int penBlue
= (int)expr
->Nth(5)->IntegerValue();
1636 wxColour
col(penRed
, penGreen
, penBlue
);
1637 wxPen
*p
= wxThePenList
->FindOrCreatePen(col
, penWidth
, penStyle
);
1640 m_gdiObjects
.Append(p
);
1645 int brushStyle
= (int)expr
->Nth(1)->IntegerValue();
1646 int brushRed
= (int)expr
->Nth(2)->IntegerValue();
1647 int brushGreen
= (int)expr
->Nth(3)->IntegerValue();
1648 int brushBlue
= (int)expr
->Nth(4)->IntegerValue();
1649 wxColour
col(brushRed
, brushGreen
, brushBlue
);
1650 wxBrush
*b
= wxTheBrushList
->FindOrCreateBrush(col
, brushStyle
);
1653 m_gdiObjects
.Append(b
);
1658 int fontPointSize
= (int)expr
->Nth(1)->IntegerValue();
1659 int fontFamily
= (int)expr
->Nth(2)->IntegerValue();
1660 int fontStyle
= (int)expr
->Nth(3)->IntegerValue();
1661 int fontWeight
= (int)expr
->Nth(4)->IntegerValue();
1662 int fontUnderlined
= (int)expr
->Nth(5)->IntegerValue();
1663 m_gdiObjects
.Append(wxTheFontList
->FindOrCreateFont(fontPointSize
,
1664 fontFamily
, fontStyle
, fontWeight
, (fontUnderlined
!= 0)));
1670 m_gdiObjects
.Append(NULL
);
1678 // Now read in the operations
1683 sprintf(buf
, "op%d_%d", whichAngle
, i
);
1684 wxExpr
*expr
= NULL
;
1685 clause
->GetAttributeValue(buf
, &expr
);
1692 wxExpr
*idExpr
= expr
->Nth(0);
1693 int opId
= (int)idExpr
->IntegerValue();
1696 case DRAWOP_SET_PEN
:
1697 case DRAWOP_SET_BRUSH
:
1698 case DRAWOP_SET_FONT
:
1699 case DRAWOP_SET_TEXT_COLOUR
:
1700 case DRAWOP_SET_BK_COLOUR
:
1701 case DRAWOP_SET_BK_MODE
:
1703 wxOpSetGDI
*theOp
= new wxOpSetGDI(opId
, this, 0);
1704 theOp
->ReadExpr(this, expr
);
1705 m_ops
.Append(theOp
);
1709 case DRAWOP_SET_CLIPPING_RECT
:
1710 case DRAWOP_DESTROY_CLIPPING_RECT
:
1712 wxOpSetClipping
*theOp
= new wxOpSetClipping(opId
, 0.0, 0.0, 0.0, 0.0);
1713 theOp
->ReadExpr(this, expr
);
1714 m_ops
.Append(theOp
);
1718 case DRAWOP_DRAW_LINE
:
1719 case DRAWOP_DRAW_RECT
:
1720 case DRAWOP_DRAW_ROUNDED_RECT
:
1721 case DRAWOP_DRAW_ELLIPSE
:
1722 case DRAWOP_DRAW_POINT
:
1723 case DRAWOP_DRAW_ARC
:
1724 case DRAWOP_DRAW_TEXT
:
1726 wxOpDraw
*theOp
= new wxOpDraw(opId
, 0.0, 0.0, 0.0, 0.0);
1727 theOp
->ReadExpr(this, expr
);
1728 m_ops
.Append(theOp
);
1731 case DRAWOP_DRAW_SPLINE
:
1732 case DRAWOP_DRAW_POLYLINE
:
1733 case DRAWOP_DRAW_POLYGON
:
1735 wxOpPolyDraw
*theOp
= new wxOpPolyDraw(opId
, 0, NULL
);
1736 theOp
->ReadExpr(this, expr
);
1737 m_ops
.Append(theOp
);
1747 wxString outlineObjectsStr
;
1748 outlineObjectsStr
.Printf(wxT("outline_objects%d"), whichAngle
);
1750 // Now read in the list of outline and fill operations, if any
1751 wxExpr
*expr1
= clause
->AttributeValue(outlineObjectsStr
);
1754 wxExpr
*eachExpr
= expr1
->GetFirst();
1757 m_outlineColours
.Append((wxObject
*)eachExpr
->IntegerValue());
1758 eachExpr
= eachExpr
->GetNext();
1762 wxString fillObjectsStr
;
1763 fillObjectsStr
.Printf(wxT("fill_objects%d"), whichAngle
);
1765 expr1
= clause
->AttributeValue(fillObjectsStr
);
1768 wxExpr
*eachExpr
= expr1
->GetFirst();
1771 m_fillColours
.Append((wxObject
*)eachExpr
->IntegerValue());
1772 eachExpr
= eachExpr
->GetNext();
1778 // Does the copying for this object
1779 void wxPseudoMetaFile::Copy(wxPseudoMetaFile
& copy
)
1783 copy
.m_currentRotation
= m_currentRotation
;
1784 copy
.m_width
= m_width
;
1785 copy
.m_height
= m_height
;
1786 copy
.m_rotateable
= m_rotateable
;
1787 copy
.m_fillBrush
= m_fillBrush
;
1788 copy
.m_outlinePen
= m_outlinePen
;
1789 copy
.m_outlineOp
= m_outlineOp
;
1791 // Copy the GDI objects
1792 wxNode
*node
= m_gdiObjects
.GetFirst();
1795 wxObject
*obj
= (wxObject
*)node
->GetData();
1796 copy
.m_gdiObjects
.Append(obj
);
1797 node
= node
->GetNext();
1800 // Copy the operations
1801 node
= m_ops
.GetFirst();
1804 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1805 copy
.m_ops
.Append(op
->Copy(©
));
1806 node
= node
->GetNext();
1809 // Copy the outline/fill operations
1810 node
= m_outlineColours
.GetFirst();
1813 copy
.m_outlineColours
.Append((wxObject
*)node
->GetData());
1814 node
= node
->GetNext();
1816 node
= m_fillColours
.GetFirst();
1819 copy
.m_fillColours
.Append((wxObject
*)node
->GetData());
1820 node
= node
->GetNext();
1825 * Pass size of existing image; scale height to
1826 * fit width and return new width and height.
1830 bool wxPseudoMetaFile::LoadFromMetaFile(const wxString
& filename
, double *rwidth
, double *rheight
)
1832 if (!wxFileExists(filename
))
1835 wxXMetaFile
*metaFile
= new wxXMetaFile
;
1837 if (!metaFile
->ReadFile(filename
))
1846 // Convert from metafile records to wxDrawnShape records
1847 wxNode
*node
= metaFile
->metaRecords
.GetFirst();
1850 wxMetaRecord
*record
= (wxMetaRecord
*)node
->GetData();
1851 switch (record
->metaFunction
)
1853 case META_SETBKCOLOR
:
1855 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_BK_COLOUR
, this, 0);
1856 op
->m_r
= (unsigned char)record
->param1
;
1857 op
->m_g
= (unsigned char)record
->param2
;
1858 op
->m_b
= (unsigned char)record
->param3
;
1862 case META_SETBKMODE
:
1864 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_BK_MODE
, this, 0, (int)record
->param1
);
1868 case META_SETMAPMODE
:
1872 // case META_SETROP2:
1873 // case META_SETRELABS:
1874 // case META_SETPOLYFILLMODE:
1875 // case META_SETSTRETCHBLTMODE:
1876 // case META_SETTEXTCHAREXTRA:
1877 case META_SETTEXTCOLOR
:
1879 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_TEXT_COLOUR
, this, 0);
1880 op
->m_r
= (unsigned char)record
->param1
;
1881 op
->m_g
= (unsigned char)record
->param2
;
1882 op
->m_b
= (unsigned char)record
->param3
;
1886 // case META_SETTEXTJUSTIFICATION:
1887 // case META_SETWINDOWORG:
1888 // case META_SETWINDOWEXT:
1889 // case META_SETVIEWPORTORG:
1890 // case META_SETVIEWPORTEXT:
1891 // case META_OFFSETWINDOWORG:
1892 // case META_SCALEWINDOWEXT:
1893 // case META_OFFSETVIEWPORTORG:
1894 // case META_SCALEVIEWPORTEXT:
1897 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_LINE
, (double)lastX
, (double)lastY
,
1898 (double)record
->param1
, (double)record
->param2
);
1904 lastX
= (double)record
->param1
;
1905 lastY
= (double)record
->param2
;
1908 case META_EXCLUDECLIPRECT
:
1911 wxMetaRecord *rec = new wxMetaRecord(META_EXCLUDECLIPRECT);
1912 rec->param4 = getshort(handle); // m_y2
1913 rec->param3 = getshort(handle); // x2
1914 rec->param2 = getshort(handle); // y1
1915 rec->param1 = getshort(handle); // x1
1919 case META_INTERSECTCLIPRECT
:
1922 rec->param4 = getshort(handle); // m_y2
1923 rec->param3 = getshort(handle); // x2
1924 rec->param2 = getshort(handle); // y1
1925 rec->param1 = getshort(handle); // x1
1929 // case META_ARC: // DO!!!
1932 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_ELLIPSE
,
1933 (double)record
->param1
, (double)record
->param2
,
1934 (double)(record
->param3
- record
->param1
),
1935 (double)(record
->param4
- record
->param2
));
1939 // case META_FLOODFILL:
1940 // case META_PIE: // DO!!!
1941 case META_RECTANGLE
:
1943 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_RECT
,
1944 (double)record
->param1
, (double)record
->param2
,
1945 (double)(record
->param3
- record
->param1
),
1946 (double)(record
->param4
- record
->param2
));
1950 case META_ROUNDRECT
:
1952 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_ROUNDED_RECT
,
1953 (double)record
->param1
, (double)record
->param2
,
1954 (double)(record
->param3
- record
->param1
),
1955 (double)(record
->param4
- record
->param2
), (double)record
->param5
);
1959 // case META_PATBLT:
1960 // case META_SAVEDC:
1963 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_POINT
,
1964 (double)record
->param1
, (double)record
->param2
,
1967 // SHOULD SET THE COLOUR - SET PEN?
1968 // rec->param3 = getint(handle); // COLORREF
1972 // case META_OFFSETCLIPRGN:
1975 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_TEXT
,
1976 (double)record
->param1
, (double)record
->param2
,
1977 0.0, 0.0, 0.0, record
->stringParam
);
1981 // case META_BITBLT:
1982 // case META_STRETCHBLT:
1985 int n
= (int)record
->param1
;
1986 wxRealPoint
*newPoints
= new wxRealPoint
[n
];
1987 for (int i
= 0; i
< n
; i
++)
1989 newPoints
[i
].x
= record
->points
[i
].x
;
1990 newPoints
[i
].y
= record
->points
[i
].y
;
1993 wxOpPolyDraw
*op
= new wxOpPolyDraw(DRAWOP_DRAW_POLYGON
, n
, newPoints
);
1999 int n
= (int)record
->param1
;
2000 wxRealPoint
*newPoints
= new wxRealPoint
[n
];
2001 for (int i
= 0; i
< n
; i
++)
2003 newPoints
[i
].x
= record
->points
[i
].x
;
2004 newPoints
[i
].y
= record
->points
[i
].y
;
2007 wxOpPolyDraw
*op
= new wxOpPolyDraw(DRAWOP_DRAW_POLYLINE
, n
, newPoints
);
2011 // case META_ESCAPE:
2012 // case META_RESTOREDC:
2013 // case META_FILLREGION:
2014 // case META_FRAMEREGION:
2015 // case META_INVERTREGION:
2016 // case META_PAINTREGION:
2017 // case META_SELECTCLIPREGION: // DO THIS!
2018 case META_SELECTOBJECT
:
2020 // The pen, brush etc. has already been created when the metafile
2021 // was read in, so we don't create it - we set it.
2022 wxNode
*recNode
= metaFile
->gdiObjects
.Item((int)record
->param2
);
2025 wxMetaRecord
*gdiRec
= (wxMetaRecord
*)recNode
->GetData();
2026 if (gdiRec
&& (gdiRec
->param1
!= 0))
2028 wxObject
*obj
= (wxObject
*)gdiRec
->param1
;
2029 if (obj
->IsKindOf(CLASSINFO(wxPen
)))
2031 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_PEN
, this, (int)record
->param2
);
2034 else if (obj
->IsKindOf(CLASSINFO(wxBrush
)))
2036 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_BRUSH
, this, (int)record
->param2
);
2039 else if (obj
->IsKindOf(CLASSINFO(wxFont
)))
2041 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_FONT
, this, (int)record
->param2
);
2048 // case META_SETTEXTALIGN:
2049 // case META_DRAWTEXT:
2051 // case META_SETMAPPERFLAGS:
2052 // case META_EXTTEXTOUT:
2053 // case META_SETDIBTODEV:
2054 // case META_SELECTPALETTE:
2055 // case META_REALIZEPALETTE:
2056 // case META_ANIMATEPALETTE:
2057 // case META_SETPALENTRIES:
2058 // case META_POLYPOLYGON:
2059 // case META_RESIZEPALETTE:
2060 // case META_DIBBITBLT:
2061 // case META_DIBSTRETCHBLT:
2062 case META_DIBCREATEPATTERNBRUSH
:
2065 m_gdiObjects
.Append(NULL
);
2068 // case META_STRETCHDIB:
2069 // case META_EXTFLOODFILL:
2070 // case META_RESETDC:
2071 // case META_STARTDOC:
2072 // case META_STARTPAGE:
2073 // case META_ENDPAGE:
2074 // case META_ABORTDOC:
2075 // case META_ENDDOC:
2076 // case META_DELETEOBJECT: // DO!!
2077 case META_CREATEPALETTE
:
2080 m_gdiObjects
.Append(NULL
);
2083 case META_CREATEBRUSH
:
2086 m_gdiObjects
.Append(NULL
);
2089 case META_CREATEPATTERNBRUSH
:
2092 m_gdiObjects
.Append(NULL
);
2095 case META_CREATEPENINDIRECT
:
2097 // The pen is created when the metafile is read in.
2098 // We keep track of all the GDI objects needed for this
2099 // image so when reading the wxDrawnShape from file,
2100 // we can read in all the GDI objects, then refer
2101 // to them by an index starting from zero thereafter.
2102 m_gdiObjects
.Append((wxObject
*)record
->param1
);
2105 case META_CREATEFONTINDIRECT
:
2107 m_gdiObjects
.Append((wxObject
*)record
->param1
);
2110 case META_CREATEBRUSHINDIRECT
:
2112 // Don't have to do anything here: the pen is created
2113 // when the metafile is read in.
2114 m_gdiObjects
.Append((wxObject
*)record
->param1
);
2117 case META_CREATEBITMAPINDIRECT
:
2120 m_gdiObjects
.Append(NULL
);
2123 case META_CREATEBITMAP
:
2126 m_gdiObjects
.Append(NULL
);
2129 case META_CREATEREGION
:
2132 m_gdiObjects
.Append(NULL
);
2140 node
= node
->GetNext();
2142 double actualWidth
= (double)fabs(metaFile
->right
- metaFile
->left
);
2143 double actualHeight
= (double)fabs(metaFile
->bottom
- metaFile
->top
);
2145 double initialScaleX
= 1.0;
2146 double initialScaleY
= 1.0;
2148 double xoffset
, yoffset
;
2150 // Translate so origin is at centre of rectangle
2151 if (metaFile
->bottom
> metaFile
->top
)
2152 yoffset
= - (double)((metaFile
->bottom
- metaFile
->top
)/2.0);
2154 yoffset
= - (double)((metaFile
->top
- metaFile
->bottom
)/2.0);
2156 if (metaFile
->right
> metaFile
->left
)
2157 xoffset
= - (double)((metaFile
->right
- metaFile
->left
)/2.0);
2159 xoffset
= - (double)((metaFile
->left
- metaFile
->right
)/2.0);
2161 Translate(xoffset
, yoffset
);
2163 // Scale to a reasonable size (take the width of this wxDrawnShape
2165 if (actualWidth
!= 0.0)
2167 initialScaleX
= (double)((*rwidth
) / actualWidth
);
2168 initialScaleY
= initialScaleX
;
2169 (*rheight
) = initialScaleY
*actualHeight
;
2171 Scale(initialScaleX
, initialScaleY
);
2173 m_width
= (actualWidth
*initialScaleX
);
2174 m_height
= *rheight
;
2180 // Scale to fit size
2181 void wxPseudoMetaFile::ScaleTo(double w
, double h
)
2183 double scaleX
= (double)(w
/m_width
);
2184 double scaleY
= (double)(h
/m_height
);
2187 Scale(scaleX
, scaleY
);
2190 void wxPseudoMetaFile::GetBounds(double *boundMinX
, double *boundMinY
, double *boundMaxX
, double *boundMaxY
)
2192 double maxX
= (double) -99999.9;
2193 double maxY
= (double) -99999.9;
2194 double minX
= (double) 99999.9;
2195 double minY
= (double) 99999.9;
2197 wxNode
*node
= m_ops
.GetFirst();
2200 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
2201 switch (op
->GetOp())
2203 case DRAWOP_DRAW_LINE
:
2204 case DRAWOP_DRAW_RECT
:
2205 case DRAWOP_DRAW_ROUNDED_RECT
:
2206 case DRAWOP_DRAW_ELLIPSE
:
2207 case DRAWOP_DRAW_POINT
:
2208 case DRAWOP_DRAW_TEXT
:
2210 wxOpDraw
*opDraw
= (wxOpDraw
*)op
;
2211 if (opDraw
->m_x1
< minX
) minX
= opDraw
->m_x1
;
2212 if (opDraw
->m_x1
> maxX
) maxX
= opDraw
->m_x1
;
2213 if (opDraw
->m_y1
< minY
) minY
= opDraw
->m_y1
;
2214 if (opDraw
->m_y1
> maxY
) maxY
= opDraw
->m_y1
;
2215 if (op
->GetOp() == DRAWOP_DRAW_LINE
)
2217 if (opDraw
->m_x2
< minX
) minX
= opDraw
->m_x2
;
2218 if (opDraw
->m_x2
> maxX
) maxX
= opDraw
->m_x2
;
2219 if (opDraw
->m_y2
< minY
) minY
= opDraw
->m_y2
;
2220 if (opDraw
->m_y2
> maxY
) maxY
= opDraw
->m_y2
;
2222 else if (op
->GetOp() == DRAWOP_DRAW_RECT
||
2223 op
->GetOp() == DRAWOP_DRAW_ROUNDED_RECT
||
2224 op
->GetOp() == DRAWOP_DRAW_ELLIPSE
)
2226 if ((opDraw
->m_x1
+ opDraw
->m_x2
) < minX
) minX
= (opDraw
->m_x1
+ opDraw
->m_x2
);
2227 if ((opDraw
->m_x1
+ opDraw
->m_x2
) > maxX
) maxX
= (opDraw
->m_x1
+ opDraw
->m_x2
);
2228 if ((opDraw
->m_y1
+ opDraw
->m_y2
) < minY
) minY
= (opDraw
->m_y1
+ opDraw
->m_y2
);
2229 if ((opDraw
->m_y1
+ opDraw
->m_y2
) > maxY
) maxY
= (opDraw
->m_y1
+ opDraw
->m_y2
);
2233 case DRAWOP_DRAW_ARC
:
2235 // TODO: don't yet know how to calculate the bounding box
2236 // for an arc. So pretend it's a line; to get a correct
2237 // bounding box, draw a blank rectangle first, of the correct
2239 wxOpDraw
*opDraw
= (wxOpDraw
*)op
;
2240 if (opDraw
->m_x1
< minX
) minX
= opDraw
->m_x1
;
2241 if (opDraw
->m_x1
> maxX
) maxX
= opDraw
->m_x1
;
2242 if (opDraw
->m_y1
< minY
) minY
= opDraw
->m_y1
;
2243 if (opDraw
->m_y1
> maxY
) maxY
= opDraw
->m_y1
;
2244 if (opDraw
->m_x2
< minX
) minX
= opDraw
->m_x2
;
2245 if (opDraw
->m_x2
> maxX
) maxX
= opDraw
->m_x2
;
2246 if (opDraw
->m_y2
< minY
) minY
= opDraw
->m_y2
;
2247 if (opDraw
->m_y2
> maxY
) maxY
= opDraw
->m_y2
;
2250 case DRAWOP_DRAW_POLYLINE
:
2251 case DRAWOP_DRAW_POLYGON
:
2252 case DRAWOP_DRAW_SPLINE
:
2254 wxOpPolyDraw
*poly
= (wxOpPolyDraw
*)op
;
2255 for (int i
= 0; i
< poly
->m_noPoints
; i
++)
2257 if (poly
->m_points
[i
].x
< minX
) minX
= poly
->m_points
[i
].x
;
2258 if (poly
->m_points
[i
].x
> maxX
) maxX
= poly
->m_points
[i
].x
;
2259 if (poly
->m_points
[i
].y
< minY
) minY
= poly
->m_points
[i
].y
;
2260 if (poly
->m_points
[i
].y
> maxY
) maxY
= poly
->m_points
[i
].y
;
2267 node
= node
->GetNext();
2275 *w = (double)fabs(maxX - minX);
2276 *h = (double)fabs(maxY - minY);
2280 // Calculate size from current operations
2281 void wxPseudoMetaFile::CalculateSize(wxDrawnShape
* shape
)
2283 double boundMinX
, boundMinY
, boundMaxX
, boundMaxY
;
2285 GetBounds(& boundMinX
, & boundMinY
, & boundMaxX
, & boundMaxY
);
2287 SetSize(boundMaxX
- boundMinX
, boundMaxY
- boundMinY
);
2291 shape
->SetWidth(m_width
);
2292 shape
->SetHeight(m_height
);
2296 // Set of functions for drawing into a pseudo metafile.
2297 // They use integers, but doubles are used internally for accuracy
2300 void wxPseudoMetaFile::DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
)
2302 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_LINE
,
2303 (double) pt1
.x
, (double) pt1
.y
, (double) pt2
.x
, (double) pt2
.y
);
2305 m_ops
.Append(theOp
);
2308 void wxPseudoMetaFile::DrawRectangle(const wxRect
& rect
)
2310 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_RECT
,
2311 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2313 m_ops
.Append(theOp
);
2316 void wxPseudoMetaFile::DrawRoundedRectangle(const wxRect
& rect
, double radius
)
2318 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_ROUNDED_RECT
,
2319 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2321 theOp
->m_radius
= radius
;
2323 m_ops
.Append(theOp
);
2326 void wxPseudoMetaFile::DrawEllipse(const wxRect
& rect
)
2328 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_ELLIPSE
,
2329 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2331 m_ops
.Append(theOp
);
2334 void wxPseudoMetaFile::DrawArc(const wxPoint
& centrePt
, const wxPoint
& startPt
, const wxPoint
& endPt
)
2336 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_ARC
,
2337 (double) centrePt
.x
, (double) centrePt
.y
, (double) startPt
.x
, (double) startPt
.y
);
2339 theOp
->m_x3
= (double) endPt
.x
;
2340 theOp
->m_y3
= (double) endPt
.y
;
2342 m_ops
.Append(theOp
);
2345 void wxPseudoMetaFile::DrawEllipticArc(const wxRect
& rect
, double startAngle
, double endAngle
)
2347 const double pi
= 3.1415926535897932384626433832795 ;
2349 double startAngleRadians
= startAngle
* (pi
*2.0/360.0);
2350 double endAngleRadians
= endAngle
* (pi
*2.0/360.0);
2352 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_ELLIPTIC_ARC
,
2353 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2355 theOp
->m_x3
= startAngleRadians
;
2356 theOp
->m_y3
= endAngleRadians
;
2358 m_ops
.Append(theOp
);
2361 void wxPseudoMetaFile::DrawPoint(const wxPoint
& pt
)
2363 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_POINT
,
2364 (double) pt
.x
, (double) pt
.y
, 0.0, 0.0);
2366 m_ops
.Append(theOp
);
2369 void wxPseudoMetaFile::DrawText(const wxString
& text
, const wxPoint
& pt
)
2371 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_TEXT
,
2372 (double) pt
.x
, (double) pt
.y
, 0.0, 0.0);
2374 theOp
->m_textString
= copystring(text
);
2376 m_ops
.Append(theOp
);
2379 void wxPseudoMetaFile::DrawLines(int n
, wxPoint pts
[])
2381 wxRealPoint
* realPoints
= new wxRealPoint
[n
];
2383 for (i
= 0; i
< n
; i
++)
2385 realPoints
[i
].x
= pts
[i
].x
;
2386 realPoints
[i
].y
= pts
[i
].y
;
2388 wxOpPolyDraw
* theOp
= new wxOpPolyDraw(DRAWOP_DRAW_POLYLINE
, n
, realPoints
);
2389 m_ops
.Append(theOp
);
2392 void wxPseudoMetaFile::DrawPolygon(int n
, wxPoint pts
[], int flags
)
2394 wxRealPoint
* realPoints
= new wxRealPoint
[n
];
2396 for (i
= 0; i
< n
; i
++)
2398 realPoints
[i
].x
= pts
[i
].x
;
2399 realPoints
[i
].y
= pts
[i
].y
;
2401 wxOpPolyDraw
* theOp
= new wxOpPolyDraw(DRAWOP_DRAW_POLYGON
, n
, realPoints
);
2402 m_ops
.Append(theOp
);
2404 if (flags
& oglMETAFLAGS_OUTLINE
)
2405 m_outlineOp
= (m_ops
.GetCount() - 1);
2408 void wxPseudoMetaFile::DrawSpline(int n
, wxPoint pts
[])
2410 wxRealPoint
* realPoints
= new wxRealPoint
[n
];
2412 for (i
= 0; i
< n
; i
++)
2414 realPoints
[i
].x
= pts
[i
].x
;
2415 realPoints
[i
].y
= pts
[i
].y
;
2417 wxOpPolyDraw
* theOp
= new wxOpPolyDraw(DRAWOP_DRAW_SPLINE
, n
, realPoints
);
2418 m_ops
.Append(theOp
);
2421 void wxPseudoMetaFile::SetClippingRect(const wxRect
& rect
)
2423 wxOpSetClipping
* theOp
= new wxOpSetClipping(DRAWOP_SET_CLIPPING_RECT
,
2424 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2427 void wxPseudoMetaFile::DestroyClippingRect()
2429 wxOpSetClipping
* theOp
= new wxOpSetClipping(DRAWOP_DESTROY_CLIPPING_RECT
,
2430 0.0, 0.0, 0.0, 0.0);
2432 m_ops
.Append(theOp
);
2435 void wxPseudoMetaFile::SetPen(wxPen
* pen
, bool isOutline
)
2437 m_gdiObjects
.Append(pen
);
2438 int n
= m_gdiObjects
.GetCount();
2440 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_PEN
, this, n
- 1);
2442 m_ops
.Append(theOp
);
2446 m_outlineColours
.Append((wxObject
*) (n
- 1));
2450 void wxPseudoMetaFile::SetBrush(wxBrush
* brush
, bool isFill
)
2452 m_gdiObjects
.Append(brush
);
2453 int n
= m_gdiObjects
.GetCount();
2455 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_BRUSH
, this, n
- 1);
2457 m_ops
.Append(theOp
);
2461 m_fillColours
.Append((wxObject
*) (n
- 1));
2465 void wxPseudoMetaFile::SetFont(wxFont
* font
)
2467 m_gdiObjects
.Append(font
);
2468 int n
= m_gdiObjects
.GetCount();
2470 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_FONT
, this, n
- 1);
2472 m_ops
.Append(theOp
);
2475 void wxPseudoMetaFile::SetTextColour(const wxColour
& colour
)
2477 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_TEXT_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::SetBackgroundColour(const wxColour
& colour
)
2487 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_BK_COLOUR
, this, 0);
2488 theOp
->m_r
= colour
.Red();
2489 theOp
->m_g
= colour
.Green();
2490 theOp
->m_b
= colour
.Blue();
2492 m_ops
.Append(theOp
);
2495 void wxPseudoMetaFile::SetBackgroundMode(int mode
)
2497 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_BK_MODE
, this, 0, mode
);
2499 m_ops
.Append(theOp
);