File: drawn.h

package info (click to toggle)
pgadmin3 1.20.0~beta2-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 73,704 kB
  • ctags: 18,591
  • sloc: cpp: 193,786; ansic: 18,736; sh: 5,154; pascal: 1,120; yacc: 927; makefile: 516; lex: 421; xml: 126; perl: 40
file content (280 lines) | stat: -rw-r--r-- 8,302 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
//////////////////////////////////////////////////////////////////////////
//
// pgAdmin III - PostgreSQL Tools
//
// Portions Copyright (C) 1998 - 2011, Julian Smart
// Portions Copyright (C) 2011 - 2014, The pgAdmin Development Team
// This software is released under the PostgreSQL Licence
//
// drawn.h - wxDrawnShape
//
//////////////////////////////////////////////////////////////////////////

#ifndef _OGL_DRAWN_H_
#define _OGL_DRAWN_H_

#define oglMETAFLAGS_OUTLINE         1
#define oglMETAFLAGS_ATTACHMENTS     2

class wxDrawnShape;
class wxPseudoMetaFile: public wxObject
{
	DECLARE_DYNAMIC_CLASS(wxPseudoMetaFile)
public:
	wxPseudoMetaFile();
	wxPseudoMetaFile(wxPseudoMetaFile &mf);
	~wxPseudoMetaFile();

	void Draw(wxDC &dc, double xoffset, double yoffset);

#if wxUSE_PROLOGIO
	void WriteAttributes(wxExpr *clause, int whichAngle);
	void ReadAttributes(wxExpr *clause, int whichAngle);
#endif

	void Clear();

	void Copy(wxPseudoMetaFile &copy);

	void Scale(double sx, double sy);
	void ScaleTo(double w, double h); // Scale to fit size
	void Translate(double x, double y);

	// Rotate about the given axis by theta radians from the x axis.
	void Rotate(double x, double y, double theta);

	bool LoadFromMetaFile(const wxString &filename, double *width, double *height);

	void GetBounds(double *minX, double *minY, double *maxX, double *maxY);

	// Calculate size from current operations
	void CalculateSize(wxDrawnShape *shape);

	inline wxList &GetOutlineColours() const
	{
		return (wxList &) m_outlineColours;
	}
	inline wxList &GetFillColours() const
	{
		return (wxList &) m_fillColours;
	}
	inline void SetRotateable(bool rot)
	{
		m_rotateable = rot;
	}
	inline bool GetRotateable() const
	{
		return m_rotateable;
	}

	inline void SetSize(double w, double h)
	{
		m_width = w;
		m_height = h;
	}

	inline void SetFillBrush(wxBrush *brush)
	{
		m_fillBrush = brush;
	}
	inline wxBrush *GetFillBrush() const
	{
		return m_fillBrush;
	}

	inline void SetOutlinePen(wxPen *pen)
	{
		m_outlinePen = pen;
	}
	inline wxPen *GetOutlinePen() const
	{
		return m_outlinePen;
	}

	inline void SetOutlineOp(int op)
	{
		m_outlineOp = op;
	}
	inline int GetOutlineOp() const
	{
		return m_outlineOp;
	}

	inline wxList &GetOps() const
	{
		return (wxList &) m_ops;
	}

	// Is this a valid (non-empty) metafile?
	inline bool IsValid() const
	{
		return (m_ops.GetCount() > 0);
	}

public:
	/// Set of functions for drawing into a pseudo metafile.
	/// They use integers, but doubles are used internally for accuracy
	/// when scaling.

	virtual void DrawLine(const wxPoint &pt1, const wxPoint &pt2);
	virtual void DrawRectangle(const wxRect &rect);
	virtual void DrawRoundedRectangle(const wxRect &rect, double radius);
	virtual void DrawArc(const wxPoint &centrePt, const wxPoint &startPt, const wxPoint &endPt);
	virtual void DrawEllipticArc(const wxRect &rect, double startAngle, double endAngle);
	virtual void DrawEllipse(const wxRect &rect);
	virtual void DrawPoint(const wxPoint &pt);
	virtual void DrawText(const wxString &text, const wxPoint &pt);
	virtual void DrawLines(int n, wxPoint pts[]);
	// flags:
	// oglMETAFLAGS_OUTLINE: will be used for drawing the outline and
	//                       also drawing lines/arrows at the circumference.
	// oglMETAFLAGS_ATTACHMENTS: will be used for initialising attachment points at
	//                       the vertices (perhaps a rare case...)
	virtual void DrawPolygon(int n, wxPoint pts[], int flags = 0);
	virtual void DrawSpline(int n, wxPoint pts[]);

	virtual void SetClippingRect(const wxRect &rect);
	virtual void DestroyClippingRect();

	virtual void SetPen(wxPen *pen, bool isOutline = FALSE);     // TODO: eventually, just store GDI object attributes, not actual
	virtual void SetBrush(wxBrush *brush, bool isFill = FALSE);  // pens/brushes etc.
	virtual void SetFont(wxFont *font);
	virtual void SetTextColour(const wxColour &colour);
	virtual void SetBackgroundColour(const wxColour &colour);
	virtual void SetBackgroundMode(int mode);

public:
	bool              m_rotateable;
	double            m_width;
	double            m_height;
	wxList            m_ops; // List of drawing operations (see drawnp.h)
	wxList            m_gdiObjects; // List of pens, brushes and fonts for this object.
	int               m_outlineOp;  // The op representing the outline, if any

	// Pen/brush specifying outline/fill colours
	// to override operations.
	wxPen            *m_outlinePen;
	wxBrush          *m_fillBrush;
	wxList            m_outlineColours; // List of the GDI operations that comprise the outline
	wxList            m_fillColours; // List of the GDI operations that fill the shape
	double             m_currentRotation;
};

#define oglDRAWN_ANGLE_0        0
#define oglDRAWN_ANGLE_90       1
#define oglDRAWN_ANGLE_180      2
#define oglDRAWN_ANGLE_270      3

class wxDrawnShape: public wxRectangleShape
{
	DECLARE_DYNAMIC_CLASS(wxDrawnShape)
public:
	wxDrawnShape();
	~wxDrawnShape();

	void OnDraw(wxDC &dc);

#if wxUSE_PROLOGIO
	// I/O
	void WriteAttributes(wxExpr *clause);
	void ReadAttributes(wxExpr *clause);
#endif

	// Does the copying for this object
	void Copy(wxShape &copy);

	void Scale(double sx, double sy);
	void Translate(double x, double y);
	// Rotate about the given axis by theta radians from the x axis.
	void Rotate(double x, double y, double theta);

	// Get current rotation
	inline double GetRotation() const
	{
		return m_rotation;
	}

	void SetSize(double w, double h, bool recursive = TRUE);
	bool LoadFromMetaFile(const wxString &filename);

	inline void SetSaveToFile(bool save)
	{
		m_saveToFile = save;
	}
	inline wxPseudoMetaFile &GetMetaFile(int which = 0) const
	{
		return (wxPseudoMetaFile &) m_metafiles[which];
	}

	void OnDrawOutline(wxDC &dc, double x, double y, double w, double h);

	// Get the perimeter point using the special outline op, if there is one,
	// otherwise use default wxRectangleShape scheme
	bool GetPerimeterPoint(double x1, double y1,
	                       double x2, double y2,
	                       double *x3, double *y3);

	/// Set of functions for drawing into a pseudo metafile.
	/// They use integers, but doubles are used internally for accuracy
	/// when scaling.

	virtual void DrawLine(const wxPoint &pt1, const wxPoint &pt2);
	virtual void DrawRectangle(const wxRect &rect);
	virtual void DrawRoundedRectangle(const wxRect &rect, double radius);
	virtual void DrawArc(const wxPoint &centrePt, const wxPoint &startPt, const wxPoint &endPt);
	virtual void DrawEllipticArc(const wxRect &rect, double startAngle, double endAngle);
	virtual void DrawEllipse(const wxRect &rect);
	virtual void DrawPoint(const wxPoint &pt);
	virtual void DrawText(const wxString &text, const wxPoint &pt);
	virtual void DrawLines(int n, wxPoint pts[]);
	virtual void DrawPolygon(int n, wxPoint pts[], int flags = 0);
	virtual void DrawSpline(int n, wxPoint pts[]);

	virtual void SetClippingRect(const wxRect &rect);
	virtual void DestroyClippingRect();

	virtual void SetDrawnPen(wxPen *pen, bool isOutline = FALSE);     // TODO: eventually, just store GDI object attributes, not actual
	virtual void SetDrawnBrush(wxBrush *brush, bool isFill = FALSE);  // pens/brushes etc.
	virtual void SetDrawnFont(wxFont *font);
	virtual void SetDrawnTextColour(const wxColour &colour);
	virtual void SetDrawnBackgroundColour(const wxColour &colour);
	virtual void SetDrawnBackgroundMode(int mode);

	// Set the width/height according to the shapes in the metafile.
	// Call this after drawing into the shape.
	inline void CalculateSize()
	{
		m_metafiles[m_currentAngle].CalculateSize(this);
	}

	inline void DrawAtAngle(int angle)
	{
		m_currentAngle = angle;
	};

	inline int GetAngle() const
	{
		return m_currentAngle;
	}

// Implementation
protected:
	// Which metafile do we use now? Based on current rotation and validity
	// of metafiles.
	int DetermineMetaFile(double rotation);

private:
	// One metafile for each 90 degree rotation (or just a single one).
	wxPseudoMetaFile      m_metafiles[4];

	// Don't save all wxDrawnShape metafiles to file: sometimes
	// we take the metafile data from a symbol library.
	bool                  m_saveToFile;

	// Which angle are we using/drawing into?
	int                   m_currentAngle;
};

#endif
// _DRAWN_H_