]> Shamusworld >> Repos - architektonas/commitdiff
Initial stab at text object. Nonfunctional ATM.
authorShamus Hammons <jlhamm@acm.org>
Fri, 15 Mar 2013 04:41:22 +0000 (23:41 -0500)
committerShamus Hammons <jlhamm@acm.org>
Fri, 15 Mar 2013 04:41:22 +0000 (23:41 -0500)
architektonas.pro
src/dimension.cpp
src/dimension.h
src/drawlineaction.cpp
src/drawtextaction.cpp [new file with mode: 0644]
src/drawtextaction.h [new file with mode: 0644]
src/line.cpp
src/line.h
src/text.cpp [new file with mode: 0644]
src/text.h [new file with mode: 0644]

index 5287f4d47c5f5852e3583a0998da257d355c1d78..40ac752b5b5d6106a8f5a9532ffc4605d6731259 100644 (file)
@@ -52,6 +52,7 @@ HEADERS = \
        src/drawingview.h \
        src/drawcircleaction.h \
        src/drawlineaction.h \
+       src/drawtextaction.h \
        src/ellipse.h \
        src/fileio.h \
        src/generaltab.h \
@@ -61,6 +62,7 @@ HEADERS = \
        src/object.h \
        src/painter.h \
        src/settingsdialog.h \
+       src/text.h \
        src/vector.h
 
 SOURCES = \
@@ -75,6 +77,7 @@ SOURCES = \
        src/drawingview.cpp \
        src/drawcircleaction.cpp \
        src/drawlineaction.cpp \
+       src/drawtextaction.cpp \
        src/ellipse.cpp \
        src/fileio.cpp \
        src/generaltab.cpp \
@@ -83,5 +86,6 @@ SOURCES = \
        src/object.cpp \
        src/painter.cpp \
        src/settingsdialog.cpp \
+       src/text.cpp \
        src/vector.cpp
 
index d2aeaf699b84fdd4e109cd641cbf70d1ebd5fa1c..eb978fdb0cc50807782662b583ffdce1606d2d2a 100644 (file)
@@ -9,6 +9,7 @@
 // WHO  WHEN        WHAT
 // ---  ----------  ------------------------------------------------------------
 // JLH  04/04/2011  Created this file, basic rendering
+// JLH  03/14/2013  Updated to new connection system
 //
 
 #include "dimension.h"
@@ -26,23 +27,10 @@ Dimension::Dimension(Vector p1, Vector p2, DimensionType dt/*= DTLinear*/ ,Objec
 }
 
 
-#if 0
-// This is bad, p1 & p2 could be NULL, causing much consternation...
-Dimension::Dimension(Vector * p1, Vector * p2, DimensionType dt/*= DTLinear*/ , Object * p/*= NULL*/):
-       Object(*p1, p), endpoint(*p2),
-       dragging(false), draggingHandle1(false), draggingHandle2(false),
-       length(p2->Magnitude()), type(dt), point1(p1), point2(p2)
-{
-}
-#endif
-
-
 // This is bad, p1 & p2 could be NULL, causing much consternation...
 Dimension::Dimension(Connection p1, Connection p2, DimensionType dt/*= DTLinear*/ , Object * p/*= NULL*/):
-/*     Object(p1.object->GetPointForParameter(p1.t), p),
-       endpoint(p2.object->GetPointForParameter(p2.t)),*/
        dragging(false), draggingHandle1(false), draggingHandle2(false),
-       /*length(p2->Magnitude()),*/length(0), type(dt), point1(p1), point2(p2)
+       length(0), type(dt), point1(p1), point2(p2)
 {
 }
 
@@ -56,19 +44,11 @@ Dimension::~Dimension()
 {
        // If there are valid Vector pointers in here, use them to update the internal
        // positions. Otherwise, we just use the internal positions by default.
-#if 0
-       if (point1)
-               position = *point1;
-
-       if (point2)
-               endpoint = *point2;
-#else
        if (point1.object)
                position = point1.object->GetPointAtParameter(point1.t);
 
        if (point2.object)
                endpoint = point2.object->GetPointAtParameter(point2.t);
-#endif
 
        if (state == OSSelected)
                painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine));
@@ -107,50 +87,8 @@ Dimension::~Dimension()
        painter->SetFont(QFont("Arial", 10.0 * Painter::zoom * SCREEN_ZOOM));
        Vector v1((p1.x - p2.x) / 2.0, (p1.y - p2.y) / 2.0);
        Point ctr = p2 + v1;
-       // This is in pixels, which isn't even remotely correct... !!! FIX !!!
        QString dimText = QString("%1\"").arg(Vector(endpoint - position).Magnitude());
-//     int textWidth = QFontMetrics(painter->font()).width(dimText);
-//     int textHeight = QFontMetrics(painter->font()).height();
-#if 0
-//We have to do transformation voodoo to make the text come out readable and in correct orientation...
-//Some things to note here: if angle > 90 degrees, then we need to take the negative of the angle
-//for our text.
-painter->save();
-painter->translate(ctr.x, ctr.y);
-int yOffset = -8;
-//16 : printf("textHeight: %d\n", textHeight);
-
-//Fix text so it isn't upside down...
-if ((angle > PI * 0.5) && (angle < PI * 1.5))
-{
-       angle += PI;
-       yOffset = 18;
-}
-
-painter->rotate(angle * RADIANS_TO_DEGREES);
-painter->scale(1.0, -1.0);
-//painter->translate(-textWidth / 2, -24);
-//     painter->drawText(0, 0, textWidth, 20, Qt::AlignCenter, dimText);
-       // This version draws the y-coord from the baseline of the font
-       painter->DrawText(-textWidth / 2, yOffset, dimText);
-//painter->setPen(QPen(QColor(0xFF, 0x20, 0x20), 1.0, Qt::SolidLine));
-//painter->drawLine(20, 0, -20, 0);
-//painter->drawLine(0, 20, 0, -20);
-painter->restore();
-#else
-//     painter->DrawText(QRectF(QPointF(ctr.x, ctr.y), QPointF(ctr.x + textWidth, ctr.y + textHeight)), Qt::AlignVCenter, dimText);
-// Now that we've taken our own good advice, maybe we should have the painter class
-// do a nice abstracted text draw routine? :-)
        painter->DrawAngledText(ctr, angle, dimText);
-#endif
-
-/*
-All of the preceeding makes me think that rather than try to compensate for Qt's unbelieveably
-AWFUL decision to go with a wrong-handed graphics subsystem, it may be better to just stuff
-all of that crap into some kind of subclass that handles all the nastiness behind the scenes.
-I mean, really, all this crap just to get some proplerly rendered text on the screen? How
-retarded is that? :-/
-*/
 }
 
 
@@ -347,22 +285,6 @@ about keeping track of old states...
 }
 
 
-#if 0
-void Dimension::SetPoint1(Vector * v)
-{
-       point1 = v;
-       needUpdate = true;
-}
-
-
-void Dimension::SetPoint2(Vector * v)
-{
-       point2 = v;
-       needUpdate = true;
-}
-#endif
-
-
 /*virtual*/ void Dimension::Enumerate(FILE * file)
 {
        fprintf(file, "DIMENSION (%lf,%lf) (%lf,%lf) %i\n", position.x, position.y, endpoint.x, endpoint.y, type);
@@ -438,20 +360,6 @@ void Dimension::SetPoint2(Vector * v)
 }
 
 
-#if 0
-Vector Dimension::GetPoint1(void)
-{
-       return position;
-}
-
-
-Vector Dimension::GetPoint2(void)
-{
-       return endpoint;
-}
-#endif
-
-
 void Dimension::FlipSides(void)
 {
 #if 0
index be8e5c51a31eda8efea566c3b4439bbbdb32c9f8..2784e83bb3a9f8271844a03df89e1cf01e08aa15 100644 (file)
@@ -10,7 +10,6 @@ class Dimension: public Object
 {
        public:
                Dimension(Vector, Vector, DimensionType dt = DTLinear, Object * p = 0);
-//             Dimension(Vector *, Vector *, DimensionType dt = DTLinear, Object * p = 0);
                Dimension(Connection, Connection, DimensionType dt = DTLinear, Object * p = 0);
                ~Dimension();
 
index 780ad58a66c3fd49f9e563f3156aa3af29ffa98f..b0b992a3de7e1d077d2222087ecc40eb54464da3 100644 (file)
@@ -26,6 +26,7 @@ DrawLineAction::DrawLineAction(): state(0), line(NULL)
 {
 }
 
+
 DrawLineAction::~DrawLineAction()
 {
 }
@@ -47,6 +48,7 @@ DrawLineAction::~DrawLineAction()
        }
 }
 
+
 /*virtual*/ void DrawLineAction::MouseDown(Vector point)
 {
        if (state == FIRST_POINT)
@@ -55,6 +57,7 @@ DrawLineAction::~DrawLineAction()
                p2 = point;
 }
 
+
 /*virtual*/ void DrawLineAction::MouseMoved(Vector point)
 {
        if (state == FIRST_POINT)
@@ -63,6 +66,7 @@ DrawLineAction::~DrawLineAction()
                p2 = point;
 }
 
+
 /*virtual*/ void DrawLineAction::MouseReleased(void)
 {
        if (state == FIRST_POINT)
@@ -81,3 +85,4 @@ DrawLineAction::~DrawLineAction()
                p1 = p2;
        }
 }
+
diff --git a/src/drawtextaction.cpp b/src/drawtextaction.cpp
new file mode 100644 (file)
index 0000000..fafdf95
--- /dev/null
@@ -0,0 +1,87 @@
+// drawtextaction.cpp: Draw text object
+//
+// Part of the Architektonas Project
+// (C) 2011 Underground Software
+// See the README and GPLv3 files for licensing and warranty information
+//
+// JLH = James Hammons <jlhamm@acm.org>
+//
+// WHO  WHEN        WHAT
+// ---  ----------  ------------------------------------------------------------
+// JLH  03/14/2013  Created this file
+//
+
+#include "drawtextaction.h"
+#include "painter.h"
+#include "text.h"
+//#include "vector.h"
+
+
+#define FIRST_POINT 0
+#define NEXT_POINT 1
+
+
+DrawTextAction::DrawTextAction(): state(0), text(NULL)
+{
+}
+
+
+DrawTextAction::~DrawTextAction()
+{
+}
+
+
+/*virtual*/ void DrawTextAction::Draw(Painter * painter)
+{
+       painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine));
+
+       // I think stuff like crosshairs should be done in the DrawingView, tho
+       if (state == FIRST_POINT)
+       {
+               painter->DrawHandle(p1);
+       }
+       else
+       {
+//             painter->DrawLine(p1, p2);
+//             painter->DrawHandle(p2);
+       }
+}
+
+
+/*virtual*/ void DrawTextAction::MouseDown(Vector point)
+{
+       if (state == FIRST_POINT)
+               p1 = point;
+//     else
+//             p2 = point;
+}
+
+
+/*virtual*/ void DrawTextAction::MouseMoved(Vector point)
+{
+       if (state == FIRST_POINT)
+               p1 = point;
+//     else
+//             p2 = point;
+}
+
+
+/*virtual*/ void DrawTextAction::MouseReleased(void)
+{
+       if (state == FIRST_POINT)
+       {
+//             p2 = p1;
+               state = NEXT_POINT;
+       }
+       else if (state == NEXT_POINT)
+       {
+               // We create the new object here, and then pass it off to the
+               // DrawingView which stuffs it into the document.
+//             text = new Text(p1, p2);
+               // We don't need no stinkin' sentinels, when we have signals & slots!
+               emit ObjectReady(text);
+
+//             p1 = p2;
+       }
+}
+
diff --git a/src/drawtextaction.h b/src/drawtextaction.h
new file mode 100644 (file)
index 0000000..23c7c6a
--- /dev/null
@@ -0,0 +1,25 @@
+#ifndef __DRAWTEXTACTION_H__
+#define __DRAWTEXTACTION_H__
+
+#include "action.h"
+
+class Text;
+
+class DrawTextAction: public Action
+{
+       public:
+               DrawTextAction();
+               ~DrawTextAction();
+
+               virtual void Draw(Painter *);
+               virtual void MouseDown(Vector);
+               virtual void MouseMoved(Vector);
+               virtual void MouseReleased(void);
+
+       private:
+               int state;
+               Text * text;
+               Vector p1;
+};
+
+#endif // __DRAWTEXTACTION_H__
index 244af94a8e0d887fa855b73d8e7c204fcd4309ea..d37106e5a7846df0f9fe8fabed88aee129ea42c5 100644 (file)
@@ -30,6 +30,7 @@ Line::Line(Vector p1, Vector p2, Object * p/*= NULL*/): Object(p1, p), endpoint(
 {
 }
 
+
 Line::~Line()
 {
 // Taking care of connections should be done by the Container, as we don't know
@@ -48,6 +49,7 @@ Line::~Line()
 #endif
 }
 
+
 /*virtual*/ void Line::Draw(Painter * painter)
 {
        painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine));
@@ -238,6 +240,7 @@ Like so:
        return false;
 }
 
+
 /*virtual*/ void Line::PointerMoved(Vector point)
 {
        // Hit test tells us what we hit (if anything) through boolean variables. It
@@ -335,6 +338,7 @@ the horizontal line or vertical line that intersects from the current mouse posi
        }
 }
 
+
 /*virtual*/ void Line::PointerReleased(void)
 {
        if (draggingHandle1 || draggingHandle2)
@@ -385,6 +389,7 @@ about keeping track of old states...
                state = oldState;
 }
 
+
 // Check to see if the point passed in coincides with any we have. If so, return a
 // pointer to it; otherwise, return NULL.
 /*virtual*/ Vector * Line::GetPointAt(Vector v)
@@ -398,37 +403,63 @@ about keeping track of old states...
 }
 
 
-#if 0
-void Line::SetDimensionOnPoint1(Dimension * dimension)
+/*virtual*/ void Line::Enumerate(FILE * file)
 {
-       dimPoint1 = dimension;
+       fprintf(file, "LINE (%lf,%lf) (%lf,%lf)\n", position.x, position.y, endpoint.x, endpoint.y);
+}
+
 
-       if (dimension)
-               dimension->SetPoint1(position);
+/*virtual*/ Object * Line::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 Line(position, endpoint, parent);
 }
 
-void Line::SetDimensionOnPoint2(Dimension * dimension)
+
+/*virtual*/ Vector Line::GetPointAtParameter(double parameter)
 {
-       dimPoint2 = dimension;
+       if (parameter <= 0)
+               return position;
+       else if (parameter >= 1.0)
+               return endpoint;
+
+       // Our parameter lies between zero and one, so calculate it!
+       Vector v(endpoint, position);
+       double length = v.Magnitude();
+       // We scale the magnitude of v so that it lies between 0 and 1...
+       // By multiplying the parameter by the magnitude, we obtain the point we
+       // want. No scaling necessary as it's inherent in the approach!
+       double spotOnLength = length * parameter;
 
-       if (dimension)
-               dimension->SetPoint2(endpoint);
+       // To get our point, we use the initial point of the line and add in our
+       // scaled point.
+       Vector result = position + (v * spotOnLength);
+       return result;
 }
-#else
+
+
 void Line::SetDimensionOnLine(Dimension * dimension/*=NULL*/)
 {
        // If they don't pass one in, create it for the caller.
        if (dimension == NULL)
        {
-printf("Line::SetDimensionOnLine(): Creating new dimension...\n");
+//printf("Line::SetDimensionOnLine(): Creating new dimension...\n");
 //             dimension = new Dimension(position, endpoint, DTLinear, this);
                dimension = new Dimension(Connection(this, 0), Connection(this, 1.0), DTLinear, this);
 
                if (parent)
-{
-printf("Line::SetDimensionOnLine(): Adding to parent...\n");
+//{
+//printf("Line::SetDimensionOnLine(): Adding to parent...\n");
                        parent->Add(dimension);
-}
+//}
        }
        else
        {
@@ -437,26 +468,9 @@ printf("Line::SetDimensionOnLine(): Adding to parent...\n");
        }
 
        // Make sure the Dimension is connected to us...
-#if 0
-       connected.push_back(Connection(dimension, 0));
-       connected.push_back(Connection(dimension, 1.0));
-#else
        Connect(dimension, 0);
        Connect(dimension, 1.0);
-#endif
-
-//     attachedDimension = dimension;
-
-#if 0
-       // After we set the points here, we don't have to care about them anymore.
-       if (dimension)
-       {
-               dimension->SetPoint1(&position);
-               dimension->SetPoint2(&endpoint);
-       }
-#endif
 }
-#endif
 
 
 Object * Line::FindAttachedDimension(void)
@@ -472,7 +486,7 @@ Object * Line::FindAttachedDimension(void)
        {
                for(uint j=i+1; j<connected.size(); j++)
                {
-printf("Line: connected[i]=%X, connected[j]=%X, connected[i].t=%lf, connected[j].t=%lf\n", connected[i].object, connected[j].object, connected[i].t, connected[j].t);
+//printf("Line: connected[i]=%X, connected[j]=%X, connected[i].t=%lf, connected[j].t=%lf\n", connected[i].object, connected[j].object, connected[i].t, connected[j].t);
                        if ((connected[i].object == connected[j].object)
                                && ((connected[i].t == 0 && connected[j].t == 1.0)
                                || (connected[i].t == 1.0 && connected[j].t == 0)))
@@ -654,45 +668,3 @@ else
 }
 */
 
-/*virtual*/ void Line::Enumerate(FILE * file)
-{
-       fprintf(file, "LINE (%lf,%lf) (%lf,%lf)\n", position.x, position.y, endpoint.x, endpoint.y);
-}
-
-
-/*virtual*/ Object * Line::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 Line(position, endpoint, parent);
-}
-
-
-/*virtual*/ Vector Line::GetPointAtParameter(double parameter)
-{
-       if (parameter <= 0)
-               return position;
-       else if (parameter >= 1.0)
-               return endpoint;
-
-       // Our parameter lies between zero and one, so calculate it!
-       Vector v(endpoint, position);
-       double length = v.Magnitude();
-       // We scale the magnitude of v so that it lies between 0 and 1...
-       // By multiplying the parameter by the magnitude, we obtain the point we
-       // want. No scaling necessary as it's inherent in the approach!
-       double spotOnLength = length * parameter;
-
-       // To get our point, we use the initial point of the line and add in our
-       // scaled point.
-       Vector result = position + (v * spotOnLength);
-       return result;
-}
-
index e9b73c79d273f95599cff453306b1b8813900810..b7d32f20a98ba5ea319ceb676f50244cfcdc1eb1 100644 (file)
@@ -20,8 +20,6 @@ class Line: public Object
                virtual void Enumerate(FILE *);
                virtual Object * Copy(void);
                virtual Vector GetPointAtParameter(double parameter);
-//             void SetDimensionOnPoint1(Dimension *);
-//             void SetDimensionOnPoint2(Dimension *);
                void SetDimensionOnLine(Dimension * d = 0);
                Object * FindAttachedDimension(void);
 
diff --git a/src/text.cpp b/src/text.cpp
new file mode 100644 (file)
index 0000000..af34ea2
--- /dev/null
@@ -0,0 +1,15 @@
+// text.cpp: Draw text object
+//
+// Part of the Architektonas Project
+// (C) 2011 Underground Software
+// See the README and GPLv3 files for licensing and warranty information
+//
+// JLH = James Hammons <jlhamm@acm.org>
+//
+// WHO  WHEN        WHAT
+// ---  ----------  ------------------------------------------------------------
+// JLH  03/14/2013  Created this file
+//
+
+#include "text.h"
+
diff --git a/src/text.h b/src/text.h
new file mode 100644 (file)
index 0000000..351a1a1
--- /dev/null
@@ -0,0 +1,32 @@
+#ifndef __TEXT_H__
+#define __TEXT_H__
+
+#include "object.h"
+#include <QtGui>
+
+class Text: public Object
+{
+       public:
+               Text(Vector, QString, Object * p = 0);
+               ~Text();
+
+               virtual void Draw(Painter *);
+               virtual Vector Center(void);
+               virtual bool Collided(Vector);
+               virtual void PointerMoved(Vector);
+               virtual void PointerReleased(void);
+               virtual void Enumerate(FILE *);
+//             virtual Object * Copy(void);
+               virtual Vector GetPointAtParameter(double parameter);
+
+       protected:
+               Vector oldPoint;                                        // Used for dragging
+
+       private:
+               bool dragging;
+               bool draggingHandle1;
+               bool draggingHandle2;
+               bool objectWasDragged;
+};
+
+#endif // __TEXT_H__