X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fcontainer.cpp;h=2ee9c7afa2291d9591302d14d051c1ffd82217d1;hb=baf67656b97e3d61e9223e66ebe4f554e364cd4a;hp=a5653347ab325f97aa254897c4b25383af89e116;hpb=d41ddd699001f6bbf6ac621f5c467bd13efb6087;p=architektonas diff --git a/src/container.cpp b/src/container.cpp index a565334..2ee9c7a 100644 --- a/src/container.cpp +++ b/src/container.cpp @@ -4,7 +4,7 @@ // (C) 2011 Underground Software // See the README and GPLv3 files for licensing and warranty information // -// JLH = James L. Hammons +// JLH = James Hammons // // WHO WHEN WHAT // --- ---------- ------------------------------------------------------------ @@ -16,6 +16,7 @@ #include "container.h" #include +#include "dimension.h" Container::Container(Vector p1, Object * p/*= NULL*/): Object(p1, p), @@ -23,22 +24,53 @@ Container::Container(Vector p1, Object * p/*= NULL*/): Object(p1, p), { } + +// Copy constructor +Container::Container(const Container & copy): Object(copy.position, copy.parent) +{ + // Use overloaded assignment operator + *this = copy; +} + + Container::~Container() { +#if 0 // No memory leaks! while (objects.size() > 0) { delete objects[0]; objects.erase(objects.begin()); } +#else + Clear(); +#endif } -/*virtual*/ void Container::Draw(QPainter * painter) + +// Assignment operator +Container & Container::operator=(const Container & copy) +{ + // Take care of self-assignment + if (this == ©) + return *this; + + Clear(); + + for(int i=0; i<(int)copy.objects.size(); i++) + objects.push_back(copy.objects[i]); + + return *this; +} + + +/*virtual*/ void Container::Draw(Painter * painter) { for(int i=0; i<(int)objects.size(); i++) objects[i]->Draw(painter); } + /*virtual*/ Vector Container::Center(void) { return position; @@ -57,6 +89,7 @@ I click here and drag there?" Also: should put the snap logic into the Object base class (as a static method)... */ + /*virtual*/ bool Container::Collided(Vector point) { objectWasDragged = false; @@ -117,8 +150,34 @@ Like so: { if (objects[i]->Collided(point)) { +Dimension * dimension = objects[i]->GetAttachedDimension(); + objects.erase(objects.begin() + i); // Calls the destructor, (deletes the object, I presume... O_o) + +// If this object had an attached dimension, reattach it to another object, if any... +// The only problem with that approach is if the object it gets attached to is deleted, +// it will call the dimension to use a NULL pointer and BLAMMO +if (dimension) +{ + Vector p1 = dimension->GetPoint1(); + Vector p2 = dimension->GetPoint2(); + for(int j=0; j<(int)objects.size(); j++) + { + Vector * objectP1 = objects[i]->GetPointAt(p1); + Vector * objectP2 = objects[i]->GetPointAt(p2); + + if (objectP1) + dimension->SetPoint1(objectP1); + + if (objectP2) + dimension->SetPoint2(objectP2); + } +} + + // This only allows deleting objects one at a time... break; + // however, this way of doing things could be problematic if we don't + // delete one at a time... Need to come up with a better approach. } } } @@ -138,8 +197,10 @@ Like so: return collision; } + // The TLC is passing all mouse movement here, so we're doing the same here. // Need to adjust all other objects to handle things correctly. + // One optimization that will need to be done eventually is to subdivide the screen // into parts and keep subdividing until an acceptable number of objects lie within // the slice. This way, the GUI will still be responsive and *not* have to test @@ -159,6 +220,7 @@ Like so: // needUpdate = false; } + /*virtual*/ void Container::PointerReleased(void) { dragging = false; @@ -179,6 +241,7 @@ about keeping track of old states... objects[i]->PointerReleased(); } + /*virtual*/ bool Container::NeedsUpdate(void) { needUpdate = false; @@ -192,7 +255,19 @@ about keeping track of old states... return needUpdate; } + /*virtual*/ void Container::Add(Object * object) { objects.push_back(object); } + + +void Container::Clear(void) +{ + // No memory leaks! + while (objects.size() > 0) + { + delete objects[0]; + objects.erase(objects.begin()); + } +}