xoreos  0.0.5
gui.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef ENGINES_AURORA_GUI_H
26 #define ENGINES_AURORA_GUI_H
27 
28 #include <list>
29 #include <map>
30 
31 #include <boost/noncopyable.hpp>
32 
33 #include "src/common/ustring.h"
34 
35 #include "src/events/types.h"
36 
37 namespace Engines {
38 
39 class Widget;
40 class Console;
41 
43 class GUI : boost::noncopyable {
44 public:
45  static const uint32 kStartCodeNone = 0;
46  static const uint32 kReturnCodeNone = 0;
47  static const uint32 kReturnCodeAbort = 0xFFFFFFFF;
48 
49 
50  GUI(Console *console = 0);
51  virtual ~GUI();
52 
53  virtual void show();
54  virtual void hide();
55 
57  uint32 run(uint32 startCode = kStartCodeNone);
59  virtual void abort();
60 
62  void addEvent(const Events::Event &event);
65 
66  virtual Common::UString getName() const;
67 
68 
69 protected:
71 
73 
76 
77  GUI *_sub;
78 
79 
81  void addWidget(Widget *widget);
83  void removeWidget(Widget *widget);
84 
86  void clearWidgets();
88  bool empty();
89 
91  bool hasWidget(const Common::UString &tag) const;
92 
94  Widget *getWidget(const Common::UString &tag, bool vital = false);
96  const Widget *getWidget(const Common::UString &tag, bool vital = false) const;
97 
99  void declareGroup(const std::list<Widget *> &group);
100 
102  void removeFocus();
103 
105  void updateMouse();
106 
108  virtual void mouseUp();
109  virtual void mouseDown();
110 
112  uint32 sub(GUI &gui, uint32 startCode = kStartCodeNone, bool showSelf = true, bool hideSelf = true);
113 
115  void setPosition(float x, float y, float z);
116 
118  void getPosition(float &x, float &y, float &z) const;
119 
121  virtual void callbackRun();
123  virtual void callbackActive(Widget &widget);
125  virtual void callbackTextInput(const Common::UString &text);
127  virtual void callbackKeyInput(const Events::Key &key, const Events::EventType &type);
128 
130  void addChild(GUI *gui);
132  void removeChild(GUI *gui);
133 
134 private:
135  typedef std::list<Widget *> WidgetList;
136  typedef std::map<Common::UString, Widget *> WidgetMap;
137 
138  std::list<GUI *> _childGUIs;
139 
142 
143  float _x;
144  float _y;
145  float _z;
146 
147  std::list<Events::Event> _eventQueue;
148 
150  Widget *getWidgetAt(float x, float y);
151 
152  void changedWidget(Widget *widget);
153  void checkWidgetActive(Widget *widget);
154 
155  void mouseMove(const Events::Event &event);
156  void mouseDown(const Events::Event &event);
157  void mouseUp(const Events::Event &event);
158  void mouseWheel(const Events::Event &event);
159  void textInput(const Events::Event &event);
160  void keyDown(const Events::Event &event);
161  void keyUp(const Events::Event &event);
162 
163  float toGUIX(int x); // Convert an event X coordinate to a GUI X coordinate
164  float toGUIY(int y); // Convert an event Y coordinate to a GUI Y coordinate
165 
167  void mouseMove(Widget *widget, const Events::Event &event);
169  void mouseDown(Widget *widget, const Events::Event &event);
171  void mouseUp(Widget *widget, const Events::Event &event);
173  void mouseWheel(Widget *widget, const Events::Event &event);
174 
175  friend class Widget;
176 };
177 
178 } // End of namespace Engines
179 
180 #endif // ENGINES_AURORA_GUI_H
virtual void mouseUp()
The mouse state has changed.
Definition: gui.cpp:443
Basic event types.
Widget * getWidget(const Common::UString &tag, bool vital=false)
Return a widget in the GUI.
Definition: gui.cpp:314
float toGUIX(int x)
Definition: gui.cpp:567
float toGUIY(int y)
Definition: gui.cpp:573
static const uint32 kReturnCodeAbort
Definition: gui.h:47
void mouseMove(const Events::Event &event)
Mouse move event triggered.
Definition: gui.cpp:498
uint32 _returnCode
The GUI&#39;s return code.
Definition: gui.h:75
A class holding an UTF-8 string.
Definition: ustring.h:48
void setPosition(float x, float y, float z)
Set the GUI&#39;s position.
Definition: gui.cpp:394
virtual void callbackActive(Widget &widget)
Callback that&#39;s triggered when a widget was activated.
Definition: gui.cpp:231
Console * _console
Definition: gui.h:70
Widget * getWidgetAt(float x, float y)
Return the widget at that position.
Definition: gui.cpp:446
void removeFocus()
Forcefully remove the focus from the current widget.
Definition: gui.cpp:422
virtual void callbackKeyInput(const Events::Key &key, const Events::EventType &type)
Callback that&#39;s triggered when a key is pressed or released.
Definition: gui.cpp:237
static const uint32 kReturnCodeNone
Definition: gui.h:46
void declareGroup(const std::list< Widget *> &group)
Put these widgets together into a group.
Definition: gui.cpp:340
uint32 run(uint32 startCode=kStartCodeNone)
Run the GUI.
Definition: gui.cpp:94
void checkWidgetActive(Widget *widget)
Check if a widget was activated.
Definition: gui.cpp:469
SDL_Event Event
Definition: types.h:42
virtual ~GUI()
Definition: gui.cpp:52
WidgetMap _widgetMap
All widgets in the GUI, index by their tag.
Definition: gui.h:141
A GUI.
Definition: gui.h:43
void keyUp(const Events::Event &event)
Key up event triggeered.
Definition: gui.cpp:563
virtual void show()
Show the GUI.
Definition: gui.cpp:62
void mouseWheel(const Events::Event &event)
Mouse wheel event triggered.
Definition: gui.cpp:544
void removeChild(GUI *gui)
Remove a child GUI object from this GUI.
Definition: gui.cpp:245
virtual void callbackRun()
Callback that&#39;s triggered periodically in the run() method.
Definition: gui.cpp:227
std::map< Common::UString, Widget * > WidgetMap
Definition: gui.h:136
uint32 sub(GUI &gui, uint32 startCode=kStartCodeNone, bool showSelf=true, bool hideSelf=true)
Open up a sub GUI.
Definition: gui.cpp:349
virtual void mouseDown()
Definition: gui.cpp:440
void keyDown(const Events::Event &event)
Key down event triggered.
Definition: gui.cpp:559
uint32 _startCode
The GUI&#39;s start code.
Definition: gui.h:74
virtual void abort()
Abort the currently running GUI.
Definition: gui.cpp:156
std::list< GUI * > _childGUIs
Definition: gui.h:138
float _x
The GUI X position.
Definition: gui.h:143
void changedWidget(Widget *widget)
The current widget has changed.
Definition: gui.cpp:456
Unicode string handling.
void clearWidgets()
Clear all widgets.
Definition: gui.cpp:295
void getPosition(float &x, float &y, float &z) const
Get the GUI&#39;s position.
Definition: gui.cpp:416
WidgetList _widgets
All widgets in the GUI.
Definition: gui.h:140
A widget in a GUI.
Definition: widget.h:40
void updateMouse()
Force an update of the mouse position.
Definition: gui.cpp:426
uint32_t uint32
Definition: types.h:204
Widget * _currentWidget
The widget the mouse is currently on.
Definition: gui.h:72
EventType
Custom event types.
Definition: types.h:45
Key
Definition: types.h:78
static const uint32 kStartCodeNone
Definition: gui.h:45
virtual void callbackTextInput(const Common::UString &text)
Callback that&#39;s triggered when a text input is received.
Definition: gui.cpp:234
float _z
The GUI Z position.
Definition: gui.h:145
GUI(Console *console=0)
Definition: gui.cpp:46
void addEvent(const Events::Event &event)
Add a single event for consideration into the GUI event queue.
Definition: gui.cpp:163
void addWidget(Widget *widget)
Add a widget.
Definition: gui.cpp:250
GUI * _sub
The currently running sub GUI.
Definition: gui.h:77
std::list< Widget * > WidgetList
Definition: gui.h:135
virtual Common::UString getName() const
Definition: gui.cpp:223
uint32 processEventQueue()
Process the current event queue.
Definition: gui.cpp:167
bool empty()
Check if the gui is currently empty.
Definition: gui.cpp:306
void textInput(const Events::Event &event)
Text input event received.
Definition: gui.cpp:555
virtual void hide()
Hide the GUI.
Definition: gui.cpp:80
bool hasWidget(const Common::UString &tag) const
Does this specific widget exist within the GUI?
Definition: gui.cpp:310
float _y
The GUI Y position.
Definition: gui.h:144
std::list< Events::Event > _eventQueue
The GUI event queue.
Definition: gui.h:147
void removeWidget(Widget *widget)
Remove a widget.
Definition: gui.cpp:267
void addChild(GUI *gui)
Add a child GUI object to this GUI.
Definition: gui.cpp:240