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/ogl.h"
42 // Control point types
43 // Rectangle and most other shapes
44 #define CONTROL_POINT_VERTICAL 1
45 #define CONTROL_POINT_HORIZONTAL 2
46 #define CONTROL_POINT_DIAGONAL 3
49 #define CONTROL_POINT_ENDPOINT_TO 4
50 #define CONTROL_POINT_ENDPOINT_FROM 5
51 #define CONTROL_POINT_LINE 6
53 IMPLEMENT_DYNAMIC_CLASS(wxShapeTextLine
, wxObject
)
54 IMPLEMENT_DYNAMIC_CLASS(wxAttachmentPoint
, wxObject
)
56 wxShapeTextLine::wxShapeTextLine(double the_x
, double the_y
, const wxString
& the_line
)
58 m_x
= the_x
; m_y
= the_y
; m_line
= the_line
;
61 wxShapeTextLine::~wxShapeTextLine()
65 IMPLEMENT_ABSTRACT_CLASS(wxShapeEvtHandler
, wxObject
)
67 wxShapeEvtHandler::wxShapeEvtHandler(wxShapeEvtHandler
*prev
, wxShape
*shape
)
69 m_previousHandler
= prev
;
70 m_handlerShape
= shape
;
73 wxShapeEvtHandler::~wxShapeEvtHandler()
77 // Creates a copy of this event handler.
78 wxShapeEvtHandler
* wxShapeEvtHandler::CreateNewCopy()
80 wxShapeEvtHandler
* newObject
= (wxShapeEvtHandler
*) GetClassInfo()->CreateObject();
82 wxASSERT( (newObject
!= NULL
) );
83 wxASSERT( (newObject
->IsKindOf(CLASSINFO(wxShapeEvtHandler
))) );
85 newObject
->m_previousHandler
= newObject
;
93 void wxShapeEvtHandler::OnDelete()
95 if (this != GetShape())
99 void wxShapeEvtHandler::OnDraw(wxDC
& dc
)
101 if (m_previousHandler
)
102 m_previousHandler
->OnDraw(dc
);
105 void wxShapeEvtHandler::OnMoveLinks(wxDC
& dc
)
107 if (m_previousHandler
)
108 m_previousHandler
->OnMoveLinks(dc
);
111 void wxShapeEvtHandler::OnMoveLink(wxDC
& dc
, bool moveControlPoints
)
113 if (m_previousHandler
)
114 m_previousHandler
->OnMoveLink(dc
, moveControlPoints
);
117 void wxShapeEvtHandler::OnDrawContents(wxDC
& dc
)
119 if (m_previousHandler
)
120 m_previousHandler
->OnDrawContents(dc
);
123 void wxShapeEvtHandler::OnDrawBranches(wxDC
& dc
, bool erase
)
125 if (m_previousHandler
)
126 m_previousHandler
->OnDrawBranches(dc
, erase
);
129 void wxShapeEvtHandler::OnSize(double x
, double y
)
131 if (m_previousHandler
)
132 m_previousHandler
->OnSize(x
, y
);
135 bool wxShapeEvtHandler::OnMovePre(wxDC
& dc
, double x
, double y
, double old_x
, double old_y
, bool display
)
137 if (m_previousHandler
)
138 return m_previousHandler
->OnMovePre(dc
, x
, y
, old_x
, old_y
, display
);
143 void wxShapeEvtHandler::OnMovePost(wxDC
& dc
, double x
, double y
, double old_x
, double old_y
, bool display
)
145 if (m_previousHandler
)
146 m_previousHandler
->OnMovePost(dc
, x
, y
, old_x
, old_y
, display
);
149 void wxShapeEvtHandler::OnErase(wxDC
& dc
)
151 if (m_previousHandler
)
152 m_previousHandler
->OnErase(dc
);
155 void wxShapeEvtHandler::OnEraseContents(wxDC
& dc
)
157 if (m_previousHandler
)
158 m_previousHandler
->OnEraseContents(dc
);
161 void wxShapeEvtHandler::OnHighlight(wxDC
& dc
)
163 if (m_previousHandler
)
164 m_previousHandler
->OnHighlight(dc
);
167 void wxShapeEvtHandler::OnLeftClick(double x
, double y
, int keys
, int attachment
)
169 if (m_previousHandler
)
170 m_previousHandler
->OnLeftClick(x
, y
, keys
, attachment
);
173 void wxShapeEvtHandler::OnLeftDoubleClick(double x
, double y
, int keys
, int attachment
)
175 if (m_previousHandler
)
176 m_previousHandler
->OnLeftDoubleClick(x
, y
, keys
, attachment
);
179 void wxShapeEvtHandler::OnRightClick(double x
, double y
, int keys
, int attachment
)
181 if (m_previousHandler
)
182 m_previousHandler
->OnRightClick(x
, y
, keys
, attachment
);
185 void wxShapeEvtHandler::OnDragLeft(bool draw
, double x
, double y
, int keys
, int attachment
)
187 if (m_previousHandler
)
188 m_previousHandler
->OnDragLeft(draw
, x
, y
, keys
, attachment
);
191 void wxShapeEvtHandler::OnBeginDragLeft(double x
, double y
, int keys
, int attachment
)
193 if (m_previousHandler
)
194 m_previousHandler
->OnBeginDragLeft(x
, y
, keys
, attachment
);
197 void wxShapeEvtHandler::OnEndDragLeft(double x
, double y
, int keys
, int attachment
)
199 if (m_previousHandler
)
200 m_previousHandler
->OnEndDragLeft(x
, y
, keys
, attachment
);
203 void wxShapeEvtHandler::OnDragRight(bool draw
, double x
, double y
, int keys
, int attachment
)
205 if (m_previousHandler
)
206 m_previousHandler
->OnDragRight(draw
, x
, y
, keys
, attachment
);
209 void wxShapeEvtHandler::OnBeginDragRight(double x
, double y
, int keys
, int attachment
)
211 if (m_previousHandler
)
212 m_previousHandler
->OnBeginDragRight(x
, y
, keys
, attachment
);
215 void wxShapeEvtHandler::OnEndDragRight(double x
, double y
, int keys
, int attachment
)
217 if (m_previousHandler
)
218 m_previousHandler
->OnEndDragRight(x
, y
, keys
, attachment
);
221 // Control points ('handles') redirect control to the actual shape, to make it easier
222 // to override sizing behaviour.
223 void wxShapeEvtHandler::OnSizingDragLeft(wxControlPoint
* pt
, bool draw
, double x
, double y
, int keys
, int attachment
)
225 if (m_previousHandler
)
226 m_previousHandler
->OnSizingDragLeft(pt
, draw
, x
, y
, keys
, attachment
);
229 void wxShapeEvtHandler::OnSizingBeginDragLeft(wxControlPoint
* pt
, double x
, double y
, int keys
, int attachment
)
231 if (m_previousHandler
)
232 m_previousHandler
->OnSizingBeginDragLeft(pt
, x
, y
, keys
, attachment
);
235 void wxShapeEvtHandler::OnSizingEndDragLeft(wxControlPoint
* pt
, double x
, double y
, int keys
, int attachment
)
237 if (m_previousHandler
)
238 m_previousHandler
->OnSizingEndDragLeft(pt
, x
, y
, keys
, attachment
);
241 void wxShapeEvtHandler::OnDrawOutline(wxDC
& dc
, double x
, double y
, double w
, double h
)
243 if (m_previousHandler
)
244 m_previousHandler
->OnDrawOutline(dc
, x
, y
, w
, h
);
247 void wxShapeEvtHandler::OnDrawControlPoints(wxDC
& dc
)
249 if (m_previousHandler
)
250 m_previousHandler
->OnDrawControlPoints(dc
);
253 void wxShapeEvtHandler::OnEraseControlPoints(wxDC
& dc
)
255 if (m_previousHandler
)
256 m_previousHandler
->OnEraseControlPoints(dc
);
259 // Can override this to prevent or intercept line reordering.
260 void wxShapeEvtHandler::OnChangeAttachment(int attachment
, wxLineShape
* line
, wxList
& ordering
)
262 if (m_previousHandler
)
263 m_previousHandler
->OnChangeAttachment(attachment
, line
, ordering
);
266 IMPLEMENT_ABSTRACT_CLASS(wxShape
, wxShapeEvtHandler
)
268 wxShape::wxShape(wxShapeCanvas
*can
)
270 m_eventHandler
= this;
275 m_xpos
= 0.0; m_ypos
= 0.0;
276 m_pen
= g_oglBlackPen
;
277 m_brush
= wxWHITE_BRUSH
;
278 m_font
= g_oglNormalFont
;
279 m_textColour
= wxBLACK
;
280 m_textColourName
= wxT("BLACK");
283 m_attachmentMode
= ATTACHMENT_MODE_NONE
;
284 m_spaceAttachments
= TRUE
;
285 m_disableLabel
= FALSE
;
286 m_fixedWidth
= FALSE
;
287 m_fixedHeight
= FALSE
;
288 m_drawHandles
= TRUE
;
289 m_sensitivity
= OP_ALL
;
292 m_formatMode
= FORMAT_CENTRE_HORIZ
| FORMAT_CENTRE_VERT
;
293 m_shadowMode
= SHADOW_NONE
;
296 m_shadowBrush
= wxBLACK_BRUSH
;
299 m_regionName
= wxT("0");
300 m_centreResize
= TRUE
;
301 m_maintainAspectRatio
= FALSE
;
302 m_highlighted
= FALSE
;
304 m_branchNeckLength
= 10;
305 m_branchStemLength
= 10;
306 m_branchSpacing
= 10;
307 m_branchStyle
= BRANCHING_ATTACHMENT_NORMAL
;
309 // Set up a default region. Much of the above will be put into
310 // the region eventually (the duplication is for compatibility)
311 wxShapeRegion
*region
= new wxShapeRegion
;
312 m_regions
.Append(region
);
313 region
->SetName(wxT("0"));
314 region
->SetFont(g_oglNormalFont
);
315 region
->SetFormatMode(FORMAT_CENTRE_HORIZ
| FORMAT_CENTRE_VERT
);
316 region
->SetColour(wxT("BLACK"));
322 m_parent
->GetChildren().DeleteObject(this);
329 m_canvas
->RemoveShape(this);
331 GetEventHandler()->OnDelete();
334 void wxShape::SetHighlight(bool hi
, bool recurse
)
339 wxNode
*node
= m_children
.GetFirst();
342 wxShape
*child
= (wxShape
*)node
->GetData();
343 child
->SetHighlight(hi
, recurse
);
344 node
= node
->GetNext();
349 void wxShape::SetSensitivityFilter(int sens
, bool recursive
)
351 if (sens
& OP_DRAG_LEFT
)
356 m_sensitivity
= sens
;
359 wxNode
*node
= m_children
.GetFirst();
362 wxShape
*obj
= (wxShape
*)node
->GetData();
363 obj
->SetSensitivityFilter(sens
, TRUE
);
364 node
= node
->GetNext();
369 void wxShape::SetDraggable(bool drag
, bool recursive
)
373 m_sensitivity
|= OP_DRAG_LEFT
;
375 if (m_sensitivity
& OP_DRAG_LEFT
)
376 m_sensitivity
= m_sensitivity
- OP_DRAG_LEFT
;
380 wxNode
*node
= m_children
.GetFirst();
383 wxShape
*obj
= (wxShape
*)node
->GetData();
384 obj
->SetDraggable(drag
, TRUE
);
385 node
= node
->GetNext();
390 void wxShape::SetDrawHandles(bool drawH
)
392 m_drawHandles
= drawH
;
393 wxNode
*node
= m_children
.GetFirst();
396 wxShape
*obj
= (wxShape
*)node
->GetData();
397 obj
->SetDrawHandles(drawH
);
398 node
= node
->GetNext();
402 void wxShape::SetShadowMode(int mode
, bool redraw
)
404 if (redraw
&& GetCanvas())
406 wxClientDC
dc(GetCanvas());
407 GetCanvas()->PrepareDC(dc
);
420 void wxShape::SetCanvas(wxShapeCanvas
*theCanvas
)
422 m_canvas
= theCanvas
;
423 wxNode
*node
= m_children
.GetFirst();
426 wxShape
*child
= (wxShape
*)node
->GetData();
427 child
->SetCanvas(theCanvas
);
428 node
= node
->GetNext();
432 void wxShape::AddToCanvas(wxShapeCanvas
*theCanvas
, wxShape
*addAfter
)
434 theCanvas
->AddShape(this, addAfter
);
435 wxNode
*node
= m_children
.GetFirst();
436 wxShape
*lastImage
= this;
439 wxShape
*object
= (wxShape
*)node
->GetData();
440 object
->AddToCanvas(theCanvas
, lastImage
);
443 node
= node
->GetNext();
447 // Insert at front of canvas
448 void wxShape::InsertInCanvas(wxShapeCanvas
*theCanvas
)
450 theCanvas
->InsertShape(this);
451 wxNode
*node
= m_children
.GetFirst();
452 wxShape
*lastImage
= this;
455 wxShape
*object
= (wxShape
*)node
->GetData();
456 object
->AddToCanvas(theCanvas
, lastImage
);
459 node
= node
->GetNext();
463 void wxShape::RemoveFromCanvas(wxShapeCanvas
*theCanvas
)
467 theCanvas
->RemoveShape(this);
468 wxNode
*node
= m_children
.GetFirst();
471 wxShape
*object
= (wxShape
*)node
->GetData();
472 object
->RemoveFromCanvas(theCanvas
);
474 node
= node
->GetNext();
478 void wxShape::ClearAttachments()
480 wxNode
*node
= m_attachmentPoints
.GetFirst();
483 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->GetData();
485 node
= node
->GetNext();
487 m_attachmentPoints
.Clear();
490 void wxShape::ClearText(int regionId
)
494 m_text
.DeleteContents(TRUE
);
496 m_text
.DeleteContents(FALSE
);
498 wxNode
*node
= m_regions
.Item(regionId
);
501 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
505 void wxShape::ClearRegions()
507 wxNode
*node
= m_regions
.GetFirst();
510 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
511 wxNode
*next
= node
->GetNext();
518 void wxShape::AddRegion(wxShapeRegion
*region
)
520 m_regions
.Append(region
);
523 void wxShape::SetDefaultRegionSize()
525 wxNode
*node
= m_regions
.GetFirst();
527 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
529 GetBoundingBoxMin(&w
, &h
);
530 region
->SetSize(w
, h
);
533 bool wxShape::HitTest(double x
, double y
, int *attachment
, double *distance
)
538 double width
= 0.0, height
= 0.0;
539 GetBoundingBoxMin(&width
, &height
);
540 if (fabs(width
) < 4.0) width
= 4.0;
541 if (fabs(height
) < 4.0) height
= 4.0;
543 width
+= (double)4.0; height
+= (double)4.0; // Allowance for inaccurate mousing
545 double left
= (double)(m_xpos
- (width
/2.0));
546 double top
= (double)(m_ypos
- (height
/2.0));
547 double right
= (double)(m_xpos
+ (width
/2.0));
548 double bottom
= (double)(m_ypos
+ (height
/2.0));
550 int nearest_attachment
= 0;
552 // If within the bounding box, check the attachment points
553 // within the object.
555 if (x
>= left
&& x
<= right
&& y
>= top
&& y
<= bottom
)
557 int n
= GetNumberOfAttachments();
558 double nearest
= 999999.0;
560 // GetAttachmentPosition[Edge] takes a logical attachment position,
561 // i.e. if it's rotated through 90%, position 0 is East-facing.
563 for (int i
= 0; i
< n
; i
++)
566 if (GetAttachmentPositionEdge(i
, &xp
, &yp
))
568 double l
= (double)sqrt(((xp
- x
) * (xp
- x
)) +
569 ((yp
- y
) * (yp
- y
)));
574 nearest_attachment
= i
;
578 *attachment
= nearest_attachment
;
585 // Format a text string according to the region size, adding
586 // strings with positions to region text list
588 static bool GraphicsInSizeToContents
= FALSE
; // Infinite recursion elimination
589 void wxShape::FormatText(wxDC
& dc
, const wxString
& s
, int i
)
594 if (m_regions
.GetCount() < 1)
596 wxNode
*node
= m_regions
.Item(i
);
600 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
601 // region->SetText(s); // don't set the formatted text yet, it will be done below
602 region
->m_regionText
= s
;
603 dc
.SetFont(* region
->GetFont());
605 region
->GetSize(&w
, &h
);
607 wxStringList
*stringList
= oglFormatText(dc
, s
, (w
-5), (h
-5), region
->GetFormatMode());
608 node
= (wxNode
*)stringList
->GetFirst();
611 wxChar
*s
= (wxChar
*)node
->GetData();
612 wxShapeTextLine
*line
= new wxShapeTextLine(0.0, 0.0, s
);
613 region
->GetFormattedText().Append((wxObject
*)line
);
614 node
= node
->GetNext();
619 // Don't try to resize an object with more than one image (this case should be dealt
620 // with by overriden handlers)
621 if ((region
->GetFormatMode() & FORMAT_SIZE_TO_CONTENTS
) &&
622 (region
->GetFormattedText().GetCount() > 0) &&
623 (m_regions
.GetCount() == 1) && !GraphicsInSizeToContents
)
625 oglGetCentredTextExtent(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, w
, h
, &actualW
, &actualH
);
626 if ((actualW
+m_textMarginX
!= w
) || (actualH
+m_textMarginY
!= h
))
628 // If we are a descendant of a composite, must make sure the composite gets
630 wxShape
*topAncestor
= GetTopAncestor();
632 if (topAncestor
!= this)
634 // Make sure we don't recurse infinitely
635 GraphicsInSizeToContents
= TRUE
;
637 wxCompositeShape
*composite
= (wxCompositeShape
*)topAncestor
;
638 composite
->Erase(dc
);
639 SetSize(actualW
+m_textMarginX
, actualH
+m_textMarginY
);
640 Move(dc
, m_xpos
, m_ypos
);
641 composite
->CalculateSize();
642 if (composite
->Selected())
644 composite
->DeleteControlPoints(& dc
);
645 composite
->MakeControlPoints();
646 composite
->MakeMandatoryControlPoints();
648 // Where infinite recursion might happen if we didn't stop it
651 GraphicsInSizeToContents
= FALSE
;
656 SetSize(actualW
+m_textMarginX
, actualH
+m_textMarginY
);
657 Move(dc
, m_xpos
, m_ypos
);
659 SetSize(actualW
+m_textMarginX
, actualH
+m_textMarginY
);
660 Move(dc
, m_xpos
, m_ypos
);
664 oglCentreText(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, actualW
, actualH
, region
->GetFormatMode());
668 void wxShape::Recentre(wxDC
& dc
)
671 GetBoundingBoxMin(&w
, &h
);
673 int noRegions
= m_regions
.GetCount();
674 for (int i
= 0; i
< noRegions
; i
++)
676 wxNode
*node
= m_regions
.Item(i
);
679 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
680 oglCentreText(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, w
, h
, region
->GetFormatMode());
685 bool wxShape::GetPerimeterPoint(double x1
, double y1
,
686 double x2
, double y2
,
687 double *x3
, double *y3
)
692 void wxShape::SetPen(wxPen
*the_pen
)
697 void wxShape::SetBrush(wxBrush
*the_brush
)
702 // Get the top-most (non-division) ancestor, or self
703 wxShape
*wxShape::GetTopAncestor()
708 if (GetParent()->IsKindOf(CLASSINFO(wxDivisionShape
)))
710 else return GetParent()->GetTopAncestor();
717 void wxShape::SetFont(wxFont
*the_font
, int regionId
)
720 wxNode
*node
= m_regions
.Item(regionId
);
723 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
724 region
->SetFont(the_font
);
727 wxFont
*wxShape::GetFont(int n
) const
729 wxNode
*node
= m_regions
.Item(n
);
732 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
733 return region
->GetFont();
736 void wxShape::SetFormatMode(int mode
, int regionId
)
738 wxNode
*node
= m_regions
.Item(regionId
);
741 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
742 region
->SetFormatMode(mode
);
745 int wxShape::GetFormatMode(int regionId
) const
747 wxNode
*node
= m_regions
.Item(regionId
);
750 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
751 return region
->GetFormatMode();
754 void wxShape::SetTextColour(const wxString
& the_colour
, int regionId
)
756 wxColour
*wxcolour
= wxTheColourDatabase
->FindColour(the_colour
);
757 m_textColour
= wxcolour
;
758 m_textColourName
= the_colour
;
760 wxNode
*node
= m_regions
.Item(regionId
);
763 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
764 region
->SetColour(the_colour
);
767 wxString
wxShape::GetTextColour(int regionId
) const
769 wxNode
*node
= m_regions
.Item(regionId
);
771 return wxEmptyString
;
772 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
773 return region
->GetColour();
776 void wxShape::SetRegionName(const wxString
& name
, int regionId
)
778 wxNode
*node
= m_regions
.Item(regionId
);
781 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
782 region
->SetName(name
);
785 wxString
wxShape::GetRegionName(int regionId
)
787 wxNode
*node
= m_regions
.Item(regionId
);
789 return wxEmptyString
;
790 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
791 return region
->GetName();
794 int wxShape::GetRegionId(const wxString
& name
)
796 wxNode
*node
= m_regions
.GetFirst();
800 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
801 if (region
->GetName() == name
)
803 node
= node
->GetNext();
809 // Name all m_regions in all subimages recursively.
810 void wxShape::NameRegions(const wxString
& parentName
)
812 int n
= GetNumberOfTextRegions();
814 for (int i
= 0; i
< n
; i
++)
816 if (parentName
.Length() > 0)
817 buff
<< parentName
<< wxT(".") << i
;
820 SetRegionName(buff
, i
);
822 wxNode
*node
= m_children
.GetFirst();
827 wxShape
*child
= (wxShape
*)node
->GetData();
828 if (parentName
.Length() > 0)
829 buff
<< parentName
<< wxT(".") << j
;
832 child
->NameRegions(buff
);
833 node
= node
->GetNext();
838 // Get a region by name, possibly looking recursively into composites.
839 wxShape
*wxShape::FindRegion(const wxString
& name
, int *regionId
)
841 int id
= GetRegionId(name
);
848 wxNode
*node
= m_children
.GetFirst();
851 wxShape
*child
= (wxShape
*)node
->GetData();
852 wxShape
*actualImage
= child
->FindRegion(name
, regionId
);
855 node
= node
->GetNext();
860 // Finds all region names for this image (composite or simple).
861 // Supply empty string list.
862 void wxShape::FindRegionNames(wxStringList
& list
)
864 int n
= GetNumberOfTextRegions();
865 for (int i
= 0; i
< n
; i
++)
867 wxString
name(GetRegionName(i
));
871 wxNode
*node
= m_children
.GetFirst();
874 wxShape
*child
= (wxShape
*)node
->GetData();
875 child
->FindRegionNames(list
);
876 node
= node
->GetNext();
880 void wxShape::AssignNewIds()
884 wxNode
*node
= m_children
.GetFirst();
887 wxShape
*child
= (wxShape
*)node
->GetData();
888 child
->AssignNewIds();
889 node
= node
->GetNext();
893 void wxShape::OnDraw(wxDC
& dc
)
897 void wxShape::OnMoveLinks(wxDC
& dc
)
899 // Want to set the ends of all attached links
900 // to point to/from this object
902 wxNode
*current
= m_lines
.GetFirst();
905 wxLineShape
*line
= (wxLineShape
*)current
->GetData();
906 line
->GetEventHandler()->OnMoveLink(dc
);
907 current
= current
->GetNext();
912 void wxShape::OnDrawContents(wxDC
& dc
)
914 double bound_x
, bound_y
;
915 GetBoundingBoxMin(&bound_x
, &bound_y
);
916 if (m_regions
.GetCount() < 1) return;
918 if (m_pen
) dc
.SetPen(* m_pen
);
920 wxShapeRegion
*region
= (wxShapeRegion
*)m_regions
.GetFirst()->GetData();
921 if (region
->GetFont()) dc
.SetFont(* region
->GetFont());
923 dc
.SetTextForeground(* (region
->GetActualColourObject()));
924 dc
.SetBackgroundMode(wxTRANSPARENT
);
927 oglCentreText(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, bound_x
, bound_y
, region
->GetFormatMode());
930 if (!GetDisableLabel())
932 oglDrawFormattedText(dc
, &(region
->GetFormattedText()), m_xpos
, m_ypos
, bound_x
, bound_y
, region
->GetFormatMode());
936 void wxShape::DrawContents(wxDC
& dc
)
938 GetEventHandler()->OnDrawContents(dc
);
941 void wxShape::OnSize(double x
, double y
)
945 bool wxShape::OnMovePre(wxDC
& dc
, double x
, double y
, double old_x
, double old_y
, bool display
)
950 void wxShape::OnMovePost(wxDC
& dc
, double x
, double y
, double old_x
, double old_y
, bool display
)
954 void wxShape::OnErase(wxDC
& dc
)
960 wxNode
*current
= m_lines
.GetFirst();
963 wxLineShape
*line
= (wxLineShape
*)current
->GetData();
964 line
->GetEventHandler()->OnErase(dc
);
965 current
= current
->GetNext();
967 GetEventHandler()->OnEraseContents(dc
);
970 void wxShape::OnEraseContents(wxDC
& dc
)
975 double maxX
, maxY
, minX
, minY
;
978 GetBoundingBoxMin(&minX
, &minY
);
979 GetBoundingBoxMax(&maxX
, &maxY
);
980 double topLeftX
= (double)(xp
- (maxX
/ 2.0) - 2.0);
981 double topLeftY
= (double)(yp
- (maxY
/ 2.0) - 2.0);
985 penWidth
= m_pen
->GetWidth();
987 dc
.SetPen(GetBackgroundPen());
988 dc
.SetBrush(GetBackgroundBrush());
990 dc
.DrawRectangle(WXROUND(topLeftX
- penWidth
), WXROUND(topLeftY
- penWidth
),
991 WXROUND(maxX
+ penWidth
*2.0 + 4.0), WXROUND(maxY
+ penWidth
*2.0 + 4.0));
994 void wxShape::EraseLinks(wxDC
& dc
, int attachment
, bool recurse
)
999 wxNode
*current
= m_lines
.GetFirst();
1002 wxLineShape
*line
= (wxLineShape
*)current
->GetData();
1003 if (attachment
== -1 || ((line
->GetTo() == this && line
->GetAttachmentTo() == attachment
) ||
1004 (line
->GetFrom() == this && line
->GetAttachmentFrom() == attachment
)))
1005 line
->GetEventHandler()->OnErase(dc
);
1006 current
= current
->GetNext();
1010 wxNode
*node
= m_children
.GetFirst();
1013 wxShape
*child
= (wxShape
*)node
->GetData();
1014 child
->EraseLinks(dc
, attachment
, recurse
);
1015 node
= node
->GetNext();
1020 void wxShape::DrawLinks(wxDC
& dc
, int attachment
, bool recurse
)
1025 wxNode
*current
= m_lines
.GetFirst();
1028 wxLineShape
*line
= (wxLineShape
*)current
->GetData();
1029 if (attachment
== -1 ||
1030 (line
->GetTo() == this && line
->GetAttachmentTo() == attachment
) ||
1031 (line
->GetFrom() == this && line
->GetAttachmentFrom() == attachment
))
1033 current
= current
->GetNext();
1037 wxNode
*node
= m_children
.GetFirst();
1040 wxShape
*child
= (wxShape
*)node
->GetData();
1041 child
->DrawLinks(dc
, attachment
, recurse
);
1042 node
= node
->GetNext();
1047 // Returns TRUE if pt1 <= pt2 in the sense that one point comes before another on an
1048 // edge of the shape.
1049 // attachmentPoint is the attachment point (= side) in question.
1051 // This is the default, rectangular implementation.
1052 bool wxShape::AttachmentSortTest(int attachmentPoint
, const wxRealPoint
& pt1
, const wxRealPoint
& pt2
)
1054 int physicalAttachment
= LogicalToPhysicalAttachment(attachmentPoint
);
1055 switch (physicalAttachment
)
1060 return (pt1
.x
<= pt2
.x
) ;
1066 return (pt1
.y
<= pt2
.y
) ;
1074 bool wxShape::MoveLineToNewAttachment(wxDC
& dc
, wxLineShape
*to_move
,
1077 if (GetAttachmentMode() == ATTACHMENT_MODE_NONE
)
1080 int newAttachment
, oldAttachment
;
1083 // Is (x, y) on this object? If so, find the new attachment point
1084 // the user has moved the point to
1085 bool hit
= HitTest(x
, y
, &newAttachment
, &distance
);
1091 if (to_move
->GetTo() == this)
1092 oldAttachment
= to_move
->GetAttachmentTo();
1094 oldAttachment
= to_move
->GetAttachmentFrom();
1096 // The links in a new ordering.
1099 // First, add all links to the new list.
1100 wxNode
*node
= m_lines
.GetFirst();
1103 newOrdering
.Append(node
->GetData());
1104 node
= node
->GetNext();
1107 // Delete the line object from the list of links; we're going to move
1108 // it to another position in the list
1109 newOrdering
.DeleteObject(to_move
);
1111 double old_x
= (double) -99999.9;
1112 double old_y
= (double) -99999.9;
1114 node
= newOrdering
.GetFirst();
1117 while (!found
&& node
)
1119 wxLineShape
*line
= (wxLineShape
*)node
->GetData();
1120 if ((line
->GetTo() == this && oldAttachment
== line
->GetAttachmentTo()) ||
1121 (line
->GetFrom() == this && oldAttachment
== line
->GetAttachmentFrom()))
1123 double startX
, startY
, endX
, endY
;
1125 line
->GetEnds(&startX
, &startY
, &endX
, &endY
);
1126 if (line
->GetTo() == this)
1136 wxRealPoint
thisPoint(xp
, yp
);
1137 wxRealPoint
lastPoint(old_x
, old_y
);
1138 wxRealPoint
newPoint(x
, y
);
1140 if (AttachmentSortTest(newAttachment
, newPoint
, thisPoint
) && AttachmentSortTest(newAttachment
, lastPoint
, newPoint
))
1143 newOrdering
.Insert(node
, to_move
);
1149 node
= node
->GetNext();
1153 newOrdering
.Append(to_move
);
1155 GetEventHandler()->OnChangeAttachment(newAttachment
, to_move
, newOrdering
);
1160 void wxShape::OnChangeAttachment(int attachment
, wxLineShape
* line
, wxList
& ordering
)
1162 if (line
->GetTo() == this)
1163 line
->SetAttachmentTo(attachment
);
1165 line
->SetAttachmentFrom(attachment
);
1167 ApplyAttachmentOrdering(ordering
);
1169 wxClientDC
dc(GetCanvas());
1170 GetCanvas()->PrepareDC(dc
);
1174 if (!GetCanvas()->GetQuickEditMode()) GetCanvas()->Redraw(dc
);
1177 // Reorders the lines according to the given list.
1178 void wxShape::ApplyAttachmentOrdering(wxList
& linesToSort
)
1180 // This is a temporary store of all the lines.
1183 wxNode
*node
= m_lines
.GetFirst();
1186 wxLineShape
*line
= (wxLineShape
*)node
->GetData();
1187 linesStore
.Append(line
);
1188 node
= node
->GetNext();;
1193 node
= linesToSort
.GetFirst();
1196 wxLineShape
*line
= (wxLineShape
*)node
->GetData();
1197 if (linesStore
.Member(line
))
1200 linesStore
.DeleteObject(line
);
1201 m_lines
.Append(line
);
1203 node
= node
->GetNext();
1206 // Now add any lines that haven't been listed in linesToSort.
1207 node
= linesStore
.GetFirst();
1210 wxLineShape
*line
= (wxLineShape
*)node
->GetData();
1211 m_lines
.Append(line
);
1212 node
= node
->GetNext();
1216 // Reorders the lines coming into the node image at this attachment
1217 // position, in the order in which they appear in linesToSort.
1218 // Any remaining lines not in the list will be added to the end.
1219 void wxShape::SortLines(int attachment
, wxList
& linesToSort
)
1221 // This is a temporary store of all the lines at this attachment
1222 // point. We'll tick them off as we've processed them.
1223 wxList linesAtThisAttachment
;
1225 wxNode
*node
= m_lines
.GetFirst();
1228 wxLineShape
*line
= (wxLineShape
*)node
->GetData();
1229 wxNode
*next
= node
->GetNext();
1230 if ((line
->GetTo() == this && line
->GetAttachmentTo() == attachment
) ||
1231 (line
->GetFrom() == this && line
->GetAttachmentFrom() == attachment
))
1233 linesAtThisAttachment
.Append(line
);
1237 else node
= node
->GetNext();
1240 node
= linesToSort
.GetFirst();
1243 wxLineShape
*line
= (wxLineShape
*)node
->GetData();
1244 if (linesAtThisAttachment
.Member(line
))
1247 linesAtThisAttachment
.DeleteObject(line
);
1248 m_lines
.Append(line
);
1250 node
= node
->GetNext();
1253 // Now add any lines that haven't been listed in linesToSort.
1254 node
= linesAtThisAttachment
.GetFirst();
1257 wxLineShape
*line
= (wxLineShape
*)node
->GetData();
1258 m_lines
.Append(line
);
1259 node
= node
->GetNext();
1263 void wxShape::OnHighlight(wxDC
& dc
)
1267 void wxShape::OnLeftClick(double x
, double y
, int keys
, int attachment
)
1269 if ((m_sensitivity
& OP_CLICK_LEFT
) != OP_CLICK_LEFT
)
1275 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1276 m_parent
->GetEventHandler()->OnLeftClick(x
, y
, keys
, attachment
);
1282 void wxShape::OnRightClick(double x
, double y
, int keys
, int attachment
)
1284 if ((m_sensitivity
& OP_CLICK_RIGHT
) != OP_CLICK_RIGHT
)
1290 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1291 m_parent
->GetEventHandler()->OnRightClick(x
, y
, keys
, attachment
);
1297 double DragOffsetX
= 0.0;
1298 double DragOffsetY
= 0.0;
1300 void wxShape::OnDragLeft(bool draw
, double x
, double y
, int keys
, int attachment
)
1302 if ((m_sensitivity
& OP_DRAG_LEFT
) != OP_DRAG_LEFT
)
1308 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1309 m_parent
->GetEventHandler()->OnDragLeft(draw
, x
, y
, keys
, attachment
);
1314 wxClientDC
dc(GetCanvas());
1315 GetCanvas()->PrepareDC(dc
);
1317 dc
.SetLogicalFunction(OGLRBLF
);
1319 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
1320 dc
.SetPen(dottedPen
);
1321 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
1324 xx
= x
+ DragOffsetX
;
1325 yy
= y
+ DragOffsetY
;
1327 m_canvas
->Snap(&xx
, &yy
);
1328 // m_xpos = xx; m_ypos = yy;
1330 GetBoundingBoxMax(&w
, &h
);
1331 GetEventHandler()->OnDrawOutline(dc
, xx
, yy
, w
, h
);
1334 void wxShape::OnBeginDragLeft(double x
, double y
, int keys
, int attachment
)
1336 if ((m_sensitivity
& OP_DRAG_LEFT
) != OP_DRAG_LEFT
)
1342 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1343 m_parent
->GetEventHandler()->OnBeginDragLeft(x
, y
, keys
, attachment
);
1348 DragOffsetX
= m_xpos
- x
;
1349 DragOffsetY
= m_ypos
- y
;
1351 wxClientDC
dc(GetCanvas());
1352 GetCanvas()->PrepareDC(dc
);
1354 // New policy: don't erase shape until end of drag.
1358 xx
= x
+ DragOffsetX
;
1359 yy
= y
+ DragOffsetY
;
1360 m_canvas
->Snap(&xx
, &yy
);
1361 // m_xpos = xx; m_ypos = yy;
1362 dc
.SetLogicalFunction(OGLRBLF
);
1364 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
1365 dc
.SetPen(dottedPen
);
1366 dc
.SetBrush((* wxTRANSPARENT_BRUSH
));
1369 GetBoundingBoxMax(&w
, &h
);
1370 GetEventHandler()->OnDrawOutline(dc
, xx
, yy
, w
, h
);
1371 m_canvas
->CaptureMouse();
1374 void wxShape::OnEndDragLeft(double x
, double y
, int keys
, int attachment
)
1376 m_canvas
->ReleaseMouse();
1377 if ((m_sensitivity
& OP_DRAG_LEFT
) != OP_DRAG_LEFT
)
1383 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1384 m_parent
->GetEventHandler()->OnEndDragLeft(x
, y
, keys
, attachment
);
1389 wxClientDC
dc(GetCanvas());
1390 GetCanvas()->PrepareDC(dc
);
1392 dc
.SetLogicalFunction(wxCOPY
);
1394 double xx
= x
+ DragOffsetX
;
1395 double yy
= y
+ DragOffsetY
;
1396 m_canvas
->Snap(&xx
, &yy
);
1397 // canvas->Snap(&m_xpos, &m_ypos);
1399 // New policy: erase shape at end of drag.
1403 if (m_canvas
&& !m_canvas
->GetQuickEditMode()) m_canvas
->Redraw(dc
);
1406 void wxShape::OnDragRight(bool draw
, double x
, double y
, int keys
, int attachment
)
1408 if ((m_sensitivity
& OP_DRAG_RIGHT
) != OP_DRAG_RIGHT
)
1414 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1415 m_parent
->GetEventHandler()->OnDragRight(draw
, x
, y
, keys
, attachment
);
1421 void wxShape::OnBeginDragRight(double x
, double y
, int keys
, int attachment
)
1423 if ((m_sensitivity
& OP_DRAG_RIGHT
) != OP_DRAG_RIGHT
)
1429 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1430 m_parent
->GetEventHandler()->OnBeginDragRight(x
, y
, keys
, attachment
);
1436 void wxShape::OnEndDragRight(double x
, double y
, int keys
, int attachment
)
1438 if ((m_sensitivity
& OP_DRAG_RIGHT
) != OP_DRAG_RIGHT
)
1444 m_parent
->HitTest(x
, y
, &attachment
, &dist
);
1445 m_parent
->GetEventHandler()->OnEndDragRight(x
, y
, keys
, attachment
);
1451 void wxShape::OnDrawOutline(wxDC
& dc
, double x
, double y
, double w
, double h
)
1453 double top_left_x
= (double)(x
- w
/2.0);
1454 double top_left_y
= (double)(y
- h
/2.0);
1455 double top_right_x
= (double)(top_left_x
+ w
);
1456 double top_right_y
= (double)top_left_y
;
1457 double bottom_left_x
= (double)top_left_x
;
1458 double bottom_left_y
= (double)(top_left_y
+ h
);
1459 double bottom_right_x
= (double)top_right_x
;
1460 double bottom_right_y
= (double)bottom_left_y
;
1463 points
[0].x
= WXROUND(top_left_x
); points
[0].y
= WXROUND(top_left_y
);
1464 points
[1].x
= WXROUND(top_right_x
); points
[1].y
= WXROUND(top_right_y
);
1465 points
[2].x
= WXROUND(bottom_right_x
); points
[2].y
= WXROUND(bottom_right_y
);
1466 points
[3].x
= WXROUND(bottom_left_x
); points
[3].y
= WXROUND(bottom_left_y
);
1467 points
[4].x
= WXROUND(top_left_x
); points
[4].y
= WXROUND(top_left_y
);
1469 dc
.DrawLines(5, points
);
1472 void wxShape::Attach(wxShapeCanvas
*can
)
1477 void wxShape::Detach()
1482 void wxShape::Move(wxDC
& dc
, double x
, double y
, bool display
)
1484 double old_x
= m_xpos
;
1485 double old_y
= m_ypos
;
1487 if (!GetEventHandler()->OnMovePre(dc
, x
, y
, old_x
, old_y
, display
))
1494 m_xpos
= x
; m_ypos
= y
;
1496 ResetControlPoints();
1503 GetEventHandler()->OnMovePost(dc
, x
, y
, old_x
, old_y
, display
);
1506 void wxShape::MoveLinks(wxDC
& dc
)
1508 GetEventHandler()->OnMoveLinks(dc
);
1512 void wxShape::Draw(wxDC
& dc
)
1516 GetEventHandler()->OnDraw(dc
);
1517 GetEventHandler()->OnDrawContents(dc
);
1518 GetEventHandler()->OnDrawControlPoints(dc
);
1519 GetEventHandler()->OnDrawBranches(dc
);
1523 void wxShape::Flash()
1527 wxClientDC
dc(GetCanvas());
1528 GetCanvas()->PrepareDC(dc
);
1530 dc
.SetLogicalFunction(OGLRBLF
);
1532 dc
.SetLogicalFunction(wxCOPY
);
1537 void wxShape::Show(bool show
)
1540 wxNode
*node
= m_children
.GetFirst();
1543 wxShape
*image
= (wxShape
*)node
->GetData();
1545 node
= node
->GetNext();
1549 void wxShape::Erase(wxDC
& dc
)
1551 GetEventHandler()->OnErase(dc
);
1552 GetEventHandler()->OnEraseControlPoints(dc
);
1553 GetEventHandler()->OnDrawBranches(dc
, TRUE
);
1556 void wxShape::EraseContents(wxDC
& dc
)
1558 GetEventHandler()->OnEraseContents(dc
);
1561 void wxShape::AddText(const wxString
& string
)
1563 wxNode
*node
= m_regions
.GetFirst();
1566 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
1567 region
->ClearText();
1568 wxShapeTextLine
*new_line
=
1569 new wxShapeTextLine(0.0, 0.0, string
);
1570 region
->GetFormattedText().Append(new_line
);
1572 m_formatted
= FALSE
;
1575 void wxShape::SetSize(double x
, double y
, bool recursive
)
1577 SetAttachmentSize(x
, y
);
1578 SetDefaultRegionSize();
1581 void wxShape::SetAttachmentSize(double w
, double h
)
1585 double width
, height
;
1586 GetBoundingBoxMin(&width
, &height
);
1589 else scaleX
= w
/width
;
1592 else scaleY
= h
/height
;
1594 wxNode
*node
= m_attachmentPoints
.GetFirst();
1597 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->GetData();
1598 point
->m_x
= (double)(point
->m_x
* scaleX
);
1599 point
->m_y
= (double)(point
->m_y
* scaleY
);
1600 node
= node
->GetNext();
1604 // Add line FROM this object
1605 void wxShape::AddLine(wxLineShape
*line
, wxShape
*other
,
1606 int attachFrom
, int attachTo
,
1607 // The line ordering
1608 int positionFrom
, int positionTo
)
1610 if (positionFrom
== -1)
1612 if (!m_lines
.Member(line
))
1613 m_lines
.Append(line
);
1617 // Don't preserve old ordering if we have new ordering instructions
1618 m_lines
.DeleteObject(line
);
1619 if (positionFrom
< (int) m_lines
.GetCount())
1621 wxNode
* node
= m_lines
.Item(positionFrom
);
1622 m_lines
.Insert(node
, line
);
1625 m_lines
.Append(line
);
1628 if (positionTo
== -1)
1630 if (!other
->m_lines
.Member(line
))
1631 other
->m_lines
.Append(line
);
1635 // Don't preserve old ordering if we have new ordering instructions
1636 other
->m_lines
.DeleteObject(line
);
1637 if (positionTo
< (int) other
->m_lines
.GetCount())
1639 wxNode
* node
= other
->m_lines
.Item(positionTo
);
1640 other
->m_lines
.Insert(node
, line
);
1643 other
->m_lines
.Append(line
);
1646 // Wrong: doesn't preserve ordering of shape already linked
1647 m_lines
.DeleteObject(line
);
1648 other
->m_lines
.DeleteObject(line
);
1650 if (positionFrom
== -1)
1651 m_lines
.Append(line
);
1654 if (positionFrom
< m_lines
.GetCount())
1656 wxNode
* node
= m_lines
.Item(positionFrom
);
1657 m_lines
.Insert(node
, line
);
1660 m_lines
.Append(line
);
1663 if (positionTo
== -1)
1664 other
->m_lines
.Append(line
);
1667 if (positionTo
< other
->m_lines
.GetCount())
1669 wxNode
* node
= other
->m_lines
.Item(positionTo
);
1670 other
->m_lines
.Insert(node
, line
);
1673 other
->m_lines
.Append(line
);
1677 line
->SetFrom(this);
1679 line
->SetAttachments(attachFrom
, attachTo
);
1682 void wxShape::RemoveLine(wxLineShape
*line
)
1684 if (line
->GetFrom() == this)
1685 line
->GetTo()->m_lines
.DeleteObject(line
);
1687 line
->GetFrom()->m_lines
.DeleteObject(line
);
1689 m_lines
.DeleteObject(line
);
1693 void wxShape::WriteAttributes(wxExpr
*clause
)
1695 clause
->AddAttributeValueString("type", GetClassInfo()->GetClassName());
1696 clause
->AddAttributeValue("id", m_id
);
1700 int penWidth
= m_pen
->GetWidth();
1701 int penStyle
= m_pen
->GetStyle();
1703 clause
->AddAttributeValue("pen_width", (long)penWidth
);
1704 if (penStyle
!= wxSOLID
)
1705 clause
->AddAttributeValue("pen_style", (long)penStyle
);
1707 wxString penColour
= wxTheColourDatabase
->FindName(m_pen
->GetColour());
1708 if (penColour
== "")
1710 wxString
hex(oglColourToHex(m_pen
->GetColour()));
1711 hex
= wxString("#") + hex
;
1712 clause
->AddAttributeValueString("pen_colour", hex
);
1714 else if (penColour
!= "BLACK")
1715 clause
->AddAttributeValueString("pen_colour", penColour
);
1720 wxString brushColour
= wxTheColourDatabase
->FindName(m_brush
->GetColour());
1722 if (brushColour
== "")
1724 wxString
hex(oglColourToHex(m_brush
->GetColour()));
1725 hex
= wxString("#") + hex
;
1726 clause
->AddAttributeValueString("brush_colour", hex
);
1728 else if (brushColour
!= "WHITE")
1729 clause
->AddAttributeValueString("brush_colour", brushColour
);
1731 if (m_brush
->GetStyle() != wxSOLID
)
1732 clause
->AddAttributeValue("brush_style", (long)m_brush
->GetStyle());
1737 int n_lines
= m_lines
.GetCount();
1740 wxExpr
*list
= new wxExpr(wxExprList
);
1741 wxNode
*node
= m_lines
.GetFirst();
1744 wxShape
*line
= (wxShape
*)node
->GetData();
1745 wxExpr
*id_expr
= new wxExpr(line
->GetId());
1746 list
->Append(id_expr
);
1747 node
= node
->GetNext();
1749 clause
->AddAttributeValue("arcs", list
);
1752 // Miscellaneous members
1753 if (m_attachmentMode
!= 0)
1754 clause
->AddAttributeValue("use_attachments", (long)m_attachmentMode
);
1755 if (m_sensitivity
!= OP_ALL
)
1756 clause
->AddAttributeValue("sensitivity", (long)m_sensitivity
);
1757 if (!m_spaceAttachments
)
1758 clause
->AddAttributeValue("space_attachments", (long)m_spaceAttachments
);
1760 clause
->AddAttributeValue("fixed_width", (long)m_fixedWidth
);
1762 clause
->AddAttributeValue("fixed_height", (long)m_fixedHeight
);
1763 if (m_shadowMode
!= SHADOW_NONE
)
1764 clause
->AddAttributeValue("shadow_mode", (long)m_shadowMode
);
1765 if (m_centreResize
!= TRUE
)
1766 clause
->AddAttributeValue("centre_resize", (long)0);
1767 clause
->AddAttributeValue("maintain_aspect_ratio", (long) m_maintainAspectRatio
);
1768 if (m_highlighted
!= FALSE
)
1769 clause
->AddAttributeValue("hilite", (long)m_highlighted
);
1771 if (m_parent
) // For composite objects
1772 clause
->AddAttributeValue("parent", (long)m_parent
->GetId());
1774 if (m_rotation
!= 0.0)
1775 clause
->AddAttributeValue("rotation", m_rotation
);
1777 if (!this->IsKindOf(CLASSINFO(wxLineShape
)))
1779 clause
->AddAttributeValue("neck_length", (long) m_branchNeckLength
);
1780 clause
->AddAttributeValue("stem_length", (long) m_branchStemLength
);
1781 clause
->AddAttributeValue("branch_spacing", (long) m_branchSpacing
);
1782 clause
->AddAttributeValue("branch_style", (long) m_branchStyle
);
1785 // Write user-defined attachment points, if any
1786 if (m_attachmentPoints
.GetCount() > 0)
1788 wxExpr
*attachmentList
= new wxExpr(wxExprList
);
1789 wxNode
*node
= m_attachmentPoints
.GetFirst();
1792 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->GetData();
1793 wxExpr
*pointExpr
= new wxExpr(wxExprList
);
1794 pointExpr
->Append(new wxExpr((long)point
->m_id
));
1795 pointExpr
->Append(new wxExpr(point
->m_x
));
1796 pointExpr
->Append(new wxExpr(point
->m_y
));
1797 attachmentList
->Append(pointExpr
);
1798 node
= node
->GetNext();
1800 clause
->AddAttributeValue("user_attachments", attachmentList
);
1803 // Write text regions
1804 WriteRegions(clause
);
1807 void wxShape::WriteRegions(wxExpr
*clause
)
1809 // Output regions as region1 = (...), region2 = (...), etc
1810 // and formatted text as text1 = (...), text2 = (...) etc.
1812 char regionNameBuf
[20];
1813 char textNameBuf
[20];
1814 wxNode
*node
= m_regions
.GetFirst();
1817 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
1818 sprintf(regionNameBuf
, "region%d", regionNo
);
1819 sprintf(textNameBuf
, "text%d", regionNo
);
1821 // Original text and region attributes:
1822 // region1 = (regionName regionText x y width height minWidth minHeight proportionX proportionY
1823 // formatMode fontSize fontFamily fontStyle fontWeight textColour)
1824 wxExpr
*regionExpr
= new wxExpr(wxExprList
);
1825 regionExpr
->Append(new wxExpr(wxExprString
, region
->m_regionName
));
1826 regionExpr
->Append(new wxExpr(wxExprString
, region
->m_regionText
));
1828 regionExpr
->Append(new wxExpr(region
->m_x
));
1829 regionExpr
->Append(new wxExpr(region
->m_y
));
1830 regionExpr
->Append(new wxExpr(region
->GetWidth()));
1831 regionExpr
->Append(new wxExpr(region
->GetHeight()));
1833 regionExpr
->Append(new wxExpr(region
->m_minWidth
));
1834 regionExpr
->Append(new wxExpr(region
->m_minHeight
));
1835 regionExpr
->Append(new wxExpr(region
->m_regionProportionX
));
1836 regionExpr
->Append(new wxExpr(region
->m_regionProportionY
));
1838 regionExpr
->Append(new wxExpr((long)region
->m_formatMode
));
1840 regionExpr
->Append(new wxExpr((long)(region
->m_font
? region
->m_font
->GetPointSize() : 10)));
1841 regionExpr
->Append(new wxExpr((long)(region
->m_font
? region
->m_font
->GetFamily() : wxDEFAULT
)));
1842 regionExpr
->Append(new wxExpr((long)(region
->m_font
? region
->m_font
->GetStyle() : wxDEFAULT
)));
1843 regionExpr
->Append(new wxExpr((long)(region
->m_font
? region
->m_font
->GetWeight() : wxNORMAL
)));
1844 regionExpr
->Append(new wxExpr(wxExprString
, region
->m_textColour
));
1846 // New members for pen colour/style
1847 regionExpr
->Append(new wxExpr(wxExprString
, region
->m_penColour
));
1848 regionExpr
->Append(new wxExpr((long)region
->m_penStyle
));
1851 // text1 = ((x y string) (x y string) ...)
1852 wxExpr
*textExpr
= new wxExpr(wxExprList
);
1854 wxNode
*textNode
= region
->m_formattedText
.GetFirst();
1857 wxShapeTextLine
*line
= (wxShapeTextLine
*)textNode
->GetData();
1858 wxExpr
*list2
= new wxExpr(wxExprList
);
1859 list2
->Append(new wxExpr(line
->GetX()));
1860 list2
->Append(new wxExpr(line
->GetY()));
1861 list2
->Append(new wxExpr(wxExprString
, line
->GetText()));
1862 textExpr
->Append(list2
);
1863 textNode
= textNode
->GetNext();
1866 // Now add both attributes to the clause
1867 clause
->AddAttributeValue(regionNameBuf
, regionExpr
);
1868 clause
->AddAttributeValue(textNameBuf
, textExpr
);
1870 node
= node
->GetNext();
1875 void wxShape::ReadAttributes(wxExpr
*clause
)
1877 clause
->GetAttributeValue("id", m_id
);
1880 clause
->GetAttributeValue("x", m_xpos
);
1881 clause
->GetAttributeValue("y", m_ypos
);
1883 // Input text strings (FOR COMPATIBILITY WITH OLD FILES ONLY. SEE REGION CODE BELOW.)
1885 wxExpr
*strings
= clause
->AttributeValue("text");
1886 if (strings
&& strings
->Type() == wxExprList
)
1888 m_formatted
= TRUE
; // Assume text is formatted unless we prove otherwise
1889 wxExpr
*node
= strings
->value
.first
;
1892 wxExpr
*string_expr
= node
;
1895 wxString
the_string("");
1897 // string_expr can either be a string, or a list of
1898 // 3 elements: x, y, and string.
1899 if (string_expr
->Type() == wxExprString
)
1901 the_string
= string_expr
->StringValue();
1902 m_formatted
= FALSE
;
1904 else if (string_expr
->Type() == wxExprList
)
1906 wxExpr
*first
= string_expr
->value
.first
;
1907 wxExpr
*second
= first
? first
->next
: (wxExpr
*) NULL
;
1908 wxExpr
*third
= second
? second
->next
: (wxExpr
*) NULL
;
1910 if (first
&& second
&& third
&&
1911 (first
->Type() == wxExprReal
|| first
->Type() == wxExprInteger
) &&
1912 (second
->Type() == wxExprReal
|| second
->Type() == wxExprInteger
) &&
1913 third
->Type() == wxExprString
)
1915 if (first
->Type() == wxExprReal
)
1916 the_x
= first
->RealValue();
1917 else the_x
= (double)first
->IntegerValue();
1919 if (second
->Type() == wxExprReal
)
1920 the_y
= second
->RealValue();
1921 else the_y
= (double)second
->IntegerValue();
1923 the_string
= third
->StringValue();
1926 wxShapeTextLine
*line
=
1927 new wxShapeTextLine(the_x
, the_y
, the_string
);
1928 m_text
.Append(line
);
1934 wxString pen_string
= "";
1935 wxString brush_string
= "";
1937 int pen_style
= wxSOLID
;
1938 int brush_style
= wxSOLID
;
1939 m_attachmentMode
= ATTACHMENT_MODE_NONE
;
1941 clause
->GetAttributeValue("pen_colour", pen_string
);
1942 clause
->GetAttributeValue("text_colour", m_textColourName
);
1944 SetTextColour(m_textColourName
);
1946 clause
->GetAttributeValue("region_name", m_regionName
);
1948 clause
->GetAttributeValue("brush_colour", brush_string
);
1949 clause
->GetAttributeValue("pen_width", pen_width
);
1950 clause
->GetAttributeValue("pen_style", pen_style
);
1951 clause
->GetAttributeValue("brush_style", brush_style
);
1953 int iVal
= (int) m_attachmentMode
;
1954 clause
->GetAttributeValue("use_attachments", iVal
);
1955 m_attachmentMode
= iVal
;
1957 clause
->GetAttributeValue("sensitivity", m_sensitivity
);
1959 iVal
= (int) m_spaceAttachments
;
1960 clause
->GetAttributeValue("space_attachments", iVal
);
1961 m_spaceAttachments
= (iVal
!= 0);
1963 iVal
= (int) m_fixedWidth
;
1964 clause
->GetAttributeValue("fixed_width", iVal
);
1965 m_fixedWidth
= (iVal
!= 0);
1967 iVal
= (int) m_fixedHeight
;
1968 clause
->GetAttributeValue("fixed_height", iVal
);
1969 m_fixedHeight
= (iVal
!= 0);
1971 clause
->GetAttributeValue("format_mode", m_formatMode
);
1972 clause
->GetAttributeValue("shadow_mode", m_shadowMode
);
1974 iVal
= m_branchNeckLength
;
1975 clause
->GetAttributeValue("neck_length", iVal
);
1976 m_branchNeckLength
= iVal
;
1978 iVal
= m_branchStemLength
;
1979 clause
->GetAttributeValue("stem_length", iVal
);
1980 m_branchStemLength
= iVal
;
1982 iVal
= m_branchSpacing
;
1983 clause
->GetAttributeValue("branch_spacing", iVal
);
1984 m_branchSpacing
= iVal
;
1986 clause
->GetAttributeValue("branch_style", m_branchStyle
);
1988 iVal
= (int) m_centreResize
;
1989 clause
->GetAttributeValue("centre_resize", iVal
);
1990 m_centreResize
= (iVal
!= 0);
1992 iVal
= (int) m_maintainAspectRatio
;
1993 clause
->GetAttributeValue("maintain_aspect_ratio", iVal
);
1994 m_maintainAspectRatio
= (iVal
!= 0);
1996 iVal
= (int) m_highlighted
;
1997 clause
->GetAttributeValue("hilite", iVal
);
1998 m_highlighted
= (iVal
!= 0);
2000 clause
->GetAttributeValue("rotation", m_rotation
);
2002 if (pen_string
== "")
2003 pen_string
= "BLACK";
2004 if (brush_string
== "")
2005 brush_string
= "WHITE";
2007 if (pen_string
.GetChar(0) == '#')
2009 wxColour
col(oglHexToColour(pen_string
.After('#')));
2010 m_pen
= wxThePenList
->FindOrCreatePen(col
, pen_width
, pen_style
);
2013 m_pen
= wxThePenList
->FindOrCreatePen(pen_string
, pen_width
, pen_style
);
2016 m_pen
= wxBLACK_PEN
;
2018 if (brush_string
.GetChar(0) == '#')
2020 wxColour
col(oglHexToColour(brush_string
.After('#')));
2021 m_brush
= wxTheBrushList
->FindOrCreateBrush(col
, brush_style
);
2024 m_brush
= wxTheBrushList
->FindOrCreateBrush(brush_string
, brush_style
);
2027 m_brush
= wxWHITE_BRUSH
;
2029 int point_size
= 10;
2030 clause
->GetAttributeValue("point_size", point_size
);
2031 SetFont(oglMatchFont(point_size
));
2033 // Read user-defined attachment points, if any
2034 wxExpr
*attachmentList
= clause
->AttributeValue("user_attachments");
2037 wxExpr
*pointExpr
= attachmentList
->GetFirst();
2040 wxExpr
*idExpr
= pointExpr
->Nth(0);
2041 wxExpr
*xExpr
= pointExpr
->Nth(1);
2042 wxExpr
*yExpr
= pointExpr
->Nth(2);
2043 if (idExpr
&& xExpr
&& yExpr
)
2045 wxAttachmentPoint
*point
= new wxAttachmentPoint
;
2046 point
->m_id
= (int)idExpr
->IntegerValue();
2047 point
->m_x
= xExpr
->RealValue();
2048 point
->m_y
= yExpr
->RealValue();
2049 m_attachmentPoints
.Append((wxObject
*)point
);
2051 pointExpr
= pointExpr
->GetNext();
2055 // Read text regions
2056 ReadRegions(clause
);
2059 void wxShape::ReadRegions(wxExpr
*clause
)
2063 // region1 = (regionName regionText x y width height minWidth minHeight proportionX proportionY
2064 // formatMode fontSize fontFamily fontStyle fontWeight textColour)
2066 char regionNameBuf
[20];
2067 char textNameBuf
[20];
2069 wxExpr
*regionExpr
= NULL
;
2070 wxExpr
*textExpr
= NULL
;
2071 sprintf(regionNameBuf
, "region%d", regionNo
);
2072 sprintf(textNameBuf
, "text%d", regionNo
);
2074 m_formatted
= TRUE
; // Assume text is formatted unless we prove otherwise
2076 while ((regionExpr
= clause
->AttributeValue(regionNameBuf
)))
2079 * Get the region information
2083 wxString
regionName("");
2084 wxString
regionText("");
2088 double height
= 0.0;
2089 double minWidth
= 5.0;
2090 double minHeight
= 5.0;
2091 double m_regionProportionX
= -1.0;
2092 double m_regionProportionY
= -1.0;
2093 int formatMode
= FORMAT_NONE
;
2095 int fontFamily
= wxSWISS
;
2096 int fontStyle
= wxNORMAL
;
2097 int fontWeight
= wxNORMAL
;
2098 wxString
regionTextColour("");
2099 wxString
penColour("");
2100 int penStyle
= wxSOLID
;
2102 if (regionExpr
->Type() == wxExprList
)
2104 wxExpr
*nameExpr
= regionExpr
->Nth(0);
2105 wxExpr
*textExpr
= regionExpr
->Nth(1);
2106 wxExpr
*xExpr
= regionExpr
->Nth(2);
2107 wxExpr
*yExpr
= regionExpr
->Nth(3);
2108 wxExpr
*widthExpr
= regionExpr
->Nth(4);
2109 wxExpr
*heightExpr
= regionExpr
->Nth(5);
2110 wxExpr
*minWidthExpr
= regionExpr
->Nth(6);
2111 wxExpr
*minHeightExpr
= regionExpr
->Nth(7);
2112 wxExpr
*propXExpr
= regionExpr
->Nth(8);
2113 wxExpr
*propYExpr
= regionExpr
->Nth(9);
2114 wxExpr
*formatExpr
= regionExpr
->Nth(10);
2115 wxExpr
*sizeExpr
= regionExpr
->Nth(11);
2116 wxExpr
*familyExpr
= regionExpr
->Nth(12);
2117 wxExpr
*styleExpr
= regionExpr
->Nth(13);
2118 wxExpr
*weightExpr
= regionExpr
->Nth(14);
2119 wxExpr
*colourExpr
= regionExpr
->Nth(15);
2120 wxExpr
*penColourExpr
= regionExpr
->Nth(16);
2121 wxExpr
*penStyleExpr
= regionExpr
->Nth(17);
2123 regionName
= nameExpr
->StringValue();
2124 regionText
= textExpr
->StringValue();
2126 x
= xExpr
->RealValue();
2127 y
= yExpr
->RealValue();
2129 width
= widthExpr
->RealValue();
2130 height
= heightExpr
->RealValue();
2132 minWidth
= minWidthExpr
->RealValue();
2133 minHeight
= minHeightExpr
->RealValue();
2135 m_regionProportionX
= propXExpr
->RealValue();
2136 m_regionProportionY
= propYExpr
->RealValue();
2138 formatMode
= (int) formatExpr
->IntegerValue();
2139 fontSize
= (int)sizeExpr
->IntegerValue();
2140 fontFamily
= (int)familyExpr
->IntegerValue();
2141 fontStyle
= (int)styleExpr
->IntegerValue();
2142 fontWeight
= (int)weightExpr
->IntegerValue();
2146 regionTextColour
= colourExpr
->StringValue();
2149 regionTextColour
= "BLACK";
2152 penColour
= penColourExpr
->StringValue();
2154 penStyle
= (int)penStyleExpr
->IntegerValue();
2156 wxFont
*font
= wxTheFontList
->FindOrCreateFont(fontSize
, fontFamily
, fontStyle
, fontWeight
);
2158 wxShapeRegion
*region
= new wxShapeRegion
;
2159 region
->SetProportions(m_regionProportionX
, m_regionProportionY
);
2160 region
->SetFont(font
);
2161 region
->SetSize(width
, height
);
2162 region
->SetPosition(x
, y
);
2163 region
->SetMinSize(minWidth
, minHeight
);
2164 region
->SetFormatMode(formatMode
);
2165 region
->SetPenStyle(penStyle
);
2166 if (penColour
!= "")
2167 region
->SetPenColour(penColour
);
2169 region
->m_textColour
= regionTextColour
;
2170 region
->m_regionText
= regionText
;
2171 region
->m_regionName
= regionName
;
2173 m_regions
.Append(region
);
2176 * Get the formatted text strings
2179 textExpr
= clause
->AttributeValue(textNameBuf
);
2180 if (textExpr
&& (textExpr
->Type() == wxExprList
))
2182 wxExpr
*node
= textExpr
->value
.first
;
2185 wxExpr
*string_expr
= node
;
2188 wxString
the_string("");
2190 // string_expr can either be a string, or a list of
2191 // 3 elements: x, y, and string.
2192 if (string_expr
->Type() == wxExprString
)
2194 the_string
= string_expr
->StringValue();
2195 m_formatted
= FALSE
;
2197 else if (string_expr
->Type() == wxExprList
)
2199 wxExpr
*first
= string_expr
->value
.first
;
2200 wxExpr
*second
= first
? first
->next
: (wxExpr
*) NULL
;
2201 wxExpr
*third
= second
? second
->next
: (wxExpr
*) NULL
;
2203 if (first
&& second
&& third
&&
2204 (first
->Type() == wxExprReal
|| first
->Type() == wxExprInteger
) &&
2205 (second
->Type() == wxExprReal
|| second
->Type() == wxExprInteger
) &&
2206 third
->Type() == wxExprString
)
2208 if (first
->Type() == wxExprReal
)
2209 the_x
= first
->RealValue();
2210 else the_x
= (double)first
->IntegerValue();
2212 if (second
->Type() == wxExprReal
)
2213 the_y
= second
->RealValue();
2214 else the_y
= (double)second
->IntegerValue();
2216 the_string
= third
->StringValue();
2221 wxShapeTextLine
*line
=
2222 new wxShapeTextLine(the_x
, the_y
, the_string
);
2223 region
->m_formattedText
.Append(line
);
2230 sprintf(regionNameBuf
, "region%d", regionNo
);
2231 sprintf(textNameBuf
, "text%d", regionNo
);
2234 // Compatibility: check for no regions (old file).
2235 // Lines and divided rectangles must deal with this compatibility
2236 // theirselves. Composites _may_ not have any regions anyway.
2237 if ((m_regions
.GetCount() == 0) &&
2238 !this->IsKindOf(CLASSINFO(wxLineShape
)) && !this->IsKindOf(CLASSINFO(wxDividedShape
)) &&
2239 !this->IsKindOf(CLASSINFO(wxCompositeShape
)))
2241 wxShapeRegion
*newRegion
= new wxShapeRegion
;
2242 newRegion
->SetName("0");
2243 m_regions
.Append((wxObject
*)newRegion
);
2244 if (m_text
.GetCount() > 0)
2246 newRegion
->ClearText();
2247 wxNode
*node
= m_text
.GetFirst();
2250 wxShapeTextLine
*textLine
= (wxShapeTextLine
*)node
->GetData();
2251 wxNode
*next
= node
->GetNext();
2252 newRegion
->GetFormattedText().Append((wxObject
*)textLine
);
2262 void wxShape::Copy(wxShape
& copy
)
2265 copy
.m_xpos
= m_xpos
;
2266 copy
.m_ypos
= m_ypos
;
2268 copy
.m_brush
= m_brush
;
2269 copy
.m_textColour
= m_textColour
;
2270 copy
.m_centreResize
= m_centreResize
;
2271 copy
.m_maintainAspectRatio
= m_maintainAspectRatio
;
2272 copy
.m_attachmentMode
= m_attachmentMode
;
2273 copy
.m_spaceAttachments
= m_spaceAttachments
;
2274 copy
.m_highlighted
= m_highlighted
;
2275 copy
.m_rotation
= m_rotation
;
2276 copy
.m_textColourName
= m_textColourName
;
2277 copy
.m_regionName
= m_regionName
;
2279 copy
.m_sensitivity
= m_sensitivity
;
2280 copy
.m_draggable
= m_draggable
;
2281 copy
.m_fixedWidth
= m_fixedWidth
;
2282 copy
.m_fixedHeight
= m_fixedHeight
;
2283 copy
.m_formatMode
= m_formatMode
;
2284 copy
.m_drawHandles
= m_drawHandles
;
2286 copy
.m_visible
= m_visible
;
2287 copy
.m_shadowMode
= m_shadowMode
;
2288 copy
.m_shadowOffsetX
= m_shadowOffsetX
;
2289 copy
.m_shadowOffsetY
= m_shadowOffsetY
;
2290 copy
.m_shadowBrush
= m_shadowBrush
;
2292 copy
.m_branchNeckLength
= m_branchNeckLength
;
2293 copy
.m_branchStemLength
= m_branchStemLength
;
2294 copy
.m_branchSpacing
= m_branchSpacing
;
2296 // Copy text regions
2297 copy
.ClearRegions();
2298 wxNode
*node
= m_regions
.GetFirst();
2301 wxShapeRegion
*region
= (wxShapeRegion
*)node
->GetData();
2302 wxShapeRegion
*newRegion
= new wxShapeRegion(*region
);
2303 copy
.m_regions
.Append(newRegion
);
2304 node
= node
->GetNext();
2308 copy
.ClearAttachments();
2309 node
= m_attachmentPoints
.GetFirst();
2312 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->GetData();
2313 wxAttachmentPoint
*newPoint
= new wxAttachmentPoint
;
2314 newPoint
->m_id
= point
->m_id
;
2315 newPoint
->m_x
= point
->m_x
;
2316 newPoint
->m_y
= point
->m_y
;
2317 copy
.m_attachmentPoints
.Append((wxObject
*)newPoint
);
2318 node
= node
->GetNext();
2322 copy
.m_lines
.Clear();
2323 node
= m_lines
.GetFirst();
2326 wxLineShape
* line
= (wxLineShape
*) node
->GetData();
2327 copy
.m_lines
.Append(line
);
2328 node
= node
->GetNext();
2332 // Create and return a new, fully copied object.
2333 wxShape
*wxShape::CreateNewCopy(bool resetMapping
, bool recompute
)
2336 oglObjectCopyMapping
.Clear();
2338 wxShape
* newObject
= (wxShape
*) GetClassInfo()->CreateObject();
2340 wxASSERT( (newObject
!= NULL
) );
2341 wxASSERT( (newObject
->IsKindOf(CLASSINFO(wxShape
))) );
2345 if (GetEventHandler() != this)
2347 wxShapeEvtHandler
* newHandler
= GetEventHandler()->CreateNewCopy();
2348 newObject
->SetEventHandler(newHandler
);
2349 newObject
->SetPreviousHandler(NULL
);
2350 newHandler
->SetPreviousHandler(newObject
);
2351 newHandler
->SetShape(newObject
);
2355 newObject
->Recompute();
2359 // Does the copying for this object, including copying event
2360 // handler data if any. Calls the virtual Copy function.
2361 void wxShape::CopyWithHandler(wxShape
& copy
)
2365 if (GetEventHandler() != this)
2367 wxASSERT( copy
.GetEventHandler() != NULL
);
2368 wxASSERT( copy
.GetEventHandler() != (©
) );
2369 wxASSERT( GetEventHandler()->GetClassInfo() == copy
.GetEventHandler()->GetClassInfo() );
2370 GetEventHandler()->CopyData(* (copy
.GetEventHandler()));
2375 // Default - make 6 control points
2376 void wxShape::MakeControlPoints()
2378 double maxX
, maxY
, minX
, minY
;
2380 GetBoundingBoxMax(&maxX
, &maxY
);
2381 GetBoundingBoxMin(&minX
, &minY
);
2383 double widthMin
= (double)(minX
+ CONTROL_POINT_SIZE
+ 2);
2384 double heightMin
= (double)(minY
+ CONTROL_POINT_SIZE
+ 2);
2386 // Offsets from main object
2387 double top
= (double)(- (heightMin
/ 2.0));
2388 double bottom
= (double)(heightMin
/ 2.0 + (maxY
- minY
));
2389 double left
= (double)(- (widthMin
/ 2.0));
2390 double right
= (double)(widthMin
/ 2.0 + (maxX
- minX
));
2392 wxControlPoint
*control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, left
, top
,
2393 CONTROL_POINT_DIAGONAL
);
2394 m_canvas
->AddShape(control
);
2395 m_controlPoints
.Append(control
);
2397 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, 0, top
,
2398 CONTROL_POINT_VERTICAL
);
2399 m_canvas
->AddShape(control
);
2400 m_controlPoints
.Append(control
);
2402 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, right
, top
,
2403 CONTROL_POINT_DIAGONAL
);
2404 m_canvas
->AddShape(control
);
2405 m_controlPoints
.Append(control
);
2407 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, right
, 0,
2408 CONTROL_POINT_HORIZONTAL
);
2409 m_canvas
->AddShape(control
);
2410 m_controlPoints
.Append(control
);
2412 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, right
, bottom
,
2413 CONTROL_POINT_DIAGONAL
);
2414 m_canvas
->AddShape(control
);
2415 m_controlPoints
.Append(control
);
2417 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, 0, bottom
,
2418 CONTROL_POINT_VERTICAL
);
2419 m_canvas
->AddShape(control
);
2420 m_controlPoints
.Append(control
);
2422 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, left
, bottom
,
2423 CONTROL_POINT_DIAGONAL
);
2424 m_canvas
->AddShape(control
);
2425 m_controlPoints
.Append(control
);
2427 control
= new wxControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
, left
, 0,
2428 CONTROL_POINT_HORIZONTAL
);
2429 m_canvas
->AddShape(control
);
2430 m_controlPoints
.Append(control
);
2434 void wxShape::MakeMandatoryControlPoints()
2436 wxNode
*node
= m_children
.GetFirst();
2439 wxShape
*child
= (wxShape
*)node
->GetData();
2440 child
->MakeMandatoryControlPoints();
2441 node
= node
->GetNext();
2445 void wxShape::ResetMandatoryControlPoints()
2447 wxNode
*node
= m_children
.GetFirst();
2450 wxShape
*child
= (wxShape
*)node
->GetData();
2451 child
->ResetMandatoryControlPoints();
2452 node
= node
->GetNext();
2456 void wxShape::ResetControlPoints()
2458 ResetMandatoryControlPoints();
2460 if (m_controlPoints
.GetCount() < 1)
2463 double maxX
, maxY
, minX
, minY
;
2465 GetBoundingBoxMax(&maxX
, &maxY
);
2466 GetBoundingBoxMin(&minX
, &minY
);
2468 double widthMin
= (double)(minX
+ CONTROL_POINT_SIZE
+ 2);
2469 double heightMin
= (double)(minY
+ CONTROL_POINT_SIZE
+ 2);
2471 // Offsets from main object
2472 double top
= (double)(- (heightMin
/ 2.0));
2473 double bottom
= (double)(heightMin
/ 2.0 + (maxY
- minY
));
2474 double left
= (double)(- (widthMin
/ 2.0));
2475 double right
= (double)(widthMin
/ 2.0 + (maxX
- minX
));
2477 wxNode
*node
= m_controlPoints
.GetFirst();
2478 wxControlPoint
*control
= (wxControlPoint
*)node
->GetData();
2479 control
->m_xoffset
= left
; control
->m_yoffset
= top
;
2481 node
= node
->GetNext(); control
= (wxControlPoint
*)node
->GetData();
2482 control
->m_xoffset
= 0; control
->m_yoffset
= top
;
2484 node
= node
->GetNext(); control
= (wxControlPoint
*)node
->GetData();
2485 control
->m_xoffset
= right
; control
->m_yoffset
= top
;
2487 node
= node
->GetNext(); control
= (wxControlPoint
*)node
->GetData();
2488 control
->m_xoffset
= right
; control
->m_yoffset
= 0;
2490 node
= node
->GetNext(); control
= (wxControlPoint
*)node
->GetData();
2491 control
->m_xoffset
= right
; control
->m_yoffset
= bottom
;
2493 node
= node
->GetNext(); control
= (wxControlPoint
*)node
->GetData();
2494 control
->m_xoffset
= 0; control
->m_yoffset
= bottom
;
2496 node
= node
->GetNext(); control
= (wxControlPoint
*)node
->GetData();
2497 control
->m_xoffset
= left
; control
->m_yoffset
= bottom
;
2499 node
= node
->GetNext(); control
= (wxControlPoint
*)node
->GetData();
2500 control
->m_xoffset
= left
; control
->m_yoffset
= 0;
2503 void wxShape::DeleteControlPoints(wxDC
*dc
)
2505 wxNode
*node
= m_controlPoints
.GetFirst();
2508 wxControlPoint
*control
= (wxControlPoint
*)node
->GetData();
2510 control
->GetEventHandler()->OnErase(*dc
);
2511 m_canvas
->RemoveShape(control
);
2514 node
= m_controlPoints
.GetFirst();
2516 // Children of divisions are contained objects,
2518 if (!IsKindOf(CLASSINFO(wxDivisionShape
)))
2520 node
= m_children
.GetFirst();
2523 wxShape
*child
= (wxShape
*)node
->GetData();
2524 child
->DeleteControlPoints(dc
);
2525 node
= node
->GetNext();
2530 void wxShape::OnDrawControlPoints(wxDC
& dc
)
2535 dc
.SetBrush(* wxBLACK_BRUSH
);
2536 dc
.SetPen(* wxBLACK_PEN
);
2538 wxNode
*node
= m_controlPoints
.GetFirst();
2541 wxControlPoint
*control
= (wxControlPoint
*)node
->GetData();
2543 node
= node
->GetNext();
2545 // Children of divisions are contained objects,
2547 // This test bypasses the type facility for speed
2548 // (critical when drawing)
2549 if (!IsKindOf(CLASSINFO(wxDivisionShape
)))
2551 node
= m_children
.GetFirst();
2554 wxShape
*child
= (wxShape
*)node
->GetData();
2555 child
->GetEventHandler()->OnDrawControlPoints(dc
);
2556 node
= node
->GetNext();
2561 void wxShape::OnEraseControlPoints(wxDC
& dc
)
2563 wxNode
*node
= m_controlPoints
.GetFirst();
2566 wxControlPoint
*control
= (wxControlPoint
*)node
->GetData();
2568 node
= node
->GetNext();
2570 if (!IsKindOf(CLASSINFO(wxDivisionShape
)))
2572 node
= m_children
.GetFirst();
2575 wxShape
*child
= (wxShape
*)node
->GetData();
2576 child
->GetEventHandler()->OnEraseControlPoints(dc
);
2577 node
= node
->GetNext();
2582 void wxShape::Select(bool select
, wxDC
* dc
)
2584 m_selected
= select
;
2587 MakeControlPoints();
2588 // Children of divisions are contained objects,
2590 if (!IsKindOf(CLASSINFO(wxDivisionShape
)))
2592 wxNode
*node
= m_children
.GetFirst();
2595 wxShape
*child
= (wxShape
*)node
->GetData();
2596 child
->MakeMandatoryControlPoints();
2597 node
= node
->GetNext();
2601 GetEventHandler()->OnDrawControlPoints(*dc
);
2605 DeleteControlPoints(dc
);
2606 if (!IsKindOf(CLASSINFO(wxDivisionShape
)))
2608 wxNode
*node
= m_children
.GetFirst();
2611 wxShape
*child
= (wxShape
*)node
->GetData();
2612 child
->DeleteControlPoints(dc
);
2613 node
= node
->GetNext();
2619 bool wxShape::Selected() const
2624 bool wxShape::AncestorSelected() const
2626 if (m_selected
) return TRUE
;
2630 return GetParent()->AncestorSelected();
2633 int wxShape::GetNumberOfAttachments() const
2635 // Should return the MAXIMUM attachment point id here,
2636 // so higher-level functions can iterate through all attachments,
2637 // even if they're not contiguous.
2638 if (m_attachmentPoints
.GetCount() == 0)
2643 wxNode
*node
= m_attachmentPoints
.GetFirst();
2646 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->GetData();
2647 if (point
->m_id
> maxN
)
2649 node
= node
->GetNext();
2655 bool wxShape::AttachmentIsValid(int attachment
) const
2657 if (m_attachmentPoints
.GetCount() == 0)
2659 return ((attachment
>= 0) && (attachment
< 4)) ;
2662 wxNode
*node
= m_attachmentPoints
.GetFirst();
2665 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->GetData();
2666 if (point
->m_id
== attachment
)
2668 node
= node
->GetNext();
2673 bool wxShape::GetAttachmentPosition(int attachment
, double *x
, double *y
,
2674 int nth
, int no_arcs
, wxLineShape
*line
)
2676 if (m_attachmentMode
== ATTACHMENT_MODE_NONE
)
2678 *x
= m_xpos
; *y
= m_ypos
;
2681 else if (m_attachmentMode
== ATTACHMENT_MODE_BRANCHING
)
2683 wxRealPoint pt
, stemPt
;
2684 GetBranchingAttachmentPoint(attachment
, nth
, pt
, stemPt
);
2689 else if (m_attachmentMode
== ATTACHMENT_MODE_EDGE
)
2691 if (m_attachmentPoints
.GetCount() > 0)
2693 wxNode
*node
= m_attachmentPoints
.GetFirst();
2696 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->GetData();
2697 if (point
->m_id
== attachment
)
2699 *x
= (double)(m_xpos
+ point
->m_x
);
2700 *y
= (double)(m_ypos
+ point
->m_y
);
2703 node
= node
->GetNext();
2705 *x
= m_xpos
; *y
= m_ypos
;
2710 // Assume is rectangular
2712 GetBoundingBoxMax(&w
, &h
);
2713 double top
= (double)(m_ypos
+ h
/2.0);
2714 double bottom
= (double)(m_ypos
- h
/2.0);
2715 double left
= (double)(m_xpos
- w
/2.0);
2716 double right
= (double)(m_xpos
+ w
/2.0);
2718 bool isEnd
= (line
&& line
->IsEnd(this));
2720 int physicalAttachment
= LogicalToPhysicalAttachment(attachment
);
2723 switch (physicalAttachment
)
2727 wxRealPoint pt
= CalcSimpleAttachment(wxRealPoint(left
, bottom
), wxRealPoint(right
, bottom
),
2728 nth
, no_arcs
, line
);
2730 *x
= pt
.x
; *y
= pt
.y
;
2735 wxRealPoint pt
= CalcSimpleAttachment(wxRealPoint(right
, bottom
), wxRealPoint(right
, top
),
2736 nth
, no_arcs
, line
);
2738 *x
= pt
.x
; *y
= pt
.y
;
2743 wxRealPoint pt
= CalcSimpleAttachment(wxRealPoint(left
, top
), wxRealPoint(right
, top
),
2744 nth
, no_arcs
, line
);
2746 *x
= pt
.x
; *y
= pt
.y
;
2751 wxRealPoint pt
= CalcSimpleAttachment(wxRealPoint(left
, bottom
), wxRealPoint(left
, top
),
2752 nth
, no_arcs
, line
);
2754 *x
= pt
.x
; *y
= pt
.y
;
2769 void wxShape::GetBoundingBoxMax(double *w
, double *h
)
2772 GetBoundingBoxMin(&ww
, &hh
);
2773 if (m_shadowMode
!= SHADOW_NONE
)
2775 ww
+= m_shadowOffsetX
;
2776 hh
+= m_shadowOffsetY
;
2782 // Returns TRUE if image is a descendant of this composite
2783 bool wxShape::HasDescendant(wxShape
*image
)
2787 wxNode
*node
= m_children
.GetFirst();
2790 wxShape
*child
= (wxShape
*)node
->GetData();
2791 bool ans
= child
->HasDescendant(image
);
2794 node
= node
->GetNext();
2799 // Clears points from a list of wxRealPoints, and clears list
2800 void wxShape::ClearPointList(wxList
& list
)
2802 wxNode
* node
= list
.GetFirst();
2805 wxRealPoint
* pt
= (wxRealPoint
*) node
->GetData();
2808 node
= node
->GetNext();
2813 // Assuming the attachment lies along a vertical or horizontal line,
2814 // calculate the position on that point.
2815 wxRealPoint
wxShape::CalcSimpleAttachment(const wxRealPoint
& pt1
, const wxRealPoint
& pt2
,
2816 int nth
, int noArcs
, wxLineShape
* line
)
2818 bool isEnd
= (line
&& line
->IsEnd(this));
2820 // Are we horizontal or vertical?
2821 bool isHorizontal
= (oglRoughlyEqual(pt1
.y
, pt2
.y
) == TRUE
);
2827 wxRealPoint firstPoint
, secondPoint
;
2839 if (m_spaceAttachments
)
2841 if (line
&& (line
->GetAlignmentType(isEnd
) == LINE_ALIGNMENT_TO_NEXT_HANDLE
))
2843 // Align line according to the next handle along
2844 wxRealPoint
*point
= line
->GetNextControlPoint(this);
2845 if (point
->x
< firstPoint
.x
)
2847 else if (point
->x
> secondPoint
.x
)
2853 x
= firstPoint
.x
+ (nth
+ 1)*(secondPoint
.x
- firstPoint
.x
)/(noArcs
+ 1);
2855 else x
= (secondPoint
.x
- firstPoint
.x
)/2.0; // Midpoint
2861 wxASSERT( oglRoughlyEqual(pt1
.x
, pt2
.x
) == TRUE
);
2863 wxRealPoint firstPoint
, secondPoint
;
2875 if (m_spaceAttachments
)
2877 if (line
&& (line
->GetAlignmentType(isEnd
) == LINE_ALIGNMENT_TO_NEXT_HANDLE
))
2879 // Align line according to the next handle along
2880 wxRealPoint
*point
= line
->GetNextControlPoint(this);
2881 if (point
->y
< firstPoint
.y
)
2883 else if (point
->y
> secondPoint
.y
)
2889 y
= firstPoint
.y
+ (nth
+ 1)*(secondPoint
.y
- firstPoint
.y
)/(noArcs
+ 1);
2891 else y
= (secondPoint
.y
- firstPoint
.y
)/2.0; // Midpoint
2896 return wxRealPoint(x
, y
);
2899 // Return the zero-based position in m_lines of line.
2900 int wxShape::GetLinePosition(wxLineShape
* line
)
2903 for (i
= 0; i
< m_lines
.GetCount(); i
++)
2904 if ((wxLineShape
*) (m_lines
.Item(i
)->GetData()) == line
)
2914 // shoulder1 ->---------<- shoulder2
2916 // <- branching attachment point N-1
2918 // This function gets information about where branching connections go.
2919 // Returns FALSE if there are no lines at this attachment.
2920 bool wxShape::GetBranchingAttachmentInfo(int attachment
, wxRealPoint
& root
, wxRealPoint
& neck
,
2921 wxRealPoint
& shoulder1
, wxRealPoint
& shoulder2
)
2923 int physicalAttachment
= LogicalToPhysicalAttachment(attachment
);
2925 // Number of lines at this attachment.
2926 int lineCount
= GetAttachmentLineCount(attachment
);
2931 int totalBranchLength
= m_branchSpacing
* (lineCount
- 1);
2933 root
= GetBranchingAttachmentRoot(attachment
);
2935 // Assume that we have attachment points 0 to 3: top, right, bottom, left.
2936 switch (physicalAttachment
)
2941 neck
.y
= root
.y
- m_branchNeckLength
;
2943 shoulder1
.x
= root
.x
- (totalBranchLength
/2.0) ;
2944 shoulder2
.x
= root
.x
+ (totalBranchLength
/2.0) ;
2946 shoulder1
.y
= neck
.y
;
2947 shoulder2
.y
= neck
.y
;
2952 neck
.x
= root
.x
+ m_branchNeckLength
;
2955 shoulder1
.x
= neck
.x
;
2956 shoulder2
.x
= neck
.x
;
2958 shoulder1
.y
= neck
.y
- (totalBranchLength
/2.0) ;
2959 shoulder2
.y
= neck
.y
+ (totalBranchLength
/2.0) ;
2965 neck
.y
= root
.y
+ m_branchNeckLength
;
2967 shoulder1
.x
= root
.x
- (totalBranchLength
/2.0) ;
2968 shoulder2
.x
= root
.x
+ (totalBranchLength
/2.0) ;
2970 shoulder1
.y
= neck
.y
;
2971 shoulder2
.y
= neck
.y
;
2976 neck
.x
= root
.x
- m_branchNeckLength
;
2979 shoulder1
.x
= neck
.x
;
2980 shoulder2
.x
= neck
.x
;
2982 shoulder1
.y
= neck
.y
- (totalBranchLength
/2.0) ;
2983 shoulder2
.y
= neck
.y
+ (totalBranchLength
/2.0) ;
2988 wxFAIL_MSG( wxT("Unrecognised attachment point in GetBranchingAttachmentInfo.") );
2995 // n is the number of the adjoining line, from 0 to N-1 where N is the number of lines
2996 // at this attachment point.
2997 // Get the attachment point where the arc joins the stem, and also the point where the
2998 // the stem meets the shoulder.
2999 bool wxShape::GetBranchingAttachmentPoint(int attachment
, int n
, wxRealPoint
& pt
, wxRealPoint
& stemPt
)
3001 int physicalAttachment
= LogicalToPhysicalAttachment(attachment
);
3003 wxRealPoint root
, neck
, shoulder1
, shoulder2
;
3004 GetBranchingAttachmentInfo(attachment
, root
, neck
, shoulder1
, shoulder2
);
3006 // Assume that we have attachment points 0 to 3: top, right, bottom, left.
3007 switch (physicalAttachment
)
3011 pt
.y
= neck
.y
- m_branchStemLength
;
3012 pt
.x
= shoulder1
.x
+ n
*m_branchSpacing
;
3020 pt
.y
= neck
.y
+ m_branchStemLength
;
3021 pt
.x
= shoulder1
.x
+ n
*m_branchSpacing
;
3029 pt
.x
= neck
.x
+ m_branchStemLength
;
3030 pt
.y
= shoulder1
.y
+ n
*m_branchSpacing
;
3038 pt
.x
= neck
.x
- m_branchStemLength
;
3039 pt
.y
= shoulder1
.y
+ n
*m_branchSpacing
;
3047 wxFAIL_MSG( wxT("Unrecognised attachment point in GetBranchingAttachmentPoint.") );
3055 // Get the number of lines at this attachment position.
3056 int wxShape::GetAttachmentLineCount(int attachment
) const
3059 wxNode
* node
= m_lines
.GetFirst();
3062 wxLineShape
* lineShape
= (wxLineShape
*) node
->GetData();
3063 if ((lineShape
->GetFrom() == this) && (lineShape
->GetAttachmentFrom() == attachment
))
3065 else if ((lineShape
->GetTo() == this) && (lineShape
->GetAttachmentTo() == attachment
))
3068 node
= node
->GetNext();
3073 // This function gets the root point at the given attachment.
3074 wxRealPoint
wxShape::GetBranchingAttachmentRoot(int attachment
)
3076 int physicalAttachment
= LogicalToPhysicalAttachment(attachment
);
3080 double width
, height
;
3081 GetBoundingBoxMax(& width
, & height
);
3083 // Assume that we have attachment points 0 to 3: top, right, bottom, left.
3084 switch (physicalAttachment
)
3089 root
.y
= GetY() - height
/2.0;
3094 root
.x
= GetX() + width
/2.0;
3101 root
.y
= GetY() + height
/2.0;
3106 root
.x
= GetX() - width
/2.0;
3112 wxFAIL_MSG( wxT("Unrecognised attachment point in GetBranchingAttachmentRoot.") );
3119 // Draw or erase the branches (not the actual arcs though)
3120 void wxShape::OnDrawBranches(wxDC
& dc
, int attachment
, bool erase
)
3122 int count
= GetAttachmentLineCount(attachment
);
3126 wxRealPoint root
, neck
, shoulder1
, shoulder2
;
3127 GetBranchingAttachmentInfo(attachment
, root
, neck
, shoulder1
, shoulder2
);
3131 dc
.SetPen(*wxWHITE_PEN
);
3132 dc
.SetBrush(*wxWHITE_BRUSH
);
3136 dc
.SetPen(*wxBLACK_PEN
);
3137 dc
.SetBrush(*wxBLACK_BRUSH
);
3141 dc
.DrawLine((long) root
.x
, (long) root
.y
, (long) neck
.x
, (long) neck
.y
);
3145 // Draw shoulder-to-shoulder line
3146 dc
.DrawLine((long) shoulder1
.x
, (long) shoulder1
.y
, (long) shoulder2
.x
, (long) shoulder2
.y
);
3148 // Draw all the little branches
3150 for (i
= 0; i
< count
; i
++)
3152 wxRealPoint pt
, stemPt
;
3153 GetBranchingAttachmentPoint(attachment
, i
, pt
, stemPt
);
3154 dc
.DrawLine((long) stemPt
.x
, (long) stemPt
.y
, (long) pt
.x
, (long) pt
.y
);
3156 if ((GetBranchStyle() & BRANCHING_ATTACHMENT_BLOB
) && (count
> 1))
3159 // dc.DrawEllipse((long) (stemPt.x + 0.5 - (blobSize/2.0)), (long) (stemPt.y + 0.5 - (blobSize/2.0)), blobSize, blobSize);
3160 dc
.DrawEllipse((long) (stemPt
.x
- (blobSize
/2.0)), (long) (stemPt
.y
- (blobSize
/2.0)), blobSize
, blobSize
);
3165 // Draw or erase the branches (not the actual arcs though)
3166 void wxShape::OnDrawBranches(wxDC
& dc
, bool erase
)
3168 if (m_attachmentMode
!= ATTACHMENT_MODE_BRANCHING
)
3171 int count
= GetNumberOfAttachments();
3173 for (i
= 0; i
< count
; i
++)
3174 OnDrawBranches(dc
, i
, erase
);
3177 // Only get the attachment position at the _edge_ of the shape, ignoring
3178 // branching mode. This is used e.g. to indicate the edge of interest, not the point
3179 // on the attachment branch.
3180 bool wxShape::GetAttachmentPositionEdge(int attachment
, double *x
, double *y
,
3181 int nth
, int no_arcs
, wxLineShape
*line
)
3183 int oldMode
= m_attachmentMode
;
3185 // Calculate as if to edge, not branch
3186 if (m_attachmentMode
== ATTACHMENT_MODE_BRANCHING
)
3187 m_attachmentMode
= ATTACHMENT_MODE_EDGE
;
3188 bool success
= GetAttachmentPosition(attachment
, x
, y
, nth
, no_arcs
, line
);
3189 m_attachmentMode
= oldMode
;
3194 // Rotate the standard attachment point from physical (0 is always North)
3195 // to logical (0 -> 1 if rotated by 90 degrees)
3196 int wxShape::PhysicalToLogicalAttachment(int physicalAttachment
) const
3198 const double pi
= 3.1415926535897932384626433832795 ;
3200 if (oglRoughlyEqual(GetRotation(), 0.0))
3202 i
= physicalAttachment
;
3204 else if (oglRoughlyEqual(GetRotation(), (pi
/2.0)))
3206 i
= physicalAttachment
- 1;
3208 else if (oglRoughlyEqual(GetRotation(), pi
))
3210 i
= physicalAttachment
- 2;
3212 else if (oglRoughlyEqual(GetRotation(), (3.0*pi
/2.0)))
3214 i
= physicalAttachment
- 3;
3217 // Can't handle -- assume the same.
3218 return physicalAttachment
;
3226 // Rotate the standard attachment point from logical
3227 // to physical (0 is always North)
3228 int wxShape::LogicalToPhysicalAttachment(int logicalAttachment
) const
3230 const double pi
= 3.1415926535897932384626433832795 ;
3232 if (oglRoughlyEqual(GetRotation(), 0.0))
3234 i
= logicalAttachment
;
3236 else if (oglRoughlyEqual(GetRotation(), (pi
/2.0)))
3238 i
= logicalAttachment
+ 1;
3240 else if (oglRoughlyEqual(GetRotation(), pi
))
3242 i
= logicalAttachment
+ 2;
3244 else if (oglRoughlyEqual(GetRotation(), (3.0*pi
/2.0)))
3246 i
= logicalAttachment
+ 3;
3249 // Can't handle -- assume the same.
3250 return logicalAttachment
;
3258 void wxShape::Rotate(double WXUNUSED(x
), double WXUNUSED(y
), double theta
)
3260 const double pi
= 3.1415926535897932384626433832795 ;
3262 if (m_rotation
< 0.0)
3266 else if (m_rotation
> 2*pi
)
3273 wxPen
wxShape::GetBackgroundPen()
3277 wxColour c
= GetCanvas()->GetBackgroundColour();
3278 return wxPen(c
, 1, wxSOLID
);
3280 return * g_oglWhiteBackgroundPen
;
3284 wxBrush
wxShape::GetBackgroundBrush()
3288 wxColour c
= GetCanvas()->GetBackgroundColour();
3289 return wxBrush(c
, wxSOLID
);
3291 return * g_oglWhiteBackgroundBrush
;