1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDrawnShape
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #define oglMETAFLAGS_OUTLINE 1
17 #define oglMETAFLAGS_ATTACHMENTS 2
19 class WXDLLIMPEXP_OGL wxDrawnShape
;
20 class WXDLLIMPEXP_OGL wxPseudoMetaFile
: public wxObject
22 DECLARE_DYNAMIC_CLASS(wxPseudoMetaFile
)
25 wxPseudoMetaFile(wxPseudoMetaFile
& mf
);
28 void Draw(wxDC
& dc
, double xoffset
, double yoffset
);
31 void WriteAttributes(wxExpr
*clause
, int whichAngle
);
32 void ReadAttributes(wxExpr
*clause
, int whichAngle
);
37 void Copy(wxPseudoMetaFile
& copy
);
39 void Scale(double sx
, double sy
);
40 void ScaleTo(double w
, double h
); // Scale to fit size
41 void Translate(double x
, double y
);
43 // Rotate about the given axis by theta radians from the x axis.
44 void Rotate(double x
, double y
, double theta
);
46 bool LoadFromMetaFile(const wxString
& filename
, double *width
, double *height
);
48 void GetBounds(double *minX
, double *minY
, double *maxX
, double *maxY
);
50 // Calculate size from current operations
51 void CalculateSize(wxDrawnShape
* shape
);
53 inline wxList
& GetOutlineColours() const { return (wxList
&) m_outlineColours
; }
54 inline wxList
& GetFillColours() const { return (wxList
&) m_fillColours
; }
55 inline void SetRotateable(bool rot
) { m_rotateable
= rot
; }
56 inline bool GetRotateable() const { return m_rotateable
; }
58 inline void SetSize(double w
, double h
) { m_width
= w
; m_height
= h
; }
60 inline void SetFillBrush(wxBrush
* brush
) { m_fillBrush
= brush
; }
61 inline wxBrush
* GetFillBrush() const { return m_fillBrush
; }
63 inline void SetOutlinePen(wxPen
* pen
) { m_outlinePen
= pen
; }
64 inline wxPen
* GetOutlinePen() const { return m_outlinePen
; }
66 inline void SetOutlineOp(int op
) { m_outlineOp
= op
; }
67 inline int GetOutlineOp() const { return m_outlineOp
; }
69 inline wxList
& GetOps() const { return (wxList
&) m_ops
; }
71 // Is this a valid (non-empty) metafile?
72 inline bool IsValid() const { return (m_ops
.GetCount() > 0); }
75 /// Set of functions for drawing into a pseudo metafile.
76 /// They use integers, but doubles are used internally for accuracy
79 virtual void DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
);
80 virtual void DrawRectangle(const wxRect
& rect
);
81 virtual void DrawRoundedRectangle(const wxRect
& rect
, double radius
);
82 virtual void DrawArc(const wxPoint
& centrePt
, const wxPoint
& startPt
, const wxPoint
& endPt
);
83 virtual void DrawEllipticArc(const wxRect
& rect
, double startAngle
, double endAngle
);
84 virtual void DrawEllipse(const wxRect
& rect
);
85 virtual void DrawPoint(const wxPoint
& pt
);
86 virtual void DrawText(const wxString
& text
, const wxPoint
& pt
);
87 virtual void DrawLines(int n
, wxPoint pts
[]);
89 // oglMETAFLAGS_OUTLINE: will be used for drawing the outline and
90 // also drawing lines/arrows at the circumference.
91 // oglMETAFLAGS_ATTACHMENTS: will be used for initialising attachment points at
92 // the vertices (perhaps a rare case...)
93 virtual void DrawPolygon(int n
, wxPoint pts
[], int flags
= 0);
94 virtual void DrawSpline(int n
, wxPoint pts
[]);
96 virtual void SetClippingRect(const wxRect
& rect
);
97 virtual void DestroyClippingRect();
99 virtual void SetPen(wxPen
* pen
, bool isOutline
= false); // TODO: eventually, just store GDI object attributes, not actual
100 virtual void SetBrush(wxBrush
* brush
, bool isFill
= false); // pens/brushes etc.
101 virtual void SetFont(wxFont
* font
);
102 virtual void SetTextColour(const wxColour
& colour
);
103 virtual void SetBackgroundColour(const wxColour
& colour
);
104 virtual void SetBackgroundMode(int mode
);
110 wxList m_ops
; // List of drawing operations (see drawnp.h)
111 wxList m_gdiObjects
; // List of pens, brushes and fonts for this object.
112 int m_outlineOp
; // The op representing the outline, if any
114 // Pen/brush specifying outline/fill colours
115 // to override operations.
117 wxBrush
* m_fillBrush
;
118 wxList m_outlineColours
; // List of the GDI operations that comprise the outline
119 wxList m_fillColours
; // List of the GDI operations that fill the shape
120 double m_currentRotation
;
123 #define oglDRAWN_ANGLE_0 0
124 #define oglDRAWN_ANGLE_90 1
125 #define oglDRAWN_ANGLE_180 2
126 #define oglDRAWN_ANGLE_270 3
128 class WXDLLIMPEXP_OGL wxDrawnShape
: public wxRectangleShape
130 DECLARE_DYNAMIC_CLASS(wxDrawnShape
)
135 void OnDraw(wxDC
& dc
);
139 void WriteAttributes(wxExpr
*clause
);
140 void ReadAttributes(wxExpr
*clause
);
143 // Does the copying for this object
144 void Copy(wxShape
& copy
);
146 void Scale(double sx
, double sy
);
147 void Translate(double x
, double y
);
148 // Rotate about the given axis by theta radians from the x axis.
149 void Rotate(double x
, double y
, double theta
);
151 // Get current rotation
152 inline double GetRotation() const { return m_rotation
; }
154 void SetSize(double w
, double h
, bool recursive
= true);
155 bool LoadFromMetaFile(const wxString
& filename
);
157 inline void SetSaveToFile(bool save
) { m_saveToFile
= save
; }
158 inline wxPseudoMetaFile
& GetMetaFile(int which
= 0) const { return (wxPseudoMetaFile
&) m_metafiles
[which
]; }
160 void OnDrawOutline(wxDC
& dc
, double x
, double y
, double w
, double h
);
162 // Get the perimeter point using the special outline op, if there is one,
163 // otherwise use default wxRectangleShape scheme
164 bool GetPerimeterPoint(double x1
, double y1
,
165 double x2
, double y2
,
166 double *x3
, double *y3
);
168 /// Set of functions for drawing into a pseudo metafile.
169 /// They use integers, but doubles are used internally for accuracy
172 virtual void DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
);
173 virtual void DrawRectangle(const wxRect
& rect
);
174 virtual void DrawRoundedRectangle(const wxRect
& rect
, double radius
);
175 virtual void DrawArc(const wxPoint
& centrePt
, const wxPoint
& startPt
, const wxPoint
& endPt
);
176 virtual void DrawEllipticArc(const wxRect
& rect
, double startAngle
, double endAngle
);
177 virtual void DrawEllipse(const wxRect
& rect
);
178 virtual void DrawPoint(const wxPoint
& pt
);
179 virtual void DrawText(const wxString
& text
, const wxPoint
& pt
);
180 virtual void DrawLines(int n
, wxPoint pts
[]);
181 virtual void DrawPolygon(int n
, wxPoint pts
[], int flags
= 0);
182 virtual void DrawSpline(int n
, wxPoint pts
[]);
184 virtual void SetClippingRect(const wxRect
& rect
);
185 virtual void DestroyClippingRect();
187 virtual void SetDrawnPen(wxPen
* pen
, bool isOutline
= false); // TODO: eventually, just store GDI object attributes, not actual
188 virtual void SetDrawnBrush(wxBrush
* brush
, bool isFill
= false); // pens/brushes etc.
189 virtual void SetDrawnFont(wxFont
* font
);
190 virtual void SetDrawnTextColour(const wxColour
& colour
);
191 virtual void SetDrawnBackgroundColour(const wxColour
& colour
);
192 virtual void SetDrawnBackgroundMode(int mode
);
194 // Set the width/height according to the shapes in the metafile.
195 // Call this after drawing into the shape.
196 inline void CalculateSize() { m_metafiles
[m_currentAngle
].CalculateSize(this); }
198 inline void DrawAtAngle(int angle
) { m_currentAngle
= angle
; };
200 inline int GetAngle() const { return m_currentAngle
; }
204 // Which metafile do we use now? Based on current rotation and validity
206 int DetermineMetaFile(double rotation
);
209 // One metafile for each 90 degree rotation (or just a single one).
210 wxPseudoMetaFile m_metafiles
[4];
212 // Don't save all wxDrawnShape metafiles to file: sometimes
213 // we take the metafile data from a symbol library.
216 // Which angle are we using/drawing into?