1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDrawnShape
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "drawn.h"
21 #define oglMETAFLAGS_OUTLINE 1
22 #define oglMETAFLAGS_ATTACHMENTS 2
25 class wxPseudoMetaFile
: public wxObject
27 DECLARE_DYNAMIC_CLASS(wxPseudoMetaFile
)
30 wxPseudoMetaFile(wxPseudoMetaFile
& mf
);
33 void Draw(wxDC
& dc
, double xoffset
, double yoffset
);
36 void WritePrologAttributes(wxExpr
*clause
, int whichAngle
);
37 void ReadPrologAttributes(wxExpr
*clause
, int whichAngle
);
42 void Copy(wxPseudoMetaFile
& copy
);
44 void Scale(double sx
, double sy
);
45 void ScaleTo(double w
, double h
); // Scale to fit size
46 void Translate(double x
, double y
);
48 // Rotate about the given axis by theta radians from the x axis.
49 void Rotate(double x
, double y
, double theta
);
51 bool LoadFromMetaFile(char *filename
, double *width
, double *height
);
53 void GetBounds(double *minX
, double *minY
, double *maxX
, double *maxY
);
55 // Calculate size from current operations
56 void CalculateSize(wxDrawnShape
* shape
);
58 inline wxList
& GetOutlineColours() const { return (wxList
&) m_outlineColours
; }
59 inline wxList
& GetFillColours() const { return (wxList
&) m_fillColours
; }
60 inline void SetRotateable(bool rot
) { m_rotateable
= rot
; }
61 inline bool GetRotateable() const { return m_rotateable
; }
63 inline void SetSize(double w
, double h
) { m_width
= w
; m_height
= h
; }
65 inline void SetFillBrush(wxBrush
* brush
) { m_fillBrush
= brush
; }
66 inline wxBrush
* GetFillBrush() const { return m_fillBrush
; }
68 inline void SetOutlinePen(wxPen
* pen
) { m_outlinePen
= pen
; }
69 inline wxPen
* GetOutlinePen() const { return m_outlinePen
; }
71 inline void SetOutlineOp(int op
) { m_outlineOp
= op
; }
72 inline int GetOutlineOp() const { return m_outlineOp
; }
74 inline wxList
& GetOps() const { return (wxList
&) m_ops
; }
76 // Is this a valid (non-empty) metafile?
77 inline bool IsValid() const { return (m_ops
.Number() > 0); }
80 /// Set of functions for drawing into a pseudo metafile.
81 /// They use integers, but doubles are used internally for accuracy
84 virtual void DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
);
85 virtual void DrawRectangle(const wxRect
& rect
);
86 virtual void DrawRoundedRectangle(const wxRect
& rect
, double radius
);
87 virtual void DrawArc(const wxPoint
& centrePt
, const wxPoint
& startPt
, const wxPoint
& endPt
);
88 virtual void DrawEllipticArc(const wxRect
& rect
, double startAngle
, double endAngle
);
89 virtual void DrawEllipse(const wxRect
& rect
);
90 virtual void DrawPoint(const wxPoint
& pt
);
91 virtual void DrawText(const wxString
& text
, const wxPoint
& pt
);
92 virtual void DrawLines(int n
, wxPoint pts
[]);
94 // oglMETAFLAGS_OUTLINE: will be used for drawing the outline and
95 // also drawing lines/arrows at the circumference.
96 // oglMETAFLAGS_ATTACHMENTS: will be used for initialising attachment points at
97 // the vertices (perhaps a rare case...)
98 virtual void DrawPolygon(int n
, wxPoint pts
[], int flags
= 0);
99 virtual void DrawSpline(int n
, wxPoint pts
[]);
101 virtual void SetClippingRect(const wxRect
& rect
);
102 virtual void DestroyClippingRect();
104 virtual void SetPen(wxPen
* pen
, bool isOutline
= FALSE
); // TODO: eventually, just store GDI object attributes, not actual
105 virtual void SetBrush(wxBrush
* brush
, bool isFill
= FALSE
); // pens/brushes etc.
106 virtual void SetFont(wxFont
* font
);
107 virtual void SetTextColour(const wxColour
& colour
);
108 virtual void SetBackgroundColour(const wxColour
& colour
);
109 virtual void SetBackgroundMode(int mode
);
115 wxList m_ops
; // List of drawing operations (see drawnp.h)
116 wxList m_gdiObjects
; // List of pens, brushes and fonts for this object.
117 int m_outlineOp
; // The op representing the outline, if any
119 // Pen/brush specifying outline/fill colours
120 // to override operations.
122 wxBrush
* m_fillBrush
;
123 wxList m_outlineColours
; // List of the GDI operations that comprise the outline
124 wxList m_fillColours
; // List of the GDI operations that fill the shape
125 double m_currentRotation
;
128 #define oglDRAWN_ANGLE_0 0
129 #define oglDRAWN_ANGLE_90 1
130 #define oglDRAWN_ANGLE_180 2
131 #define oglDRAWN_ANGLE_270 3
133 class wxDrawnShape
: public wxRectangleShape
135 DECLARE_DYNAMIC_CLASS(wxDrawnShape
)
140 void OnDraw(wxDC
& dc
);
143 // Prolog database stuff
145 void WritePrologAttributes(wxExpr
*clause
);
146 void ReadPrologAttributes(wxExpr
*clause
);
149 // Does the copying for this object
150 void Copy(wxShape
& copy
);
152 void Scale(double sx
, double sy
);
153 void Translate(double x
, double y
);
154 // Rotate about the given axis by theta radians from the x axis.
155 void Rotate(double x
, double y
, double theta
);
157 // Get current rotation
158 inline double GetRotation() const { return m_rotation
; }
160 void SetSize(double w
, double h
, bool recursive
= TRUE
);
161 bool LoadFromMetaFile(char *filename
);
163 inline void SetSaveToFile(bool save
) { m_saveToFile
= save
; }
164 inline wxPseudoMetaFile
& GetMetaFile(int which
= 0) const { return (wxPseudoMetaFile
&) m_metafiles
[which
]; }
166 void OnDrawOutline(wxDC
& dc
, double x
, double y
, double w
, double h
);
168 // Get the perimeter point using the special outline op, if there is one,
169 // otherwise use default wxRectangleShape scheme
170 bool GetPerimeterPoint(double x1
, double y1
,
171 double x2
, double y2
,
172 double *x3
, double *y3
);
174 /// Set of functions for drawing into a pseudo metafile.
175 /// They use integers, but doubles are used internally for accuracy
178 virtual void DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
);
179 virtual void DrawRectangle(const wxRect
& rect
);
180 virtual void DrawRoundedRectangle(const wxRect
& rect
, double radius
);
181 virtual void DrawArc(const wxPoint
& centrePt
, const wxPoint
& startPt
, const wxPoint
& endPt
);
182 virtual void DrawEllipticArc(const wxRect
& rect
, double startAngle
, double endAngle
);
183 virtual void DrawEllipse(const wxRect
& rect
);
184 virtual void DrawPoint(const wxPoint
& pt
);
185 virtual void DrawText(const wxString
& text
, const wxPoint
& pt
);
186 virtual void DrawLines(int n
, wxPoint pts
[]);
187 virtual void DrawPolygon(int n
, wxPoint pts
[], int flags
= 0);
188 virtual void DrawSpline(int n
, wxPoint pts
[]);
190 virtual void SetClippingRect(const wxRect
& rect
);
191 virtual void DestroyClippingRect();
193 virtual void SetPen(wxPen
* pen
, bool isOutline
= FALSE
); // TODO: eventually, just store GDI object attributes, not actual
194 virtual void SetBrush(wxBrush
* brush
, bool isFill
= FALSE
); // pens/brushes etc.
195 virtual void SetFont(wxFont
* font
);
196 virtual void SetTextColour(const wxColour
& colour
);
197 virtual void SetBackgroundColour(const wxColour
& colour
);
198 virtual void SetBackgroundMode(int mode
);
200 // Set the width/height according to the shapes in the metafile.
201 // Call this after drawing into the shape.
202 inline void CalculateSize() { m_metafiles
[m_currentAngle
].CalculateSize(this); }
204 inline void DrawAtAngle(int angle
) { m_currentAngle
= angle
; };
206 inline int GetAngle() const { return m_currentAngle
; }
208 // Which metafile do we use now? Based on current rotation and validity
210 int DetermineMetaFile(double rotation
);
213 // One metafile for each 90 degree rotation (or just a single one).
214 wxPseudoMetaFile m_metafiles
[4];
216 // Don't save all wxDrawnShape metafiles to file: sometimes
217 // we take the metafile data from a symbol library.
220 // Which angle are we using/drawing into?