]> Shamusworld >> Repos - architektonas/blobdiff - src/circle.cpp
Converted codebase from Qt4 to Qt5.
[architektonas] / src / circle.cpp
index b722f4d390a3c290ec6a68338b6591ebc061497a..ed37be3fcd7268faf59cfcb3906316f69a447045 100644 (file)
@@ -100,6 +100,9 @@ Circle::~Circle()
        if (snapToGrid)
                point = SnapPointToGrid(point);
 
+       if (snapPointIsValid)
+               point = snapPoint;
+
        draggingCenter = hitCenter;
        draggingEdge = hitCircle;
 
@@ -118,7 +121,7 @@ Circle::~Circle()
 }
 
 
-/*virtual*/ void Circle::PointerMoved(Vector point)
+/*virtual*/ bool Circle::PointerMoved(Vector point)
 {
        if (selectionInProgress)
        {
@@ -129,14 +132,26 @@ Circle::~Circle()
                else
                        state = OSInactive;
 
-               return;
+               return false;
        }
 
+/*
+Note that we can separate this out in the TLC, and it would probably make more sense
+to do it there as then we can be assured that all hit testing is done before we do
+any snapping. !!! FIX !!!
+*/
        // Hit test tells us what we hit (if anything) through boolean variables. It
        // also tells us whether or not the state changed.
        SaveHitState();
-       HitTest(point);
+       bool hovered = HitTest(point);
        needUpdate = HitStateChanged();
+
+       if (snapToGrid)
+               point = SnapPointToGrid(point);
+
+       if (snapPointIsValid)
+               point = snapPoint;
+
        objectWasDragged = (draggingEdge | draggingCenter);
 
        if (objectWasDragged)
@@ -149,6 +164,7 @@ Circle::~Circle()
 
        // Save this point so the rendering code knows where to draw the handle...
        dragPoint = point;
+       return hovered;
 }
 
 
@@ -172,8 +188,8 @@ Circle::~Circle()
        double length = Vector::Magnitude(position, point);
 //printf("Circle::length = %lf, radius = %lf\n", length, radius);
 //How to translate this into pixels from Document space???
-//Maybe we need to pass a scaling factor in here from the caller? That would make sense, as
-//the caller knows about the zoom factor and all that good kinda crap
+//Maybe we need to pass a scaling factor in here from the caller? That would make
+//sense, as the caller knows about the zoom factor and all that good kinda crap
 /*
 Document passes in the correct Cartesian coordinates being pointed to by the mouse.
 So all we have to be concerned with is properly scaling our hot zones/handle sizes,
@@ -185,7 +201,16 @@ the radius will be 5.0. By multiplying the length by the zoom factor, we align o
 pointed at length with our on screen length.
 */
        if ((length * Painter::zoom) < 8.0)
+       {
                hitCenter = true;
+
+               // Make sure we don't try to snap to ourselves...!
+               if (!draggingCenter)
+               {
+                       snapPoint = position;
+                       snapPointIsValid = true;
+               }
+       }
 //wrong:       else if ((length < (radius + 2.0)) && (length > (radius - 2.0)))
 /*NB: The following should be identical to what we have down below, but it doesn't work out that way... :-P */
 //close, but no        else if (((length * Painter::zoom) < ((radius * Painter::zoom) + 2.0)) && ((length * Painter::zoom) > ((radius * Painter::zoom) - 2.0)))
@@ -243,10 +268,16 @@ same reference number.
 }
 
 
+/*virtual*/ void Circle::Rotate(Point point, double angle)
+{
+       Point c1 = Geometry::RotatePointAroundPoint(position, point, angle);
+       position = c1;
+}
+
+
 /*virtual*/ void Circle::Mirror(Point p1, Point p2)
 {
        Point c1 = Geometry::MirrorPointAroundLine(position, p1, p2);
-//     return new Circle(c1, radius);
        position = c1;
 }