]> Shamusworld >> Repos - architektonas/commitdiff
Added UI feedback to Dimension object.
authorShamus Hammons <jlhamm@acm.org>
Tue, 4 Feb 2014 21:03:48 +0000 (15:03 -0600)
committerShamus Hammons <jlhamm@acm.org>
Tue, 4 Feb 2014 21:03:48 +0000 (15:03 -0600)
src/dimension.cpp
src/dimension.h

index 63e1ba2e7f50b9b38778974d467e78b5a24c56e6..c9777e50bd673688bc5d06dee646c6a4753cd19d 100644 (file)
@@ -69,10 +69,19 @@ all objects move as a unified whole.
        if (point2.object)
                endpoint = point2.object->GetPointAtParameter(point2.t);
 
+       painter->SetPen(QPen(Qt::magenta, 2.0, Qt::DotLine));
+
+       if ((state == OSSelected) || ((state == OSInactive) && hitPoint1))
+               painter->DrawHandle(position);
+
+       if ((state == OSSelected) || ((state == OSInactive) && hitPoint2))
+               painter->DrawHandle(endpoint);
+#if 0
        if (state == OSSelected)
                painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine));
        else
 //             painter->SetPen(QPen(Qt::blue, 1.0, Qt::SolidLine));
+#endif
                painter->SetPen(QPen(Qt::blue, 1.0 * Painter::zoom * size, Qt::SolidLine));
 
        painter->SetBrush(QBrush(QColor(Qt::blue)));
@@ -186,16 +195,16 @@ I believe they are pixels.
 
        if (hitPoint1)
        {
-//             oldState = state;
-//             state = OSSelected;
+               oldState = state;
+               state = OSSelected;
                oldPoint = position;
                draggingHandle1 = true;
                return true;
        }
        else if (hitPoint2)
        {
-//             oldState = state;
-//             state = OSSelected;
+               oldState = state;
+               state = OSSelected;
                oldPoint = endpoint;
                draggingHandle2 = true;
                return true;
@@ -208,6 +217,7 @@ I believe they are pixels.
 
 /*virtual*/ void Dimension::PointerMoved(Vector point)
 {
+#if 0
        // We know this is true because mouse move messages don't come here unless
        // the object was actually clicked on--therefore we *know* we're being
        // dragged...
@@ -244,6 +254,29 @@ I believe they are pixels.
        }
        else
                needUpdate = false;
+#else
+       // Hit test tells us what we hit (if anything) through boolean variables. (It
+       // also tells us whether or not the state changed. --not any more)
+       SaveHitState();
+       HitTest(point);
+       needUpdate = HitStateChanged();
+
+       objectWasDragged = (/*draggingLine |*/ draggingHandle1 | draggingHandle2);
+
+       if (objectWasDragged)
+       {
+               Vector delta = point - oldPoint;
+
+               if (draggingHandle1)// || draggingLine)
+                       position += delta;
+
+               if (draggingHandle2)// || draggingLine)
+                       endpoint += delta;
+
+               oldPoint = point;
+               needUpdate = true;
+       }
+#endif
 }
 
 
@@ -316,6 +349,23 @@ about keeping track of old states...
 }
 
 
+void Dimension::SaveHitState(void)
+{
+       oldHitPoint1 = hitPoint1;
+       oldHitPoint2 = hitPoint2;
+//     oldHitLine = hitLine;
+}
+
+
+bool Dimension::HitStateChanged(void)
+{
+       if ((hitPoint1 != oldHitPoint1) || (hitPoint2 != oldHitPoint2))
+               return true;
+
+       return false;
+}
+
+
 /*virtual*/ void Dimension::Enumerate(FILE * file)
 {
        fprintf(file, "DIMENSION %i (%lf,%lf) (%lf,%lf) %i\n", layer, position.x, position.y, endpoint.x, endpoint.y, type);
index 7ffca2faabf8e72b4473c809c1f8981391cf8c07..32aa2857c3582ee1786faaa70b7f62baf0210c29 100644 (file)
@@ -28,9 +28,14 @@ class Dimension: public Object
                virtual QRectF Extents(void);
                void FlipSides(void);
 
+       protected:
+               void SaveHitState(void);
+               bool HitStateChanged(void);
+
        protected:
                Vector endpoint;                                        // Starting point is Object::position
                Vector oldPoint;                                        // Used for dragging
+               Point oldEndpoint;
 
        private:
                bool dragging;
@@ -41,6 +46,7 @@ class Dimension: public Object
                DimensionType dimensionType;
                bool hitPoint1;
                bool hitPoint2;
+               bool oldHitPoint1, oldHitPoint2;
        public:
                double size;                                            // Size of arrows/text in base units