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