X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fcircle.cpp;h=ed37be3fcd7268faf59cfcb3906316f69a447045;hb=6c1279871f6bb86bc59e2561b6a7f74ab081f71e;hp=1f350b0341615f7cc2abbde872c0448c13e68b66;hpb=f97fcdd0f5c95d15cc8f03a818ed8e90e76e8f5a;p=architektonas diff --git a/src/circle.cpp b/src/circle.cpp index 1f350b0..ed37be3 100644 --- a/src/circle.cpp +++ b/src/circle.cpp @@ -16,6 +16,7 @@ #include "circle.h" #include +#include "geometry.h" #include "painter.h" @@ -53,6 +54,28 @@ Circle::~Circle() if (state == OSSelected && draggingEdge && objectWasDragged) painter->DrawHandle(dragPoint); + + // If resizing the circle, draw an information panel showing the new radius. + if (draggingEdge) + { + 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))); + QRectF textRect(10.0, 10.0, 270.0, 70.0); // x, y, w, h + painter->DrawRoundedRect(textRect, 7.0, 7.0); + + textRect.setLeft(textRect.left() + 14); + painter->SetFont(*Object::font); + pen = QPen(QColor(0x00, 0x5F, 0xDF)); + painter->SetPen(pen); + painter->DrawText(textRect, Qt::AlignVCenter, text); +#else + painter->DrawInformativeText(text); +#endif + } } @@ -64,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; @@ -76,6 +111,7 @@ Circle::~Circle() dragPoint = point; oldState = state; state = OSSelected; + oldRadius = radius; return true; } @@ -85,24 +121,42 @@ Circle::~Circle() } -/*virtual*/ void Circle::PointerMoved(Vector point) +/*virtual*/ bool Circle::PointerMoved(Vector point) { if (selectionInProgress) { // Check for whether or not the rect contains this circle - if (selection.normalized().contains(Extents())) +// if (selection.normalized().contains(Extents())) + if (selection.contains(Extents())) state = OSSelected; else state = OSInactive; - return; + return false; } +/* +Note that we can separate this out in the TLC, and it would probably make more sense +to do it there as then we can be assured that all hit testing is done before we do +any snapping. !!! FIX !!! +*/ // 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); + SaveHitState(); + bool hovered = HitTest(point); + needUpdate = HitStateChanged(); + + if (snapToGrid) + point = SnapPointToGrid(point); + + if (snapPointIsValid) + point = snapPoint; + objectWasDragged = (draggingEdge | draggingCenter); + if (objectWasDragged) + needUpdate = true; + if (draggingEdge) radius = Vector::Magnitude(point, position); else if (draggingCenter) @@ -110,6 +164,7 @@ Circle::~Circle() // Save this point so the rendering code knows where to draw the handle... dragPoint = point; + return hovered; } @@ -128,13 +183,13 @@ Circle::~Circle() /*virtual*/ bool Circle::HitTest(Point point) { - SaveState(); +// SaveHitState(); hitCenter = hitCircle = false; double length = Vector::Magnitude(position, point); //printf("Circle::length = %lf, radius = %lf\n", length, radius); //How to translate this into pixels from Document space??? -//Maybe we need to pass a scaling factor in here from the caller? That would make sense, as -//the caller knows about the zoom factor and all that good kinda crap +//Maybe we need to pass a scaling factor in here from the caller? That would make +//sense, as the caller knows about the zoom factor and all that good kinda crap /* 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, @@ -146,7 +201,16 @@ 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; + + // Make sure we don't try to snap to ourselves...! + if (!draggingCenter) + { + 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))) @@ -155,7 +219,8 @@ pointed at length with our on screen length. else if ((fabs(length - radius) * Painter::zoom) < 2.0) hitCircle = true; - return StateChanged(); +// return HitStateChanged(); + return (hitCenter || hitCircle ? true : false); } @@ -165,14 +230,14 @@ pointed at length with our on screen length. } -void Circle::SaveState(void) +void Circle::SaveHitState(void) { oldHitCenter = hitCenter; oldHitCircle = hitCircle; } -bool Circle::StateChanged(void) +bool Circle::HitStateChanged(void) { if ((hitCenter != oldHitCenter) || (hitCircle != oldHitCircle)) return true; @@ -183,6 +248,50 @@ bool Circle::StateChanged(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); +} + + +/*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); +} + + +/*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; }