]> Shamusworld >> Repos - architektonas/blobdiff - src/utils.cpp
Further progress on Polylines: Polylines can be selected and moved.
[architektonas] / src / utils.cpp
index b9ca463bbc948bda5ba79bcfeaa220af0588d0c3..cd05ba735e95f30ac96aacf56f205e6548840a79 100644 (file)
@@ -1,3 +1,4 @@
+//
 // utils.cpp: Stuff that's useful to have kicking around, in one spot
 //
 // Part of the Architektonas Project
@@ -16,7 +17,6 @@
 #include <string.h>            // For memcpy()
 #include "geometry.h"
 
-
 //
 // Copy objects in one vector to another, creating copies and placing them in
 // the other vector. Clearing & etc. of vectors is responsibility of the caller!
@@ -31,7 +31,6 @@ void CopyObjects(VPVector & from, VPVector & to)
        }
 }
 
-
 VPVector CopyObjects(VPVector & src)
 {
        VPVector copy;
@@ -45,7 +44,6 @@ VPVector CopyObjects(VPVector & src)
        return copy;
 }
 
-
 //
 // Create a copy of the passed in object.
 //
@@ -75,6 +73,11 @@ Object * CopyObject(Object * obj)
                newObject = new Dimension();
                memcpy(newObject, obj, sizeof(Dimension));
                break;
+       case OTPolyline:
+               newObject = new Polyline();
+               memcpy(newObject, obj, sizeof(Polyline));
+               ((Polyline *)newObject)->points = ((Polyline *)obj)->points;
+               break;
        case OTSpline:
                newObject = new Spline();
                memcpy(newObject, obj, sizeof(Spline));
@@ -104,7 +107,6 @@ Object * CopyObject(Object * obj)
        return (Object *)newObject;
 }
 
-
 //
 // Create a copy of the passed in object.  This version calls the second
 // version of CopyObjects() (with one parameter and a vector return value).
@@ -140,6 +142,12 @@ Object * CopyObject2(Object * obj)
                memcpy(newObject, obj, sizeof(Dimension));
                break;
 
+       case OTPolyline:
+               newObject = new Polyline();
+               memcpy(newObject, obj, sizeof(Polyline));
+               ((Polyline *)newObject)->points = ((Polyline *)obj)->points;
+               break;
+
        case OTSpline:
                newObject = new Spline();
                memcpy(newObject, obj, sizeof(Spline));
@@ -167,7 +175,6 @@ Object * CopyObject2(Object * obj)
        return (Object *)newObject;
 }
 
-
 void MoveSelectedObjectsTo(VPVector & dest, VPVector & from)
 {
        VPVectorIter i = from.begin();
@@ -186,7 +193,6 @@ void MoveSelectedObjectsTo(VPVector & dest, VPVector & from)
        }
 }
 
-
 VPVector MoveSelectedObjectsFrom(VPVector & from)
 {
        VPVector objects;
@@ -208,7 +214,6 @@ VPVector MoveSelectedObjectsFrom(VPVector & from)
        return objects;
 }
 
-
 //hmm, this won't work, as these are just pointers...
 //[should work now]
 void CopySelectedObjectsTo(VPVector & dest, VPVector & from)
@@ -222,7 +227,6 @@ void CopySelectedObjectsTo(VPVector & dest, VPVector & from)
        }
 }
 
-
 VPVector CopySelectedObjects(VPVector & src)
 {
        VPVector copy;
@@ -238,21 +242,18 @@ VPVector CopySelectedObjects(VPVector & src)
        return copy;
 }
 
-
 void AddObjectsTo(VPVector & dest, VPVector & from)
 {
        for(VPVectorIter i=from.begin(); i!=from.end(); i++)
                dest.push_back(*i);
 }
 
-
 void ClearSelected(VPVector & v)
 {
        for(VPVectorIter i=v.begin(); i!=v.end(); i++)
                ((Object *)(*i))->selected = false;
 }
 
-
 //
 // Select all *visible* objects.  If an object's layer is invisible, skip it.
 //
@@ -266,7 +267,6 @@ void SelectAll(VPVector & v)
        }
 }
 
-
 //
 // Recursively go down thru the Container's vectors, deleting all the objects
 // contained therein.  Once that is done, the main Container can be deleted.
@@ -290,7 +290,6 @@ void DeleteContents(VPVector & v)
        v.clear();
 }
 
-
 void DeleteSelectedObjects(VPVector & v)
 {
        VPVectorIter i = v.begin();
@@ -309,7 +308,6 @@ void DeleteSelectedObjects(VPVector & v)
        }
 }
 
-
 //
 // This is used to remove selected objects from one container in order to move
 // them to a different container.
@@ -329,6 +327,24 @@ void RemoveSelectedObjects(VPVector & v)
        }
 }
 
+//
+// This is used to remove hovered objects from one container in order to delete
+// them from the same container.
+//
+void RemoveHoveredObjects(VPVector & v)
+{
+       VPVectorIter i = v.begin();
+
+       while (i != v.end())
+       {
+               Object * obj = (Object *)(*i);
+
+               if (obj->hovered)
+                       v.erase(i);
+               else
+                       i++;
+       }
+}
 
 void SavePointsFrom(VPVector & v, std::vector<Object> & save)
 {
@@ -342,7 +358,6 @@ void SavePointsFrom(VPVector & v, std::vector<Object> & save)
        }
 }
 
-
 void RestorePointsTo(VPVector & v, std::vector<Object> & s)
 {
        std::vector<Object>::iterator i;
@@ -360,7 +375,6 @@ void RestorePointsTo(VPVector & v, std::vector<Object> & s)
        }
 }
 
-
 void RestorePointsTo(VPVector & v, VPVector & s)
 {
        for(VPVectorIter i=s.begin(), j=v.begin(); i!=s.end(); i++, j++)
@@ -383,7 +397,6 @@ void RestorePointsTo(VPVector & v, VPVector & s)
        }
 }
 
-
 //
 // Translate a single object; it it's a Container, translate all its contents,
 // including subcontainers.
@@ -397,12 +410,13 @@ void TranslateObject(Object * obj, Point delta)
                for(VPVectorIter i=c->objects.begin(); i!=c->objects.end(); i++)
                        TranslateObject((Object *)*i, delta);
        }
+       else if (obj->type == OTPolyline)
+               ((Polyline *)obj)->Translate(delta);
 
        obj->p[0] += delta;
        obj->p[1] += delta;
 }
 
-
 /*
 So we need to make it so that we pick the container's point clicked on, and translate all the other parts *not* clicked on.
 */
@@ -464,7 +478,6 @@ void TranslateContainer(Container * c, Point point, Point delta)
        TranslateObject((Object *)c, clickedDelta);
 }
 
-
 //
 // Translate all objects in the passed in vector, including Containers and all
 // the objects they contain.
@@ -482,10 +495,13 @@ void TranslateObjects(VPVector & v, Point delta)
                        Container * c = (Container *)obj;
                        TranslateObjects(c->objects, delta);
                }
+               else if (obj->type == OTPolyline)
+               {
+                       ((Polyline *)obj)->Translate(delta);
+               }
        }
 }
 
-
 //
 // This does not *copy* the objects, it simply flattens out the pointers in the
 // Container and all sub-Containers.
@@ -510,7 +526,6 @@ VPVector Flatten(Container * src)
        return flat;
 }
 
-
 //
 // This does not *copy* the objects, it simply flattens out the pointers in the
 // vector and all sub-Containers in the vector.
@@ -534,4 +549,3 @@ VPVector Flatten(VPVector src)
 
        return flat;
 }
-