]> Shamusworld >> Repos - architektonas/blob - src/drawlineaction.cpp
Preliminary Add Line tool work...
[architektonas] / src / drawlineaction.cpp
1 // drawlineaction.cpp: Action class for drawing lines
2 //
3 // Part of the Architektonas Project
4 // (C) 2011 Underground Software
5 // See the README and GPLv3 files for licensing and warranty information
6 //
7 // JLH = James L. Hammons <jlhamm@acm.org>
8 //
9 // WHO  WHEN        WHAT
10 // ---  ----------  ------------------------------------------------------------
11 // JLH  10/04/2011  Created this file
12 // JLH  11/07/2011  Made it so this class actually does something ;-)
13 //
14
15 #include "drawlineaction.h"
16 #include "line.h"
17 #include "painter.h"
18 //#include "vector.h"
19
20
21 #define FIRST_POINT 0
22 #define NEXT_POINT 1
23
24
25 DrawLineAction::DrawLineAction(): state(0), line(NULL)
26 {
27 }
28
29 DrawLineAction::~DrawLineAction()
30 {
31 }
32
33
34 /*virtual*/ void DrawLineAction::Draw(Painter * painter)
35 {
36         // Need to fix pen colors, etc...
37         if (state == FIRST_POINT)
38         {
39                 painter->DrawPoint(p1.x, p1.y);
40         }
41         else
42         {
43                 painter->DrawLine(p1, p2);
44         }
45 }
46
47 /*virtual*/ void DrawLineAction::MouseDown(Vector point)
48 {
49         if (state == FIRST_POINT)
50                 p1 = point;
51         else
52                 p2 = point;
53 }
54
55 /*virtual*/ void DrawLineAction::MouseMoved(Vector point)
56 {
57         if (state == FIRST_POINT)
58                 p1 = point;
59         else
60                 p2 = point;
61 }
62
63 /*virtual*/ void DrawLineAction::MouseReleased(void)
64 {
65         if (state == FIRST_POINT)
66                 state = NEXT_POINT;
67         else if (state == NEXT_POINT)
68         {
69                 // We create the new object here, and then pass it off to the document.
70                 line = new Line(p1, p2);
71                 // We don't need no stinkin' sentinels, when we have signals & slots!
72                 emit ObjectReady(line);
73                 
74                 p1 = p2;
75         }
76 }