]>
git.saurik.com Git - wxWidgets.git/blob - contrib/samples/ogl/studio/shapes.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Shape classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _STUDIO_SHAPES_H_
13 #define _STUDIO_SHAPES_H_
15 #if defined(__GNUG__) && !defined(__APPLE__)
19 #include <wx/docview.h>
20 #include <wx/string.h>
21 #include <wx/deprecated/setup.h>
22 #include <wx/deprecated/wxexpr.h>
24 #include <wx/ogl/ogl.h>
25 #include <wx/ogl/basicp.h>
26 #include <wx/ogl/linesp.h>
27 #include <wx/ogl/drawn.h>
29 class csDiagramDocument
;
32 * Override a few members for this application
35 class csDiagram
: public wxDiagram
37 DECLARE_CLASS(csDiagram
)
39 csDiagram(csDiagramDocument
* doc
) { m_doc
= doc
; }
41 bool OnShapeSave(wxExprDatabase
& db
, wxShape
& shape
, wxExpr
& expr
);
42 bool OnShapeLoad(wxExprDatabase
& db
, wxShape
& shape
, wxExpr
& expr
);
44 inline csDiagramDocument
* GetDocument() const { return m_doc
; }
45 virtual void Redraw(wxDC
& dc
);
48 csDiagramDocument
* m_doc
;
51 class wxDiagramClipboard
: public wxDiagram
53 DECLARE_DYNAMIC_CLASS(wxDiagramClipboard
)
55 wxDiagramClipboard() {}
56 ~wxDiagramClipboard() {}
58 // Copy selection to clipboard
59 bool Copy(wxDiagram
* diagram
);
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);
69 // Draw contents to a Windows metafile device context and bitmap, and then copy
70 // to the Windows clipboard.
71 bool CopyToClipboard(double scale
);
76 virtual bool OnStartCopy(wxDiagram
* WXUNUSED(diagramTo
)) { return true; };
77 virtual bool OnEndCopy(wxDiagram
* WXUNUSED(diagramTo
)) { return true; };
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
);
85 bool DoCopy(wxDiagram
* diagramFrom
, wxDiagram
* diagramTo
, bool newIds
,
86 wxDC
* dc
, int offsetX
= 0, int offsetY
= 0);
90 class csDiagramCommand
;
92 class csDiagramClipboard
: public wxDiagramClipboard
94 DECLARE_DYNAMIC_CLASS(csDiagramClipboard
)
96 csDiagramClipboard() { m_currentCmd
= NULL
; }
97 ~csDiagramClipboard() {}
100 virtual bool OnStartCopy(wxDiagram
* diagramTo
);
101 virtual bool OnEndCopy(wxDiagram
* diagramTo
);
103 virtual bool OnAddShape(wxDiagram
* diagramTo
, wxShape
* newShape
, wxDC
* dc
);
106 csDiagramCommand
* m_currentCmd
;
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.
119 class csThinRectangleShape
: public wxDrawnShape
121 DECLARE_DYNAMIC_CLASS(csThinRectangleShape
)
123 csThinRectangleShape();
126 class csWideRectangleShape
: public wxDrawnShape
128 DECLARE_DYNAMIC_CLASS(csWideRectangleShape
)
130 csWideRectangleShape();
133 class csTriangleShape
: public wxDrawnShape
135 DECLARE_DYNAMIC_CLASS(csTriangleShape
)
140 class csSemiCircleShape
: public wxDrawnShape
142 DECLARE_DYNAMIC_CLASS(csSemiCircleShape
)
147 class csCircleShape
: public wxCircleShape
149 DECLARE_DYNAMIC_CLASS(csCircleShape
)
154 class csCircleShadowShape
: public wxCircleShape
156 DECLARE_DYNAMIC_CLASS(csCircleShadowShape
)
158 csCircleShadowShape();
161 class csOctagonShape
: public wxPolygonShape
163 DECLARE_DYNAMIC_CLASS(csOctagonShape
)
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
); }
177 // This is a transparent shape for drawing around other shapes.
178 class csGroupShape
: public wxRectangleShape
180 DECLARE_DYNAMIC_CLASS(csGroupShape
)
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
);
189 class csTextBoxShape
: public wxRectangleShape
191 DECLARE_DYNAMIC_CLASS(csTextBoxShape
)
196 class csLineShape
: public wxLineShape
198 DECLARE_DYNAMIC_CLASS(csLineShape
)
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);
207 * Temporary arc label object
210 class csLabelShape
: public wxLabelShape
212 DECLARE_DYNAMIC_CLASS(csLabelShape
)
215 csLabelShape(wxLineShape
*parent
= NULL
, wxShapeRegion
*region
= NULL
, double w
= 0.0, double h
= 0.0);
217 void OnEndDragLeft(double x
, double y
, int keys
=0, int attachment
= 0);
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.
225 class csEvtHandler
: public wxShapeEvtHandler
227 DECLARE_DYNAMIC_CLASS(csEvtHandler
)
229 csEvtHandler(wxShapeEvtHandler
*prev
= NULL
, wxShape
*shape
= NULL
, const wxString
& lab
= wxEmptyString
);
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
);
244 void OnLeftDoubleClick(double x
, double y
, int keys
= 0, int attachment
= 0);
246 // Copy any event handler data
247 virtual void CopyData(wxShapeEvtHandler
& copy
);
249 // Popup up a property dialog
250 virtual bool EditProperties();
256 class ShapeEditMenu
: public wxMenu
261 void OnCommand(wxCommandEvent
& event
);
263 DECLARE_EVENT_TABLE()
266 extern void studioShapeEditProc(wxMenu
& menu
, wxCommandEvent
& event
);