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