1 // circle.cpp: Circle object
3 // Part of the Architektonas Project
4 // (C) 2011 Underground Software
5 // See the README and GPLv3 files for licensing and warranty information
7 // JLH = James L. Hammons <jlhamm@acm.org>
10 // --- ---------- ------------------------------------------------------------
11 // JLH 03/28/2011 Created this file
18 Circle::Circle(Vector p1, double r, Object * p/*= NULL*/): Object(p1, p), radius(r),
19 dragging(false), draggingHandle1(false), draggingHandle2(false)//, needUpdate(false)
27 /*virtual*/ void Circle::Draw(QPainter * painter)
29 if (state == OSSelected)
30 painter->setPen(QPen(Qt::red, 2.0, Qt::DotLine));
32 painter->setPen(QPen(Qt::black, 1.0, Qt::SolidLine));
34 // if (draggingHandle1)
35 if (state == OSSelected)
36 painter->drawEllipse(QPointF(position.x, position.y), 4.0, 4.0);
38 // if (draggingHandle2)
39 // if (state == OSSelected)
40 // painter->drawEllipse(QPointF(endpoint.x, endpoint.y), 4.0, 4.0);
41 if (state == OSSelected && dragging)
42 painter->drawEllipse(QPointF(oldPoint.x, oldPoint.y), 4.0, 4.0);
44 painter->drawEllipse(QPointF(position.x, position.y), radius, radius);
47 /*virtual*/ Vector Circle::Center(void)
52 /*virtual*/ bool Circle::Collided(Vector point)
54 objectWasDragged = false;
55 Vector v1 = position - point;
57 if (state == OSInactive)
59 //printf("Circle: pp = %lf, length = %lf, distance = %lf\n", parameterizedPoint, lineSegment.Magnitude(), distance);
60 //printf(" v1.Magnitude = %lf, v2.Magnitude = %lf\n", v1.Magnitude(), v2.Magnitude());
61 //printf(" point = %lf,%lf,%lf; p1 = %lf,%lf,%lf; p2 = %lf,%lf,%lf\n", point.x, point.y, point.z, position.x, position.y, position.z, endpoint.x, endpoint.y, endpoint.z);
63 //How to translate this into pixels from Document space???
64 //Maybe we need to pass a scaling factor in here from the caller? That would make sense, as
65 //the caller knows about the zoom factor and all that good kinda crap
66 if (v1.Magnitude() < 10.0)
70 oldPoint = position; //maybe "position"?
71 draggingHandle1 = true;
74 else if ((v1.Magnitude() < radius + 2.0) && (v1.Magnitude() > radius - 2.0))
83 else if (state == OSSelected)
85 // Here we test for collision with handles as well! (SOON!)
88 if (v1.Magnitude() < 2.0) // Handle #1
89 else if (v2.Magnitude() < 2.0) // Handle #2
91 if ((v1.Magnitude() < radius + 2.0) && (v1.Magnitude() > radius - 2.0))
94 // state = OSInactive;
105 /*virtual*/ void Circle::PointerMoved(Vector point)
107 objectWasDragged = true;
111 // Here we need to check whether or not we're dragging a handle or the object itself...
112 // Vector delta = point - oldPoint;
114 // position += delta;
115 // endpoint += delta;
116 radius = Vector(point - position).Magnitude();
121 else if (draggingHandle1)
123 Vector delta = point - oldPoint;
128 /* else if (draggingHandle2)
130 Vector delta = point - oldPoint;
141 /*virtual*/ void Circle::PointerReleased(void)
144 draggingHandle1 = false;
145 draggingHandle2 = false;
147 // Here we check for just a click: If object was clicked and dragged, then
148 // revert to the old state (OSInactive). Otherwise, keep the new state that
150 /*Maybe it would be better to just check for "object was dragged" state and not have to worry
151 about keeping track of old states...
153 if (objectWasDragged)
158 /*virtual*/ bool Circle::NeedsUpdate(void)