]> git.saurik.com Git - wxWidgets.git/blame - contrib/samples/ogl/studio/shapes.h
wxTinderbox build fixes.
[wxWidgets.git] / contrib / samples / ogl / studio / shapes.h
CommitLineData
1fc25a89
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: shapes.h
3// Purpose: Shape classes
4// Author: Julian Smart
5// Modified by:
6// Created: 12/07/98
7// RCS-ID: $Id$
8// Copyright: (c) Julian Smart
9// Licence:
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _STUDIO_SHAPES_H_
13#define _STUDIO_SHAPES_H_
14
1fc25a89
JS
15#include <wx/docview.h>
16#include <wx/string.h>
cecdcad1 17#include <wx/ogl/ogl.h> // base header of OGL, includes and adjusts wx/deprecated/setup.h
1fc25a89
JS
18#include <wx/ogl/basicp.h>
19#include <wx/ogl/linesp.h>
20#include <wx/ogl/drawn.h>
21
22class csDiagramDocument;
23
24/*
25 * Override a few members for this application
26 */
cecdcad1 27
1fc25a89
JS
28class csDiagram: public wxDiagram
29{
30DECLARE_CLASS(csDiagram)
31public:
32 csDiagram(csDiagramDocument* doc) { m_doc = doc; }
33 ~csDiagram();
cecdcad1 34#if wxUSE_PROLOGIO
1fc25a89
JS
35 bool OnShapeSave(wxExprDatabase& db, wxShape& shape, wxExpr& expr);
36 bool OnShapeLoad(wxExprDatabase& db, wxShape& shape, wxExpr& expr);
cecdcad1 37#endif // wxUSE_PROLOGIO
1fc25a89
JS
38
39 inline csDiagramDocument* GetDocument() const { return m_doc; }
40 virtual void Redraw(wxDC& dc);
41
42protected:
43 csDiagramDocument* m_doc;
44};
45
46class wxDiagramClipboard: public wxDiagram
47{
48DECLARE_DYNAMIC_CLASS(wxDiagramClipboard)
49public:
50 wxDiagramClipboard() {}
51 ~wxDiagramClipboard() {}
52
53 // Copy selection to clipboard
54 bool Copy(wxDiagram* diagram);
55
56 // Copy contents to the diagram, with new ids.
57 // If dc is non-NULL, the pasted shapes will be selected.
58 // The offsets are used to place the shapes at a different position
59 // from the original (for example, for duplicating shapes).
60 bool Paste(wxDiagram* diagram, wxDC* dc = NULL,
61 int offsetX = 0, int offsetY = 0);
62
63#ifdef __WXMSW__
64 // Draw contents to a Windows metafile device context and bitmap, and then copy
65 // to the Windows clipboard.
66 bool CopyToClipboard(double scale);
67#endif
68
69// Overridables
70 // Start/end copying
2ba06d5a
WS
71 virtual bool OnStartCopy(wxDiagram* WXUNUSED(diagramTo)) { return true; };
72 virtual bool OnEndCopy(wxDiagram* WXUNUSED(diagramTo)) { return true; };
1fc25a89
JS
73
74 // Override this to e.g. have the shape added through a Do/Undo command system.
75 // By default, we'll just add it directly to the destination diagram, and
76 // select the shape (if dc is non-NULL).
77 virtual bool OnAddShape(wxDiagram* diagramTo, wxShape* newShape, wxDC* dc);
78
79protected:
80 bool DoCopy(wxDiagram* diagramFrom, wxDiagram* diagramTo, bool newIds,
81 wxDC* dc, int offsetX = 0, int offsetY = 0);
82
83};
84
85class csDiagramCommand;
86
87class csDiagramClipboard: public wxDiagramClipboard
88{
89DECLARE_DYNAMIC_CLASS(csDiagramClipboard)
90public:
91 csDiagramClipboard() { m_currentCmd = NULL; }
92 ~csDiagramClipboard() {}
93
94 // Start/end copying
d1f47235
DS
95 virtual bool OnStartCopy(wxDiagram* diagramTo);
96 virtual bool OnEndCopy(wxDiagram* diagramTo);
1fc25a89 97
d1f47235 98 virtual bool OnAddShape(wxDiagram* diagramTo, wxShape* newShape, wxDC* dc);
1fc25a89
JS
99
100protected:
101 csDiagramCommand* m_currentCmd;
102};
103
104
105/*
106 * The Studio shapes
107 * N.B. TODO: these should really all have another constructor
108 * for the ready-initialised shape, with the default one not having any
109 * data. Otherwise when copying a shape, you have to delete the old data
110 * first -> slightly less efficient. The initialised shapes are only required
111 * for the first creation of the shape in the palette, everything else is copied.
112 */
113
114class csThinRectangleShape: public wxDrawnShape
115{
116DECLARE_DYNAMIC_CLASS(csThinRectangleShape)
117public:
118 csThinRectangleShape();
119};
120
121class csWideRectangleShape: public wxDrawnShape
122{
123DECLARE_DYNAMIC_CLASS(csWideRectangleShape)
124public:
125 csWideRectangleShape();
126};
127
128class csTriangleShape: public wxDrawnShape
129{
130DECLARE_DYNAMIC_CLASS(csTriangleShape)
131public:
132 csTriangleShape();
133};
134
135class csSemiCircleShape: public wxDrawnShape
136{
137DECLARE_DYNAMIC_CLASS(csSemiCircleShape)
138public:
139 csSemiCircleShape();
140};
141
142class csCircleShape: public wxCircleShape
143{
144DECLARE_DYNAMIC_CLASS(csCircleShape)
145public:
146 csCircleShape();
147};
148
149class csCircleShadowShape: public wxCircleShape
150{
151DECLARE_DYNAMIC_CLASS(csCircleShadowShape)
152public:
153 csCircleShadowShape();
154};
155
156class csOctagonShape: public wxPolygonShape
157{
158DECLARE_DYNAMIC_CLASS(csOctagonShape)
159public:
160 csOctagonShape();
161
162 // The attachments are as if it's a rectangle
163 bool GetAttachmentPosition(int attachment, double *x, double *y,
164 int nth = 0, int no_arcs = 1, wxLineShape *line = NULL)
165 { return wxShape::GetAttachmentPosition(attachment, x, y, nth, no_arcs, line); }
166 int GetNumberOfAttachments() const
167 { return wxShape::GetNumberOfAttachments(); }
168 bool AttachmentIsValid(int attachment) const
169 { return wxShape::AttachmentIsValid(attachment); }
170};
171
172// This is a transparent shape for drawing around other shapes.
173class csGroupShape: public wxRectangleShape
174{
175DECLARE_DYNAMIC_CLASS(csGroupShape)
176public:
177 csGroupShape();
178
179 void OnDraw(wxDC& dc);
180 // Must modify the hit-test so it doesn't obscure shapes that are inside.
181 bool HitTest(double x, double y, int* attachment, double* distance);
182};
183
184class csTextBoxShape: public wxRectangleShape
185{
186DECLARE_DYNAMIC_CLASS(csTextBoxShape)
187public:
188 csTextBoxShape();
189};
190
191class csLineShape: public wxLineShape
192{
193DECLARE_DYNAMIC_CLASS(csLineShape)
194public:
195 csLineShape();
196
197 virtual bool OnMoveMiddleControlPoint(wxDC& dc, wxLineControlPoint* lpt, const wxRealPoint& pt);
198 wxLabelShape* OnCreateLabelShape(wxLineShape *parent = NULL, wxShapeRegion *region = NULL, double w = 0.0, double h = 0.0);
199};
200
201/*
202 * Temporary arc label object
203 */
cecdcad1 204
1fc25a89
JS
205class csLabelShape: public wxLabelShape
206{
207 DECLARE_DYNAMIC_CLASS(csLabelShape)
208
209 public:
210 csLabelShape(wxLineShape *parent = NULL, wxShapeRegion *region = NULL, double w = 0.0, double h = 0.0);
211
212 void OnEndDragLeft(double x, double y, int keys=0, int attachment = 0);
213};
214
215/*
216 * All shape event behaviour is routed through this handler, so we don't
217 * have to derive from each shape class. We plug this in to each shape.
218 */
219
220class csEvtHandler: public wxShapeEvtHandler
221{
222 DECLARE_DYNAMIC_CLASS(csEvtHandler)
223 public:
1484b5cc 224 csEvtHandler(wxShapeEvtHandler *prev = NULL, wxShape *shape = NULL, const wxString& lab = wxEmptyString);
1fc25a89
JS
225 ~csEvtHandler();
226
227 void OnLeftClick(double x, double y, int keys = 0, int attachment = 0);
228 void OnRightClick(double x, double y, int keys = 0, int attachment = 0);
229 void OnBeginDragRight(double x, double y, int keys = 0, int attachment = 0);
230 void OnDragRight(bool draw, double x, double y, int keys = 0, int attachment = 0);
231 void OnEndDragRight(double x, double y, int keys = 0, int attachment = 0);
232 void OnEndSize(double x, double y);
233 void OnDragLeft(bool draw, double x, double y, int keys = 0, int attachment = 0);
234 void OnBeginDragLeft(double x, double y, int keys = 0, int attachment = 0);
235 void OnEndDragLeft(double x, double y, int keys = 0, int attachment = 0);
236 void OnSizingEndDragLeft(wxControlPoint* pt, double x, double y, int keys = 0, int attachment = 0);
237 void OnChangeAttachment(int attachment, wxLineShape* line, wxList& ordering);
238
239 void OnLeftDoubleClick(double x, double y, int keys = 0, int attachment = 0);
240
241 // Copy any event handler data
242 virtual void CopyData(wxShapeEvtHandler& copy);
243
244 // Popup up a property dialog
245 virtual bool EditProperties();
246
247public:
248 wxString m_label;
249};
250
251class ShapeEditMenu: public wxMenu
252{
253public:
254 ShapeEditMenu() {}
255
256 void OnCommand(wxCommandEvent& event);
257
258DECLARE_EVENT_TABLE()
259};
260
261extern void studioShapeEditProc(wxMenu& menu, wxCommandEvent& event);
262
263#endif
264 // _STUDIO_SHAPES_H_