1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxLineShape
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "lines.h"
14 #pragma implementation "linesp.h"
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
28 #include <wx/wxexpr.h>
43 #include <wx/ogl/basic.h>
44 #include <wx/ogl/basicp.h>
45 #include <wx/ogl/lines.h>
46 #include <wx/ogl/linesp.h>
47 #include <wx/ogl/drawn.h>
48 #include <wx/ogl/misc.h>
49 #include <wx/ogl/canvas.h>
52 IMPLEMENT_DYNAMIC_CLASS(wxLineShape
, wxShape
)
54 wxLineShape::wxLineShape()
56 m_sensitivity
= OP_CLICK_LEFT
| OP_CLICK_RIGHT
;
61 m_actualTextWidth = 0.0;
62 m_actualTextHeight = 0.0;
67 m_arrowSpacing
= 5.0; // For the moment, don't bother saving this to file.
68 m_ignoreArrowOffsets
= FALSE
;
70 m_maintainStraightLines
= FALSE
;
74 m_lineControlPoints
= NULL
;
76 // Clear any existing regions (created in an earlier constructor)
77 // and make the three line regions.
79 wxShapeRegion
*newRegion
= new wxShapeRegion
;
80 newRegion
->SetName("Middle");
81 newRegion
->SetSize(150, 50);
82 m_regions
.Append((wxObject
*)newRegion
);
84 newRegion
= new wxShapeRegion
;
85 newRegion
->SetName("Start");
86 newRegion
->SetSize(150, 50);
87 m_regions
.Append((wxObject
*)newRegion
);
89 newRegion
= new wxShapeRegion
;
90 newRegion
->SetName("End");
91 newRegion
->SetSize(150, 50);
92 m_regions
.Append((wxObject
*)newRegion
);
94 for (int i
= 0; i
< 3; i
++)
95 m_labelObjects
[i
] = NULL
;
98 wxLineShape::~wxLineShape()
100 if (m_lineControlPoints
)
102 ClearPointList(*m_lineControlPoints
);
103 delete m_lineControlPoints
;
105 for (int i
= 0; i
< 3; i
++)
107 if (m_labelObjects
[i
])
109 m_labelObjects
[i
]->Select(FALSE
);
110 m_labelObjects
[i
]->RemoveFromCanvas(m_canvas
);
111 delete m_labelObjects
[i
];
112 m_labelObjects
[i
] = NULL
;
115 ClearArrowsAtPosition(-1);
118 void wxLineShape::MakeLineControlPoints(int n
)
120 if (m_lineControlPoints
)
122 ClearPointList(*m_lineControlPoints
);
123 delete m_lineControlPoints
;
125 m_lineControlPoints
= new wxList
;
128 for (i
= 0; i
< n
; i
++)
130 wxRealPoint
*point
= new wxRealPoint(-999, -999);
131 m_lineControlPoints
->Append((wxObject
*) point
);
135 wxNode
*wxLineShape::InsertLineControlPoint(wxDC
* dc
)
140 wxNode
*last
= m_lineControlPoints
->Last();
141 wxNode
*second_last
= last
->Previous();
142 wxRealPoint
*last_point
= (wxRealPoint
*)last
->Data();
143 wxRealPoint
*second_last_point
= (wxRealPoint
*)second_last
->Data();
145 // Choose a point half way between the last and penultimate points
146 double line_x
= ((last_point
->x
+ second_last_point
->x
)/2);
147 double line_y
= ((last_point
->y
+ second_last_point
->y
)/2);
149 wxRealPoint
*point
= new wxRealPoint(line_x
, line_y
);
150 wxNode
*node
= m_lineControlPoints
->Insert(last
, (wxObject
*) point
);
154 bool wxLineShape::DeleteLineControlPoint()
156 if (m_lineControlPoints
->Number() < 3)
159 wxNode
*last
= m_lineControlPoints
->Last();
160 wxNode
*second_last
= last
->Previous();
162 wxRealPoint
*second_last_point
= (wxRealPoint
*)second_last
->Data();
163 delete second_last_point
;
169 void wxLineShape::Initialise()
171 if (m_lineControlPoints
)
173 // Just move the first and last control points
174 wxNode
*first
= m_lineControlPoints
->First();
175 wxRealPoint
*first_point
= (wxRealPoint
*)first
->Data();
177 wxNode
*last
= m_lineControlPoints
->Last();
178 wxRealPoint
*last_point
= (wxRealPoint
*)last
->Data();
180 // If any of the line points are at -999, we must
181 // initialize them by placing them half way between the first
183 wxNode
*node
= first
->Next();
186 wxRealPoint
*point
= (wxRealPoint
*)node
->Data();
187 if (point
->x
== -999)
189 double x1
, y1
, x2
, y2
;
190 if (first_point
->x
< last_point
->x
)
191 { x1
= first_point
->x
; x2
= last_point
->x
; }
193 { x2
= first_point
->x
; x1
= last_point
->x
; }
195 if (first_point
->y
< last_point
->y
)
196 { y1
= first_point
->y
; y2
= last_point
->y
; }
198 { y2
= first_point
->y
; y1
= last_point
->y
; }
200 point
->x
= ((x2
- x1
)/2 + x1
);
201 point
->y
= ((y2
- y1
)/2 + y1
);
208 // Format a text string according to the region size, adding
209 // strings with positions to region text list
210 void wxLineShape::FormatText(wxDC
& dc
, const wxString
& s
, int i
)
215 if (m_regions
.Number() < 1)
217 wxNode
*node
= m_regions
.Nth(i
);
221 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
223 dc
.SetFont(* region
->GetFont());
225 region
->GetSize(&w
, &h
);
226 // Initialize the size if zero
227 if (((w
== 0) || (h
== 0)) && (strlen(s
) > 0))
230 region
->SetSize(w
, h
);
233 wxStringList
*string_list
= oglFormatText(dc
, s
, (w
-5), (h
-5), region
->GetFormatMode());
234 node
= string_list
->First();
237 char *s
= (char *)node
->Data();
238 wxShapeTextLine
*line
= new wxShapeTextLine(0.0, 0.0, s
);
239 region
->GetFormattedText().Append((wxObject
*)line
);
245 if (region
->GetFormatMode() & FORMAT_SIZE_TO_CONTENTS
)
247 oglGetCentredTextExtent(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, w
, h
, &actualW
, &actualH
);
248 if ((actualW
!= w
) || (actualH
!= h
))
251 GetLabelPosition(i
, &xx
, &yy
);
252 EraseRegion(dc
, region
, xx
, yy
);
253 if (m_labelObjects
[i
])
255 m_labelObjects
[i
]->Select(FALSE
, &dc
);
256 m_labelObjects
[i
]->Erase(dc
);
257 m_labelObjects
[i
]->SetSize(actualW
, actualH
);
260 region
->SetSize(actualW
, actualH
);
262 if (m_labelObjects
[i
])
264 m_labelObjects
[i
]->Select(TRUE
, & dc
);
265 m_labelObjects
[i
]->Draw(dc
);
269 oglCentreText(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, actualW
, actualH
, region
->GetFormatMode());
273 void wxLineShape::DrawRegion(wxDC
& dc
, wxShapeRegion
*region
, double x
, double y
)
275 if (GetDisableLabel())
280 region
->GetSize(&w
, &h
);
282 // Get offset from x, y
283 region
->GetPosition(&xx
, &yy
);
288 // First, clear a rectangle for the text IF there is any
289 if (region
->GetFormattedText().Number() > 0)
291 dc
.SetPen(* g_oglWhiteBackgroundPen
);
292 dc
.SetBrush(* g_oglWhiteBackgroundBrush
);
295 if (region
->GetFont()) dc
.SetFont(* region
->GetFont());
297 dc
.DrawRectangle((long)(xp
- w
/2.0), (long)(yp
- h
/2.0), (long)w
, (long)h
);
299 if (m_pen
) dc
.SetPen(* m_pen
);
300 dc
.SetTextForeground(* region
->GetActualColourObject());
303 dc
.SetTextBackground(g_oglWhiteBackgroundBrush
->GetColour());
306 oglDrawFormattedText(dc
, &(region
->GetFormattedText()), xp
, yp
, w
, h
, region
->GetFormatMode());
310 void wxLineShape::EraseRegion(wxDC
& dc
, wxShapeRegion
*region
, double x
, double y
)
312 if (GetDisableLabel())
317 region
->GetSize(&w
, &h
);
319 // Get offset from x, y
320 region
->GetPosition(&xx
, &yy
);
325 if (region
->GetFormattedText().Number() > 0)
327 dc
.SetPen(* g_oglWhiteBackgroundPen
);
328 dc
.SetBrush(* g_oglWhiteBackgroundBrush
);
330 dc
.DrawRectangle((long)(xp
- w
/2.0), (long)(yp
- h
/2.0), (long)w
, (long)h
);
334 // Get the reference point for a label. Region x and y
335 // are offsets from this.
336 // position is 0, 1, 2
337 void wxLineShape::GetLabelPosition(int position
, double *x
, double *y
)
343 // Want to take the middle section for the label
344 int n
= m_lineControlPoints
->Number();
345 int half_way
= (int)(n
/2);
347 // Find middle of this line
348 wxNode
*node
= m_lineControlPoints
->Nth(half_way
- 1);
349 wxRealPoint
*point
= (wxRealPoint
*)node
->Data();
350 wxNode
*next_node
= node
->Next();
351 wxRealPoint
*next_point
= (wxRealPoint
*)next_node
->Data();
353 double dx
= (next_point
->x
- point
->x
);
354 double dy
= (next_point
->y
- point
->y
);
355 *x
= (double)(point
->x
+ dx
/2.0);
356 *y
= (double)(point
->y
+ dy
/2.0);
361 wxNode
*node
= m_lineControlPoints
->First();
362 *x
= ((wxRealPoint
*)node
->Data())->x
;
363 *y
= ((wxRealPoint
*)node
->Data())->y
;
368 wxNode
*node
= m_lineControlPoints
->Last();
369 *x
= ((wxRealPoint
*)node
->Data())->x
;
370 *y
= ((wxRealPoint
*)node
->Data())->y
;
379 * Find whether line is supposed to be vertical or horizontal and
383 void GraphicsStraightenLine(wxRealPoint
*point1
, wxRealPoint
*point2
)
385 double dx
= point2
->x
- point1
->x
;
386 double dy
= point2
->y
- point1
->y
;
390 else if (fabs(dy
/dx
) > 1.0)
392 point2
->x
= point1
->x
;
394 else point2
->y
= point1
->y
;
397 void wxLineShape::Straighten(wxDC
*dc
)
399 if (!m_lineControlPoints
|| m_lineControlPoints
->Number() < 3)
405 wxNode
*first_point_node
= m_lineControlPoints
->First();
406 wxNode
*last_point_node
= m_lineControlPoints
->Last();
407 wxNode
*second_last_point_node
= last_point_node
->Previous();
409 wxRealPoint
*last_point
= (wxRealPoint
*)last_point_node
->Data();
410 wxRealPoint
*second_last_point
= (wxRealPoint
*)second_last_point_node
->Data();
412 GraphicsStraightenLine(last_point
, second_last_point
);
414 wxNode
*node
= first_point_node
;
415 while (node
&& (node
!= second_last_point_node
))
417 wxRealPoint
*point
= (wxRealPoint
*)node
->Data();
418 wxRealPoint
*next_point
= (wxRealPoint
*)(node
->Next()->Data());
420 GraphicsStraightenLine(point
, next_point
);
429 void wxLineShape::Unlink()
432 m_to
->GetLines().DeleteObject(this);
434 m_from
->GetLines().DeleteObject(this);
439 void wxLineShape::SetEnds(double x1
, double y1
, double x2
, double y2
)
442 wxNode
*first_point_node
= m_lineControlPoints
->First();
443 wxNode
*last_point_node
= m_lineControlPoints
->Last();
444 wxRealPoint
*first_point
= (wxRealPoint
*)first_point_node
->Data();
445 wxRealPoint
*last_point
= (wxRealPoint
*)last_point_node
->Data();
452 m_xpos
= (double)((x1
+ x2
)/2.0);
453 m_ypos
= (double)((y1
+ y2
)/2.0);
456 // Get absolute positions of ends
457 void wxLineShape::GetEnds(double *x1
, double *y1
, double *x2
, double *y2
)
459 wxNode
*first_point_node
= m_lineControlPoints
->First();
460 wxNode
*last_point_node
= m_lineControlPoints
->Last();
461 wxRealPoint
*first_point
= (wxRealPoint
*)first_point_node
->Data();
462 wxRealPoint
*last_point
= (wxRealPoint
*)last_point_node
->Data();
464 *x1
= first_point
->x
; *y1
= first_point
->y
;
465 *x2
= last_point
->x
; *y2
= last_point
->y
;
468 void wxLineShape::SetAttachments(int from_attach
, int to_attach
)
470 m_attachmentFrom
= from_attach
;
471 m_attachmentTo
= to_attach
;
474 bool wxLineShape::HitTest(double x
, double y
, int *attachment
, double *distance
)
476 if (!m_lineControlPoints
)
479 // Look at label regions in case mouse is over a label
480 bool inLabelRegion
= FALSE
;
481 for (int i
= 0; i
< 3; i
++)
483 wxNode
*regionNode
= m_regions
.Nth(i
);
486 wxShapeRegion
*region
= (wxShapeRegion
*)regionNode
->Data();
487 if (region
->m_formattedText
.Number() > 0)
489 double xp
, yp
, cx
, cy
, cw
, ch
;
490 GetLabelPosition(i
, &xp
, &yp
);
491 // Offset region from default label position
492 region
->GetPosition(&cx
, &cy
);
493 region
->GetSize(&cw
, &ch
);
496 double rLeft
= (double)(cx
- (cw
/2.0));
497 double rTop
= (double)(cy
- (ch
/2.0));
498 double rRight
= (double)(cx
+ (cw
/2.0));
499 double rBottom
= (double)(cy
+ (ch
/2.0));
500 if (x
> rLeft
&& x
< rRight
&& y
> rTop
&& y
< rBottom
)
502 inLabelRegion
= TRUE
;
509 wxNode
*node
= m_lineControlPoints
->First();
511 while (node
&& node
->Next())
513 wxRealPoint
*point1
= (wxRealPoint
*)node
->Data();
514 wxRealPoint
*point2
= (wxRealPoint
*)node
->Next()->Data();
516 // Allow for inaccurate mousing or vert/horiz lines
518 double left
= wxMin(point1
->x
, point2
->x
) - extra
;
519 double right
= wxMax(point1
->x
, point2
->x
) + extra
;
521 double bottom
= wxMin(point1
->y
, point2
->y
) - extra
;
522 double top
= wxMax(point1
->y
, point2
->y
) + extra
;
524 if ((x
> left
&& x
< right
&& y
> bottom
&& y
< top
) || inLabelRegion
)
526 // Work out distance from centre of line
527 double centre_x
= (double)(left
+ (right
- left
)/2.0);
528 double centre_y
= (double)(bottom
+ (top
- bottom
)/2.0);
531 *distance
= (double)sqrt((centre_x
- x
)*(centre_x
- x
) + (centre_y
- y
)*(centre_y
- y
));
540 void wxLineShape::DrawArrows(wxDC
& dc
)
542 // Distance along line of each arrow: space them out evenly.
543 double startArrowPos
= 0.0;
544 double endArrowPos
= 0.0;
545 double middleArrowPos
= 0.0;
547 wxNode
*node
= m_arcArrows
.First();
550 wxArrowHead
*arrow
= (wxArrowHead
*)node
->Data();
551 switch (arrow
->GetArrowEnd())
553 case ARROW_POSITION_START
:
555 if ((arrow
->GetXOffset() != 0.0) && !m_ignoreArrowOffsets
)
556 // If specified, x offset is proportional to line length
557 DrawArrow(dc
, arrow
, arrow
->GetXOffset(), TRUE
);
560 DrawArrow(dc
, arrow
, startArrowPos
, FALSE
); // Absolute distance
561 startArrowPos
+= arrow
->GetSize() + arrow
->GetSpacing();
565 case ARROW_POSITION_END
:
567 if ((arrow
->GetXOffset() != 0.0) && !m_ignoreArrowOffsets
)
568 DrawArrow(dc
, arrow
, arrow
->GetXOffset(), TRUE
);
571 DrawArrow(dc
, arrow
, endArrowPos
, FALSE
);
572 endArrowPos
+= arrow
->GetSize() + arrow
->GetSpacing();
576 case ARROW_POSITION_MIDDLE
:
578 arrow
->SetXOffset(middleArrowPos
);
579 if ((arrow
->GetXOffset() != 0.0) && !m_ignoreArrowOffsets
)
580 DrawArrow(dc
, arrow
, arrow
->GetXOffset(), TRUE
);
583 DrawArrow(dc
, arrow
, middleArrowPos
, FALSE
);
584 middleArrowPos
+= arrow
->GetSize() + arrow
->GetSpacing();
593 void wxLineShape::DrawArrow(wxDC
& dc
, wxArrowHead
*arrow
, double xOffset
, bool proportionalOffset
)
595 wxNode
*first_line_node
= m_lineControlPoints
->First();
596 wxRealPoint
*first_line_point
= (wxRealPoint
*)first_line_node
->Data();
597 wxNode
*second_line_node
= first_line_node
->Next();
598 wxRealPoint
*second_line_point
= (wxRealPoint
*)second_line_node
->Data();
600 wxNode
*last_line_node
= m_lineControlPoints
->Last();
601 wxRealPoint
*last_line_point
= (wxRealPoint
*)last_line_node
->Data();
602 wxNode
*second_last_line_node
= last_line_node
->Previous();
603 wxRealPoint
*second_last_line_point
= (wxRealPoint
*)second_last_line_node
->Data();
605 // Position where we want to start drawing
606 double positionOnLineX
, positionOnLineY
;
608 // Position of start point of line, at the end of which we draw the arrow.
609 double startPositionX
, startPositionY
;
611 switch (arrow
->GetPosition())
613 case ARROW_POSITION_START
:
615 // If we're using a proportional offset, calculate just where this will
617 double realOffset
= xOffset
;
618 if (proportionalOffset
)
621 (double)sqrt((second_line_point
->x
- first_line_point
->x
)*(second_line_point
->x
- first_line_point
->x
) +
622 (second_line_point
->y
- first_line_point
->y
)*(second_line_point
->y
- first_line_point
->y
));
623 realOffset
= (double)(xOffset
* totalLength
);
625 GetPointOnLine(second_line_point
->x
, second_line_point
->y
,
626 first_line_point
->x
, first_line_point
->y
,
627 realOffset
, &positionOnLineX
, &positionOnLineY
);
628 startPositionX
= second_line_point
->x
;
629 startPositionY
= second_line_point
->y
;
632 case ARROW_POSITION_END
:
634 // If we're using a proportional offset, calculate just where this will
636 double realOffset
= xOffset
;
637 if (proportionalOffset
)
640 (double)sqrt((second_last_line_point
->x
- last_line_point
->x
)*(second_last_line_point
->x
- last_line_point
->x
) +
641 (second_last_line_point
->y
- last_line_point
->y
)*(second_last_line_point
->y
- last_line_point
->y
));
642 realOffset
= (double)(xOffset
* totalLength
);
644 GetPointOnLine(second_last_line_point
->x
, second_last_line_point
->y
,
645 last_line_point
->x
, last_line_point
->y
,
646 realOffset
, &positionOnLineX
, &positionOnLineY
);
647 startPositionX
= second_last_line_point
->x
;
648 startPositionY
= second_last_line_point
->y
;
651 case ARROW_POSITION_MIDDLE
:
653 // Choose a point half way between the last and penultimate points
654 double x
= ((last_line_point
->x
+ second_last_line_point
->x
)/2);
655 double y
= ((last_line_point
->y
+ second_last_line_point
->y
)/2);
657 // If we're using a proportional offset, calculate just where this will
659 double realOffset
= xOffset
;
660 if (proportionalOffset
)
663 (double)sqrt((second_last_line_point
->x
- x
)*(second_last_line_point
->x
- x
) +
664 (second_last_line_point
->y
- y
)*(second_last_line_point
->y
- y
));
665 realOffset
= (double)(xOffset
* totalLength
);
668 GetPointOnLine(second_last_line_point
->x
, second_last_line_point
->y
,
669 x
, y
, realOffset
, &positionOnLineX
, &positionOnLineY
);
670 startPositionX
= second_last_line_point
->x
;
671 startPositionY
= second_last_line_point
->y
;
677 * Add yOffset to arrow, if any
680 const double myPi
= (double) 3.14159265;
681 // The translation that the y offset may give
684 if ((arrow
->GetYOffset() != 0.0) && !m_ignoreArrowOffsets
)
690 (x1, y1)--------------(x3, y3)------------------(x2, y2)
691 x4 = x3 - d * sin(theta)
692 y4 = y3 + d * cos(theta)
694 Where theta = tan(-1) of (y3-y1)/(x3-x1)
696 double x1
= startPositionX
;
697 double y1
= startPositionY
;
698 double x3
= positionOnLineX
;
699 double y3
= positionOnLineY
;
700 double d
= -arrow
->GetYOffset(); // Negate so +offset is above line
704 theta
= (double)(myPi
/2.0);
706 theta
= (double)atan((y3
-y1
)/(x3
-x1
));
708 double x4
= (double)(x3
- (d
*sin(theta
)));
709 double y4
= (double)(y3
+ (d
*cos(theta
)));
711 deltaX
= x4
- positionOnLineX
;
712 deltaY
= y4
- positionOnLineY
;
715 switch (arrow
->_GetType())
719 double arrowLength
= arrow
->GetSize();
720 double arrowWidth
= (double)(arrowLength
/3.0);
722 double tip_x
, tip_y
, side1_x
, side1_y
, side2_x
, side2_y
;
723 oglGetArrowPoints(startPositionX
+deltaX
, startPositionY
+deltaY
,
724 positionOnLineX
+deltaX
, positionOnLineY
+deltaY
,
725 arrowLength
, arrowWidth
, &tip_x
, &tip_y
,
726 &side1_x
, &side1_y
, &side2_x
, &side2_y
);
729 points
[0].x
= (int) tip_x
; points
[0].y
= (int) tip_y
;
730 points
[1].x
= (int) side1_x
; points
[1].y
= (int) side1_y
;
731 points
[2].x
= (int) side2_x
; points
[2].y
= (int) side2_y
;
732 points
[3].x
= (int) tip_x
; points
[3].y
= (int) tip_y
;
735 dc
.SetBrush(* m_brush
);
736 dc
.DrawPolygon(4, points
);
739 case ARROW_HOLLOW_CIRCLE
:
740 case ARROW_FILLED_CIRCLE
:
742 // Find point on line of centre of circle, which is a radius away
743 // from the end position
744 double diameter
= (double)(arrow
->GetSize());
746 GetPointOnLine(startPositionX
+deltaX
, startPositionY
+deltaY
,
747 positionOnLineX
+deltaX
, positionOnLineY
+deltaY
,
748 (double)(diameter
/2.0),
751 // Convert ellipse centre to top-left coordinates
752 double x1
= (double)(x
- (diameter
/2.0));
753 double y1
= (double)(y
- (diameter
/2.0));
756 if (arrow
->_GetType() == ARROW_HOLLOW_CIRCLE
)
757 dc
.SetBrush(* g_oglWhiteBackgroundBrush
);
759 dc
.SetBrush(* m_brush
);
761 dc
.DrawEllipse((long) x1
, (long) y1
, (long) diameter
, (long) diameter
);
764 case ARROW_SINGLE_OBLIQUE
:
770 if (arrow
->GetMetaFile())
772 // Find point on line of centre of object, which is a half-width away
773 // from the end position
776 * <-- start pos <-----><-- positionOnLineX
778 * --------------| x | <-- e.g. rectangular arrowhead
782 GetPointOnLine(startPositionX
, startPositionY
,
783 positionOnLineX
, positionOnLineY
,
784 (double)(arrow
->GetMetaFile()->m_width
/2.0),
787 // Calculate theta for rotating the metafile.
790 | o(x2, y2) 'o' represents the arrowhead.
795 |______________________
798 double x1
= startPositionX
;
799 double y1
= startPositionY
;
800 double x2
= positionOnLineX
;
801 double y2
= positionOnLineY
;
803 if ((x1
== x2
) && (y1
== y2
))
806 else if ((x1
== x2
) && (y1
> y2
))
807 theta
= (double)(3.0*myPi
/2.0);
809 else if ((x1
== x2
) && (y2
> y1
))
810 theta
= (double)(myPi
/2.0);
812 else if ((x2
> x1
) && (y2
>= y1
))
813 theta
= (double)atan((y2
- y1
)/(x2
- x1
));
816 theta
= (double)(myPi
+ atan((y2
- y1
)/(x2
- x1
)));
818 else if ((x2
> x1
) && (y2
< y1
))
819 theta
= (double)(2*myPi
+ atan((y2
- y1
)/(x2
- x1
)));
823 wxFatalError("Unknown arrowhead rotation case in lines.cc");
826 // Rotate about the centre of the object, then place
827 // the object on the line.
828 if (arrow
->GetMetaFile()->GetRotateable())
829 arrow
->GetMetaFile()->Rotate(0.0, 0.0, theta
);
833 // If erasing, just draw a rectangle.
834 double minX
, minY
, maxX
, maxY
;
835 arrow
->GetMetaFile()->GetBounds(&minX
, &minY
, &maxX
, &maxY
);
836 // Make erasing rectangle slightly bigger or you get droppings.
838 dc
.DrawRectangle((long)(deltaX
+ x
+ minX
- (extraPixels
/2.0)), (long)(deltaY
+ y
+ minY
- (extraPixels
/2.0)),
839 (long)(maxX
- minX
+ extraPixels
), (long)(maxY
- minY
+ extraPixels
));
842 arrow
->GetMetaFile()->Draw(dc
, x
+deltaX
, y
+deltaY
);
852 void wxLineShape::OnErase(wxDC
& dc
)
854 wxPen
*old_pen
= m_pen
;
855 wxBrush
*old_brush
= m_brush
;
856 SetPen(g_oglWhiteBackgroundPen
);
857 SetBrush(g_oglWhiteBackgroundBrush
);
859 double bound_x
, bound_y
;
860 GetBoundingBoxMax(&bound_x
, &bound_y
);
861 if (m_font
) dc
.SetFont(* m_font
);
863 // Undraw text regions
864 for (int i
= 0; i
< 3; i
++)
866 wxNode
*node
= m_regions
.Nth(i
);
870 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
871 GetLabelPosition(i
, &x
, &y
);
872 EraseRegion(dc
, region
, x
, y
);
877 dc
.SetPen(* g_oglWhiteBackgroundPen
);
878 dc
.SetBrush(* g_oglWhiteBackgroundBrush
);
880 // Drawing over the line only seems to work if the line has a thickness
882 if (old_pen
&& (old_pen
->GetWidth() > 1))
884 dc
.DrawRectangle((long)(m_xpos
- (bound_x
/2.0) - 2.0), (long)(m_ypos
- (bound_y
/2.0) - 2.0),
885 (long)(bound_x
+4.0), (long)(bound_y
+4.0));
890 GetEventHandler()->OnDraw(dc
);
891 GetEventHandler()->OnEraseControlPoints(dc
);
895 if (old_pen
) SetPen(old_pen
);
896 if (old_brush
) SetBrush(old_brush
);
899 void wxLineShape::GetBoundingBoxMin(double *w
, double *h
)
906 wxNode
*node
= m_lineControlPoints
->First();
909 wxRealPoint
*point
= (wxRealPoint
*)node
->Data();
911 if (point
->x
< x1
) x1
= point
->x
;
912 if (point
->y
< y1
) y1
= point
->y
;
913 if (point
->x
> x2
) x2
= point
->x
;
914 if (point
->y
> y2
) y2
= point
->y
;
918 *w
= (double)(x2
- x1
);
919 *h
= (double)(y2
- y1
);
923 * For a node image of interest, finds the position of this arc
924 * amongst all the arcs which are attached to THIS SIDE of the node image,
925 * and the number of same.
927 void wxLineShape::FindNth(wxShape
*image
, int *nth
, int *no_arcs
, bool incoming
)
931 wxNode
*node
= image
->GetLines().First();
934 this_attachment
= m_attachmentTo
;
936 this_attachment
= m_attachmentFrom
;
938 // Find number of lines going into/out of this particular attachment point
941 wxLineShape
*line
= (wxLineShape
*)node
->Data();
943 if (line
->m_from
== image
)
945 // This is the nth line attached to 'image'
946 if ((line
== this) && !incoming
)
949 // Increment num count if this is the same side (attachment number)
950 if (line
->m_attachmentFrom
== this_attachment
)
954 if (line
->m_to
== image
)
956 // This is the nth line attached to 'image'
957 if ((line
== this) && incoming
)
960 // Increment num count if this is the same side (attachment number)
961 if (line
->m_attachmentTo
== this_attachment
)
971 void wxLineShape::OnDrawOutline(wxDC
& dc
, double x
, double y
, double w
, double h
)
973 wxPen
*old_pen
= m_pen
;
974 wxBrush
*old_brush
= m_brush
;
976 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
978 SetBrush( wxTRANSPARENT_BRUSH
);
980 GetEventHandler()->OnDraw(dc
);
982 if (old_pen
) SetPen(old_pen
);
984 if (old_brush
) SetBrush(old_brush
);
988 bool wxLineShape::OnMovePre(wxDC
& dc
, double x
, double y
, double old_x
, double old_y
, bool display
)
990 double x_offset
= x
- old_x
;
991 double y_offset
= y
- old_y
;
993 if (m_lineControlPoints
&& !(x_offset
== 0.0 && y_offset
== 0.0))
995 wxNode
*node
= m_lineControlPoints
->First();
998 wxRealPoint
*point
= (wxRealPoint
*)node
->Data();
999 point
->x
+= x_offset
;
1000 point
->y
+= y_offset
;
1001 node
= node
->Next();
1006 // Move temporary label rectangles if necessary
1007 for (int i
= 0; i
< 3; i
++)
1009 if (m_labelObjects
[i
])
1011 m_labelObjects
[i
]->Erase(dc
);
1012 double xp
, yp
, xr
, yr
;
1013 GetLabelPosition(i
, &xp
, &yp
);
1014 wxNode
*node
= m_regions
.Nth(i
);
1017 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
1018 region
->GetPosition(&xr
, &yr
);
1025 m_labelObjects
[i
]->Move(dc
, xp
+xr
, yp
+yr
);
1031 void wxLineShape::OnMoveLink(wxDC
& dc
, bool moveControlPoints
)
1033 if (!m_from
|| !m_to
)
1036 if (m_lineControlPoints
->Number() > 2)
1039 // Do each end - nothing in the middle. User has to move other points
1040 // manually if necessary.
1041 double end_x
, end_y
;
1042 double other_end_x
, other_end_y
;
1044 FindLineEndPoints(&end_x
, &end_y
, &other_end_x
, &other_end_y
);
1046 wxNode
*first
= m_lineControlPoints
->First();
1047 wxRealPoint
*first_point
= (wxRealPoint
*)first
->Data();
1048 wxNode
*last
= m_lineControlPoints
->Last();
1049 wxRealPoint
*last_point
= (wxRealPoint
*)last
->Data();
1051 /* This is redundant, surely? Done by SetEnds.
1052 first_point->x = end_x; first_point->y = end_y;
1053 last_point->x = other_end_x; last_point->y = other_end_y;
1056 double oldX
= m_xpos
;
1057 double oldY
= m_ypos
;
1059 SetEnds(end_x
, end_y
, other_end_x
, other_end_y
);
1061 // Do a second time, because one may depend on the other.
1062 FindLineEndPoints(&end_x
, &end_y
, &other_end_x
, &other_end_y
);
1063 SetEnds(end_x
, end_y
, other_end_x
, other_end_y
);
1065 // Try to move control points with the arc
1066 double x_offset
= m_xpos
- oldX
;
1067 double y_offset
= m_ypos
- oldY
;
1069 // if (moveControlPoints && m_lineControlPoints && !(x_offset == 0.0 && y_offset == 0.0))
1070 // Only move control points if it's a self link. And only works if attachment mode is ON.
1071 if ((m_from
== m_to
) && (m_from
->GetAttachmentMode() != ATTACHMENT_MODE_NONE
) && moveControlPoints
&& m_lineControlPoints
&& !(x_offset
== 0.0 && y_offset
== 0.0))
1073 wxNode
*node
= m_lineControlPoints
->First();
1076 if ((node
!= m_lineControlPoints
->First()) && (node
!= m_lineControlPoints
->Last()))
1078 wxRealPoint
*point
= (wxRealPoint
*)node
->Data();
1079 point
->x
+= x_offset
;
1080 point
->y
+= y_offset
;
1082 node
= node
->Next();
1086 Move(dc
, m_xpos
, m_ypos
);
1089 // Finds the x, y points at the two ends of the line.
1090 // This function can be used by e.g. line-routing routines to
1091 // get the actual points on the two node images where the lines will be drawn
1093 void wxLineShape::FindLineEndPoints(double *fromX
, double *fromY
, double *toX
, double *toY
)
1095 if (!m_from
|| !m_to
)
1098 // Do each end - nothing in the middle. User has to move other points
1099 // manually if necessary.
1100 double end_x
, end_y
;
1101 double other_end_x
, other_end_y
;
1103 wxNode
*first
= m_lineControlPoints
->First();
1104 wxRealPoint
*first_point
= (wxRealPoint
*)first
->Data();
1105 wxNode
*last
= m_lineControlPoints
->Last();
1106 wxRealPoint
*last_point
= (wxRealPoint
*)last
->Data();
1108 wxNode
*second
= first
->Next();
1109 wxRealPoint
*second_point
= (wxRealPoint
*)second
->Data();
1111 wxNode
*second_last
= last
->Previous();
1112 wxRealPoint
*second_last_point
= (wxRealPoint
*)second_last
->Data();
1114 if (m_lineControlPoints
->Number() > 2)
1116 if (m_from
->GetAttachmentMode() != ATTACHMENT_MODE_NONE
)
1119 FindNth(m_from
, &nth
, &no_arcs
, FALSE
); // Not incoming
1120 m_from
->GetAttachmentPosition(m_attachmentFrom
, &end_x
, &end_y
, nth
, no_arcs
, this);
1123 (void) m_from
->GetPerimeterPoint(m_from
->GetX(), m_from
->GetY(),
1124 (double)second_point
->x
, (double)second_point
->y
,
1127 if (m_to
->GetAttachmentMode() != ATTACHMENT_MODE_NONE
)
1130 FindNth(m_to
, &nth
, &no_arcs
, TRUE
); // Incoming
1131 m_to
->GetAttachmentPosition(m_attachmentTo
, &other_end_x
, &other_end_y
, nth
, no_arcs
, this);
1134 (void) m_to
->GetPerimeterPoint(m_to
->GetX(), m_to
->GetY(),
1135 (double)second_last_point
->x
, (double)second_last_point
->y
,
1136 &other_end_x
, &other_end_y
);
1140 double fromX
= m_from
->GetX();
1141 double fromY
= m_from
->GetY();
1142 double toX
= m_to
->GetX();
1143 double toY
= m_to
->GetY();
1145 if (m_from
->GetAttachmentMode() != ATTACHMENT_MODE_NONE
)
1148 FindNth(m_from
, &nth
, &no_arcs
, FALSE
);
1149 m_from
->GetAttachmentPosition(m_attachmentFrom
, &end_x
, &end_y
, nth
, no_arcs
, this);
1154 if (m_to
->GetAttachmentMode() != ATTACHMENT_MODE_NONE
)
1157 FindNth(m_to
, &nth
, &no_arcs
, TRUE
);
1158 m_to
->GetAttachmentPosition(m_attachmentTo
, &other_end_x
, &other_end_y
, nth
, no_arcs
, this);
1163 if (m_from
->GetAttachmentMode() == ATTACHMENT_MODE_NONE
)
1164 (void) m_from
->GetPerimeterPoint(m_from
->GetX(), m_from
->GetY(),
1168 if (m_to
->GetAttachmentMode() == ATTACHMENT_MODE_NONE
)
1169 (void) m_to
->GetPerimeterPoint(m_to
->GetX(), m_to
->GetY(),
1171 &other_end_x
, &other_end_y
);
1179 void wxLineShape::OnDraw(wxDC
& dc
)
1181 if (m_lineControlPoints
)
1186 dc
.SetBrush(* m_brush
);
1188 int n
= m_lineControlPoints
->Number();
1189 wxPoint
*points
= new wxPoint
[n
];
1191 for (i
= 0; i
< n
; i
++)
1193 wxRealPoint
* point
= (wxRealPoint
*) m_lineControlPoints
->Nth(i
)->Data();
1194 points
[i
].x
= WXROUND(point
->x
);
1195 points
[i
].y
= WXROUND(point
->y
);
1199 dc
.DrawSpline(n
, points
);
1201 dc
.DrawLines(n
, points
);
1204 // For some reason, last point isn't drawn under Windows.
1205 dc
.DrawPoint(points
[n
-1]);
1211 // Problem with pen - if not a solid pen, does strange things
1212 // to the arrowhead. So make (get) a new pen that's solid.
1213 if (m_pen
&& (m_pen
->GetStyle() != wxSOLID
))
1216 wxThePenList
->FindOrCreatePen(m_pen
->GetColour(), 1, wxSOLID
);
1218 dc
.SetPen(* solid_pen
);
1224 void wxLineShape::OnDrawControlPoints(wxDC
& dc
)
1229 // Draw temporary label rectangles if necessary
1230 for (int i
= 0; i
< 3; i
++)
1232 if (m_labelObjects
[i
])
1233 m_labelObjects
[i
]->Draw(dc
);
1235 wxShape::OnDrawControlPoints(dc
);
1238 void wxLineShape::OnEraseControlPoints(wxDC
& dc
)
1240 // Erase temporary label rectangles if necessary
1241 for (int i
= 0; i
< 3; i
++)
1243 if (m_labelObjects
[i
])
1244 m_labelObjects
[i
]->Erase(dc
);
1246 wxShape::OnEraseControlPoints(dc
);
1249 void wxLineShape::OnDragLeft(bool draw
, double x
, double y
, int keys
, int attachment
)
1253 void wxLineShape::OnBeginDragLeft(double x
, double y
, int keys
, int attachment
)
1257 void wxLineShape::OnEndDragLeft(double x
, double y
, int keys
, int attachment
)
1262 void wxLineShape::SetArrowSize(double length, double width)
1264 arrow_length = length;
1265 arrow_width = width;
1268 void wxLineShape::SetStartArrow(int style)
1270 start_style = style;
1273 void wxLineShape::SetMiddleArrow(int style)
1275 middle_style = style;
1278 void wxLineShape::SetEndArrow(int style)
1284 void wxLineShape::OnDrawContents(wxDC
& dc
)
1286 if (GetDisableLabel())
1289 for (int i
= 0; i
< 3; i
++)
1291 wxNode
*node
= m_regions
.Nth(i
);
1294 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
1296 GetLabelPosition(i
, &x
, &y
);
1297 DrawRegion(dc
, region
, x
, y
);
1302 void wxLineShape::SetTo(wxShape
*object
)
1307 void wxLineShape::SetFrom(wxShape
*object
)
1312 void wxLineShape::MakeControlPoints()
1314 if (m_canvas
&& m_lineControlPoints
)
1316 wxNode
*first
= m_lineControlPoints
->First();
1317 wxNode
*last
= m_lineControlPoints
->Last();
1318 wxRealPoint
*first_point
= (wxRealPoint
*)first
->Data();
1319 wxRealPoint
*last_point
= (wxRealPoint
*)last
->Data();
1321 wxLineControlPoint
*control
= new wxLineControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
,
1322 first_point
->x
, first_point
->y
,
1323 CONTROL_POINT_ENDPOINT_FROM
);
1324 control
->m_point
= first_point
;
1325 m_canvas
->AddShape(control
);
1326 m_controlPoints
.Append(control
);
1329 wxNode
*node
= first
->Next();
1330 while (node
!= last
)
1332 wxRealPoint
*point
= (wxRealPoint
*)node
->Data();
1334 control
= new wxLineControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
,
1336 CONTROL_POINT_LINE
);
1337 control
->m_point
= point
;
1339 m_canvas
->AddShape(control
);
1340 m_controlPoints
.Append(control
);
1342 node
= node
->Next();
1344 control
= new wxLineControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
,
1345 last_point
->x
, last_point
->y
,
1346 CONTROL_POINT_ENDPOINT_TO
);
1347 control
->m_point
= last_point
;
1348 m_canvas
->AddShape(control
);
1349 m_controlPoints
.Append(control
);
1355 void wxLineShape::ResetControlPoints()
1357 if (m_canvas
&& m_lineControlPoints
&& m_controlPoints
.Number() > 0)
1359 wxNode
*node
= m_controlPoints
.First();
1360 wxNode
*control_node
= m_lineControlPoints
->First();
1361 while (node
&& control_node
)
1363 wxRealPoint
*point
= (wxRealPoint
*)control_node
->Data();
1364 wxLineControlPoint
*control
= (wxLineControlPoint
*)node
->Data();
1365 control
->SetX(point
->x
);
1366 control
->SetY(point
->y
);
1368 node
= node
->Next();
1369 control_node
= control_node
->Next();
1375 void wxLineShape::WriteAttributes(wxExpr
*clause
)
1377 wxShape::WriteAttributes(clause
);
1380 clause
->AddAttributeValue("from", m_from
->GetId());
1382 clause
->AddAttributeValue("to", m_to
->GetId());
1384 if (m_attachmentTo
!= 0)
1385 clause
->AddAttributeValue("attachment_to", (long)m_attachmentTo
);
1386 if (m_attachmentFrom
!= 0)
1387 clause
->AddAttributeValue("attachment_from", (long)m_attachmentFrom
);
1389 if (m_alignmentStart
!= 0)
1390 clause
->AddAttributeValue("align_start", (long)m_alignmentStart
);
1391 if (m_alignmentEnd
!= 0)
1392 clause
->AddAttributeValue("align_end", (long)m_alignmentEnd
);
1394 clause
->AddAttributeValue("is_spline", (long)m_isSpline
);
1395 if (m_maintainStraightLines
)
1396 clause
->AddAttributeValue("keep_lines_straight", (long)m_maintainStraightLines
);
1398 // Make a list of lists for the (sp)line controls
1399 wxExpr
*list
= new wxExpr(wxExprList
);
1400 wxNode
*node
= m_lineControlPoints
->First();
1403 wxRealPoint
*point
= (wxRealPoint
*)node
->Data();
1404 wxExpr
*point_list
= new wxExpr(wxExprList
);
1405 wxExpr
*x_expr
= new wxExpr((double) point
->x
);
1406 wxExpr
*y_expr
= new wxExpr((double) point
->y
);
1407 point_list
->Append(x_expr
);
1408 point_list
->Append(y_expr
);
1409 list
->Append(point_list
);
1411 node
= node
->Next();
1413 clause
->AddAttributeValue("controls", list
);
1415 // Write arc arrows in new OGL format, if there are any.
1416 // This is a list of lists. Each sublist comprises:
1417 // (arrowType arrowEnd xOffset arrowSize)
1418 if (m_arcArrows
.Number() > 0)
1420 wxExpr
*arrow_list
= new wxExpr(wxExprList
);
1421 node
= m_arcArrows
.First();
1424 wxArrowHead
*head
= (wxArrowHead
*)node
->Data();
1425 wxExpr
*head_list
= new wxExpr(wxExprList
);
1426 head_list
->Append(new wxExpr((long)head
->_GetType()));
1427 head_list
->Append(new wxExpr((long)head
->GetArrowEnd()));
1428 head_list
->Append(new wxExpr(head
->GetXOffset()));
1429 head_list
->Append(new wxExpr(head
->GetArrowSize()));
1430 head_list
->Append(new wxExpr(wxExprString
, head
->GetName()));
1431 head_list
->Append(new wxExpr(head
->GetId()));
1433 // New members of wxArrowHead
1434 head_list
->Append(new wxExpr(head
->GetYOffset()));
1435 head_list
->Append(new wxExpr(head
->GetSpacing()));
1437 arrow_list
->Append(head_list
);
1439 node
= node
->Next();
1441 clause
->AddAttributeValue("arrows", arrow_list
);
1445 void wxLineShape::ReadAttributes(wxExpr
*clause
)
1447 wxShape::ReadAttributes(clause
);
1449 int iVal
= (int) m_isSpline
;
1450 clause
->AssignAttributeValue("is_spline", &iVal
);
1451 m_isSpline
= (iVal
!= 0);
1453 iVal
= (int) m_maintainStraightLines
;
1454 clause
->AssignAttributeValue("keep_lines_straight", &iVal
);
1455 m_maintainStraightLines
= (iVal
!= 0);
1457 clause
->AssignAttributeValue("align_start", &m_alignmentStart
);
1458 clause
->AssignAttributeValue("align_end", &m_alignmentEnd
);
1460 // Compatibility: check for no regions.
1461 if (m_regions
.Number() == 0)
1463 wxShapeRegion
*newRegion
= new wxShapeRegion
;
1464 newRegion
->SetName("Middle");
1465 newRegion
->SetSize(150, 50);
1466 m_regions
.Append((wxObject
*)newRegion
);
1467 if (m_text
.Number() > 0)
1469 newRegion
->ClearText();
1470 wxNode
*node
= m_text
.First();
1473 wxShapeTextLine
*textLine
= (wxShapeTextLine
*)node
->Data();
1474 wxNode
*next
= node
->Next();
1475 newRegion
->GetFormattedText().Append((wxObject
*)textLine
);
1481 newRegion
= new wxShapeRegion
;
1482 newRegion
->SetName("Start");
1483 newRegion
->SetSize(150, 50);
1484 m_regions
.Append((wxObject
*)newRegion
);
1486 newRegion
= new wxShapeRegion
;
1487 newRegion
->SetName("End");
1488 newRegion
->SetSize(150, 50);
1489 m_regions
.Append((wxObject
*)newRegion
);
1493 m_attachmentFrom
= 0;
1495 clause
->AssignAttributeValue("attachment_to", &m_attachmentTo
);
1496 clause
->AssignAttributeValue("attachment_from", &m_attachmentFrom
);
1498 wxExpr
*line_list
= NULL
;
1500 // When image is created, there are default control points. Override
1501 // them if there are some in the file.
1502 clause
->AssignAttributeValue("controls", &line_list
);
1506 // Read a list of lists for the spline controls
1507 if (m_lineControlPoints
)
1509 ClearPointList(*m_lineControlPoints
);
1512 m_lineControlPoints
= new wxList
;
1514 wxExpr
*node
= line_list
->value
.first
;
1518 wxExpr
*xexpr
= node
->value
.first
;
1519 double x
= xexpr
->RealValue();
1521 wxExpr
*yexpr
= xexpr
->next
;
1522 double y
= yexpr
->RealValue();
1524 wxRealPoint
*point
= new wxRealPoint(x
, y
);
1525 m_lineControlPoints
->Append((wxObject
*) point
);
1531 // Read arrow list, for new OGL code
1532 wxExpr
*arrow_list
= NULL
;
1534 clause
->AssignAttributeValue("arrows", &arrow_list
);
1537 wxExpr
*node
= arrow_list
->value
.first
;
1541 WXTYPE arrowType
= ARROW_ARROW
;
1543 double xOffset
= 0.0;
1544 double arrowSize
= 0.0;
1545 wxString
arrowName("");
1548 wxExpr
*type_expr
= node
->Nth(0);
1549 wxExpr
*end_expr
= node
->Nth(1);
1550 wxExpr
*dist_expr
= node
->Nth(2);
1551 wxExpr
*size_expr
= node
->Nth(3);
1552 wxExpr
*name_expr
= node
->Nth(4);
1553 wxExpr
*id_expr
= node
->Nth(5);
1555 // New members of wxArrowHead
1556 wxExpr
*yOffsetExpr
= node
->Nth(6);
1557 wxExpr
*spacingExpr
= node
->Nth(7);
1560 arrowType
= (int)type_expr
->IntegerValue();
1562 arrowEnd
= (int)end_expr
->IntegerValue();
1564 xOffset
= dist_expr
->RealValue();
1566 arrowSize
= size_expr
->RealValue();
1568 arrowName
= name_expr
->StringValue();
1570 arrowId
= id_expr
->IntegerValue();
1573 arrowId
= wxNewId();
1575 wxRegisterId(arrowId
);
1577 wxArrowHead
*arrowHead
= AddArrow(arrowType
, arrowEnd
, arrowSize
, xOffset
, (char*) (const char*) arrowName
, NULL
, arrowId
);
1579 arrowHead
->SetYOffset(yOffsetExpr
->RealValue());
1581 arrowHead
->SetSpacing(spacingExpr
->RealValue());
1589 void wxLineShape::Copy(wxShape
& copy
)
1591 wxShape::Copy(copy
);
1593 wxASSERT( copy
.IsKindOf(CLASSINFO(wxLineShape
)) );
1595 wxLineShape
& lineCopy
= (wxLineShape
&) copy
;
1597 lineCopy
.m_to
= m_to
;
1598 lineCopy
.m_from
= m_from
;
1599 lineCopy
.m_attachmentTo
= m_attachmentTo
;
1600 lineCopy
.m_attachmentFrom
= m_attachmentFrom
;
1601 lineCopy
.m_isSpline
= m_isSpline
;
1602 lineCopy
.m_alignmentStart
= m_alignmentStart
;
1603 lineCopy
.m_alignmentEnd
= m_alignmentEnd
;
1604 lineCopy
.m_maintainStraightLines
= m_maintainStraightLines
;
1605 lineCopy
.m_lineOrientations
.Clear();
1607 wxNode
*node
= m_lineOrientations
.First();
1610 lineCopy
.m_lineOrientations
.Append(node
->Data());
1611 node
= node
->Next();
1614 if (lineCopy
.m_lineControlPoints
)
1616 ClearPointList(*lineCopy
.m_lineControlPoints
);
1617 delete lineCopy
.m_lineControlPoints
;
1620 lineCopy
.m_lineControlPoints
= new wxList
;
1622 node
= m_lineControlPoints
->First();
1625 wxRealPoint
*point
= (wxRealPoint
*)node
->Data();
1626 wxRealPoint
*new_point
= new wxRealPoint(point
->x
, point
->y
);
1627 lineCopy
.m_lineControlPoints
->Append((wxObject
*) new_point
);
1628 node
= node
->Next();
1632 lineCopy
.ClearArrowsAtPosition(-1);
1633 node
= m_arcArrows
.First();
1636 wxArrowHead
*arrow
= (wxArrowHead
*)node
->Data();
1637 lineCopy
.m_arcArrows
.Append(new wxArrowHead(*arrow
));
1638 node
= node
->Next();
1642 // Override select, to create/delete temporary label-moving objects
1643 void wxLineShape::Select(bool select
, wxDC
* dc
)
1645 wxShape::Select(select
, dc
);
1648 for (int i
= 0; i
< 3; i
++)
1650 wxNode
*node
= m_regions
.Nth(i
);
1653 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
1654 if (region
->m_formattedText
.Number() > 0)
1656 double w
, h
, x
, y
, xx
, yy
;
1657 region
->GetSize(&w
, &h
);
1658 region
->GetPosition(&x
, &y
);
1659 GetLabelPosition(i
, &xx
, &yy
);
1660 if (m_labelObjects
[i
])
1662 m_labelObjects
[i
]->Select(FALSE
);
1663 m_labelObjects
[i
]->RemoveFromCanvas(m_canvas
);
1664 delete m_labelObjects
[i
];
1666 m_labelObjects
[i
] = OnCreateLabelShape(this, region
, w
, h
);
1667 m_labelObjects
[i
]->AddToCanvas(m_canvas
);
1668 m_labelObjects
[i
]->Show(TRUE
);
1670 m_labelObjects
[i
]->Move(*dc
, (double)(x
+ xx
), (double)(y
+ yy
));
1671 m_labelObjects
[i
]->Select(TRUE
, dc
);
1678 for (int i
= 0; i
< 3; i
++)
1680 if (m_labelObjects
[i
])
1682 m_labelObjects
[i
]->Select(FALSE
, dc
);
1683 m_labelObjects
[i
]->Erase(*dc
);
1684 m_labelObjects
[i
]->RemoveFromCanvas(m_canvas
);
1685 delete m_labelObjects
[i
];
1686 m_labelObjects
[i
] = NULL
;
1693 * Line control point
1697 IMPLEMENT_DYNAMIC_CLASS(wxLineControlPoint
, wxControlPoint
)
1699 wxLineControlPoint::wxLineControlPoint(wxShapeCanvas
*theCanvas
, wxShape
*object
, double size
, double x
, double y
, int the_type
):
1700 wxControlPoint(theCanvas
, object
, size
, x
, y
, the_type
)
1708 wxLineControlPoint::~wxLineControlPoint()
1712 void wxLineControlPoint::OnDraw(wxDC
& dc
)
1714 wxRectangleShape::OnDraw(dc
);
1717 // Implement movement of Line point
1718 void wxLineControlPoint::OnDragLeft(bool draw
, double x
, double y
, int keys
, int attachment
)
1720 m_shape
->GetEventHandler()->OnSizingDragLeft(this, draw
, x
, y
, keys
, attachment
);
1723 void wxLineControlPoint::OnBeginDragLeft(double x
, double y
, int keys
, int attachment
)
1725 m_shape
->GetEventHandler()->OnSizingBeginDragLeft(this, x
, y
, keys
, attachment
);
1728 void wxLineControlPoint::OnEndDragLeft(double x
, double y
, int keys
, int attachment
)
1730 m_shape
->GetEventHandler()->OnSizingEndDragLeft(this, x
, y
, keys
, attachment
);
1733 // Control points ('handles') redirect control to the actual shape, to make it easier
1734 // to override sizing behaviour.
1735 void wxLineShape::OnSizingDragLeft(wxControlPoint
* pt
, bool draw
, double x
, double y
, int keys
, int attachment
)
1737 wxLineControlPoint
* lpt
= (wxLineControlPoint
*) pt
;
1739 wxClientDC
dc(GetCanvas());
1740 GetCanvas()->PrepareDC(dc
);
1742 dc
.SetLogicalFunction(OGLRBLF
);
1744 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
1745 dc
.SetPen(dottedPen
);
1746 dc
.SetBrush((* wxTRANSPARENT_BRUSH
));
1748 if (lpt
->m_type
== CONTROL_POINT_LINE
)
1750 m_canvas
->Snap(&x
, &y
);
1752 lpt
->SetX(x
); lpt
->SetY(y
);
1753 lpt
->m_point
->x
= x
; lpt
->m_point
->y
= y
;
1755 wxLineShape
*lineShape
= (wxLineShape
*)this;
1757 wxPen
*old_pen
= lineShape
->GetPen();
1758 wxBrush
*old_brush
= lineShape
->GetBrush();
1760 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
1761 lineShape
->SetPen(& dottedPen
);
1762 lineShape
->SetBrush(wxTRANSPARENT_BRUSH
);
1764 lineShape
->GetEventHandler()->OnMoveLink(dc
, FALSE
);
1766 lineShape
->SetPen(old_pen
);
1767 lineShape
->SetBrush(old_brush
);
1770 if (lpt
->m_type
== CONTROL_POINT_ENDPOINT_FROM
|| lpt
->m_type
== CONTROL_POINT_ENDPOINT_TO
)
1772 // lpt->SetX(x); lpt->SetY(y);
1777 void wxLineShape::OnSizingBeginDragLeft(wxControlPoint
* pt
, double x
, double y
, int keys
, int attachment
)
1779 wxLineControlPoint
* lpt
= (wxLineControlPoint
*) pt
;
1781 wxClientDC
dc(GetCanvas());
1782 GetCanvas()->PrepareDC(dc
);
1784 wxLineShape
*lineShape
= (wxLineShape
*)this;
1785 if (lpt
->m_type
== CONTROL_POINT_LINE
)
1787 lpt
->m_originalPos
= * (lpt
->m_point
);
1788 m_canvas
->Snap(&x
, &y
);
1792 // Redraw start and end objects because we've left holes
1793 // when erasing the line
1794 lineShape
->GetFrom()->OnDraw(dc
);
1795 lineShape
->GetFrom()->OnDrawContents(dc
);
1796 lineShape
->GetTo()->OnDraw(dc
);
1797 lineShape
->GetTo()->OnDrawContents(dc
);
1799 this->SetDisableLabel(TRUE
);
1800 dc
.SetLogicalFunction(OGLRBLF
);
1802 lpt
->m_xpos
= x
; lpt
->m_ypos
= y
;
1803 lpt
->m_point
->x
= x
; lpt
->m_point
->y
= y
;
1805 wxPen
*old_pen
= lineShape
->GetPen();
1806 wxBrush
*old_brush
= lineShape
->GetBrush();
1808 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
1809 lineShape
->SetPen(& dottedPen
);
1810 lineShape
->SetBrush(wxTRANSPARENT_BRUSH
);
1812 lineShape
->GetEventHandler()->OnMoveLink(dc
, FALSE
);
1814 lineShape
->SetPen(old_pen
);
1815 lineShape
->SetBrush(old_brush
);
1818 if (lpt
->m_type
== CONTROL_POINT_ENDPOINT_FROM
|| lpt
->m_type
== CONTROL_POINT_ENDPOINT_TO
)
1820 m_canvas
->SetCursor(* g_oglBullseyeCursor
);
1821 lpt
->m_oldCursor
= wxSTANDARD_CURSOR
;
1825 void wxLineShape::OnSizingEndDragLeft(wxControlPoint
* pt
, double x
, double y
, int keys
, int attachment
)
1827 wxLineControlPoint
* lpt
= (wxLineControlPoint
*) pt
;
1829 wxClientDC
dc(GetCanvas());
1830 GetCanvas()->PrepareDC(dc
);
1832 this->SetDisableLabel(FALSE
);
1833 wxLineShape
*lineShape
= (wxLineShape
*)this;
1835 if (lpt
->m_type
== CONTROL_POINT_LINE
)
1837 m_canvas
->Snap(&x
, &y
);
1839 wxRealPoint pt
= wxRealPoint(x
, y
);
1841 // Move the control point back to where it was;
1842 // MoveControlPoint will move it to the new position
1843 // if it decides it wants. We only moved the position
1844 // during user feedback so we could redraw the line
1845 // as it changed shape.
1846 lpt
->m_xpos
= lpt
->m_originalPos
.x
; lpt
->m_ypos
= lpt
->m_originalPos
.y
;
1847 lpt
->m_point
->x
= lpt
->m_originalPos
.x
; lpt
->m_point
->y
= lpt
->m_originalPos
.y
;
1849 OnMoveMiddleControlPoint(dc
, lpt
, pt
);
1851 if (lpt
->m_type
== CONTROL_POINT_ENDPOINT_FROM
)
1853 if (lpt
->m_oldCursor
)
1854 m_canvas
->SetCursor(* lpt
->m_oldCursor
);
1858 // lpt->m_xpos = x; lpt->m_ypos = y;
1860 if (lineShape
->GetFrom())
1862 lineShape
->GetFrom()->MoveLineToNewAttachment(dc
, lineShape
, x
, y
);
1865 if (lpt
->m_type
== CONTROL_POINT_ENDPOINT_TO
)
1867 if (lpt
->m_oldCursor
)
1868 m_canvas
->SetCursor(* lpt
->m_oldCursor
);
1870 // lpt->m_xpos = x; lpt->m_ypos = y;
1872 if (lineShape
->GetTo())
1874 lineShape
->GetTo()->MoveLineToNewAttachment(dc
, lineShape
, x
, y
);
1881 for (i
= 0; i
< lineShape
->GetLineControlPoints()->Number(); i
++)
1882 if (((wxRealPoint
*)(lineShape
->GetLineControlPoints()->Nth(i
)->Data())) == lpt
->m_point
)
1885 // N.B. in OnMoveControlPoint, an event handler in Hardy could have deselected
1886 // the line and therefore deleted 'this'. -> GPF, intermittently.
1887 // So assume at this point that we've been blown away.
1889 lineShape
->OnMoveControlPoint(i
+1, x
, y
);
1893 // This is called only when a non-end control point is moved.
1894 bool wxLineShape::OnMoveMiddleControlPoint(wxDC
& dc
, wxLineControlPoint
* lpt
, const wxRealPoint
& pt
)
1896 lpt
->m_xpos
= pt
.x
; lpt
->m_ypos
= pt
.y
;
1897 lpt
->m_point
->x
= pt
.x
; lpt
->m_point
->y
= pt
.y
;
1899 GetEventHandler()->OnMoveLink(dc
);
1904 // Implement movement of endpoint to a new attachment
1905 // OBSOLETE: done by dragging with the left button.
1908 void wxLineControlPoint::OnDragRight(bool draw
, double x
, double y
, int keys
, int attachment
)
1910 if (m_type
== CONTROL_POINT_ENDPOINT_FROM
|| m_type
== CONTROL_POINT_ENDPOINT_TO
)
1912 m_xpos
= x
; m_ypos
= y
;
1916 void wxLineControlPoint::OnBeginDragRight(double x
, double y
, int keys
, int attachment
)
1918 wxClientDC
dc(GetCanvas());
1919 GetCanvas()->PrepareDC(dc
);
1921 wxLineShape
*lineShape
= (wxLineShape
*)m_shape
;
1922 if (m_type
== CONTROL_POINT_ENDPOINT_FROM
|| m_type
== CONTROL_POINT_ENDPOINT_TO
)
1925 lineShape
->GetEventHandler()->OnDraw(dc
);
1926 if (m_type
== CONTROL_POINT_ENDPOINT_FROM
)
1928 lineShape
->GetFrom()->GetEventHandler()->OnDraw(dc
);
1929 lineShape
->GetFrom()->GetEventHandler()->OnDrawContents(dc
);
1933 lineShape
->GetTo()->GetEventHandler()->OnDraw(dc
);
1934 lineShape
->GetTo()->GetEventHandler()->OnDrawContents(dc
);
1936 m_canvas
->SetCursor(g_oglBullseyeCursor
);
1937 m_oldCursor
= wxSTANDARD_CURSOR
;
1941 void wxLineControlPoint::OnEndDragRight(double x
, double y
, int keys
, int attachment
)
1943 wxClientDC
dc(GetCanvas());
1944 GetCanvas()->PrepareDC(dc
);
1946 wxLineShape
*lineShape
= (wxLineShape
*)m_shape
;
1947 if (m_type
== CONTROL_POINT_ENDPOINT_FROM
)
1950 m_canvas
->SetCursor(m_oldCursor
);
1952 m_xpos
= x
; m_ypos
= y
;
1954 if (lineShape
->GetFrom())
1956 lineShape
->GetFrom()->EraseLinks(dc
);
1961 if (lineShape
->GetFrom()->HitTest(x
, y
, &new_attachment
, &distance
))
1962 lineShape
->SetAttachments(new_attachment
, lineShape
->GetAttachmentTo());
1964 lineShape
->GetFrom()->MoveLinks(dc
);
1967 if (m_type
== CONTROL_POINT_ENDPOINT_TO
)
1970 m_canvas
->SetCursor(m_oldCursor
);
1973 m_xpos
= x
; m_ypos
= y
;
1975 if (lineShape
->GetTo())
1977 lineShape
->GetTo()->EraseLinks(dc
);
1981 if (lineShape
->GetTo()->HitTest(x
, y
, &new_attachment
, &distance
))
1982 lineShape
->SetAttachments(lineShape
->GetAttachmentFrom(), new_attachment
);
1984 lineShape
->GetTo()->MoveLinks(dc
);
1988 for (i
= 0; i
< lineShape
->GetLineControlPoints()->Number(); i
++)
1989 if (((wxRealPoint
*)(lineShape
->GetLineControlPoints()->Nth(i
)->Data())) == m_point
)
1991 lineShape
->OnMoveControlPoint(i
+1, x
, y
);
1992 if (!m_canvas
->GetQuickEditMode()) m_canvas
->Redraw(dc
);
1997 * Get the point on the given line (x1, y1) (x2, y2)
1998 * distance 'length' along from the end,
1999 * returned values in x and y
2002 void GetPointOnLine(double x1
, double y1
, double x2
, double y2
,
2003 double length
, double *x
, double *y
)
2005 double l
= (double)sqrt((x2
- x1
)*(x2
- x1
) + (y2
- y1
)*(y2
- y1
));
2010 double i_bar
= (x2
- x1
)/l
;
2011 double j_bar
= (y2
- y1
)/l
;
2013 *x
= (- length
*i_bar
) + x2
;
2014 *y
= (- length
*j_bar
) + y2
;
2017 wxArrowHead
*wxLineShape::AddArrow(WXTYPE type
, int end
, double size
, double xOffset
,
2018 const wxString
& name
, wxPseudoMetaFile
*mf
, long arrowId
)
2020 wxArrowHead
*arrow
= new wxArrowHead(type
, end
, size
, xOffset
, name
, mf
, arrowId
);
2021 m_arcArrows
.Append(arrow
);
2026 * Add arrowhead at a particular position in the arrowhead list.
2028 bool wxLineShape::AddArrowOrdered(wxArrowHead
*arrow
, wxList
& referenceList
, int end
)
2030 wxNode
*refNode
= referenceList
.First();
2031 wxNode
*currNode
= m_arcArrows
.First();
2032 wxString
targetName(arrow
->GetName());
2033 if (!refNode
) return FALSE
;
2035 // First check whether we need to insert in front of list,
2036 // because this arrowhead is the first in the reference
2037 // list and should therefore be first in the current list.
2038 wxArrowHead
*refArrow
= (wxArrowHead
*)refNode
->Data();
2039 if (refArrow
->GetName() == targetName
)
2041 m_arcArrows
.Insert(arrow
);
2045 while (refNode
&& currNode
)
2047 wxArrowHead
*currArrow
= (wxArrowHead
*)currNode
->Data();
2048 refArrow
= (wxArrowHead
*)refNode
->Data();
2050 // Matching: advance current arrow pointer
2051 if ((currArrow
->GetArrowEnd() == end
) &&
2052 (currArrow
->GetName() == refArrow
->GetName()))
2054 currNode
= currNode
->Next(); // Could be NULL now
2056 currArrow
= (wxArrowHead
*)currNode
->Data();
2059 // Check if we're at the correct position in the
2061 if (targetName
== refArrow
->GetName())
2064 m_arcArrows
.Insert(currNode
, arrow
);
2066 m_arcArrows
.Append(arrow
);
2069 refNode
= refNode
->Next();
2071 m_arcArrows
.Append(arrow
);
2075 void wxLineShape::ClearArrowsAtPosition(int end
)
2077 wxNode
*node
= m_arcArrows
.First();
2080 wxArrowHead
*arrow
= (wxArrowHead
*)node
->Data();
2081 wxNode
*next
= node
->Next();
2090 case ARROW_POSITION_START
:
2092 if (arrow
->GetArrowEnd() == ARROW_POSITION_START
)
2099 case ARROW_POSITION_END
:
2101 if (arrow
->GetArrowEnd() == ARROW_POSITION_END
)
2108 case ARROW_POSITION_MIDDLE
:
2110 if (arrow
->GetArrowEnd() == ARROW_POSITION_MIDDLE
)
2122 bool wxLineShape::ClearArrow(const wxString
& name
)
2124 wxNode
*node
= m_arcArrows
.First();
2127 wxArrowHead
*arrow
= (wxArrowHead
*)node
->Data();
2128 if (arrow
->GetName() == name
)
2134 node
= node
->Next();
2140 * Finds an arrowhead at the given position (if -1, any position)
2144 wxArrowHead
*wxLineShape::FindArrowHead(int position
, const wxString
& name
)
2146 wxNode
*node
= m_arcArrows
.First();
2149 wxArrowHead
*arrow
= (wxArrowHead
*)node
->Data();
2150 if (((position
== -1) || (position
== arrow
->GetArrowEnd())) &&
2151 (arrow
->GetName() == name
))
2153 node
= node
->Next();
2158 wxArrowHead
*wxLineShape::FindArrowHead(long arrowId
)
2160 wxNode
*node
= m_arcArrows
.First();
2163 wxArrowHead
*arrow
= (wxArrowHead
*)node
->Data();
2164 if (arrowId
== arrow
->GetId())
2166 node
= node
->Next();
2172 * Deletes an arrowhead at the given position (if -1, any position)
2176 bool wxLineShape::DeleteArrowHead(int position
, const wxString
& name
)
2178 wxNode
*node
= m_arcArrows
.First();
2181 wxArrowHead
*arrow
= (wxArrowHead
*)node
->Data();
2182 if (((position
== -1) || (position
== arrow
->GetArrowEnd())) &&
2183 (arrow
->GetName() == name
))
2189 node
= node
->Next();
2194 // Overloaded DeleteArrowHead: pass arrowhead id.
2195 bool wxLineShape::DeleteArrowHead(long id
)
2197 wxNode
*node
= m_arcArrows
.First();
2200 wxArrowHead
*arrow
= (wxArrowHead
*)node
->Data();
2201 if (arrow
->GetId() == id
)
2207 node
= node
->Next();
2213 * Calculate the minimum width a line
2214 * occupies, for the purposes of drawing lines in tools.
2218 double wxLineShape::FindMinimumWidth()
2220 double minWidth
= 0.0;
2221 wxNode
*node
= m_arcArrows
.First();
2224 wxArrowHead
*arrowHead
= (wxArrowHead
*)node
->Data();
2225 minWidth
+= arrowHead
->GetSize();
2227 minWidth
+= arrowHead
->GetSpacing();
2229 node
= node
->Next();
2231 // We have ABSOLUTE minimum now. So
2232 // scale it to give it reasonable aesthetics
2233 // when drawing with line.
2235 minWidth
= (double)(minWidth
* 1.4);
2239 SetEnds(0.0, 0.0, minWidth
, 0.0);
2245 // Find which position we're talking about at this (x, y).
2246 // Returns ARROW_POSITION_START, ARROW_POSITION_MIDDLE, ARROW_POSITION_END
2247 int wxLineShape::FindLinePosition(double x
, double y
)
2249 double startX
, startY
, endX
, endY
;
2250 GetEnds(&startX
, &startY
, &endX
, &endY
);
2252 // Find distances from centre, start and end. The smallest wins.
2253 double centreDistance
= (double)(sqrt((x
- m_xpos
)*(x
- m_xpos
) + (y
- m_ypos
)*(y
- m_ypos
)));
2254 double startDistance
= (double)(sqrt((x
- startX
)*(x
- startX
) + (y
- startY
)*(y
- startY
)));
2255 double endDistance
= (double)(sqrt((x
- endX
)*(x
- endX
) + (y
- endY
)*(y
- endY
)));
2257 if (centreDistance
< startDistance
&& centreDistance
< endDistance
)
2258 return ARROW_POSITION_MIDDLE
;
2259 else if (startDistance
< endDistance
)
2260 return ARROW_POSITION_START
;
2262 return ARROW_POSITION_END
;
2265 // Set alignment flags
2266 void wxLineShape::SetAlignmentOrientation(bool isEnd
, bool isHoriz
)
2270 if (isHoriz
&& ((m_alignmentEnd
& LINE_ALIGNMENT_HORIZ
) != LINE_ALIGNMENT_HORIZ
))
2271 m_alignmentEnd
|= LINE_ALIGNMENT_HORIZ
;
2272 else if (!isHoriz
&& ((m_alignmentEnd
& LINE_ALIGNMENT_HORIZ
) == LINE_ALIGNMENT_HORIZ
))
2273 m_alignmentEnd
-= LINE_ALIGNMENT_HORIZ
;
2277 if (isHoriz
&& ((m_alignmentStart
& LINE_ALIGNMENT_HORIZ
) != LINE_ALIGNMENT_HORIZ
))
2278 m_alignmentStart
|= LINE_ALIGNMENT_HORIZ
;
2279 else if (!isHoriz
&& ((m_alignmentStart
& LINE_ALIGNMENT_HORIZ
) == LINE_ALIGNMENT_HORIZ
))
2280 m_alignmentStart
-= LINE_ALIGNMENT_HORIZ
;
2284 void wxLineShape::SetAlignmentType(bool isEnd
, int alignType
)
2288 if (alignType
== LINE_ALIGNMENT_TO_NEXT_HANDLE
)
2290 if ((m_alignmentEnd
& LINE_ALIGNMENT_TO_NEXT_HANDLE
) != LINE_ALIGNMENT_TO_NEXT_HANDLE
)
2291 m_alignmentEnd
|= LINE_ALIGNMENT_TO_NEXT_HANDLE
;
2293 else if ((m_alignmentEnd
& LINE_ALIGNMENT_TO_NEXT_HANDLE
) == LINE_ALIGNMENT_TO_NEXT_HANDLE
)
2294 m_alignmentEnd
-= LINE_ALIGNMENT_TO_NEXT_HANDLE
;
2298 if (alignType
== LINE_ALIGNMENT_TO_NEXT_HANDLE
)
2300 if ((m_alignmentStart
& LINE_ALIGNMENT_TO_NEXT_HANDLE
) != LINE_ALIGNMENT_TO_NEXT_HANDLE
)
2301 m_alignmentStart
|= LINE_ALIGNMENT_TO_NEXT_HANDLE
;
2303 else if ((m_alignmentStart
& LINE_ALIGNMENT_TO_NEXT_HANDLE
) == LINE_ALIGNMENT_TO_NEXT_HANDLE
)
2304 m_alignmentStart
-= LINE_ALIGNMENT_TO_NEXT_HANDLE
;
2308 bool wxLineShape::GetAlignmentOrientation(bool isEnd
)
2311 return ((m_alignmentEnd
& LINE_ALIGNMENT_HORIZ
) == LINE_ALIGNMENT_HORIZ
);
2313 return ((m_alignmentStart
& LINE_ALIGNMENT_HORIZ
) == LINE_ALIGNMENT_HORIZ
);
2316 int wxLineShape::GetAlignmentType(bool isEnd
)
2319 return (m_alignmentEnd
& LINE_ALIGNMENT_TO_NEXT_HANDLE
);
2321 return (m_alignmentStart
& LINE_ALIGNMENT_TO_NEXT_HANDLE
);
2324 wxRealPoint
*wxLineShape::GetNextControlPoint(wxShape
*nodeObject
)
2326 int n
= m_lineControlPoints
->Number();
2328 if (m_to
== nodeObject
)
2330 // Must be END of line, so we want (n - 1)th control point.
2331 // But indexing ends at n-1, so subtract 2.
2335 wxNode
*node
= m_lineControlPoints
->Nth(nn
);
2338 return (wxRealPoint
*)node
->Data();
2349 IMPLEMENT_DYNAMIC_CLASS(wxArrowHead
, wxObject
)
2351 wxArrowHead::wxArrowHead(WXTYPE type
, int end
, double size
, double dist
, const wxString
& name
,
2352 wxPseudoMetaFile
*mf
, long arrowId
)
2354 m_arrowType
= type
; m_arrowEnd
= end
; m_arrowSize
= size
;
2366 wxArrowHead::wxArrowHead(wxArrowHead
& toCopy
)
2368 m_arrowType
= toCopy
.m_arrowType
; m_arrowEnd
= toCopy
.GetArrowEnd();
2369 m_arrowSize
= toCopy
.m_arrowSize
;
2370 m_xOffset
= toCopy
.m_xOffset
;
2371 m_yOffset
= toCopy
.m_yOffset
;
2372 m_spacing
= toCopy
.m_spacing
;
2373 m_arrowName
= toCopy
.m_arrowName
;
2374 if (toCopy
.m_metaFile
)
2375 m_metaFile
= new wxPseudoMetaFile(*(toCopy
.m_metaFile
));
2381 wxArrowHead::~wxArrowHead()
2383 if (m_metaFile
) delete m_metaFile
;
2386 void wxArrowHead::SetSize(double size
)
2389 if ((m_arrowType
== ARROW_METAFILE
) && m_metaFile
)
2391 double oldWidth
= m_metaFile
->m_width
;
2392 if (oldWidth
== 0.0)
2395 double scale
= (double)(size
/oldWidth
);
2397 m_metaFile
->Scale(scale
, scale
);
2401 // Can override this to create a different class of label shape
2402 wxLabelShape
* wxLineShape::OnCreateLabelShape(wxLineShape
*parent
, wxShapeRegion
*region
, double w
, double h
)
2404 return new wxLabelShape(parent
, region
, w
, h
);
2412 IMPLEMENT_DYNAMIC_CLASS(wxLabelShape
, wxRectangleShape
)
2414 wxLabelShape::wxLabelShape(wxLineShape
*parent
, wxShapeRegion
*region
, double w
, double h
):wxRectangleShape(w
, h
)
2416 m_lineShape
= parent
;
2417 m_shapeRegion
= region
;
2418 SetPen(wxThePenList
->FindOrCreatePen(wxColour(0, 0, 0), 1, wxDOT
));
2421 wxLabelShape::~wxLabelShape()
2425 void wxLabelShape::OnDraw(wxDC
& dc
)
2427 if (m_lineShape
&& !m_lineShape
->GetDrawHandles())
2430 double x1
= (double)(m_xpos
- m_width
/2.0);
2431 double y1
= (double)(m_ypos
- m_height
/2.0);
2435 if (m_pen
->GetWidth() == 0)
2436 dc
.SetPen(* g_oglTransparentPen
);
2440 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
2442 if (m_cornerRadius
> 0.0)
2443 dc
.DrawRoundedRectangle(WXROUND(x1
), WXROUND(y1
), WXROUND(m_width
), WXROUND(m_height
), m_cornerRadius
);
2445 dc
.DrawRectangle(WXROUND(x1
), WXROUND(y1
), WXROUND(m_width
), WXROUND(m_height
));
2448 void wxLabelShape::OnDrawContents(wxDC
& dc
)
2452 void wxLabelShape::OnDragLeft(bool draw
, double x
, double y
, int keys
, int attachment
)
2454 wxRectangleShape::OnDragLeft(draw
, x
, y
, keys
, attachment
);
2457 void wxLabelShape::OnBeginDragLeft(double x
, double y
, int keys
, int attachment
)
2459 wxRectangleShape::OnBeginDragLeft(x
, y
, keys
, attachment
);
2462 void wxLabelShape::OnEndDragLeft(double x
, double y
, int keys
, int attachment
)
2464 wxRectangleShape::OnEndDragLeft(x
, y
, keys
, attachment
);
2467 bool wxLabelShape::OnMovePre(wxDC
& dc
, double x
, double y
, double old_x
, double old_y
, bool display
)
2469 return m_lineShape
->OnLabelMovePre(dc
, this, x
, y
, old_x
, old_y
, display
);
2472 bool wxLineShape::OnLabelMovePre(wxDC
& dc
, wxLabelShape
* labelShape
, double x
, double y
, double old_x
, double old_y
, bool display
)
2474 labelShape
->m_shapeRegion
->SetSize(labelShape
->GetWidth(), labelShape
->GetHeight());
2476 // Find position in line's region list
2478 wxNode
*node
= GetRegions().First();
2481 if (labelShape
->m_shapeRegion
== (wxShapeRegion
*)node
->Data())
2485 node
= node
->Next();
2490 GetLabelPosition(i
, &xx
, &yy
);
2491 // Set the region's offset, relative to the default position for
2493 labelShape
->m_shapeRegion
->SetPosition((double)(x
- xx
), (double)(y
- yy
));
2495 labelShape
->SetX(x
);
2496 labelShape
->SetY(y
);
2498 // Need to reformat to fit region.
2499 if (labelShape
->m_shapeRegion
->GetText())
2502 wxString
s(labelShape
->m_shapeRegion
->GetText());
2503 labelShape
->FormatText(dc
, s
, i
);
2504 DrawRegion(dc
, labelShape
->m_shapeRegion
, xx
, yy
);
2509 // Divert left and right clicks to line object
2510 void wxLabelShape::OnLeftClick(double x
, double y
, int keys
, int attachment
)
2512 m_lineShape
->GetEventHandler()->OnLeftClick(x
, y
, keys
, attachment
);
2515 void wxLabelShape::OnRightClick(double x
, double y
, int keys
, int attachment
)
2517 m_lineShape
->GetEventHandler()->OnRightClick(x
, y
, keys
, attachment
);