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