X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fobject.cpp;h=4cc846028a669576f12e8545214b54f69c1a4103;hb=7f3a6b11585376eecd80979ec3da2346c5314d88;hp=8f9377bf7345624c61acffb6b9de11735a4ec656;hpb=eb0057e8a8145032152e4c417fcd102ef5a21484;p=architektonas diff --git a/src/object.cpp b/src/object.cpp index 8f9377b..4cc8460 100644 --- a/src/object.cpp +++ b/src/object.cpp @@ -16,6 +16,8 @@ // #include "object.h" +#include +#include // Initialize static variables bool Object::fixedAngle = false; @@ -25,22 +27,36 @@ int Object::viewportHeight = 0; bool Object::deleteActive = false; bool Object::dimensionActive = false; bool Object::snapToGrid = true; - - -Object::Object(): position(Vector(0, 0)), parent(0), state(OSInactive), oldState(OSInactive), - needUpdate(false), attachedDimension(0) +//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; +Point Object::snapPoint; +bool Object::snapPointIsValid = false; + + +Object::Object(): position(Vector(0, 0)), parent(0), type(OTObject), + 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) { } Object::~Object() { +printf("Object: Destroyed!\n"); + for(uint i=0; iDisconnectAll(this); } @@ -61,8 +77,9 @@ Object::~Object() } -/*virtual*/ void Object::PointerMoved(Vector) +/*virtual*/ bool Object::PointerMoved(Vector) { + return false; } @@ -77,6 +94,12 @@ Object::~Object() } +/*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 *) { @@ -113,6 +136,111 @@ Object::~Object() } +// This returns a point on the object at 'parameter', which is between 0 and 1. +// Default is to return the object's position. +/*virtual*/ Vector Object::GetPointAtParameter(double) +{ + return position; +} + + +// Since these functions are pretty much non-object specific, we can implement +// them here. :-) +/*virtual*/ void Object::Connect(Object * obj, double parameter) +{ + // Check to see if this connection is already in our list... + Connection c(obj, parameter); + std::vector::iterator i; + + for(i=connected.begin(); i!=connected.end(); i++) + { + // Bail out if this connection is already present... + if (*i == c) + return; + } + + // Connection is a new one, add it in... + connected.push_back(c); +} + + +/*virtual*/ void Object::Disconnect(Object * obj, double parameter) +{ + std::vector::iterator i; + + for(i=connected.begin(); i!=connected.end(); i++) + { + if (((*i).object == obj) && ((*i).t == parameter)) + { + connected.erase(i); + return; + } + } +} + + +/*virtual*/ void Object::DisconnectAll(Object * obj) +{ + std::vector::iterator i; + + for(i=connected.begin(); i!=connected.end(); ) + { + if ((*i).object == obj) + connected.erase(i); + else + i++; + } +} + + +/*virtual*/ QRectF Object::Extents(void) +{ + // Generic object returns an empty rect... + return QRectF(); +} + + +#if 0 +/*virtual*/ ObjectType Object::Type(void) +{ + return OTObject; +} +#endif + + +/*virtual*/ void Object::Translate(Vector amount) +{ + position += amount; +} + + +/*virtual*/ void Object::Rotate(Point, double) +{ +} + + +/*virtual*/ void Object::Scale(Point, double) +{ +} + + +/*virtual*/ void Object::Mirror(Point, Point) +{ +} + + +/*virtual*/ void Object::Save(void) +{ + oldPosition = position; +} + + +/*virtual*/ void Object::Restore(void) +{ + position = oldPosition; +} + + ObjectState Object::GetState(void) { return state; @@ -125,10 +253,10 @@ void Object::Reparent(Object * newParent) } -Dimension * Object::GetAttachedDimension(void) +/*Dimension * Object::GetAttachedDimension(void) { return attachedDimension; -} +}*/ // Class methods... @@ -173,3 +301,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; +} + +