]> Shamusworld >> Repos - architektonas/commitdiff
Added ability to drag objects to Line endpoints.
authorShamus Hammons <jlhamm@acm.org>
Tue, 7 Feb 2017 04:11:26 +0000 (22:11 -0600)
committerShamus Hammons <jlhamm@acm.org>
Tue, 7 Feb 2017 04:11:26 +0000 (22:11 -0600)
src/drawingview.cpp
src/drawingview.h

index a88be252f9df4b9e3fb011bb700f4316a544a302..9fb0332a2ff9ccc5b327f460fafbc21435bebc39 100644 (file)
@@ -93,7 +93,6 @@ DrawingView::DrawingView(QWidget * parent/*= NULL*/): QWidget(parent),
        document.objects.push_back(new Text(Vector(10, 83), "Here is some awesome text!"));
 #endif
 
-printf("Document topLevel = %s\n", (document.topLevel ? "true" : "false"));
 /*
 Here we set the grid size in pixels--12 in this case. Initially, we have our
 zoom set to make this represent 12 inches at a zoom factor of 25%. (This is
@@ -1260,11 +1259,12 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event)
 
        // Do object hit testing...
        bool needUpdate = HitTestObjects(point);
+       GetHovered(hover);
 
        // Check for multi-hover...
        if (numHovered > 1)
        {
-               GetHovered(hover);
+//need to check for case where hover is over 2 circles and a 3rd's center...
                Object * obj1 = (Object *)hover[0], * obj2 = (Object *)hover[1];
 
                Geometry::Intersects(obj1, obj2);
@@ -1309,6 +1309,8 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event)
        {
                if (hoveringIntersection)
                        point = intersectionPoint;
+               else if (hoverPointValid)
+                       point = hoverPoint;
                else if (Global::snapToGrid)
                        point = SnapPointToGrid(point);
 
@@ -1323,6 +1325,8 @@ void DrawingView::mouseMoveEvent(QMouseEvent * event)
        {
                if (hoveringIntersection)
                        point = intersectionPoint;
+               else if (hoverPointValid)
+                       point = hoverPoint;
                else if (Global::snapToGrid)
                        point = SnapPointToGrid(point);
 
@@ -1678,6 +1682,7 @@ bool DrawingView::HitTestObjects(Point point)
        std::vector<void *>::iterator i;
        numHovered = 0;
        bool needUpdate = false;
+       hoverPointValid = false;
 
        for(i=document.objects.begin(); i!=document.objects.end(); i++)
        {
@@ -1728,9 +1733,17 @@ bool DrawingView::HitTest(Object * obj, Point point)
                                / lineSegment.Magnitude());
 
                if ((v1.Magnitude() * Global::zoom) < 8.0)
+               {
                        obj->hitPoint[0] = true;
+                       hoverPoint = obj->p[0];
+                       hoverPointValid = true;
+               }
                else if ((v2.Magnitude() * Global::zoom) < 8.0)
+               {
                        obj->hitPoint[1] = true;
+                       hoverPoint = obj->p[1];
+                       hoverPointValid = true;
+               }
                else if ((distance * Global::zoom) < 5.0)
                        obj->hitObject = true;
 
index 1af3a7776506a98fe1de0fbeec85a699ab90e88b..8e7357ef841ca6e0ebeed8ed2419bf2befaae26f 100644 (file)
@@ -87,6 +87,8 @@ class DrawingView: public QWidget
                std::vector<Object> toolScratch;
                Point toolPoint[32];
                Point intersectionPoint;
+               Point hoverPoint;
+               bool hoverPointValid;
                bool hoveringIntersection;
                Object * dragged;
                bool draggingObject;