src/drawingview.h \
src/drawcircleaction.h \
src/drawlineaction.h \
+ src/drawtextaction.h \
src/ellipse.h \
src/fileio.h \
src/generaltab.h \
src/object.h \
src/painter.h \
src/settingsdialog.h \
+ src/text.h \
src/vector.h
SOURCES = \
src/drawingview.cpp \
src/drawcircleaction.cpp \
src/drawlineaction.cpp \
+ src/drawtextaction.cpp \
src/ellipse.cpp \
src/fileio.cpp \
src/generaltab.cpp \
src/object.cpp \
src/painter.cpp \
src/settingsdialog.cpp \
+ src/text.cpp \
src/vector.cpp
// WHO WHEN WHAT
// --- ---------- ------------------------------------------------------------
// JLH 04/04/2011 Created this file, basic rendering
+// JLH 03/14/2013 Updated to new connection system
//
#include "dimension.h"
}
-#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)
{
}
{
// 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));
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? :-/
-*/
}
}
-#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);
}
-#if 0
-Vector Dimension::GetPoint1(void)
-{
- return position;
-}
-
-
-Vector Dimension::GetPoint2(void)
-{
- return endpoint;
-}
-#endif
-
-
void Dimension::FlipSides(void)
{
#if 0
{
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();
{
}
+
DrawLineAction::~DrawLineAction()
{
}
}
}
+
/*virtual*/ void DrawLineAction::MouseDown(Vector point)
{
if (state == FIRST_POINT)
p2 = point;
}
+
/*virtual*/ void DrawLineAction::MouseMoved(Vector point)
{
if (state == FIRST_POINT)
p2 = point;
}
+
/*virtual*/ void DrawLineAction::MouseReleased(void)
{
if (state == FIRST_POINT)
p1 = p2;
}
}
+
--- /dev/null
+// 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;
+ }
+}
+
--- /dev/null
+#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__
{
}
+
Line::~Line()
{
// Taking care of connections should be done by the Container, as we don't know
#endif
}
+
/*virtual*/ void Line::Draw(Painter * painter)
{
painter->SetPen(QPen(Qt::red, 2.0, Qt::DotLine));
return false;
}
+
/*virtual*/ void Line::PointerMoved(Vector point)
{
// Hit test tells us what we hit (if anything) through boolean variables. It
}
}
+
/*virtual*/ void Line::PointerReleased(void)
{
if (draggingHandle1 || draggingHandle2)
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)
}
-#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
{
}
// 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)
{
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)))
}
*/
-/*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;
-}
-
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);
--- /dev/null
+// 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"
+
--- /dev/null
+#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__