X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Farc.cpp;h=355d7a76f2b5b425ddc5b882f7e21e86a22d8dc4;hb=70297ac8ec7453e4196f4b58056bcfe4b04f2aca;hp=8fc66319bbe540ef96a153ed193c6ec4635993e9;hpb=59e5af9d8606aa091fa979e19f78e9325a1c0825;p=architektonas diff --git a/src/arc.cpp b/src/arc.cpp index 8fc6631..355d7a7 100644 --- a/src/arc.cpp +++ b/src/arc.cpp @@ -121,6 +121,7 @@ Arc::~Arc() } painter->DrawArc(position, radius, startAngle, angleSpan); +// painter->DrawRect(Extents()); } @@ -236,6 +237,17 @@ so let's do like this: /*virtual*/ void Arc::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; + } + // The TLC will send these messages if the object is selected but not clicked on. // So we have to be careful with our assumptions here. // This is actually untrue in that case, we need to come up with something better @@ -281,10 +293,11 @@ so let's do like this: // Here we check for just a click: If object was clicked and dragged, then // revert to the old state (OSInactive). Otherwise, keep the new state that // we set. -/*Maybe it would be better to just check for "object was dragged" state and not have to worry -about keeping track of old states... -Well, we can't know if it was dragged from Inactive or not, that's the problem. We could make -a variable called "needToRevertToInactive" instead +/* +Maybe it would be better to just check for "object was dragged" state and not +have to worry about keeping track of old states... +Well, we can't know if it was dragged from Inactive or not, that's the problem. +We could make a variable called "needToRevertToInactive" instead I mean, we could write like: if (objectWasDragged && oldState == OSInactive) @@ -299,23 +312,64 @@ but this is actually more compact and cleaner. /*virtual*/ QRectF Arc::Extents(void) { -#warning "!!! Arc extents not calculated !!!" - return QRectF(); -} + double start = startAngle; + double end = start + angleSpan; + QPointF p1(cos(start), sin(start)); + QPointF p2(cos(end), sin(end)); + QRectF bounds(p1, p2); + + // Swap X/Y coordinates if they're backwards... + if (bounds.left() > bounds.right()) + { + double temp = bounds.left(); + bounds.setLeft(bounds.right()); + bounds.setRight(temp); + } + if (bounds.bottom() > bounds.top()) + { + double temp = bounds.bottom(); + bounds.setBottom(bounds.top()); + bounds.setTop(temp); + } -#if 0 -/*virtual*/ bool Arc::NeedsUpdate(void) -{ - return needUpdate; + // If the end of the arc is before the beginning, add 360 degrees to it + if (end < start) + end += 2.0 * PI; + + // Adjust the bounds depending on which axes are crossed + if ((start < PI_OVER_2) && (end > PI_OVER_2)) + bounds.setTop(1.0); + + if ((start < PI) && (end > PI)) + bounds.setLeft(-1.0); + + if ((start < (PI + PI_OVER_2)) && (end > (PI + PI_OVER_2))) + bounds.setBottom(-1.0); + + if ((start < (2.0 * PI)) && (end > (2.0 * PI))) + bounds.setRight(1.0); + + if ((start < ((2.0 * PI) + PI_OVER_2)) && (end > ((2.0 * PI) + PI_OVER_2))) + bounds.setTop(1.0); + + if ((start < (3.0 * PI)) && (end > (3.0 * PI))) + bounds.setLeft(-1.0); + + if ((start < ((3.0 * PI) + PI_OVER_2)) && (end > ((3.0 * PI) + PI_OVER_2))) + bounds.setBottom(-1.0); + + bounds.setTopLeft(QPointF(bounds.left() * radius, bounds.top() * radius)); + bounds.setBottomRight(QPointF(bounds.right() * radius, bounds.bottom() * radius)); + bounds.translate(position.x, position.y); + return bounds; } -#endif #if 0 -/*virtual*/ ObjectType Arc::Type(void) +/*virtual*/ bool Arc::NeedsUpdate(void) { - return OTArc; + return needUpdate; } #endif