]> git.saurik.com Git - wxWidgets.git/blame - contrib/include/wx/ogl/drawn.h
setter by ref for
[wxWidgets.git] / contrib / include / wx / ogl / drawn.h
CommitLineData
1fc25a89
JS
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
ab7ce33c 15#if defined(__GNUG__) && !defined(__APPLE__)
1fc25a89
JS
16#pragma interface "drawn.h"
17#endif
18
1fc25a89
JS
19
20#define oglMETAFLAGS_OUTLINE 1
21#define oglMETAFLAGS_ATTACHMENTS 2
22
5f331691
RD
23class WXDLLIMPEXP_OGL wxDrawnShape;
24class WXDLLIMPEXP_OGL wxPseudoMetaFile: public wxObject
1fc25a89
JS
25{
26 DECLARE_DYNAMIC_CLASS(wxPseudoMetaFile)
27 public:
28 wxPseudoMetaFile();
29 wxPseudoMetaFile(wxPseudoMetaFile& mf);
30 ~wxPseudoMetaFile();
31
32 void Draw(wxDC& dc, double xoffset, double yoffset);
33
2b5f62a0 34#if wxUSE_PROLOGIO
1fc25a89
JS
35 void WriteAttributes(wxExpr *clause, int whichAngle);
36 void ReadAttributes(wxExpr *clause, int whichAngle);
37#endif
38
39 void Clear();
40
41 void Copy(wxPseudoMetaFile& copy);
42
43 void Scale(double sx, double sy);
44 void ScaleTo(double w, double h); // Scale to fit size
45 void Translate(double x, double y);
46
47 // Rotate about the given axis by theta radians from the x axis.
48 void Rotate(double x, double y, double theta);
49
9e053640 50 bool LoadFromMetaFile(const wxString& filename, double *width, double *height);
1fc25a89
JS
51
52 void GetBounds(double *minX, double *minY, double *maxX, double *maxY);
53
54 // Calculate size from current operations
55 void CalculateSize(wxDrawnShape* shape);
56
57 inline wxList& GetOutlineColours() const { return (wxList&) m_outlineColours; }
58 inline wxList& GetFillColours() const { return (wxList&) m_fillColours; }
59 inline void SetRotateable(bool rot) { m_rotateable = rot; }
60 inline bool GetRotateable() const { return m_rotateable; }
61
62 inline void SetSize(double w, double h) { m_width = w; m_height = h; }
63
64 inline void SetFillBrush(wxBrush* brush) { m_fillBrush = brush; }
65 inline wxBrush* GetFillBrush() const { return m_fillBrush; }
66
67 inline void SetOutlinePen(wxPen* pen) { m_outlinePen = pen; }
68 inline wxPen* GetOutlinePen() const { return m_outlinePen; }
69
70 inline void SetOutlineOp(int op) { m_outlineOp = op; }
71 inline int GetOutlineOp() const { return m_outlineOp; }
72
73 inline wxList& GetOps() const { return (wxList&) m_ops; }
74
75 // Is this a valid (non-empty) metafile?
b9ac87bc 76 inline bool IsValid() const { return (m_ops.GetCount() > 0); }
1fc25a89
JS
77
78public:
79 /// Set of functions for drawing into a pseudo metafile.
80 /// They use integers, but doubles are used internally for accuracy
81 /// when scaling.
82
83 virtual void DrawLine(const wxPoint& pt1, const wxPoint& pt2);
84 virtual void DrawRectangle(const wxRect& rect);
85 virtual void DrawRoundedRectangle(const wxRect& rect, double radius);
86 virtual void DrawArc(const wxPoint& centrePt, const wxPoint& startPt, const wxPoint& endPt);
87 virtual void DrawEllipticArc(const wxRect& rect, double startAngle, double endAngle);
88 virtual void DrawEllipse(const wxRect& rect);
89 virtual void DrawPoint(const wxPoint& pt);
90 virtual void DrawText(const wxString& text, const wxPoint& pt);
91 virtual void DrawLines(int n, wxPoint pts[]);
92 // flags:
93 // oglMETAFLAGS_OUTLINE: will be used for drawing the outline and
94 // also drawing lines/arrows at the circumference.
95 // oglMETAFLAGS_ATTACHMENTS: will be used for initialising attachment points at
96 // the vertices (perhaps a rare case...)
97 virtual void DrawPolygon(int n, wxPoint pts[], int flags = 0);
98 virtual void DrawSpline(int n, wxPoint pts[]);
99
100 virtual void SetClippingRect(const wxRect& rect);
101 virtual void DestroyClippingRect();
102
103 virtual void SetPen(wxPen* pen, bool isOutline = FALSE); // TODO: eventually, just store GDI object attributes, not actual
104 virtual void SetBrush(wxBrush* brush, bool isFill = FALSE); // pens/brushes etc.
105 virtual void SetFont(wxFont* font);
106 virtual void SetTextColour(const wxColour& colour);
107 virtual void SetBackgroundColour(const wxColour& colour);
108 virtual void SetBackgroundMode(int mode);
109
110public:
111 bool m_rotateable;
112 double m_width;
113 double m_height;
114 wxList m_ops; // List of drawing operations (see drawnp.h)
115 wxList m_gdiObjects; // List of pens, brushes and fonts for this object.
116 int m_outlineOp; // The op representing the outline, if any
117
118 // Pen/brush specifying outline/fill colours
119 // to override operations.
120 wxPen* m_outlinePen;
121 wxBrush* m_fillBrush;
122 wxList m_outlineColours; // List of the GDI operations that comprise the outline
123 wxList m_fillColours; // List of the GDI operations that fill the shape
124 double m_currentRotation;
125};
126
127#define oglDRAWN_ANGLE_0 0
128#define oglDRAWN_ANGLE_90 1
129#define oglDRAWN_ANGLE_180 2
130#define oglDRAWN_ANGLE_270 3
131
5f331691 132class WXDLLIMPEXP_OGL wxDrawnShape: public wxRectangleShape
1fc25a89
JS
133{
134 DECLARE_DYNAMIC_CLASS(wxDrawnShape)
135 public:
136 wxDrawnShape();
137 ~wxDrawnShape();
138
139 void OnDraw(wxDC& dc);
140
2b5f62a0 141#if wxUSE_PROLOGIO
1fc25a89
JS
142 // I/O
143 void WriteAttributes(wxExpr *clause);
144 void ReadAttributes(wxExpr *clause);
145#endif
146
147 // Does the copying for this object
148 void Copy(wxShape& copy);
149
150 void Scale(double sx, double sy);
151 void Translate(double x, double y);
152 // Rotate about the given axis by theta radians from the x axis.
153 void Rotate(double x, double y, double theta);
154
155 // Get current rotation
156 inline double GetRotation() const { return m_rotation; }
157
158 void SetSize(double w, double h, bool recursive = TRUE);
9e053640 159 bool LoadFromMetaFile(const wxString& filename);
1fc25a89
JS
160
161 inline void SetSaveToFile(bool save) { m_saveToFile = save; }
162 inline wxPseudoMetaFile& GetMetaFile(int which = 0) const { return (wxPseudoMetaFile&) m_metafiles[which]; }
163
164 void OnDrawOutline(wxDC& dc, double x, double y, double w, double h);
165
166 // Get the perimeter point using the special outline op, if there is one,
167 // otherwise use default wxRectangleShape scheme
168 bool GetPerimeterPoint(double x1, double y1,
169 double x2, double y2,
170 double *x3, double *y3);
171
172 /// Set of functions for drawing into a pseudo metafile.
173 /// They use integers, but doubles are used internally for accuracy
174 /// when scaling.
175
176 virtual void DrawLine(const wxPoint& pt1, const wxPoint& pt2);
177 virtual void DrawRectangle(const wxRect& rect);
178 virtual void DrawRoundedRectangle(const wxRect& rect, double radius);
179 virtual void DrawArc(const wxPoint& centrePt, const wxPoint& startPt, const wxPoint& endPt);
180 virtual void DrawEllipticArc(const wxRect& rect, double startAngle, double endAngle);
181 virtual void DrawEllipse(const wxRect& rect);
182 virtual void DrawPoint(const wxPoint& pt);
183 virtual void DrawText(const wxString& text, const wxPoint& pt);
184 virtual void DrawLines(int n, wxPoint pts[]);
185 virtual void DrawPolygon(int n, wxPoint pts[], int flags = 0);
186 virtual void DrawSpline(int n, wxPoint pts[]);
187
188 virtual void SetClippingRect(const wxRect& rect);
189 virtual void DestroyClippingRect();
190
191 virtual void SetDrawnPen(wxPen* pen, bool isOutline = FALSE); // TODO: eventually, just store GDI object attributes, not actual
192 virtual void SetDrawnBrush(wxBrush* brush, bool isFill = FALSE); // pens/brushes etc.
193 virtual void SetDrawnFont(wxFont* font);
194 virtual void SetDrawnTextColour(const wxColour& colour);
195 virtual void SetDrawnBackgroundColour(const wxColour& colour);
196 virtual void SetDrawnBackgroundMode(int mode);
197
198 // Set the width/height according to the shapes in the metafile.
199 // Call this after drawing into the shape.
200 inline void CalculateSize() { m_metafiles[m_currentAngle].CalculateSize(this); }
201
202 inline void DrawAtAngle(int angle) { m_currentAngle = angle; };
203
204 inline int GetAngle() const { return m_currentAngle; }
205
206// Implementation
207protected:
208 // Which metafile do we use now? Based on current rotation and validity
209 // of metafiles.
210 int DetermineMetaFile(double rotation);
211
212private:
213 // One metafile for each 90 degree rotation (or just a single one).
214 wxPseudoMetaFile m_metafiles[4];
215
216 // Don't save all wxDrawnShape metafiles to file: sometimes
217 // we take the metafile data from a symbol library.
218 bool m_saveToFile;
219
220 // Which angle are we using/drawing into?
221 int m_currentAngle;
222};
223
224#endif
225 // _DRAWN_H_
226