]> git.saurik.com Git - wxWidgets.git/blob - contrib/include/wx/ogl/drawn.h
Fixes after stock gdi changes within core library
[wxWidgets.git] / contrib / include / wx / ogl / drawn.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: drawn.h
3 // Purpose: wxDrawnShape
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 12/07/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _OGL_DRAWN_H_
13 #define _OGL_DRAWN_H_
14
15
16 #define oglMETAFLAGS_OUTLINE 1
17 #define oglMETAFLAGS_ATTACHMENTS 2
18
19 class WXDLLIMPEXP_OGL wxDrawnShape;
20 class WXDLLIMPEXP_OGL wxPseudoMetaFile: public wxObject
21 {
22 DECLARE_DYNAMIC_CLASS(wxPseudoMetaFile)
23 public:
24 wxPseudoMetaFile();
25 wxPseudoMetaFile(wxPseudoMetaFile& mf);
26 ~wxPseudoMetaFile();
27
28 void Draw(wxDC& dc, double xoffset, double yoffset);
29
30 #if wxUSE_PROLOGIO
31 void WriteAttributes(wxExpr *clause, int whichAngle);
32 void ReadAttributes(wxExpr *clause, int whichAngle);
33 #endif
34
35 void Clear();
36
37 void Copy(wxPseudoMetaFile& copy);
38
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);
42
43 // Rotate about the given axis by theta radians from the x axis.
44 void Rotate(double x, double y, double theta);
45
46 bool LoadFromMetaFile(const wxString& filename, double *width, double *height);
47
48 void GetBounds(double *minX, double *minY, double *maxX, double *maxY);
49
50 // Calculate size from current operations
51 void CalculateSize(wxDrawnShape* shape);
52
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; }
57
58 inline void SetSize(double w, double h) { m_width = w; m_height = h; }
59
60 inline void SetFillBrush(wxBrush* brush) { m_fillBrush = brush; }
61 inline const wxBrush* GetFillBrush() const { return m_fillBrush; }
62
63 inline void SetOutlinePen(wxPen* pen) { m_outlinePen = pen; }
64 inline const wxPen* GetOutlinePen() const { return m_outlinePen; }
65
66 inline void SetOutlineOp(int op) { m_outlineOp = op; }
67 inline int GetOutlineOp() const { return m_outlineOp; }
68
69 inline wxList& GetOps() const { return (wxList&) m_ops; }
70
71 // Is this a valid (non-empty) metafile?
72 inline bool IsValid() const { return (m_ops.GetCount() > 0); }
73
74 public:
75 /// Set of functions for drawing into a pseudo metafile.
76 /// They use integers, but doubles are used internally for accuracy
77 /// when scaling.
78
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[]);
88 // flags:
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[]);
95
96 virtual void SetClippingRect(const wxRect& rect);
97 virtual void DestroyClippingRect();
98
99 virtual void SetPen(const wxPen* pen, bool isOutline = false); // TODO: eventually, just store GDI object attributes, not actual
100 virtual void SetBrush(const 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);
105
106 public:
107 bool m_rotateable;
108 double m_width;
109 double m_height;
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
113
114 // Pen/brush specifying outline/fill colours
115 // to override operations.
116 const wxPen* m_outlinePen;
117 const 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;
121 };
122
123 #define oglDRAWN_ANGLE_0 0
124 #define oglDRAWN_ANGLE_90 1
125 #define oglDRAWN_ANGLE_180 2
126 #define oglDRAWN_ANGLE_270 3
127
128 class WXDLLIMPEXP_OGL wxDrawnShape: public wxRectangleShape
129 {
130 DECLARE_DYNAMIC_CLASS(wxDrawnShape)
131 public:
132 wxDrawnShape();
133 ~wxDrawnShape();
134
135 void OnDraw(wxDC& dc);
136
137 #if wxUSE_PROLOGIO
138 // I/O
139 void WriteAttributes(wxExpr *clause);
140 void ReadAttributes(wxExpr *clause);
141 #endif
142
143 // Does the copying for this object
144 void Copy(wxShape& copy);
145
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);
150
151 // Get current rotation
152 inline double GetRotation() const { return m_rotation; }
153
154 void SetSize(double w, double h, bool recursive = true);
155 bool LoadFromMetaFile(const wxString& filename);
156
157 inline void SetSaveToFile(bool save) { m_saveToFile = save; }
158 inline wxPseudoMetaFile& GetMetaFile(int which = 0) const { return (wxPseudoMetaFile&) m_metafiles[which]; }
159
160 void OnDrawOutline(wxDC& dc, double x, double y, double w, double h);
161
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);
167
168 /// Set of functions for drawing into a pseudo metafile.
169 /// They use integers, but doubles are used internally for accuracy
170 /// when scaling.
171
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[]);
183
184 virtual void SetClippingRect(const wxRect& rect);
185 virtual void DestroyClippingRect();
186
187 virtual void SetDrawnPen(const wxPen* pen, bool isOutline = false); // TODO: eventually, just store GDI object attributes, not actual
188 virtual void SetDrawnBrush(const 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);
193
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); }
197
198 inline void DrawAtAngle(int angle) { m_currentAngle = angle; };
199
200 inline int GetAngle() const { return m_currentAngle; }
201
202 // Implementation
203 protected:
204 // Which metafile do we use now? Based on current rotation and validity
205 // of metafiles.
206 int DetermineMetaFile(double rotation);
207
208 private:
209 // One metafile for each 90 degree rotation (or just a single one).
210 wxPseudoMetaFile m_metafiles[4];
211
212 // Don't save all wxDrawnShape metafiles to file: sometimes
213 // we take the metafile data from a symbol library.
214 bool m_saveToFile;
215
216 // Which angle are we using/drawing into?
217 int m_currentAngle;
218 };
219
220 #endif
221 // _DRAWN_H_