1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxLineShape
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "lines.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include <wx/wxprec.h>
28 #include <wx/wxexpr.h>
49 IMPLEMENT_DYNAMIC_CLASS(wxLineShape
, wxShape
)
51 wxLineShape::wxLineShape()
53 m_sensitivity
= OP_CLICK_LEFT
| OP_CLICK_RIGHT
;
58 m_actualTextWidth = 0.0;
59 m_actualTextHeight = 0.0;
64 m_arrowSpacing
= 5.0; // For the moment, don't bother saving this to file.
65 m_ignoreArrowOffsets
= FALSE
;
67 m_maintainStraightLines
= FALSE
;
71 m_lineControlPoints
= NULL
;
73 // Clear any existing regions (created in an earlier constructor)
74 // and make the three line regions.
76 wxShapeRegion
*newRegion
= new wxShapeRegion
;
77 newRegion
->SetName("Middle");
78 newRegion
->SetSize(150, 50);
79 m_regions
.Append((wxObject
*)newRegion
);
81 newRegion
= new wxShapeRegion
;
82 newRegion
->SetName("Start");
83 newRegion
->SetSize(150, 50);
84 m_regions
.Append((wxObject
*)newRegion
);
86 newRegion
= new wxShapeRegion
;
87 newRegion
->SetName("End");
88 newRegion
->SetSize(150, 50);
89 m_regions
.Append((wxObject
*)newRegion
);
91 for (int i
= 0; i
< 3; i
++)
92 m_labelObjects
[i
] = NULL
;
95 wxLineShape::~wxLineShape()
97 if (m_lineControlPoints
)
99 ClearPointList(*m_lineControlPoints
);
100 delete m_lineControlPoints
;
102 for (int i
= 0; i
< 3; i
++)
104 if (m_labelObjects
[i
])
106 m_labelObjects
[i
]->Select(FALSE
);
107 m_labelObjects
[i
]->RemoveFromCanvas(m_canvas
);
108 delete m_labelObjects
[i
];
109 m_labelObjects
[i
] = NULL
;
112 ClearArrowsAtPosition(-1);
115 void wxLineShape::MakeLineControlPoints(int n
)
117 if (m_lineControlPoints
)
119 ClearPointList(*m_lineControlPoints
);
120 delete m_lineControlPoints
;
122 m_lineControlPoints
= new wxList
;
125 for (i
= 0; i
< n
; i
++)
127 wxRealPoint
*point
= new wxRealPoint(-999, -999);
128 m_lineControlPoints
->Append((wxObject
*) point
);
132 wxNode
*wxLineShape::InsertLineControlPoint(wxDC
* dc
)
137 wxNode
*last
= m_lineControlPoints
->Last();
138 wxNode
*second_last
= last
->Previous();
139 wxRealPoint
*last_point
= (wxRealPoint
*)last
->Data();
140 wxRealPoint
*second_last_point
= (wxRealPoint
*)second_last
->Data();
142 // Choose a point half way between the last and penultimate points
143 double line_x
= ((last_point
->x
+ second_last_point
->x
)/2);
144 double line_y
= ((last_point
->y
+ second_last_point
->y
)/2);
146 wxRealPoint
*point
= new wxRealPoint(line_x
, line_y
);
147 wxNode
*node
= m_lineControlPoints
->Insert(last
, (wxObject
*) point
);
151 bool wxLineShape::DeleteLineControlPoint()
153 if (m_lineControlPoints
->Number() < 3)
156 wxNode
*last
= m_lineControlPoints
->Last();
157 wxNode
*second_last
= last
->Previous();
159 wxRealPoint
*second_last_point
= (wxRealPoint
*)second_last
->Data();
160 delete second_last_point
;
166 void wxLineShape::Initialise()
168 if (m_lineControlPoints
)
170 // Just move the first and last control points
171 wxNode
*first
= m_lineControlPoints
->First();
172 wxRealPoint
*first_point
= (wxRealPoint
*)first
->Data();
174 wxNode
*last
= m_lineControlPoints
->Last();
175 wxRealPoint
*last_point
= (wxRealPoint
*)last
->Data();
177 // If any of the line points are at -999, we must
178 // initialize them by placing them half way between the first
180 wxNode
*node
= first
->Next();
183 wxRealPoint
*point
= (wxRealPoint
*)node
->Data();
184 if (point
->x
== -999)
186 double x1
, y1
, x2
, y2
;
187 if (first_point
->x
< last_point
->x
)
188 { x1
= first_point
->x
; x2
= last_point
->x
; }
190 { x2
= first_point
->x
; x1
= last_point
->x
; }
192 if (first_point
->y
< last_point
->y
)
193 { y1
= first_point
->y
; y2
= last_point
->y
; }
195 { y2
= first_point
->y
; y1
= last_point
->y
; }
197 point
->x
= ((x2
- x1
)/2 + x1
);
198 point
->y
= ((y2
- y1
)/2 + y1
);
205 // Format a text string according to the region size, adding
206 // strings with positions to region text list
207 void wxLineShape::FormatText(wxDC
& dc
, const wxString
& s
, int i
)
212 if (m_regions
.Number() < 1)
214 wxNode
*node
= m_regions
.Nth(i
);
218 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
220 dc
.SetFont(region
->GetFont());
222 region
->GetSize(&w
, &h
);
223 // Initialize the size if zero
224 if (((w
== 0) || (h
== 0)) && (strlen(s
) > 0))
227 region
->SetSize(w
, h
);
230 wxStringList
*string_list
= oglFormatText(dc
, s
, (w
-5), (h
-5), region
->GetFormatMode());
231 node
= string_list
->First();
234 char *s
= (char *)node
->Data();
235 wxShapeTextLine
*line
= new wxShapeTextLine(0.0, 0.0, s
);
236 region
->GetFormattedText().Append((wxObject
*)line
);
242 if (region
->GetFormatMode() & FORMAT_SIZE_TO_CONTENTS
)
244 oglGetCentredTextExtent(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, w
, h
, &actualW
, &actualH
);
245 if ((actualW
!= w
) || (actualH
!= h
))
248 GetLabelPosition(i
, &xx
, &yy
);
249 EraseRegion(dc
, region
, xx
, yy
);
250 if (m_labelObjects
[i
])
252 m_labelObjects
[i
]->Select(FALSE
, &dc
);
253 m_labelObjects
[i
]->Erase(dc
);
254 m_labelObjects
[i
]->SetSize(actualW
, actualH
);
257 region
->SetSize(actualW
, actualH
);
259 if (m_labelObjects
[i
])
261 m_labelObjects
[i
]->Select(TRUE
, & dc
);
262 m_labelObjects
[i
]->Draw(dc
);
266 oglCentreText(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, actualW
, actualH
, region
->GetFormatMode());
270 void wxLineShape::DrawRegion(wxDC
& dc
, wxShapeRegion
*region
, double x
, double y
)
272 if (GetDisableLabel())
277 region
->GetSize(&w
, &h
);
279 // Get offset from x, y
280 region
->GetPosition(&xx
, &yy
);
285 // First, clear a rectangle for the text IF there is any
286 if (region
->GetFormattedText().Number() > 0)
288 dc
.SetPen(g_oglWhiteBackgroundPen
);
289 dc
.SetBrush(g_oglWhiteBackgroundBrush
);
292 if (region
->GetFont()) dc
.SetFont(region
->GetFont());
294 dc
.DrawRectangle((double)(xp
- w
/2.0), (double)(yp
- h
/2.0), (double)w
, (double)h
);
296 if (m_pen
) dc
.SetPen(m_pen
);
297 dc
.SetTextForeground(* region
->GetActualColourObject());
300 dc
.SetTextBackground(g_oglWhiteBackgroundBrush
->GetColour());
303 oglDrawFormattedText(dc
, &(region
->GetFormattedText()), xp
, yp
, w
, h
, region
->GetFormatMode());
307 void wxLineShape::EraseRegion(wxDC
& dc
, wxShapeRegion
*region
, double x
, double y
)
309 if (GetDisableLabel())
314 region
->GetSize(&w
, &h
);
316 // Get offset from x, y
317 region
->GetPosition(&xx
, &yy
);
322 if (region
->GetFormattedText().Number() > 0)
324 dc
.SetPen(g_oglWhiteBackgroundPen
);
325 dc
.SetBrush(g_oglWhiteBackgroundBrush
);
327 dc
.DrawRectangle((double)(xp
- w
/2.0), (double)(yp
- h
/2.0), (double)w
, (double)h
);
331 // Get the reference point for a label. Region x and y
332 // are offsets from this.
333 // position is 0, 1, 2
334 void wxLineShape::GetLabelPosition(int position
, double *x
, double *y
)
340 // Want to take the middle section for the label
341 int n
= m_lineControlPoints
->Number();
342 int half_way
= (int)(n
/2);
344 // Find middle of this line
345 wxNode
*node
= m_lineControlPoints
->Nth(half_way
- 1);
346 wxRealPoint
*point
= (wxRealPoint
*)node
->Data();
347 wxNode
*next_node
= node
->Next();
348 wxRealPoint
*next_point
= (wxRealPoint
*)next_node
->Data();
350 double dx
= (next_point
->x
- point
->x
);
351 double dy
= (next_point
->y
- point
->y
);
352 *x
= (double)(point
->x
+ dx
/2.0);
353 *y
= (double)(point
->y
+ dy
/2.0);
358 wxNode
*node
= m_lineControlPoints
->First();
359 *x
= ((wxRealPoint
*)node
->Data())->x
;
360 *y
= ((wxRealPoint
*)node
->Data())->y
;
365 wxNode
*node
= m_lineControlPoints
->Last();
366 *x
= ((wxRealPoint
*)node
->Data())->x
;
367 *y
= ((wxRealPoint
*)node
->Data())->y
;
376 * Find whether line is supposed to be vertical or horizontal and
380 void GraphicsStraightenLine(wxRealPoint
*point1
, wxRealPoint
*point2
)
382 double dx
= point2
->x
- point1
->x
;
383 double dy
= point2
->y
- point1
->y
;
387 else if (fabs(dy
/dx
) > 1.0)
389 point2
->x
= point1
->x
;
391 else point2
->y
= point1
->y
;
394 void wxLineShape::Straighten(wxDC
*dc
)
396 if (!m_lineControlPoints
|| m_lineControlPoints
->Number() < 3)
402 wxNode
*first_point_node
= m_lineControlPoints
->First();
403 wxNode
*last_point_node
= m_lineControlPoints
->Last();
404 wxNode
*second_last_point_node
= last_point_node
->Previous();
406 wxRealPoint
*last_point
= (wxRealPoint
*)last_point_node
->Data();
407 wxRealPoint
*second_last_point
= (wxRealPoint
*)second_last_point_node
->Data();
409 GraphicsStraightenLine(last_point
, second_last_point
);
411 wxNode
*node
= first_point_node
;
412 while (node
&& (node
!= second_last_point_node
))
414 wxRealPoint
*point
= (wxRealPoint
*)node
->Data();
415 wxRealPoint
*next_point
= (wxRealPoint
*)(node
->Next()->Data());
417 GraphicsStraightenLine(point
, next_point
);
426 void wxLineShape::Unlink()
429 m_to
->GetLines().DeleteObject(this);
431 m_from
->GetLines().DeleteObject(this);
436 void wxLineShape::SetEnds(double x1
, double y1
, double x2
, double y2
)
439 wxNode
*first_point_node
= m_lineControlPoints
->First();
440 wxNode
*last_point_node
= m_lineControlPoints
->Last();
441 wxRealPoint
*first_point
= (wxRealPoint
*)first_point_node
->Data();
442 wxRealPoint
*last_point
= (wxRealPoint
*)last_point_node
->Data();
449 m_xpos
= (double)((x1
+ x2
)/2.0);
450 m_ypos
= (double)((y1
+ y2
)/2.0);
453 // Get absolute positions of ends
454 void wxLineShape::GetEnds(double *x1
, double *y1
, double *x2
, double *y2
)
456 wxNode
*first_point_node
= m_lineControlPoints
->First();
457 wxNode
*last_point_node
= m_lineControlPoints
->Last();
458 wxRealPoint
*first_point
= (wxRealPoint
*)first_point_node
->Data();
459 wxRealPoint
*last_point
= (wxRealPoint
*)last_point_node
->Data();
461 *x1
= first_point
->x
; *y1
= first_point
->y
;
462 *x2
= last_point
->x
; *y2
= last_point
->y
;
465 void wxLineShape::SetAttachments(int from_attach
, int to_attach
)
467 m_attachmentFrom
= from_attach
;
468 m_attachmentTo
= to_attach
;
471 bool wxLineShape::HitTest(double x
, double y
, int *attachment
, double *distance
)
473 if (!m_lineControlPoints
)
476 // Look at label regions in case mouse is over a label
477 bool inLabelRegion
= FALSE
;
478 for (int i
= 0; i
< 3; i
++)
480 wxNode
*regionNode
= m_regions
.Nth(i
);
483 wxShapeRegion
*region
= (wxShapeRegion
*)regionNode
->Data();
484 if (region
->m_formattedText
.Number() > 0)
486 double xp
, yp
, cx
, cy
, cw
, ch
;
487 GetLabelPosition(i
, &xp
, &yp
);
488 // Offset region from default label position
489 region
->GetPosition(&cx
, &cy
);
490 region
->GetSize(&cw
, &ch
);
493 double rLeft
= (double)(cx
- (cw
/2.0));
494 double rTop
= (double)(cy
- (ch
/2.0));
495 double rRight
= (double)(cx
+ (cw
/2.0));
496 double rBottom
= (double)(cy
+ (ch
/2.0));
497 if (x
> rLeft
&& x
< rRight
&& y
> rTop
&& y
< rBottom
)
499 inLabelRegion
= TRUE
;
506 wxNode
*node
= m_lineControlPoints
->First();
508 while (node
&& node
->Next())
510 wxRealPoint
*point1
= (wxRealPoint
*)node
->Data();
511 wxRealPoint
*point2
= (wxRealPoint
*)node
->Next()->Data();
513 // Allow for inaccurate mousing or vert/horiz lines
515 double left
= wxMin(point1
->x
, point2
->x
) - extra
;
516 double right
= wxMax(point1
->x
, point2
->x
) + extra
;
518 double bottom
= wxMin(point1
->y
, point2
->y
) - extra
;
519 double top
= wxMax(point1
->y
, point2
->y
) + extra
;
521 if ((x
> left
&& x
< right
&& y
> bottom
&& y
< top
) || inLabelRegion
)
523 // Work out distance from centre of line
524 double centre_x
= (double)(left
+ (right
- left
)/2.0);
525 double centre_y
= (double)(bottom
+ (top
- bottom
)/2.0);
528 *distance
= (double)sqrt((centre_x
- x
)*(centre_x
- x
) + (centre_y
- y
)*(centre_y
- y
));
537 void wxLineShape::DrawArrows(wxDC
& dc
)
539 // Distance along line of each arrow: space them out evenly.
540 double startArrowPos
= 0.0;
541 double endArrowPos
= 0.0;
542 double middleArrowPos
= 0.0;
544 wxNode
*node
= m_arcArrows
.First();
547 wxArrowHead
*arrow
= (wxArrowHead
*)node
->Data();
548 switch (arrow
->GetArrowEnd())
550 case ARROW_POSITION_START
:
552 if ((arrow
->GetXOffset() != 0.0) && !m_ignoreArrowOffsets
)
553 // If specified, x offset is proportional to line length
554 DrawArrow(dc
, arrow
, arrow
->GetXOffset(), TRUE
);
557 DrawArrow(dc
, arrow
, startArrowPos
, FALSE
); // Absolute distance
558 startArrowPos
+= arrow
->GetSize() + arrow
->GetSpacing();
562 case ARROW_POSITION_END
:
564 if ((arrow
->GetXOffset() != 0.0) && !m_ignoreArrowOffsets
)
565 DrawArrow(dc
, arrow
, arrow
->GetXOffset(), TRUE
);
568 DrawArrow(dc
, arrow
, endArrowPos
, FALSE
);
569 endArrowPos
+= arrow
->GetSize() + arrow
->GetSpacing();
573 case ARROW_POSITION_MIDDLE
:
575 arrow
->SetXOffset(middleArrowPos
);
576 if ((arrow
->GetXOffset() != 0.0) && !m_ignoreArrowOffsets
)
577 DrawArrow(dc
, arrow
, arrow
->GetXOffset(), TRUE
);
580 DrawArrow(dc
, arrow
, middleArrowPos
, FALSE
);
581 middleArrowPos
+= arrow
->GetSize() + arrow
->GetSpacing();
590 void wxLineShape::DrawArrow(wxDC
& dc
, wxArrowHead
*arrow
, double xOffset
, bool proportionalOffset
)
592 wxNode
*first_line_node
= m_lineControlPoints
->First();
593 wxRealPoint
*first_line_point
= (wxRealPoint
*)first_line_node
->Data();
594 wxNode
*second_line_node
= first_line_node
->Next();
595 wxRealPoint
*second_line_point
= (wxRealPoint
*)second_line_node
->Data();
597 wxNode
*last_line_node
= m_lineControlPoints
->Last();
598 wxRealPoint
*last_line_point
= (wxRealPoint
*)last_line_node
->Data();
599 wxNode
*second_last_line_node
= last_line_node
->Previous();
600 wxRealPoint
*second_last_line_point
= (wxRealPoint
*)second_last_line_node
->Data();
602 // Position where we want to start drawing
603 double positionOnLineX
, positionOnLineY
;
605 // Position of start point of line, at the end of which we draw the arrow.
606 double startPositionX
, startPositionY
;
608 switch (arrow
->GetPosition())
610 case ARROW_POSITION_START
:
612 // If we're using a proportional offset, calculate just where this will
614 double realOffset
= xOffset
;
615 if (proportionalOffset
)
618 (double)sqrt((second_line_point
->x
- first_line_point
->x
)*(second_line_point
->x
- first_line_point
->x
) +
619 (second_line_point
->y
- first_line_point
->y
)*(second_line_point
->y
- first_line_point
->y
));
620 realOffset
= (double)(xOffset
* totalLength
);
622 GetPointOnLine(second_line_point
->x
, second_line_point
->y
,
623 first_line_point
->x
, first_line_point
->y
,
624 realOffset
, &positionOnLineX
, &positionOnLineY
);
625 startPositionX
= second_line_point
->x
;
626 startPositionY
= second_line_point
->y
;
629 case ARROW_POSITION_END
:
631 // If we're using a proportional offset, calculate just where this will
633 double realOffset
= xOffset
;
634 if (proportionalOffset
)
637 (double)sqrt((second_last_line_point
->x
- last_line_point
->x
)*(second_last_line_point
->x
- last_line_point
->x
) +
638 (second_last_line_point
->y
- last_line_point
->y
)*(second_last_line_point
->y
- last_line_point
->y
));
639 realOffset
= (double)(xOffset
* totalLength
);
641 GetPointOnLine(second_last_line_point
->x
, second_last_line_point
->y
,
642 last_line_point
->x
, last_line_point
->y
,
643 realOffset
, &positionOnLineX
, &positionOnLineY
);
644 startPositionX
= second_last_line_point
->x
;
645 startPositionY
= second_last_line_point
->y
;
648 case ARROW_POSITION_MIDDLE
:
650 // Choose a point half way between the last and penultimate points
651 double x
= ((last_line_point
->x
+ second_last_line_point
->x
)/2);
652 double y
= ((last_line_point
->y
+ second_last_line_point
->y
)/2);
654 // If we're using a proportional offset, calculate just where this will
656 double realOffset
= xOffset
;
657 if (proportionalOffset
)
660 (double)sqrt((second_last_line_point
->x
- x
)*(second_last_line_point
->x
- x
) +
661 (second_last_line_point
->y
- y
)*(second_last_line_point
->y
- y
));
662 realOffset
= (double)(xOffset
* totalLength
);
665 GetPointOnLine(second_last_line_point
->x
, second_last_line_point
->y
,
666 x
, y
, realOffset
, &positionOnLineX
, &positionOnLineY
);
667 startPositionX
= second_last_line_point
->x
;
668 startPositionY
= second_last_line_point
->y
;
674 * Add yOffset to arrow, if any
677 const double myPi
= (double) 3.14159265;
678 // The translation that the y offset may give
681 if ((arrow
->GetYOffset() != 0.0) && !m_ignoreArrowOffsets
)
687 (x1, y1)--------------(x3, y3)------------------(x2, y2)
688 x4 = x3 - d * sin(theta)
689 y4 = y3 + d * cos(theta)
691 Where theta = tan(-1) of (y3-y1)/(x3-x1)
693 double x1
= startPositionX
;
694 double y1
= startPositionY
;
695 double x3
= positionOnLineX
;
696 double y3
= positionOnLineY
;
697 double d
= -arrow
->GetYOffset(); // Negate so +offset is above line
701 theta
= (double)(myPi
/2.0);
703 theta
= (double)atan((y3
-y1
)/(x3
-x1
));
705 double x4
= (double)(x3
- (d
*sin(theta
)));
706 double y4
= (double)(y3
+ (d
*cos(theta
)));
708 deltaX
= x4
- positionOnLineX
;
709 deltaY
= y4
- positionOnLineY
;
712 switch (arrow
->_GetType())
716 double arrowLength
= arrow
->GetSize();
717 double arrowWidth
= (double)(arrowLength
/3.0);
719 double tip_x
, tip_y
, side1_x
, side1_y
, side2_x
, side2_y
;
720 oglGetArrowPoints(startPositionX
+deltaX
, startPositionY
+deltaY
,
721 positionOnLineX
+deltaX
, positionOnLineY
+deltaY
,
722 arrowLength
, arrowWidth
, &tip_x
, &tip_y
,
723 &side1_x
, &side1_y
, &side2_x
, &side2_y
);
726 points
[0].x
= tip_x
; points
[0].y
= tip_y
;
727 points
[1].x
= side1_x
; points
[1].y
= side1_y
;
728 points
[2].x
= side2_x
; points
[2].y
= side2_y
;
729 points
[3].x
= tip_x
; points
[3].y
= tip_y
;
732 dc
.SetBrush(m_brush
);
733 dc
.DrawPolygon(4, points
);
736 case ARROW_HOLLOW_CIRCLE
:
737 case ARROW_FILLED_CIRCLE
:
739 // Find point on line of centre of circle, which is a radius away
740 // from the end position
741 double diameter
= (double)(arrow
->GetSize());
743 GetPointOnLine(startPositionX
+deltaX
, startPositionY
+deltaY
,
744 positionOnLineX
+deltaX
, positionOnLineY
+deltaY
,
745 (double)(diameter
/2.0),
748 // Convert ellipse centre to top-left coordinates
749 double x1
= (double)(x
- (diameter
/2.0));
750 double y1
= (double)(y
- (diameter
/2.0));
753 if (arrow
->_GetType() == ARROW_HOLLOW_CIRCLE
)
754 dc
.SetBrush(g_oglWhiteBackgroundBrush
);
756 dc
.SetBrush(m_brush
);
758 dc
.DrawEllipse(x1
, y1
, diameter
, diameter
);
761 case ARROW_SINGLE_OBLIQUE
:
767 if (arrow
->GetMetaFile())
769 // Find point on line of centre of object, which is a half-width away
770 // from the end position
773 * <-- start pos <-----><-- positionOnLineX
775 * --------------| x | <-- e.g. rectangular arrowhead
779 GetPointOnLine(startPositionX
, startPositionY
,
780 positionOnLineX
, positionOnLineY
,
781 (double)(arrow
->GetMetaFile()->m_width
/2.0),
784 // Calculate theta for rotating the metafile.
787 | o(x2, y2) 'o' represents the arrowhead.
792 |______________________
795 double x1
= startPositionX
;
796 double y1
= startPositionY
;
797 double x2
= positionOnLineX
;
798 double y2
= positionOnLineY
;
800 if ((x1
== x2
) && (y1
== y2
))
803 else if ((x1
== x2
) && (y1
> y2
))
804 theta
= (double)(3.0*myPi
/2.0);
806 else if ((x1
== x2
) && (y2
> y1
))
807 theta
= (double)(myPi
/2.0);
809 else if ((x2
> x1
) && (y2
>= y1
))
810 theta
= (double)atan((y2
- y1
)/(x2
- x1
));
813 theta
= (double)(myPi
+ atan((y2
- y1
)/(x2
- x1
)));
815 else if ((x2
> x1
) && (y2
< y1
))
816 theta
= (double)(2*myPi
+ atan((y2
- y1
)/(x2
- x1
)));
820 wxFatalError("Unknown arrowhead rotation case in lines.cc");
823 // Rotate about the centre of the object, then place
824 // the object on the line.
825 if (arrow
->GetMetaFile()->GetRotateable())
826 arrow
->GetMetaFile()->Rotate(0.0, 0.0, theta
);
830 // If erasing, just draw a rectangle.
831 double minX
, minY
, maxX
, maxY
;
832 arrow
->GetMetaFile()->GetBounds(&minX
, &minY
, &maxX
, &maxY
);
833 // Make erasing rectangle slightly bigger or you get droppings.
835 dc
.DrawRectangle((double)(deltaX
+ x
+ minX
- (extraPixels
/2.0)), (double)(deltaY
+ y
+ minY
- (extraPixels
/2.0)),
836 (double)(maxX
- minX
+ extraPixels
), (double)(maxY
- minY
+ extraPixels
));
839 arrow
->GetMetaFile()->Draw(dc
, x
+deltaX
, y
+deltaY
);
849 void wxLineShape::OnErase(wxDC
& dc
)
851 wxPen
*old_pen
= m_pen
;
852 wxBrush
*old_brush
= m_brush
;
853 SetPen(g_oglWhiteBackgroundPen
);
854 SetBrush(g_oglWhiteBackgroundBrush
);
856 double bound_x
, bound_y
;
857 GetBoundingBoxMax(&bound_x
, &bound_y
);
858 if (m_font
) dc
.SetFont(m_font
);
860 // Undraw text regions
861 for (int i
= 0; i
< 3; i
++)
863 wxNode
*node
= m_regions
.Nth(i
);
867 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
868 GetLabelPosition(i
, &x
, &y
);
869 EraseRegion(dc
, region
, x
, y
);
874 dc
.SetPen(g_oglWhiteBackgroundPen
);
875 dc
.SetBrush(g_oglWhiteBackgroundBrush
);
877 // Drawing over the line only seems to work if the line has a thickness
879 if (old_pen
&& (old_pen
->GetWidth() > 1))
881 dc
.DrawRectangle((double)(m_xpos
- (bound_x
/2.0) - 2.0), (double)(m_ypos
- (bound_y
/2.0) - 2.0),
882 (double)(bound_x
+4.0), (double)(bound_y
+4.0));
887 GetEventHandler()->OnDraw(dc
);
888 GetEventHandler()->OnEraseControlPoints(dc
);
892 if (old_pen
) SetPen(old_pen
);
893 if (old_brush
) SetBrush(old_brush
);
896 void wxLineShape::GetBoundingBoxMin(double *w
, double *h
)
903 wxNode
*node
= m_lineControlPoints
->First();
906 wxRealPoint
*point
= (wxRealPoint
*)node
->Data();
908 if (point
->x
< x1
) x1
= point
->x
;
909 if (point
->y
< y1
) y1
= point
->y
;
910 if (point
->x
> x2
) x2
= point
->x
;
911 if (point
->y
> y2
) y2
= point
->y
;
915 *w
= (double)(x2
- x1
);
916 *h
= (double)(y2
- y1
);
920 * For a node image of interest, finds the position of this arc
921 * amongst all the arcs which are attached to THIS SIDE of the node image,
922 * and the number of same.
924 void wxLineShape::FindNth(wxShape
*image
, int *nth
, int *no_arcs
, bool incoming
)
928 wxNode
*node
= image
->GetLines().First();
931 this_attachment
= m_attachmentTo
;
933 this_attachment
= m_attachmentFrom
;
935 // Find number of lines going into/out of this particular attachment point
938 wxLineShape
*line
= (wxLineShape
*)node
->Data();
940 if (line
->m_from
== image
)
942 // This is the nth line attached to 'image'
943 if ((line
== this) && !incoming
)
946 // Increment num count if this is the same side (attachment number)
947 if (line
->m_attachmentFrom
== this_attachment
)
951 if (line
->m_to
== image
)
953 // This is the nth line attached to 'image'
954 if ((line
== this) && incoming
)
957 // Increment num count if this is the same side (attachment number)
958 if (line
->m_attachmentTo
== this_attachment
)
968 void wxLineShape::OnDrawOutline(wxDC
& dc
, double x
, double y
, double w
, double h
)
970 wxPen
*old_pen
= m_pen
;
971 wxBrush
*old_brush
= m_brush
;
973 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
975 SetBrush( wxTRANSPARENT_BRUSH
);
977 GetEventHandler()->OnDraw(dc
);
979 if (old_pen
) SetPen(old_pen
);
981 if (old_brush
) SetBrush(old_brush
);
985 bool wxLineShape::OnMovePre(wxDC
& dc
, double x
, double y
, double old_x
, double old_y
, bool display
)
987 double x_offset
= x
- old_x
;
988 double y_offset
= y
- old_y
;
990 if (m_lineControlPoints
&& !(x_offset
== 0.0 && y_offset
== 0.0))
992 wxNode
*node
= m_lineControlPoints
->First();
995 wxRealPoint
*point
= (wxRealPoint
*)node
->Data();
996 point
->x
+= x_offset
;
997 point
->y
+= y_offset
;
1003 // Move temporary label rectangles if necessary
1004 for (int i
= 0; i
< 3; i
++)
1006 if (m_labelObjects
[i
])
1008 m_labelObjects
[i
]->Erase(dc
);
1009 double xp
, yp
, xr
, yr
;
1010 GetLabelPosition(i
, &xp
, &yp
);
1011 wxNode
*node
= m_regions
.Nth(i
);
1014 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
1015 region
->GetPosition(&xr
, &yr
);
1022 m_labelObjects
[i
]->Move(dc
, xp
+xr
, yp
+yr
);
1028 void wxLineShape::OnMoveLink(wxDC
& dc
, bool moveControlPoints
)
1030 if (!m_from
|| !m_to
)
1033 if (m_lineControlPoints
->Number() > 2)
1036 // Do each end - nothing in the middle. User has to move other points
1037 // manually if necessary.
1038 double end_x
, end_y
;
1039 double other_end_x
, other_end_y
;
1041 FindLineEndPoints(&end_x
, &end_y
, &other_end_x
, &other_end_y
);
1043 wxNode
*first
= m_lineControlPoints
->First();
1044 wxRealPoint
*first_point
= (wxRealPoint
*)first
->Data();
1045 wxNode
*last
= m_lineControlPoints
->Last();
1046 wxRealPoint
*last_point
= (wxRealPoint
*)last
->Data();
1048 /* This is redundant, surely? Done by SetEnds.
1049 first_point->x = end_x; first_point->y = end_y;
1050 last_point->x = other_end_x; last_point->y = other_end_y;
1053 double oldX
= m_xpos
;
1054 double oldY
= m_ypos
;
1056 SetEnds(end_x
, end_y
, other_end_x
, other_end_y
);
1058 // Do a second time, because one may depend on the other.
1059 FindLineEndPoints(&end_x
, &end_y
, &other_end_x
, &other_end_y
);
1060 SetEnds(end_x
, end_y
, other_end_x
, other_end_y
);
1062 // Try to move control points with the arc
1063 double x_offset
= m_xpos
- oldX
;
1064 double y_offset
= m_ypos
- oldY
;
1066 // if (moveControlPoints && m_lineControlPoints && !(x_offset == 0.0 && y_offset == 0.0))
1067 // Only move control points if it's a self link. And only works if attachment mode is ON.
1068 if ((m_from
== m_to
) && m_from
->GetAttachmentMode() && moveControlPoints
&& m_lineControlPoints
&& !(x_offset
== 0.0 && y_offset
== 0.0))
1070 wxNode
*node
= m_lineControlPoints
->First();
1073 if ((node
!= m_lineControlPoints
->First()) && (node
!= m_lineControlPoints
->Last()))
1075 wxRealPoint
*point
= (wxRealPoint
*)node
->Data();
1076 point
->x
+= x_offset
;
1077 point
->y
+= y_offset
;
1079 node
= node
->Next();
1083 Move(dc
, m_xpos
, m_ypos
);
1086 // Finds the x, y points at the two ends of the line.
1087 // This function can be used by e.g. line-routing routines to
1088 // get the actual points on the two node images where the lines will be drawn
1090 void wxLineShape::FindLineEndPoints(double *fromX
, double *fromY
, double *toX
, double *toY
)
1092 if (!m_from
|| !m_to
)
1095 // Do each end - nothing in the middle. User has to move other points
1096 // manually if necessary.
1097 double end_x
, end_y
;
1098 double other_end_x
, other_end_y
;
1100 wxNode
*first
= m_lineControlPoints
->First();
1101 wxRealPoint
*first_point
= (wxRealPoint
*)first
->Data();
1102 wxNode
*last
= m_lineControlPoints
->Last();
1103 wxRealPoint
*last_point
= (wxRealPoint
*)last
->Data();
1105 wxNode
*second
= first
->Next();
1106 wxRealPoint
*second_point
= (wxRealPoint
*)second
->Data();
1108 wxNode
*second_last
= last
->Previous();
1109 wxRealPoint
*second_last_point
= (wxRealPoint
*)second_last
->Data();
1111 if (m_lineControlPoints
->Number() > 2)
1113 if (m_from
->GetAttachmentMode())
1116 FindNth(m_from
, &nth
, &no_arcs
, FALSE
); // Not incoming
1117 m_from
->GetAttachmentPosition(m_attachmentFrom
, &end_x
, &end_y
, nth
, no_arcs
, this);
1120 (void) m_from
->GetPerimeterPoint(m_from
->GetX(), m_from
->GetY(),
1121 (double)second_point
->x
, (double)second_point
->y
,
1124 if (m_to
->GetAttachmentMode())
1127 FindNth(m_to
, &nth
, &no_arcs
, TRUE
); // Incoming
1128 m_to
->GetAttachmentPosition(m_attachmentTo
, &other_end_x
, &other_end_y
, nth
, no_arcs
, this);
1131 (void) m_to
->GetPerimeterPoint(m_to
->GetX(), m_to
->GetY(),
1132 (double)second_last_point
->x
, (double)second_last_point
->y
,
1133 &other_end_x
, &other_end_y
);
1137 double fromX
= m_from
->GetX();
1138 double fromY
= m_from
->GetY();
1139 double toX
= m_to
->GetX();
1140 double toY
= m_to
->GetY();
1142 if (m_from
->GetAttachmentMode())
1145 FindNth(m_from
, &nth
, &no_arcs
, FALSE
);
1146 m_from
->GetAttachmentPosition(m_attachmentFrom
, &end_x
, &end_y
, nth
, no_arcs
, this);
1151 if (m_to
->GetAttachmentMode())
1154 FindNth(m_to
, &nth
, &no_arcs
, TRUE
);
1155 m_to
->GetAttachmentPosition(m_attachmentTo
, &other_end_x
, &other_end_y
, nth
, no_arcs
, this);
1160 if (!m_from
->GetAttachmentMode())
1161 (void) m_from
->GetPerimeterPoint(m_from
->GetX(), m_from
->GetY(),
1165 if (!m_to
->GetAttachmentMode())
1166 (void) m_to
->GetPerimeterPoint(m_to
->GetX(), m_to
->GetY(),
1168 &other_end_x
, &other_end_y
);
1176 void wxLineShape::OnDraw(wxDC
& dc
)
1178 if (m_lineControlPoints
)
1183 dc
.SetBrush(m_brush
);
1185 int n
= m_lineControlPoints
->Number();
1186 wxPoint
*points
= new wxPoint
[n
];
1188 for (i
= 0; i
< n
; i
++)
1190 wxRealPoint
* point
= (wxRealPoint
*) m_lineControlPoints
->Nth(i
)->Data();
1191 points
[i
].x
= WXROUND(point
->x
);
1192 points
[i
].y
= WXROUND(point
->y
);
1196 dc
.DrawSpline(n
, points
);
1198 dc
.DrawLines(n
, points
);
1201 // For some reason, last point isn't drawn under Windows.
1202 dc
.DrawPoint(points
[n
-1]);
1208 // Problem with pen - if not a solid pen, does strange things
1209 // to the arrowhead. So make (get) a new pen that's solid.
1210 if (m_pen
&& (m_pen
->GetStyle() != wxSOLID
))
1213 wxThePenList
->FindOrCreatePen(m_pen
->GetColour(), 1, wxSOLID
);
1215 dc
.SetPen(solid_pen
);
1221 void wxLineShape::OnDrawControlPoints(wxDC
& dc
)
1226 // Draw temporary label rectangles if necessary
1227 for (int i
= 0; i
< 3; i
++)
1229 if (m_labelObjects
[i
])
1230 m_labelObjects
[i
]->Draw(dc
);
1232 wxShape::OnDrawControlPoints(dc
);
1235 void wxLineShape::OnEraseControlPoints(wxDC
& dc
)
1237 // Erase temporary label rectangles if necessary
1238 for (int i
= 0; i
< 3; i
++)
1240 if (m_labelObjects
[i
])
1241 m_labelObjects
[i
]->Erase(dc
);
1243 wxShape::OnEraseControlPoints(dc
);
1246 void wxLineShape::OnDragLeft(bool draw
, double x
, double y
, int keys
, int attachment
)
1250 void wxLineShape::OnBeginDragLeft(double x
, double y
, int keys
, int attachment
)
1254 void wxLineShape::OnEndDragLeft(double x
, double y
, int keys
, int attachment
)
1259 void wxLineShape::SetArrowSize(double length, double width)
1261 arrow_length = length;
1262 arrow_width = width;
1265 void wxLineShape::SetStartArrow(int style)
1267 start_style = style;
1270 void wxLineShape::SetMiddleArrow(int style)
1272 middle_style = style;
1275 void wxLineShape::SetEndArrow(int style)
1281 void wxLineShape::OnDrawContents(wxDC
& dc
)
1283 if (GetDisableLabel())
1286 for (int i
= 0; i
< 3; i
++)
1288 wxNode
*node
= m_regions
.Nth(i
);
1291 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
1293 GetLabelPosition(i
, &x
, &y
);
1294 DrawRegion(dc
, region
, x
, y
);
1299 void wxLineShape::SetTo(wxShape
*object
)
1304 void wxLineShape::SetFrom(wxShape
*object
)
1309 void wxLineShape::MakeControlPoints()
1311 if (m_canvas
&& m_lineControlPoints
)
1313 wxNode
*first
= m_lineControlPoints
->First();
1314 wxNode
*last
= m_lineControlPoints
->Last();
1315 wxRealPoint
*first_point
= (wxRealPoint
*)first
->Data();
1316 wxRealPoint
*last_point
= (wxRealPoint
*)last
->Data();
1318 wxLineControlPoint
*control
= new wxLineControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
,
1319 first_point
->x
, first_point
->y
,
1320 CONTROL_POINT_ENDPOINT_FROM
);
1321 control
->m_point
= first_point
;
1322 m_canvas
->AddShape(control
);
1323 m_controlPoints
.Append(control
);
1326 wxNode
*node
= first
->Next();
1327 while (node
!= last
)
1329 wxRealPoint
*point
= (wxRealPoint
*)node
->Data();
1331 control
= new wxLineControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
,
1333 CONTROL_POINT_LINE
);
1334 control
->m_point
= point
;
1336 m_canvas
->AddShape(control
);
1337 m_controlPoints
.Append(control
);
1339 node
= node
->Next();
1341 control
= new wxLineControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
,
1342 last_point
->x
, last_point
->y
,
1343 CONTROL_POINT_ENDPOINT_TO
);
1344 control
->m_point
= last_point
;
1345 m_canvas
->AddShape(control
);
1346 m_controlPoints
.Append(control
);
1352 void wxLineShape::ResetControlPoints()
1354 if (m_canvas
&& m_lineControlPoints
&& m_controlPoints
.Number() > 0)
1356 wxNode
*node
= m_controlPoints
.First();
1357 wxNode
*control_node
= m_lineControlPoints
->First();
1358 while (node
&& control_node
)
1360 wxRealPoint
*point
= (wxRealPoint
*)control_node
->Data();
1361 wxLineControlPoint
*control
= (wxLineControlPoint
*)node
->Data();
1362 control
->SetX(point
->x
);
1363 control
->SetY(point
->y
);
1365 node
= node
->Next();
1366 control_node
= control_node
->Next();
1372 void wxLineShape::WriteAttributes(wxExpr
*clause
)
1374 wxShape::WriteAttributes(clause
);
1377 clause
->AddAttributeValue("from", m_from
->GetId());
1379 clause
->AddAttributeValue("to", m_to
->GetId());
1381 if (m_attachmentTo
!= 0)
1382 clause
->AddAttributeValue("attachment_to", (long)m_attachmentTo
);
1383 if (m_attachmentFrom
!= 0)
1384 clause
->AddAttributeValue("attachment_from", (long)m_attachmentFrom
);
1386 if (m_alignmentStart
!= 0)
1387 clause
->AddAttributeValue("align_start", (long)m_alignmentStart
);
1388 if (m_alignmentEnd
!= 0)
1389 clause
->AddAttributeValue("align_end", (long)m_alignmentEnd
);
1391 clause
->AddAttributeValue("is_spline", (long)m_isSpline
);
1392 if (m_maintainStraightLines
)
1393 clause
->AddAttributeValue("keep_lines_straight", (long)m_maintainStraightLines
);
1395 // Make a list of lists for the (sp)line controls
1396 wxExpr
*list
= new wxExpr(wxExprList
);
1397 wxNode
*node
= m_lineControlPoints
->First();
1400 wxRealPoint
*point
= (wxRealPoint
*)node
->Data();
1401 wxExpr
*point_list
= new wxExpr(wxExprList
);
1402 wxExpr
*x_expr
= new wxExpr((double) point
->x
);
1403 wxExpr
*y_expr
= new wxExpr((double) point
->y
);
1404 point_list
->Append(x_expr
);
1405 point_list
->Append(y_expr
);
1406 list
->Append(point_list
);
1408 node
= node
->Next();
1410 clause
->AddAttributeValue("controls", list
);
1412 // Write arc arrows in new OGL format, if there are any.
1413 // This is a list of lists. Each sublist comprises:
1414 // (arrowType arrowEnd xOffset arrowSize)
1415 if (m_arcArrows
.Number() > 0)
1417 wxExpr
*arrow_list
= new wxExpr(wxExprList
);
1418 node
= m_arcArrows
.First();
1421 wxArrowHead
*head
= (wxArrowHead
*)node
->Data();
1422 wxExpr
*head_list
= new wxExpr(wxExprList
);
1423 head_list
->Append(new wxExpr((long)head
->_GetType()));
1424 head_list
->Append(new wxExpr((long)head
->GetArrowEnd()));
1425 head_list
->Append(new wxExpr(head
->GetXOffset()));
1426 head_list
->Append(new wxExpr(head
->GetArrowSize()));
1427 head_list
->Append(new wxExpr(wxExprString
, (head
->GetName() ? head
->GetName() : "")));
1428 head_list
->Append(new wxExpr(head
->GetId()));
1430 // New members of wxArrowHead
1431 head_list
->Append(new wxExpr(head
->GetYOffset()));
1432 head_list
->Append(new wxExpr(head
->GetSpacing()));
1434 arrow_list
->Append(head_list
);
1436 node
= node
->Next();
1438 clause
->AddAttributeValue("arrows", arrow_list
);
1442 void wxLineShape::ReadAttributes(wxExpr
*clause
)
1444 wxShape::ReadAttributes(clause
);
1446 int iVal
= (int) m_isSpline
;
1447 clause
->AssignAttributeValue("is_spline", &iVal
);
1448 m_isSpline
= (iVal
!= 0);
1450 iVal
= (int) m_maintainStraightLines
;
1451 clause
->AssignAttributeValue("keep_lines_straight", &iVal
);
1452 m_maintainStraightLines
= (iVal
!= 0);
1454 clause
->AssignAttributeValue("align_start", &m_alignmentStart
);
1455 clause
->AssignAttributeValue("align_end", &m_alignmentEnd
);
1457 // Compatibility: check for no regions.
1458 if (m_regions
.Number() == 0)
1460 wxShapeRegion
*newRegion
= new wxShapeRegion
;
1461 newRegion
->SetName("Middle");
1462 newRegion
->SetSize(150, 50);
1463 m_regions
.Append((wxObject
*)newRegion
);
1464 if (m_text
.Number() > 0)
1466 newRegion
->ClearText();
1467 wxNode
*node
= m_text
.First();
1470 wxShapeTextLine
*textLine
= (wxShapeTextLine
*)node
->Data();
1471 wxNode
*next
= node
->Next();
1472 newRegion
->GetFormattedText().Append((wxObject
*)textLine
);
1478 newRegion
= new wxShapeRegion
;
1479 newRegion
->SetName("Start");
1480 newRegion
->SetSize(150, 50);
1481 m_regions
.Append((wxObject
*)newRegion
);
1483 newRegion
= new wxShapeRegion
;
1484 newRegion
->SetName("End");
1485 newRegion
->SetSize(150, 50);
1486 m_regions
.Append((wxObject
*)newRegion
);
1490 m_attachmentFrom
= 0;
1492 clause
->AssignAttributeValue("attachment_to", &m_attachmentTo
);
1493 clause
->AssignAttributeValue("attachment_from", &m_attachmentFrom
);
1495 wxExpr
*line_list
= NULL
;
1497 // When image is created, there are default control points. Override
1498 // them if there are some in the file.
1499 clause
->AssignAttributeValue("controls", &line_list
);
1503 // Read a list of lists for the spline controls
1504 if (m_lineControlPoints
)
1506 ClearPointList(*m_lineControlPoints
);
1509 m_lineControlPoints
= new wxList
;
1511 wxExpr
*node
= line_list
->value
.first
;
1515 wxExpr
*xexpr
= node
->value
.first
;
1516 double x
= xexpr
->RealValue();
1518 wxExpr
*yexpr
= xexpr
->next
;
1519 double y
= yexpr
->RealValue();
1521 wxRealPoint
*point
= new wxRealPoint(x
, y
);
1522 m_lineControlPoints
->Append((wxObject
*) point
);
1528 // Read arrow list, for new OGL code
1529 wxExpr
*arrow_list
= NULL
;
1531 clause
->AssignAttributeValue("arrows", &arrow_list
);
1534 wxExpr
*node
= arrow_list
->value
.first
;
1538 WXTYPE arrowType
= ARROW_ARROW
;
1540 double xOffset
= 0.0;
1541 double arrowSize
= 0.0;
1542 wxString
arrowName("");
1545 wxExpr
*type_expr
= node
->Nth(0);
1546 wxExpr
*end_expr
= node
->Nth(1);
1547 wxExpr
*dist_expr
= node
->Nth(2);
1548 wxExpr
*size_expr
= node
->Nth(3);
1549 wxExpr
*name_expr
= node
->Nth(4);
1550 wxExpr
*id_expr
= node
->Nth(5);
1552 // New members of wxArrowHead
1553 wxExpr
*yOffsetExpr
= node
->Nth(6);
1554 wxExpr
*spacingExpr
= node
->Nth(7);
1557 arrowType
= (int)type_expr
->IntegerValue();
1559 arrowEnd
= (int)end_expr
->IntegerValue();
1561 xOffset
= dist_expr
->RealValue();
1563 arrowSize
= size_expr
->RealValue();
1565 arrowName
= name_expr
->StringValue();
1567 arrowId
= id_expr
->IntegerValue();
1572 RegisterId(arrowId
);
1574 wxArrowHead
*arrowHead
= AddArrow(arrowType
, arrowEnd
, arrowSize
, xOffset
, (char*) (const char*) arrowName
, NULL
, arrowId
);
1576 arrowHead
->SetYOffset(yOffsetExpr
->RealValue());
1578 arrowHead
->SetSpacing(spacingExpr
->RealValue());
1586 void wxLineShape::Copy(wxShape
& copy
)
1588 wxShape::Copy(copy
);
1590 wxASSERT( copy
.IsKindOf(CLASSINFO(wxLineShape
)) );
1592 wxLineShape
& lineCopy
= (wxLineShape
&) copy
;
1594 lineCopy
.m_to
= m_to
;
1595 lineCopy
.m_from
= m_from
;
1596 lineCopy
.m_attachmentTo
= m_attachmentTo
;
1597 lineCopy
.m_attachmentFrom
= m_attachmentFrom
;
1598 lineCopy
.m_isSpline
= m_isSpline
;
1599 lineCopy
.m_alignmentStart
= m_alignmentStart
;
1600 lineCopy
.m_alignmentEnd
= m_alignmentEnd
;
1601 lineCopy
.m_maintainStraightLines
= m_maintainStraightLines
;
1602 lineCopy
.m_lineOrientations
.Clear();
1604 wxNode
*node
= m_lineOrientations
.First();
1607 lineCopy
.m_lineOrientations
.Append(node
->Data());
1608 node
= node
->Next();
1611 if (lineCopy
.m_lineControlPoints
)
1613 ClearPointList(*lineCopy
.m_lineControlPoints
);
1614 delete lineCopy
.m_lineControlPoints
;
1617 lineCopy
.m_lineControlPoints
= new wxList
;
1619 node
= m_lineControlPoints
->First();
1622 wxRealPoint
*point
= (wxRealPoint
*)node
->Data();
1623 wxRealPoint
*new_point
= new wxRealPoint(point
->x
, point
->y
);
1624 lineCopy
.m_lineControlPoints
->Append((wxObject
*) new_point
);
1625 node
= node
->Next();
1629 lineCopy
.ClearArrowsAtPosition(-1);
1630 node
= m_arcArrows
.First();
1633 wxArrowHead
*arrow
= (wxArrowHead
*)node
->Data();
1634 lineCopy
.m_arcArrows
.Append(new wxArrowHead(*arrow
));
1635 node
= node
->Next();
1639 // Override select, to create/delete temporary label-moving objects
1640 void wxLineShape::Select(bool select
, wxDC
* dc
)
1642 wxShape::Select(select
, dc
);
1645 for (int i
= 0; i
< 3; i
++)
1647 wxNode
*node
= m_regions
.Nth(i
);
1650 wxShapeRegion
*region
= (wxShapeRegion
*)node
->Data();
1651 if (region
->m_formattedText
.Number() > 0)
1653 double w
, h
, x
, y
, xx
, yy
;
1654 region
->GetSize(&w
, &h
);
1655 region
->GetPosition(&x
, &y
);
1656 GetLabelPosition(i
, &xx
, &yy
);
1657 if (m_labelObjects
[i
])
1659 m_labelObjects
[i
]->Select(FALSE
);
1660 m_labelObjects
[i
]->RemoveFromCanvas(m_canvas
);
1661 delete m_labelObjects
[i
];
1663 m_labelObjects
[i
] = OnCreateLabelShape(this, region
, w
, h
);
1664 m_labelObjects
[i
]->AddToCanvas(m_canvas
);
1665 m_labelObjects
[i
]->Show(TRUE
);
1667 m_labelObjects
[i
]->Move(*dc
, (double)(x
+ xx
), (double)(y
+ yy
));
1668 m_labelObjects
[i
]->Select(TRUE
, dc
);
1675 for (int i
= 0; i
< 3; i
++)
1677 if (m_labelObjects
[i
])
1679 m_labelObjects
[i
]->Select(FALSE
, dc
);
1680 m_labelObjects
[i
]->Erase(*dc
);
1681 m_labelObjects
[i
]->RemoveFromCanvas(m_canvas
);
1682 delete m_labelObjects
[i
];
1683 m_labelObjects
[i
] = NULL
;
1690 * Line control point
1694 IMPLEMENT_DYNAMIC_CLASS(wxLineControlPoint
, wxControlPoint
)
1696 wxLineControlPoint::wxLineControlPoint(wxShapeCanvas
*theCanvas
, wxShape
*object
, double size
, double x
, double y
, int the_type
):
1697 wxControlPoint(theCanvas
, object
, size
, x
, y
, the_type
)
1705 wxLineControlPoint::~wxLineControlPoint()
1709 void wxLineControlPoint::OnDraw(wxDC
& dc
)
1711 wxRectangleShape::OnDraw(dc
);
1714 // Implement movement of Line point
1715 void wxLineControlPoint::OnDragLeft(bool draw
, double x
, double y
, int keys
, int attachment
)
1717 m_shape
->GetEventHandler()->OnSizingDragLeft(this, draw
, x
, y
, keys
, attachment
);
1720 void wxLineControlPoint::OnBeginDragLeft(double x
, double y
, int keys
, int attachment
)
1722 m_shape
->GetEventHandler()->OnSizingBeginDragLeft(this, x
, y
, keys
, attachment
);
1725 void wxLineControlPoint::OnEndDragLeft(double x
, double y
, int keys
, int attachment
)
1727 m_shape
->GetEventHandler()->OnSizingEndDragLeft(this, x
, y
, keys
, attachment
);
1730 // Control points ('handles') redirect control to the actual shape, to make it easier
1731 // to override sizing behaviour.
1732 void wxLineShape::OnSizingDragLeft(wxControlPoint
* pt
, bool draw
, double x
, double y
, int keys
, int attachment
)
1734 wxLineControlPoint
* lpt
= (wxLineControlPoint
*) pt
;
1736 wxClientDC
dc(GetCanvas());
1737 GetCanvas()->PrepareDC(dc
);
1739 dc
.SetLogicalFunction(wxXOR
);
1741 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
1742 dc
.SetPen(dottedPen
);
1743 dc
.SetBrush((* wxTRANSPARENT_BRUSH
));
1745 if (lpt
->m_type
== CONTROL_POINT_LINE
)
1747 m_canvas
->Snap(&x
, &y
);
1749 lpt
->SetX(x
); lpt
->SetY(y
);
1750 lpt
->m_point
->x
= x
; lpt
->m_point
->y
= y
;
1752 wxLineShape
*lineShape
= (wxLineShape
*)this;
1754 wxPen
*old_pen
= lineShape
->GetPen();
1755 wxBrush
*old_brush
= lineShape
->GetBrush();
1757 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
1758 lineShape
->SetPen(& dottedPen
);
1759 lineShape
->SetBrush(wxTRANSPARENT_BRUSH
);
1761 lineShape
->GetEventHandler()->OnMoveLink(dc
, FALSE
);
1763 lineShape
->SetPen(old_pen
);
1764 lineShape
->SetBrush(old_brush
);
1767 if (lpt
->m_type
== CONTROL_POINT_ENDPOINT_FROM
|| lpt
->m_type
== CONTROL_POINT_ENDPOINT_TO
)
1769 // lpt->SetX(x); lpt->SetY(y);
1774 void wxLineShape::OnSizingBeginDragLeft(wxControlPoint
* pt
, double x
, double y
, int keys
, int attachment
)
1776 wxLineControlPoint
* lpt
= (wxLineControlPoint
*) pt
;
1778 wxClientDC
dc(GetCanvas());
1779 GetCanvas()->PrepareDC(dc
);
1781 wxLineShape
*lineShape
= (wxLineShape
*)this;
1782 if (lpt
->m_type
== CONTROL_POINT_LINE
)
1784 lpt
->m_originalPos
= * (lpt
->m_point
);
1785 m_canvas
->Snap(&x
, &y
);
1789 // Redraw start and end objects because we've left holes
1790 // when erasing the line
1791 lineShape
->GetFrom()->OnDraw(dc
);
1792 lineShape
->GetFrom()->OnDrawContents(dc
);
1793 lineShape
->GetTo()->OnDraw(dc
);
1794 lineShape
->GetTo()->OnDrawContents(dc
);
1796 this->SetDisableLabel(TRUE
);
1797 dc
.SetLogicalFunction(wxXOR
);
1799 lpt
->m_xpos
= x
; lpt
->m_ypos
= y
;
1800 lpt
->m_point
->x
= x
; lpt
->m_point
->y
= y
;
1802 wxPen
*old_pen
= lineShape
->GetPen();
1803 wxBrush
*old_brush
= lineShape
->GetBrush();
1805 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
1806 lineShape
->SetPen(& dottedPen
);
1807 lineShape
->SetBrush(wxTRANSPARENT_BRUSH
);
1809 lineShape
->GetEventHandler()->OnMoveLink(dc
, FALSE
);
1811 lineShape
->SetPen(old_pen
);
1812 lineShape
->SetBrush(old_brush
);
1815 if (lpt
->m_type
== CONTROL_POINT_ENDPOINT_FROM
|| lpt
->m_type
== CONTROL_POINT_ENDPOINT_TO
)
1817 m_canvas
->SetCursor(g_oglBullseyeCursor
);
1818 lpt
->m_oldCursor
= wxSTANDARD_CURSOR
;
1822 void wxLineShape::OnSizingEndDragLeft(wxControlPoint
* pt
, double x
, double y
, int keys
, int attachment
)
1824 wxLineControlPoint
* lpt
= (wxLineControlPoint
*) pt
;
1826 wxClientDC
dc(GetCanvas());
1827 GetCanvas()->PrepareDC(dc
);
1829 this->SetDisableLabel(FALSE
);
1830 wxLineShape
*lineShape
= (wxLineShape
*)this;
1832 if (lpt
->m_type
== CONTROL_POINT_LINE
)
1834 m_canvas
->Snap(&x
, &y
);
1836 wxRealPoint pt
= wxRealPoint(x
, y
);
1838 // Move the control point back to where it was;
1839 // MoveControlPoint will move it to the new position
1840 // if it decides it wants. We only moved the position
1841 // during user feedback so we could redraw the line
1842 // as it changed shape.
1843 lpt
->m_xpos
= lpt
->m_originalPos
.x
; lpt
->m_ypos
= lpt
->m_originalPos
.y
;
1844 lpt
->m_point
->x
= lpt
->m_originalPos
.x
; lpt
->m_point
->y
= lpt
->m_originalPos
.y
;
1846 OnMoveMiddleControlPoint(dc
, lpt
, pt
);
1848 if (lpt
->m_type
== CONTROL_POINT_ENDPOINT_FROM
)
1850 if (lpt
->m_oldCursor
)
1851 m_canvas
->SetCursor(lpt
->m_oldCursor
);
1855 // lpt->m_xpos = x; lpt->m_ypos = y;
1857 if (lineShape
->GetFrom())
1859 lineShape
->GetFrom()->MoveLineToNewAttachment(dc
, lineShape
, x
, y
);
1862 if (lpt
->m_type
== CONTROL_POINT_ENDPOINT_TO
)
1864 if (lpt
->m_oldCursor
)
1865 m_canvas
->SetCursor(lpt
->m_oldCursor
);
1867 // lpt->m_xpos = x; lpt->m_ypos = y;
1869 if (lineShape
->GetTo())
1871 lineShape
->GetTo()->MoveLineToNewAttachment(dc
, lineShape
, x
, y
);
1878 for (i
= 0; i
< lineShape
->GetLineControlPoints()->Number(); i
++)
1879 if (((wxRealPoint
*)(lineShape
->GetLineControlPoints()->Nth(i
)->Data())) == lpt
->m_point
)
1882 // N.B. in OnMoveControlPoint, an event handler in Hardy could have deselected
1883 // the line and therefore deleted 'this'. -> GPF, intermittently.
1884 // So assume at this point that we've been blown away.
1886 lineShape
->OnMoveControlPoint(i
+1, x
, y
);
1890 // This is called only when a non-end control point is moved.
1891 bool wxLineShape::OnMoveMiddleControlPoint(wxDC
& dc
, wxLineControlPoint
* lpt
, const wxRealPoint
& pt
)
1893 lpt
->m_xpos
= pt
.x
; lpt
->m_ypos
= pt
.y
;
1894 lpt
->m_point
->x
= pt
.x
; lpt
->m_point
->y
= pt
.y
;
1896 GetEventHandler()->OnMoveLink(dc
);
1901 // Implement movement of endpoint to a new attachment
1902 // OBSOLETE: done by dragging with the left button.
1905 void wxLineControlPoint::OnDragRight(bool draw
, double x
, double y
, int keys
, int attachment
)
1907 if (m_type
== CONTROL_POINT_ENDPOINT_FROM
|| m_type
== CONTROL_POINT_ENDPOINT_TO
)
1909 m_xpos
= x
; m_ypos
= y
;
1913 void wxLineControlPoint::OnBeginDragRight(double x
, double y
, int keys
, int attachment
)
1915 wxClientDC
dc(GetCanvas());
1916 GetCanvas()->PrepareDC(dc
);
1918 wxLineShape
*lineShape
= (wxLineShape
*)m_shape
;
1919 if (m_type
== CONTROL_POINT_ENDPOINT_FROM
|| m_type
== CONTROL_POINT_ENDPOINT_TO
)
1922 lineShape
->GetEventHandler()->OnDraw(dc
);
1923 if (m_type
== CONTROL_POINT_ENDPOINT_FROM
)
1925 lineShape
->GetFrom()->GetEventHandler()->OnDraw(dc
);
1926 lineShape
->GetFrom()->GetEventHandler()->OnDrawContents(dc
);
1930 lineShape
->GetTo()->GetEventHandler()->OnDraw(dc
);
1931 lineShape
->GetTo()->GetEventHandler()->OnDrawContents(dc
);
1933 m_canvas
->SetCursor(g_oglBullseyeCursor
);
1934 m_oldCursor
= wxSTANDARD_CURSOR
;
1938 void wxLineControlPoint::OnEndDragRight(double x
, double y
, int keys
, int attachment
)
1940 wxClientDC
dc(GetCanvas());
1941 GetCanvas()->PrepareDC(dc
);
1943 wxLineShape
*lineShape
= (wxLineShape
*)m_shape
;
1944 if (m_type
== CONTROL_POINT_ENDPOINT_FROM
)
1947 m_canvas
->SetCursor(m_oldCursor
);
1949 m_xpos
= x
; m_ypos
= y
;
1951 if (lineShape
->GetFrom())
1953 lineShape
->GetFrom()->EraseLinks(dc
);
1958 if (lineShape
->GetFrom()->HitTest(x
, y
, &new_attachment
, &distance
))
1959 lineShape
->SetAttachments(new_attachment
, lineShape
->GetAttachmentTo());
1961 lineShape
->GetFrom()->MoveLinks(dc
);
1964 if (m_type
== CONTROL_POINT_ENDPOINT_TO
)
1967 m_canvas
->SetCursor(m_oldCursor
);
1970 m_xpos
= x
; m_ypos
= y
;
1972 if (lineShape
->GetTo())
1974 lineShape
->GetTo()->EraseLinks(dc
);
1978 if (lineShape
->GetTo()->HitTest(x
, y
, &new_attachment
, &distance
))
1979 lineShape
->SetAttachments(lineShape
->GetAttachmentFrom(), new_attachment
);
1981 lineShape
->GetTo()->MoveLinks(dc
);
1985 for (i
= 0; i
< lineShape
->GetLineControlPoints()->Number(); i
++)
1986 if (((wxRealPoint
*)(lineShape
->GetLineControlPoints()->Nth(i
)->Data())) == m_point
)
1988 lineShape
->OnMoveControlPoint(i
+1, x
, y
);
1989 if (!m_canvas
->GetQuickEditMode()) m_canvas
->Redraw(dc
);
1994 * Get the point on the given line (x1, y1) (x2, y2)
1995 * distance 'length' along from the end,
1996 * returned values in x and y
1999 void GetPointOnLine(double x1
, double y1
, double x2
, double y2
,
2000 double length
, double *x
, double *y
)
2002 double l
= (double)sqrt((x2
- x1
)*(x2
- x1
) + (y2
- y1
)*(y2
- y1
));
2007 double i_bar
= (x2
- x1
)/l
;
2008 double j_bar
= (y2
- y1
)/l
;
2010 *x
= (- length
*i_bar
) + x2
;
2011 *y
= (- length
*j_bar
) + y2
;
2014 wxArrowHead
*wxLineShape::AddArrow(WXTYPE type
, int end
, double size
, double xOffset
,
2015 const wxString
& name
, wxPseudoMetaFile
*mf
, long arrowId
)
2017 wxArrowHead
*arrow
= new wxArrowHead(type
, end
, size
, xOffset
, name
, mf
, arrowId
);
2018 m_arcArrows
.Append(arrow
);
2023 * Add arrowhead at a particular position in the arrowhead list.
2025 bool wxLineShape::AddArrowOrdered(wxArrowHead
*arrow
, wxList
& referenceList
, int end
)
2027 wxNode
*refNode
= referenceList
.First();
2028 wxNode
*currNode
= m_arcArrows
.First();
2029 wxString
targetName(arrow
->GetName());
2030 if (!refNode
) return FALSE
;
2032 // First check whether we need to insert in front of list,
2033 // because this arrowhead is the first in the reference
2034 // list and should therefore be first in the current list.
2035 wxArrowHead
*refArrow
= (wxArrowHead
*)refNode
->Data();
2036 if (refArrow
->GetName() == targetName
)
2038 m_arcArrows
.Insert(arrow
);
2042 while (refNode
&& currNode
)
2044 wxArrowHead
*currArrow
= (wxArrowHead
*)currNode
->Data();
2045 refArrow
= (wxArrowHead
*)refNode
->Data();
2047 // Matching: advance current arrow pointer
2048 if ((currArrow
->GetArrowEnd() == end
) &&
2049 (currArrow
->GetName() == refArrow
->GetName()))
2051 currNode
= currNode
->Next(); // Could be NULL now
2053 currArrow
= (wxArrowHead
*)currNode
->Data();
2056 // Check if we're at the correct position in the
2058 if (targetName
== refArrow
->GetName())
2061 m_arcArrows
.Insert(currNode
, arrow
);
2063 m_arcArrows
.Append(arrow
);
2066 refNode
= refNode
->Next();
2068 m_arcArrows
.Append(arrow
);
2072 void wxLineShape::ClearArrowsAtPosition(int end
)
2074 wxNode
*node
= m_arcArrows
.First();
2077 wxArrowHead
*arrow
= (wxArrowHead
*)node
->Data();
2078 wxNode
*next
= node
->Next();
2087 case ARROW_POSITION_START
:
2089 if (arrow
->GetArrowEnd() == ARROW_POSITION_START
)
2096 case ARROW_POSITION_END
:
2098 if (arrow
->GetArrowEnd() == ARROW_POSITION_END
)
2105 case ARROW_POSITION_MIDDLE
:
2107 if (arrow
->GetArrowEnd() == ARROW_POSITION_MIDDLE
)
2119 bool wxLineShape::ClearArrow(const wxString
& name
)
2121 wxNode
*node
= m_arcArrows
.First();
2124 wxArrowHead
*arrow
= (wxArrowHead
*)node
->Data();
2125 if (arrow
->GetName() == name
)
2131 node
= node
->Next();
2137 * Finds an arrowhead at the given position (if -1, any position)
2141 wxArrowHead
*wxLineShape::FindArrowHead(int position
, const wxString
& name
)
2143 wxNode
*node
= m_arcArrows
.First();
2146 wxArrowHead
*arrow
= (wxArrowHead
*)node
->Data();
2147 if (((position
== -1) || (position
== arrow
->GetArrowEnd())) &&
2148 (arrow
->GetName() == name
))
2150 node
= node
->Next();
2155 wxArrowHead
*wxLineShape::FindArrowHead(long arrowId
)
2157 wxNode
*node
= m_arcArrows
.First();
2160 wxArrowHead
*arrow
= (wxArrowHead
*)node
->Data();
2161 if (arrowId
== arrow
->GetId())
2163 node
= node
->Next();
2169 * Deletes an arrowhead at the given position (if -1, any position)
2173 bool wxLineShape::DeleteArrowHead(int position
, const wxString
& name
)
2175 wxNode
*node
= m_arcArrows
.First();
2178 wxArrowHead
*arrow
= (wxArrowHead
*)node
->Data();
2179 if (((position
== -1) || (position
== arrow
->GetArrowEnd())) &&
2180 (arrow
->GetName() == name
))
2186 node
= node
->Next();
2191 // Overloaded DeleteArrowHead: pass arrowhead id.
2192 bool wxLineShape::DeleteArrowHead(long id
)
2194 wxNode
*node
= m_arcArrows
.First();
2197 wxArrowHead
*arrow
= (wxArrowHead
*)node
->Data();
2198 if (arrow
->GetId() == id
)
2204 node
= node
->Next();
2210 * Calculate the minimum width a line
2211 * occupies, for the purposes of drawing lines in tools.
2215 double wxLineShape::FindMinimumWidth()
2217 double minWidth
= 0.0;
2218 wxNode
*node
= m_arcArrows
.First();
2221 wxArrowHead
*arrowHead
= (wxArrowHead
*)node
->Data();
2222 minWidth
+= arrowHead
->GetSize();
2224 minWidth
+= arrowHead
->GetSpacing();
2226 node
= node
->Next();
2228 // We have ABSOLUTE minimum now. So
2229 // scale it to give it reasonable aesthetics
2230 // when drawing with line.
2232 minWidth
= (double)(minWidth
* 1.4);
2236 SetEnds(0.0, 0.0, minWidth
, 0.0);
2242 // Find which position we're talking about at this (x, y).
2243 // Returns ARROW_POSITION_START, ARROW_POSITION_MIDDLE, ARROW_POSITION_END
2244 int wxLineShape::FindLinePosition(double x
, double y
)
2246 double startX
, startY
, endX
, endY
;
2247 GetEnds(&startX
, &startY
, &endX
, &endY
);
2249 // Find distances from centre, start and end. The smallest wins.
2250 double centreDistance
= (double)(sqrt((x
- m_xpos
)*(x
- m_xpos
) + (y
- m_ypos
)*(y
- m_ypos
)));
2251 double startDistance
= (double)(sqrt((x
- startX
)*(x
- startX
) + (y
- startY
)*(y
- startY
)));
2252 double endDistance
= (double)(sqrt((x
- endX
)*(x
- endX
) + (y
- endY
)*(y
- endY
)));
2254 if (centreDistance
< startDistance
&& centreDistance
< endDistance
)
2255 return ARROW_POSITION_MIDDLE
;
2256 else if (startDistance
< endDistance
)
2257 return ARROW_POSITION_START
;
2259 return ARROW_POSITION_END
;
2262 // Set alignment flags
2263 void wxLineShape::SetAlignmentOrientation(bool isEnd
, bool isHoriz
)
2267 if (isHoriz
&& ((m_alignmentEnd
& LINE_ALIGNMENT_HORIZ
) != LINE_ALIGNMENT_HORIZ
))
2268 m_alignmentEnd
|= LINE_ALIGNMENT_HORIZ
;
2269 else if (!isHoriz
&& ((m_alignmentEnd
& LINE_ALIGNMENT_HORIZ
) == LINE_ALIGNMENT_HORIZ
))
2270 m_alignmentEnd
-= LINE_ALIGNMENT_HORIZ
;
2274 if (isHoriz
&& ((m_alignmentStart
& LINE_ALIGNMENT_HORIZ
) != LINE_ALIGNMENT_HORIZ
))
2275 m_alignmentStart
|= LINE_ALIGNMENT_HORIZ
;
2276 else if (!isHoriz
&& ((m_alignmentStart
& LINE_ALIGNMENT_HORIZ
) == LINE_ALIGNMENT_HORIZ
))
2277 m_alignmentStart
-= LINE_ALIGNMENT_HORIZ
;
2281 void wxLineShape::SetAlignmentType(bool isEnd
, int alignType
)
2285 if (alignType
== LINE_ALIGNMENT_TO_NEXT_HANDLE
)
2287 if ((m_alignmentEnd
& LINE_ALIGNMENT_TO_NEXT_HANDLE
) != LINE_ALIGNMENT_TO_NEXT_HANDLE
)
2288 m_alignmentEnd
|= LINE_ALIGNMENT_TO_NEXT_HANDLE
;
2290 else if ((m_alignmentEnd
& LINE_ALIGNMENT_TO_NEXT_HANDLE
) == LINE_ALIGNMENT_TO_NEXT_HANDLE
)
2291 m_alignmentEnd
-= LINE_ALIGNMENT_TO_NEXT_HANDLE
;
2295 if (alignType
== LINE_ALIGNMENT_TO_NEXT_HANDLE
)
2297 if ((m_alignmentStart
& LINE_ALIGNMENT_TO_NEXT_HANDLE
) != LINE_ALIGNMENT_TO_NEXT_HANDLE
)
2298 m_alignmentStart
|= LINE_ALIGNMENT_TO_NEXT_HANDLE
;
2300 else if ((m_alignmentStart
& LINE_ALIGNMENT_TO_NEXT_HANDLE
) == LINE_ALIGNMENT_TO_NEXT_HANDLE
)
2301 m_alignmentStart
-= LINE_ALIGNMENT_TO_NEXT_HANDLE
;
2305 bool wxLineShape::GetAlignmentOrientation(bool isEnd
)
2308 return ((m_alignmentEnd
& LINE_ALIGNMENT_HORIZ
) == LINE_ALIGNMENT_HORIZ
);
2310 return ((m_alignmentStart
& LINE_ALIGNMENT_HORIZ
) == LINE_ALIGNMENT_HORIZ
);
2313 int wxLineShape::GetAlignmentType(bool isEnd
)
2316 return (m_alignmentEnd
& LINE_ALIGNMENT_TO_NEXT_HANDLE
);
2318 return (m_alignmentStart
& LINE_ALIGNMENT_TO_NEXT_HANDLE
);
2321 wxRealPoint
*wxLineShape::GetNextControlPoint(wxShape
*nodeObject
)
2323 int n
= m_lineControlPoints
->Number();
2325 if (m_to
== nodeObject
)
2327 // Must be END of line, so we want (n - 1)th control point.
2328 // But indexing ends at n-1, so subtract 2.
2332 wxNode
*node
= m_lineControlPoints
->Nth(nn
);
2335 return (wxRealPoint
*)node
->Data();
2346 IMPLEMENT_DYNAMIC_CLASS(wxArrowHead
, wxObject
)
2348 wxArrowHead::wxArrowHead(WXTYPE type
, int end
, double size
, double dist
, const wxString
& name
,
2349 wxPseudoMetaFile
*mf
, long arrowId
)
2351 m_arrowType
= type
; m_arrowEnd
= end
; m_arrowSize
= size
;
2363 wxArrowHead::wxArrowHead(wxArrowHead
& toCopy
)
2365 m_arrowType
= toCopy
.m_arrowType
; m_arrowEnd
= toCopy
.GetArrowEnd();
2366 m_arrowSize
= toCopy
.m_arrowSize
;
2367 m_xOffset
= toCopy
.m_xOffset
;
2368 m_yOffset
= toCopy
.m_yOffset
;
2369 m_spacing
= toCopy
.m_spacing
;
2370 m_arrowName
= toCopy
.m_arrowName
;
2371 if (toCopy
.m_metaFile
)
2372 m_metaFile
= new wxPseudoMetaFile(*(toCopy
.m_metaFile
));
2378 wxArrowHead::~wxArrowHead()
2380 if (m_metaFile
) delete m_metaFile
;
2383 void wxArrowHead::SetSize(double size
)
2386 if ((m_arrowType
== ARROW_METAFILE
) && m_metaFile
)
2388 double oldWidth
= m_metaFile
->m_width
;
2389 if (oldWidth
== 0.0)
2392 double scale
= (double)(size
/oldWidth
);
2394 m_metaFile
->Scale(scale
, scale
);
2398 // Can override this to create a different class of label shape
2399 wxLabelShape
* wxLineShape::OnCreateLabelShape(wxLineShape
*parent
, wxShapeRegion
*region
, double w
, double h
)
2401 return new wxLabelShape(parent
, region
, w
, h
);
2409 IMPLEMENT_DYNAMIC_CLASS(wxLabelShape
, wxRectangleShape
)
2411 wxLabelShape::wxLabelShape(wxLineShape
*parent
, wxShapeRegion
*region
, double w
, double h
):wxRectangleShape(w
, h
)
2413 m_lineShape
= parent
;
2414 m_shapeRegion
= region
;
2415 SetPen(wxThePenList
->FindOrCreatePen(wxColour(0, 0, 0), 1, wxDOT
));
2418 wxLabelShape::~wxLabelShape()
2422 void wxLabelShape::OnDraw(wxDC
& dc
)
2424 if (m_lineShape
&& !m_lineShape
->GetDrawHandles())
2427 double x1
= (double)(m_xpos
- m_width
/2.0);
2428 double y1
= (double)(m_ypos
- m_height
/2.0);
2432 if (m_pen
->GetWidth() == 0)
2433 dc
.SetPen(g_oglTransparentPen
);
2437 dc
.SetBrush(wxTRANSPARENT_BRUSH
);
2439 if (m_cornerRadius
> 0.0)
2440 dc
.DrawRoundedRectangle(WXROUND(x1
), WXROUND(y1
), WXROUND(m_width
), WXROUND(m_height
), m_cornerRadius
);
2442 dc
.DrawRectangle(WXROUND(x1
), WXROUND(y1
), WXROUND(m_width
), WXROUND(m_height
));
2445 void wxLabelShape::OnDrawContents(wxDC
& dc
)
2449 void wxLabelShape::OnDragLeft(bool draw
, double x
, double y
, int keys
, int attachment
)
2451 wxRectangleShape::OnDragLeft(draw
, x
, y
, keys
, attachment
);
2454 void wxLabelShape::OnBeginDragLeft(double x
, double y
, int keys
, int attachment
)
2456 wxRectangleShape::OnBeginDragLeft(x
, y
, keys
, attachment
);
2459 void wxLabelShape::OnEndDragLeft(double x
, double y
, int keys
, int attachment
)
2461 wxRectangleShape::OnEndDragLeft(x
, y
, keys
, attachment
);
2464 bool wxLabelShape::OnMovePre(wxDC
& dc
, double x
, double y
, double old_x
, double old_y
, bool display
)
2466 return m_lineShape
->OnLabelMovePre(dc
, this, x
, y
, old_x
, old_y
, display
);
2469 bool wxLineShape::OnLabelMovePre(wxDC
& dc
, wxLabelShape
* labelShape
, double x
, double y
, double old_x
, double old_y
, bool display
)
2471 labelShape
->m_shapeRegion
->SetSize(labelShape
->GetWidth(), labelShape
->GetHeight());
2473 // Find position in line's region list
2475 wxNode
*node
= GetRegions().First();
2478 if (labelShape
->m_shapeRegion
== (wxShapeRegion
*)node
->Data())
2482 node
= node
->Next();
2487 GetLabelPosition(i
, &xx
, &yy
);
2488 // Set the region's offset, relative to the default position for
2490 labelShape
->m_shapeRegion
->SetPosition((double)(x
- xx
), (double)(y
- yy
));
2492 labelShape
->SetX(x
);
2493 labelShape
->SetY(y
);
2495 // Need to reformat to fit region.
2496 if (labelShape
->m_shapeRegion
->GetText())
2499 wxString
s(labelShape
->m_shapeRegion
->GetText());
2500 labelShape
->FormatText(dc
, s
, i
);
2501 DrawRegion(dc
, labelShape
->m_shapeRegion
, xx
, yy
);
2506 // Divert left and right clicks to line object
2507 void wxLabelShape::OnLeftClick(double x
, double y
, int keys
, int attachment
)
2509 m_lineShape
->GetEventHandler()->OnLeftClick(x
, y
, keys
, attachment
);
2512 void wxLabelShape::OnRightClick(double x
, double y
, int keys
, int attachment
)
2514 m_lineShape
->GetEventHandler()->OnRightClick(x
, y
, keys
, attachment
);