1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxDrawnShape
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
16 #pragma interface "drawn.h"
22 class wxPseudoMetaFile
: public wxObject
24 DECLARE_DYNAMIC_CLASS(wxPseudoMetaFile
)
27 wxPseudoMetaFile(wxPseudoMetaFile
& mf
);
30 void Draw(wxDC
& dc
, float xoffset
, float yoffset
);
33 void WritePrologAttributes(wxExpr
*clause
);
34 void ReadPrologAttributes(wxExpr
*clause
);
39 void Copy(wxPseudoMetaFile
& copy
);
41 void Scale(float sx
, float sy
);
42 void ScaleTo(float w
, float h
); // Scale to fit size
43 void Translate(float x
, float y
);
45 // Rotate about the given axis by theta radians from the x axis.
46 void Rotate(float x
, float y
, float theta
);
48 bool LoadFromMetaFile(char *filename
, float *width
, float *height
);
50 void GetBounds(float *minX
, float *minY
, float *maxX
, float *maxY
);
52 // Calculate size from current operations
53 void CalculateSize(wxDrawnShape
* shape
);
55 inline wxList
& GetOutlineColours() const { return (wxList
&) m_outlineColours
; }
56 inline wxList
& GetFillColours() const { return (wxList
&) m_fillColours
; }
57 inline void SetRotateable(bool rot
) { m_rotateable
= rot
; }
58 inline bool GetRotateable() const { return m_rotateable
; }
60 inline void SetSize(float w
, float h
) { m_width
= w
; m_height
= h
; }
62 inline void SetFillBrush(wxBrush
* brush
) { m_fillBrush
= brush
; }
63 inline wxBrush
* GetFillBrush() const { return m_fillBrush
; }
65 inline void SetOutlinePen(wxPen
* pen
) { m_outlinePen
= pen
; }
66 inline wxPen
* GetOutlinePen() const { return m_outlinePen
; }
69 /// Set of functions for drawing into a pseudo metafile.
70 /// They use integers, but doubles are used internally for accuracy
73 virtual void DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
);
74 virtual void DrawRectangle(const wxRect
& rect
);
75 virtual void DrawRoundedRectangle(const wxRect
& rect
, double radius
);
76 virtual void DrawEllipse(const wxRect
& rect
);
77 virtual void DrawPoint(const wxPoint
& pt
);
78 virtual void DrawText(const wxString
& text
, const wxPoint
& pt
);
79 virtual void DrawLines(int n
, wxPoint pts
[]);
80 virtual void DrawPolygon(int n
, wxPoint pts
[]);
81 virtual void DrawSpline(int n
, wxPoint pts
[]);
83 virtual void SetClippingRect(const wxRect
& rect
);
84 virtual void DestroyClippingRect();
86 virtual void SetPen(wxPen
* pen
, bool isOutline
= FALSE
); // TODO: eventually, just store GDI object attributes, not actual
87 virtual void SetBrush(wxBrush
* brush
, bool isFill
= FALSE
); // pens/brushes etc.
88 virtual void SetFont(wxFont
* font
);
89 virtual void SetTextColour(const wxColour
& colour
);
90 virtual void SetBackgroundColour(const wxColour
& colour
);
91 virtual void SetBackgroundMode(int mode
);
97 wxList m_ops
; // List of drawing operations (see drawnp.h)
98 wxList m_gdiObjects
; // List of pens, brushes and fonts for this object.
100 // Pen/brush specifying outline/fill colours
101 // to override operations.
103 wxBrush
* m_fillBrush
;
104 wxList m_outlineColours
; // List of the GDI operations that comprise the outline
105 wxList m_fillColours
; // List of the GDI operations that fill the shape
106 float m_currentRotation
;
109 class wxDrawnShape
: public wxRectangleShape
111 DECLARE_DYNAMIC_CLASS(wxDrawnShape
)
116 void OnDraw(wxDC
& dc
);
119 // Prolog database stuff
121 void WritePrologAttributes(wxExpr
*clause
);
122 void ReadPrologAttributes(wxExpr
*clause
);
125 // Does the copying for this object
126 void Copy(wxShape
& copy
);
128 void Scale(float sx
, float sy
);
129 void Translate(float x
, float y
);
130 // Rotate about the given axis by theta radians from the x axis.
131 void Rotate(float x
, float y
, float theta
);
133 // Get current rotation
134 inline float GetRotation() const { return m_rotation
; }
136 void SetSize(float w
, float h
, bool recursive
= TRUE
);
137 bool LoadFromMetaFile(char *filename
);
139 inline void SetSaveToFile(bool save
) { m_saveToFile
= save
; }
140 inline wxPseudoMetaFile
& GetMetaFile() const { return (wxPseudoMetaFile
&) m_metafile
; }
142 /// Set of functions for drawing into a pseudo metafile.
143 /// They use integers, but doubles are used internally for accuracy
146 virtual void DrawLine(const wxPoint
& pt1
, const wxPoint
& pt2
);
147 virtual void DrawRectangle(const wxRect
& rect
);
148 virtual void DrawRoundedRectangle(const wxRect
& rect
, double radius
);
149 virtual void DrawEllipse(const wxRect
& rect
);
150 virtual void DrawPoint(const wxPoint
& pt
);
151 virtual void DrawText(const wxString
& text
, const wxPoint
& pt
);
152 virtual void DrawLines(int n
, wxPoint pts
[]);
153 virtual void DrawPolygon(int n
, wxPoint pts
[]);
154 virtual void DrawSpline(int n
, wxPoint pts
[]);
156 virtual void SetClippingRect(const wxRect
& rect
);
157 virtual void DestroyClippingRect();
159 virtual void SetPen(wxPen
* pen
, bool isOutline
= FALSE
); // TODO: eventually, just store GDI object attributes, not actual
160 virtual void SetBrush(wxBrush
* brush
, bool isFill
= FALSE
); // pens/brushes etc.
161 virtual void SetFont(wxFont
* font
);
162 virtual void SetTextColour(const wxColour
& colour
);
163 virtual void SetBackgroundColour(const wxColour
& colour
);
164 virtual void SetBackgroundMode(int mode
);
166 // Set the width/height according to the shapes in the metafile.
167 // Call this after drawing into the shape.
168 inline void CalculateSize() { m_metafile
.CalculateSize(this); }
171 wxPseudoMetaFile m_metafile
;
173 // Don't save all wxDrawnShape metafiles to file: sometimes
174 // we take the metafile data from a symbol library.