]> Shamusworld >> Repos - architektonas/blobdiff - src/circle.cpp
Added new triangulation tool, ability to snap to endpoints/intersections.
[architektonas] / src / circle.cpp
index 909d30416bac3676beaf8d6d8cbe905184f04eb7..093f53395834bd3472a05a3242ad148bd1cc8759 100644 (file)
@@ -16,6 +16,7 @@
 #include "circle.h"
 
 #include <QtGui>
+#include "geometry.h"
 #include "painter.h"
 
 
@@ -59,7 +60,7 @@ Circle::~Circle()
        {
                QString text = QObject::tr("Radius: %1\nScale: %2%");
                text = text.arg(radius, 0, 'd', 4).arg(radius / oldRadius * 100.0, 0, 'd', 0);
-
+#if 0
                QPen pen = QPen(QColor(0x00, 0xFF, 0x00), 1.0, Qt::SolidLine);
                painter->SetPen(pen);
                painter->SetBrush(QBrush(QColor(0x40, 0xFF, 0x40, 0x9F)));
@@ -71,6 +72,9 @@ Circle::~Circle()
                pen = QPen(QColor(0x00, 0x5F, 0xDF));
                painter->SetPen(pen);
                painter->DrawText(textRect, Qt::AlignVCenter, text);
+#else
+               painter->DrawInformativeText(text);
+#endif
        }
 }
 
@@ -83,10 +87,22 @@ Circle::~Circle()
 
 /*virtual*/ bool Circle::Collided(Vector point)
 {
+       // Someone told us to fuck off, so we'll fuck off. :-)
+       if (ignoreClicks)
+               return false;
+
        // We can assume this, since this is a mouse down event here.
        objectWasDragged = false;
        HitTest(point);
 
+       // Now that we've done our hit testing on the non-snapped point, snap it if
+       // necessary...
+       if (snapToGrid)
+               point = SnapPointToGrid(point);
+
+       if (snapPointIsValid)
+               point = snapPoint;
+
        draggingCenter = hitCenter;
        draggingEdge = hitCircle;
 
@@ -105,7 +121,7 @@ Circle::~Circle()
 }
 
 
-/*virtual*/ void Circle::PointerMoved(Vector point)
+/*virtual*/ bool Circle::PointerMoved(Vector point)
 {
        if (selectionInProgress)
        {
@@ -116,14 +132,21 @@ Circle::~Circle()
                else
                        state = OSInactive;
 
-               return;
+               return false;
        }
 
        // 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)
@@ -136,6 +159,7 @@ Circle::~Circle()
 
        // Save this point so the rendering code knows where to draw the handle...
        dragPoint = point;
+       return hovered;
 }
 
 
@@ -172,7 +196,11 @@ 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;
+               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)))
@@ -210,7 +238,7 @@ bool Circle::HitStateChanged(void)
 
 /*virtual*/ void Circle::Enumerate(FILE * file)
 {
-       fprintf(file, "CIRCLE (%lf,%lf) %lf\n", position.x, position.y, radius);
+       fprintf(file, "CIRCLE %i (%lf,%lf) %lf\n", layer, position.x, position.y, radius);
 }
 
 
@@ -229,3 +257,31 @@ same reference number.
        return new Circle(position, radius, parent);
 }
 
+
+/*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);
+       position = c1;
+}
+
+
+/*virtual*/ void Circle::Save(void)
+{
+       Object::Save();
+       oldRadius2 = radius;
+}
+
+
+/*virtual*/ void Circle::Restore(void)
+{
+       Object::Restore();
+       radius = oldRadius2;
+}
+