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"
28 #include <wx/wxexpr.h>
30 #include <wx/ogl/basic.h>
31 #include <wx/ogl/basicp.h>
32 #include <wx/ogl/canvas.h>
33 #include <wx/ogl/mfutils.h>
34 #include <wx/ogl/drawn.h>
35 #include <wx/ogl/drawnp.h>
36 #include <wx/ogl/misc.h>
40 static void IntToHex(unsigned int dec
, char *buf
);
41 static unsigned long HexToInt(char *buf
);
42 extern char *oglBuffer
;
45 #define gyTYPE_BRUSH 41
46 #define gyTYPE_FONT 42
53 IMPLEMENT_DYNAMIC_CLASS(wxDrawnShape
, wxRectangleShape
)
55 wxDrawnShape::wxDrawnShape():wxRectangleShape(100.0, 50.0)
58 m_currentAngle
= oglDRAWN_ANGLE_0
;
61 wxDrawnShape::~wxDrawnShape()
65 void wxDrawnShape::OnDraw(wxDC
& dc
)
67 // Pass pen and brush in case we have force outline
69 if (m_shadowMode
!= SHADOW_NONE
)
72 m_metafiles
[m_currentAngle
].m_fillBrush
= m_shadowBrush
;
73 m_metafiles
[m_currentAngle
].m_outlinePen
= g_oglTransparentPen
;
74 m_metafiles
[m_currentAngle
].Draw(dc
, m_xpos
+ m_shadowOffsetX
, m_ypos
+ m_shadowOffsetY
);
77 m_metafiles
[m_currentAngle
].m_outlinePen
= m_pen
;
78 m_metafiles
[m_currentAngle
].m_fillBrush
= m_brush
;
79 m_metafiles
[m_currentAngle
].Draw(dc
, m_xpos
, m_ypos
);
82 void wxDrawnShape::SetSize(double w
, double h
, bool recursive
)
84 SetAttachmentSize(w
, h
);
88 if (GetWidth() == 0.0)
90 else scaleX
= w
/GetWidth();
91 if (GetHeight() == 0.0)
93 else scaleY
= h
/GetHeight();
96 for (i
= 0; i
< 4; i
++)
98 if (m_metafiles
[i
].IsValid())
99 m_metafiles
[i
].Scale(scaleX
, scaleY
);
103 SetDefaultRegionSize();
106 void wxDrawnShape::Scale(double sx
, double sy
)
109 for (i
= 0; i
< 4; i
++)
111 if (m_metafiles
[i
].IsValid())
113 m_metafiles
[i
].Scale(sx
, sy
);
114 m_metafiles
[i
].CalculateSize(this);
119 void wxDrawnShape::Translate(double x
, double y
)
122 for (i
= 0; i
< 4; i
++)
124 if (m_metafiles
[i
].IsValid())
126 m_metafiles
[i
].Translate(x
, y
);
127 m_metafiles
[i
].CalculateSize(this);
132 // theta is absolute rotation from the zero position
133 void wxDrawnShape::Rotate(double x
, double y
, double theta
)
135 m_currentAngle
= DetermineMetaFile(theta
);
137 if (m_currentAngle
== 0)
140 if (!m_metafiles
[0].GetRotateable())
143 m_metafiles
[0].Rotate(x
, y
, theta
);
146 double actualTheta
= theta
-m_rotation
;
148 // Rotate attachment points
149 double sinTheta
= (double)sin(actualTheta
);
150 double cosTheta
= (double)cos(actualTheta
);
151 wxNode
*node
= m_attachmentPoints
.GetFirst();
154 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->GetData();
155 double x1
= point
->m_x
;
156 double y1
= point
->m_y
;
157 point
->m_x
= x1
*cosTheta
- y1
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
158 point
->m_y
= x1
*sinTheta
+ y1
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
159 node
= node
->GetNext();
163 m_metafiles
[m_currentAngle
].CalculateSize(this);
166 // Which metafile do we use now? Based on current rotation and validity
169 int wxDrawnShape::DetermineMetaFile(double rotation
)
171 double tolerance
= 0.0001;
172 const double pi
= 3.1415926535897932384626433832795 ;
174 double angle2
= pi
/2.0;
176 double angle4
= 3.0*pi
/2.0;
178 int whichMetafile
= 0;
180 if (oglRoughlyEqual(rotation
, angle1
, tolerance
))
184 else if (oglRoughlyEqual(rotation
, angle2
, tolerance
))
188 else if (oglRoughlyEqual(rotation
, angle3
, tolerance
))
192 else if (oglRoughlyEqual(rotation
, angle4
, tolerance
))
197 if ((whichMetafile
> 0) && !m_metafiles
[whichMetafile
].IsValid())
200 return whichMetafile
;
203 void wxDrawnShape::OnDrawOutline(wxDC
& dc
, double x
, double y
, double w
, double h
)
205 if (m_metafiles
[m_currentAngle
].GetOutlineOp() != -1)
207 wxNode
* node
= m_metafiles
[m_currentAngle
].GetOps().Item(m_metafiles
[m_currentAngle
].GetOutlineOp());
208 wxASSERT (node
!= NULL
);
209 wxDrawOp
* op
= (wxDrawOp
*) node
->GetData();
211 if (op
->OnDrawOutline(dc
, x
, y
, w
, h
, m_width
, m_height
))
215 // Default... just use a rectangle
216 wxRectangleShape::OnDrawOutline(dc
, x
, y
, w
, h
);
219 // Get the perimeter point using the special outline op, if there is one,
220 // otherwise use default wxRectangleShape scheme
221 bool wxDrawnShape::GetPerimeterPoint(double x1
, double y1
,
222 double x2
, double y2
,
223 double *x3
, double *y3
)
225 if (m_metafiles
[m_currentAngle
].GetOutlineOp() != -1)
227 wxNode
* node
= m_metafiles
[m_currentAngle
].GetOps().Item(m_metafiles
[m_currentAngle
].GetOutlineOp());
228 wxASSERT (node
!= NULL
);
229 wxDrawOp
* op
= (wxDrawOp
*) node
->GetData();
231 if (op
->GetPerimeterPoint(x1
, y1
, x2
, y2
, x3
, y3
, GetX(), GetY(), GetAttachmentMode()))
235 // Default... just use a rectangle
236 return wxRectangleShape::GetPerimeterPoint(x1
, y1
, x2
, y2
, x3
, y3
);
240 void wxDrawnShape::WriteAttributes(wxExpr
*clause
)
242 wxRectangleShape::WriteAttributes(clause
);
244 clause
->AddAttributeValue("current_angle", (long)m_currentAngle
);
245 clause
->AddAttributeValue("save_metafile", (long)m_saveToFile
);
249 for (i
= 0; i
< 4; i
++)
251 if (m_metafiles
[i
].IsValid())
252 m_metafiles
[i
].WriteAttributes(clause
, i
);
257 void wxDrawnShape::ReadAttributes(wxExpr
*clause
)
259 wxRectangleShape::ReadAttributes(clause
);
261 int iVal
= (int) m_saveToFile
;
262 clause
->GetAttributeValue("save_metafile", iVal
);
263 clause
->GetAttributeValue("current_angle", m_currentAngle
);
264 m_saveToFile
= (iVal
!= 0);
269 for (i
= 0; i
< 4; i
++)
271 m_metafiles
[i
].ReadAttributes(clause
, i
);
277 // Does the copying for this object
278 void wxDrawnShape::Copy(wxShape
& copy
)
280 wxRectangleShape::Copy(copy
);
282 wxASSERT( copy
.IsKindOf(CLASSINFO(wxDrawnShape
)) ) ;
284 wxDrawnShape
& drawnCopy
= (wxDrawnShape
&) copy
;
287 for (i
= 0; i
< 4; i
++)
289 m_metafiles
[i
].Copy(drawnCopy
.m_metafiles
[i
]);
291 drawnCopy
.m_saveToFile
= m_saveToFile
;
292 drawnCopy
.m_currentAngle
= m_currentAngle
;
295 bool wxDrawnShape::LoadFromMetaFile(const wxString
& filename
)
297 return m_metafiles
[0].LoadFromMetaFile(filename
, &m_width
, &m_height
);
300 // Set of functions for drawing into a pseudo metafile.
301 // They use integers, but doubles are used internally for accuracy
304 void wxDrawnShape::DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
)
306 m_metafiles
[m_currentAngle
].DrawLine(pt1
, pt2
);
309 void wxDrawnShape::DrawRectangle(const wxRect
& rect
)
311 m_metafiles
[m_currentAngle
].DrawRectangle(rect
);
314 void wxDrawnShape::DrawRoundedRectangle(const wxRect
& rect
, double radius
)
316 m_metafiles
[m_currentAngle
].DrawRoundedRectangle(rect
, radius
);
319 void wxDrawnShape::DrawEllipse(const wxRect
& rect
)
321 m_metafiles
[m_currentAngle
].DrawEllipse(rect
);
324 void wxDrawnShape::DrawArc(const wxPoint
& centrePt
, const wxPoint
& startPt
, const wxPoint
& endPt
)
326 m_metafiles
[m_currentAngle
].DrawArc(centrePt
, startPt
, endPt
);
329 void wxDrawnShape::DrawEllipticArc(const wxRect
& rect
, double startAngle
, double endAngle
)
331 m_metafiles
[m_currentAngle
].DrawEllipticArc(rect
, startAngle
, endAngle
);
334 void wxDrawnShape::DrawPoint(const wxPoint
& pt
)
336 m_metafiles
[m_currentAngle
].DrawPoint(pt
);
339 void wxDrawnShape::DrawText(const wxString
& text
, const wxPoint
& pt
)
341 m_metafiles
[m_currentAngle
].DrawText(text
, pt
);
344 void wxDrawnShape::DrawLines(int n
, wxPoint pts
[])
346 m_metafiles
[m_currentAngle
].DrawLines(n
, pts
);
349 void wxDrawnShape::DrawPolygon(int n
, wxPoint pts
[], int flags
)
351 if (flags
& oglMETAFLAGS_ATTACHMENTS
)
355 for (i
= 0; i
< n
; i
++)
356 m_attachmentPoints
.Append(new wxAttachmentPoint(i
, pts
[i
].x
, pts
[i
].y
));
358 m_metafiles
[m_currentAngle
].DrawPolygon(n
, pts
, flags
);
361 void wxDrawnShape::DrawSpline(int n
, wxPoint pts
[])
363 m_metafiles
[m_currentAngle
].DrawSpline(n
, pts
);
366 void wxDrawnShape::SetClippingRect(const wxRect
& rect
)
368 m_metafiles
[m_currentAngle
].SetClippingRect(rect
);
371 void wxDrawnShape::DestroyClippingRect()
373 m_metafiles
[m_currentAngle
].DestroyClippingRect();
376 void wxDrawnShape::SetDrawnPen(wxPen
* pen
, bool isOutline
)
378 m_metafiles
[m_currentAngle
].SetPen(pen
, isOutline
);
381 void wxDrawnShape::SetDrawnBrush(wxBrush
* brush
, bool isFill
)
383 m_metafiles
[m_currentAngle
].SetBrush(brush
, isFill
);
386 void wxDrawnShape::SetDrawnFont(wxFont
* font
)
388 m_metafiles
[m_currentAngle
].SetFont(font
);
391 void wxDrawnShape::SetDrawnTextColour(const wxColour
& colour
)
393 m_metafiles
[m_currentAngle
].SetTextColour(colour
);
396 void wxDrawnShape::SetDrawnBackgroundColour(const wxColour
& colour
)
398 m_metafiles
[m_currentAngle
].SetBackgroundColour(colour
);
401 void wxDrawnShape::SetDrawnBackgroundMode(int mode
)
403 m_metafiles
[m_currentAngle
].SetBackgroundMode(mode
);
408 * Individual operations
413 * Set font, brush, text colour
417 wxOpSetGDI::wxOpSetGDI(int theOp
, wxPseudoMetaFile
*theImage
, int theGdiIndex
, int theMode
):
420 m_gdiIndex
= theGdiIndex
;
425 void wxOpSetGDI::Do(wxDC
& dc
, double xoffset
, double yoffset
)
431 // Check for overriding this operation for outline
433 if (m_image
->m_outlineColours
.Member((wxObject
*)m_gdiIndex
))
435 if (m_image
->m_outlinePen
)
436 dc
.SetPen(* m_image
->m_outlinePen
);
440 wxNode
*node
= m_image
->m_gdiObjects
.Item(m_gdiIndex
);
443 wxPen
*pen
= (wxPen
*)node
->GetData();
450 case DRAWOP_SET_BRUSH
:
452 // Check for overriding this operation for outline or fill
454 if (m_image
->m_outlineColours
.Member((wxObject
*)m_gdiIndex
))
456 // Need to construct a brush to match the outline pen's colour
457 if (m_image
->m_outlinePen
)
459 wxBrush
*br
= wxTheBrushList
->FindOrCreateBrush(m_image
->m_outlinePen
->GetColour(), wxSOLID
);
464 else if (m_image
->m_fillColours
.Member((wxObject
*)m_gdiIndex
))
466 if (m_image
->m_fillBrush
)
468 dc
.SetBrush(* m_image
->m_fillBrush
);
473 wxNode
*node
= m_image
->m_gdiObjects
.Item(m_gdiIndex
);
476 wxBrush
*brush
= (wxBrush
*)node
->GetData();
478 dc
.SetBrush(* brush
);
483 case DRAWOP_SET_FONT
:
485 wxNode
*node
= m_image
->m_gdiObjects
.Item(m_gdiIndex
);
488 wxFont
*font
= (wxFont
*)node
->GetData();
494 case DRAWOP_SET_TEXT_COLOUR
:
496 wxColour
col(m_r
,m_g
,m_b
);
497 dc
.SetTextForeground(col
);
500 case DRAWOP_SET_BK_COLOUR
:
502 wxColour
col(m_r
,m_g
,m_b
);
503 dc
.SetTextBackground(col
);
506 case DRAWOP_SET_BK_MODE
:
508 dc
.SetBackgroundMode(m_mode
);
516 wxDrawOp
*wxOpSetGDI::Copy(wxPseudoMetaFile
*newImage
)
518 wxOpSetGDI
*newOp
= new wxOpSetGDI(m_op
, newImage
, m_gdiIndex
, m_mode
);
526 wxExpr
*wxOpSetGDI::WriteExpr(wxPseudoMetaFile
*image
)
528 wxExpr
*expr
= new wxExpr(wxExprList
);
529 expr
->Append(new wxExpr((long)m_op
));
533 case DRAWOP_SET_BRUSH
:
534 case DRAWOP_SET_FONT
:
536 expr
->Append(new wxExpr((long)m_gdiIndex
));
539 case DRAWOP_SET_TEXT_COLOUR
:
540 case DRAWOP_SET_BK_COLOUR
:
542 expr
->Append(new wxExpr((long)m_r
));
543 expr
->Append(new wxExpr((long)m_g
));
544 expr
->Append(new wxExpr((long)m_b
));
547 case DRAWOP_SET_BK_MODE
:
549 expr
->Append(new wxExpr((long)m_mode
));
558 void wxOpSetGDI::ReadExpr(wxPseudoMetaFile
*image
, wxExpr
*expr
)
563 case DRAWOP_SET_BRUSH
:
564 case DRAWOP_SET_FONT
:
566 m_gdiIndex
= (int)expr
->Item(1)->IntegerValue();
569 case DRAWOP_SET_TEXT_COLOUR
:
570 case DRAWOP_SET_BK_COLOUR
:
572 m_r
= (unsigned char)expr
->Item(1)->IntegerValue();
573 m_g
= (unsigned char)expr
->Item(2)->IntegerValue();
574 m_b
= (unsigned char)expr
->Item(3)->IntegerValue();
577 case DRAWOP_SET_BK_MODE
:
579 m_mode
= (int)expr
->Item(1)->IntegerValue();
589 * Set/destroy clipping
593 wxOpSetClipping::wxOpSetClipping(int theOp
, double theX1
, double theY1
,
594 double theX2
, double theY2
):wxDrawOp(theOp
)
602 wxDrawOp
*wxOpSetClipping::Copy(wxPseudoMetaFile
*newImage
)
604 wxOpSetClipping
*newOp
= new wxOpSetClipping(m_op
, m_x1
, m_y1
, m_x2
, m_y2
);
608 void wxOpSetClipping::Do(wxDC
& dc
, double xoffset
, double yoffset
)
612 case DRAWOP_SET_CLIPPING_RECT
:
614 dc
.SetClippingRegion((long)(m_x1
+ xoffset
), (long)(m_y1
+ yoffset
), (long)(m_x2
+ xoffset
), (long)(m_y2
+ yoffset
));
617 case DRAWOP_DESTROY_CLIPPING_RECT
:
619 dc
.DestroyClippingRegion();
627 void wxOpSetClipping::Scale(double xScale
, double yScale
)
635 void wxOpSetClipping::Translate(double x
, double y
)
642 wxExpr
*wxOpSetClipping::WriteExpr(wxPseudoMetaFile
*image
)
644 wxExpr
*expr
= new wxExpr(wxExprList
);
645 expr
->Append(new wxExpr((long)m_op
));
648 case DRAWOP_SET_CLIPPING_RECT
:
650 expr
->Append(new wxExpr(m_x1
));
651 expr
->Append(new wxExpr(m_y1
));
652 expr
->Append(new wxExpr(m_x2
));
653 expr
->Append(new wxExpr(m_y2
));
662 void wxOpSetClipping::ReadExpr(wxPseudoMetaFile
*image
, wxExpr
*expr
)
666 case DRAWOP_SET_CLIPPING_RECT
:
668 m_x1
= expr
->Item(1)->RealValue();
669 m_y1
= expr
->Item(2)->RealValue();
670 m_x2
= expr
->Item(3)->RealValue();
671 m_y2
= expr
->Item(4)->RealValue();
681 * Draw line, rectangle, rounded rectangle, ellipse, point, arc, text
685 wxOpDraw::wxOpDraw(int theOp
, double theX1
, double theY1
, double theX2
, double theY2
,
686 double theRadius
, wxChar
*s
) : wxDrawOp(theOp
)
694 m_radius
= theRadius
;
695 if (s
) m_textString
= copystring(s
);
696 else m_textString
= NULL
;
699 wxOpDraw::~wxOpDraw()
701 if (m_textString
) delete[] m_textString
;
704 wxDrawOp
*wxOpDraw::Copy(wxPseudoMetaFile
*newImage
)
706 wxOpDraw
*newOp
= new wxOpDraw(m_op
, m_x1
, m_y1
, m_x2
, m_y2
, m_radius
, m_textString
);
712 void wxOpDraw::Do(wxDC
& dc
, double xoffset
, double yoffset
)
716 case DRAWOP_DRAW_LINE
:
718 dc
.DrawLine(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
), WXROUND(m_x2
+xoffset
), WXROUND(m_y2
+yoffset
));
721 case DRAWOP_DRAW_RECT
:
723 dc
.DrawRectangle(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
), WXROUND(m_x2
), WXROUND(m_y2
));
726 case DRAWOP_DRAW_ROUNDED_RECT
:
728 dc
.DrawRoundedRectangle(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
), WXROUND(m_x2
), WXROUND(m_y2
), m_radius
);
731 case DRAWOP_DRAW_ELLIPSE
:
733 dc
.DrawEllipse(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
), WXROUND(m_x2
), WXROUND(m_y2
));
736 case DRAWOP_DRAW_ARC
:
738 dc
.DrawArc(WXROUND(m_x2
+xoffset
), WXROUND(m_y2
+yoffset
),
739 WXROUND(m_x3
+xoffset
), WXROUND(m_y3
+yoffset
),
740 WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
));
743 case DRAWOP_DRAW_ELLIPTIC_ARC
:
745 const double pi
= 3.1415926535897932384626433832795 ;
747 // Convert back to degrees
749 WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
),
750 WXROUND(m_x2
), WXROUND(m_y2
),
751 WXROUND(m_x3
*(360.0/(2.0*pi
))), WXROUND(m_y3
*(360.0/(2.0*pi
))));
754 case DRAWOP_DRAW_POINT
:
756 dc
.DrawPoint(WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
));
759 case DRAWOP_DRAW_TEXT
:
761 dc
.DrawText(m_textString
, WXROUND(m_x1
+xoffset
), WXROUND(m_y1
+yoffset
));
769 void wxOpDraw::Scale(double scaleX
, double scaleY
)
776 if (m_op
!= DRAWOP_DRAW_ELLIPTIC_ARC
)
785 void wxOpDraw::Translate(double x
, double y
)
792 case DRAWOP_DRAW_LINE
:
798 case DRAWOP_DRAW_ARC
:
806 case DRAWOP_DRAW_ELLIPTIC_ARC
:
815 void wxOpDraw::Rotate(double x
, double y
, double theta
, double sinTheta
, double cosTheta
)
817 double newX1
= m_x1
*cosTheta
- m_y1
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
818 double newY1
= m_x1
*sinTheta
+ m_y1
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
822 case DRAWOP_DRAW_LINE
:
824 double newX2
= m_x2
*cosTheta
- m_y2
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
825 double newY2
= m_x2
*sinTheta
+ m_y2
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
833 case DRAWOP_DRAW_RECT
:
834 case DRAWOP_DRAW_ROUNDED_RECT
:
835 case DRAWOP_DRAW_ELLIPTIC_ARC
:
837 // Assume only 0, 90, 180, 270 degree rotations.
838 // oldX1, oldY1 represents the top left corner. Find the
839 // bottom right, and rotate that. Then the width/height is the difference
840 // between x/y values.
841 double oldBottomRightX
= m_x1
+ m_x2
;
842 double oldBottomRightY
= m_y1
+ m_y2
;
843 double newBottomRightX
= oldBottomRightX
*cosTheta
- oldBottomRightY
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
844 double newBottomRightY
= oldBottomRightX
*sinTheta
+ oldBottomRightY
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
846 // Now find the new top-left, bottom-right coordinates.
847 double minX
= wxMin(newX1
, newBottomRightX
);
848 double minY
= wxMin(newY1
, newBottomRightY
);
849 double maxX
= wxMax(newX1
, newBottomRightX
);
850 double maxY
= wxMax(newY1
, newBottomRightY
);
854 m_x2
= maxX
- minX
; // width
855 m_y2
= maxY
- minY
; // height
857 if (m_op
== DRAWOP_DRAW_ELLIPTIC_ARC
)
859 // Add rotation to angles
866 case DRAWOP_DRAW_ARC
:
868 double newX2
= m_x2
*cosTheta
- m_y2
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
869 double newY2
= m_x2
*sinTheta
+ m_y2
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
870 double newX3
= m_x3
*cosTheta
- m_y3
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
871 double newY3
= m_x3
*sinTheta
+ m_y3
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
888 wxExpr
*wxOpDraw::WriteExpr(wxPseudoMetaFile
*image
)
890 wxExpr
*expr
= new wxExpr(wxExprList
);
891 expr
->Append(new wxExpr((long)m_op
));
894 case DRAWOP_DRAW_LINE
:
895 case DRAWOP_DRAW_RECT
:
896 case DRAWOP_DRAW_ELLIPSE
:
898 expr
->Append(new wxExpr(m_x1
));
899 expr
->Append(new wxExpr(m_y1
));
900 expr
->Append(new wxExpr(m_x2
));
901 expr
->Append(new wxExpr(m_y2
));
904 case DRAWOP_DRAW_ROUNDED_RECT
:
906 expr
->Append(new wxExpr(m_x1
));
907 expr
->Append(new wxExpr(m_y1
));
908 expr
->Append(new wxExpr(m_x2
));
909 expr
->Append(new wxExpr(m_y2
));
910 expr
->Append(new wxExpr(m_radius
));
913 case DRAWOP_DRAW_POINT
:
915 expr
->Append(new wxExpr(m_x1
));
916 expr
->Append(new wxExpr(m_y1
));
919 case DRAWOP_DRAW_TEXT
:
921 expr
->Append(new wxExpr(m_x1
));
922 expr
->Append(new wxExpr(m_y1
));
923 expr
->Append(new wxExpr(wxExprString
, m_textString
));
926 case DRAWOP_DRAW_ARC
:
927 case DRAWOP_DRAW_ELLIPTIC_ARC
:
929 expr
->Append(new wxExpr(m_x1
));
930 expr
->Append(new wxExpr(m_y1
));
931 expr
->Append(new wxExpr(m_x2
));
932 expr
->Append(new wxExpr(m_y2
));
933 expr
->Append(new wxExpr(m_x3
));
934 expr
->Append(new wxExpr(m_y3
));
945 void wxOpDraw::ReadExpr(wxPseudoMetaFile
*image
, wxExpr
*expr
)
949 case DRAWOP_DRAW_LINE
:
950 case DRAWOP_DRAW_RECT
:
951 case DRAWOP_DRAW_ELLIPSE
:
953 m_x1
= expr
->Item(1)->RealValue();
954 m_y1
= expr
->Item(2)->RealValue();
955 m_x2
= expr
->Item(3)->RealValue();
956 m_y2
= expr
->Item(4)->RealValue();
959 case DRAWOP_DRAW_ROUNDED_RECT
:
961 m_x1
= expr
->Item(1)->RealValue();
962 m_y1
= expr
->Item(2)->RealValue();
963 m_x2
= expr
->Item(3)->RealValue();
964 m_y2
= expr
->Item(4)->RealValue();
965 m_radius
= expr
->Item(5)->RealValue();
968 case DRAWOP_DRAW_POINT
:
970 m_x1
= expr
->Item(1)->RealValue();
971 m_y1
= expr
->Item(2)->RealValue();
974 case DRAWOP_DRAW_TEXT
:
976 m_x1
= expr
->Item(1)->RealValue();
977 m_y1
= expr
->Item(2)->RealValue();
978 wxString
str(expr
->Item(3)->StringValue());
979 m_textString
= copystring(str
);
982 case DRAWOP_DRAW_ARC
:
983 case DRAWOP_DRAW_ELLIPTIC_ARC
:
985 m_x1
= expr
->Item(1)->RealValue();
986 m_y1
= expr
->Item(2)->RealValue();
987 m_x2
= expr
->Item(3)->RealValue();
988 m_y2
= expr
->Item(4)->RealValue();
989 m_x3
= expr
->Item(5)->RealValue();
990 m_y3
= expr
->Item(6)->RealValue();
1002 * Draw polygon, polyline, spline
1006 wxOpPolyDraw::wxOpPolyDraw(int theOp
, int n
, wxRealPoint
*thePoints
):wxDrawOp(theOp
)
1009 m_points
= thePoints
;
1012 wxOpPolyDraw::~wxOpPolyDraw()
1017 wxDrawOp
*wxOpPolyDraw::Copy(wxPseudoMetaFile
*newImage
)
1019 wxRealPoint
*newPoints
= new wxRealPoint
[m_noPoints
];
1020 for (int i
= 0; i
< m_noPoints
; i
++)
1022 newPoints
[i
].x
= m_points
[i
].x
;
1023 newPoints
[i
].y
= m_points
[i
].y
;
1025 wxOpPolyDraw
*newOp
= new wxOpPolyDraw(m_op
, m_noPoints
, newPoints
);
1029 void wxOpPolyDraw::Do(wxDC
& dc
, double xoffset
, double yoffset
)
1033 case DRAWOP_DRAW_POLYLINE
:
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
.DrawLines(m_noPoints
, actualPoints
, WXROUND(xoffset
), WXROUND(yoffset
));
1045 delete[] actualPoints
;
1048 case DRAWOP_DRAW_POLYGON
:
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
.DrawPolygon(m_noPoints
, actualPoints
, WXROUND(xoffset
), WXROUND(yoffset
));
1060 delete[] actualPoints
;
1063 case DRAWOP_DRAW_SPLINE
:
1065 wxPoint
*actualPoints
= new wxPoint
[m_noPoints
];
1067 for (i
= 0; i
< m_noPoints
; i
++)
1069 actualPoints
[i
].x
= WXROUND(m_points
[i
].x
);
1070 actualPoints
[i
].y
= WXROUND(m_points
[i
].y
);
1073 dc
.DrawSpline(m_noPoints
, actualPoints
); // no offsets in DrawSpline // , xoffset, yoffset);
1075 delete[] actualPoints
;
1084 void wxOpPolyDraw::Scale(double scaleX
, double scaleY
)
1086 for (int i
= 0; i
< m_noPoints
; i
++)
1088 m_points
[i
].x
*= scaleX
;
1089 m_points
[i
].y
*= scaleY
;
1093 void wxOpPolyDraw::Translate(double x
, double y
)
1095 for (int i
= 0; i
< m_noPoints
; i
++)
1102 void wxOpPolyDraw::Rotate(double x
, double y
, double theta
, double sinTheta
, double cosTheta
)
1104 for (int i
= 0; i
< m_noPoints
; i
++)
1106 double x1
= m_points
[i
].x
;
1107 double y1
= m_points
[i
].y
;
1108 m_points
[i
].x
= x1
*cosTheta
- y1
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
1109 m_points
[i
].y
= x1
*sinTheta
+ y1
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
1114 wxExpr
*wxOpPolyDraw::WriteExpr(wxPseudoMetaFile
*image
)
1116 wxExpr
*expr
= new wxExpr(wxExprList
);
1117 expr
->Append(new wxExpr((long)m_op
));
1118 expr
->Append(new wxExpr((long)m_noPoints
));
1127 * Store each coordinate pair in a hex string to save space.
1128 * E.g. "1B9080CD". 4 hex digits per coordinate pair.
1132 for (int i
= 0; i
< m_noPoints
; i
++)
1134 long signedX
= (long)(m_points
[i
].x
*100.0);
1135 long signedY
= (long)(m_points
[i
].y
*100.0);
1137 // Scale to 0 -> 64K
1138 long unSignedX
= (long)(signedX
+ 32767.0);
1139 long unSignedY
= (long)(signedY
+ 32767.0);
1141 // IntToHex((unsigned int)signedX, buf2);
1142 // IntToHex((unsigned int)signedY, buf3);
1143 IntToHex((int)unSignedX
, buf2
);
1144 IntToHex((int)unSignedY
, buf3
);
1146 // Don't overrun the buffer
1149 strcat(oglBuffer
, buf2
);
1150 strcat(oglBuffer
, buf3
);
1153 expr
->Append(new wxExpr(wxExprString
, oglBuffer
));
1157 void wxOpPolyDraw::ReadExpr(wxPseudoMetaFile
*image
, wxExpr
*expr
)
1159 m_noPoints
= (int)expr
->Item(1)->IntegerValue();
1164 m_points
= new wxRealPoint
[m_noPoints
];
1167 wxString hexString
= expr
->Item(2)->StringValue();
1168 while (i
< m_noPoints
)
1170 buf1
[0] = hexString
[(size_t)bufPtr
];
1171 buf1
[1] = hexString
[(size_t)(bufPtr
+ 1)];
1172 buf1
[2] = hexString
[(size_t)(bufPtr
+ 2)];
1173 buf1
[3] = hexString
[(size_t)(bufPtr
+ 3)];
1176 buf2
[0] = hexString
[(size_t)(bufPtr
+ 4)];
1177 buf2
[1] = hexString
[(size_t)(bufPtr
+ 5)];
1178 buf2
[2] = hexString
[(size_t)(bufPtr
+ 6)];
1179 buf2
[3] = hexString
[(size_t)(bufPtr
+ 7)];
1184 // int signedX = (signed int)HexToInt(buf1);
1185 // int signedY = (signed int)HexToInt(buf2);
1186 long unSignedX
= HexToInt(buf1
);
1187 long unSignedY
= HexToInt(buf2
);
1188 // Scale -32K -> +32K
1189 long signedX
= unSignedX
- 32767;
1190 long signedY
= unSignedY
- 32767;
1192 int testX
= (signed int)unSignedX
;
1193 int testY
= (signed int)unSignedY
;
1196 m_points
[i
].x
= (double)(signedX
/ 100.0);
1197 m_points
[i
].y
= (double)(signedY
/ 100.0);
1204 // Draw an outline using the current operation.
1205 bool wxOpPolyDraw::OnDrawOutline(wxDC
& dc
, double x
, double y
, double w
, double h
, double oldW
, double oldH
)
1207 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1209 // Multiply all points by proportion of new size to old size
1210 double x_proportion
= (double)(fabs(w
/oldW
));
1211 double y_proportion
= (double)(fabs(h
/oldH
));
1214 wxPoint
*intPoints
= new wxPoint
[n
];
1216 for (i
= 0; i
< n
; i
++)
1218 intPoints
[i
].x
= WXROUND (x_proportion
* m_points
[i
].x
);
1219 intPoints
[i
].y
= WXROUND (y_proportion
* m_points
[i
].y
);
1221 dc
.DrawPolygon(n
, intPoints
, (long) x
, (long) y
);
1226 // Assume (x1, y1) is centre of box (most generally, line end at box)
1227 bool wxOpPolyDraw::GetPerimeterPoint(double x1
, double y1
,
1228 double x2
, double y2
,
1229 double *x3
, double *y3
,
1230 double xOffset
, double yOffset
,
1235 // First check for situation where the line is vertical,
1236 // and we would want to connect to a point on that vertical --
1237 // oglFindEndForPolyline can't cope with this (the arrow
1238 // gets drawn to the wrong place).
1239 if ((attachmentMode
== ATTACHMENT_MODE_NONE
) && (x1
== x2
))
1241 // Look for the point we'd be connecting to. This is
1244 for (i
= 0; i
< n
; i
++)
1246 wxRealPoint
*point
= & (m_points
[i
]);
1247 if (point
->x
== 0.0)
1249 if ((y2
> y1
) && (point
->y
> 0.0))
1251 *x3
= point
->x
+ xOffset
;
1252 *y3
= point
->y
+ yOffset
;
1255 else if ((y2
< y1
) && (point
->y
< 0.0))
1257 *x3
= point
->x
+ xOffset
;
1258 *y3
= point
->y
+ yOffset
;
1265 double *xpoints
= new double[n
];
1266 double *ypoints
= new double[n
];
1269 for (i
= 0; i
< n
; i
++)
1271 wxRealPoint
*point
= & (m_points
[i
]);
1272 xpoints
[i
] = point
->x
+ xOffset
;
1273 ypoints
[i
] = point
->y
+ yOffset
;
1276 oglFindEndForPolyline(n
, xpoints
, ypoints
,
1277 x1
, y1
, x2
, y2
, x3
, y3
);
1291 static char hexArray
[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B',
1292 'C', 'D', 'E', 'F' };
1294 // Convert unsigned 16-bit integer to 4-character hex string
1295 static void IntToHex(unsigned int dec
, char *buf
)
1297 int digit1
= (int)(dec
/4096);
1298 int digit2
= (int)((dec
- (digit1
*4096))/256);
1299 int digit3
= (int)((dec
- (digit1
*4096) - (digit2
*256))/16);
1300 int digit4
= dec
- (digit1
*4096 + digit2
*256 + digit3
*16);
1302 buf
[0] = hexArray
[digit1
];
1303 buf
[1] = hexArray
[digit2
];
1304 buf
[2] = hexArray
[digit3
];
1305 buf
[3] = hexArray
[digit4
];
1309 // One hex digit to decimal number
1310 static int HexToInt1(char hex
)
1352 // 4-digit hex string to unsigned integer
1353 static unsigned long HexToInt(char *buf
)
1355 long d1
= (long)(HexToInt1(buf
[0])*4096.0) ;
1356 long d2
= (long)(HexToInt1(buf
[1])*256.0) ;
1357 long d3
= (long)(HexToInt1(buf
[2])*16.0) ;
1358 long d4
= (long)(HexToInt1(buf
[3])) ;
1359 unsigned long n
= (long)(d1
+ d2
+ d3
+ d4
) ;
1364 * wxPseudo meta-file
1368 IMPLEMENT_DYNAMIC_CLASS(wxPseudoMetaFile
, wxObject
)
1370 wxPseudoMetaFile::wxPseudoMetaFile()
1372 m_currentRotation
= 0;
1373 m_rotateable
= TRUE
;
1376 m_outlinePen
= NULL
;
1381 wxPseudoMetaFile::wxPseudoMetaFile(wxPseudoMetaFile
& mf
)
1386 wxPseudoMetaFile::~wxPseudoMetaFile()
1391 void wxPseudoMetaFile::Clear()
1393 wxNode
*node
= m_ops
.GetFirst();
1396 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1398 node
= node
->GetNext();
1401 m_gdiObjects
.Clear();
1402 m_outlineColours
.Clear();
1403 m_fillColours
.Clear();
1407 void wxPseudoMetaFile::Draw(wxDC
& dc
, double xoffset
, double yoffset
)
1409 wxNode
*node
= m_ops
.GetFirst();
1412 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1413 op
->Do(dc
, xoffset
, yoffset
);
1414 node
= node
->GetNext();
1418 void wxPseudoMetaFile::Scale(double sx
, double sy
)
1420 wxNode
*node
= m_ops
.GetFirst();
1423 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1425 node
= node
->GetNext();
1431 void wxPseudoMetaFile::Translate(double x
, double y
)
1433 wxNode
*node
= m_ops
.GetFirst();
1436 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1437 op
->Translate(x
, y
);
1438 node
= node
->GetNext();
1442 void wxPseudoMetaFile::Rotate(double x
, double y
, double theta
)
1444 double theta1
= theta
-m_currentRotation
;
1445 if (theta1
== 0.0) return;
1446 double cosTheta
= (double)cos(theta1
);
1447 double sinTheta
= (double)sin(theta1
);
1449 wxNode
*node
= m_ops
.GetFirst();
1452 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1453 op
->Rotate(x
, y
, theta
, sinTheta
, cosTheta
);
1454 node
= node
->GetNext();
1456 m_currentRotation
= theta
;
1460 void wxPseudoMetaFile::WriteAttributes(wxExpr
*clause
, int whichAngle
)
1463 widthStr
.Printf(wxT("meta_width%d"), whichAngle
);
1466 heightStr
.Printf(wxT("meta_height%d"), whichAngle
);
1468 wxString outlineStr
;
1469 outlineStr
.Printf(wxT("outline_op%d"), whichAngle
);
1471 wxString rotateableStr
;
1472 rotateableStr
.Printf(wxT("meta_rotateable%d"), whichAngle
);
1474 // Write width and height
1475 clause
->AddAttributeValue(widthStr
, m_width
);
1476 clause
->AddAttributeValue(heightStr
, m_height
);
1477 clause
->AddAttributeValue(rotateableStr
, (long)m_rotateable
);
1478 clause
->AddAttributeValue(outlineStr
, (long)m_outlineOp
);
1480 // Write GDI objects
1483 wxNode
*node
= m_gdiObjects
.GetFirst();
1486 sprintf(buf
, "gdi%d_%d", whichAngle
, i
);
1487 wxObject
*obj
= (wxObject
*)node
->GetData();
1488 wxExpr
*expr
= NULL
;
1491 if (obj
->IsKindOf(CLASSINFO(wxPen
)))
1493 wxPen
*thePen
= (wxPen
*)obj
;
1494 expr
= new wxExpr(wxExprList
);
1495 expr
->Append(new wxExpr((long)gyTYPE_PEN
));
1496 expr
->Append(new wxExpr((long)thePen
->GetWidth()));
1497 expr
->Append(new wxExpr((long)thePen
->GetStyle()));
1498 expr
->Append(new wxExpr((long)thePen
->GetColour().Red()));
1499 expr
->Append(new wxExpr((long)thePen
->GetColour().Green()));
1500 expr
->Append(new wxExpr((long)thePen
->GetColour().Blue()));
1502 else if (obj
->IsKindOf(CLASSINFO(wxBrush
)))
1504 wxBrush
*theBrush
= (wxBrush
*)obj
;
1505 expr
= new wxExpr(wxExprList
);
1506 expr
->Append(new wxExpr((long)gyTYPE_BRUSH
));
1507 expr
->Append(new wxExpr((long)theBrush
->GetStyle()));
1508 expr
->Append(new wxExpr((long)theBrush
->GetColour().Red()));
1509 expr
->Append(new wxExpr((long)theBrush
->GetColour().Green()));
1510 expr
->Append(new wxExpr((long)theBrush
->GetColour().Blue()));
1512 else if (obj
->IsKindOf(CLASSINFO(wxFont
)))
1514 wxFont
*theFont
= (wxFont
*)obj
;
1515 expr
= new wxExpr(wxExprList
);
1516 expr
->Append(new wxExpr((long)gyTYPE_FONT
));
1517 expr
->Append(new wxExpr((long)theFont
->GetPointSize()));
1518 expr
->Append(new wxExpr((long)theFont
->GetFamily()));
1519 expr
->Append(new wxExpr((long)theFont
->GetStyle()));
1520 expr
->Append(new wxExpr((long)theFont
->GetWeight()));
1521 expr
->Append(new wxExpr((long)theFont
->GetUnderlined()));
1526 // If no recognised GDI object, append a place holder anyway.
1527 expr
= new wxExpr(wxExprList
);
1528 expr
->Append(new wxExpr((long)0));
1533 clause
->AddAttributeValue(buf
, expr
);
1536 node
= node
->GetNext();
1539 // Write drawing operations
1541 node
= m_ops
.GetFirst();
1544 sprintf(buf
, "op%d_%d", whichAngle
, i
);
1545 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1546 wxExpr
*expr
= op
->WriteExpr(this);
1549 clause
->AddAttributeValue(buf
, expr
);
1552 node
= node
->GetNext();
1555 // Write outline and fill GDI op lists (if any)
1556 if (m_outlineColours
.GetCount() > 0)
1558 wxExpr
*outlineExpr
= new wxExpr(wxExprList
);
1559 node
= m_outlineColours
.GetFirst();
1562 outlineExpr
->Append(new wxExpr((long)node
->GetData()));
1563 node
= node
->GetNext();
1565 wxString outlineObjectsStr
;
1566 outlineObjectsStr
.Printf(wxT("outline_objects%d"), whichAngle
);
1568 clause
->AddAttributeValue(outlineObjectsStr
, outlineExpr
);
1570 if (m_fillColours
.GetCount() > 0)
1572 wxExpr
*fillExpr
= new wxExpr(wxExprList
);
1573 node
= m_fillColours
.GetFirst();
1576 fillExpr
->Append(new wxExpr((long)node
->GetData()));
1577 node
= node
->GetNext();
1579 wxString fillObjectsStr
;
1580 fillObjectsStr
.Printf(wxT("fill_objects%d"), whichAngle
);
1582 clause
->AddAttributeValue(fillObjectsStr
, fillExpr
);
1587 void wxPseudoMetaFile::ReadAttributes(wxExpr
*clause
, int whichAngle
)
1590 widthStr
.Printf(wxT("meta_width%d"), whichAngle
);
1593 heightStr
.Printf(wxT("meta_height%d"), whichAngle
);
1595 wxString outlineStr
;
1596 outlineStr
.Printf(wxT("outline_op%d"), whichAngle
);
1598 wxString rotateableStr
;
1599 rotateableStr
.Printf(wxT("meta_rotateable%d"), whichAngle
);
1601 clause
->GetAttributeValue(widthStr
, m_width
);
1602 clause
->GetAttributeValue(heightStr
, m_height
);
1603 clause
->GetAttributeValue(outlineStr
, m_outlineOp
);
1605 int iVal
= (int) m_rotateable
;
1606 clause
->GetAttributeValue(rotateableStr
, iVal
);
1607 m_rotateable
= (iVal
!= 0);
1612 bool keepGoing
= TRUE
;
1615 sprintf(buf
, "gdi%d_%d", whichAngle
, i
);
1616 wxExpr
*expr
= NULL
;
1617 clause
->GetAttributeValue(buf
, &expr
);
1624 wxExpr
*idExpr
= expr
->Item(0);
1625 switch (idExpr
->IntegerValue())
1629 int penWidth
= (int)expr
->Item(1)->IntegerValue();
1630 int penStyle
= (int)expr
->Item(2)->IntegerValue();
1631 int penRed
= (int)expr
->Item(3)->IntegerValue();
1632 int penGreen
= (int)expr
->Item(4)->IntegerValue();
1633 int penBlue
= (int)expr
->Item(5)->IntegerValue();
1634 wxColour
col(penRed
, penGreen
, penBlue
);
1635 wxPen
*p
= wxThePenList
->FindOrCreatePen(col
, penWidth
, penStyle
);
1638 m_gdiObjects
.Append(p
);
1643 int brushStyle
= (int)expr
->Item(1)->IntegerValue();
1644 int brushRed
= (int)expr
->Item(2)->IntegerValue();
1645 int brushGreen
= (int)expr
->Item(3)->IntegerValue();
1646 int brushBlue
= (int)expr
->Item(4)->IntegerValue();
1647 wxColour
col(brushRed
, brushGreen
, brushBlue
);
1648 wxBrush
*b
= wxTheBrushList
->FindOrCreateBrush(col
, brushStyle
);
1651 m_gdiObjects
.Append(b
);
1656 int fontPointSize
= (int)expr
->Item(1)->IntegerValue();
1657 int fontFamily
= (int)expr
->Item(2)->IntegerValue();
1658 int fontStyle
= (int)expr
->Item(3)->IntegerValue();
1659 int fontWeight
= (int)expr
->Item(4)->IntegerValue();
1660 int fontUnderlined
= (int)expr
->Item(5)->IntegerValue();
1661 m_gdiObjects
.Append(wxTheFontList
->FindOrCreateFont(fontPointSize
,
1662 fontFamily
, fontStyle
, fontWeight
, (fontUnderlined
!= 0)));
1668 m_gdiObjects
.Append(NULL
);
1676 // Now read in the operations
1681 sprintf(buf
, "op%d_%d", whichAngle
, i
);
1682 wxExpr
*expr
= NULL
;
1683 clause
->GetAttributeValue(buf
, &expr
);
1690 wxExpr
*idExpr
= expr
->Item(0);
1691 int opId
= (int)idExpr
->IntegerValue();
1694 case DRAWOP_SET_PEN
:
1695 case DRAWOP_SET_BRUSH
:
1696 case DRAWOP_SET_FONT
:
1697 case DRAWOP_SET_TEXT_COLOUR
:
1698 case DRAWOP_SET_BK_COLOUR
:
1699 case DRAWOP_SET_BK_MODE
:
1701 wxOpSetGDI
*theOp
= new wxOpSetGDI(opId
, this, 0);
1702 theOp
->ReadExpr(this, expr
);
1703 m_ops
.Append(theOp
);
1707 case DRAWOP_SET_CLIPPING_RECT
:
1708 case DRAWOP_DESTROY_CLIPPING_RECT
:
1710 wxOpSetClipping
*theOp
= new wxOpSetClipping(opId
, 0.0, 0.0, 0.0, 0.0);
1711 theOp
->ReadExpr(this, expr
);
1712 m_ops
.Append(theOp
);
1716 case DRAWOP_DRAW_LINE
:
1717 case DRAWOP_DRAW_RECT
:
1718 case DRAWOP_DRAW_ROUNDED_RECT
:
1719 case DRAWOP_DRAW_ELLIPSE
:
1720 case DRAWOP_DRAW_POINT
:
1721 case DRAWOP_DRAW_ARC
:
1722 case DRAWOP_DRAW_TEXT
:
1724 wxOpDraw
*theOp
= new wxOpDraw(opId
, 0.0, 0.0, 0.0, 0.0);
1725 theOp
->ReadExpr(this, expr
);
1726 m_ops
.Append(theOp
);
1729 case DRAWOP_DRAW_SPLINE
:
1730 case DRAWOP_DRAW_POLYLINE
:
1731 case DRAWOP_DRAW_POLYGON
:
1733 wxOpPolyDraw
*theOp
= new wxOpPolyDraw(opId
, 0, NULL
);
1734 theOp
->ReadExpr(this, expr
);
1735 m_ops
.Append(theOp
);
1745 wxString outlineObjectsStr
;
1746 outlineObjectsStr
.Printf(wxT("outline_objects%d"), whichAngle
);
1748 // Now read in the list of outline and fill operations, if any
1749 wxExpr
*expr1
= clause
->AttributeValue(outlineObjectsStr
);
1752 wxExpr
*eachExpr
= expr1
->GetFirst();
1755 m_outlineColours
.Append((wxObject
*)eachExpr
->IntegerValue());
1756 eachExpr
= eachExpr
->GetNext();
1760 wxString fillObjectsStr
;
1761 fillObjectsStr
.Printf(wxT("fill_objects%d"), whichAngle
);
1763 expr1
= clause
->AttributeValue(fillObjectsStr
);
1766 wxExpr
*eachExpr
= expr1
->GetFirst();
1769 m_fillColours
.Append((wxObject
*)eachExpr
->IntegerValue());
1770 eachExpr
= eachExpr
->GetNext();
1776 // Does the copying for this object
1777 void wxPseudoMetaFile::Copy(wxPseudoMetaFile
& copy
)
1781 copy
.m_currentRotation
= m_currentRotation
;
1782 copy
.m_width
= m_width
;
1783 copy
.m_height
= m_height
;
1784 copy
.m_rotateable
= m_rotateable
;
1785 copy
.m_fillBrush
= m_fillBrush
;
1786 copy
.m_outlinePen
= m_outlinePen
;
1787 copy
.m_outlineOp
= m_outlineOp
;
1789 // Copy the GDI objects
1790 wxNode
*node
= m_gdiObjects
.GetFirst();
1793 wxObject
*obj
= (wxObject
*)node
->GetData();
1794 copy
.m_gdiObjects
.Append(obj
);
1795 node
= node
->GetNext();
1798 // Copy the operations
1799 node
= m_ops
.GetFirst();
1802 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
1803 copy
.m_ops
.Append(op
->Copy(©
));
1804 node
= node
->GetNext();
1807 // Copy the outline/fill operations
1808 node
= m_outlineColours
.GetFirst();
1811 copy
.m_outlineColours
.Append((wxObject
*)node
->GetData());
1812 node
= node
->GetNext();
1814 node
= m_fillColours
.GetFirst();
1817 copy
.m_fillColours
.Append((wxObject
*)node
->GetData());
1818 node
= node
->GetNext();
1823 * Pass size of existing image; scale height to
1824 * fit width and return new width and height.
1828 bool wxPseudoMetaFile::LoadFromMetaFile(const wxString
& filename
, double *rwidth
, double *rheight
)
1830 if (!wxFileExists(filename
))
1833 wxXMetaFile
*metaFile
= new wxXMetaFile
;
1835 if (!metaFile
->ReadFile(filename
))
1844 // Convert from metafile records to wxDrawnShape records
1845 wxNode
*node
= metaFile
->metaRecords
.GetFirst();
1848 wxMetaRecord
*record
= (wxMetaRecord
*)node
->GetData();
1849 switch (record
->metaFunction
)
1851 case META_SETBKCOLOR
:
1853 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_BK_COLOUR
, this, 0);
1854 op
->m_r
= (unsigned char)record
->param1
;
1855 op
->m_g
= (unsigned char)record
->param2
;
1856 op
->m_b
= (unsigned char)record
->param3
;
1860 case META_SETBKMODE
:
1862 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_BK_MODE
, this, 0, (int)record
->param1
);
1866 case META_SETMAPMODE
:
1870 // case META_SETROP2:
1871 // case META_SETRELABS:
1872 // case META_SETPOLYFILLMODE:
1873 // case META_SETSTRETCHBLTMODE:
1874 // case META_SETTEXTCHAREXTRA:
1875 case META_SETTEXTCOLOR
:
1877 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_TEXT_COLOUR
, this, 0);
1878 op
->m_r
= (unsigned char)record
->param1
;
1879 op
->m_g
= (unsigned char)record
->param2
;
1880 op
->m_b
= (unsigned char)record
->param3
;
1884 // case META_SETTEXTJUSTIFICATION:
1885 // case META_SETWINDOWORG:
1886 // case META_SETWINDOWEXT:
1887 // case META_SETVIEWPORTORG:
1888 // case META_SETVIEWPORTEXT:
1889 // case META_OFFSETWINDOWORG:
1890 // case META_SCALEWINDOWEXT:
1891 // case META_OFFSETVIEWPORTORG:
1892 // case META_SCALEVIEWPORTEXT:
1895 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_LINE
, (double)lastX
, (double)lastY
,
1896 (double)record
->param1
, (double)record
->param2
);
1902 lastX
= (double)record
->param1
;
1903 lastY
= (double)record
->param2
;
1906 case META_EXCLUDECLIPRECT
:
1909 wxMetaRecord *rec = new wxMetaRecord(META_EXCLUDECLIPRECT);
1910 rec->param4 = getshort(handle); // m_y2
1911 rec->param3 = getshort(handle); // x2
1912 rec->param2 = getshort(handle); // y1
1913 rec->param1 = getshort(handle); // x1
1917 case META_INTERSECTCLIPRECT
:
1920 rec->param4 = getshort(handle); // m_y2
1921 rec->param3 = getshort(handle); // x2
1922 rec->param2 = getshort(handle); // y1
1923 rec->param1 = getshort(handle); // x1
1927 // case META_ARC: // DO!!!
1930 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_ELLIPSE
,
1931 (double)record
->param1
, (double)record
->param2
,
1932 (double)(record
->param3
- record
->param1
),
1933 (double)(record
->param4
- record
->param2
));
1937 // case META_FLOODFILL:
1938 // case META_PIE: // DO!!!
1939 case META_RECTANGLE
:
1941 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_RECT
,
1942 (double)record
->param1
, (double)record
->param2
,
1943 (double)(record
->param3
- record
->param1
),
1944 (double)(record
->param4
- record
->param2
));
1948 case META_ROUNDRECT
:
1950 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_ROUNDED_RECT
,
1951 (double)record
->param1
, (double)record
->param2
,
1952 (double)(record
->param3
- record
->param1
),
1953 (double)(record
->param4
- record
->param2
), (double)record
->param5
);
1957 // case META_PATBLT:
1958 // case META_SAVEDC:
1961 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_POINT
,
1962 (double)record
->param1
, (double)record
->param2
,
1965 // SHOULD SET THE COLOUR - SET PEN?
1966 // rec->param3 = getint(handle); // COLORREF
1970 // case META_OFFSETCLIPRGN:
1973 wxOpDraw
*op
= new wxOpDraw(DRAWOP_DRAW_TEXT
,
1974 (double)record
->param1
, (double)record
->param2
,
1975 0.0, 0.0, 0.0, record
->stringParam
);
1979 // case META_BITBLT:
1980 // case META_STRETCHBLT:
1983 int n
= (int)record
->param1
;
1984 wxRealPoint
*newPoints
= new wxRealPoint
[n
];
1985 for (int i
= 0; i
< n
; i
++)
1987 newPoints
[i
].x
= record
->points
[i
].x
;
1988 newPoints
[i
].y
= record
->points
[i
].y
;
1991 wxOpPolyDraw
*op
= new wxOpPolyDraw(DRAWOP_DRAW_POLYGON
, n
, newPoints
);
1997 int n
= (int)record
->param1
;
1998 wxRealPoint
*newPoints
= new wxRealPoint
[n
];
1999 for (int i
= 0; i
< n
; i
++)
2001 newPoints
[i
].x
= record
->points
[i
].x
;
2002 newPoints
[i
].y
= record
->points
[i
].y
;
2005 wxOpPolyDraw
*op
= new wxOpPolyDraw(DRAWOP_DRAW_POLYLINE
, n
, newPoints
);
2009 // case META_ESCAPE:
2010 // case META_RESTOREDC:
2011 // case META_FILLREGION:
2012 // case META_FRAMEREGION:
2013 // case META_INVERTREGION:
2014 // case META_PAINTREGION:
2015 // case META_SELECTCLIPREGION: // DO THIS!
2016 case META_SELECTOBJECT
:
2018 // The pen, brush etc. has already been created when the metafile
2019 // was read in, so we don't create it - we set it.
2020 wxNode
*recNode
= metaFile
->gdiObjects
.Item((int)record
->param2
);
2023 wxMetaRecord
*gdiRec
= (wxMetaRecord
*)recNode
->GetData();
2024 if (gdiRec
&& (gdiRec
->param1
!= 0))
2026 wxObject
*obj
= (wxObject
*)gdiRec
->param1
;
2027 if (obj
->IsKindOf(CLASSINFO(wxPen
)))
2029 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_PEN
, this, (int)record
->param2
);
2032 else if (obj
->IsKindOf(CLASSINFO(wxBrush
)))
2034 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_BRUSH
, this, (int)record
->param2
);
2037 else if (obj
->IsKindOf(CLASSINFO(wxFont
)))
2039 wxOpSetGDI
*op
= new wxOpSetGDI(DRAWOP_SET_FONT
, this, (int)record
->param2
);
2046 // case META_SETTEXTALIGN:
2047 // case META_DRAWTEXT:
2049 // case META_SETMAPPERFLAGS:
2050 // case META_EXTTEXTOUT:
2051 // case META_SETDIBTODEV:
2052 // case META_SELECTPALETTE:
2053 // case META_REALIZEPALETTE:
2054 // case META_ANIMATEPALETTE:
2055 // case META_SETPALENTRIES:
2056 // case META_POLYPOLYGON:
2057 // case META_RESIZEPALETTE:
2058 // case META_DIBBITBLT:
2059 // case META_DIBSTRETCHBLT:
2060 case META_DIBCREATEPATTERNBRUSH
:
2063 m_gdiObjects
.Append(NULL
);
2066 // case META_STRETCHDIB:
2067 // case META_EXTFLOODFILL:
2068 // case META_RESETDC:
2069 // case META_STARTDOC:
2070 // case META_STARTPAGE:
2071 // case META_ENDPAGE:
2072 // case META_ABORTDOC:
2073 // case META_ENDDOC:
2074 // case META_DELETEOBJECT: // DO!!
2075 case META_CREATEPALETTE
:
2078 m_gdiObjects
.Append(NULL
);
2081 case META_CREATEBRUSH
:
2084 m_gdiObjects
.Append(NULL
);
2087 case META_CREATEPATTERNBRUSH
:
2090 m_gdiObjects
.Append(NULL
);
2093 case META_CREATEPENINDIRECT
:
2095 // The pen is created when the metafile is read in.
2096 // We keep track of all the GDI objects needed for this
2097 // image so when reading the wxDrawnShape from file,
2098 // we can read in all the GDI objects, then refer
2099 // to them by an index starting from zero thereafter.
2100 m_gdiObjects
.Append((wxObject
*)record
->param1
);
2103 case META_CREATEFONTINDIRECT
:
2105 m_gdiObjects
.Append((wxObject
*)record
->param1
);
2108 case META_CREATEBRUSHINDIRECT
:
2110 // Don't have to do anything here: the pen is created
2111 // when the metafile is read in.
2112 m_gdiObjects
.Append((wxObject
*)record
->param1
);
2115 case META_CREATEBITMAPINDIRECT
:
2118 m_gdiObjects
.Append(NULL
);
2121 case META_CREATEBITMAP
:
2124 m_gdiObjects
.Append(NULL
);
2127 case META_CREATEREGION
:
2130 m_gdiObjects
.Append(NULL
);
2138 node
= node
->GetNext();
2140 double actualWidth
= (double)fabs(metaFile
->right
- metaFile
->left
);
2141 double actualHeight
= (double)fabs(metaFile
->bottom
- metaFile
->top
);
2143 double initialScaleX
= 1.0;
2144 double initialScaleY
= 1.0;
2146 double xoffset
, yoffset
;
2148 // Translate so origin is at centre of rectangle
2149 if (metaFile
->bottom
> metaFile
->top
)
2150 yoffset
= - (double)((metaFile
->bottom
- metaFile
->top
)/2.0);
2152 yoffset
= - (double)((metaFile
->top
- metaFile
->bottom
)/2.0);
2154 if (metaFile
->right
> metaFile
->left
)
2155 xoffset
= - (double)((metaFile
->right
- metaFile
->left
)/2.0);
2157 xoffset
= - (double)((metaFile
->left
- metaFile
->right
)/2.0);
2159 Translate(xoffset
, yoffset
);
2161 // Scale to a reasonable size (take the width of this wxDrawnShape
2163 if (actualWidth
!= 0.0)
2165 initialScaleX
= (double)((*rwidth
) / actualWidth
);
2166 initialScaleY
= initialScaleX
;
2167 (*rheight
) = initialScaleY
*actualHeight
;
2169 Scale(initialScaleX
, initialScaleY
);
2171 m_width
= (actualWidth
*initialScaleX
);
2172 m_height
= *rheight
;
2178 // Scale to fit size
2179 void wxPseudoMetaFile::ScaleTo(double w
, double h
)
2181 double scaleX
= (double)(w
/m_width
);
2182 double scaleY
= (double)(h
/m_height
);
2185 Scale(scaleX
, scaleY
);
2188 void wxPseudoMetaFile::GetBounds(double *boundMinX
, double *boundMinY
, double *boundMaxX
, double *boundMaxY
)
2190 double maxX
= (double) -99999.9;
2191 double maxY
= (double) -99999.9;
2192 double minX
= (double) 99999.9;
2193 double minY
= (double) 99999.9;
2195 wxNode
*node
= m_ops
.GetFirst();
2198 wxDrawOp
*op
= (wxDrawOp
*)node
->GetData();
2199 switch (op
->GetOp())
2201 case DRAWOP_DRAW_LINE
:
2202 case DRAWOP_DRAW_RECT
:
2203 case DRAWOP_DRAW_ROUNDED_RECT
:
2204 case DRAWOP_DRAW_ELLIPSE
:
2205 case DRAWOP_DRAW_POINT
:
2206 case DRAWOP_DRAW_TEXT
:
2208 wxOpDraw
*opDraw
= (wxOpDraw
*)op
;
2209 if (opDraw
->m_x1
< minX
) minX
= opDraw
->m_x1
;
2210 if (opDraw
->m_x1
> maxX
) maxX
= opDraw
->m_x1
;
2211 if (opDraw
->m_y1
< minY
) minY
= opDraw
->m_y1
;
2212 if (opDraw
->m_y1
> maxY
) maxY
= opDraw
->m_y1
;
2213 if (op
->GetOp() == DRAWOP_DRAW_LINE
)
2215 if (opDraw
->m_x2
< minX
) minX
= opDraw
->m_x2
;
2216 if (opDraw
->m_x2
> maxX
) maxX
= opDraw
->m_x2
;
2217 if (opDraw
->m_y2
< minY
) minY
= opDraw
->m_y2
;
2218 if (opDraw
->m_y2
> maxY
) maxY
= opDraw
->m_y2
;
2220 else if (op
->GetOp() == DRAWOP_DRAW_RECT
||
2221 op
->GetOp() == DRAWOP_DRAW_ROUNDED_RECT
||
2222 op
->GetOp() == DRAWOP_DRAW_ELLIPSE
)
2224 if ((opDraw
->m_x1
+ opDraw
->m_x2
) < minX
) minX
= (opDraw
->m_x1
+ opDraw
->m_x2
);
2225 if ((opDraw
->m_x1
+ opDraw
->m_x2
) > maxX
) maxX
= (opDraw
->m_x1
+ opDraw
->m_x2
);
2226 if ((opDraw
->m_y1
+ opDraw
->m_y2
) < minY
) minY
= (opDraw
->m_y1
+ opDraw
->m_y2
);
2227 if ((opDraw
->m_y1
+ opDraw
->m_y2
) > maxY
) maxY
= (opDraw
->m_y1
+ opDraw
->m_y2
);
2231 case DRAWOP_DRAW_ARC
:
2233 // TODO: don't yet know how to calculate the bounding box
2234 // for an arc. So pretend it's a line; to get a correct
2235 // bounding box, draw a blank rectangle first, of the correct
2237 wxOpDraw
*opDraw
= (wxOpDraw
*)op
;
2238 if (opDraw
->m_x1
< minX
) minX
= opDraw
->m_x1
;
2239 if (opDraw
->m_x1
> maxX
) maxX
= opDraw
->m_x1
;
2240 if (opDraw
->m_y1
< minY
) minY
= opDraw
->m_y1
;
2241 if (opDraw
->m_y1
> maxY
) maxY
= opDraw
->m_y1
;
2242 if (opDraw
->m_x2
< minX
) minX
= opDraw
->m_x2
;
2243 if (opDraw
->m_x2
> maxX
) maxX
= opDraw
->m_x2
;
2244 if (opDraw
->m_y2
< minY
) minY
= opDraw
->m_y2
;
2245 if (opDraw
->m_y2
> maxY
) maxY
= opDraw
->m_y2
;
2248 case DRAWOP_DRAW_POLYLINE
:
2249 case DRAWOP_DRAW_POLYGON
:
2250 case DRAWOP_DRAW_SPLINE
:
2252 wxOpPolyDraw
*poly
= (wxOpPolyDraw
*)op
;
2253 for (int i
= 0; i
< poly
->m_noPoints
; i
++)
2255 if (poly
->m_points
[i
].x
< minX
) minX
= poly
->m_points
[i
].x
;
2256 if (poly
->m_points
[i
].x
> maxX
) maxX
= poly
->m_points
[i
].x
;
2257 if (poly
->m_points
[i
].y
< minY
) minY
= poly
->m_points
[i
].y
;
2258 if (poly
->m_points
[i
].y
> maxY
) maxY
= poly
->m_points
[i
].y
;
2265 node
= node
->GetNext();
2273 *w = (double)fabs(maxX - minX);
2274 *h = (double)fabs(maxY - minY);
2278 // Calculate size from current operations
2279 void wxPseudoMetaFile::CalculateSize(wxDrawnShape
* shape
)
2281 double boundMinX
, boundMinY
, boundMaxX
, boundMaxY
;
2283 GetBounds(& boundMinX
, & boundMinY
, & boundMaxX
, & boundMaxY
);
2285 SetSize(boundMaxX
- boundMinX
, boundMaxY
- boundMinY
);
2289 shape
->SetWidth(m_width
);
2290 shape
->SetHeight(m_height
);
2294 // Set of functions for drawing into a pseudo metafile.
2295 // They use integers, but doubles are used internally for accuracy
2298 void wxPseudoMetaFile::DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
)
2300 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_LINE
,
2301 (double) pt1
.x
, (double) pt1
.y
, (double) pt2
.x
, (double) pt2
.y
);
2303 m_ops
.Append(theOp
);
2306 void wxPseudoMetaFile::DrawRectangle(const wxRect
& rect
)
2308 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_RECT
,
2309 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2311 m_ops
.Append(theOp
);
2314 void wxPseudoMetaFile::DrawRoundedRectangle(const wxRect
& rect
, double radius
)
2316 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_ROUNDED_RECT
,
2317 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2319 theOp
->m_radius
= radius
;
2321 m_ops
.Append(theOp
);
2324 void wxPseudoMetaFile::DrawEllipse(const wxRect
& rect
)
2326 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_ELLIPSE
,
2327 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2329 m_ops
.Append(theOp
);
2332 void wxPseudoMetaFile::DrawArc(const wxPoint
& centrePt
, const wxPoint
& startPt
, const wxPoint
& endPt
)
2334 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_ARC
,
2335 (double) centrePt
.x
, (double) centrePt
.y
, (double) startPt
.x
, (double) startPt
.y
);
2337 theOp
->m_x3
= (double) endPt
.x
;
2338 theOp
->m_y3
= (double) endPt
.y
;
2340 m_ops
.Append(theOp
);
2343 void wxPseudoMetaFile::DrawEllipticArc(const wxRect
& rect
, double startAngle
, double endAngle
)
2345 const double pi
= 3.1415926535897932384626433832795 ;
2347 double startAngleRadians
= startAngle
* (pi
*2.0/360.0);
2348 double endAngleRadians
= endAngle
* (pi
*2.0/360.0);
2350 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_ELLIPTIC_ARC
,
2351 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2353 theOp
->m_x3
= startAngleRadians
;
2354 theOp
->m_y3
= endAngleRadians
;
2356 m_ops
.Append(theOp
);
2359 void wxPseudoMetaFile::DrawPoint(const wxPoint
& pt
)
2361 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_POINT
,
2362 (double) pt
.x
, (double) pt
.y
, 0.0, 0.0);
2364 m_ops
.Append(theOp
);
2367 void wxPseudoMetaFile::DrawText(const wxString
& text
, const wxPoint
& pt
)
2369 wxOpDraw
*theOp
= new wxOpDraw(DRAWOP_DRAW_TEXT
,
2370 (double) pt
.x
, (double) pt
.y
, 0.0, 0.0);
2372 theOp
->m_textString
= copystring(text
);
2374 m_ops
.Append(theOp
);
2377 void wxPseudoMetaFile::DrawLines(int n
, wxPoint pts
[])
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_POLYLINE
, n
, realPoints
);
2387 m_ops
.Append(theOp
);
2390 void wxPseudoMetaFile::DrawPolygon(int n
, wxPoint pts
[], int flags
)
2392 wxRealPoint
* realPoints
= new wxRealPoint
[n
];
2394 for (i
= 0; i
< n
; i
++)
2396 realPoints
[i
].x
= pts
[i
].x
;
2397 realPoints
[i
].y
= pts
[i
].y
;
2399 wxOpPolyDraw
* theOp
= new wxOpPolyDraw(DRAWOP_DRAW_POLYGON
, n
, realPoints
);
2400 m_ops
.Append(theOp
);
2402 if (flags
& oglMETAFLAGS_OUTLINE
)
2403 m_outlineOp
= (m_ops
.GetCount() - 1);
2406 void wxPseudoMetaFile::DrawSpline(int n
, wxPoint pts
[])
2408 wxRealPoint
* realPoints
= new wxRealPoint
[n
];
2410 for (i
= 0; i
< n
; i
++)
2412 realPoints
[i
].x
= pts
[i
].x
;
2413 realPoints
[i
].y
= pts
[i
].y
;
2415 wxOpPolyDraw
* theOp
= new wxOpPolyDraw(DRAWOP_DRAW_SPLINE
, n
, realPoints
);
2416 m_ops
.Append(theOp
);
2419 void wxPseudoMetaFile::SetClippingRect(const wxRect
& rect
)
2421 wxOpSetClipping
* theOp
= new wxOpSetClipping(DRAWOP_SET_CLIPPING_RECT
,
2422 (double) rect
.x
, (double) rect
.y
, (double) rect
.width
, (double) rect
.height
);
2425 void wxPseudoMetaFile::DestroyClippingRect()
2427 wxOpSetClipping
* theOp
= new wxOpSetClipping(DRAWOP_DESTROY_CLIPPING_RECT
,
2428 0.0, 0.0, 0.0, 0.0);
2430 m_ops
.Append(theOp
);
2433 void wxPseudoMetaFile::SetPen(wxPen
* pen
, bool isOutline
)
2435 m_gdiObjects
.Append(pen
);
2436 int n
= m_gdiObjects
.GetCount();
2438 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_PEN
, this, n
- 1);
2440 m_ops
.Append(theOp
);
2444 m_outlineColours
.Append((wxObject
*) (n
- 1));
2448 void wxPseudoMetaFile::SetBrush(wxBrush
* brush
, bool isFill
)
2450 m_gdiObjects
.Append(brush
);
2451 int n
= m_gdiObjects
.GetCount();
2453 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_BRUSH
, this, n
- 1);
2455 m_ops
.Append(theOp
);
2459 m_fillColours
.Append((wxObject
*) (n
- 1));
2463 void wxPseudoMetaFile::SetFont(wxFont
* font
)
2465 m_gdiObjects
.Append(font
);
2466 int n
= m_gdiObjects
.GetCount();
2468 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_FONT
, this, n
- 1);
2470 m_ops
.Append(theOp
);
2473 void wxPseudoMetaFile::SetTextColour(const wxColour
& colour
)
2475 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_TEXT_COLOUR
, this, 0);
2476 theOp
->m_r
= colour
.Red();
2477 theOp
->m_g
= colour
.Green();
2478 theOp
->m_b
= colour
.Blue();
2480 m_ops
.Append(theOp
);
2483 void wxPseudoMetaFile::SetBackgroundColour(const wxColour
& colour
)
2485 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_BK_COLOUR
, this, 0);
2486 theOp
->m_r
= colour
.Red();
2487 theOp
->m_g
= colour
.Green();
2488 theOp
->m_b
= colour
.Blue();
2490 m_ops
.Append(theOp
);
2493 void wxPseudoMetaFile::SetBackgroundMode(int mode
)
2495 wxOpSetGDI
* theOp
= new wxOpSetGDI(DRAWOP_SET_BK_MODE
, this, 0, mode
);
2497 m_ops
.Append(theOp
);