Initial commit, includes Lua with broken Luabind as a backup for branching purposes
[terrastrategy.git] / include / gui / basic.h
blob85ec5c54a229e1f80c6dc19c1fe2e2bfa7833bad
1 //
2 // Copyright (C) 2008 by Martin Moracek
3 //
4 // This program 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 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program 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 this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 /**
20 * @file basic.h
22 * Provides collection of basic widgets.
25 #pragma once
27 #include <boost/signals/connection.hpp>
29 #include "gui.h"
30 #include "widget.h"
31 #include "pixmap.h"
32 #include "richtext.h"
33 #include "plaintext.h"
35 namespace tre {
38 * Abstract widgets
40 class AbstractStatic : virtual public Widget {
41 public:
42 AbstractStatic(Gui & g, Widget * p);
44 void OnMouseEnter(void) {}
45 void OnMouseExit(void) {}
48 class AbstractButton : virtual public Widget {
49 public:
50 // public signals
51 boost::signal<void (void)> clicked;
53 public:
54 AbstractButton(Gui & g, Widget * p);
56 void OnMouseEnter(void);
57 void OnMouseExit(void);
59 private:
60 // slots
61 class OnButtonPressed;
62 class OnButtonReleased;
64 // connections
65 boost::signals::connection buttonCon1;
66 boost::signals::connection buttonCon2;
69 class AbstractEdit : virtual public Widget {
70 public:
71 AbstractEdit(Gui & g, Widget * p);
73 void OnMouseEnter(void);
75 private:
76 // slots
77 class OnButtonPressed;
78 class OnKeyPressed;
80 // connections
81 boost::signals::connection buttonCon;
82 boost::signals::connection keyCon;
84 private:
85 virtual void InsertCharacter(wchar_t chr) = 0;
89 * Static text widget (without frame-like parent)
91 class StaticText : public Widget {
92 public:
93 static Widget * CreateWidget(Gui & gui, Widget * parent);
95 public:
96 PlainText text;
98 public:
99 StaticText(Gui & g, Widget * p);
101 void OnMouseEnter(void) {}
102 void OnMouseExit(void) {}
103 void OnGuiResize(const Vector2f & scale);
105 void Draw(void);
106 void LoadFromXml(TiXmlElement & root);
109 class StaticRichText : public Widget {
110 public:
111 static Widget * CreateWidget(Gui & gui, Widget * parent);
113 public:
114 RichText text;
116 public:
117 StaticRichText(Gui & g, Widget * p);
119 void OnMouseEnter(void) {}
120 void OnMouseExit(void) {}
121 void OnGuiResize(const Vector2f & scale);
123 void Draw(void);
124 void LoadFromXml(TiXmlElement & root);
128 * Parent class for most pixmap based widgets
130 class PixmapWidget : virtual public Widget, private boost::noncopyable {
131 public:
132 PixmapWidget(Pixmap * pix) : pixmap_(pix) {}
133 ~PixmapWidget();
135 void OnGuiResize(const Vector2f & scale);
137 void SetSize(const Vector2f & sz);
138 void Draw(void);
140 protected:
141 Pixmap * pixmap_;
143 protected:
144 void SetState(uint u, WidgetState w);
148 * Basic widgets
150 class Frame : public AbstractStatic, public PixmapWidget {
151 public:
152 static Widget * CreateWidget(Gui & gui, Widget * parent);
154 public:
155 Frame(Gui & g, Widget * p);
157 void LoadFromXml(TiXmlElement & root);
160 class FrameRaised : public Frame {
161 public:
162 static Widget * CreateWidget(Gui & gui, Widget * parent);
164 public:
165 FrameRaised(Gui & g, Widget * p) : Frame(g, p) {}
167 void LoadFromXml(TiXmlElement & root);
170 class FrameSunken : public Frame {
171 public:
172 static Widget * CreateWidget(Gui & gui, Widget * parent);
174 public:
175 FrameSunken(Gui & g, Widget * p) : Frame(g, p) {}
177 void LoadFromXml(TiXmlElement & root);
180 // class StaticLine : public Pixmap2x1L {
181 // public:
182 // StaticLine(Gui & g, Widget * p);
183 // StaticLine(Gui & g, Widget * p, Mesh & pm);
185 // void LoadFromXml(TiXmlElement & root);
186 // };
188 class PushButton : public AbstractButton, public PixmapWidget {
189 public:
190 static Widget * CreateWidget(Gui & gui, Widget * parent);
192 public:
193 PushButton(Gui & g, Widget * p);
195 void OnGuiResize(const Vector2f & scale);
197 const std::wstring GetCaption(void) const {return caption_.GetText();}
198 void SetCaption(const std::string & text) {caption_.SetText(text);}
200 void SetSize(const Vector2f & sz);
201 void Draw(void);
202 void LoadFromXml(TiXmlElement & root);
204 private:
205 class EventBinder;
207 private:
208 PlainText caption_;
211 // class EditBox : public Pixmap3x1 {
212 // public:
213 // EditBox(Gui & g, Widget * p);
214 // EditBox(Gui & g, Widget * p, Mesh & pm);
216 // void LoadFromXml(TiXmlElement & root);
217 // };
219 // class CheckBox : public Pixmap1x1 {
220 // public:
221 // CheckBox(Gui & g, Widget * p);
222 // CheckBox(Gui & g, Widget * p, Mesh & pm);
224 // void LoadFromXml(TiXmlElement & root);
225 // };
227 // class RadioButton : public Pixmap1x1 {
228 // public:
229 // RadioButton(Gui & g, Widget * p);
230 // RadioButton(Gui & g, Widget * p, Mesh & pm);
232 // void LoadFromXml(TiXmlElement & root);
233 // };
235 // class DropDownList : public Pixmap3x1 {
236 // public:
237 // DropDownList(Gui & g, Widget * p);
238 // DropDownList(Gui & g, Widget * p, Mesh & pm);
240 // void LoadFromXml(TiXmlElement & root);
241 // };
243 // class ListBox : public Widget {
244 // };
246 // class TabWidget : public Widget {
247 // };
249 // class Window : public Widget {
250 // };
252 // class RenderView : public Widget {
253 // };