Debian Codegraph @

engine/include/widgets.h

raw
1 // ____ _ __
2 // / __ )____ _____ | | / /___ ___________
3 // / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/
4 // / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ )
5 // /_____/\____/____/ |__/|__/\__,_/_/ /____/
6 //
7 // A futuristic real-time strategy game.
8 // This file is part of Bos Wars.
9 //
10 /**@name widgets.h - The widgets headerfile. */
11 //
12 // (c) Copyright 2005-2008 by Francois Beerten and Jimmy Salmon
13 //
14 // This program is free software; you can redistribute it and/or modify
15 // it under the terms of the GNU General Public License as published by
16 // the Free Software Foundation; only version 2 of the License.
17 //
18 // This program is distributed in the hope that it will be useful,
19 // but WITHOUT ANY WARRANTY; without even the implied warranty of
20 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 // GNU General Public License for more details.
22 //
23 // You should have received a copy of the GNU General Public License
24 // along with this program; if not, write to the Free Software
25 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
26 // 02111-1307, USA.
27
28 #ifndef __WIDGETS_H__
29 #define __WIDGETS_H__
30
31 #include <guichan.h>
32 #include <guichan/gsdl.h>
33 #include "font.h"
34 #include "luacallback.h"
35
36
37 extern bool GuichanActive;
38
39 void initGuichan();
40 void freeGuichan();
41 void handleInput(const SDL_Event *event);
42
43 class LuaActionListener : public gcn::ActionListener
44 {
45 LuaCallback callback;
46 public:
47 LuaActionListener(lua_State *lua, lua_Object function);
48 virtual void action(const std::string &eventId);
49 virtual ~LuaActionListener();
50 };
51
52 class MyOpenGLGraphics : public gcn::Graphics
53 {
54 public:
55 virtual void _beginDraw();
56 virtual void _endDraw();
57
58 virtual void drawImage(const gcn::Image *image, int srcX, int srcY,
59 int dstX, int dstY, int width, int height);
60
61 virtual void drawPoint(int x, int y);
62 virtual void drawLine(int x1, int y1, int x2, int y2);
63 virtual void drawRectangle(const gcn::Rectangle &rectangle);
64 virtual void fillRectangle(const gcn::Rectangle &rectangle);
65
66 virtual void setColor(const gcn::Color &color) { mColor = color; }
67 virtual const gcn::Color &getColor() { return mColor; }
68
69 private:
70 gcn::Color mColor;
71 };
72
73 class ImageWidget : public gcn::Icon
74 {
75 public:
76 ImageWidget(gcn::Image *img) : gcn::Icon(img) {}
77 };
78
79 class ButtonWidget : public gcn::Button
80 {
81 public:
82 ButtonWidget(const std::string &caption) : Button(caption)
83 {
84 this->setHotKey(GetHotKey(caption));
85 }
86 };
87
88 class ImageButton : public gcn::Button
89 {
90 public:
91 ImageButton();
92 ImageButton(const std::string &caption);
93
94 virtual void draw(gcn::Graphics *graphics);
95 virtual void adjustSize();
96
97 void setNormalImage(gcn::Image *image) { normalImage = image; adjustSize(); }
98 void setPressedImage(gcn::Image *image) { pressedImage = image; }
99 void setDisabledImage(gcn::Image *image) { disabledImage = image; }
100
101 gcn::Image *normalImage;
102 gcn::Image *pressedImage;
103 gcn::Image *disabledImage;
104 };
105
106 class ImageRadioButton : public gcn::RadioButton
107 {
108 public:
109 ImageRadioButton();
110 ImageRadioButton(const std::string &caption, const std::string &group,
111 bool marked);
112
113 virtual void drawBox(gcn::Graphics *graphics);
114 virtual void draw(gcn::Graphics *graphics);
115
116 virtual void mousePress(int x, int y, int button);
117 virtual void mouseRelease(int x, int y, int button);
118 virtual void mouseClick(int x, int y, int button, int count);
119 virtual void adjustSize();
120
121 void setUncheckedNormalImage(gcn::Image *image) { uncheckedNormalImage = image; }
122 void setUncheckedPressedImage(gcn::Image *image) { uncheckedPressedImage = image; }
123 void setCheckedNormalImage(gcn::Image *image) { checkedNormalImage = image; }
124 void setCheckedPressedImage(gcn::Image *image) { checkedPressedImage = image; }
125
126 gcn::Image *uncheckedNormalImage;
127 gcn::Image *uncheckedPressedImage;
128 gcn::Image *checkedNormalImage;
129 gcn::Image *checkedPressedImage;
130 bool mMouseDown;
131 };
132
133 class ImageCheckBox : public gcn::CheckBox
134 {
135 public:
136 ImageCheckBox();
137 ImageCheckBox(const std::string &caption, bool marked = false);
138
139 virtual void draw(gcn::Graphics *graphics);
140 virtual void drawBox(gcn::Graphics *graphics);
141
142 virtual void mousePress(int x, int y, int button);
143 virtual void mouseRelease(int x, int y, int button);
144 virtual void mouseClick(int x, int y, int button, int count);
145 virtual void adjustSize();
146
147 void setUncheckedNormalImage(gcn::Image *image) { uncheckedNormalImage = image; }
148 void setUncheckedPressedImage(gcn::Image *image) { uncheckedPressedImage = image; }
149 void setCheckedNormalImage(gcn::Image *image) { checkedNormalImage = image; }
150 void setCheckedPressedImage(gcn::Image *image) { checkedPressedImage = image; }
151
152 gcn::Image *uncheckedNormalImage;
153 gcn::Image *uncheckedPressedImage;
154 gcn::Image *checkedNormalImage;
155 gcn::Image *checkedPressedImage;
156 bool mMouseDown;
157 };
158
159 class ImageSlider : public gcn::Slider
160 {
161 public:
162 ImageSlider(double scaleEnd = 1.0);
163 ImageSlider(double scaleStart, double scaleEnd);
164
165 virtual void drawMarker(gcn::Graphics* graphics);
166 virtual void draw(gcn::Graphics* graphics);
167
168 void setMarkerImage(gcn::Image *image);
169 void setBackgroundImage(gcn::Image *image);
170
171 gcn::Image *markerImage;
172 gcn::Image *backgroundImage;
173 };
174
175 class MultiLineLabel : public gcn::Widget
176 {
177 public:
178 MultiLineLabel();
179 MultiLineLabel(const std::string &caption);
180
181 virtual void setCaption(const std::string &caption);
182 virtual const std::string &getCaption() const;
183 virtual void setAlignment(unsigned int alignment);
184 virtual unsigned int getAlignment();
185 virtual void setVerticalAlignment(unsigned int alignment);
186 virtual unsigned int getVerticalAlignment();
187 virtual void setLineWidth(int width);
188 virtual int getLineWidth();
189 virtual void adjustSize();
190 virtual void draw(gcn::Graphics *graphics);
191 virtual void drawBorder(gcn::Graphics *graphics);
192
193 enum {
194 LEFT = 0,
195 CENTER,
196 RIGHT,
197 TOP,
198 BOTTOM
199 };
200
201 private:
202 void wordWrap();
203
204 std::string mCaption;
205 std::vector<std::string> mTextRows;
206 unsigned int mAlignment;
207 unsigned int mVerticalAlignment;
208 int mLineWidth;
209 };
210
211 class ScrollingWidget : public gcn::ScrollArea
212 {
213 public:
214 ScrollingWidget(int width, int height);
215 void add(gcn::Widget *widget, int x, int y);
216 void restart();
217 void setSpeed(float speed) { this->speedY = speed; }
218 float getSpeed() { return this->speedY; }
219 private:
220 virtual void logic();
221 private:
222 gcn::Container container; /// Data container
223 float speedY; /// vertical speed of the container (positive number: go up).
224 float containerY; /// Y position of the container
225 bool finished; /// True while scrolling ends.
226 };
227
228 class Windows : public gcn::Window
229 {
230 public:
231 Windows(const std::string &text, int width, int height);
232 void add(gcn::Widget *widget, int x, int y);
233 private:
234 virtual void mouseMotion(int x, int y);
235 virtual void setBackgroundColor(const gcn::Color &color);
236 virtual void setBaseColor(const gcn::Color &color);
237 private:
238 gcn::ScrollArea scroll; /// To use scroll bar.
239 gcn::Container container; /// data container.
240 bool blockwholewindow; /// Manage condition limit of moveable windows. @see mouseMotion.
241 /// @todo Method to set this variable. Maybe set the variable static.
242 };
243
244 class StringListModel : public gcn::ListModel
245 {
246 public:
247 virtual int getNumberOfElements() { return mElements.size(); }
248 virtual std::string getElementAt(int i) { return mElements[i]; }
249 void add(std::string element) { mElements.push_back(element); }
250 void clear() { mElements.clear(); }
251
252 private:
253 std::vector<std::string> mElements;
254 };
255
256 class LuaListModel : public StringListModel
257 {
258 public:
259 void setList(lua_State *lua, lua_Object *lo);
260 };
261
262 class ListBoxWidget : public gcn::ScrollArea
263 {
264 public:
265 ListBoxWidget(unsigned int width, unsigned int height);
266 void setList(lua_State *lua, lua_Object *lo);
267 void setSelected(int i);
268 int getSelected() const;
269 virtual void setBackgroundColor(const gcn::Color &color);
270 virtual void setFont(gcn::Font *font);
271 virtual void addActionListener(gcn::ActionListener *actionListener);
272 virtual bool getDirty() const;
273 private:
274 void adjustSize();
275 private:
276 LuaListModel lualistmodel;
277 gcn::ListBox listbox;
278 };
279
280 class DropDownWidget : public gcn::DropDown
281 {
282 LuaListModel listmodel;
283 public:
284 DropDownWidget() {}
285 void setList(lua_State *lua, lua_Object *lo);
286 virtual void setSize(int width, int height);
287 };
288
289 class StatBoxWidget : public gcn::Widget
290 {
291 public:
292 StatBoxWidget(int width, int height);
293
294 virtual void draw(gcn::Graphics *graphics);
295 void setCaption(const std::string &s);
296 const std::string &getCaption() const;
297 void setPercent(const int percent);
298 int getPercent() const;
299
300 private:
301 int width; /// width of the widget.
302 int height; /// height of the widget.
303 std::string caption; /// caption of the widget.
304 unsigned int percent; /// percent value of the widget.
305 };
306
307 class MenuScreen : public gcn::Container
308 {
309 public:
310 MenuScreen();
311
312 int run(bool loop = true);
313 void stop(int result = 0, bool stopAll = false);
314 void stopAll(int result = 0) { stop(result, true); }
315 void addLogicCallback(LuaActionListener *listener);
316 virtual void draw(gcn::Graphics *graphics);
317 virtual void logic();
318 void setDrawMenusUnder(bool drawUnder) { this->drawUnder = drawUnder; }
319 bool getDrawMenusUnder() { return this->drawUnder; }
320
321 private:
322 bool runLoop;
323 int loopResult;
324 gcn::Widget *oldtop;
325 LuaActionListener *logiclistener;
326 bool drawUnder;
327 };
328
329 #endif
330