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