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
20 Circle::Circle(Vector p1, double r, Object * p/*= NULL*/): Object(p1, p), radius(r),
21 dragging(false), draggingHandle1(false), draggingHandle2(false)//, needUpdate(false)
29 /*virtual*/ void Circle::Draw(Painter * painter)
31 if (state == OSSelected)
32 painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine));
34 painter->SetPen(QPen(Qt::black, 1.0, Qt::SolidLine));
36 // if (draggingHandle1)
37 if (state == OSSelected)
38 painter->DrawEllipse(position, 4.0, 4.0);
40 // if (draggingHandle2)
41 // if (state == OSSelected)
42 // painter->drawEllipse(QPointF(endpoint.x, endpoint.y), 4.0, 4.0);
43 if (state == OSSelected && dragging)
44 painter->DrawEllipse(oldPoint, 4.0, 4.0);
46 painter->DrawEllipse(position, radius, radius);
49 /*virtual*/ Vector Circle::Center(void)
54 /*virtual*/ bool Circle::Collided(Vector point)
56 objectWasDragged = false;
57 Vector v1 = position - point;
59 if (state == OSInactive)
61 //printf("Circle: pp = %lf, length = %lf, distance = %lf\n", parameterizedPoint, lineSegment.Magnitude(), distance);
62 //printf(" v1.Magnitude = %lf, v2.Magnitude = %lf\n", v1.Magnitude(), v2.Magnitude());
63 //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);
65 //How to translate this into pixels from Document space???
66 //Maybe we need to pass a scaling factor in here from the caller? That would make sense, as
67 //the caller knows about the zoom factor and all that good kinda crap
68 if (v1.Magnitude() < 10.0)
72 oldPoint = position; //maybe "position"?
73 draggingHandle1 = true;
76 else if ((v1.Magnitude() < radius + 2.0) && (v1.Magnitude() > radius - 2.0))
85 else if (state == OSSelected)
87 // Here we test for collision with handles as well! (SOON!)
90 if (v1.Magnitude() < 2.0) // Handle #1
91 else if (v2.Magnitude() < 2.0) // Handle #2
93 if ((v1.Magnitude() < radius + 2.0) && (v1.Magnitude() > radius - 2.0))
96 // state = OSInactive;
107 /*virtual*/ void Circle::PointerMoved(Vector point)
109 objectWasDragged = true;
113 // Here we need to check whether or not we're dragging a handle or the object itself...
114 // Vector delta = point - oldPoint;
116 // position += delta;
117 // endpoint += delta;
118 radius = Vector(point - position).Magnitude();
123 else if (draggingHandle1)
125 Vector delta = point - oldPoint;
130 /* else if (draggingHandle2)
132 Vector delta = point - oldPoint;
143 /*virtual*/ void Circle::PointerReleased(void)
146 draggingHandle1 = false;
147 draggingHandle2 = false;
149 // Here we check for just a click: If object was clicked and dragged, then
150 // revert to the old state (OSInactive). Otherwise, keep the new state that
152 /*Maybe it would be better to just check for "object was dragged" state and not have to worry
153 about keeping track of old states...
155 if (objectWasDragged)
160 /*virtual*/ bool Circle::NeedsUpdate(void)