]> git.saurik.com Git - wxWidgets.git/blob - utils/ogl/src/lines.h
7adecf124601078bd9f5aff1f8d201f0260dda6e
[wxWidgets.git] / utils / ogl / src / lines.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: lines.h
3 // Purpose: wxLineShape
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_LINES_H_
13 #define _OGL_LINES_H_
14
15 #ifdef __GNUG__
16 #pragma interface "lines.h"
17 #endif
18
19 class wxLabelShape;
20 class wxPseudoMetaFile;
21 class wxLineControlPoint;
22 /*
23 * Arcs with multiple arrowheads
24 *
25 */
26
27 // Types of arrowhead
28 // (i) Built-in
29 #define ARROW_HOLLOW_CIRCLE 1
30 #define ARROW_FILLED_CIRCLE 2
31 #define ARROW_ARROW 3
32 #define ARROW_SINGLE_OBLIQUE 4
33 #define ARROW_DOUBLE_OBLIQUE 5
34 // (ii) Custom
35 #define ARROW_METAFILE 20
36
37 // Position of arrow on line
38 #define ARROW_POSITION_START 0
39 #define ARROW_POSITION_END 1
40 #define ARROW_POSITION_MIDDLE 2
41
42 // Line alignment flags
43 // Vertical by default
44 #define LINE_ALIGNMENT_HORIZ 1
45 #define LINE_ALIGNMENT_VERT 0
46 #define LINE_ALIGNMENT_TO_NEXT_HANDLE 2
47 #define LINE_ALIGNMENT_NONE 0
48
49 class wxArrowHead: public wxObject
50 {
51 DECLARE_DYNAMIC_CLASS(wxArrowHead)
52
53 public:
54 wxArrowHead(WXTYPE type = 0, int end = 0, float size = 0.0, float dist = 0.0, const wxString& name = "", wxPseudoMetaFile *mf = NULL,
55 long arrowId = -1);
56 ~wxArrowHead();
57 wxArrowHead(wxArrowHead& toCopy);
58
59 inline WXTYPE _GetType() const { return m_arrowType; }
60 inline int GetPosition() const { return m_arrowEnd; }
61 inline float GetXOffset() const { return m_xOffset; }
62 inline float GetYOffset() const { return m_yOffset; }
63 inline float GetSpacing() const { return m_spacing; }
64 inline float GetSize() const { return m_arrowSize; }
65 inline wxString GetName() const { return m_arrowName; }
66 inline void SetXOffset(float x) { m_xOffset = x; }
67 inline void SetYOffset(float y) { m_yOffset = y; }
68 inline wxPseudoMetaFile *GetMetaFile() const { return m_metaFile; }
69 inline long GetId() const { return m_id; }
70 inline int GetArrowEnd() const { return m_arrowEnd; }
71 inline float GetArrowSize() const { return m_arrowSize; }
72 void SetSize(float size);
73 inline void SetSpacing(float sp) { m_spacing = sp; }
74
75 protected:
76 WXTYPE m_arrowType;
77 int m_arrowEnd; // Position on line
78 float m_xOffset; // Distance from arc start or end, w.r.t. point on arrowhead
79 // nearest start or end. If zero, use default spacing.
80 float m_yOffset; // vertical offset (w.r.t. a horizontal line). Normally zero.
81 float m_spacing; // Spacing from the last arrowhead
82 float m_arrowSize; // Length of arrowhead
83 wxString m_arrowName; // Name of arrow
84 bool m_saveToFile; // TRUE if we want to save custom arrowheads to file.
85 wxPseudoMetaFile* m_metaFile; // Pseudo metafile if this is a custom arrowhead
86 long m_id; // identifier
87 };
88
89 // Line object
90 class wxLineShape: public wxShape
91 {
92 DECLARE_DYNAMIC_CLASS(wxLineShape)
93
94 public:
95 wxLineShape();
96 ~wxLineShape();
97
98 // Called when a connected object has moved, to move the link to
99 // correct position
100 // moveControlPoints must be disabled when a control point is being
101 // dragged.
102 void OnMoveLink(wxDC& dc, bool moveControlPoints = TRUE);
103 bool OnMovePre(wxDC& dc, float x, float y, float old_x, float old_y, bool display = TRUE);
104 void OnDraw(wxDC& dc);
105 void OnDrawContents(wxDC& dc);
106 void OnDrawControlPoints(wxDC& dc);
107 void OnEraseControlPoints(wxDC& dc);
108 void OnErase(wxDC& dc);
109 virtual inline void OnMoveControlPoint(int WXUNUSED(which), float WXUNUSED(x), float WXUNUSED(y)) {}
110 void OnDrawOutline(wxDC& dc, float x, float y, float w, float h);
111 void GetBoundingBoxMin(float *w, float *h);
112 void FormatText(wxDC& dc, const wxString& s, int regionId = 0);
113 virtual void SetEnds(float x1, float y1, float x2, float y2);
114 virtual void GetEnds(float *x1, float *y1, float *x2, float *y2);
115 inline virtual wxShape *GetFrom() { return m_from; }
116 inline virtual wxShape *GetTo() { return m_to; }
117 inline virtual int GetAttachmentFrom() { return m_attachmentFrom; }
118 inline virtual int GetAttachmentTo() { return m_attachmentTo; }
119
120 virtual void SetFrom(wxShape *object);
121 virtual void SetTo(wxShape *object);
122 virtual void DrawArrows(wxDC& dc);
123
124 // Finds the x, y points at the two ends of the line.
125 // This function can be used by e.g. line-routing routines to
126 // get the actual points on the two node images where the lines will be drawn
127 // to/from.
128 void FindLineEndPoints(float *fromX, float *fromY, float *toX, float *toY);
129
130 // Format one region at this position
131 void DrawRegion(wxDC& dc, wxShapeRegion *region, float x, float y);
132
133 // Erase one region at this position
134 void EraseRegion(wxDC& dc, wxShapeRegion *region, float x, float y);
135
136 // Get the reference point for a label. Region x and y
137 // are offsets from this.
138 // position is 0 (middle), 1 (start), 2 (end)
139 void GetLabelPosition(int position, float *x, float *y);
140
141 // Straighten verticals and horizontals
142 virtual void Straighten(wxDC& dc);
143
144 // Not implemented
145 inline void SetMaintainStraightLines(bool flag) { m_maintainStraightLines = flag; }
146 inline bool GetMaintainStraightLines() const { return m_maintainStraightLines; }
147
148 // Make handle control points
149 void MakeControlPoints();
150 void ResetControlPoints();
151
152 // Make a given number of control points
153 virtual void MakeLineControlPoints(int n);
154 virtual wxNode *InsertLineControlPoint(wxDC* dc);
155 virtual bool DeleteLineControlPoint();
156 virtual void Initialise();
157 inline wxList *GetLineControlPoints() { return m_lineControlPoints; }
158
159 // Override dragging behaviour - don't want to be able to drag lines!
160 void OnDragLeft(bool draw, float x, float y, int keys=0, int attachment = 0);
161 void OnBeginDragLeft(float x, float y, int keys=0, int attachment = 0);
162 void OnEndDragLeft(float x, float y, int keys=0, int attachment = 0);
163
164 // Override select, to create/delete temporary label-moving objects
165 void Select(bool select = TRUE, wxDC* dc = NULL);
166
167 // Set to spline (TRUE) or line (FALSE)
168 inline void SetSpline(bool spl) { m_isSpline = spl; }
169 inline bool IsSpline() const { return m_isSpline; }
170
171 void Unlink();
172 void SetAttachments(int from_attach, int to_attach);
173
174 bool HitTest(float x, float y, int *attachment, float *distance);
175
176 #ifdef PROLOGIO
177 // Prolog database stuff
178 virtual char *GetFunctor();
179 virtual void WritePrologAttributes(wxExpr *clause);
180 virtual void ReadPrologAttributes(wxExpr *clause);
181 #endif
182
183 virtual void FindNth(wxShape *image, int *nth, int *no_arcs, bool incoming);
184
185 // Find which position we're talking about at this (x, y).
186 // Returns ARROW_POSITION_START, ARROW_POSITION_MIDDLE, ARROW_POSITION_END
187 int FindLinePosition(float x, float y);
188
189 // This is really to distinguish between lines and other images.
190 // For lines, want to pass drag to canvas, since lines tend to prevent
191 // dragging on a canvas (they get in the way.)
192 virtual bool Draggable() const { return FALSE; }
193
194 // Does the copying for this object
195 void Copy(wxLineShape& copy);
196 wxShape *PrivateCopy();
197
198 // New OGL stuff
199 wxArrowHead *AddArrow(WXTYPE type, int end = ARROW_POSITION_END,
200 float arrowSize = 10.0, float xOffset = 0.0, const wxString& name = "",
201 wxPseudoMetaFile *mf = NULL, long arrowId = -1);
202
203 // Add an arrowhead in the position indicated by the reference
204 // list of arrowheads, which contains all legal arrowheads for this
205 // line, in the correct order.
206 // E.g. reference list: a b c d e
207 // Current line list: a d
208 // Add c, then line list is: a c d
209 // If no legal arrowhead position, return FALSE.
210 // Assume reference list is for one end only, since it potentially defines
211 // the ordering for any one of the 3 positions. So we don't check
212 // the reference list for arrowhead position.
213 bool AddArrowOrdered(wxArrowHead *arrow, wxList& referenceList, int end);
214
215 // Delete arrowhead(s)
216 void ClearArrowsAtPosition(int end = -1);
217 bool ClearArrow(const wxString& name);
218 wxArrowHead *FindArrowHead(int position, const wxString& name);
219 wxArrowHead *FindArrowHead(long arrowId);
220 bool DeleteArrowHead(int position, const wxString& name);
221 bool DeleteArrowHead(long arrowId);
222 void DrawArrow(wxDC& dc, wxArrowHead *arrow, float xOffset, bool proportionalOffset);
223 inline void SetIgnoreOffsets(bool ignore) { m_ignoreArrowOffsets = ignore; }
224
225 // Find horizontal width for drawing a line with
226 // arrows in minimum space. Assume arrows at
227 // END only
228 float FindMinimumWidth();
229
230 // Set alignment flags. ALIGNMENT NOT IMPLEMENTED.
231 void SetAlignmentOrientation(bool isEnd, bool isHoriz);
232 void SetAlignmentType(bool isEnd, int alignType);
233 bool GetAlignmentOrientation(bool isEnd);
234 int GetAlignmentType(bool isEnd);
235
236 // Find next control point in line after the start/end point
237 // (depending on whether the node object is at start or end)
238 wxRealPoint *GetNextControlPoint(wxShape *nodeObject);
239 inline bool IsEnd(wxShape *nodeObject) const { return (m_to == nodeObject); }
240
241 private:
242 bool m_erasing; // flag to say whether we're erasing or drawing
243 // this line (really so metafiles can draw a
244 // blank rectangle)
245 bool m_ignoreArrowOffsets; // Don't always want to draw arrowhead offsets
246 // because they may not work on tool palettes (for example)
247 bool m_isSpline;
248 bool m_maintainStraightLines;
249
250 protected:
251 // Temporary list of line segment orientations
252 // so we know what direction the line is supposed to be dog-legging
253 // in. The values are integer: 0 for vertical, 1 for horizontal.
254 wxList m_lineOrientations;
255
256 // Temporary pointers for start, middle and end label editing objects
257 // (active only when the line is selected)
258 wxLabelShape* m_labelObjects[3];
259
260 // These define the segmented line - not to be confused with temporary control
261 // points which appear when object is selected (although in this case they'll
262 // probably be the same)
263 wxList* m_lineControlPoints;
264
265 float m_arrowSpacing; // Separation between adjacent arrows
266
267 wxShape* m_to;
268 wxShape* m_from;
269
270 /*
271 float m_actualTextWidth; // Space the text takes up
272 float m_actualTextHeight; // (depends on text content unlike nodes)
273 */
274 int m_attachmentTo; // Attachment point at one end
275 int m_attachmentFrom; // Attachment point at other end
276
277 // Alignment flags
278 int m_alignmentStart;
279 int m_alignmentEnd;
280
281 wxList m_arcArrows;
282
283 };
284
285 #endif
286 // _OGL_LINES_H_