Fixed some transforms, move to 3d and quaternion math in progress...
[ne.git] / src / ui / element.h
blob0b9dfcaadfb32528361bf925bc8a0d9f3f1aa3b9
1 /************************************************************************
2 This file is part of NE.
4 NE is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 NE is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with NE. If not, see <http://www.gnu.org/licenses/>.
16 ************************************************************************/
18 #ifndef ELEMENT_H_
19 #define ELEMENT_H_
21 #include "resource/texturefactory.h"
22 #include "base/vec.h"
23 #include <vector>
24 #include <string>
26 class Element
28 public:
29 Element(const std::string &name)
30 : m_name(name), m_callback(0), m_r(1.0), m_g(1.0), m_b(1.0) {}
31 virtual ~Element() {}
33 virtual void draw() = 0;
35 virtual int run()
37 if (m_callback)
38 return m_callback(m_callback_data);
39 else
40 return 0;
43 inline void setCallback(int (*cb)(void*), void *data=0)
45 m_callback_data = data;
46 m_callback = cb;
49 virtual void addChild(Element *e)
51 m_children.push_back(e);
54 inline unsigned int numChildren() const
56 return m_children.size();
59 inline Element *child(unsigned int index)
61 return m_children[index];
64 inline void setPos(Vec3f p)
66 m_pos = p;
69 inline const Vec3f &getPos() const
71 return m_pos;
74 inline void setSize(Vec3f s)
76 m_size = s;
79 inline const Vec3f &getSize() const
81 return m_size;
84 inline const std::string &getName() const
86 return m_name;
89 inline void setColor(float r, float g, float b)
91 m_r = r;
92 m_g = g;
93 m_b = b;
96 protected:
97 void drawBackround() {}
99 std::string m_name;
101 void *m_callback_data;
102 int (*m_callback)(void*);
104 Vec3f m_pos;
105 Vec3f m_size;
107 float m_r, m_g, m_b;
109 std::vector<Element*> m_children;
112 #endif