1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Basic OGL classes (2)
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "basicp.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 // Two stage construction: need to call Create
54 IMPLEMENT_DYNAMIC_CLASS(wxPolygonShape
, wxShape
)
56 wxPolygonShape::wxPolygonShape()
59 m_originalPoints
= NULL
;
62 void wxPolygonShape::Create(wxList
*the_points
)
66 m_originalPoints
= the_points
;
68 // Duplicate the list of points
69 m_points
= new wxList
;
71 wxNode
*node
= the_points
->GetFirst();
74 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
75 wxRealPoint
*new_point
= new wxRealPoint(point
->x
, point
->y
);
76 m_points
->Append((wxObject
*) new_point
);
77 node
= node
->GetNext();
79 CalculateBoundingBox();
80 m_originalWidth
= m_boundWidth
;
81 m_originalHeight
= m_boundHeight
;
82 SetDefaultRegionSize();
85 wxPolygonShape::~wxPolygonShape()
90 void wxPolygonShape::ClearPoints()
94 wxNode
*node
= m_points
->GetFirst();
97 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
100 node
= m_points
->GetFirst();
105 if (m_originalPoints
)
107 wxNode
*node
= m_originalPoints
->GetFirst();
110 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
113 node
= m_originalPoints
->GetFirst();
115 delete m_originalPoints
;
116 m_originalPoints
= NULL
;
121 // Width and height. Centre of object is centre of box.
122 void wxPolygonShape::GetBoundingBoxMin(double *width
, double *height
)
124 *width
= m_boundWidth
;
125 *height
= m_boundHeight
;
128 void wxPolygonShape::CalculateBoundingBox()
130 // Calculate bounding box at construction (and presumably resize) time
132 double right
= -10000;
134 double bottom
= -10000;
136 wxNode
*node
= m_points
->GetFirst();
139 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
140 if (point
->x
< left
) left
= point
->x
;
141 if (point
->x
> right
) right
= point
->x
;
143 if (point
->y
< top
) top
= point
->y
;
144 if (point
->y
> bottom
) bottom
= point
->y
;
146 node
= node
->GetNext();
148 m_boundWidth
= right
- left
;
149 m_boundHeight
= bottom
- top
;
152 // Recalculates the centre of the polygon, and
153 // readjusts the point offsets accordingly.
154 // Necessary since the centre of the polygon
155 // is expected to be the real centre of the bounding
157 void wxPolygonShape::CalculatePolygonCentre()
160 double right
= -10000;
162 double bottom
= -10000;
164 wxNode
*node
= m_points
->GetFirst();
167 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
168 if (point
->x
< left
) left
= point
->x
;
169 if (point
->x
> right
) right
= point
->x
;
171 if (point
->y
< top
) top
= point
->y
;
172 if (point
->y
> bottom
) bottom
= point
->y
;
174 node
= node
->GetNext();
176 double bwidth
= right
- left
;
177 double bheight
= bottom
- top
;
179 double newCentreX
= (double)(left
+ (bwidth
/2.0));
180 double newCentreY
= (double)(top
+ (bheight
/2.0));
182 node
= m_points
->GetFirst();
185 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
186 point
->x
-= newCentreX
;
187 point
->y
-= newCentreY
;
188 node
= node
->GetNext();
190 m_xpos
+= newCentreX
;
191 m_ypos
+= newCentreY
;
194 bool PolylineHitTest(double n
, double xvec
[], double yvec
[],
195 double x1
, double y1
, double x2
, double y2
)
199 double lastx
= xvec
[0];
200 double lasty
= yvec
[0];
202 double min_ratio
= 1.0;
207 for (i
= 1; i
< n
; i
++)
209 oglCheckLineIntersection(x1
, y1
, x2
, y2
, lastx
, lasty
, xvec
[i
], yvec
[i
],
210 &line_ratio
, &other_ratio
);
211 if (line_ratio
!= 1.0)
213 // sprintf(buf, "Line ratio = %.2f, other ratio = %.2f\n", line_ratio, other_ratio);
214 // ClipsErrorFunction(buf);
218 if (line_ratio
< min_ratio
)
219 min_ratio
= line_ratio
;
222 // Do last (implicit) line if last and first doubles are not identical
223 if (!(xvec
[0] == lastx
&& yvec
[0] == lasty
))
225 oglCheckLineIntersection(x1
, y1
, x2
, y2
, lastx
, lasty
, xvec
[0], yvec
[0],
226 &line_ratio
, &other_ratio
);
227 if (line_ratio
!= 1.0)
229 // sprintf(buf, "Line ratio = %.2f, other ratio = %.2f\n", line_ratio, other_ratio);
230 // ClipsErrorFunction(buf);
232 if (line_ratio
< min_ratio
)
233 min_ratio
= line_ratio
;
235 // ClipsErrorFunction("\n");
239 bool wxPolygonShape::HitTest(double x
, double y
, int *attachment
, double *distance
)
241 // Imagine four lines radiating from this point. If all of these lines hit the polygon,
242 // we're inside it, otherwise we're not. Obviously we'd need more radiating lines
243 // to be sure of correct results for very strange (concave) shapes.
244 double endPointsX
[4];
245 double endPointsY
[4];
248 endPointsY
[0] = (double)(y
- 1000.0);
250 endPointsX
[1] = (double)(x
+ 1000.0);
254 endPointsY
[2] = (double)(y
+ 1000.0);
256 endPointsX
[3] = (double)(x
- 1000.0);
259 // Store polygon points in an array
260 int np
= m_points
->GetCount();
261 double *xpoints
= new double[np
];
262 double *ypoints
= new double[np
];
263 wxNode
*node
= m_points
->GetFirst();
267 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
268 xpoints
[i
] = point
->x
+ m_xpos
;
269 ypoints
[i
] = point
->y
+ m_ypos
;
270 node
= node
->GetNext();
274 // We assume it's inside the polygon UNLESS one or more
275 // lines don't hit the outline.
276 bool isContained
= TRUE
;
279 for (i
= 0; i
< noPoints
; i
++)
281 if (!PolylineHitTest(np
, xpoints
, ypoints
, x
, y
, endPointsX
[i
], endPointsY
[i
]))
286 ClipsErrorFunction("It's a hit!\n");
288 ClipsErrorFunction("No hit.\n");
296 int nearest_attachment
= 0;
298 // If a hit, check the attachment points within the object.
299 int n
= GetNumberOfAttachments();
300 double nearest
= 999999.0;
302 for (i
= 0; i
< n
; i
++)
305 if (GetAttachmentPositionEdge(i
, &xp
, &yp
))
307 double l
= (double)sqrt(((xp
- x
) * (xp
- x
)) +
308 ((yp
- y
) * (yp
- y
)));
312 nearest_attachment
= i
;
316 *attachment
= nearest_attachment
;
321 // Really need to be able to reset the shape! Otherwise, if the
322 // points ever go to zero, we've lost it, and can't resize.
323 void wxPolygonShape::SetSize(double new_width
, double new_height
, bool recursive
)
325 SetAttachmentSize(new_width
, new_height
);
327 // Multiply all points by proportion of new size to old size
328 double x_proportion
= (double)(fabs(new_width
/m_originalWidth
));
329 double y_proportion
= (double)(fabs(new_height
/m_originalHeight
));
331 wxNode
*node
= m_points
->GetFirst();
332 wxNode
*original_node
= m_originalPoints
->GetFirst();
333 while (node
&& original_node
)
335 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
336 wxRealPoint
*original_point
= (wxRealPoint
*)original_node
->GetData();
338 point
->x
= (original_point
->x
* x_proportion
);
339 point
->y
= (original_point
->y
* y_proportion
);
341 node
= node
->GetNext();
342 original_node
= original_node
->GetNext();
345 // CalculateBoundingBox();
346 m_boundWidth
= (double)fabs(new_width
);
347 m_boundHeight
= (double)fabs(new_height
);
348 SetDefaultRegionSize();
351 // Make the original points the same as the working points
352 void wxPolygonShape::UpdateOriginalPoints()
354 if (!m_originalPoints
) m_originalPoints
= new wxList
;
355 wxNode
*original_node
= m_originalPoints
->GetFirst();
356 while (original_node
)
358 wxNode
*next_node
= original_node
->GetNext();
359 wxRealPoint
*original_point
= (wxRealPoint
*)original_node
->GetData();
360 delete original_point
;
361 delete original_node
;
363 original_node
= next_node
;
366 wxNode
*node
= m_points
->GetFirst();
369 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
370 wxRealPoint
*original_point
= new wxRealPoint(point
->x
, point
->y
);
371 m_originalPoints
->Append((wxObject
*) original_point
);
373 node
= node
->GetNext();
375 CalculateBoundingBox();
376 m_originalWidth
= m_boundWidth
;
377 m_originalHeight
= m_boundHeight
;
380 void wxPolygonShape::AddPolygonPoint(int pos
)
382 wxNode
*node
= m_points
->Item(pos
);
383 if (!node
) node
= m_points
->GetFirst();
384 wxRealPoint
*firstPoint
= (wxRealPoint
*)node
->GetData();
386 wxNode
*node2
= m_points
->Item(pos
+ 1);
387 if (!node2
) node2
= m_points
->GetFirst();
388 wxRealPoint
*secondPoint
= (wxRealPoint
*)node2
->GetData();
390 double x
= (double)((secondPoint
->x
- firstPoint
->x
)/2.0 + firstPoint
->x
);
391 double y
= (double)((secondPoint
->y
- firstPoint
->y
)/2.0 + firstPoint
->y
);
392 wxRealPoint
*point
= new wxRealPoint(x
, y
);
394 if (pos
>= (int) (m_points
->GetCount() - 1))
395 m_points
->Append((wxObject
*) point
);
397 m_points
->Insert(node2
, (wxObject
*) point
);
399 UpdateOriginalPoints();
403 DeleteControlPoints();
408 void wxPolygonShape::DeletePolygonPoint(int pos
)
410 wxNode
*node
= m_points
->Item(pos
);
413 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
416 UpdateOriginalPoints();
419 DeleteControlPoints();
425 // Assume (x1, y1) is centre of box (most generally, line end at box)
426 bool wxPolygonShape::GetPerimeterPoint(double x1
, double y1
,
427 double x2
, double y2
,
428 double *x3
, double *y3
)
430 int n
= m_points
->GetCount();
432 // First check for situation where the line is vertical,
433 // and we would want to connect to a point on that vertical --
434 // oglFindEndForPolyline can't cope with this (the arrow
435 // gets drawn to the wrong place).
436 if ((m_attachmentMode
== ATTACHMENT_MODE_NONE
) && (x1
== x2
))
438 // Look for the point we'd be connecting to. This is
440 wxNode
*node
= m_points
->GetFirst();
443 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
446 if ((y2
> y1
) && (point
->y
> 0.0))
448 *x3
= point
->x
+ m_xpos
;
449 *y3
= point
->y
+ m_ypos
;
452 else if ((y2
< y1
) && (point
->y
< 0.0))
454 *x3
= point
->x
+ m_xpos
;
455 *y3
= point
->y
+ m_ypos
;
459 node
= node
->GetNext();
463 double *xpoints
= new double[n
];
464 double *ypoints
= new double[n
];
466 wxNode
*node
= m_points
->GetFirst();
470 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
471 xpoints
[i
] = point
->x
+ m_xpos
;
472 ypoints
[i
] = point
->y
+ m_ypos
;
473 node
= node
->GetNext();
477 oglFindEndForPolyline(n
, xpoints
, ypoints
,
478 x1
, y1
, x2
, y2
, x3
, y3
);
486 void wxPolygonShape::OnDraw(wxDC
& dc
)
488 int n
= m_points
->GetCount();
489 wxPoint
*intPoints
= new wxPoint
[n
];
491 for (i
= 0; i
< n
; i
++)
493 wxRealPoint
* point
= (wxRealPoint
*) m_points
->Item(i
)->GetData();
494 intPoints
[i
].x
= WXROUND(point
->x
);
495 intPoints
[i
].y
= WXROUND(point
->y
);
498 if (m_shadowMode
!= SHADOW_NONE
)
501 dc
.SetBrush(* m_shadowBrush
);
502 dc
.SetPen(* g_oglTransparentPen
);
504 dc
.DrawPolygon(n
, intPoints
, WXROUND(m_xpos
+ m_shadowOffsetX
), WXROUND(m_ypos
+ m_shadowOffsetY
));
509 if (m_pen
->GetWidth() == 0)
510 dc
.SetPen(* g_oglTransparentPen
);
515 dc
.SetBrush(* m_brush
);
516 dc
.DrawPolygon(n
, intPoints
, WXROUND(m_xpos
), WXROUND(m_ypos
));
521 void wxPolygonShape::OnDrawOutline(wxDC
& dc
, double x
, double y
, double w
, double h
)
523 dc
.SetBrush(* wxTRANSPARENT_BRUSH
);
524 // Multiply all points by proportion of new size to old size
525 double x_proportion
= (double)(fabs(w
/m_originalWidth
));
526 double y_proportion
= (double)(fabs(h
/m_originalHeight
));
528 int n
= m_originalPoints
->GetCount();
529 wxPoint
*intPoints
= new wxPoint
[n
];
531 for (i
= 0; i
< n
; i
++)
533 wxRealPoint
* point
= (wxRealPoint
*) m_originalPoints
->Item(i
)->GetData();
534 intPoints
[i
].x
= WXROUND(x_proportion
* point
->x
);
535 intPoints
[i
].y
= WXROUND(y_proportion
* point
->y
);
537 dc
.DrawPolygon(n
, intPoints
, WXROUND(x
), WXROUND(y
));
541 // Make as many control points as there are vertices.
542 void wxPolygonShape::MakeControlPoints()
544 wxNode
*node
= m_points
->GetFirst();
547 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
548 wxPolygonControlPoint
*control
= new wxPolygonControlPoint(m_canvas
, this, CONTROL_POINT_SIZE
,
549 point
, point
->x
, point
->y
);
550 m_canvas
->AddShape(control
);
551 m_controlPoints
.Append(control
);
552 node
= node
->GetNext();
556 void wxPolygonShape::ResetControlPoints()
558 wxNode
*node
= m_points
->GetFirst();
559 wxNode
*controlPointNode
= m_controlPoints
.GetFirst();
560 while (node
&& controlPointNode
)
562 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
563 wxPolygonControlPoint
*controlPoint
= (wxPolygonControlPoint
*)controlPointNode
->GetData();
565 controlPoint
->m_xoffset
= point
->x
;
566 controlPoint
->m_yoffset
= point
->y
;
567 controlPoint
->m_polygonVertex
= point
;
569 node
= node
->GetNext();
570 controlPointNode
= controlPointNode
->GetNext();
576 void wxPolygonShape::WriteAttributes(wxExpr
*clause
)
578 wxShape::WriteAttributes(clause
);
580 clause
->AddAttributeValue(wxT("x"), m_xpos
);
581 clause
->AddAttributeValue(wxT("y"), m_ypos
);
583 // Make a list of lists for the coordinates
584 wxExpr
*list
= new wxExpr(wxExprList
);
585 wxNode
*node
= m_points
->GetFirst();
588 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
589 wxExpr
*point_list
= new wxExpr(wxExprList
);
590 wxExpr
*x_expr
= new wxExpr((double)point
->x
);
591 wxExpr
*y_expr
= new wxExpr((double)point
->y
);
593 point_list
->Append(x_expr
);
594 point_list
->Append(y_expr
);
595 list
->Append(point_list
);
597 node
= node
->GetNext();
599 clause
->AddAttributeValue(wxT("points"), list
);
601 // Save the original (unscaled) points
602 list
= new wxExpr(wxExprList
);
603 node
= m_originalPoints
->GetFirst();
606 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
607 wxExpr
*point_list
= new wxExpr(wxExprList
);
608 wxExpr
*x_expr
= new wxExpr((double) point
->x
);
609 wxExpr
*y_expr
= new wxExpr((double) point
->y
);
610 point_list
->Append(x_expr
);
611 point_list
->Append(y_expr
);
612 list
->Append(point_list
);
614 node
= node
->GetNext();
616 clause
->AddAttributeValue(wxT("m_originalPoints"), list
);
619 void wxPolygonShape::ReadAttributes(wxExpr
*clause
)
621 wxShape::ReadAttributes(clause
);
623 // Read a list of lists
624 m_points
= new wxList
;
625 m_originalPoints
= new wxList
;
627 wxExpr
*points_list
= NULL
;
628 clause
->AssignAttributeValue(wxT("points"), &points_list
);
630 // If no points_list, don't crash!! Assume a diamond instead.
631 double the_height
= 100.0;
632 double the_width
= 100.0;
635 wxRealPoint
*point
= new wxRealPoint(0.0, (-the_height
/2));
636 m_points
->Append((wxObject
*) point
);
638 point
= new wxRealPoint((the_width
/2), 0.0);
639 m_points
->Append((wxObject
*) point
);
641 point
= new wxRealPoint(0.0, (the_height
/2));
642 m_points
->Append((wxObject
*) point
);
644 point
= new wxRealPoint((-the_width
/2), 0.0);
645 m_points
->Append((wxObject
*) point
);
647 point
= new wxRealPoint(0.0, (-the_height
/2));
648 m_points
->Append((wxObject
*) point
);
652 wxExpr
*node
= points_list
->value
.first
;
656 wxExpr
*xexpr
= node
->value
.first
;
657 long x
= xexpr
->IntegerValue();
659 wxExpr
*yexpr
= xexpr
->next
;
660 long y
= yexpr
->IntegerValue();
662 wxRealPoint
*point
= new wxRealPoint((double)x
, (double)y
);
663 m_points
->Append((wxObject
*) point
);
670 clause
->AssignAttributeValue(wxT("m_originalPoints"), &points_list
);
672 // If no points_list, don't crash!! Assume a diamond instead.
675 wxRealPoint
*point
= new wxRealPoint(0.0, (-the_height
/2));
676 m_originalPoints
->Append((wxObject
*) point
);
678 point
= new wxRealPoint((the_width
/2), 0.0);
679 m_originalPoints
->Append((wxObject
*) point
);
681 point
= new wxRealPoint(0.0, (the_height
/2));
682 m_originalPoints
->Append((wxObject
*) point
);
684 point
= new wxRealPoint((-the_width
/2), 0.0);
685 m_originalPoints
->Append((wxObject
*) point
);
687 point
= new wxRealPoint(0.0, (-the_height
/2));
688 m_originalPoints
->Append((wxObject
*) point
);
690 m_originalWidth
= the_width
;
691 m_originalHeight
= the_height
;
695 wxExpr
*node
= points_list
->value
.first
;
698 double max_x
= -1000;
699 double max_y
= -1000;
702 wxExpr
*xexpr
= node
->value
.first
;
703 long x
= xexpr
->IntegerValue();
705 wxExpr
*yexpr
= xexpr
->next
;
706 long y
= yexpr
->IntegerValue();
708 wxRealPoint
*point
= new wxRealPoint((double)x
, (double)y
);
709 m_originalPoints
->Append((wxObject
*) point
);
722 m_originalWidth
= max_x
- min_x
;
723 m_originalHeight
= max_y
- min_y
;
726 CalculateBoundingBox();
730 void wxPolygonShape::Copy(wxShape
& copy
)
734 wxASSERT( copy
.IsKindOf(CLASSINFO(wxPolygonShape
)) );
736 wxPolygonShape
& polyCopy
= (wxPolygonShape
&) copy
;
738 polyCopy
.ClearPoints();
740 polyCopy
.m_points
= new wxList
;
741 polyCopy
.m_originalPoints
= new wxList
;
743 wxNode
*node
= m_points
->GetFirst();
746 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
747 wxRealPoint
*new_point
= new wxRealPoint(point
->x
, point
->y
);
748 polyCopy
.m_points
->Append((wxObject
*) new_point
);
749 node
= node
->GetNext();
751 node
= m_originalPoints
->GetFirst();
754 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
755 wxRealPoint
*new_point
= new wxRealPoint(point
->x
, point
->y
);
756 polyCopy
.m_originalPoints
->Append((wxObject
*) new_point
);
757 node
= node
->GetNext();
759 polyCopy
.m_boundWidth
= m_boundWidth
;
760 polyCopy
.m_boundHeight
= m_boundHeight
;
761 polyCopy
.m_originalWidth
= m_originalWidth
;
762 polyCopy
.m_originalHeight
= m_originalHeight
;
765 int wxPolygonShape::GetNumberOfAttachments() const
767 int maxN
= (m_points
? (m_points
->GetCount() - 1) : 0);
768 wxNode
*node
= m_attachmentPoints
.GetFirst();
771 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->GetData();
772 if (point
->m_id
> maxN
)
774 node
= node
->GetNext();
779 bool wxPolygonShape::GetAttachmentPosition(int attachment
, double *x
, double *y
,
780 int nth
, int no_arcs
, wxLineShape
*line
)
782 if ((m_attachmentMode
== ATTACHMENT_MODE_EDGE
) && m_points
&& attachment
< (int) m_points
->GetCount())
784 wxRealPoint
*point
= (wxRealPoint
*)m_points
->Item(attachment
)->GetData();
785 *x
= point
->x
+ m_xpos
;
786 *y
= point
->y
+ m_ypos
;
790 { return wxShape::GetAttachmentPosition(attachment
, x
, y
, nth
, no_arcs
, line
); }
793 bool wxPolygonShape::AttachmentIsValid(int attachment
) const
798 if ((attachment
>= 0) && (attachment
< (int) m_points
->GetCount()))
801 wxNode
*node
= m_attachmentPoints
.GetFirst();
804 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->GetData();
805 if (point
->m_id
== attachment
)
807 node
= node
->GetNext();
812 // Rotate about the given axis by the given amount in radians
813 void wxPolygonShape::Rotate(double x
, double y
, double theta
)
815 double actualTheta
= theta
-m_rotation
;
817 // Rotate attachment points
818 double sinTheta
= (double)sin(actualTheta
);
819 double cosTheta
= (double)cos(actualTheta
);
820 wxNode
*node
= m_attachmentPoints
.GetFirst();
823 wxAttachmentPoint
*point
= (wxAttachmentPoint
*)node
->GetData();
824 double x1
= point
->m_x
;
825 double y1
= point
->m_y
;
826 point
->m_x
= x1
*cosTheta
- y1
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
827 point
->m_y
= x1
*sinTheta
+ y1
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
828 node
= node
->GetNext();
831 node
= m_points
->GetFirst();
834 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
835 double x1
= point
->x
;
836 double y1
= point
->y
;
837 point
->x
= x1
*cosTheta
- y1
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
838 point
->y
= x1
*sinTheta
+ y1
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
839 node
= node
->GetNext();
841 node
= m_originalPoints
->GetFirst();
844 wxRealPoint
*point
= (wxRealPoint
*)node
->GetData();
845 double x1
= point
->x
;
846 double y1
= point
->y
;
847 point
->x
= x1
*cosTheta
- y1
*sinTheta
+ x
*(1.0 - cosTheta
) + y
*sinTheta
;
848 point
->y
= x1
*sinTheta
+ y1
*cosTheta
+ y
*(1.0 - cosTheta
) + x
*sinTheta
;
849 node
= node
->GetNext();
854 CalculatePolygonCentre();
855 CalculateBoundingBox();
856 ResetControlPoints();
861 IMPLEMENT_DYNAMIC_CLASS(wxRectangleShape
, wxShape
)
863 wxRectangleShape::wxRectangleShape(double w
, double h
)
865 m_width
= w
; m_height
= h
; m_cornerRadius
= 0.0;
866 SetDefaultRegionSize();
869 void wxRectangleShape::OnDraw(wxDC
& dc
)
871 double x1
= (double)(m_xpos
- m_width
/2.0);
872 double y1
= (double)(m_ypos
- m_height
/2.0);
874 if (m_shadowMode
!= SHADOW_NONE
)
877 dc
.SetBrush(* m_shadowBrush
);
878 dc
.SetPen(* g_oglTransparentPen
);
880 if (m_cornerRadius
!= 0.0)
881 dc
.DrawRoundedRectangle(WXROUND(x1
+ m_shadowOffsetX
), WXROUND(y1
+ m_shadowOffsetY
),
882 WXROUND(m_width
), WXROUND(m_height
), m_cornerRadius
);
884 dc
.DrawRectangle(WXROUND(x1
+ m_shadowOffsetX
), WXROUND(y1
+ m_shadowOffsetY
), WXROUND(m_width
), WXROUND(m_height
));
889 if (m_pen
->GetWidth() == 0)
890 dc
.SetPen(* g_oglTransparentPen
);
895 dc
.SetBrush(* m_brush
);
897 if (m_cornerRadius
!= 0.0)
898 dc
.DrawRoundedRectangle(WXROUND(x1
), WXROUND(y1
), WXROUND(m_width
), WXROUND(m_height
), m_cornerRadius
);
900 dc
.DrawRectangle(WXROUND(x1
), WXROUND(y1
), WXROUND(m_width
), WXROUND(m_height
));
903 void wxRectangleShape::GetBoundingBoxMin(double *the_width
, double *the_height
)
905 *the_width
= m_width
;
906 *the_height
= m_height
;
909 void wxRectangleShape::SetSize(double x
, double y
, bool recursive
)
911 SetAttachmentSize(x
, y
);
912 m_width
= (double)wxMax(x
, 1.0);
913 m_height
= (double)wxMax(y
, 1.0);
914 SetDefaultRegionSize();
917 void wxRectangleShape::SetCornerRadius(double rad
)
919 m_cornerRadius
= rad
;
922 // Assume (x1, y1) is centre of box (most generally, line end at box)
923 bool wxRectangleShape::GetPerimeterPoint(double x1
, double y1
,
924 double x2
, double y2
,
925 double *x3
, double *y3
)
927 double bound_x
, bound_y
;
928 GetBoundingBoxMax(&bound_x
, &bound_y
);
929 oglFindEndForBox(bound_x
, bound_y
, m_xpos
, m_ypos
, x2
, y2
, x3
, y3
);
935 void wxRectangleShape::WriteAttributes(wxExpr
*clause
)
937 wxShape::WriteAttributes(clause
);
938 clause
->AddAttributeValue(wxT("x"), m_xpos
);
939 clause
->AddAttributeValue(wxT("y"), m_ypos
);
941 clause
->AddAttributeValue(wxT("width"), m_width
);
942 clause
->AddAttributeValue(wxT("height"), m_height
);
943 if (m_cornerRadius
!= 0.0)
944 clause
->AddAttributeValue(wxT("corner"), m_cornerRadius
);
947 void wxRectangleShape::ReadAttributes(wxExpr
*clause
)
949 wxShape::ReadAttributes(clause
);
950 clause
->AssignAttributeValue(wxT("width"), &m_width
);
951 clause
->AssignAttributeValue(wxT("height"), &m_height
);
952 clause
->AssignAttributeValue(wxT("corner"), &m_cornerRadius
);
954 // In case we're reading an old file, set the region's size
955 if (m_regions
.GetCount() == 1)
957 wxShapeRegion
*region
= (wxShapeRegion
*)m_regions
.GetFirst()->GetData();
958 region
->SetSize(m_width
, m_height
);
963 void wxRectangleShape::Copy(wxShape
& copy
)
967 wxASSERT( copy
.IsKindOf(CLASSINFO(wxRectangleShape
)) );
969 wxRectangleShape
& rectCopy
= (wxRectangleShape
&) copy
;
970 rectCopy
.m_width
= m_width
;
971 rectCopy
.m_height
= m_height
;
972 rectCopy
.m_cornerRadius
= m_cornerRadius
;
975 int wxRectangleShape::GetNumberOfAttachments() const
977 return wxShape::GetNumberOfAttachments();
981 // There are 4 attachment points on a rectangle - 0 = top, 1 = right, 2 = bottom,
983 bool wxRectangleShape::GetAttachmentPosition(int attachment
, double *x
, double *y
,
984 int nth
, int no_arcs
, wxLineShape
*line
)
986 return wxShape::GetAttachmentPosition(attachment
, x
, y
, nth
, no_arcs
, line
);
989 // Text object (no box)
991 IMPLEMENT_DYNAMIC_CLASS(wxTextShape
, wxRectangleShape
)
993 wxTextShape::wxTextShape(double width
, double height
):
994 wxRectangleShape(width
, height
)
998 void wxTextShape::OnDraw(wxDC
& dc
)
1002 void wxTextShape::Copy(wxShape
& copy
)
1004 wxRectangleShape::Copy(copy
);
1008 void wxTextShape::WriteAttributes(wxExpr
*clause
)
1010 wxRectangleShape::WriteAttributes(clause
);
1016 IMPLEMENT_DYNAMIC_CLASS(wxEllipseShape
, wxShape
)
1018 wxEllipseShape::wxEllipseShape(double w
, double h
)
1020 m_width
= w
; m_height
= h
;
1021 SetDefaultRegionSize();
1024 void wxEllipseShape::GetBoundingBoxMin(double *w
, double *h
)
1026 *w
= m_width
; *h
= m_height
;
1029 bool wxEllipseShape::GetPerimeterPoint(double x1
, double y1
,
1030 double x2
, double y2
,
1031 double *x3
, double *y3
)
1033 double bound_x
, bound_y
;
1034 GetBoundingBoxMax(&bound_x
, &bound_y
);
1036 // oglFindEndForBox(bound_x, bound_y, m_xpos, m_ypos, x2, y2, x3, y3);
1037 oglDrawArcToEllipse(m_xpos
, m_ypos
, bound_x
, bound_y
, x2
, y2
, x1
, y1
, x3
, y3
);
1042 void wxEllipseShape::OnDraw(wxDC
& dc
)
1044 if (m_shadowMode
!= SHADOW_NONE
)
1047 dc
.SetBrush(* m_shadowBrush
);
1048 dc
.SetPen(* g_oglTransparentPen
);
1049 dc
.DrawEllipse((long) ((m_xpos
- GetWidth()/2) + m_shadowOffsetX
),
1050 (long) ((m_ypos
- GetHeight()/2) + m_shadowOffsetY
),
1051 (long) GetWidth(), (long) GetHeight());
1056 if (m_pen
->GetWidth() == 0)
1057 dc
.SetPen(* g_oglTransparentPen
);
1062 dc
.SetBrush(* m_brush
);
1063 dc
.DrawEllipse((long) (m_xpos
- GetWidth()/2), (long) (m_ypos
- GetHeight()/2), (long) GetWidth(), (long) GetHeight());
1066 void wxEllipseShape::SetSize(double x
, double y
, bool recursive
)
1068 SetAttachmentSize(x
, y
);
1071 SetDefaultRegionSize();
1075 void wxEllipseShape::WriteAttributes(wxExpr
*clause
)
1077 wxShape::WriteAttributes(clause
);
1078 clause
->AddAttributeValue(wxT("x"), m_xpos
);
1079 clause
->AddAttributeValue(wxT("y"), m_ypos
);
1081 clause
->AddAttributeValue(wxT("width"), m_width
);
1082 clause
->AddAttributeValue(wxT("height"), m_height
);
1085 void wxEllipseShape::ReadAttributes(wxExpr
*clause
)
1087 wxShape::ReadAttributes(clause
);
1088 clause
->AssignAttributeValue(wxT("width"), &m_width
);
1089 clause
->AssignAttributeValue(wxT("height"), &m_height
);
1091 // In case we're reading an old file, set the region's size
1092 if (m_regions
.GetCount() == 1)
1094 wxShapeRegion
*region
= (wxShapeRegion
*)m_regions
.GetFirst()->GetData();
1095 region
->SetSize(m_width
, m_height
);
1100 void wxEllipseShape::Copy(wxShape
& copy
)
1102 wxShape::Copy(copy
);
1104 wxASSERT( copy
.IsKindOf(CLASSINFO(wxEllipseShape
)) );
1106 wxEllipseShape
& ellipseCopy
= (wxEllipseShape
&) copy
;
1108 ellipseCopy
.m_width
= m_width
;
1109 ellipseCopy
.m_height
= m_height
;
1112 int wxEllipseShape::GetNumberOfAttachments() const
1114 return wxShape::GetNumberOfAttachments();
1117 // There are 4 attachment points on an ellipse - 0 = top, 1 = right, 2 = bottom,
1119 bool wxEllipseShape::GetAttachmentPosition(int attachment
, double *x
, double *y
,
1120 int nth
, int no_arcs
, wxLineShape
*line
)
1122 if (m_attachmentMode
== ATTACHMENT_MODE_BRANCHING
)
1123 return wxShape::GetAttachmentPosition(attachment
, x
, y
, nth
, no_arcs
, line
);
1125 if (m_attachmentMode
!= ATTACHMENT_MODE_NONE
)
1127 double top
= (double)(m_ypos
+ m_height
/2.0);
1128 double bottom
= (double)(m_ypos
- m_height
/2.0);
1129 double left
= (double)(m_xpos
- m_width
/2.0);
1130 double right
= (double)(m_xpos
+ m_width
/2.0);
1132 int physicalAttachment
= LogicalToPhysicalAttachment(attachment
);
1134 switch (physicalAttachment
)
1138 if (m_spaceAttachments
)
1139 *x
= left
+ (nth
+ 1)*m_width
/(no_arcs
+ 1);
1142 // We now have the point on the bounding box: but get the point on the ellipse
1143 // by imagining a vertical line from (*x, m_ypos - m_height- 500) to (*x, m_ypos) intersecting
1145 oglDrawArcToEllipse(m_xpos
, m_ypos
, m_width
, m_height
, *x
, (double)(m_ypos
-m_height
-500), *x
, m_ypos
, x
, y
);
1151 if (m_spaceAttachments
)
1152 *y
= bottom
+ (nth
+ 1)*m_height
/(no_arcs
+ 1);
1154 oglDrawArcToEllipse(m_xpos
, m_ypos
, m_width
, m_height
, (double)(m_xpos
+m_width
+500), *y
, m_xpos
, *y
, x
, y
);
1159 if (m_spaceAttachments
)
1160 *x
= left
+ (nth
+ 1)*m_width
/(no_arcs
+ 1);
1163 oglDrawArcToEllipse(m_xpos
, m_ypos
, m_width
, m_height
, *x
, (double)(m_ypos
+m_height
+500), *x
, m_ypos
, x
, y
);
1169 if (m_spaceAttachments
)
1170 *y
= bottom
+ (nth
+ 1)*m_height
/(no_arcs
+ 1);
1172 oglDrawArcToEllipse(m_xpos
, m_ypos
, m_width
, m_height
, (double)(m_xpos
-m_width
-500), *y
, m_xpos
, *y
, x
, y
);
1177 return wxShape::GetAttachmentPosition(attachment
, x
, y
, nth
, no_arcs
, line
);
1184 { *x
= m_xpos
; *y
= m_ypos
; return TRUE
; }
1189 IMPLEMENT_DYNAMIC_CLASS(wxCircleShape
, wxEllipseShape
)
1191 wxCircleShape::wxCircleShape(double diameter
):wxEllipseShape(diameter
, diameter
)
1193 SetMaintainAspectRatio(TRUE
);
1196 void wxCircleShape::Copy(wxShape
& copy
)
1198 wxEllipseShape::Copy(copy
);
1201 bool wxCircleShape::GetPerimeterPoint(double x1
, double y1
,
1202 double x2
, double y2
,
1203 double *x3
, double *y3
)
1205 oglFindEndForCircle(m_width
/2,
1206 m_xpos
, m_ypos
, // Centre of circle
1207 x2
, y2
, // Other end of line
1215 double wxControlPoint::sm_controlPointDragStartX
= 0.0;
1216 double wxControlPoint::sm_controlPointDragStartY
= 0.0;
1217 double wxControlPoint::sm_controlPointDragStartWidth
= 0.0;
1218 double wxControlPoint::sm_controlPointDragStartHeight
= 0.0;
1219 double wxControlPoint::sm_controlPointDragEndWidth
= 0.0;
1220 double wxControlPoint::sm_controlPointDragEndHeight
= 0.0;
1221 double wxControlPoint::sm_controlPointDragPosX
= 0.0;
1222 double wxControlPoint::sm_controlPointDragPosY
= 0.0;
1224 IMPLEMENT_DYNAMIC_CLASS(wxControlPoint
, wxRectangleShape
)
1226 wxControlPoint::wxControlPoint(wxShapeCanvas
*theCanvas
, wxShape
*object
, double size
, double the_xoffset
, double the_yoffset
, int the_type
):wxRectangleShape(size
, size
)
1228 m_canvas
= theCanvas
;
1230 m_xoffset
= the_xoffset
;
1231 m_yoffset
= the_yoffset
;
1233 SetPen(g_oglBlackForegroundPen
);
1234 SetBrush(wxBLACK_BRUSH
);
1237 m_eraseObject
= TRUE
;
1240 wxControlPoint::~wxControlPoint()
1244 // Don't even attempt to draw any text - waste of time!
1245 void wxControlPoint::OnDrawContents(wxDC
& dc
)
1249 void wxControlPoint::OnDraw(wxDC
& dc
)
1251 m_xpos
= m_shape
->GetX() + m_xoffset
;
1252 m_ypos
= m_shape
->GetY() + m_yoffset
;
1253 wxRectangleShape::OnDraw(dc
);
1256 void wxControlPoint::OnErase(wxDC
& dc
)
1258 wxRectangleShape::OnErase(dc
);
1261 // Implement resizing of canvas object
1262 void wxControlPoint::OnDragLeft(bool draw
, double x
, double y
, int keys
, int attachment
)
1264 m_shape
->GetEventHandler()->OnSizingDragLeft(this, draw
, x
, y
, keys
, attachment
);
1267 void wxControlPoint::OnBeginDragLeft(double x
, double y
, int keys
, int attachment
)
1269 m_shape
->GetEventHandler()->OnSizingBeginDragLeft(this, x
, y
, keys
, attachment
);
1272 void wxControlPoint::OnEndDragLeft(double x
, double y
, int keys
, int attachment
)
1274 m_shape
->GetEventHandler()->OnSizingEndDragLeft(this, x
, y
, keys
, attachment
);
1277 int wxControlPoint::GetNumberOfAttachments() const
1282 bool wxControlPoint::GetAttachmentPosition(int attachment
, double *x
, double *y
,
1283 int nth
, int no_arcs
, wxLineShape
*line
)
1285 *x
= m_xpos
; *y
= m_ypos
;
1289 // Control points ('handles') redirect control to the actual shape, to make it easier
1290 // to override sizing behaviour.
1291 void wxShape::OnSizingDragLeft(wxControlPoint
* pt
, bool draw
, double x
, double y
, int keys
, int attachment
)
1295 this->GetBoundingBoxMin(&bound_x
, &bound_y
);
1297 wxClientDC
dc(GetCanvas());
1298 GetCanvas()->PrepareDC(dc
);
1300 dc
.SetLogicalFunction(OGLRBLF
);
1302 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
1303 dc
.SetPen(dottedPen
);
1304 dc
.SetBrush((* wxTRANSPARENT_BRUSH
));
1306 if (this->GetCentreResize())
1308 // Maintain the same centre point.
1309 double new_width
= (double)(2.0*fabs(x
- this->GetX()));
1310 double new_height
= (double)(2.0*fabs(y
- this->GetY()));
1312 // Constrain sizing according to what control point you're dragging
1313 if (pt
->m_type
== CONTROL_POINT_HORIZONTAL
)
1315 if (GetMaintainAspectRatio())
1317 new_height
= bound_y
*(new_width
/bound_x
);
1320 new_height
= bound_y
;
1322 else if (pt
->m_type
== CONTROL_POINT_VERTICAL
)
1324 if (GetMaintainAspectRatio())
1326 new_width
= bound_x
*(new_height
/bound_y
);
1329 new_width
= bound_x
;
1331 else if (pt
->m_type
== CONTROL_POINT_DIAGONAL
&& (keys
& KEY_SHIFT
))
1332 new_height
= bound_y
*(new_width
/bound_x
);
1334 if (this->GetFixedWidth())
1335 new_width
= bound_x
;
1337 if (this->GetFixedHeight())
1338 new_height
= bound_y
;
1340 pt
->sm_controlPointDragEndWidth
= new_width
;
1341 pt
->sm_controlPointDragEndHeight
= new_height
;
1343 this->GetEventHandler()->OnDrawOutline(dc
, this->GetX(), this->GetY(),
1344 new_width
, new_height
);
1348 // Don't maintain the same centre point!
1349 double newX1
= wxMin(pt
->sm_controlPointDragStartX
, x
);
1350 double newY1
= wxMin(pt
->sm_controlPointDragStartY
, y
);
1351 double newX2
= wxMax(pt
->sm_controlPointDragStartX
, x
);
1352 double newY2
= wxMax(pt
->sm_controlPointDragStartY
, y
);
1353 if (pt
->m_type
== CONTROL_POINT_HORIZONTAL
)
1355 newY1
= pt
->sm_controlPointDragStartY
;
1356 newY2
= newY1
+ pt
->sm_controlPointDragStartHeight
;
1358 else if (pt
->m_type
== CONTROL_POINT_VERTICAL
)
1360 newX1
= pt
->sm_controlPointDragStartX
;
1361 newX2
= newX1
+ pt
->sm_controlPointDragStartWidth
;
1363 else if (pt
->m_type
== CONTROL_POINT_DIAGONAL
&& ((keys
& KEY_SHIFT
) || GetMaintainAspectRatio()))
1365 double newH
= (double)((newX2
- newX1
)*(pt
->sm_controlPointDragStartHeight
/pt
->sm_controlPointDragStartWidth
));
1366 if (GetY() > pt
->sm_controlPointDragStartY
)
1367 newY2
= (double)(newY1
+ newH
);
1369 newY1
= (double)(newY2
- newH
);
1371 double newWidth
= (double)(newX2
- newX1
);
1372 double newHeight
= (double)(newY2
- newY1
);
1374 if (pt
->m_type
== CONTROL_POINT_VERTICAL
&& GetMaintainAspectRatio())
1376 newWidth
= bound_x
* (newHeight
/bound_y
) ;
1379 if (pt
->m_type
== CONTROL_POINT_HORIZONTAL
&& GetMaintainAspectRatio())
1381 newHeight
= bound_y
* (newWidth
/bound_x
) ;
1384 pt
->sm_controlPointDragPosX
= (double)(newX1
+ (newWidth
/2.0));
1385 pt
->sm_controlPointDragPosY
= (double)(newY1
+ (newHeight
/2.0));
1386 if (this->GetFixedWidth())
1389 if (this->GetFixedHeight())
1390 newHeight
= bound_y
;
1392 pt
->sm_controlPointDragEndWidth
= newWidth
;
1393 pt
->sm_controlPointDragEndHeight
= newHeight
;
1394 this->GetEventHandler()->OnDrawOutline(dc
, pt
->sm_controlPointDragPosX
, pt
->sm_controlPointDragPosY
, newWidth
, newHeight
);
1398 void wxShape::OnSizingBeginDragLeft(wxControlPoint
* pt
, double x
, double y
, int keys
, int attachment
)
1400 m_canvas
->CaptureMouse();
1402 wxClientDC
dc(GetCanvas());
1403 GetCanvas()->PrepareDC(dc
);
1405 if (pt->m_eraseObject)
1409 dc
.SetLogicalFunction(OGLRBLF
);
1413 this->GetBoundingBoxMin(&bound_x
, &bound_y
);
1415 // Choose the 'opposite corner' of the object as the stationary
1416 // point in case this is non-centring resizing.
1417 if (pt
->GetX() < this->GetX())
1418 pt
->sm_controlPointDragStartX
= (double)(this->GetX() + (bound_x
/2.0));
1420 pt
->sm_controlPointDragStartX
= (double)(this->GetX() - (bound_x
/2.0));
1422 if (pt
->GetY() < this->GetY())
1423 pt
->sm_controlPointDragStartY
= (double)(this->GetY() + (bound_y
/2.0));
1425 pt
->sm_controlPointDragStartY
= (double)(this->GetY() - (bound_y
/2.0));
1427 if (pt
->m_type
== CONTROL_POINT_HORIZONTAL
)
1428 pt
->sm_controlPointDragStartY
= (double)(this->GetY() - (bound_y
/2.0));
1429 else if (pt
->m_type
== CONTROL_POINT_VERTICAL
)
1430 pt
->sm_controlPointDragStartX
= (double)(this->GetX() - (bound_x
/2.0));
1432 // We may require the old width and height.
1433 pt
->sm_controlPointDragStartWidth
= bound_x
;
1434 pt
->sm_controlPointDragStartHeight
= bound_y
;
1436 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
1437 dc
.SetPen(dottedPen
);
1438 dc
.SetBrush((* wxTRANSPARENT_BRUSH
));
1440 if (this->GetCentreResize())
1442 double new_width
= (double)(2.0*fabs(x
- this->GetX()));
1443 double new_height
= (double)(2.0*fabs(y
- this->GetY()));
1445 // Constrain sizing according to what control point you're dragging
1446 if (pt
->m_type
== CONTROL_POINT_HORIZONTAL
)
1448 if (GetMaintainAspectRatio())
1450 new_height
= bound_y
*(new_width
/bound_x
);
1453 new_height
= bound_y
;
1455 else if (pt
->m_type
== CONTROL_POINT_VERTICAL
)
1457 if (GetMaintainAspectRatio())
1459 new_width
= bound_x
*(new_height
/bound_y
);
1462 new_width
= bound_x
;
1464 else if (pt
->m_type
== CONTROL_POINT_DIAGONAL
&& (keys
& KEY_SHIFT
))
1465 new_height
= bound_y
*(new_width
/bound_x
);
1467 if (this->GetFixedWidth())
1468 new_width
= bound_x
;
1470 if (this->GetFixedHeight())
1471 new_height
= bound_y
;
1473 pt
->sm_controlPointDragEndWidth
= new_width
;
1474 pt
->sm_controlPointDragEndHeight
= new_height
;
1475 this->GetEventHandler()->OnDrawOutline(dc
, this->GetX(), this->GetY(),
1476 new_width
, new_height
);
1480 // Don't maintain the same centre point!
1481 double newX1
= wxMin(pt
->sm_controlPointDragStartX
, x
);
1482 double newY1
= wxMin(pt
->sm_controlPointDragStartY
, y
);
1483 double newX2
= wxMax(pt
->sm_controlPointDragStartX
, x
);
1484 double newY2
= wxMax(pt
->sm_controlPointDragStartY
, y
);
1485 if (pt
->m_type
== CONTROL_POINT_HORIZONTAL
)
1487 newY1
= pt
->sm_controlPointDragStartY
;
1488 newY2
= newY1
+ pt
->sm_controlPointDragStartHeight
;
1490 else if (pt
->m_type
== CONTROL_POINT_VERTICAL
)
1492 newX1
= pt
->sm_controlPointDragStartX
;
1493 newX2
= newX1
+ pt
->sm_controlPointDragStartWidth
;
1495 else if (pt
->m_type
== CONTROL_POINT_DIAGONAL
&& ((keys
& KEY_SHIFT
) || GetMaintainAspectRatio()))
1497 double newH
= (double)((newX2
- newX1
)*(pt
->sm_controlPointDragStartHeight
/pt
->sm_controlPointDragStartWidth
));
1498 if (pt
->GetY() > pt
->sm_controlPointDragStartY
)
1499 newY2
= (double)(newY1
+ newH
);
1501 newY1
= (double)(newY2
- newH
);
1503 double newWidth
= (double)(newX2
- newX1
);
1504 double newHeight
= (double)(newY2
- newY1
);
1506 if (pt
->m_type
== CONTROL_POINT_VERTICAL
&& GetMaintainAspectRatio())
1508 newWidth
= bound_x
* (newHeight
/bound_y
) ;
1511 if (pt
->m_type
== CONTROL_POINT_HORIZONTAL
&& GetMaintainAspectRatio())
1513 newHeight
= bound_y
* (newWidth
/bound_x
) ;
1516 pt
->sm_controlPointDragPosX
= (double)(newX1
+ (newWidth
/2.0));
1517 pt
->sm_controlPointDragPosY
= (double)(newY1
+ (newHeight
/2.0));
1518 if (this->GetFixedWidth())
1521 if (this->GetFixedHeight())
1522 newHeight
= bound_y
;
1524 pt
->sm_controlPointDragEndWidth
= newWidth
;
1525 pt
->sm_controlPointDragEndHeight
= newHeight
;
1526 this->GetEventHandler()->OnDrawOutline(dc
, pt
->sm_controlPointDragPosX
, pt
->sm_controlPointDragPosY
, newWidth
, newHeight
);
1530 void wxShape::OnSizingEndDragLeft(wxControlPoint
* pt
, double x
, double y
, int keys
, int attachment
)
1532 wxClientDC
dc(GetCanvas());
1533 GetCanvas()->PrepareDC(dc
);
1535 m_canvas
->ReleaseMouse();
1536 dc
.SetLogicalFunction(wxCOPY
);
1538 this->ResetControlPoints();
1542 if (!pt->m_eraseObject)
1546 this->SetSize(pt
->sm_controlPointDragEndWidth
, pt
->sm_controlPointDragEndHeight
);
1548 // The next operation could destroy this control point (it does for label objects,
1549 // via formatting the text), so save all values we're going to use, or
1550 // we'll be accessing garbage.
1551 wxShape
*theObject
= this;
1552 wxShapeCanvas
*theCanvas
= m_canvas
;
1553 bool eraseIt
= pt
->m_eraseObject
;
1555 if (theObject
->GetCentreResize())
1556 theObject
->Move(dc
, theObject
->GetX(), theObject
->GetY());
1558 theObject
->Move(dc
, pt
->sm_controlPointDragPosX
, pt
->sm_controlPointDragPosY
);
1562 theObject->Show(TRUE);
1565 // Recursively redraw links if we have a composite.
1566 if (theObject
->GetChildren().GetCount() > 0)
1567 theObject
->DrawLinks(dc
, -1, TRUE
);
1569 double width
, height
;
1570 theObject
->GetBoundingBoxMax(&width
, &height
);
1571 theObject
->GetEventHandler()->OnEndSize(width
, height
);
1573 if (!theCanvas
->GetQuickEditMode() && eraseIt
) theCanvas
->Redraw(dc
);
1578 // Polygon control points
1580 IMPLEMENT_DYNAMIC_CLASS(wxPolygonControlPoint
, wxControlPoint
)
1582 wxPolygonControlPoint::wxPolygonControlPoint(wxShapeCanvas
*theCanvas
, wxShape
*object
, double size
,
1583 wxRealPoint
*vertex
, double the_xoffset
, double the_yoffset
):
1584 wxControlPoint(theCanvas
, object
, size
, the_xoffset
, the_yoffset
, 0)
1586 m_polygonVertex
= vertex
;
1587 m_originalDistance
= 0.0;
1590 wxPolygonControlPoint::~wxPolygonControlPoint()
1594 // Calculate what new size would be, at end of resize
1595 void wxPolygonControlPoint::CalculateNewSize(double x
, double y
)
1599 GetShape()->GetBoundingBoxMin(&bound_x
, &bound_y
);
1601 double dist
= (double)sqrt((x
- m_shape
->GetX())*(x
- m_shape
->GetX()) +
1602 (y
- m_shape
->GetY())*(y
- m_shape
->GetY()));
1604 m_newSize
.x
= (double)(dist
/this->m_originalDistance
)*this->m_originalSize
.x
;
1605 m_newSize
.y
= (double)(dist
/this->m_originalDistance
)*this->m_originalSize
.y
;
1609 // Implement resizing polygon or moving the vertex.
1610 void wxPolygonControlPoint::OnDragLeft(bool draw
, double x
, double y
, int keys
, int attachment
)
1612 m_shape
->GetEventHandler()->OnSizingDragLeft(this, draw
, x
, y
, keys
, attachment
);
1615 void wxPolygonControlPoint::OnBeginDragLeft(double x
, double y
, int keys
, int attachment
)
1617 m_shape
->GetEventHandler()->OnSizingBeginDragLeft(this, x
, y
, keys
, attachment
);
1620 void wxPolygonControlPoint::OnEndDragLeft(double x
, double y
, int keys
, int attachment
)
1622 m_shape
->GetEventHandler()->OnSizingEndDragLeft(this, x
, y
, keys
, attachment
);
1625 // Control points ('handles') redirect control to the actual shape, to make it easier
1626 // to override sizing behaviour.
1627 void wxPolygonShape::OnSizingDragLeft(wxControlPoint
* pt
, bool draw
, double x
, double y
, int keys
, int attachment
)
1629 wxPolygonControlPoint
* ppt
= (wxPolygonControlPoint
*) pt
;
1631 wxClientDC
dc(GetCanvas());
1632 GetCanvas()->PrepareDC(dc
);
1634 dc
.SetLogicalFunction(OGLRBLF
);
1636 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
1637 dc
.SetPen(dottedPen
);
1638 dc
.SetBrush((* wxTRANSPARENT_BRUSH
));
1640 if (0) // keys & KEY_CTRL)
1642 // TODO: mend this code. Currently we rely on altering the
1643 // actual points, but we should assume we're not, as per
1644 // the normal sizing case.
1645 m_canvas
->Snap(&x
, &y
);
1648 ppt
->m_polygonVertex
->x
= x
- this->GetX();
1649 ppt
->m_polygonVertex
->y
= y
- this->GetY();
1652 ((wxPolygonShape
*)this)->CalculateBoundingBox();
1653 ((wxPolygonShape
*)this)->CalculatePolygonCentre();
1657 ppt
->CalculateNewSize(x
, y
);
1660 this->GetEventHandler()->OnDrawOutline(dc
, this->GetX(), this->GetY(),
1661 ppt
->GetNewSize().x
, ppt
->GetNewSize().y
);
1664 void wxPolygonShape::OnSizingBeginDragLeft(wxControlPoint
* pt
, double x
, double y
, int keys
, int attachment
)
1666 wxPolygonControlPoint
* ppt
= (wxPolygonControlPoint
*) pt
;
1668 wxClientDC
dc(GetCanvas());
1669 GetCanvas()->PrepareDC(dc
);
1673 dc
.SetLogicalFunction(OGLRBLF
);
1677 this->GetBoundingBoxMin(&bound_x
, &bound_y
);
1679 double dist
= (double)sqrt((x
- this->GetX())*(x
- this->GetX()) +
1680 (y
- this->GetY())*(y
- this->GetY()));
1681 ppt
->m_originalDistance
= dist
;
1682 ppt
->m_originalSize
.x
= bound_x
;
1683 ppt
->m_originalSize
.y
= bound_y
;
1685 if (ppt
->m_originalDistance
== 0.0) ppt
->m_originalDistance
= (double) 0.0001;
1687 wxPen
dottedPen(wxColour(0, 0, 0), 1, wxDOT
);
1688 dc
.SetPen(dottedPen
);
1689 dc
.SetBrush((* wxTRANSPARENT_BRUSH
));
1691 if (0) // keys & KEY_CTRL)
1693 // TODO: mend this code. Currently we rely on altering the
1694 // actual points, but we should assume we're not, as per
1695 // the normal sizing case.
1696 m_canvas
->Snap(&x
, &y
);
1699 ppt
->m_polygonVertex
->x
= x
- this->GetX();
1700 ppt
->m_polygonVertex
->y
= y
- this->GetY();
1703 ((wxPolygonShape
*)this)->CalculateBoundingBox();
1704 ((wxPolygonShape
*)this)->CalculatePolygonCentre();
1708 ppt
->CalculateNewSize(x
, y
);
1711 this->GetEventHandler()->OnDrawOutline(dc
, this->GetX(), this->GetY(),
1712 ppt
->GetNewSize().x
, ppt
->GetNewSize().y
);
1714 m_canvas
->CaptureMouse();
1717 void wxPolygonShape::OnSizingEndDragLeft(wxControlPoint
* pt
, double x
, double y
, int keys
, int attachment
)
1719 wxPolygonControlPoint
* ppt
= (wxPolygonControlPoint
*) pt
;
1721 wxClientDC
dc(GetCanvas());
1722 GetCanvas()->PrepareDC(dc
);
1724 m_canvas
->ReleaseMouse();
1725 dc
.SetLogicalFunction(wxCOPY
);
1727 // If we're changing shape, must reset the original points
1728 if (keys
& KEY_CTRL
)
1730 ((wxPolygonShape
*)this)->CalculateBoundingBox();
1731 ((wxPolygonShape
*)this)->UpdateOriginalPoints();
1735 SetSize(ppt
->GetNewSize().x
, ppt
->GetNewSize().y
);
1738 ((wxPolygonShape
*)this)->CalculateBoundingBox();
1739 ((wxPolygonShape
*)this)->CalculatePolygonCentre();
1742 this->ResetControlPoints();
1743 this->Move(dc
, this->GetX(), this->GetY());
1744 if (!m_canvas
->GetQuickEditMode()) m_canvas
->Redraw(dc
);
1751 IMPLEMENT_DYNAMIC_CLASS(wxShapeRegion
, wxObject
)
1753 wxShapeRegion::wxShapeRegion()
1755 m_regionText
= wxEmptyString
;
1756 m_font
= g_oglNormalFont
;
1764 m_regionProportionX
= -1.0;
1765 m_regionProportionY
= -1.0;
1766 m_formatMode
= FORMAT_CENTRE_HORIZ
| FORMAT_CENTRE_VERT
;
1767 m_regionName
= wxEmptyString
;
1768 m_textColour
= wxT("BLACK");
1769 m_penColour
= wxT("BLACK");
1770 m_penStyle
= wxSOLID
;
1771 m_actualColourObject
= NULL
;
1772 m_actualPenObject
= NULL
;
1775 wxShapeRegion::wxShapeRegion(wxShapeRegion
& region
)
1777 m_regionText
= region
.m_regionText
;
1778 m_regionName
= region
.m_regionName
;
1779 m_textColour
= region
.m_textColour
;
1781 m_font
= region
.m_font
;
1782 m_minHeight
= region
.m_minHeight
;
1783 m_minWidth
= region
.m_minWidth
;
1784 m_width
= region
.m_width
;
1785 m_height
= region
.m_height
;
1789 m_regionProportionX
= region
.m_regionProportionX
;
1790 m_regionProportionY
= region
.m_regionProportionY
;
1791 m_formatMode
= region
.m_formatMode
;
1792 m_actualColourObject
= NULL
;
1793 m_actualPenObject
= NULL
;
1794 m_penStyle
= region
.m_penStyle
;
1795 m_penColour
= region
.m_penColour
;
1798 wxNode
*node
= region
.m_formattedText
.GetFirst();
1801 wxShapeTextLine
*line
= (wxShapeTextLine
*)node
->GetData();
1802 wxShapeTextLine
*new_line
=
1803 new wxShapeTextLine(line
->GetX(), line
->GetY(), line
->GetText());
1804 m_formattedText
.Append(new_line
);
1805 node
= node
->GetNext();
1809 wxShapeRegion::~wxShapeRegion()
1814 void wxShapeRegion::ClearText()
1816 wxNode
*node
= m_formattedText
.GetFirst();
1819 wxShapeTextLine
*line
= (wxShapeTextLine
*)node
->GetData();
1820 wxNode
*next
= node
->GetNext();
1827 void wxShapeRegion::SetFont(wxFont
*f
)
1832 void wxShapeRegion::SetMinSize(double w
, double h
)
1838 void wxShapeRegion::SetSize(double w
, double h
)
1844 void wxShapeRegion::SetPosition(double xp
, double yp
)
1850 void wxShapeRegion::SetProportions(double xp
, double yp
)
1852 m_regionProportionX
= xp
;
1853 m_regionProportionY
= yp
;
1856 void wxShapeRegion::SetFormatMode(int mode
)
1858 m_formatMode
= mode
;
1861 void wxShapeRegion::SetColour(const wxString
& col
)
1864 m_actualColourObject
= NULL
;
1867 wxColour
*wxShapeRegion::GetActualColourObject()
1869 if (!m_actualColourObject
)
1870 m_actualColourObject
= wxTheColourDatabase
->FindColour(GetColour());
1871 if (!m_actualColourObject
)
1872 m_actualColourObject
= wxBLACK
;
1873 return m_actualColourObject
;
1876 void wxShapeRegion::SetPenColour(const wxString
& col
)
1879 m_actualPenObject
= NULL
;
1882 // Returns NULL if the pen is invisible
1883 // (different to pen being transparent; indicates that
1884 // region boundary should not be drawn.)
1885 wxPen
*wxShapeRegion::GetActualPen()
1887 if (m_actualPenObject
)
1888 return m_actualPenObject
;
1890 if (!m_penColour
) return NULL
;
1891 if (m_penColour
== wxT("Invisible"))
1893 m_actualPenObject
= wxThePenList
->FindOrCreatePen(m_penColour
, 1, m_penStyle
);
1894 return m_actualPenObject
;