]>
Commit | Line | Data |
---|---|---|
2d08140f JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: basic.h | |
3 | // Purpose: Basic OGL classes and definitions | |
4 | // Author: Julian Smart | |
5 | // Modified by: | |
6 | // Created: 12/07/98 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Julian Smart | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #ifndef _OGL_BASIC_H_ | |
13 | #define _OGL_BASIC_H_ | |
14 | ||
15 | #ifdef __GNUG__ | |
16 | #pragma interface "basic.h" | |
17 | #endif | |
18 | ||
19 | #define OGL_VERSION 2.0 | |
20 | ||
21 | #ifndef DEFAULT_MOUSE_TOLERANCE | |
22 | #define DEFAULT_MOUSE_TOLERANCE 3 | |
23 | #endif | |
24 | ||
25 | // Edit these lines if you positively don't want PROLOGIO support | |
26 | #ifndef PROLOGIO | |
27 | #define PROLOGIO | |
28 | #endif | |
29 | ||
30 | // Key identifiers | |
31 | #define KEY_SHIFT 1 | |
32 | #define KEY_CTRL 2 | |
33 | ||
34 | // Arrow styles | |
35 | ||
36 | #define ARROW_NONE 0 | |
37 | #define ARROW_END 1 | |
38 | #define ARROW_BOTH 2 | |
39 | #define ARROW_MIDDLE 3 | |
40 | #define ARROW_START 4 | |
41 | ||
42 | // Control point types | |
43 | // Rectangle and most other shapes | |
44 | #define CONTROL_POINT_VERTICAL 1 | |
45 | #define CONTROL_POINT_HORIZONTAL 2 | |
46 | #define CONTROL_POINT_DIAGONAL 3 | |
47 | ||
48 | // Line | |
49 | #define CONTROL_POINT_ENDPOINT_TO 4 | |
50 | #define CONTROL_POINT_ENDPOINT_FROM 5 | |
51 | #define CONTROL_POINT_LINE 6 | |
52 | ||
53 | // Types of formatting: can be combined in a bit list | |
54 | #define FORMAT_NONE 0 | |
55 | // Left justification | |
56 | #define FORMAT_CENTRE_HORIZ 1 | |
57 | // Centre horizontally | |
58 | #define FORMAT_CENTRE_VERT 2 | |
59 | // Centre vertically | |
60 | #define FORMAT_SIZE_TO_CONTENTS 4 | |
61 | // Resize shape to contents | |
62 | ||
63 | // Shadow mode | |
64 | #define SHADOW_NONE 0 | |
65 | #define SHADOW_LEFT 1 | |
66 | #define SHADOW_RIGHT 2 | |
67 | ||
68 | /* | |
69 | * Declare types | |
70 | * | |
71 | */ | |
72 | ||
73 | #define SHAPE_BASIC wxTYPE_USER + 1 | |
74 | #define SHAPE_RECTANGLE wxTYPE_USER + 2 | |
75 | #define SHAPE_ELLIPSE wxTYPE_USER + 3 | |
76 | #define SHAPE_POLYGON wxTYPE_USER + 4 | |
77 | #define SHAPE_CIRCLE wxTYPE_USER + 5 | |
78 | #define SHAPE_LINE wxTYPE_USER + 6 | |
79 | #define SHAPE_DIVIDED_RECTANGLE wxTYPE_USER + 8 | |
80 | #define SHAPE_COMPOSITE wxTYPE_USER + 9 | |
81 | #define SHAPE_CONTROL_POINT wxTYPE_USER + 10 | |
82 | #define SHAPE_DRAWN wxTYPE_USER + 11 | |
83 | #define SHAPE_DIVISION wxTYPE_USER + 12 | |
84 | #define SHAPE_LABEL_OBJECT wxTYPE_USER + 13 | |
85 | #define SHAPE_BITMAP wxTYPE_USER + 14 | |
86 | #define SHAPE_DIVIDED_OBJECT_CONTROL_POINT wxTYPE_USER + 15 | |
87 | ||
88 | #define OBJECT_REGION wxTYPE_USER + 20 | |
89 | ||
90 | #define OP_CLICK_LEFT 1 | |
91 | #define OP_CLICK_RIGHT 2 | |
92 | #define OP_DRAG_LEFT 4 | |
93 | #define OP_DRAG_RIGHT 8 | |
94 | ||
95 | #define OP_ALL (OP_CLICK_LEFT | OP_CLICK_RIGHT | OP_DRAG_LEFT | OP_DRAG_RIGHT) | |
96 | ||
97 | // Attachment modes | |
98 | #define ATTACHMENT_MODE_NONE 0 | |
99 | #define ATTACHMENT_MODE_EDGE 1 | |
100 | #define ATTACHMENT_MODE_BRANCHING 2 | |
101 | ||
102 | // Sub-modes for branching attachment mode | |
103 | #define BRANCHING_ATTACHMENT_NORMAL 1 | |
104 | #define BRANCHING_ATTACHMENT_BLOB 2 | |
105 | ||
106 | class wxShapeTextLine; | |
107 | class wxShapeCanvas; | |
108 | class wxLineShape; | |
109 | class wxControlPoint; | |
110 | class wxShapeRegion; | |
111 | class wxShape; | |
112 | ||
113 | #ifdef PROLOGIO | |
114 | class WXDLLEXPORT wxExpr; | |
115 | class WXDLLEXPORT wxExprDatabase; | |
116 | #endif | |
117 | ||
118 | // Round up | |
119 | #define WXROUND(x) ( (long) (x + 0.5) ) | |
120 | ||
121 | ||
122 | // logical function to use when drawing rubberband boxes, etc. | |
123 | #define OGLRBLF wxINVERT | |
124 | ||
125 | ||
126 | ||
127 | class wxShapeEvtHandler: public wxObject | |
128 | { | |
129 | DECLARE_DYNAMIC_CLASS(wxShapeEvtHandler) | |
130 | ||
131 | public: | |
132 | wxShapeEvtHandler(wxShapeEvtHandler *prev = NULL, wxShape *shape = NULL); | |
133 | virtual ~wxShapeEvtHandler(); | |
134 | ||
135 | inline void SetShape(wxShape *sh) { m_handlerShape = sh; } | |
136 | inline wxShape *GetShape() const { return m_handlerShape; } | |
137 | ||
138 | inline void SetPreviousHandler(wxShapeEvtHandler* handler) { m_previousHandler = handler; } | |
139 | inline wxShapeEvtHandler* GetPreviousHandler() const { return m_previousHandler; } | |
140 | ||
141 | // This is called when the _shape_ is deleted. | |
142 | virtual void OnDelete(); | |
143 | virtual void OnDraw(wxDC& dc); | |
144 | virtual void OnDrawContents(wxDC& dc); | |
145 | virtual void OnDrawBranches(wxDC& dc, bool erase = FALSE); | |
146 | virtual void OnMoveLinks(wxDC& dc); | |
147 | virtual void OnErase(wxDC& dc); | |
148 | virtual void OnEraseContents(wxDC& dc); | |
149 | virtual void OnHighlight(wxDC& dc); | |
150 | virtual void OnLeftClick(double x, double y, int keys = 0, int attachment = 0); | |
151 | virtual void OnLeftDoubleClick(double x, double y, int keys = 0, int attachment = 0); | |
152 | virtual void OnRightClick(double x, double y, int keys = 0, int attachment = 0); | |
153 | virtual void OnSize(double x, double y); | |
154 | virtual bool OnMovePre(wxDC& dc, double x, double y, double old_x, double old_y, bool display = TRUE); | |
155 | virtual void OnMovePost(wxDC& dc, double x, double y, double old_x, double old_y, bool display = TRUE); | |
156 | ||
157 | virtual void OnDragLeft(bool draw, double x, double y, int keys=0, int attachment = 0); // Erase if draw false | |
158 | virtual void OnBeginDragLeft(double x, double y, int keys=0, int attachment = 0); | |
159 | virtual void OnEndDragLeft(double x, double y, int keys=0, int attachment = 0); | |
160 | virtual void OnDragRight(bool draw, double x, double y, int keys=0, int attachment = 0); // Erase if draw false | |
161 | virtual void OnBeginDragRight(double x, double y, int keys=0, int attachment = 0); | |
162 | virtual void OnEndDragRight(double x, double y, int keys=0, int attachment = 0); | |
163 | virtual void OnDrawOutline(wxDC& dc, double x, double y, double w, double h); | |
164 | virtual void OnDrawControlPoints(wxDC& dc); | |
165 | virtual void OnEraseControlPoints(wxDC& dc); | |
166 | virtual void OnMoveLink(wxDC& dc, bool moveControlPoints = TRUE); | |
167 | ||
168 | // Control points ('handles') redirect control to the actual shape, to make it easier | |
169 | // to override sizing behaviour. | |
170 | virtual void OnSizingDragLeft(wxControlPoint* pt, bool draw, double x, double y, int keys=0, int attachment = 0); // Erase if draw false | |
171 | virtual void OnSizingBeginDragLeft(wxControlPoint* pt, double x, double y, int keys=0, int attachment = 0); | |
172 | virtual void OnSizingEndDragLeft(wxControlPoint* pt, double x, double y, int keys=0, int attachment = 0); | |
173 | ||
174 | virtual void OnBeginSize(double WXUNUSED(w), double WXUNUSED(h)) { } | |
175 | virtual void OnEndSize(double WXUNUSED(w), double WXUNUSED(h)) { } | |
176 | ||
177 | // Can override this to prevent or intercept line reordering. | |
178 | virtual void OnChangeAttachment(int attachment, wxLineShape* line, wxList& ordering); | |
179 | ||
180 | // Creates a copy of this event handler. | |
181 | wxShapeEvtHandler *CreateNewCopy(); | |
182 | ||
183 | // Does the copy - override for new event handlers which might store | |
184 | // app-specific data. | |
185 | virtual void CopyData(wxShapeEvtHandler& copy) {}; | |
186 | ||
187 | private: | |
188 | wxShapeEvtHandler* m_previousHandler; | |
189 | wxShape* m_handlerShape; | |
190 | }; | |
191 | ||
192 | class wxShape: public wxShapeEvtHandler | |
193 | { | |
194 | DECLARE_ABSTRACT_CLASS(wxShape) | |
195 | ||
196 | public: | |
197 | ||
198 | wxShape(wxShapeCanvas *can = NULL); | |
199 | virtual ~wxShape(); | |
200 | virtual void GetBoundingBoxMax(double *width, double *height); | |
201 | virtual void GetBoundingBoxMin(double *width, double *height) = 0; | |
202 | virtual bool GetPerimeterPoint(double x1, double y1, | |
203 | double x2, double y2, | |
204 | double *x3, double *y3); | |
205 | inline wxShapeCanvas *GetCanvas() { return m_canvas; } | |
206 | void SetCanvas(wxShapeCanvas *the_canvas); | |
207 | virtual void AddToCanvas(wxShapeCanvas *the_canvas, wxShape *addAfter = NULL); | |
208 | virtual void InsertInCanvas(wxShapeCanvas *the_canvas); | |
209 | ||
210 | virtual void RemoveFromCanvas(wxShapeCanvas *the_canvas); | |
211 | inline double GetX() const { return m_xpos; } | |
212 | inline double GetY() const { return m_ypos; } | |
213 | inline void SetX(double x) { m_xpos = x; } | |
214 | inline void SetY(double y) { m_ypos = y; } | |
215 | ||
216 | inline wxShape *GetParent() const { return m_parent; } | |
217 | inline void SetParent(wxShape *p) { m_parent = p; } | |
218 | wxShape *GetTopAncestor(); | |
219 | inline wxList& GetChildren() { return m_children; } | |
220 | ||
221 | virtual void OnDraw(wxDC& dc); | |
222 | virtual void OnDrawContents(wxDC& dc); | |
223 | virtual void OnMoveLinks(wxDC& dc); | |
224 | virtual void Unlink() { }; | |
225 | void SetDrawHandles(bool drawH); | |
226 | inline bool GetDrawHandles() { return m_drawHandles; } | |
227 | virtual void OnErase(wxDC& dc); | |
228 | virtual void OnEraseContents(wxDC& dc); | |
229 | virtual void OnHighlight(wxDC& dc); | |
230 | virtual void OnLeftClick(double x, double y, int keys = 0, int attachment = 0); | |
231 | virtual void OnLeftDoubleClick(double x, double y, int keys = 0, int attachment = 0) {} | |
232 | virtual void OnRightClick(double x, double y, int keys = 0, int attachment = 0); | |
233 | virtual void OnSize(double x, double y); | |
234 | virtual bool OnMovePre(wxDC& dc, double x, double y, double old_x, double old_y, bool display = TRUE); | |
235 | virtual void OnMovePost(wxDC& dc, double x, double y, double old_x, double old_y, bool display = TRUE); | |
236 | ||
237 | virtual void OnDragLeft(bool draw, double x, double y, int keys=0, int attachment = 0); // Erase if draw false | |
238 | virtual void OnBeginDragLeft(double x, double y, int keys=0, int attachment = 0); | |
239 | virtual void OnEndDragLeft(double x, double y, int keys=0, int attachment = 0); | |
240 | virtual void OnDragRight(bool draw, double x, double y, int keys=0, int attachment = 0); // Erase if draw false | |
241 | virtual void OnBeginDragRight(double x, double y, int keys=0, int attachment = 0); | |
242 | virtual void OnEndDragRight(double x, double y, int keys=0, int attachment = 0); | |
243 | virtual void OnDrawOutline(wxDC& dc, double x, double y, double w, double h); | |
244 | virtual void OnDrawControlPoints(wxDC& dc); | |
245 | virtual void OnEraseControlPoints(wxDC& dc); | |
246 | ||
247 | virtual void OnBeginSize(double WXUNUSED(w), double WXUNUSED(h)) { } | |
248 | virtual void OnEndSize(double WXUNUSED(w), double WXUNUSED(h)) { } | |
249 | ||
250 | // Control points ('handles') redirect control to the actual shape, to make it easier | |
251 | // to override sizing behaviour. | |
252 | virtual void OnSizingDragLeft(wxControlPoint* pt, bool draw, double x, double y, int keys=0, int attachment = 0); // Erase if draw false | |
253 | virtual void OnSizingBeginDragLeft(wxControlPoint* pt, double x, double y, int keys=0, int attachment = 0); | |
254 | virtual void OnSizingEndDragLeft(wxControlPoint* pt, double x, double y, int keys=0, int attachment = 0); | |
255 | ||
256 | virtual void MakeControlPoints(); | |
257 | virtual void DeleteControlPoints(wxDC *dc = NULL); | |
258 | virtual void ResetControlPoints(); | |
259 | ||
260 | inline wxShapeEvtHandler *GetEventHandler() { return m_eventHandler; } | |
261 | inline void SetEventHandler(wxShapeEvtHandler *handler) { m_eventHandler = handler; } | |
262 | ||
263 | // Mandatory control points, e.g. the divided line moving handles | |
264 | // should appear even if a child of the 'selected' image | |
265 | virtual void MakeMandatoryControlPoints(); | |
266 | virtual void ResetMandatoryControlPoints(); | |
267 | ||
268 | inline virtual bool Recompute() { return TRUE; }; | |
269 | // Calculate size recursively, if size changes. Size might depend on children. | |
270 | inline virtual void CalculateSize() { }; | |
271 | virtual void Select(bool select = TRUE, wxDC* dc = NULL); | |
272 | virtual void SetHighlight(bool hi = TRUE, bool recurse = FALSE); | |
273 | inline virtual bool IsHighlighted() const { return m_highlighted; }; | |
274 | virtual bool Selected() const; | |
275 | virtual bool AncestorSelected() const; | |
276 | void SetSensitivityFilter(int sens = OP_ALL, bool recursive = FALSE); | |
277 | int GetSensitivityFilter() const { return m_sensitivity; } | |
278 | void SetDraggable(bool drag, bool recursive = FALSE); | |
279 | inline void SetFixedSize(bool x, bool y) { m_fixedWidth = x; m_fixedHeight = y; }; | |
280 | inline void GetFixedSize(bool *x, bool *y) const { *x = m_fixedWidth; *y = m_fixedHeight; }; | |
281 | inline bool GetFixedWidth() const { return m_fixedWidth; } | |
282 | inline bool GetFixedHeight() const { return m_fixedHeight; } | |
283 | inline void SetSpaceAttachments(bool sp) { m_spaceAttachments = sp; }; | |
284 | inline bool GetSpaceAttachments() const { return m_spaceAttachments; }; | |
285 | void SetShadowMode(int mode, bool redraw = FALSE); | |
286 | inline int GetShadowMode() const { return m_shadowMode; } | |
287 | virtual bool HitTest(double x, double y, int *attachment, double *distance); | |
288 | inline void SetCentreResize(bool cr) { m_centreResize = cr; } | |
289 | inline bool GetCentreResize() const { return m_centreResize; } | |
290 | inline void SetMaintainAspectRatio(bool ar) { m_maintainAspectRatio = ar; } | |
291 | inline bool GetMaintainAspectRatio() const { return m_maintainAspectRatio; } | |
292 | inline wxList& GetLines() const { return (wxList&) m_lines; } | |
293 | inline void SetDisableLabel(bool flag) { m_disableLabel = flag; } | |
294 | inline bool GetDisableLabel() const { return m_disableLabel; } | |
295 | inline void SetAttachmentMode(int mode) { m_attachmentMode = mode; } | |
296 | inline int GetAttachmentMode() const { return m_attachmentMode; } | |
297 | inline void SetId(long i) { m_id = i; } | |
298 | inline long GetId() const { return m_id; } | |
299 | ||
300 | void SetPen(wxPen *pen); | |
301 | void SetBrush(wxBrush *brush); | |
302 | inline void SetClientData(wxObject *client_data) { m_clientData = client_data; }; | |
303 | inline wxObject *GetClientData() const { return m_clientData; }; | |
304 | ||
305 | virtual void Show(bool show); | |
306 | virtual bool IsShown() const { return m_visible; } | |
307 | virtual void Move(wxDC& dc, double x1, double y1, bool display = TRUE); | |
308 | virtual void Erase(wxDC& dc); | |
309 | virtual void EraseContents(wxDC& dc); | |
310 | virtual void Draw(wxDC& dc); | |
311 | virtual void Flash(); | |
312 | virtual void MoveLinks(wxDC& dc); | |
313 | virtual void DrawContents(wxDC& dc); // E.g. for drawing text label | |
314 | virtual void SetSize(double x, double y, bool recursive = TRUE); | |
315 | virtual void SetAttachmentSize(double x, double y); | |
316 | void Attach(wxShapeCanvas *can); | |
317 | void Detach(); | |
318 | ||
319 | inline virtual bool Constrain() { return FALSE; } ; | |
320 | ||
321 | void AddLine(wxLineShape *line, wxShape *other, | |
322 | int attachFrom = 0, int attachTo = 0, | |
323 | // The line ordering | |
324 | int positionFrom = -1, int positionTo = -1); | |
325 | ||
326 | // Return the zero-based position in m_lines of line. | |
327 | int GetLinePosition(wxLineShape* line); | |
328 | ||
329 | void AddText(const wxString& string); | |
330 | ||
331 | inline wxPen *GetPen() const { return m_pen; } | |
332 | inline wxBrush *GetBrush() const { return m_brush; } | |
333 | ||
334 | /* | |
335 | * Region-specific functions (defaults to the default region | |
336 | * for simple objects | |
337 | */ | |
338 | ||
339 | // Set the default, single region size to be consistent | |
340 | // with the object size | |
341 | void SetDefaultRegionSize(); | |
342 | virtual void FormatText(wxDC& dc, const wxString& s, int regionId = 0); | |
343 | virtual void SetFormatMode(int mode, int regionId = 0); | |
344 | virtual int GetFormatMode(int regionId = 0) const; | |
345 | virtual void SetFont(wxFont *font, int regionId = 0); | |
346 | virtual wxFont *GetFont(int regionId = 0) const; | |
347 | virtual void SetTextColour(const wxString& colour, int regionId = 0); | |
348 | virtual wxString GetTextColour(int regionId = 0) const; | |
349 | virtual inline int GetNumberOfTextRegions() const { return m_regions.Number(); } | |
350 | virtual void SetRegionName(const wxString& name, int regionId = 0); | |
351 | ||
352 | // Get the name representing the region for this image alone. | |
353 | // I.e. this image's region ids go from 0 to N-1. | |
354 | // But the names might be "0.2.0", "0.2.1" etc. depending on position in composite. | |
355 | // So the last digit represents the region Id, the others represent positions | |
356 | // in composites. | |
357 | virtual wxString GetRegionName(int regionId); | |
358 | ||
359 | // Gets the region corresponding to the name, or -1 if not found. | |
360 | virtual int GetRegionId(const wxString& name); | |
361 | ||
362 | // Construct names for regions, unique even for children of a composite. | |
363 | virtual void NameRegions(const wxString& parentName = ""); | |
364 | ||
365 | // Get list of regions | |
366 | inline wxList& GetRegions() const { return (wxList&) m_regions; } | |
367 | ||
368 | virtual void AddRegion(wxShapeRegion *region); | |
369 | ||
370 | virtual void ClearRegions(); | |
371 | ||
372 | // Assign new ids to this image and children (if composite) | |
373 | void AssignNewIds(); | |
374 | ||
375 | // Returns actual image (same as 'this' if non-composite) and region id | |
376 | // for given region name. | |
377 | virtual wxShape *FindRegion(const wxString& regionName, int *regionId); | |
378 | ||
379 | // Finds all region names for this image (composite or simple). | |
380 | // Supply empty string list. | |
381 | virtual void FindRegionNames(wxStringList& list); | |
382 | ||
383 | virtual void ClearText(int regionId = 0); | |
384 | void RemoveLine(wxLineShape *line); | |
385 | ||
386 | #ifdef PROLOGIO | |
387 | // I/O | |
388 | virtual void WriteAttributes(wxExpr *clause); | |
389 | virtual void ReadAttributes(wxExpr *clause); | |
390 | ||
391 | // In case the object has constraints it needs to read in in a different pass | |
392 | inline virtual void ReadConstraints(wxExpr *WXUNUSED(clause), wxExprDatabase *WXUNUSED(database)) { }; | |
393 | virtual void WriteRegions(wxExpr *clause); | |
394 | virtual void ReadRegions(wxExpr *clause); | |
395 | #endif | |
396 | ||
397 | // Attachment code | |
398 | virtual bool GetAttachmentPosition(int attachment, double *x, double *y, | |
399 | int nth = 0, int no_arcs = 1, wxLineShape *line = NULL); | |
400 | virtual int GetNumberOfAttachments() const; | |
401 | virtual bool AttachmentIsValid(int attachment) const; | |
402 | ||
403 | // Only get the attachment position at the _edge_ of the shape, ignoring | |
404 | // branching mode. This is used e.g. to indicate the edge of interest, not the point | |
405 | // on the attachment branch. | |
406 | virtual bool GetAttachmentPositionEdge(int attachment, double *x, double *y, | |
407 | int nth = 0, int no_arcs = 1, wxLineShape *line = NULL); | |
408 | ||
409 | // Assuming the attachment lies along a vertical or horizontal line, | |
410 | // calculate the position on that point. | |
411 | virtual wxRealPoint CalcSimpleAttachment(const wxRealPoint& pt1, const wxRealPoint& pt2, | |
412 | int nth, int noArcs, wxLineShape* line); | |
413 | ||
414 | // Returns TRUE if pt1 <= pt2 in the sense that one point comes before another on an | |
415 | // edge of the shape. | |
416 | // attachmentPoint is the attachment point (= side) in question. | |
417 | virtual bool AttachmentSortTest(int attachmentPoint, const wxRealPoint& pt1, const wxRealPoint& pt2); | |
418 | ||
419 | virtual void EraseLinks(wxDC& dc, int attachment = -1, bool recurse = FALSE); | |
420 | virtual void DrawLinks(wxDC& dc, int attachment = -1, bool recurse = FALSE); | |
421 | ||
422 | virtual bool MoveLineToNewAttachment(wxDC& dc, wxLineShape *to_move, | |
423 | double x, double y); | |
424 | ||
425 | // Reorders the lines coming into the node image at this attachment | |
426 | // position, in the order in which they appear in linesToSort. | |
427 | virtual void SortLines(int attachment, wxList& linesToSort); | |
428 | ||
429 | // Apply an attachment ordering change | |
430 | void ApplyAttachmentOrdering(wxList& ordering); | |
431 | ||
432 | // Can override this to prevent or intercept line reordering. | |
433 | virtual void OnChangeAttachment(int attachment, wxLineShape* line, wxList& ordering); | |
434 | ||
435 | //// New banching attachment code, 24/9/98 | |
436 | ||
437 | // | |
438 | // |________| | |
439 | // | <- root | |
440 | // | <- neck | |
441 | // shoulder1 ->---------<- shoulder2 | |
442 | // | | | | |<- stem | |
443 | // <- branching attachment point N-1 | |
444 | ||
445 | // This function gets the root point at the given attachment. | |
446 | virtual wxRealPoint GetBranchingAttachmentRoot(int attachment); | |
447 | ||
448 | // This function gets information about where branching connections go (calls GetBranchingAttachmentRoot) | |
449 | virtual bool GetBranchingAttachmentInfo(int attachment, wxRealPoint& root, wxRealPoint& neck, | |
450 | wxRealPoint& shoulder1, wxRealPoint& shoulder2); | |
451 | ||
452 | // n is the number of the adjoining line, from 0 to N-1 where N is the number of lines | |
453 | // at this attachment point. | |
454 | // attachmentPoint is where the arc meets the stem, and stemPoint is where the stem meets the | |
455 | // shoulder. | |
456 | virtual bool GetBranchingAttachmentPoint(int attachment, int n, wxRealPoint& attachmentPoint, | |
457 | wxRealPoint& stemPoint); | |
458 | ||
459 | // Get the number of lines at this attachment position. | |
460 | virtual int GetAttachmentLineCount(int attachment) const; | |
461 | ||
462 | // Draw the branches (not the actual arcs though) | |
463 | virtual void OnDrawBranches(wxDC& dc, int attachment, bool erase = FALSE); | |
464 | virtual void OnDrawBranches(wxDC& dc, bool erase = FALSE); | |
465 | ||
466 | // Branching attachment settings | |
467 | inline void SetBranchNeckLength(int len) { m_branchNeckLength = len; } | |
468 | inline int GetBranchNeckLength() const { return m_branchNeckLength; } | |
469 | ||
470 | inline void SetBranchStemLength(int len) { m_branchStemLength = len; } | |
471 | inline int GetBranchStemLength() const { return m_branchStemLength; } | |
472 | ||
473 | inline void SetBranchSpacing(int len) { m_branchSpacing = len; } | |
474 | inline int GetBranchSpacing() const { return m_branchSpacing; } | |
475 | ||
476 | // Further detail on branching style, e.g. blobs on interconnections | |
477 | inline void SetBranchStyle(long style) { m_branchStyle = style; } | |
478 | inline long GetBranchStyle() const { return m_branchStyle; } | |
479 | ||
480 | // Rotate the standard attachment point from physical (0 is always North) | |
481 | // to logical (0 -> 1 if rotated by 90 degrees) | |
482 | virtual int PhysicalToLogicalAttachment(int physicalAttachment) const; | |
483 | ||
484 | // Rotate the standard attachment point from logical | |
485 | // to physical (0 is always North) | |
486 | virtual int LogicalToPhysicalAttachment(int logicalAttachment) const; | |
487 | ||
488 | // This is really to distinguish between lines and other images. | |
489 | // For lines, want to pass drag to canvas, since lines tend to prevent | |
490 | // dragging on a canvas (they get in the way.) | |
491 | virtual bool Draggable() const { return TRUE; } | |
492 | ||
493 | // Returns TRUE if image is a descendant of this image | |
494 | bool HasDescendant(wxShape *image); | |
495 | ||
496 | // Creates a copy of this shape. | |
497 | wxShape *CreateNewCopy(bool resetMapping = TRUE, bool recompute = TRUE); | |
498 | ||
499 | // Does the copying for this object | |
500 | virtual void Copy(wxShape& copy); | |
501 | ||
502 | // Does the copying for this object, including copying event | |
503 | // handler data if any. Calls the virtual Copy function. | |
504 | void CopyWithHandler(wxShape& copy); | |
505 | ||
506 | // Rotate about the given axis by the given amount in radians. | |
507 | virtual void Rotate(double x, double y, double theta); | |
508 | virtual inline double GetRotation() const { return m_rotation; } | |
509 | ||
510 | void ClearAttachments(); | |
511 | ||
512 | // Recentres all the text regions for this object | |
513 | void Recentre(wxDC& dc); | |
514 | ||
515 | // Clears points from a list of wxRealPoints | |
516 | void ClearPointList(wxList& list); | |
517 | ||
518 | private: | |
519 | wxObject* m_clientData; | |
520 | ||
521 | protected: | |
522 | wxShapeEvtHandler* m_eventHandler; | |
523 | bool m_formatted; | |
524 | double m_xpos, m_ypos; | |
525 | wxPen* m_pen; | |
526 | wxBrush* m_brush; | |
527 | wxFont* m_font; | |
528 | wxColour* m_textColour; | |
529 | wxString m_textColourName; | |
530 | wxShapeCanvas* m_canvas; | |
531 | wxList m_lines; | |
532 | wxList m_text; | |
533 | wxList m_controlPoints; | |
534 | wxList m_regions; | |
535 | wxList m_attachmentPoints; | |
536 | bool m_visible; | |
537 | bool m_disableLabel; | |
538 | long m_id; | |
539 | bool m_selected; | |
540 | bool m_highlighted; // Different from selected: user-defined highlighting, | |
541 | // e.g. thick border. | |
542 | double m_rotation; | |
543 | int m_sensitivity; | |
544 | bool m_draggable; | |
545 | int m_attachmentMode; // 0 for no attachments, 1 if using normal attachments, | |
546 | // 2 for branching attachments | |
547 | bool m_spaceAttachments; // TRUE if lines at one side should be spaced | |
548 | bool m_fixedWidth; | |
549 | bool m_fixedHeight; | |
550 | bool m_centreResize; // Default is to resize keeping the centre constant (TRUE) | |
551 | bool m_drawHandles; // Don't draw handles if FALSE, usually TRUE | |
552 | wxList m_children; // In case it's composite | |
553 | wxShape* m_parent; // In case it's a child | |
554 | int m_formatMode; | |
555 | int m_shadowMode; | |
556 | wxBrush* m_shadowBrush; | |
557 | int m_shadowOffsetX; | |
558 | int m_shadowOffsetY; | |
559 | int m_textMarginX; // Gap between text and border | |
560 | int m_textMarginY; | |
561 | wxString m_regionName; | |
562 | bool m_maintainAspectRatio; | |
563 | int m_branchNeckLength; | |
564 | int m_branchStemLength; | |
565 | int m_branchSpacing; | |
566 | long m_branchStyle; | |
567 | }; | |
568 | ||
569 | class wxPolygonShape: public wxShape | |
570 | { | |
571 | DECLARE_DYNAMIC_CLASS(wxPolygonShape) | |
572 | public: | |
573 | wxPolygonShape(); | |
574 | ~wxPolygonShape(); | |
575 | ||
576 | // Takes a list of wxRealPoints; each point is an OFFSET from the centre. | |
577 | // Deletes user's points in destructor. | |
578 | virtual void Create(wxList *points); | |
579 | virtual void ClearPoints(); | |
580 | ||
581 | void GetBoundingBoxMin(double *w, double *h); | |
582 | void CalculateBoundingBox(); | |
583 | bool GetPerimeterPoint(double x1, double y1, | |
584 | double x2, double y2, | |
585 | double *x3, double *y3); | |
586 | bool HitTest(double x, double y, int *attachment, double *distance); | |
587 | void SetSize(double x, double y, bool recursive = TRUE); | |
588 | void OnDraw(wxDC& dc); | |
589 | void OnDrawOutline(wxDC& dc, double x, double y, double w, double h); | |
590 | ||
591 | // Control points ('handles') redirect control to the actual shape, to make it easier | |
592 | // to override sizing behaviour. | |
593 | virtual void OnSizingDragLeft(wxControlPoint* pt, bool draw, double x, double y, int keys=0, int attachment = 0); | |
594 | virtual void OnSizingBeginDragLeft(wxControlPoint* pt, double x, double y, int keys=0, int attachment = 0); | |
595 | virtual void OnSizingEndDragLeft(wxControlPoint* pt, double x, double y, int keys=0, int attachment = 0); | |
596 | ||
597 | // A polygon should have a control point at each vertex, | |
598 | // with the option of moving the control points individually | |
599 | // to change the shape. | |
600 | void MakeControlPoints(); | |
601 | void ResetControlPoints(); | |
602 | ||
603 | // If we've changed the shape, must make the original | |
604 | // points match the working points | |
605 | void UpdateOriginalPoints(); | |
606 | ||
607 | // Add a control point after the given point | |
608 | virtual void AddPolygonPoint(int pos = 0); | |
609 | ||
610 | // Delete a control point | |
611 | virtual void DeletePolygonPoint(int pos = 0); | |
612 | ||
613 | // Recalculates the centre of the polygon | |
614 | virtual void CalculatePolygonCentre(); | |
615 | ||
616 | #ifdef PROLOGIO | |
617 | void WriteAttributes(wxExpr *clause); | |
618 | void ReadAttributes(wxExpr *clause); | |
619 | #endif | |
620 | ||
621 | int GetNumberOfAttachments() const; | |
622 | bool GetAttachmentPosition(int attachment, double *x, double *y, | |
623 | int nth = 0, int no_arcs = 1, wxLineShape *line = NULL); | |
624 | bool AttachmentIsValid(int attachment); | |
625 | // Does the copying for this object | |
626 | void Copy(wxShape& copy); | |
627 | ||
628 | inline wxList *GetPoints() { return m_points; } | |
629 | ||
630 | // Rotate about the given axis by the given amount in radians | |
631 | virtual void Rotate(double x, double y, double theta); | |
632 | ||
633 | private: | |
634 | wxList* m_points; | |
635 | wxList* m_originalPoints; | |
636 | double m_boundWidth; | |
637 | double m_boundHeight; | |
638 | double m_originalWidth; | |
639 | double m_originalHeight; | |
640 | }; | |
641 | ||
642 | class wxRectangleShape: public wxShape | |
643 | { | |
644 | DECLARE_DYNAMIC_CLASS(wxRectangleShape) | |
645 | public: | |
646 | wxRectangleShape(double w = 0.0, double h = 0.0); | |
647 | void GetBoundingBoxMin(double *w, double *h); | |
648 | bool GetPerimeterPoint(double x1, double y1, | |
649 | double x2, double y2, | |
650 | double *x3, double *y3); | |
651 | void OnDraw(wxDC& dc); | |
652 | void SetSize(double x, double y, bool recursive = TRUE); | |
653 | void SetCornerRadius(double rad); // If > 0, rounded corners | |
654 | ||
655 | #ifdef PROLOGIO | |
656 | void WriteAttributes(wxExpr *clause); | |
657 | void ReadAttributes(wxExpr *clause); | |
658 | #endif | |
659 | ||
660 | int GetNumberOfAttachments() const; | |
661 | bool GetAttachmentPosition(int attachment, double *x, double *y, | |
662 | int nth = 0, int no_arcs = 1, wxLineShape *line = NULL); | |
663 | // Does the copying for this object | |
664 | void Copy(wxShape& copy); | |
665 | ||
666 | inline double GetWidth() const { return m_width; } | |
667 | inline double GetHeight() const { return m_height; } | |
668 | inline void SetWidth(double w) { m_width = w; } | |
669 | inline void SetHeight(double h) { m_height = h; } | |
670 | ||
671 | protected: | |
672 | double m_width; | |
673 | double m_height; | |
674 | double m_cornerRadius; | |
675 | }; | |
676 | ||
677 | class wxTextShape: public wxRectangleShape | |
678 | { | |
679 | DECLARE_DYNAMIC_CLASS(wxTextShape) | |
680 | public: | |
681 | wxTextShape(double width = 0.0, double height = 0.0); | |
682 | ||
683 | void OnDraw(wxDC& dc); | |
684 | ||
685 | #ifdef PROLOGIO | |
686 | void WriteAttributes(wxExpr *clause); | |
687 | #endif | |
688 | ||
689 | // Does the copying for this object | |
690 | void Copy(wxShape& copy); | |
691 | }; | |
692 | ||
693 | class wxEllipseShape: public wxShape | |
694 | { | |
695 | DECLARE_DYNAMIC_CLASS(wxEllipseShape) | |
696 | public: | |
697 | wxEllipseShape(double w = 0.0, double h = 0.0); | |
698 | ||
699 | void GetBoundingBoxMin(double *w, double *h); | |
700 | bool GetPerimeterPoint(double x1, double y1, | |
701 | double x2, double y2, | |
702 | double *x3, double *y3); | |
703 | ||
704 | void OnDraw(wxDC& dc); | |
705 | void SetSize(double x, double y, bool recursive = TRUE); | |
706 | ||
707 | #ifdef PROLOGIO | |
708 | void WriteAttributes(wxExpr *clause); | |
709 | void ReadAttributes(wxExpr *clause); | |
710 | #endif | |
711 | ||
712 | int GetNumberOfAttachments() const; | |
713 | bool GetAttachmentPosition(int attachment, double *x, double *y, | |
714 | int nth = 0, int no_arcs = 1, wxLineShape *line = NULL); | |
715 | ||
716 | // Does the copying for this object | |
717 | void Copy(wxShape& copy); | |
718 | ||
719 | inline double GetWidth() const { return m_width; } | |
720 | inline double GetHeight() const { return m_height; } | |
721 | ||
722 | inline void SetWidth(double w) { m_width = w; } | |
723 | inline void SetHeight(double h) { m_height = h; } | |
724 | ||
725 | protected: | |
726 | double m_width; | |
727 | double m_height; | |
728 | }; | |
729 | ||
730 | class wxCircleShape: public wxEllipseShape | |
731 | { | |
732 | DECLARE_DYNAMIC_CLASS(wxCircleShape) | |
733 | public: | |
734 | wxCircleShape(double w = 0.0); | |
735 | ||
736 | bool GetPerimeterPoint(double x1, double y1, | |
737 | double x2, double y2, | |
738 | double *x3, double *y3); | |
739 | // Does the copying for this object | |
740 | void Copy(wxShape& copy); | |
741 | }; | |
742 | ||
743 | #endif | |
744 | // _OGL_BASIC_H_ |