+// drawlineaction.cpp: Action class for drawing lines
+//
+// Part of the Architektonas Project
+// (C) 2011 Underground Software
+// See the README and GPLv3 files for licensing and warranty information
+//
+// JLH = James L. Hammons <jlhamm@acm.org>
+//
+// WHO WHEN WHAT
+// --- ---------- ------------------------------------------------------------
+// JLH 10/04/2011 Created this file
+// JLH 11/07/2011 Made it so this class actually does something ;-)
+//
+
+#include "drawlineaction.h"
+#include "line.h"
+#include "painter.h"
+//#include "vector.h"
+
+
+#define FIRST_POINT 0
+#define NEXT_POINT 1
+
+
+DrawLineAction::DrawLineAction(): state(0), line(NULL)
+{
+}
+
+DrawLineAction::~DrawLineAction()
+{
+}
+
+
+/*virtual*/ void DrawLineAction::Draw(Painter * painter)
+{
+ // Need to fix pen colors, etc...
+ if (state == FIRST_POINT)
+ {
+ painter->DrawPoint(p1.x, p1.y);
+ }
+ else
+ {
+ painter->DrawLine(p1, p2);
+ }
+}
+
+/*virtual*/ void DrawLineAction::MouseDown(Vector point)
+{
+ if (state == FIRST_POINT)
+ p1 = point;
+ else
+ p2 = point;
+}
+
+/*virtual*/ void DrawLineAction::MouseMoved(Vector point)
+{
+ if (state == FIRST_POINT)
+ p1 = point;
+ else
+ p2 = point;
+}
+
+/*virtual*/ void DrawLineAction::MouseReleased(void)
+{
+ if (state == FIRST_POINT)
+ state = NEXT_POINT;
+ else if (state == NEXT_POINT)
+ {
+ // We create the new object here, and then pass it off to the document.
+ line = new Line(p1, p2);
+ // We don't need no stinkin' sentinels, when we have signals & slots!
+ emit ObjectReady(line);
+
+ p1 = p2;
+ }
+}