]> Shamusworld >> Repos - architektonas/blob - src/drawcircleaction.cpp
Added action for adding circles to the drawing.
[architektonas] / src / drawcircleaction.cpp
1 // drawcircleaction.cpp: Action class for drawing circles
2 //
3 // Part of the Architektonas Project
4 // (C) 2012 Underground Software
5 // See the README and GPLv3 files for licensing and warranty information
6 //
7 // JLH = James Hammons <jlhamm@acm.org>
8 //
9 // WHO  WHEN        WHAT
10 // ---  ----------  ------------------------------------------------------------
11 // JLH  02/01/2012  Created this file
12 //
13
14 #include "drawcircleaction.h"
15 #include "circle.h"
16 #include "painter.h"
17 #include "vector.h"
18
19
20 #define FIRST_POINT 0
21 #define NEXT_POINT 1
22
23
24 DrawCircleAction::DrawCircleAction(): state(0), circle(NULL)
25 {
26 }
27
28 DrawCircleAction::~DrawCircleAction()
29 {
30 }
31
32
33 /*virtual*/ void DrawCircleAction::Draw(Painter * painter)
34 {
35         // Need to fix pen colors, etc...
36         // I think stuff like crosshairs should be done in the DrawingView, tho
37         if (state == FIRST_POINT)
38         {
39                 painter->DrawPoint(p1.x, p1.y);
40         }
41         else
42         {
43                 double radius = Vector::Magnitude(p1, p2);
44                 painter->DrawEllipse(p1, radius, radius);
45         }
46 }
47
48 /*virtual*/ void DrawCircleAction::MouseDown(Vector point)
49 {
50         if (state == FIRST_POINT)
51                 p1 = point;
52         else
53                 p2 = point;
54 }
55
56 /*virtual*/ void DrawCircleAction::MouseMoved(Vector point)
57 {
58         if (state == FIRST_POINT)
59                 p1 = point;
60         else
61                 p2 = point;
62 }
63
64 /*virtual*/ void DrawCircleAction::MouseReleased(void)
65 {
66         if (state == FIRST_POINT)
67         {
68                 p2 = p1;
69                 state = NEXT_POINT;
70         }
71         else if (state == NEXT_POINT)
72         {
73                 // We create the new object here, and then pass it off to the
74                 // DrawingView which stuffs it into the document.
75                 circle = new Circle(p1, Vector::Magnitude(p1, p2));
76                 // We don't need no stinkin' sentinels, when we have signals & slots!
77                 emit ObjectReady(circle);
78
79                 state = FIRST_POINT;
80                 p1 = p2;
81         }
82 }