X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fcircle.cpp;h=e73bcdc9607fb6dd209a088e87bfb5d696062a35;hb=11cff81f10ccca1b31288fce04d696e715b922b0;hp=0780f6258bc32f67a94e3d097a5a797f3d6094c1;hpb=e11a07565fe5ef3dfafbf9a933d7a1575e058867;p=architektonas diff --git a/src/circle.cpp b/src/circle.cpp index 0780f62..e73bcdc 100644 --- a/src/circle.cpp +++ b/src/circle.cpp @@ -22,6 +22,7 @@ Circle::Circle(Vector p1, double r, Object * p/*= NULL*/): Object(p1, p), radius(r), draggingEdge(false), draggingCenter(false), hitCenter(false), hitCircle(false) { + type = OTCircle; } @@ -52,6 +53,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 + } } @@ -67,6 +90,11 @@ Circle::~Circle() 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; @@ -75,6 +103,7 @@ Circle::~Circle() dragPoint = point; oldState = state; state = OSSelected; + oldRadius = radius; return true; } @@ -86,11 +115,28 @@ Circle::~Circle() /*virtual*/ void Circle::PointerMoved(Vector point) { + if (selectionInProgress) + { + // Check for whether or not the rect contains this circle +// if (selection.normalized().contains(Extents())) + if (selection.contains(Extents())) + state = OSSelected; + else + state = OSInactive; + + return; + } + // 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) @@ -114,9 +160,9 @@ Circle::~Circle() } -bool Circle::HitTest(Point point) +/*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); @@ -143,18 +189,25 @@ 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); } -void Circle::SaveState(void) +/*virtual*/ QRectF Circle::Extents(void) +{ + return QRectF(QPointF(position.x - radius, position.y - radius), QPointF(position.x + radius, position.y + radius)); +} + + +void Circle::SaveHitState(void) { oldHitCenter = hitCenter; oldHitCircle = hitCircle; } -bool Circle::StateChanged(void) +bool Circle::HitStateChanged(void) { if ((hitCenter != oldHitCenter) || (hitCircle != oldHitCircle)) return true; @@ -165,6 +218,22 @@ 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); }