From a7721909d18369e404496061e03b5483ff781eed Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Mon, 6 Feb 2017 22:11:26 -0600 Subject: [PATCH] Added ability to drag objects to Line endpoints. --- src/drawingview.cpp | 17 +++++++++++++++-- src/drawingview.h | 2 ++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/drawingview.cpp b/src/drawingview.cpp index a88be25..9fb0332 100644 --- a/src/drawingview.cpp +++ b/src/drawingview.cpp @@ -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::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; diff --git a/src/drawingview.h b/src/drawingview.h index 1af3a77..8e7357e 100644 --- a/src/drawingview.h +++ b/src/drawingview.h @@ -87,6 +87,8 @@ class DrawingView: public QWidget std::vector toolScratch; Point toolPoint[32]; Point intersectionPoint; + Point hoverPoint; + bool hoverPointValid; bool hoveringIntersection; Object * dragged; bool draggingObject; -- 2.37.2