1 // container.cpp: Container 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/30/2011 Created this file
14 #include "container.h"
19 Container::Container(Vector p1, Object * p/*= NULL*/): Object(p1, p),
20 dragging(false), draggingHandle1(false), draggingHandle2(false)//, needUpdate(false)
24 Container::~Container()
28 /*virtual*/ void Container::Draw(QPainter * painter)
30 for(int i=0; i<(int)objects.size(); i++)
31 objects[i]->Draw(painter);
34 /*virtual*/ Vector Container::Center(void)
40 We need at least *three* handles for this object:
45 We need to think about the intuitive way (if there is any) to grab and
46 manipulate a complex object like this... Need to think, "What should happen when
47 I click here and drag there?"
49 Also: should put the snap logic into the Object base class (as a static method)...
52 /*virtual*/ bool Container::Collided(Vector point)
54 objectWasDragged = false;
55 Vector v1 = position - point;
58 if (state == OSInactive)
60 //printf("Circle: pp = %lf, length = %lf, distance = %lf\n", parameterizedPoint, lineSegment.Magnitude(), distance);
61 //printf(" v1.Magnitude = %lf, v2.Magnitude = %lf\n", v1.Magnitude(), v2.Magnitude());
62 //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);
64 //How to translate this into pixels from Document space???
65 //Maybe we need to pass a scaling factor in here from the caller? That would make sense, as
66 //the caller knows about the zoom factor and all that good kinda crap
67 if (v1.Magnitude() < 10.0)
71 oldPoint = position; //maybe "position"?
72 draggingHandle1 = true;
75 else if ((v1.Magnitude() < radius + 2.0) && (v1.Magnitude() > radius - 2.0))
84 else if (state == OSSelected)
86 // Here we test for collision with handles as well! (SOON!)
89 if (v1.Magnitude() < 2.0) // Handle #1
90 else if (v2.Magnitude() < 2.0) // Handle #2
92 if ((v1.Magnitude() < radius + 2.0) && (v1.Magnitude() > radius - 2.0))
95 // state = OSInactive;
102 bool collision = false;
104 for(int i=0; i<(int)objects.size(); i++)
106 if (objects[i]->Collided(point))
111 // Do we decouple the state of the generic container from the objects inside???
117 /*virtual*/ void Container::PointerMoved(Vector point)
119 objectWasDragged = true;
123 // Here we need to check whether or not we're dragging a handle or the object itself...
124 // Vector delta = point - oldPoint;
126 // position += delta;
127 // endpoint += delta;
128 radius = Vector(point - position).Magnitude();
133 else if (draggingHandle1)
135 Vector delta = point - oldPoint;
140 /* else if (draggingHandle2)
142 Vector delta = point - oldPoint;
152 for(int i=0; i<(int)objects.size(); i++)
154 if (objects[i]->GetState() == OSSelected)
155 objects[i]->PointerMoved(point);
158 // Generic container doesn't need this???
159 // needUpdate = false;
162 /*virtual*/ void Container::PointerReleased(void)
165 draggingHandle1 = false;
166 draggingHandle2 = false;
168 // Here we check for just a click: If object was clicked and dragged, then
169 // revert to the old state (OSInactive). Otherwise, keep the new state that
171 /*Maybe it would be better to just check for "object was dragged" state and not have to worry
172 about keeping track of old states...
174 if (objectWasDragged)
176 //Note that the preceeding is unnecessary for a generic container!
178 for(int i=0; i<(int)objects.size(); i++)
179 objects[i]->PointerReleased();
182 /*virtual*/ bool Container::NeedsUpdate(void)
186 for(int i=0; i<(int)objects.size(); i++)
188 if (objects[i]->NeedsUpdate())
195 void Container::Add(Object * object)
197 objects.push_back(object);