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 // NOTE that this deletes the object on mouse down instead of mouse up. Have to
105 // check to see how it feels to do it that way...
108 for(int i=0; i<(int)objects.size(); i++)
110 if (objects[i]->Collided(point))
112 objects.erase(objects.begin() + i); // Calls the destructor, (deletes the object, I presume... O_o)
119 for(int i=0; i<(int)objects.size(); i++)
121 if (objects[i]->Collided(point))
127 // Do we decouple the state of the generic container from the objects inside??? Mebbe.
133 // The TLC is passing all mouse movement here, so we're doing the same here.
134 // Need to adjust all other objects to handle things correctly.
135 // One optimization that will need to be done eventually is to subdivide the screen
136 // into parts and keep subdividing until an acceptable number of objects lie within
137 // the slice. This way, the GUI will still be responsive and *not* have to test
138 // every object for collision.
139 /*virtual*/ void Container::PointerMoved(Vector point)
141 // objectWasDragged = true;
142 //printf("CONTAINER: PointerMoved()\n");
144 for(int i=0; i<(int)objects.size(); i++)
146 // if (objects[i]->GetState() == OSSelected)
147 objects[i]->PointerMoved(point);
150 // Generic container doesn't need this???
151 // needUpdate = false;
154 /*virtual*/ void Container::PointerReleased(void)
157 draggingHandle1 = false;
158 draggingHandle2 = false;
160 // Here we check for just a click: If object was clicked and dragged, then
161 // revert to the old state (OSInactive). Otherwise, keep the new state that
163 /*Maybe it would be better to just check for "object was dragged" state and not have to worry
164 about keeping track of old states...
166 if (objectWasDragged)
168 //Note that the preceeding is unnecessary for a generic container!
170 for(int i=0; i<(int)objects.size(); i++)
171 objects[i]->PointerReleased();
174 /*virtual*/ bool Container::NeedsUpdate(void)
178 for(int i=0; i<(int)objects.size(); i++)
180 if (objects[i]->NeedsUpdate())
187 /*virtual*/ void Container::Add(Object * object)
189 objects.push_back(object);