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