From: Shamus Hammons Date: Tue, 4 Feb 2014 21:03:48 +0000 (-0600) Subject: Added UI feedback to Dimension object. X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?p=architektonas;a=commitdiff_plain;h=2549a213bacfb2f6993ec143083d72b716854345 Added UI feedback to Dimension object. --- diff --git a/src/dimension.cpp b/src/dimension.cpp index 63e1ba2..c9777e5 100644 --- a/src/dimension.cpp +++ b/src/dimension.cpp @@ -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); diff --git a/src/dimension.h b/src/dimension.h index 7ffca2f..32aa285 100644 --- a/src/dimension.h +++ b/src/dimension.h @@ -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