]> Shamusworld >> Repos - architektonas/blob - src/object.cpp
Initial stab at proper grid display using background image.
[architektonas] / src / object.cpp
1 //
2 // object.cpp: Base class for all CAD objects
3 //
4 // Part of the Architektonas Project
5 // (C) 2011 Underground Software
6 // See the README and GPLv3 files for licensing and warranty information
7 //
8 // JLH = James Hammons <jlhamm@acm.org>
9 //
10 // WHO  WHEN        WHAT
11 // ---  ----------  ------------------------------------------------------------
12 // JLH  03/22/2011  Created this file
13 // JLH  04/01/2011  Added constructor to allow derived objects to have empty
14 //                  constructor bodies, added state querying
15 // JLH  04/02/2001  Added static methods for global states (fixed angle, etc)
16 //
17
18 #include "object.h"
19
20 // Initialize static variables
21 bool Object::fixedAngle = false;
22 bool Object::fixedLength = false;
23 QFont * Object::font = 0;
24 int Object::viewportHeight = 0;
25 bool Object::deleteActive = false;
26 bool Object::dimensionActive = false;
27 bool Object::snapToGrid = true;
28
29
30 Object::Object(): position(Vector(0, 0)), parent(0), state(OSInactive), oldState(OSInactive),
31         needUpdate(false), attachedDimension(0)
32 {
33 }
34
35 Object::Object(Vector v,  Object * passedInParent/*= 0*/): position(v), parent(passedInParent),
36         state(OSInactive), oldState(OSInactive), needUpdate(false), attachedDimension(0)
37 {
38 }
39
40 Object::~Object()
41 {
42 }
43
44 /*virtual*/ void Object::Draw(Painter *)
45 {
46 }
47
48 /*virtual*/ Vector Object::Center(void)
49 {
50         return Vector();
51 }
52
53 /*virtual*/ bool Object::Collided(Vector)
54 {
55         return false;
56 }
57
58 /*virtual*/ void Object::PointerMoved(Vector)
59 {
60 }
61
62 /*virtual*/ void Object::PointerReleased(void)
63 {
64 }
65
66 /*virtual*/ bool Object::NeedsUpdate(void)
67 {
68         return needUpdate;
69 }
70
71 // This is intended to be overridden by the Container class, for object morphing
72 /*virtual*/ void Object::Transmute(Object *, Object *)
73 {
74 }
75
76 /*virtual*/ Object * Object::GetParent(void)
77 {
78         return parent;
79 }
80
81 /*virtual*/ void Object::Add(Object *)
82 {
83 }
84
85 ObjectState Object::GetState(void)
86 {
87         return state;
88 }
89
90 void Object::Reparent(Object * newParent)
91 {
92         parent = newParent;
93 }
94
95 // Class methods...
96
97 void Object::SetFixedAngle(bool state/*= true*/)
98 {
99         fixedAngle = state;
100 }
101
102 void Object::SetFixedLength(bool state/*= true*/)
103 {
104         fixedLength = state;
105 }
106
107 void Object::SetFont(QFont * f)
108 {
109         font = f;
110 }
111
112 void Object::SetViewportHeight(int height)
113 {
114         viewportHeight = height;
115 }
116
117 void Object::SetDeleteActive(bool state/*= true*/)
118 {
119         deleteActive = state;
120 }
121
122 void Object::SetDimensionActive(bool state/*= true*/)
123 {
124         dimensionActive = state;
125 }
126
127 void Object::SetSnapMode(bool state/*= true*/)
128 {
129         snapToGrid = state;
130 }