]> Shamusworld >> Repos - architektonas/blobdiff - src/circle.cpp
Fixed loading code, added "Base Unit" dialog.
[architektonas] / src / circle.cpp
index 35c9d7c2e53f224dd97323229027b37c246ce88a..77ea95a6290e5ca87dbe8ba9477bac561fce7bef 100644 (file)
@@ -4,7 +4,7 @@
 // (C) 2011 Underground Software
 // See the README and GPLv3 files for licensing and warranty information
 //
-// JLH = James L. Hammons <jlhamm@acm.org>
+// JLH = James Hammons <jlhamm@acm.org>
 //
 // WHO  WHEN        WHAT
 // ---  ----------  ------------------------------------------------------------
 Circle::Circle(Vector p1, double r, Object * p/*= NULL*/): Object(p1, p), radius(r),
        draggingEdge(false), draggingCenter(false), hitCenter(false), hitCircle(false)
 {
+       type = OTCircle;
 }
 
+
 Circle::~Circle()
 {
 }
 
+
 /*virtual*/ void Circle::Draw(Painter * painter)
 {
        if (state == OSSelected || hitCircle || hitCenter)
@@ -35,22 +38,30 @@ Circle::~Circle()
        else
                painter->SetPen(QPen(Qt::black, 1.0, Qt::SolidLine));
 
-       // Draw handles (if needed)
+       // Hatch/Fill...
+//     QBrush brush(Qt::DiagCrossPattern);
+//     brush.setColor(QColor(255, 255, 0));
+//     painter->SetBrush(brush);
+       painter->SetBrush(QBrush(Qt::NoBrush));
+
+       // Draw the object...
+       painter->DrawEllipse(position, radius, radius);
+
+       // & draw handles (if needed)
        if (state == OSSelected || hitCenter)
                painter->DrawHandle(position);
 
        if (state == OSSelected && draggingEdge && objectWasDragged)
                painter->DrawHandle(dragPoint);
-
-       // & finally, draw the object!
-       painter->DrawEllipse(position, radius, radius);
 }
 
+
 /*virtual*/ Vector Circle::Center(void)
 {
        return position;
 }
 
+
 /*virtual*/ bool Circle::Collided(Vector point)
 {
        // We can assume this, since this is a mouse down event here.
@@ -73,8 +84,20 @@ Circle::~Circle()
        return false;
 }
 
+
 /*virtual*/ void Circle::PointerMoved(Vector point)
 {
+       if (selectionInProgress)
+       {
+               // Check for whether or not the rect contains this circle
+               if (selection.normalized().contains(Extents()))
+                       state = OSSelected;
+               else
+                       state = OSInactive;
+
+               return;
+       }
+
        // Hit test tells us what we hit (if anything) through boolean variables. It
        // also tells us whether or not the state changed.
        needUpdate = HitTest(point);
@@ -89,6 +112,7 @@ Circle::~Circle()
        dragPoint = point;
 }
 
+
 /*virtual*/ void Circle::PointerReleased(void)
 {
        // Mouse went up, so our dragging is done (if any *was* done, that is)
@@ -101,7 +125,8 @@ Circle::~Circle()
                state = oldState;
 }
 
-bool Circle::HitTest(Point point)
+
+/*virtual*/ bool Circle::HitTest(Point point)
 {
        SaveState();
        hitCenter = hitCircle = false;
@@ -114,21 +139,39 @@ bool Circle::HitTest(Point point)
 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,
 since we generally *don't* want those to scale with the zoom level. ;-)
+
+What is going on here?
+If we're zoomed out to, say, 50%, & our radius is 10.0 (absolute), then on screen
+the radius will be 5.0. By multiplying the length by the zoom factor, we align our
+pointed at length with our on screen length.
 */
-       if (length < 8.0)
+       if ((length * Painter::zoom) < 8.0)
                hitCenter = true;
-       else if ((length < (radius + 2.0)) && (length > (radius - 2.0)))
+//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)))
+//really wrong!        else if (((length * Painter::zoom) < (radius + 2.0)) && ((length * Painter::zoom) > (radius - 2.0)))
+// close again, but sill no    else if (((length * Painter::zoom) < ((radius + 2.0) * Painter::zoom)) && ((length * Painter::zoom) > ((radius - 2.0) * Painter::zoom)))
+       else if ((fabs(length - radius) * Painter::zoom) < 2.0)
                hitCircle = true;
 
        return StateChanged();
 }
 
+
+/*virtual*/ QRectF Circle::Extents(void)
+{
+       return QRectF(QPointF(position.x - radius, position.y - radius), QPointF(position.x + radius, position.y + radius));
+}
+
+
 void Circle::SaveState(void)
 {
        oldHitCenter = hitCenter;
        oldHitCircle = hitCircle;
 }
 
+
 bool Circle::StateChanged(void)
 {
        if ((hitCenter != oldHitCenter) || (hitCircle != oldHitCircle))
@@ -136,3 +179,26 @@ bool Circle::StateChanged(void)
 
        return false;
 }
+
+
+/*virtual*/ void Circle::Enumerate(FILE * file)
+{
+       fprintf(file, "CIRCLE (%lf,%lf) %lf\n", position.x, position.y, radius);
+}
+
+
+/*virtual*/ Object * Circle::Copy(void)
+{
+#warning "!!! This doesn't take care of attached Dimensions !!!"
+/*
+This is a real problem. While having a pointer in the Dimension to this line's points
+is fast & easy, it creates a huge problem when trying to replicate an object like this.
+
+Maybe a way to fix that then, is to have reference numbers instead of pointers. That
+way, if you copy them, ... you might still have problems. Because you can't be sure if
+a copy will be persistant or not, you then *definitely* do not want them to have the
+same reference number.
+*/
+       return new Circle(position, radius, parent);
+}
+