X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fcircle.cpp;h=d8a2e5d61bda7faa31c349546a7b94c79d0771c1;hb=c58b8a9f8b1ae5494857fc423ed8e33b2bbcf329;hp=77ea95a6290e5ca87dbe8ba9477bac561fce7bef;hpb=89b8b0c60579d8ef0cf9a13521e7bf7c7864883f;p=architektonas diff --git a/src/circle.cpp b/src/circle.cpp index 77ea95a..d8a2e5d 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,19 @@ 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); + draggingCenter = hitCenter; draggingEdge = hitCircle; @@ -76,6 +108,7 @@ Circle::~Circle() dragPoint = point; oldState = state; state = OSSelected; + oldRadius = radius; return true; } @@ -90,7 +123,8 @@ Circle::~Circle() 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; @@ -100,9 +134,14 @@ Circle::~Circle() // 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(); + HitTest(point); + needUpdate = HitStateChanged(); objectWasDragged = (draggingEdge | draggingCenter); + if (objectWasDragged) + needUpdate = true; + if (draggingEdge) radius = Vector::Magnitude(point, position); else if (draggingCenter) @@ -128,7 +167,7 @@ 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); @@ -155,7 +194,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 +205,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,7 +223,7 @@ 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); } @@ -202,3 +242,32 @@ 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); +// return new Circle(c1, radius); + position = c1; +} + + +/*virtual*/ void Circle::Save(void) +{ + Object::Save(); + oldRadius2 = radius; +} + + +/*virtual*/ void Circle::Restore(void) +{ + Object::Restore(); + radius = oldRadius2; +} +