1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Basic OGL classes
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "basic.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
28 #include <wx/deprecated/wxexpr.h>
39 #include <wx/ogl/basic.h>
40 #include <wx/ogl/basicp.h>
41 #include <wx/ogl/composit.h>
42 #include <wx/ogl/lines.h>
43 #include <wx/ogl/canvas.h>
44 #include <wx/ogl/divided.h>
45 #include <wx/ogl/misc.h>
47 // Control point types
48 // Rectangle and most other shapes
49 #define CONTROL_POINT_VERTICAL 1
50 #define CONTROL_POINT_HORIZONTAL 2
51 #define CONTROL_POINT_DIAGONAL 3
54 #define CONTROL_POINT_ENDPOINT_TO 4
55 #define CONTROL_POINT_ENDPOINT_FROM 5
56 #define CONTROL_POINT_LINE 6
58 IMPLEMENT_DYNAMIC_CLASS(wxShapeTextLine
, wxObject
)
59 IMPLEMENT_DYNAMIC_CLASS(wxAttachmentPoint
, wxObject
)
61 wxShapeTextLine::wxShapeTextLine(double the_x
, double the_y
, const wxString
& the_line
)
63 m_x
= the_x
; m_y
= the_y
; m_line
= the_line
;
66 wxShapeTextLine::~wxShapeTextLine()
70 IMPLEMENT_ABSTRACT_CLASS(wxShapeEvtHandler
, wxObject
)
72 wxShapeEvtHandler::wxShapeEvtHandler(wxShapeEvtHandler
*prev
, wxShape
*shape
)
74 m_previousHandler
= prev
;
75 m_handlerShape
= shape
;
78 wxShapeEvtHandler::~wxShapeEvtHandler()
82 // Creates a copy of this event handler.
83 wxShapeEvtHandler
* wxShapeEvtHandler::CreateNewCopy()
85 wxShapeEvtHandler
* newObject
= (wxShapeEvtHandler
*) GetClassInfo()->CreateObject();
87 wxASSERT( (newObject
!= NULL
) );
88 wxASSERT( (newObject
->IsKindOf(CLASSINFO(wxShapeEvtHandler
))) );
90 newObject
->m_previousHandler
= newObject
;
98 void wxShapeEvtHandler::OnDelete()
100 if (this != GetShape())
104 void wxShapeEvtHandler::OnDraw(wxDC
& dc
)
106 if (m_previousHandler
)
107 m_previousHandler
->OnDraw(dc
);
110 void wxShapeEvtHandler::OnMoveLinks(wxDC
& dc
)
112 if (m_previousHandler
)
113 m_previousHandler
->OnMoveLinks(dc
);
116 void wxShapeEvtHandler::OnMoveLink(wxDC
& dc
, bool moveControlPoints
)
118 if (m_previousHandler
)
119 m_previousHandler
->OnMoveLink(dc
, moveControlPoints
);
122 void wxShapeEvtHandler::OnDrawContents(wxDC
& dc
)
124 if (m_previousHandler
)
125 m_previousHandler
->OnDrawContents(dc
);
128 void wxShapeEvtHandler::OnDrawBranches(wxDC
& dc
, bool erase
)
130 if (m_previousHandler
)
131 m_previousHandler
->OnDrawBranches(dc
, erase
);
134 void wxShapeEvtHandler::OnSize(double x
, double y
)
136 if (m_previousHandler
)
137 m_previousHandler
->OnSize(x
, y
);
140 bool wxShapeEvtHandler::OnMovePre(wxDC
& dc
, double x
, double y
, double old_x
, double old_y
, bool display
)
142 if (m_previousHandler
)
143 return m_previousHandler
->OnMovePre(dc
, x
, y
, old_x
, old_y
, display
);
148 void wxShapeEvtHandler::OnMovePost(wxDC
& dc
, double x
, double y
, double old_x
, double old_y
, bool display
)
150 if (m_previousHandler
)
151 m_previousHandler
->OnMovePost(dc
, x
, y
, old_x
, old_y
, display
);
154 void wxShapeEvtHandler::OnErase(wxDC
& dc
)
156 if (m_previousHandler
)
157 m_previousHandler
->OnErase(dc
);
160 void wxShapeEvtHandler::OnEraseContents(wxDC
& dc
)
162 if (m_previousHandler
)
163 m_previousHandler
->OnEraseContents(dc
);
166 void wxShapeEvtHandler::OnHighlight(wxDC
& dc
)
168 if (m_previousHandler
)
169 m_previousHandler
->OnHighlight(dc
);
172 void wxShapeEvtHandler::OnLeftClick(double x
, double y
, int keys
, int attachment
)
174 if (m_previousHandler
)
175 m_previousHandler
->OnLeftClick(x
, y
, keys
, attachment
);
178 void wxShapeEvtHandler::OnLeftDoubleClick(double x
, double y
, int keys
, int attachment
)
180 if (m_previousHandler
)
181 m_previousHandler
->OnLeftDoubleClick(x
, y
, keys
, attachment
);
184 void wxShapeEvtHandler::OnRightClick(double x
, double y
, int keys
, int attachment
)
186 if (m_previousHandler
)
187 m_previousHandler
->OnRightClick(x
, y
, keys
, attachment
);
190 void wxShapeEvtHandler::OnDragLeft(bool draw
, double x
, double y
, int keys
, int attachment
)
192 if (m_previousHandler
)
193 m_previousHandler
->OnDragLeft(draw
, x
, y
, keys
, attachment
);
196 void wxShapeEvtHandler::OnBeginDragLeft(double x
, double y
, int keys
, int attachment
)
198 if (m_previousHandler
)
199 m_previousHandler
->OnBeginDragLeft(x
, y
, keys
, attachment
);
202 void wxShapeEvtHandler::OnEndDragLeft(double x
, double y
, int keys
, int attachment
)
204 if (m_previousHandler
)
205 m_previousHandler
->OnEndDragLeft(x
, y
, keys
, attachment
);
208 void wxShapeEvtHandler::OnDragRight(bool draw
, double x
, double y
, int keys
, int attachment
)
210 if (m_previousHandler
)
211 m_previousHandler
->OnDragRight(draw
, x
, y
, keys
, attachment
);
214 void wxShapeEvtHandler::OnBeginDragRight(double x
, double y
, int keys
, int attachment
)
216 if (m_previousHandler
)
217 m_previousHandler
->OnBeginDragRight(x
, y
, keys
, attachment
);
220 void wxShapeEvtHandler::OnEndDragRight(double x
, double y
, int keys
, int attachment
)
222 if (m_previousHandler
)
223 m_previousHandler
->OnEndDragRight(x
, y
, keys
, attachment
);
226 // Control points ('handles') redirect control to the actual shape, to make it easier
227 // to override sizing behaviour.
228 void wxShapeEvtHandler::OnSizingDragLeft(wxControlPoint
* pt
, bool draw
, double x
, double y
, int keys
, int attachment
)
230 if (m_previousHandler
)
231 m_previousHandler
->OnSizingDragLeft(pt
, draw
, x
, y
, keys
, attachment
);
234 void wxShapeEvtHandler::OnSizingBeginDragLeft(wxControlPoint
* pt
, double x
, double y
, int keys
, int attachment
)
236 if (m_previousHandler
)
237 m_previousHandler
->OnSizingBeginDragLeft(pt
, x
, y
, keys
, attachment
);
240 void wxShapeEvtHandler::OnSizingEndDragLeft(wxControlPoint
* pt
, double x
, double y
, int keys
, int attachment
)
242 if (m_previousHandler
)
243 m_previousHandler
->OnSizingEndDragLeft(pt
, x
, y
, keys
, attachment
);
246 void wxShapeEvtHandler::OnDrawOutline(wxDC
& dc
, double x
, double y
, double w
, double h
)
248 if (m_previousHandler
)
249 m_previousHandler
->OnDrawOutline(dc
, x
, y
, w
, h
);
252 void wxShapeEvtHandler::OnDrawControlPoints(wxDC
& dc
)
254 if (m_previousHandler
)
255 m_previousHandler
->OnDrawControlPoints(dc
);
258 void wxShapeEvtHandler::OnEraseControlPoints(wxDC
& dc
)
260 if (m_previousHandler
)
261 m_previousHandler
->OnEraseControlPoints(dc
);
264 // Can override this to prevent or intercept line reordering.
265 void wxShapeEvtHandler::OnChangeAttachment(int attachment
, wxLineShape
* line
, wxList
& ordering
)
267 if (m_previousHandler
)
268 m_previousHandler
->OnChangeAttachment(attachment
, line
, ordering
);
271 IMPLEMENT_ABSTRACT_CLASS(wxShape
, wxShapeEvtHandler
)
273 wxShape::wxShape(wxShapeCanvas
*can
)
275 m_eventHandler
= this;
280 m_xpos
= 0.0; m_ypos
= 0.0;
281 m_pen
= g_oglBlackPen
;
282 m_brush
= wxWHITE_BRUSH
;
283 m_font
= g_oglNormalFont
;
284 m_textColour
= wxBLACK
;
285 m_textColourName
= wxT("BLACK");
288 m_attachmentMode
= ATTACHMENT_MODE_NONE
;
289 m_spaceAttachments
= TRUE
;
290 m_disableLabel
= FALSE
;
291 m_fixedWidth
= FALSE
;
292 m_fixedHeight
= FALSE
;
293 m_drawHandles
= TRUE
;
294 m_sensitivity
= OP_ALL
;
297 m_formatMode
= FORMAT_CENTRE_HORIZ
| FORMAT_CENTRE_VERT
;
298 m_shadowMode
= SHADOW_NONE
;
301 m_shadowBrush
= wxBLACK_BRUSH
;
304 m_regionName
= wxT("0");
305 m_centreResize
= TRUE
;
306 m_maintainAspectRatio
= FALSE
;
307 m_highlighted
= FALSE
;
309 m_branchNeckLength
= 10;
310 m_branchStemLength
= 10;
311 m_branchSpacing
= 10;
312 m_branchStyle
= BRANCHING_ATTACHMENT_NORMAL
;
314 // Set up a default region. Much of the above will be put into
315 // the region eventually (the duplication is for compatibility)
316 wxShapeRegion
*region
= new wxShapeRegion
;
317 m_regions
.Append(region
);
318 region
->SetName(wxT("0"));
319 region
->SetFont(g_oglNormalFont
);
320 region
->SetFormatMode(FORMAT_CENTRE_HORIZ
| FORMAT_CENTRE_VERT
);
321 region
->SetColour(wxT("BLACK"));
327 m_parent
->GetChildren().DeleteObject(this);
334 m_canvas
->RemoveShape(this);
336 GetEventHandler()->OnDelete();
339 void wxShape::SetHighlight(bool hi
, bool recurse
)
344 wxNode
*node
= m_children
.GetFirst();
347 wxShape
*child
= (wxShape
*)node
->GetData();
348 child
->SetHighlight(hi
, recurse
);
349 node
= node
->GetNext();
354 void wxShape::SetSensitivityFilter(int sens
, bool recursive
)
356 if (sens
& OP_DRAG_LEFT
)
361 m_sensitivity
= sens
;
364 wxNode
*node
= m_children
.GetFirst();
367 wxShape
*obj
= (wxShape
*)node
->GetData();
368 obj
->SetSensitivityFilter(sens
, TRUE
);
369 node
= node
->GetNext();
374 void wxShape::SetDraggable(bool drag
, bool recursive
)
378 m_sensitivity
|= OP_DRAG_LEFT
;
380 if (m_sensitivity
& OP_DRAG_LEFT
)
381 m_sensitivity
= m_sensitivity
- OP_DRAG_LEFT
;
385 wxNode
*node
= m_children
.GetFirst();
388 wxShape
*obj
= (wxShape
*)node
->GetData();
389 obj
->SetDraggable(drag
, TRUE
);
390 node
= node
->GetNext();
395 void wxShape::SetDrawHandles(bool drawH
)
397 m_drawHandles
= drawH
;
398 wxNode
*node
= m_children
.GetFirst();
401 wxShape
*obj
= (wxShape
*)node
->GetData();
402 obj
->SetDrawHandles(drawH
);
403 node
= node
->GetNext();
407 void wxShape::SetShadowMode(int mode
, bool redraw
)
409 if (redraw
&& GetCanvas())
411 wxClientDC
dc(GetCanvas());
412 GetCanvas()->PrepareDC(dc
);
425 void wxShape::SetCanvas(wxShapeCanvas
*theCanvas
)
427 m_canvas
= theCanvas
;
428 wxNode
*node
= m_children
.GetFirst();
431 wxShape
*child
= (wxShape
*)node
->GetData();
432 child
->SetCanvas(theCanvas
);
433 node
= node
->GetNext();
437 void wxShape::AddToCanvas(wxShapeCanvas
*theCanvas
, wxShape
*addAfter
)
439 theCanvas
->AddShape(this, addAfter
);
440 wxNode
*node
= m_children
.GetFirst();
441 wxShape
*lastImage
= this;
444 wxShape
*object
= (wxShape
*)node
->GetData();
445 object
->AddToCanvas(theCanvas
, lastImage
);
448 node
= node
->GetNext();
452 // Insert at front of canvas
453 void wxShape::InsertInCanvas(wxShapeCanvas
*theCanvas
)
455 theCanvas
->InsertShape(this);
456 wxNode
*node
= m_children
.GetFirst();
457 wxShape
*lastImage
= this;
460 wxShape
*object
= (wxShape
*)node
->GetData();
461 object
->AddToCanvas(theCanvas
, lastImage
);
464 node
= node
->GetNext();
468 void wxShape::RemoveFromCanvas(wxShapeCanvas
*theCanvas
)
472 theCanvas
->RemoveShape(this);
473 wxNode
*node
= m_children
.GetFirst();
476 wxShape
*object
= (wxShape
*)node
->GetData();
477 object
->RemoveFromCanvas(theCanvas
);
479 node
= node
->GetNext();
483 void wxShape::ClearAttachments()
485 wxNode
*node
= m_attachmentPoints
.GetFirst();
488 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->GetData();
490 node
= node
->GetNext();
492 m_attachmentPoints
.Clear();
495 void wxShape::ClearText(int regionId
)
499 m_text
.DeleteContents(TRUE
);
501 m_text
.DeleteContents(FALSE
);
503 wxNode
*node
= m_regions
.Item(regionId
);
506 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
510 void wxShape::ClearRegions()
512 wxNode
*node
= m_regions
.GetFirst();
515 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
516 wxNode
*next
= node
->GetNext();
523 void wxShape::AddRegion(wxShapeRegion
*region
)
525 m_regions
.Append(region
);
528 void wxShape::SetDefaultRegionSize()
530 wxNode
*node
= m_regions
.GetFirst();
532 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
534 GetBoundingBoxMin(&w
, &h
);
535 region
->SetSize(w
, h
);
538 bool wxShape::HitTest(double x
, double y
, int *attachment
, double *distance
)
543 double width
= 0.0, height
= 0.0;
544 GetBoundingBoxMin(&width
, &height
);
545 if (fabs(width
) < 4.0) width
= 4.0;
546 if (fabs(height
) < 4.0) height
= 4.0;
548 width
+= (double)4.0; height
+= (double)4.0; // Allowance for inaccurate mousing
550 double left
= (double)(m_xpos
- (width
/2.0));
551 double top
= (double)(m_ypos
- (height
/2.0));
552 double right
= (double)(m_xpos
+ (width
/2.0));
553 double bottom
= (double)(m_ypos
+ (height
/2.0));
555 int nearest_attachment
= 0;
557 // If within the bounding box, check the attachment points
558 // within the object.
560 if (x
>= left
&& x
<= right
&& y
>= top
&& y
<= bottom
)
562 int n
= GetNumberOfAttachments();
563 double nearest
= 999999.0;
565 // GetAttachmentPosition[Edge] takes a logical attachment position,
566 // i.e. if it's rotated through 90%, position 0 is East-facing.
568 for (int i
= 0; i
< n
; i
++)
571 if (GetAttachmentPositionEdge(i
, &xp
, &yp
))
573 double l
= (double)sqrt(((xp
- x
) * (xp
- x
)) +
574 ((yp
- y
) * (yp
- y
)));
579 nearest_attachment
= i
;
583 *attachment
= nearest_attachment
;
590 // Format a text string according to the region size, adding
591 // strings with positions to region text list
593 static bool GraphicsInSizeToContents
= FALSE
; // Infinite recursion elimination
594 void wxShape::FormatText(wxDC
& dc
, const wxString
& s
, int i
)
599 if (m_regions
.GetCount() < 1)
601 wxNode
*node
= m_regions
.Item(i
);
605 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
606 // region->SetText(s); // don't set the formatted text yet, it will be done below
607 region
->m_regionText
= s
;
608 dc
.SetFont(* region
->GetFont());
610 region
->GetSize(&w
, &h
);
612 wxStringList
*stringList
= oglFormatText(dc
, s
, (w
-5), (h
-5), region
->GetFormatMode());
613 node
= (wxNode
*)stringList
->GetFirst();
616 wxChar
*s
= (wxChar
*)node
->GetData();
617 wxShapeTextLine
*line
= new wxShapeTextLine(0.0, 0.0, s
);
618 region
->GetFormattedText().Append((wxObject
*)line
);
619 node
= node
->GetNext();
624 // Don't try to resize an object with more than one image (this case should be dealt
625 // with by overriden handlers)
626 if ((region
->GetFormatMode() & FORMAT_SIZE_TO_CONTENTS
) &&
627 (region
->GetFormattedText().GetCount() > 0) &&
628 (m_regions
.GetCount() == 1) && !GraphicsInSizeToContents
)
630 oglGetCentredTextExtent(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, w
, h
, &actualW
, &actualH
);
631 if ((actualW
+m_textMarginX
!= w
) || (actualH
+m_textMarginY
!= h
))
633 // If we are a descendant of a composite, must make sure the composite gets
635 wxShape
*topAncestor
= GetTopAncestor();
637 if (topAncestor
!= this)
639 // Make sure we don't recurse infinitely
640 GraphicsInSizeToContents
= TRUE
;
642 wxCompositeShape
*composite
= (wxCompositeShape
*)topAncestor
;
643 composite
->Erase(dc
);
644 SetSize(actualW
+m_textMarginX
, actualH
+m_textMarginY
);
645 Move(dc
, m_xpos
, m_ypos
);
646 composite
->CalculateSize();
647 if (composite
->Selected())
649 composite
->DeleteControlPoints(& dc
);
650 composite
->MakeControlPoints();
651 composite
->MakeMandatoryControlPoints();
653 // Where infinite recursion might happen if we didn't stop it
656 GraphicsInSizeToContents
= FALSE
;
661 SetSize(actualW
+m_textMarginX
, actualH
+m_textMarginY
);
662 Move(dc
, m_xpos
, m_ypos
);
664 SetSize(actualW
+m_textMarginX
, actualH
+m_textMarginY
);
665 Move(dc
, m_xpos
, m_ypos
);
669 oglCentreText(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, actualW
, actualH
, region
->GetFormatMode());
673 void wxShape::Recentre(wxDC
& dc
)
676 GetBoundingBoxMin(&w
, &h
);
678 int noRegions
= m_regions
.GetCount();
679 for (int i
= 0; i
< noRegions
; i
++)
681 wxNode
*node
= m_regions
.Item(i
);
684 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
685 oglCentreText(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, w
, h
, region
->GetFormatMode());
690 bool wxShape::GetPerimeterPoint(double x1
, double y1
,
691 double x2
, double y2
,
692 double *x3
, double *y3
)
697 void wxShape::SetPen(wxPen
*the_pen
)
702 void wxShape::SetBrush(wxBrush
*the_brush
)
707 // Get the top-most (non-division) ancestor, or self
708 wxShape
*wxShape::GetTopAncestor()
713 if (GetParent()->IsKindOf(CLASSINFO(wxDivisionShape
)))
715 else return GetParent()->GetTopAncestor();
722 void wxShape::SetFont(wxFont
*the_font
, int regionId
)
725 wxNode
*node
= m_regions
.Item(regionId
);
728 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
729 region
->SetFont(the_font
);
732 wxFont
*wxShape::GetFont(int n
) const
734 wxNode
*node
= m_regions
.Item(n
);
737 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
738 return region
->GetFont();
741 void wxShape::SetFormatMode(int mode
, int regionId
)
743 wxNode
*node
= m_regions
.Item(regionId
);
746 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
747 region
->SetFormatMode(mode
);
750 int wxShape::GetFormatMode(int regionId
) const
752 wxNode
*node
= m_regions
.Item(regionId
);
755 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
756 return region
->GetFormatMode();
759 void wxShape::SetTextColour(const wxString
& the_colour
, int regionId
)
761 wxColour
*wxcolour
= wxTheColourDatabase
->FindColour(the_colour
);
762 m_textColour
= wxcolour
;
763 m_textColourName
= the_colour
;
765 wxNode
*node
= m_regions
.Item(regionId
);
768 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
769 region
->SetColour(the_colour
);
772 wxString
wxShape::GetTextColour(int regionId
) const
774 wxNode
*node
= m_regions
.Item(regionId
);
776 return wxEmptyString
;
777 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
778 return region
->GetColour();
781 void wxShape::SetRegionName(const wxString
& name
, int regionId
)
783 wxNode
*node
= m_regions
.Item(regionId
);
786 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
787 region
->SetName(name
);
790 wxString
wxShape::GetRegionName(int regionId
)
792 wxNode
*node
= m_regions
.Item(regionId
);
794 return wxEmptyString
;
795 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
796 return region
->GetName();
799 int wxShape::GetRegionId(const wxString
& name
)
801 wxNode
*node
= m_regions
.GetFirst();
805 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
806 if (region
->GetName() == name
)
808 node
= node
->GetNext();
814 // Name all m_regions in all subimages recursively.
815 void wxShape::NameRegions(const wxString
& parentName
)
817 int n
= GetNumberOfTextRegions();
819 for (int i
= 0; i
< n
; i
++)
821 if (parentName
.Length() > 0)
822 buff
<< parentName
<< wxT(".") << i
;
825 SetRegionName(buff
, i
);
827 wxNode
*node
= m_children
.GetFirst();
832 wxShape
*child
= (wxShape
*)node
->GetData();
833 if (parentName
.Length() > 0)
834 buff
<< parentName
<< wxT(".") << j
;
837 child
->NameRegions(buff
);
838 node
= node
->GetNext();
843 // Get a region by name, possibly looking recursively into composites.
844 wxShape
*wxShape::FindRegion(const wxString
& name
, int *regionId
)
846 int id
= GetRegionId(name
);
853 wxNode
*node
= m_children
.GetFirst();
856 wxShape
*child
= (wxShape
*)node
->GetData();
857 wxShape
*actualImage
= child
->FindRegion(name
, regionId
);
860 node
= node
->GetNext();
865 // Finds all region names for this image (composite or simple).
866 // Supply empty string list.
867 void wxShape::FindRegionNames(wxStringList
& list
)
869 int n
= GetNumberOfTextRegions();
870 for (int i
= 0; i
< n
; i
++)
872 wxString
name(GetRegionName(i
));
876 wxNode
*node
= m_children
.GetFirst();
879 wxShape
*child
= (wxShape
*)node
->GetData();
880 child
->FindRegionNames(list
);
881 node
= node
->GetNext();
885 void wxShape::AssignNewIds()
889 wxNode
*node
= m_children
.GetFirst();
892 wxShape
*child
= (wxShape
*)node
->GetData();
893 child
->AssignNewIds();
894 node
= node
->GetNext();
898 void wxShape::OnDraw(wxDC
& dc
)
902 void wxShape::OnMoveLinks(wxDC
& dc
)
904 // Want to set the ends of all attached links
905 // to point to/from this object
907 wxNode
*current
= m_lines
.GetFirst();
910 wxLineShape
*line
= (wxLineShape
*)current
->GetData();
911 line
->GetEventHandler()->OnMoveLink(dc
);
912 current
= current
->GetNext();
917 void wxShape::OnDrawContents(wxDC
& dc
)
919 double bound_x
, bound_y
;
920 GetBoundingBoxMin(&bound_x
, &bound_y
);
921 if (m_regions
.GetCount() < 1) return;
923 if (m_pen
) dc
.SetPen(* m_pen
);
925 wxShapeRegion
*region
= (wxShapeRegion
*)m_regions
.GetFirst()->GetData();
926 if (region
->GetFont()) dc
.SetFont(* region
->GetFont());
928 dc
.SetTextForeground(* (region
->GetActualColourObject()));
929 dc
.SetBackgroundMode(wxTRANSPARENT
);
932 oglCentreText(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, bound_x
, bound_y
, region
->GetFormatMode());
935 if (!GetDisableLabel())
937 oglDrawFormattedText(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, bound_x
, bound_y
, region
->GetFormatMode());
941 void wxShape::DrawContents(wxDC
& dc
)
943 GetEventHandler()->OnDrawContents(dc
);
946 void wxShape::OnSize(double x
, double y
)
950 bool wxShape::OnMovePre(wxDC
& dc
, double x
, double y
, double old_x
, double old_y
, bool display
)
955 void wxShape::OnMovePost(wxDC
& dc
, double x
, double y
, double old_x
, double old_y
, bool display
)
959 void wxShape::OnErase(wxDC
& dc
)
965 wxNode
*current
= m_lines
.GetFirst();
968 wxLineShape
*line
= (wxLineShape
*)current
->GetData();
969 line
->GetEventHandler()->OnErase(dc
);
970 current
= current
->GetNext();
972 GetEventHandler()->OnEraseContents(dc
);
975 void wxShape::OnEraseContents(wxDC
& dc
)
980 double maxX
, maxY
, minX
, minY
;
983 GetBoundingBoxMin(&minX
, &minY
);
984 GetBoundingBoxMax(&maxX
, &maxY
);
985 double topLeftX
= (double)(xp
- (maxX
/ 2.0) - 2.0);
986 double topLeftY
= (double)(yp
- (maxY
/ 2.0) - 2.0);
990 penWidth
= m_pen
->GetWidth();
992 dc
.SetPen(GetBackgroundPen());
993 dc
.SetBrush(GetBackgroundBrush());
995 dc
.DrawRectangle(WXROUND(topLeftX
- penWidth
), WXROUND(topLeftY
- penWidth
),
996 WXROUND(maxX
+ penWidth
*2.0 + 4.0), WXROUND(maxY
+ penWidth
*2.0 + 4.0));
999 void wxShape::EraseLinks(wxDC
& dc
, int attachment
, bool recurse
)
1004 wxNode
*current
= m_lines
.GetFirst();
1007 wxLineShape
*line
= (wxLineShape
*)current
->GetData();
1008 if (attachment
== -1 || ((line
->GetTo() == this && line
->GetAttachmentTo() == attachment
) ||
1009 (line
->GetFrom() == this && line
->GetAttachmentFrom() == attachment
)))
1010 line
->GetEventHandler()->OnErase(dc
);
1011 current
= current
->GetNext();
1015 wxNode
*node
= m_children
.GetFirst();
1018 wxShape
*child
= (wxShape
*)node
->GetData();
1019 child
->EraseLinks(dc
, attachment
, recurse
);
1020 node
= node
->GetNext();
1025 void wxShape::DrawLinks(wxDC
& dc
, int attachment
, bool recurse
)
1030 wxNode
*current
= m_lines
.GetFirst();
1033 wxLineShape
*line
= (wxLineShape
*)current
->GetData();
1034 if (attachment
== -1 ||
1035 (line
->GetTo() == this && line
->GetAttachmentTo() == attachment
) ||
1036 (line
->GetFrom() == this && line
->GetAttachmentFrom() == attachment
))
1038 current
= current
->GetNext();
1042 wxNode
*node
= m_children
.GetFirst();
1045 wxShape
*child
= (wxShape
*)node
->GetData();
1046 child
->DrawLinks(dc
, attachment
, recurse
);
1047 node
= node
->GetNext();
1052 // Returns TRUE if pt1 <= pt2 in the sense that one point comes before another on an
1053 // edge of the shape.
1054 // attachmentPoint is the attachment point (= side) in question.
1056 // This is the default, rectangular implementation.
1057 bool wxShape::AttachmentSortTest(int attachmentPoint
, const wxRealPoint
& pt1
, const wxRealPoint
& pt2
)
1059 int physicalAttachment
= LogicalToPhysicalAttachment(attachmentPoint
);
1060 switch (physicalAttachment
)
1065 return (pt1
.x
<= pt2
.x
) ;
1071 return (pt1
.y
<= pt2
.y
) ;
1079 bool wxShape::MoveLineToNewAttachment(wxDC
& dc
, wxLineShape
*to_move
,
1082 if (GetAttachmentMode() == ATTACHMENT_MODE_NONE
)
1085 int newAttachment
, oldAttachment
;
1088 // Is (x, y) on this object? If so, find the new attachment point
1089 // the user has moved the point to
1090 bool hit
= HitTest(x
, y
, &newAttachment
, &distance
);
1096 if (to_move
->GetTo() == this)
1097 oldAttachment
= to_move
->GetAttachmentTo();
1099 oldAttachment
= to_move
->GetAttachmentFrom();
1101 // The links in a new ordering.
1104 // First, add all links to the new list.
1105 wxNode
*node
= m_lines
.GetFirst();
1108 newOrdering
.Append(node
->GetData());
1109 node
= node
->GetNext();
1112 // Delete the line object from the list of links; we're going to move
1113 // it to another position in the list
1114 newOrdering
.DeleteObject(to_move
);
1116 double old_x
= (double) -99999.9;
1117 double old_y
= (double) -99999.9;
1119 node
= newOrdering
.GetFirst();
1122 while (!found
&& node
)
1124 wxLineShape
*line
= (wxLineShape
*)node
->GetData();
1125 if ((line
->GetTo() == this && oldAttachment
== line
->GetAttachmentTo()) ||
1126 (line
->GetFrom() == this && oldAttachment
== line
->GetAttachmentFrom()))
1128 double startX
, startY
, endX
, endY
;
1130 line
->GetEnds(&startX
, &startY
, &endX
, &endY
);
1131 if (line
->GetTo() == this)
1141 wxRealPoint
thisPoint(xp
, yp
);
1142 wxRealPoint
lastPoint(old_x
, old_y
);
1143 wxRealPoint
newPoint(x
, y
);
1145 if (AttachmentSortTest(newAttachment
, newPoint
, thisPoint
) && AttachmentSortTest(newAttachment
, lastPoint
, newPoint
))
1148 newOrdering
.Insert(node
, to_move
);
1154 node
= node
->GetNext();
1158 newOrdering
.Append(to_move
);
1160 GetEventHandler()->OnChangeAttachment(newAttachment
, to_move
, newOrdering
);
1165 void wxShape::OnChangeAttachment(int attachment
, wxLineShape
* line
, wxList
& ordering
)
1167 if (line
->GetTo() == this)
1168 line
->SetAttachmentTo(attachment
);
1170 line
->SetAttachmentFrom(attachment
);
1172 ApplyAttachmentOrdering(ordering
);
1174 wxClientDC
dc(GetCanvas());
1175 GetCanvas()->PrepareDC(dc
);
1179 if (!GetCanvas()->GetQuickEditMode()) GetCanvas()->Redraw(dc
);
1182 // Reorders the lines according to the given list.
1183 void wxShape::ApplyAttachmentOrdering(wxList
& linesToSort
)
1185 // This is a temporary store of all the lines.
1188 wxNode
*node
= m_lines
.GetFirst();
1191 wxLineShape
*line
= (wxLineShape
*)node
->GetData();
1192 linesStore
.Append(line
);
1193 node
= node
->GetNext();;
1198 node
= linesToSort
.GetFirst();
1201 wxLineShape
*line
= (wxLineShape
*)node
->GetData();
1202 if (linesStore
.Member(line
))
1205 linesStore
.DeleteObject(line
);
1206 m_lines
.Append(line
);
1208 node
= node
->GetNext();
1211 // Now add any lines that haven't been listed in linesToSort.
1212 node
= linesStore
.GetFirst();
1215 wxLineShape
*line
= (wxLineShape
*)node
->GetData();
1216 m_lines
.Append(line
);
1217 node
= node
->GetNext();
1221 // Reorders the lines coming into the node image at this attachment
1222 // position, in the order in which they appear in linesToSort.
1223 // Any remaining lines not in the list will be added to the end.
1224 void wxShape::SortLines(int attachment
, wxList
& linesToSort
)
1226 // This is a temporary store of all the lines at this attachment
1227 // point. We'll tick them off as we've processed them.
1228 wxList linesAtThisAttachment
;
1230 wxNode
*node
= m_lines
.GetFirst();
1233 wxLineShape
*line
= (wxLineShape
*)node
->GetData();
1234 wxNode
*next
= node
->GetNext();
1235 if ((line
->GetTo() == this && line
->GetAttachmentTo() == attachment
) ||
1236 (line
->GetFrom() == this && line
->GetAttachmentFrom() == attachment
))
1238 linesAtThisAttachment
.Append(line
);
1242 else node
= node
->GetNext();
1245 node
= linesToSort
.GetFirst();
1248 wxLineShape
*line
= (wxLineShape
*)node
->GetData();
1249 if (linesAtThisAttachment
.Member(line
))
1252 linesAtThisAttachment
.DeleteObject(line
);
1253 m_lines
.Append(line
);
1255 node
= node
->GetNext();
1258 // Now add any lines that haven't been listed in linesToSort.
1259 node
= linesAtThisAttachment
.GetFirst();
1262 wxLineShape
*line
= (wxLineShape
*)node
->GetData();
1263 m_lines
.Append(line
);
1264 node
= node
->GetNext();
1268 void wxShape::OnHighlight(wxDC
& dc
)
1272 void wxShape::OnLeftClick(double x
, double y
, int keys
, int attachment
)
1274 if ((m_sensitivity
& OP_CLICK_LEFT
) != OP_CLICK_LEFT
)
1280 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1281 m_parent
->GetEventHandler()->OnLeftClick(x
, y
, keys
, attachment
);
1287 void wxShape::OnRightClick(double x
, double y
, int keys
, int attachment
)
1289 if ((m_sensitivity
& OP_CLICK_RIGHT
) != OP_CLICK_RIGHT
)
1295 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1296 m_parent
->GetEventHandler()->OnRightClick(x
, y
, keys
, attachment
);
1302 double DragOffsetX
= 0.0;
1303 double DragOffsetY
= 0.0;
1305 void wxShape::OnDragLeft(bool draw
, double x
, double y
, int keys
, int attachment
)
1307 if ((m_sensitivity
& OP_DRAG_LEFT
) != OP_DRAG_LEFT
)
1313 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1314 m_parent
->GetEventHandler()->OnDragLeft(draw
, x
, y
, keys
, attachment
);
1319 wxClientDC
dc(GetCanvas());
1320 GetCanvas()->PrepareDC(dc
);
1322 dc
.SetLogicalFunction(OGLRBLF
);
1324 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
1325 dc
.SetPen(dottedPen
);
1326 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1329 xx
= x
+ DragOffsetX
;
1330 yy
= y
+ DragOffsetY
;
1332 m_canvas
->Snap(&xx
, &yy
);
1333 // m_xpos = xx; m_ypos = yy;
1335 GetBoundingBoxMax(&w
, &h
);
1336 GetEventHandler()->OnDrawOutline(dc
, xx
, yy
, w
, h
);
1339 void wxShape::OnBeginDragLeft(double x
, double y
, int keys
, int attachment
)
1341 if ((m_sensitivity
& OP_DRAG_LEFT
) != OP_DRAG_LEFT
)
1347 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1348 m_parent
->GetEventHandler()->OnBeginDragLeft(x
, y
, keys
, attachment
);
1353 DragOffsetX
= m_xpos
- x
;
1354 DragOffsetY
= m_ypos
- y
;
1356 wxClientDC
dc(GetCanvas());
1357 GetCanvas()->PrepareDC(dc
);
1359 // New policy: don't erase shape until end of drag.
1363 xx
= x
+ DragOffsetX
;
1364 yy
= y
+ DragOffsetY
;
1365 m_canvas
->Snap(&xx
, &yy
);
1366 // m_xpos = xx; m_ypos = yy;
1367 dc
.SetLogicalFunction(OGLRBLF
);
1369 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
1370 dc
.SetPen(dottedPen
);
1371 dc
.SetBrush((* wxTRANSPARENT_BRUSH
));
1374 GetBoundingBoxMax(&w
, &h
);
1375 GetEventHandler()->OnDrawOutline(dc
, xx
, yy
, w
, h
);
1376 m_canvas
->CaptureMouse();
1379 void wxShape::OnEndDragLeft(double x
, double y
, int keys
, int attachment
)
1381 m_canvas
->ReleaseMouse();
1382 if ((m_sensitivity
& OP_DRAG_LEFT
) != OP_DRAG_LEFT
)
1388 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1389 m_parent
->GetEventHandler()->OnEndDragLeft(x
, y
, keys
, attachment
);
1394 wxClientDC
dc(GetCanvas());
1395 GetCanvas()->PrepareDC(dc
);
1397 dc
.SetLogicalFunction(wxCOPY
);
1399 double xx
= x
+ DragOffsetX
;
1400 double yy
= y
+ DragOffsetY
;
1401 m_canvas
->Snap(&xx
, &yy
);
1402 // canvas->Snap(&m_xpos, &m_ypos);
1404 // New policy: erase shape at end of drag.
1408 if (m_canvas
&& !m_canvas
->GetQuickEditMode()) m_canvas
->Redraw(dc
);
1411 void wxShape::OnDragRight(bool draw
, double x
, double y
, int keys
, int attachment
)
1413 if ((m_sensitivity
& OP_DRAG_RIGHT
) != OP_DRAG_RIGHT
)
1419 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1420 m_parent
->GetEventHandler()->OnDragRight(draw
, x
, y
, keys
, attachment
);
1426 void wxShape::OnBeginDragRight(double x
, double y
, int keys
, int attachment
)
1428 if ((m_sensitivity
& OP_DRAG_RIGHT
) != OP_DRAG_RIGHT
)
1434 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1435 m_parent
->GetEventHandler()->OnBeginDragRight(x
, y
, keys
, attachment
);
1441 void wxShape::OnEndDragRight(double x
, double y
, int keys
, int attachment
)
1443 if ((m_sensitivity
& OP_DRAG_RIGHT
) != OP_DRAG_RIGHT
)
1449 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1450 m_parent
->GetEventHandler()->OnEndDragRight(x
, y
, keys
, attachment
);
1456 void wxShape::OnDrawOutline(wxDC
& dc
, double x
, double y
, double w
, double h
)
1458 double top_left_x
= (double)(x
- w
/2.0);
1459 double top_left_y
= (double)(y
- h
/2.0);
1460 double top_right_x
= (double)(top_left_x
+ w
);
1461 double top_right_y
= (double)top_left_y
;
1462 double bottom_left_x
= (double)top_left_x
;
1463 double bottom_left_y
= (double)(top_left_y
+ h
);
1464 double bottom_right_x
= (double)top_right_x
;
1465 double bottom_right_y
= (double)bottom_left_y
;
1468 points
[0].x
= WXROUND(top_left_x
); points
[0].y
= WXROUND(top_left_y
);
1469 points
[1].x
= WXROUND(top_right_x
); points
[1].y
= WXROUND(top_right_y
);
1470 points
[2].x
= WXROUND(bottom_right_x
); points
[2].y
= WXROUND(bottom_right_y
);
1471 points
[3].x
= WXROUND(bottom_left_x
); points
[3].y
= WXROUND(bottom_left_y
);
1472 points
[4].x
= WXROUND(top_left_x
); points
[4].y
= WXROUND(top_left_y
);
1474 dc
.DrawLines(5, points
);
1477 void wxShape::Attach(wxShapeCanvas
*can
)
1482 void wxShape::Detach()
1487 void wxShape::Move(wxDC
& dc
, double x
, double y
, bool display
)
1489 double old_x
= m_xpos
;
1490 double old_y
= m_ypos
;
1492 if (!GetEventHandler()->OnMovePre(dc
, x
, y
, old_x
, old_y
, display
))
1499 m_xpos
= x
; m_ypos
= y
;
1501 ResetControlPoints();
1508 GetEventHandler()->OnMovePost(dc
, x
, y
, old_x
, old_y
, display
);
1511 void wxShape::MoveLinks(wxDC
& dc
)
1513 GetEventHandler()->OnMoveLinks(dc
);
1517 void wxShape::Draw(wxDC
& dc
)
1521 GetEventHandler()->OnDraw(dc
);
1522 GetEventHandler()->OnDrawContents(dc
);
1523 GetEventHandler()->OnDrawControlPoints(dc
);
1524 GetEventHandler()->OnDrawBranches(dc
);
1528 void wxShape::Flash()
1532 wxClientDC
dc(GetCanvas());
1533 GetCanvas()->PrepareDC(dc
);
1535 dc
.SetLogicalFunction(OGLRBLF
);
1537 dc
.SetLogicalFunction(wxCOPY
);
1542 void wxShape::Show(bool show
)
1545 wxNode
*node
= m_children
.GetFirst();
1548 wxShape
*image
= (wxShape
*)node
->GetData();
1550 node
= node
->GetNext();
1554 void wxShape::Erase(wxDC
& dc
)
1556 GetEventHandler()->OnErase(dc
);
1557 GetEventHandler()->OnEraseControlPoints(dc
);
1558 GetEventHandler()->OnDrawBranches(dc
, TRUE
);
1561 void wxShape::EraseContents(wxDC
& dc
)
1563 GetEventHandler()->OnEraseContents(dc
);
1566 void wxShape::AddText(const wxString
& string
)
1568 wxNode
*node
= m_regions
.GetFirst();
1571 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
1572 region
->ClearText();
1573 wxShapeTextLine
*new_line
=
1574 new wxShapeTextLine(0.0, 0.0, string
);
1575 region
->GetFormattedText().Append(new_line
);
1577 m_formatted
= FALSE
;
1580 void wxShape::SetSize(double x
, double y
, bool recursive
)
1582 SetAttachmentSize(x
, y
);
1583 SetDefaultRegionSize();
1586 void wxShape::SetAttachmentSize(double w
, double h
)
1590 double width
, height
;
1591 GetBoundingBoxMin(&width
, &height
);
1594 else scaleX
= w
/width
;
1597 else scaleY
= h
/height
;
1599 wxNode
*node
= m_attachmentPoints
.GetFirst();
1602 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->GetData();
1603 point
->m_x
= (double)(point
->m_x
* scaleX
);
1604 point
->m_y
= (double)(point
->m_y
* scaleY
);
1605 node
= node
->GetNext();
1609 // Add line FROM this object
1610 void wxShape::AddLine(wxLineShape
*line
, wxShape
*other
,
1611 int attachFrom
, int attachTo
,
1612 // The line ordering
1613 int positionFrom
, int positionTo
)
1615 if (positionFrom
== -1)
1617 if (!m_lines
.Member(line
))
1618 m_lines
.Append(line
);
1622 // Don't preserve old ordering if we have new ordering instructions
1623 m_lines
.DeleteObject(line
);
1624 if (positionFrom
< m_lines
.GetCount())
1626 wxNode
* node
= m_lines
.Item(positionFrom
);
1627 m_lines
.Insert(node
, line
);
1630 m_lines
.Append(line
);
1633 if (positionTo
== -1)
1635 if (!other
->m_lines
.Member(line
))
1636 other
->m_lines
.Append(line
);
1640 // Don't preserve old ordering if we have new ordering instructions
1641 other
->m_lines
.DeleteObject(line
);
1642 if (positionTo
< other
->m_lines
.GetCount())
1644 wxNode
* node
= other
->m_lines
.Item(positionTo
);
1645 other
->m_lines
.Insert(node
, line
);
1648 other
->m_lines
.Append(line
);
1651 // Wrong: doesn't preserve ordering of shape already linked
1652 m_lines
.DeleteObject(line
);
1653 other
->m_lines
.DeleteObject(line
);
1655 if (positionFrom
== -1)
1656 m_lines
.Append(line
);
1659 if (positionFrom
< m_lines
.GetCount())
1661 wxNode
* node
= m_lines
.Item(positionFrom
);
1662 m_lines
.Insert(node
, line
);
1665 m_lines
.Append(line
);
1668 if (positionTo
== -1)
1669 other
->m_lines
.Append(line
);
1672 if (positionTo
< other
->m_lines
.GetCount())
1674 wxNode
* node
= other
->m_lines
.Item(positionTo
);
1675 other
->m_lines
.Insert(node
, line
);
1678 other
->m_lines
.Append(line
);
1682 line
->SetFrom(this);
1684 line
->SetAttachments(attachFrom
, attachTo
);
1687 void wxShape::RemoveLine(wxLineShape
*line
)
1689 if (line
->GetFrom() == this)
1690 line
->GetTo()->m_lines
.DeleteObject(line
);
1692 line
->GetFrom()->m_lines
.DeleteObject(line
);
1694 m_lines
.DeleteObject(line
);
1698 void wxShape::WriteAttributes(wxExpr
*clause
)
1700 clause
->AddAttributeValueString("type", GetClassInfo()->GetClassName());
1701 clause
->AddAttributeValue("id", m_id
);
1705 int penWidth
= m_pen
->GetWidth();
1706 int penStyle
= m_pen
->GetStyle();
1708 clause
->AddAttributeValue("pen_width", (long)penWidth
);
1709 if (penStyle
!= wxSOLID
)
1710 clause
->AddAttributeValue("pen_style", (long)penStyle
);
1712 wxString penColour
= wxTheColourDatabase
->FindName(m_pen
->GetColour());
1713 if (penColour
== "")
1715 wxString
hex(oglColourToHex(m_pen
->GetColour()));
1716 hex
= wxString("#") + hex
;
1717 clause
->AddAttributeValueString("pen_colour", hex
);
1719 else if (penColour
!= "BLACK")
1720 clause
->AddAttributeValueString("pen_colour", penColour
);
1725 wxString brushColour
= wxTheColourDatabase
->FindName(m_brush
->GetColour());
1727 if (brushColour
== "")
1729 wxString
hex(oglColourToHex(m_brush
->GetColour()));
1730 hex
= wxString("#") + hex
;
1731 clause
->AddAttributeValueString("brush_colour", hex
);
1733 else if (brushColour
!= "WHITE")
1734 clause
->AddAttributeValueString("brush_colour", brushColour
);
1736 if (m_brush
->GetStyle() != wxSOLID
)
1737 clause
->AddAttributeValue("brush_style", (long)m_brush
->GetStyle());
1742 int n_lines
= m_lines
.GetCount();
1745 wxExpr
*list
= new wxExpr(wxExprList
);
1746 wxNode
*node
= m_lines
.GetFirst();
1749 wxShape
*line
= (wxShape
*)node
->GetData();
1750 wxExpr
*id_expr
= new wxExpr(line
->GetId());
1751 list
->Append(id_expr
);
1752 node
= node
->GetNext();
1754 clause
->AddAttributeValue("arcs", list
);
1757 // Miscellaneous members
1758 if (m_attachmentMode
!= 0)
1759 clause
->AddAttributeValue("use_attachments", (long)m_attachmentMode
);
1760 if (m_sensitivity
!= OP_ALL
)
1761 clause
->AddAttributeValue("sensitivity", (long)m_sensitivity
);
1762 if (!m_spaceAttachments
)
1763 clause
->AddAttributeValue("space_attachments", (long)m_spaceAttachments
);
1765 clause
->AddAttributeValue("fixed_width", (long)m_fixedWidth
);
1767 clause
->AddAttributeValue("fixed_height", (long)m_fixedHeight
);
1768 if (m_shadowMode
!= SHADOW_NONE
)
1769 clause
->AddAttributeValue("shadow_mode", (long)m_shadowMode
);
1770 if (m_centreResize
!= TRUE
)
1771 clause
->AddAttributeValue("centre_resize", (long)0);
1772 clause
->AddAttributeValue("maintain_aspect_ratio", (long) m_maintainAspectRatio
);
1773 if (m_highlighted
!= FALSE
)
1774 clause
->AddAttributeValue("hilite", (long)m_highlighted
);
1776 if (m_parent
) // For composite objects
1777 clause
->AddAttributeValue("parent", (long)m_parent
->GetId());
1779 if (m_rotation
!= 0.0)
1780 clause
->AddAttributeValue("rotation", m_rotation
);
1782 if (!this->IsKindOf(CLASSINFO(wxLineShape
)))
1784 clause
->AddAttributeValue("neck_length", (long) m_branchNeckLength
);
1785 clause
->AddAttributeValue("stem_length", (long) m_branchStemLength
);
1786 clause
->AddAttributeValue("branch_spacing", (long) m_branchSpacing
);
1787 clause
->AddAttributeValue("branch_style", (long) m_branchStyle
);
1790 // Write user-defined attachment points, if any
1791 if (m_attachmentPoints
.GetCount() > 0)
1793 wxExpr
*attachmentList
= new wxExpr(wxExprList
);
1794 wxNode
*node
= m_attachmentPoints
.GetFirst();
1797 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->GetData();
1798 wxExpr
*pointExpr
= new wxExpr(wxExprList
);
1799 pointExpr
->Append(new wxExpr((long)point
->m_id
));
1800 pointExpr
->Append(new wxExpr(point
->m_x
));
1801 pointExpr
->Append(new wxExpr(point
->m_y
));
1802 attachmentList
->Append(pointExpr
);
1803 node
= node
->GetNext();
1805 clause
->AddAttributeValue("user_attachments", attachmentList
);
1808 // Write text regions
1809 WriteRegions(clause
);
1812 void wxShape::WriteRegions(wxExpr
*clause
)
1814 // Output regions as region1 = (...), region2 = (...), etc
1815 // and formatted text as text1 = (...), text2 = (...) etc.
1817 char regionNameBuf
[20];
1818 char textNameBuf
[20];
1819 wxNode
*node
= m_regions
.GetFirst();
1822 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
1823 sprintf(regionNameBuf
, "region%d", regionNo
);
1824 sprintf(textNameBuf
, "text%d", regionNo
);
1826 // Original text and region attributes:
1827 // region1 = (regionName regionText x y width height minWidth minHeight proportionX proportionY
1828 // formatMode fontSize fontFamily fontStyle fontWeight textColour)
1829 wxExpr
*regionExpr
= new wxExpr(wxExprList
);
1830 regionExpr
->Append(new wxExpr(wxExprString
, region
->m_regionName
));
1831 regionExpr
->Append(new wxExpr(wxExprString
, region
->m_regionText
));
1833 regionExpr
->Append(new wxExpr(region
->m_x
));
1834 regionExpr
->Append(new wxExpr(region
->m_y
));
1835 regionExpr
->Append(new wxExpr(region
->GetWidth()));
1836 regionExpr
->Append(new wxExpr(region
->GetHeight()));
1838 regionExpr
->Append(new wxExpr(region
->m_minWidth
));
1839 regionExpr
->Append(new wxExpr(region
->m_minHeight
));
1840 regionExpr
->Append(new wxExpr(region
->m_regionProportionX
));
1841 regionExpr
->Append(new wxExpr(region
->m_regionProportionY
));
1843 regionExpr
->Append(new wxExpr((long)region
->m_formatMode
));
1845 regionExpr
->Append(new wxExpr((long)(region
->m_font
? region
->m_font
->GetPointSize() : 10)));
1846 regionExpr
->Append(new wxExpr((long)(region
->m_font
? region
->m_font
->GetFamily() : wxDEFAULT
)));
1847 regionExpr
->Append(new wxExpr((long)(region
->m_font
? region
->m_font
->GetStyle() : wxDEFAULT
)));
1848 regionExpr
->Append(new wxExpr((long)(region
->m_font
? region
->m_font
->GetWeight() : wxNORMAL
)));
1849 regionExpr
->Append(new wxExpr(wxExprString
, region
->m_textColour
));
1851 // New members for pen colour/style
1852 regionExpr
->Append(new wxExpr(wxExprString
, region
->m_penColour
));
1853 regionExpr
->Append(new wxExpr((long)region
->m_penStyle
));
1856 // text1 = ((x y string) (x y string) ...)
1857 wxExpr
*textExpr
= new wxExpr(wxExprList
);
1859 wxNode
*textNode
= region
->m_formattedText
.GetFirst();
1862 wxShapeTextLine
*line
= (wxShapeTextLine
*)textNode
->GetData();
1863 wxExpr
*list2
= new wxExpr(wxExprList
);
1864 list2
->Append(new wxExpr(line
->GetX()));
1865 list2
->Append(new wxExpr(line
->GetY()));
1866 list2
->Append(new wxExpr(wxExprString
, line
->GetText()));
1867 textExpr
->Append(list2
);
1868 textNode
= textNode
->GetNext();
1871 // Now add both attributes to the clause
1872 clause
->AddAttributeValue(regionNameBuf
, regionExpr
);
1873 clause
->AddAttributeValue(textNameBuf
, textExpr
);
1875 node
= node
->GetNext();
1880 void wxShape::ReadAttributes(wxExpr
*clause
)
1882 clause
->GetAttributeValue("id", m_id
);
1885 clause
->GetAttributeValue("x", m_xpos
);
1886 clause
->GetAttributeValue("y", m_ypos
);
1888 // Input text strings (FOR COMPATIBILITY WITH OLD FILES ONLY. SEE REGION CODE BELOW.)
1890 wxExpr
*strings
= clause
->AttributeValue("text");
1891 if (strings
&& strings
->Type() == wxExprList
)
1893 m_formatted
= TRUE
; // Assume text is formatted unless we prove otherwise
1894 wxExpr
*node
= strings
->value
.first
;
1897 wxExpr
*string_expr
= node
;
1900 wxString
the_string("");
1902 // string_expr can either be a string, or a list of
1903 // 3 elements: x, y, and string.
1904 if (string_expr
->Type() == wxExprString
)
1906 the_string
= string_expr
->StringValue();
1907 m_formatted
= FALSE
;
1909 else if (string_expr
->Type() == wxExprList
)
1911 wxExpr
*first
= string_expr
->value
.first
;
1912 wxExpr
*second
= first
? first
->next
: (wxExpr
*) NULL
;
1913 wxExpr
*third
= second
? second
->next
: (wxExpr
*) NULL
;
1915 if (first
&& second
&& third
&&
1916 (first
->Type() == wxExprReal
|| first
->Type() == wxExprInteger
) &&
1917 (second
->Type() == wxExprReal
|| second
->Type() == wxExprInteger
) &&
1918 third
->Type() == wxExprString
)
1920 if (first
->Type() == wxExprReal
)
1921 the_x
= first
->RealValue();
1922 else the_x
= (double)first
->IntegerValue();
1924 if (second
->Type() == wxExprReal
)
1925 the_y
= second
->RealValue();
1926 else the_y
= (double)second
->IntegerValue();
1928 the_string
= third
->StringValue();
1931 wxShapeTextLine
*line
=
1932 new wxShapeTextLine(the_x
, the_y
, the_string
);
1933 m_text
.Append(line
);
1939 wxString pen_string
= "";
1940 wxString brush_string
= "";
1942 int pen_style
= wxSOLID
;
1943 int brush_style
= wxSOLID
;
1944 m_attachmentMode
= ATTACHMENT_MODE_NONE
;
1946 clause
->GetAttributeValue("pen_colour", pen_string
);
1947 clause
->GetAttributeValue("text_colour", m_textColourName
);
1949 SetTextColour(m_textColourName
);
1951 clause
->GetAttributeValue("region_name", m_regionName
);
1953 clause
->GetAttributeValue("brush_colour", brush_string
);
1954 clause
->GetAttributeValue("pen_width", pen_width
);
1955 clause
->GetAttributeValue("pen_style", pen_style
);
1956 clause
->GetAttributeValue("brush_style", brush_style
);
1958 int iVal
= (int) m_attachmentMode
;
1959 clause
->GetAttributeValue("use_attachments", iVal
);
1960 m_attachmentMode
= iVal
;
1962 clause
->GetAttributeValue("sensitivity", m_sensitivity
);
1964 iVal
= (int) m_spaceAttachments
;
1965 clause
->GetAttributeValue("space_attachments", iVal
);
1966 m_spaceAttachments
= (iVal
!= 0);
1968 iVal
= (int) m_fixedWidth
;
1969 clause
->GetAttributeValue("fixed_width", iVal
);
1970 m_fixedWidth
= (iVal
!= 0);
1972 iVal
= (int) m_fixedHeight
;
1973 clause
->GetAttributeValue("fixed_height", iVal
);
1974 m_fixedHeight
= (iVal
!= 0);
1976 clause
->GetAttributeValue("format_mode", m_formatMode
);
1977 clause
->GetAttributeValue("shadow_mode", m_shadowMode
);
1979 iVal
= m_branchNeckLength
;
1980 clause
->GetAttributeValue("neck_length", iVal
);
1981 m_branchNeckLength
= iVal
;
1983 iVal
= m_branchStemLength
;
1984 clause
->GetAttributeValue("stem_length", iVal
);
1985 m_branchStemLength
= iVal
;
1987 iVal
= m_branchSpacing
;
1988 clause
->GetAttributeValue("branch_spacing", iVal
);
1989 m_branchSpacing
= iVal
;
1991 clause
->GetAttributeValue("branch_style", m_branchStyle
);
1993 iVal
= (int) m_centreResize
;
1994 clause
->GetAttributeValue("centre_resize", iVal
);
1995 m_centreResize
= (iVal
!= 0);
1997 iVal
= (int) m_maintainAspectRatio
;
1998 clause
->GetAttributeValue("maintain_aspect_ratio", iVal
);
1999 m_maintainAspectRatio
= (iVal
!= 0);
2001 iVal
= (int) m_highlighted
;
2002 clause
->GetAttributeValue("hilite", iVal
);
2003 m_highlighted
= (iVal
!= 0);
2005 clause
->GetAttributeValue("rotation", m_rotation
);
2007 if (pen_string
== "")
2008 pen_string
= "BLACK";
2009 if (brush_string
== "")
2010 brush_string
= "WHITE";
2012 if (pen_string
.GetChar(0) == '#')
2014 wxColour
col(oglHexToColour(pen_string
.After('#')));
2015 m_pen
= wxThePenList
->FindOrCreatePen(col
, pen_width
, pen_style
);
2018 m_pen
= wxThePenList
->FindOrCreatePen(pen_string
, pen_width
, pen_style
);
2021 m_pen
= wxBLACK_PEN
;
2023 if (brush_string
.GetChar(0) == '#')
2025 wxColour
col(oglHexToColour(brush_string
.After('#')));
2026 m_brush
= wxTheBrushList
->FindOrCreateBrush(col
, brush_style
);
2029 m_brush
= wxTheBrushList
->FindOrCreateBrush(brush_string
, brush_style
);
2032 m_brush
= wxWHITE_BRUSH
;
2034 int point_size
= 10;
2035 clause
->GetAttributeValue("point_size", point_size
);
2036 SetFont(oglMatchFont(point_size
));
2038 // Read user-defined attachment points, if any
2039 wxExpr
*attachmentList
= clause
->AttributeValue("user_attachments");
2042 wxExpr
*pointExpr
= attachmentList
->GetFirst();
2045 wxExpr
*idExpr
= pointExpr
->Nth(0);
2046 wxExpr
*xExpr
= pointExpr
->Nth(1);
2047 wxExpr
*yExpr
= pointExpr
->Nth(2);
2048 if (idExpr
&& xExpr
&& yExpr
)
2050 wxAttachmentPoint
*point
= new wxAttachmentPoint
;
2051 point
->m_id
= (int)idExpr
->IntegerValue();
2052 point
->m_x
= xExpr
->RealValue();
2053 point
->m_y
= yExpr
->RealValue();
2054 m_attachmentPoints
.Append((wxObject
*)point
);
2056 pointExpr
= pointExpr
->GetNext();
2060 // Read text regions
2061 ReadRegions(clause
);
2064 void wxShape::ReadRegions(wxExpr
*clause
)
2068 // region1 = (regionName regionText x y width height minWidth minHeight proportionX proportionY
2069 // formatMode fontSize fontFamily fontStyle fontWeight textColour)
2071 char regionNameBuf
[20];
2072 char textNameBuf
[20];
2074 wxExpr
*regionExpr
= NULL
;
2075 wxExpr
*textExpr
= NULL
;
2076 sprintf(regionNameBuf
, "region%d", regionNo
);
2077 sprintf(textNameBuf
, "text%d", regionNo
);
2079 m_formatted
= TRUE
; // Assume text is formatted unless we prove otherwise
2081 while ((regionExpr
= clause
->AttributeValue(regionNameBuf
)))
2084 * Get the region information
2088 wxString
regionName("");
2089 wxString
regionText("");
2093 double height
= 0.0;
2094 double minWidth
= 5.0;
2095 double minHeight
= 5.0;
2096 double m_regionProportionX
= -1.0;
2097 double m_regionProportionY
= -1.0;
2098 int formatMode
= FORMAT_NONE
;
2100 int fontFamily
= wxSWISS
;
2101 int fontStyle
= wxNORMAL
;
2102 int fontWeight
= wxNORMAL
;
2103 wxString
regionTextColour("");
2104 wxString
penColour("");
2105 int penStyle
= wxSOLID
;
2107 if (regionExpr
->Type() == wxExprList
)
2109 wxExpr
*nameExpr
= regionExpr
->Nth(0);
2110 wxExpr
*textExpr
= regionExpr
->Nth(1);
2111 wxExpr
*xExpr
= regionExpr
->Nth(2);
2112 wxExpr
*yExpr
= regionExpr
->Nth(3);
2113 wxExpr
*widthExpr
= regionExpr
->Nth(4);
2114 wxExpr
*heightExpr
= regionExpr
->Nth(5);
2115 wxExpr
*minWidthExpr
= regionExpr
->Nth(6);
2116 wxExpr
*minHeightExpr
= regionExpr
->Nth(7);
2117 wxExpr
*propXExpr
= regionExpr
->Nth(8);
2118 wxExpr
*propYExpr
= regionExpr
->Nth(9);
2119 wxExpr
*formatExpr
= regionExpr
->Nth(10);
2120 wxExpr
*sizeExpr
= regionExpr
->Nth(11);
2121 wxExpr
*familyExpr
= regionExpr
->Nth(12);
2122 wxExpr
*styleExpr
= regionExpr
->Nth(13);
2123 wxExpr
*weightExpr
= regionExpr
->Nth(14);
2124 wxExpr
*colourExpr
= regionExpr
->Nth(15);
2125 wxExpr
*penColourExpr
= regionExpr
->Nth(16);
2126 wxExpr
*penStyleExpr
= regionExpr
->Nth(17);
2128 regionName
= nameExpr
->StringValue();
2129 regionText
= textExpr
->StringValue();
2131 x
= xExpr
->RealValue();
2132 y
= yExpr
->RealValue();
2134 width
= widthExpr
->RealValue();
2135 height
= heightExpr
->RealValue();
2137 minWidth
= minWidthExpr
->RealValue();
2138 minHeight
= minHeightExpr
->RealValue();
2140 m_regionProportionX
= propXExpr
->RealValue();
2141 m_regionProportionY
= propYExpr
->RealValue();
2143 formatMode
= (int) formatExpr
->IntegerValue();
2144 fontSize
= (int)sizeExpr
->IntegerValue();
2145 fontFamily
= (int)familyExpr
->IntegerValue();
2146 fontStyle
= (int)styleExpr
->IntegerValue();
2147 fontWeight
= (int)weightExpr
->IntegerValue();
2151 regionTextColour
= colourExpr
->StringValue();
2154 regionTextColour
= "BLACK";
2157 penColour
= penColourExpr
->StringValue();
2159 penStyle
= (int)penStyleExpr
->IntegerValue();
2161 wxFont
*font
= wxTheFontList
->FindOrCreateFont(fontSize
, fontFamily
, fontStyle
, fontWeight
);
2163 wxShapeRegion
*region
= new wxShapeRegion
;
2164 region
->SetProportions(m_regionProportionX
, m_regionProportionY
);
2165 region
->SetFont(font
);
2166 region
->SetSize(width
, height
);
2167 region
->SetPosition(x
, y
);
2168 region
->SetMinSize(minWidth
, minHeight
);
2169 region
->SetFormatMode(formatMode
);
2170 region
->SetPenStyle(penStyle
);
2171 if (penColour
!= "")
2172 region
->SetPenColour(penColour
);
2174 region
->m_textColour
= regionTextColour
;
2175 region
->m_regionText
= regionText
;
2176 region
->m_regionName
= regionName
;
2178 m_regions
.Append(region
);
2181 * Get the formatted text strings
2184 textExpr
= clause
->AttributeValue(textNameBuf
);
2185 if (textExpr
&& (textExpr
->Type() == wxExprList
))
2187 wxExpr
*node
= textExpr
->value
.first
;
2190 wxExpr
*string_expr
= node
;
2193 wxString
the_string("");
2195 // string_expr can either be a string, or a list of
2196 // 3 elements: x, y, and string.
2197 if (string_expr
->Type() == wxExprString
)
2199 the_string
= string_expr
->StringValue();
2200 m_formatted
= FALSE
;
2202 else if (string_expr
->Type() == wxExprList
)
2204 wxExpr
*first
= string_expr
->value
.first
;
2205 wxExpr
*second
= first
? first
->next
: (wxExpr
*) NULL
;
2206 wxExpr
*third
= second
? second
->next
: (wxExpr
*) NULL
;
2208 if (first
&& second
&& third
&&
2209 (first
->Type() == wxExprReal
|| first
->Type() == wxExprInteger
) &&
2210 (second
->Type() == wxExprReal
|| second
->Type() == wxExprInteger
) &&
2211 third
->Type() == wxExprString
)
2213 if (first
->Type() == wxExprReal
)
2214 the_x
= first
->RealValue();
2215 else the_x
= (double)first
->IntegerValue();
2217 if (second
->Type() == wxExprReal
)
2218 the_y
= second
->RealValue();
2219 else the_y
= (double)second
->IntegerValue();
2221 the_string
= third
->StringValue();
2226 wxShapeTextLine
*line
=
2227 new wxShapeTextLine(the_x
, the_y
, the_string
);
2228 region
->m_formattedText
.Append(line
);
2235 sprintf(regionNameBuf
, "region%d", regionNo
);
2236 sprintf(textNameBuf
, "text%d", regionNo
);
2239 // Compatibility: check for no regions (old file).
2240 // Lines and divided rectangles must deal with this compatibility
2241 // theirselves. Composites _may_ not have any regions anyway.
2242 if ((m_regions
.GetCount() == 0) &&
2243 !this->IsKindOf(CLASSINFO(wxLineShape
)) && !this->IsKindOf(CLASSINFO(wxDividedShape
)) &&
2244 !this->IsKindOf(CLASSINFO(wxCompositeShape
)))
2246 wxShapeRegion
*newRegion
= new wxShapeRegion
;
2247 newRegion
->SetName("0");
2248 m_regions
.Append((wxObject
*)newRegion
);
2249 if (m_text
.GetCount() > 0)
2251 newRegion
->ClearText();
2252 wxNode
*node
= m_text
.GetFirst();
2255 wxShapeTextLine
*textLine
= (wxShapeTextLine
*)node
->GetData();
2256 wxNode
*next
= node
->GetNext();
2257 newRegion
->GetFormattedText().Append((wxObject
*)textLine
);
2267 void wxShape::Copy(wxShape
& copy
)
2270 copy
.m_xpos
= m_xpos
;
2271 copy
.m_ypos
= m_ypos
;
2273 copy
.m_brush
= m_brush
;
2274 copy
.m_textColour
= m_textColour
;
2275 copy
.m_centreResize
= m_centreResize
;
2276 copy
.m_maintainAspectRatio
= m_maintainAspectRatio
;
2277 copy
.m_attachmentMode
= m_attachmentMode
;
2278 copy
.m_spaceAttachments
= m_spaceAttachments
;
2279 copy
.m_highlighted
= m_highlighted
;
2280 copy
.m_rotation
= m_rotation
;
2281 copy
.m_textColourName
= m_textColourName
;
2282 copy
.m_regionName
= m_regionName
;
2284 copy
.m_sensitivity
= m_sensitivity
;
2285 copy
.m_draggable
= m_draggable
;
2286 copy
.m_fixedWidth
= m_fixedWidth
;
2287 copy
.m_fixedHeight
= m_fixedHeight
;
2288 copy
.m_formatMode
= m_formatMode
;
2289 copy
.m_drawHandles
= m_drawHandles
;
2291 copy
.m_visible
= m_visible
;
2292 copy
.m_shadowMode
= m_shadowMode
;
2293 copy
.m_shadowOffsetX
= m_shadowOffsetX
;
2294 copy
.m_shadowOffsetY
= m_shadowOffsetY
;
2295 copy
.m_shadowBrush
= m_shadowBrush
;
2297 copy
.m_branchNeckLength
= m_branchNeckLength
;
2298 copy
.m_branchStemLength
= m_branchStemLength
;
2299 copy
.m_branchSpacing
= m_branchSpacing
;
2301 // Copy text regions
2302 copy
.ClearRegions();
2303 wxNode
*node
= m_regions
.GetFirst();
2306 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
2307 wxShapeRegion
*newRegion
= new wxShapeRegion(*region
);
2308 copy
.m_regions
.Append(newRegion
);
2309 node
= node
->GetNext();
2313 copy
.ClearAttachments();
2314 node
= m_attachmentPoints
.GetFirst();
2317 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->GetData();
2318 wxAttachmentPoint
*newPoint
= new wxAttachmentPoint
;
2319 newPoint
->m_id
= point
->m_id
;
2320 newPoint
->m_x
= point
->m_x
;
2321 newPoint
->m_y
= point
->m_y
;
2322 copy
.m_attachmentPoints
.Append((wxObject
*)newPoint
);
2323 node
= node
->GetNext();
2327 copy
.m_lines
.Clear();
2328 node
= m_lines
.GetFirst();
2331 wxLineShape
* line
= (wxLineShape
*) node
->GetData();
2332 copy
.m_lines
.Append(line
);
2333 node
= node
->GetNext();
2337 // Create and return a new, fully copied object.
2338 wxShape
*wxShape::CreateNewCopy(bool resetMapping
, bool recompute
)
2341 oglObjectCopyMapping
.Clear();
2343 wxShape
* newObject
= (wxShape
*) GetClassInfo()->CreateObject();
2345 wxASSERT( (newObject
!= NULL
) );
2346 wxASSERT( (newObject
->IsKindOf(CLASSINFO(wxShape
))) );
2350 if (GetEventHandler() != this)
2352 wxShapeEvtHandler
* newHandler
= GetEventHandler()->CreateNewCopy();
2353 newObject
->SetEventHandler(newHandler
);
2354 newObject
->SetPreviousHandler(NULL
);
2355 newHandler
->SetPreviousHandler(newObject
);
2356 newHandler
->SetShape(newObject
);
2360 newObject
->Recompute();
2364 // Does the copying for this object, including copying event
2365 // handler data if any. Calls the virtual Copy function.
2366 void wxShape::CopyWithHandler(wxShape
& copy
)
2370 if (GetEventHandler() != this)
2372 wxASSERT( copy
.GetEventHandler() != NULL
);
2373 wxASSERT( copy
.GetEventHandler() != (©
) );
2374 wxASSERT( GetEventHandler()->GetClassInfo() == copy
.GetEventHandler()->GetClassInfo() );
2375 GetEventHandler()->CopyData(* (copy
.GetEventHandler()));
2380 // Default - make 6 control points
2381 void wxShape::MakeControlPoints()
2383 double maxX
, maxY
, minX
, minY
;
2385 GetBoundingBoxMax(&maxX
, &maxY
);
2386 GetBoundingBoxMin(&minX
, &minY
);
2388 double widthMin
= (double)(minX
+ CONTROL_POINT_SIZE
+ 2);
2389 double heightMin
= (double)(minY
+ CONTROL_POINT_SIZE
+ 2);
2391 // Offsets from main object
2392 double top
= (double)(- (heightMin
/ 2.0));
2393 double bottom
= (double)(heightMin
/ 2.0 + (maxY
- minY
));
2394 double left
= (double)(- (widthMin
/ 2.0));
2395 double right
= (double)(widthMin
/ 2.0 + (maxX
- minX
));
2397 wxControlPoint
*control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, left
, top
,
2398 CONTROL_POINT_DIAGONAL
);
2399 m_canvas
->AddShape(control
);
2400 m_controlPoints
.Append(control
);
2402 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, 0, top
,
2403 CONTROL_POINT_VERTICAL
);
2404 m_canvas
->AddShape(control
);
2405 m_controlPoints
.Append(control
);
2407 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, right
, top
,
2408 CONTROL_POINT_DIAGONAL
);
2409 m_canvas
->AddShape(control
);
2410 m_controlPoints
.Append(control
);
2412 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, right
, 0,
2413 CONTROL_POINT_HORIZONTAL
);
2414 m_canvas
->AddShape(control
);
2415 m_controlPoints
.Append(control
);
2417 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, right
, bottom
,
2418 CONTROL_POINT_DIAGONAL
);
2419 m_canvas
->AddShape(control
);
2420 m_controlPoints
.Append(control
);
2422 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, 0, bottom
,
2423 CONTROL_POINT_VERTICAL
);
2424 m_canvas
->AddShape(control
);
2425 m_controlPoints
.Append(control
);
2427 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, left
, bottom
,
2428 CONTROL_POINT_DIAGONAL
);
2429 m_canvas
->AddShape(control
);
2430 m_controlPoints
.Append(control
);
2432 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, left
, 0,
2433 CONTROL_POINT_HORIZONTAL
);
2434 m_canvas
->AddShape(control
);
2435 m_controlPoints
.Append(control
);
2439 void wxShape::MakeMandatoryControlPoints()
2441 wxNode
*node
= m_children
.GetFirst();
2444 wxShape
*child
= (wxShape
*)node
->GetData();
2445 child
->MakeMandatoryControlPoints();
2446 node
= node
->GetNext();
2450 void wxShape::ResetMandatoryControlPoints()
2452 wxNode
*node
= m_children
.GetFirst();
2455 wxShape
*child
= (wxShape
*)node
->GetData();
2456 child
->ResetMandatoryControlPoints();
2457 node
= node
->GetNext();
2461 void wxShape::ResetControlPoints()
2463 ResetMandatoryControlPoints();
2465 if (m_controlPoints
.GetCount() < 1)
2468 double maxX
, maxY
, minX
, minY
;
2470 GetBoundingBoxMax(&maxX
, &maxY
);
2471 GetBoundingBoxMin(&minX
, &minY
);
2473 double widthMin
= (double)(minX
+ CONTROL_POINT_SIZE
+ 2);
2474 double heightMin
= (double)(minY
+ CONTROL_POINT_SIZE
+ 2);
2476 // Offsets from main object
2477 double top
= (double)(- (heightMin
/ 2.0));
2478 double bottom
= (double)(heightMin
/ 2.0 + (maxY
- minY
));
2479 double left
= (double)(- (widthMin
/ 2.0));
2480 double right
= (double)(widthMin
/ 2.0 + (maxX
- minX
));
2482 wxNode
*node
= m_controlPoints
.GetFirst();
2483 wxControlPoint
*control
= (wxControlPoint
*)node
->GetData();
2484 control
->m_xoffset
= left
; control
->m_yoffset
= top
;
2486 node
= node
->GetNext(); control
= (wxControlPoint
*)node
->GetData();
2487 control
->m_xoffset
= 0; control
->m_yoffset
= top
;
2489 node
= node
->GetNext(); control
= (wxControlPoint
*)node
->GetData();
2490 control
->m_xoffset
= right
; control
->m_yoffset
= top
;
2492 node
= node
->GetNext(); control
= (wxControlPoint
*)node
->GetData();
2493 control
->m_xoffset
= right
; control
->m_yoffset
= 0;
2495 node
= node
->GetNext(); control
= (wxControlPoint
*)node
->GetData();
2496 control
->m_xoffset
= right
; control
->m_yoffset
= bottom
;
2498 node
= node
->GetNext(); control
= (wxControlPoint
*)node
->GetData();
2499 control
->m_xoffset
= 0; control
->m_yoffset
= bottom
;
2501 node
= node
->GetNext(); control
= (wxControlPoint
*)node
->GetData();
2502 control
->m_xoffset
= left
; control
->m_yoffset
= bottom
;
2504 node
= node
->GetNext(); control
= (wxControlPoint
*)node
->GetData();
2505 control
->m_xoffset
= left
; control
->m_yoffset
= 0;
2508 void wxShape::DeleteControlPoints(wxDC
*dc
)
2510 wxNode
*node
= m_controlPoints
.GetFirst();
2513 wxControlPoint
*control
= (wxControlPoint
*)node
->GetData();
2515 control
->GetEventHandler()->OnErase(*dc
);
2516 m_canvas
->RemoveShape(control
);
2519 node
= m_controlPoints
.GetFirst();
2521 // Children of divisions are contained objects,
2523 if (!IsKindOf(CLASSINFO(wxDivisionShape
)))
2525 node
= m_children
.GetFirst();
2528 wxShape
*child
= (wxShape
*)node
->GetData();
2529 child
->DeleteControlPoints(dc
);
2530 node
= node
->GetNext();
2535 void wxShape::OnDrawControlPoints(wxDC
& dc
)
2540 dc
.SetBrush(* wxBLACK_BRUSH
);
2541 dc
.SetPen(* wxBLACK_PEN
);
2543 wxNode
*node
= m_controlPoints
.GetFirst();
2546 wxControlPoint
*control
= (wxControlPoint
*)node
->GetData();
2548 node
= node
->GetNext();
2550 // Children of divisions are contained objects,
2552 // This test bypasses the type facility for speed
2553 // (critical when drawing)
2554 if (!IsKindOf(CLASSINFO(wxDivisionShape
)))
2556 node
= m_children
.GetFirst();
2559 wxShape
*child
= (wxShape
*)node
->GetData();
2560 child
->GetEventHandler()->OnDrawControlPoints(dc
);
2561 node
= node
->GetNext();
2566 void wxShape::OnEraseControlPoints(wxDC
& dc
)
2568 wxNode
*node
= m_controlPoints
.GetFirst();
2571 wxControlPoint
*control
= (wxControlPoint
*)node
->GetData();
2573 node
= node
->GetNext();
2575 if (!IsKindOf(CLASSINFO(wxDivisionShape
)))
2577 node
= m_children
.GetFirst();
2580 wxShape
*child
= (wxShape
*)node
->GetData();
2581 child
->GetEventHandler()->OnEraseControlPoints(dc
);
2582 node
= node
->GetNext();
2587 void wxShape::Select(bool select
, wxDC
* dc
)
2589 m_selected
= select
;
2592 MakeControlPoints();
2593 // Children of divisions are contained objects,
2595 if (!IsKindOf(CLASSINFO(wxDivisionShape
)))
2597 wxNode
*node
= m_children
.GetFirst();
2600 wxShape
*child
= (wxShape
*)node
->GetData();
2601 child
->MakeMandatoryControlPoints();
2602 node
= node
->GetNext();
2606 GetEventHandler()->OnDrawControlPoints(*dc
);
2610 DeleteControlPoints(dc
);
2611 if (!IsKindOf(CLASSINFO(wxDivisionShape
)))
2613 wxNode
*node
= m_children
.GetFirst();
2616 wxShape
*child
= (wxShape
*)node
->GetData();
2617 child
->DeleteControlPoints(dc
);
2618 node
= node
->GetNext();
2624 bool wxShape::Selected() const
2629 bool wxShape::AncestorSelected() const
2631 if (m_selected
) return TRUE
;
2635 return GetParent()->AncestorSelected();
2638 int wxShape::GetNumberOfAttachments() const
2640 // Should return the MAXIMUM attachment point id here,
2641 // so higher-level functions can iterate through all attachments,
2642 // even if they're not contiguous.
2643 if (m_attachmentPoints
.GetCount() == 0)
2648 wxNode
*node
= m_attachmentPoints
.GetFirst();
2651 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->GetData();
2652 if (point
->m_id
> maxN
)
2654 node
= node
->GetNext();
2660 bool wxShape::AttachmentIsValid(int attachment
) const
2662 if (m_attachmentPoints
.GetCount() == 0)
2664 return ((attachment
>= 0) && (attachment
< 4)) ;
2667 wxNode
*node
= m_attachmentPoints
.GetFirst();
2670 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->GetData();
2671 if (point
->m_id
== attachment
)
2673 node
= node
->GetNext();
2678 bool wxShape::GetAttachmentPosition(int attachment
, double *x
, double *y
,
2679 int nth
, int no_arcs
, wxLineShape
*line
)
2681 if (m_attachmentMode
== ATTACHMENT_MODE_NONE
)
2683 *x
= m_xpos
; *y
= m_ypos
;
2686 else if (m_attachmentMode
== ATTACHMENT_MODE_BRANCHING
)
2688 wxRealPoint pt
, stemPt
;
2689 GetBranchingAttachmentPoint(attachment
, nth
, pt
, stemPt
);
2694 else if (m_attachmentMode
== ATTACHMENT_MODE_EDGE
)
2696 if (m_attachmentPoints
.GetCount() > 0)
2698 wxNode
*node
= m_attachmentPoints
.GetFirst();
2701 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->GetData();
2702 if (point
->m_id
== attachment
)
2704 *x
= (double)(m_xpos
+ point
->m_x
);
2705 *y
= (double)(m_ypos
+ point
->m_y
);
2708 node
= node
->GetNext();
2710 *x
= m_xpos
; *y
= m_ypos
;
2715 // Assume is rectangular
2717 GetBoundingBoxMax(&w
, &h
);
2718 double top
= (double)(m_ypos
+ h
/2.0);
2719 double bottom
= (double)(m_ypos
- h
/2.0);
2720 double left
= (double)(m_xpos
- w
/2.0);
2721 double right
= (double)(m_xpos
+ w
/2.0);
2723 bool isEnd
= (line
&& line
->IsEnd(this));
2725 int physicalAttachment
= LogicalToPhysicalAttachment(attachment
);
2728 switch (physicalAttachment
)
2732 wxRealPoint pt
= CalcSimpleAttachment(wxRealPoint(left
, bottom
), wxRealPoint(right
, bottom
),
2733 nth
, no_arcs
, line
);
2735 *x
= pt
.x
; *y
= pt
.y
;
2740 wxRealPoint pt
= CalcSimpleAttachment(wxRealPoint(right
, bottom
), wxRealPoint(right
, top
),
2741 nth
, no_arcs
, line
);
2743 *x
= pt
.x
; *y
= pt
.y
;
2748 wxRealPoint pt
= CalcSimpleAttachment(wxRealPoint(left
, top
), wxRealPoint(right
, top
),
2749 nth
, no_arcs
, line
);
2751 *x
= pt
.x
; *y
= pt
.y
;
2756 wxRealPoint pt
= CalcSimpleAttachment(wxRealPoint(left
, bottom
), wxRealPoint(left
, top
),
2757 nth
, no_arcs
, line
);
2759 *x
= pt
.x
; *y
= pt
.y
;
2774 void wxShape::GetBoundingBoxMax(double *w
, double *h
)
2777 GetBoundingBoxMin(&ww
, &hh
);
2778 if (m_shadowMode
!= SHADOW_NONE
)
2780 ww
+= m_shadowOffsetX
;
2781 hh
+= m_shadowOffsetY
;
2787 // Returns TRUE if image is a descendant of this composite
2788 bool wxShape::HasDescendant(wxShape
*image
)
2792 wxNode
*node
= m_children
.GetFirst();
2795 wxShape
*child
= (wxShape
*)node
->GetData();
2796 bool ans
= child
->HasDescendant(image
);
2799 node
= node
->GetNext();
2804 // Clears points from a list of wxRealPoints, and clears list
2805 void wxShape::ClearPointList(wxList
& list
)
2807 wxNode
* node
= list
.GetFirst();
2810 wxRealPoint
* pt
= (wxRealPoint
*) node
->GetData();
2813 node
= node
->GetNext();
2818 // Assuming the attachment lies along a vertical or horizontal line,
2819 // calculate the position on that point.
2820 wxRealPoint
wxShape::CalcSimpleAttachment(const wxRealPoint
& pt1
, const wxRealPoint
& pt2
,
2821 int nth
, int noArcs
, wxLineShape
* line
)
2823 bool isEnd
= (line
&& line
->IsEnd(this));
2825 // Are we horizontal or vertical?
2826 bool isHorizontal
= (oglRoughlyEqual(pt1
.y
, pt2
.y
) == TRUE
);
2832 wxRealPoint firstPoint
, secondPoint
;
2844 if (m_spaceAttachments
)
2846 if (line
&& (line
->GetAlignmentType(isEnd
) == LINE_ALIGNMENT_TO_NEXT_HANDLE
))
2848 // Align line according to the next handle along
2849 wxRealPoint
*point
= line
->GetNextControlPoint(this);
2850 if (point
->x
< firstPoint
.x
)
2852 else if (point
->x
> secondPoint
.x
)
2858 x
= firstPoint
.x
+ (nth
+ 1)*(secondPoint
.x
- firstPoint
.x
)/(noArcs
+ 1);
2860 else x
= (secondPoint
.x
- firstPoint
.x
)/2.0; // Midpoint
2866 wxASSERT( oglRoughlyEqual(pt1
.x
, pt2
.x
) == TRUE
);
2868 wxRealPoint firstPoint
, secondPoint
;
2880 if (m_spaceAttachments
)
2882 if (line
&& (line
->GetAlignmentType(isEnd
) == LINE_ALIGNMENT_TO_NEXT_HANDLE
))
2884 // Align line according to the next handle along
2885 wxRealPoint
*point
= line
->GetNextControlPoint(this);
2886 if (point
->y
< firstPoint
.y
)
2888 else if (point
->y
> secondPoint
.y
)
2894 y
= firstPoint
.y
+ (nth
+ 1)*(secondPoint
.y
- firstPoint
.y
)/(noArcs
+ 1);
2896 else y
= (secondPoint
.y
- firstPoint
.y
)/2.0; // Midpoint
2901 return wxRealPoint(x
, y
);
2904 // Return the zero-based position in m_lines of line.
2905 int wxShape::GetLinePosition(wxLineShape
* line
)
2908 for (i
= 0; i
< m_lines
.GetCount(); i
++)
2909 if ((wxLineShape
*) (m_lines
.Item(i
)->GetData()) == line
)
2919 // shoulder1 ->---------<- shoulder2
2921 // <- branching attachment point N-1
2923 // This function gets information about where branching connections go.
2924 // Returns FALSE if there are no lines at this attachment.
2925 bool wxShape::GetBranchingAttachmentInfo(int attachment
, wxRealPoint
& root
, wxRealPoint
& neck
,
2926 wxRealPoint
& shoulder1
, wxRealPoint
& shoulder2
)
2928 int physicalAttachment
= LogicalToPhysicalAttachment(attachment
);
2930 // Number of lines at this attachment.
2931 int lineCount
= GetAttachmentLineCount(attachment
);
2936 int totalBranchLength
= m_branchSpacing
* (lineCount
- 1);
2938 root
= GetBranchingAttachmentRoot(attachment
);
2940 // Assume that we have attachment points 0 to 3: top, right, bottom, left.
2941 switch (physicalAttachment
)
2946 neck
.y
= root
.y
- m_branchNeckLength
;
2948 shoulder1
.x
= root
.x
- (totalBranchLength
/2.0) ;
2949 shoulder2
.x
= root
.x
+ (totalBranchLength
/2.0) ;
2951 shoulder1
.y
= neck
.y
;
2952 shoulder2
.y
= neck
.y
;
2957 neck
.x
= root
.x
+ m_branchNeckLength
;
2960 shoulder1
.x
= neck
.x
;
2961 shoulder2
.x
= neck
.x
;
2963 shoulder1
.y
= neck
.y
- (totalBranchLength
/2.0) ;
2964 shoulder2
.y
= neck
.y
+ (totalBranchLength
/2.0) ;
2970 neck
.y
= root
.y
+ m_branchNeckLength
;
2972 shoulder1
.x
= root
.x
- (totalBranchLength
/2.0) ;
2973 shoulder2
.x
= root
.x
+ (totalBranchLength
/2.0) ;
2975 shoulder1
.y
= neck
.y
;
2976 shoulder2
.y
= neck
.y
;
2981 neck
.x
= root
.x
- m_branchNeckLength
;
2984 shoulder1
.x
= neck
.x
;
2985 shoulder2
.x
= neck
.x
;
2987 shoulder1
.y
= neck
.y
- (totalBranchLength
/2.0) ;
2988 shoulder2
.y
= neck
.y
+ (totalBranchLength
/2.0) ;
2993 wxFAIL_MSG( wxT("Unrecognised attachment point in GetBranchingAttachmentInfo.") );
3000 // n is the number of the adjoining line, from 0 to N-1 where N is the number of lines
3001 // at this attachment point.
3002 // Get the attachment point where the arc joins the stem, and also the point where the
3003 // the stem meets the shoulder.
3004 bool wxShape::GetBranchingAttachmentPoint(int attachment
, int n
, wxRealPoint
& pt
, wxRealPoint
& stemPt
)
3006 int physicalAttachment
= LogicalToPhysicalAttachment(attachment
);
3008 wxRealPoint root
, neck
, shoulder1
, shoulder2
;
3009 GetBranchingAttachmentInfo(attachment
, root
, neck
, shoulder1
, shoulder2
);
3011 // Assume that we have attachment points 0 to 3: top, right, bottom, left.
3012 switch (physicalAttachment
)
3016 pt
.y
= neck
.y
- m_branchStemLength
;
3017 pt
.x
= shoulder1
.x
+ n
*m_branchSpacing
;
3025 pt
.y
= neck
.y
+ m_branchStemLength
;
3026 pt
.x
= shoulder1
.x
+ n
*m_branchSpacing
;
3034 pt
.x
= neck
.x
+ m_branchStemLength
;
3035 pt
.y
= shoulder1
.y
+ n
*m_branchSpacing
;
3043 pt
.x
= neck
.x
- m_branchStemLength
;
3044 pt
.y
= shoulder1
.y
+ n
*m_branchSpacing
;
3052 wxFAIL_MSG( wxT("Unrecognised attachment point in GetBranchingAttachmentPoint.") );
3060 // Get the number of lines at this attachment position.
3061 int wxShape::GetAttachmentLineCount(int attachment
) const
3064 wxNode
* node
= m_lines
.GetFirst();
3067 wxLineShape
* lineShape
= (wxLineShape
*) node
->GetData();
3068 if ((lineShape
->GetFrom() == this) && (lineShape
->GetAttachmentFrom() == attachment
))
3070 else if ((lineShape
->GetTo() == this) && (lineShape
->GetAttachmentTo() == attachment
))
3073 node
= node
->GetNext();
3078 // This function gets the root point at the given attachment.
3079 wxRealPoint
wxShape::GetBranchingAttachmentRoot(int attachment
)
3081 int physicalAttachment
= LogicalToPhysicalAttachment(attachment
);
3085 double width
, height
;
3086 GetBoundingBoxMax(& width
, & height
);
3088 // Assume that we have attachment points 0 to 3: top, right, bottom, left.
3089 switch (physicalAttachment
)
3094 root
.y
= GetY() - height
/2.0;
3099 root
.x
= GetX() + width
/2.0;
3106 root
.y
= GetY() + height
/2.0;
3111 root
.x
= GetX() - width
/2.0;
3117 wxFAIL_MSG( wxT("Unrecognised attachment point in GetBranchingAttachmentRoot.") );
3124 // Draw or erase the branches (not the actual arcs though)
3125 void wxShape::OnDrawBranches(wxDC
& dc
, int attachment
, bool erase
)
3127 int count
= GetAttachmentLineCount(attachment
);
3131 wxRealPoint root
, neck
, shoulder1
, shoulder2
;
3132 GetBranchingAttachmentInfo(attachment
, root
, neck
, shoulder1
, shoulder2
);
3136 dc
.SetPen(*wxWHITE_PEN
);
3137 dc
.SetBrush(*wxWHITE_BRUSH
);
3141 dc
.SetPen(*wxBLACK_PEN
);
3142 dc
.SetBrush(*wxBLACK_BRUSH
);
3146 dc
.DrawLine((long) root
.x
, (long) root
.y
, (long) neck
.x
, (long) neck
.y
);
3150 // Draw shoulder-to-shoulder line
3151 dc
.DrawLine((long) shoulder1
.x
, (long) shoulder1
.y
, (long) shoulder2
.x
, (long) shoulder2
.y
);
3153 // Draw all the little branches
3155 for (i
= 0; i
< count
; i
++)
3157 wxRealPoint pt
, stemPt
;
3158 GetBranchingAttachmentPoint(attachment
, i
, pt
, stemPt
);
3159 dc
.DrawLine((long) stemPt
.x
, (long) stemPt
.y
, (long) pt
.x
, (long) pt
.y
);
3161 if ((GetBranchStyle() & BRANCHING_ATTACHMENT_BLOB
) && (count
> 1))
3164 // dc.DrawEllipse((long) (stemPt.x + 0.5 - (blobSize/2.0)), (long) (stemPt.y + 0.5 - (blobSize/2.0)), blobSize, blobSize);
3165 dc
.DrawEllipse((long) (stemPt
.x
- (blobSize
/2.0)), (long) (stemPt
.y
- (blobSize
/2.0)), blobSize
, blobSize
);
3170 // Draw or erase the branches (not the actual arcs though)
3171 void wxShape::OnDrawBranches(wxDC
& dc
, bool erase
)
3173 if (m_attachmentMode
!= ATTACHMENT_MODE_BRANCHING
)
3176 int count
= GetNumberOfAttachments();
3178 for (i
= 0; i
< count
; i
++)
3179 OnDrawBranches(dc
, i
, erase
);
3182 // Only get the attachment position at the _edge_ of the shape, ignoring
3183 // branching mode. This is used e.g. to indicate the edge of interest, not the point
3184 // on the attachment branch.
3185 bool wxShape::GetAttachmentPositionEdge(int attachment
, double *x
, double *y
,
3186 int nth
, int no_arcs
, wxLineShape
*line
)
3188 int oldMode
= m_attachmentMode
;
3190 // Calculate as if to edge, not branch
3191 if (m_attachmentMode
== ATTACHMENT_MODE_BRANCHING
)
3192 m_attachmentMode
= ATTACHMENT_MODE_EDGE
;
3193 bool success
= GetAttachmentPosition(attachment
, x
, y
, nth
, no_arcs
, line
);
3194 m_attachmentMode
= oldMode
;
3199 // Rotate the standard attachment point from physical (0 is always North)
3200 // to logical (0 -> 1 if rotated by 90 degrees)
3201 int wxShape::PhysicalToLogicalAttachment(int physicalAttachment
) const
3203 const double pi
= 3.1415926535897932384626433832795 ;
3205 if (oglRoughlyEqual(GetRotation(), 0.0))
3207 i
= physicalAttachment
;
3209 else if (oglRoughlyEqual(GetRotation(), (pi
/2.0)))
3211 i
= physicalAttachment
- 1;
3213 else if (oglRoughlyEqual(GetRotation(), pi
))
3215 i
= physicalAttachment
- 2;
3217 else if (oglRoughlyEqual(GetRotation(), (3.0*pi
/2.0)))
3219 i
= physicalAttachment
- 3;
3222 // Can't handle -- assume the same.
3223 return physicalAttachment
;
3231 // Rotate the standard attachment point from logical
3232 // to physical (0 is always North)
3233 int wxShape::LogicalToPhysicalAttachment(int logicalAttachment
) const
3235 const double pi
= 3.1415926535897932384626433832795 ;
3237 if (oglRoughlyEqual(GetRotation(), 0.0))
3239 i
= logicalAttachment
;
3241 else if (oglRoughlyEqual(GetRotation(), (pi
/2.0)))
3243 i
= logicalAttachment
+ 1;
3245 else if (oglRoughlyEqual(GetRotation(), pi
))
3247 i
= logicalAttachment
+ 2;
3249 else if (oglRoughlyEqual(GetRotation(), (3.0*pi
/2.0)))
3251 i
= logicalAttachment
+ 3;
3254 // Can't handle -- assume the same.
3255 return logicalAttachment
;
3263 void wxShape::Rotate(double WXUNUSED(x
), double WXUNUSED(y
), double theta
)
3265 const double pi
= 3.1415926535897932384626433832795 ;
3267 if (m_rotation
< 0.0)
3271 else if (m_rotation
> 2*pi
)
3278 wxPen
wxShape::GetBackgroundPen()
3282 wxColour c
= GetCanvas()->GetBackgroundColour();
3283 return wxPen(c
, 1, wxSOLID
);
3285 return * g_oglWhiteBackgroundPen
;
3289 wxBrush
wxShape::GetBackgroundBrush()
3293 wxColour c
= GetCanvas()->GetBackgroundColour();
3294 return wxBrush(c
, wxSOLID
);
3296 return * g_oglWhiteBackgroundBrush
;