X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fobject.cpp;h=346c19a11536d686a0ea63ba8f4d5883bdb8f9c6;hb=642cf72c11b49a9e00128ab6258a2438c785a5ab;hp=197fa8d0f63c202d07f0a9c38183d65cb01eab92;hpb=ba6723b86d8dd67ebc7b11b245de3e7ff64f06b1;p=architektonas diff --git a/src/object.cpp b/src/object.cpp index 197fa8d..346c19a 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -17,6 +17,7 @@ #include "object.h" #include +#include // Initialize static variables bool Object::fixedAngle = false; @@ -29,17 +30,22 @@ bool Object::snapToGrid = true; //snapToPoints all well here? bool Object::ignoreClicks = false; bool Object::dontMove = false; +bool Object::selectionInProgress = false; +QRectF Object::selection; +double Object::gridSpacing; +int Object::currentLayer = 0; Object::Object(): position(Vector(0, 0)), parent(0), type(OTObject), - state(OSInactive), oldState(OSInactive), needUpdate(false) + state(OSInactive), layer(0), oldState(OSInactive), needUpdate(false) //, attachedDimension(0) { } -Object::Object(Vector v, Object * passedInParent/*= 0*/): position(v), parent(passedInParent), - state(OSInactive), oldState(OSInactive), needUpdate(false)//, attachedDimension(0) +Object::Object(Vector v, Object * passedInParent/*= 0*/): position(v), + parent(passedInParent), state(OSInactive), layer(0), oldState(OSInactive), + needUpdate(false)//, attachedDimension(0) { } @@ -85,6 +91,12 @@ printf("Object: Destroyed!\n"); } +/*virtual*/ bool Object::HitTest(Point) +{ + return false; +} + + // This is intended to be overridden by the Container class, for object morphing /*virtual*/ void Object::Transmute(Object *, Object *) { @@ -139,6 +151,7 @@ printf("Object: Destroyed!\n"); /*virtual*/ void Object::Disconnect(Object * obj, double parameter) { +#if 0 for(uint i=0; i::iterator i; + + for(i=connected.begin(); i!=connected.end(); i++) + { + if (((*i).object == obj) && ((*i).t == parameter)) + { + connected.erase(i); + return; + } + } +#endif } /*virtual*/ void Object::DisconnectAll(Object * obj) { +#if 0 // According the std::vector docs, only items at position i and beyond are // invalidated, everything before i is still valid. So we use that here. for(uint i=0; i::iterator i; + + for(i=connected.begin(); i!=connected.end(); ) + { + if ((*i).object == obj) + connected.erase(i); + else + i++; + } +#endif } @@ -181,6 +218,22 @@ printf("Object: Destroyed!\n"); #endif +/*virtual*/ void Object::Translate(Vector amount) +{ + position += amount; +} + + +/*virtual*/ void Object::Rotate(Vector, double) +{ +} + + +/*virtual*/ void Object::Scale(Vector, double) +{ +} + + ObjectState Object::GetState(void) { return state; @@ -241,3 +294,25 @@ void Object::SetSnapMode(bool state/*= true*/) { snapToGrid = state; } + + +// +// This looks strange, but it's really quite simple: We want a point that's +// more than half-way to the next grid point to snap there while conversely we +// want a point that's less than half-way to to the next grid point then snap +// to the one before it. So we add half of the grid spacing to the point, then +// divide by it so that we can remove the fractional part, then multiply it +// back to get back to the correct answer. +// +Vector Object::SnapPointToGrid(Vector point) +{ + point += gridSpacing / 2.0; // *This* adds to Z!!! + point /= gridSpacing; + point.x = floor(point.x);//need to fix this for negative numbers... + point.y = floor(point.y); + point.z = 0; // Make *sure* Z doesn't go anywhere!!! + point *= gridSpacing; + return point; +} + +