]>
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 #include <wx/docview.h>
16 #include <wx/string.h>
17 #include <wx/ogl/ogl.h> // base header of OGL, includes and adjusts wx/deprecated/setup.h
18 #include <wx/ogl/basicp.h>
19 #include <wx/ogl/linesp.h>
20 #include <wx/ogl/drawn.h>
22 class csDiagramDocument
;
25 * Override a few members for this application
28 class csDiagram
: public wxDiagram
30 DECLARE_CLASS(csDiagram
)
32 csDiagram(csDiagramDocument
* doc
) { m_doc
= doc
; }
35 bool OnShapeSave(wxExprDatabase
& db
, wxShape
& shape
, wxExpr
& expr
);
36 bool OnShapeLoad(wxExprDatabase
& db
, wxShape
& shape
, wxExpr
& expr
);
37 #endif // wxUSE_PROLOGIO
39 inline csDiagramDocument
* GetDocument() const { return m_doc
; }
40 virtual void Redraw(wxDC
& dc
);
43 csDiagramDocument
* m_doc
;
46 class wxDiagramClipboard
: public wxDiagram
48 DECLARE_DYNAMIC_CLASS(wxDiagramClipboard
)
50 wxDiagramClipboard() {}
51 ~wxDiagramClipboard() {}
53 // Copy selection to clipboard
54 bool Copy(wxDiagram
* diagram
);
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);
64 // Draw contents to a Windows metafile device context and bitmap, and then copy
65 // to the Windows clipboard.
66 bool CopyToClipboard(double scale
);
71 virtual bool OnStartCopy(wxDiagram
* WXUNUSED(diagramTo
)) { return true; };
72 virtual bool OnEndCopy(wxDiagram
* WXUNUSED(diagramTo
)) { return true; };
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
);
80 bool DoCopy(wxDiagram
* diagramFrom
, wxDiagram
* diagramTo
, bool newIds
,
81 wxDC
* dc
, int offsetX
= 0, int offsetY
= 0);
85 class csDiagramCommand
;
87 class csDiagramClipboard
: public wxDiagramClipboard
89 DECLARE_DYNAMIC_CLASS(csDiagramClipboard
)
91 csDiagramClipboard() { m_currentCmd
= NULL
; }
92 ~csDiagramClipboard() {}
95 virtual bool OnStartCopy(wxDiagram
* diagramTo
);
96 virtual bool OnEndCopy(wxDiagram
* diagramTo
);
98 virtual bool OnAddShape(wxDiagram
* diagramTo
, wxShape
* newShape
, wxDC
* dc
);
101 csDiagramCommand
* m_currentCmd
;
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.
114 class csThinRectangleShape
: public wxDrawnShape
116 DECLARE_DYNAMIC_CLASS(csThinRectangleShape
)
118 csThinRectangleShape();
121 class csWideRectangleShape
: public wxDrawnShape
123 DECLARE_DYNAMIC_CLASS(csWideRectangleShape
)
125 csWideRectangleShape();
128 class csTriangleShape
: public wxDrawnShape
130 DECLARE_DYNAMIC_CLASS(csTriangleShape
)
135 class csSemiCircleShape
: public wxDrawnShape
137 DECLARE_DYNAMIC_CLASS(csSemiCircleShape
)
142 class csCircleShape
: public wxCircleShape
144 DECLARE_DYNAMIC_CLASS(csCircleShape
)
149 class csCircleShadowShape
: public wxCircleShape
151 DECLARE_DYNAMIC_CLASS(csCircleShadowShape
)
153 csCircleShadowShape();
156 class csOctagonShape
: public wxPolygonShape
158 DECLARE_DYNAMIC_CLASS(csOctagonShape
)
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
); }
172 // This is a transparent shape for drawing around other shapes.
173 class csGroupShape
: public wxRectangleShape
175 DECLARE_DYNAMIC_CLASS(csGroupShape
)
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
);
184 class csTextBoxShape
: public wxRectangleShape
186 DECLARE_DYNAMIC_CLASS(csTextBoxShape
)
191 class csLineShape
: public wxLineShape
193 DECLARE_DYNAMIC_CLASS(csLineShape
)
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);
202 * Temporary arc label object
205 class csLabelShape
: public wxLabelShape
207 DECLARE_DYNAMIC_CLASS(csLabelShape
)
210 csLabelShape(wxLineShape
*parent
= NULL
, wxShapeRegion
*region
= NULL
, double w
= 0.0, double h
= 0.0);
212 void OnEndDragLeft(double x
, double y
, int keys
=0, int attachment
= 0);
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.
220 class csEvtHandler
: public wxShapeEvtHandler
222 DECLARE_DYNAMIC_CLASS(csEvtHandler
)
224 csEvtHandler(wxShapeEvtHandler
*prev
= NULL
, wxShape
*shape
= NULL
, const wxString
& lab
= wxEmptyString
);
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
);
239 void OnLeftDoubleClick(double x
, double y
, int keys
= 0, int attachment
= 0);
241 // Copy any event handler data
242 virtual void CopyData(wxShapeEvtHandler
& copy
);
244 // Popup up a property dialog
245 virtual bool EditProperties();
251 class ShapeEditMenu
: public wxMenu
256 void OnCommand(wxCommandEvent
& event
);
258 DECLARE_EVENT_TABLE()
261 extern void studioShapeEditProc(wxMenu
& menu
, wxCommandEvent
& event
);