]> Shamusworld >> Repos - architektonas/blobdiff - src/object.cpp
Added rotation tool.
[architektonas] / src / object.cpp
index 404d30576113a97ad9516b04677d087f81ad4346..ca065dcdc77832daa41192d3d7496739d68a193e 100644 (file)
@@ -17,6 +17,7 @@
 
 #include "object.h"
 #include <stdlib.h>
+#include <math.h>
 
 // Initialize static variables
 bool Object::fixedAngle = false;
@@ -31,17 +32,19 @@ 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),
+       parent(passedInParent), state(OSInactive), layer(0), oldState(OSInactive),
        needUpdate(false)//, attachedDimension(0)
 {
 }
@@ -221,16 +224,33 @@ printf("Object: Destroyed!\n");
 }
 
 
-/*virtual*/ void Object::Rotate(Vector, double)
+/*virtual*/ void Object::Rotate(Point, double)
 {
 }
 
 
-/*virtual*/ void Object::Scale(Vector, 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;
@@ -291,3 +311,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;
+}
+
+