X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fobject.cpp;h=346c19a11536d686a0ea63ba8f4d5883bdb8f9c6;hb=642cf72c11b49a9e00128ab6258a2438c785a5ab;hp=b5bab70d954f7c2f80e93cc29de2d3f790484c72;hpb=7b7c8ec7d7f5379e09a8b7392f465f41639b0c79;p=architektonas diff --git a/src/object.cpp b/src/object.cpp index b5bab70..346c19a 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,73 +27,231 @@ int Object::viewportHeight = 0; bool Object::deleteActive = false; bool Object::dimensionActive = false; 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), state(OSInactive), oldState(OSInactive), - needUpdate(false), attachedDimension(0) +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); } + /*virtual*/ void Object::Draw(Painter *) { } + /*virtual*/ Vector Object::Center(void) { return Vector(); } + /*virtual*/ bool Object::Collided(Vector) { return false; } + /*virtual*/ void Object::PointerMoved(Vector) { } + /*virtual*/ void Object::PointerReleased(void) { } + /*virtual*/ bool Object::NeedsUpdate(void) { return needUpdate; } + +/*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 *) { } + /*virtual*/ Object * Object::GetParent(void) { return parent; } + /*virtual*/ void Object::Add(Object *) { } + +// This returns a pointer to the point passed in, if it coincides. Otherwise returns NULL. +/*virtual*/ Vector * Object::GetPointAt(Vector) +{ + return 0; +} + + +// This is meant for writing object data to a file. +/*virtual*/ void Object::Enumerate(FILE *) +{ +} + + +/*virtual*/ Object * Object::Copy(void) +{ + return new Object(position, parent); +} + + +// 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) +{ + connected.push_back(Connection(obj, parameter)); +} + + +/*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 +} + + +/*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(Vector, double) +{ +} + + +/*virtual*/ void Object::Scale(Vector, double) +{ +} + + ObjectState Object::GetState(void) { return state; } + void Object::Reparent(Object * newParent) { parent = newParent; } + +/*Dimension * Object::GetAttachedDimension(void) +{ + return attachedDimension; +}*/ + + // Class methods... void Object::SetFixedAngle(bool state/*= true*/) @@ -99,32 +259,60 @@ void Object::SetFixedAngle(bool state/*= true*/) fixedAngle = state; } + void Object::SetFixedLength(bool state/*= true*/) { fixedLength = state; } + void Object::SetFont(QFont * f) { font = f; } + void Object::SetViewportHeight(int height) { viewportHeight = height; } + void Object::SetDeleteActive(bool state/*= true*/) { deleteActive = state; } + void Object::SetDimensionActive(bool state/*= true*/) { dimensionActive = state; } + 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; +} + +