Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
GUIManager.h
Go to the documentation of this file.
1 /* Copyright (C) 2010 Wildfire Games.
2  * This file is part of 0 A.D.
3  *
4  * 0 A.D. 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  * 0 A.D. 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.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef INCLUDED_GUIMANAGER
19 #define INCLUDED_GUIMANAGER
20 
21 #include <boost/unordered_set.hpp>
22 
23 #include "lib/input.h"
24 #include "lib/file/vfs/vfs_path.h"
25 #include "ps/CStr.h"
27 
28 #include <set>
29 
30 class CGUI;
31 struct JSObject;
32 class IGUIObject;
33 struct CColor;
34 struct SGUIIcon;
35 
36 /**
37  * External interface to the GUI system.
38  *
39  * The GUI consists of a set of pages. Each page is constructed from a
40  * series of XML files, and is independent from any other page.
41  * Only one page is active at a time. All events and render requests etc
42  * will go to the active page. This lets the GUI switch between pre-game menu
43  * and in-game UI.
44  */
46 {
48 public:
49  CGUIManager(ScriptInterface& scriptInterface);
50  ~CGUIManager();
51 
53 
54  /**
55  * Returns whether there are any current pages.
56  */
57  bool HasPages();
58 
59  /**
60  * Load a new GUI page and make it active. All current pages will be destroyed.
61  */
62  void SwitchPage(const CStrW& name, CScriptVal initData);
63 
64  /**
65  * Load a new GUI page and make it active. All current pages will be retained,
66  * and will still be drawn and receive tick events, but will not receive
67  * user inputs.
68  */
69  void PushPage(const CStrW& name, CScriptVal initData);
70 
71  /**
72  * Unload the currently active GUI page, and make the previous page active.
73  * (There must be at least two pages when you call this.)
74  */
75  void PopPage();
76 
77  /**
78  * Display a modal message box with an "OK" button.
79  */
80  void DisplayMessageBox(int width, int height, const CStrW& title, const CStrW& message);
81 
82  /**
83  * Call when a file has bee modified, to hotload pages if their .xml files changed.
84  */
85  Status ReloadChangedFiles(const VfsPath& path);
86 
87  /**
88  * Pass input events to the currently active GUI page.
89  */
91 
92  /**
93  * See CGUI::GetPreDefinedColor; applies to the currently active page.
94  */
95  bool GetPreDefinedColor(const CStr& name, CColor& output);
96 
97  /**
98  * See CGUI::IconExists; applies to the currently active page.
99  */
100  bool IconExists(const CStr& str) const;
101 
102  /**
103  * See CGUI::GetIcon; applies to the currently active page.
104  */
105  SGUIIcon GetIcon(const CStr& str) const;
106 
107  /**
108  * See CGUI::FindObjectByName; applies to the currently active page.
109  */
110  IGUIObject* FindObjectByName(const CStr& name) const;
111 
112  /**
113  * See CGUI::SendEventToAll; applies to the currently active page.
114  */
115  void SendEventToAll(const CStr& eventName);
116 
117  /**
118  * See CGUI::GetScriptObject; applies to the currently active page.
119  */
120  JSObject* GetScriptObject();
121 
122  /**
123  * See CGUI::TickObjects; applies to @em all loaded pages.
124  */
125  void TickObjects();
126 
127  /**
128  * See CGUI::Draw; applies to @em all loaded pages.
129  */
130  void Draw();
131 
132  /**
133  * See CGUI::UpdateResolution; applies to @em all loaded pages.
134  */
135  void UpdateResolution();
136 
137  /**
138  * Calls the current page's script function getSavedGameData() and returns the result.
139  */
141 
142 private:
143  struct SGUIPage
144  {
145  CStrW name;
146  boost::unordered_set<VfsPath> inputs; // for hotloading
147 
148  JSContext* cx;
149  CScriptValRooted initData; // data to be passed to the init() function
150 
151  shared_ptr<CGUI> gui; // the actual GUI page
152  };
153 
154  void LoadPage(SGUIPage& page);
155 
156  shared_ptr<CGUI> top() const;
157 
158  typedef std::vector<SGUIPage> PageStackType;
160 
161  shared_ptr<CGUI> m_CurrentGUI; // used to latch state during TickObjects/LoadPage (this is kind of ugly)
162 
164 };
165 
166 extern CGUIManager* g_GUI;
167 
168 extern InReaction gui_handler(const SDL_Event_* ev);
169 
170 #endif // INCLUDED_GUIMANAGER
void LoadPage(SGUIPage &page)
Definition: GUIManager.cpp:109
InReaction gui_handler(const SDL_Event_ *ev)
Definition: GUIManager.cpp:45
void PopPage()
Unload the currently active GUI page, and make the previous page active.
Definition: GUIManager.cpp:83
PageStackType m_PageStack
Definition: GUIManager.h:159
tuple output
Definition: tests.py:116
Definition: Overlay.h:34
CGUIManager(ScriptInterface &scriptInterface)
Definition: GUIManager.cpp:51
void PushPage(const CStrW &name, CScriptVal initData)
Load a new GUI page and make it active.
Definition: GUIManager.cpp:75
A trivial wrapper around a jsval.
Definition: ScriptVal.h:29
bool GetPreDefinedColor(const CStr &name, CColor &output)
See CGUI::GetPreDefinedColor; applies to the currently active page.
Definition: GUIManager.cpp:231
Base settings, all objects possess these settings in their m_BaseSettings Instructions can be found i...
Definition: IGUIObject.h:140
CScriptValRooted initData
Definition: GUIManager.h:149
CGUIManager * g_GUI
Definition: GUIManager.cpp:32
boost::unordered_set< VfsPath > inputs
Definition: GUIManager.h:146
void UpdateResolution()
See CGUI::UpdateResolution; applies to all loaded pages.
Definition: GUIManager.cpp:284
std::vector< SGUIPage > PageStackType
Definition: GUIManager.h:158
The main object that represents a whole GUI page.
Definition: CGUI.h:97
CScriptVal GetSavedGameData()
Calls the current page&#39;s script function getSavedGameData() and returns the result.
Definition: GUIManager.cpp:187
bool IconExists(const CStr &str) const
See CGUI::IconExists; applies to the currently active page.
Definition: GUIManager.cpp:236
SGUIIcon GetIcon(const CStr &str) const
See CGUI::GetIcon; applies to the currently active page.
Definition: GUIManager.cpp:241
Definition: path.h:75
IGUIObject * FindObjectByName(const CStr &name) const
See CGUI::FindObjectByName; applies to the currently active page.
Definition: GUIManager.cpp:246
InReaction
Definition: input.h:34
JSObject * GetScriptObject()
See CGUI::GetScriptObject; applies to the currently active page.
Definition: GUIManager.cpp:290
void TickObjects()
See CGUI::TickObjects; applies to all loaded pages.
Definition: GUIManager.cpp:261
i64 Status
Error handling system.
Definition: status.h:171
void DisplayMessageBox(int width, int height, const CStrW &title, const CStrW &message)
Display a modal message box with an &quot;OK&quot; button.
Definition: GUIManager.cpp:94
ScriptInterface & GetScriptInterface()
Definition: GUIManager.h:52
NONCOPYABLE(CGUIManager)
void SwitchPage(const CStrW &name, CScriptVal initData)
Load a new GUI page and make it active.
Definition: GUIManager.cpp:69
Abstraction around a SpiderMonkey JSContext.
ScriptInterface & m_ScriptInterface
Definition: GUIManager.h:163
void Draw()
See CGUI::Draw; applies to all loaded pages.
Definition: GUIManager.cpp:276
shared_ptr< CGUI > gui
Definition: GUIManager.h:151
shared_ptr< CGUI > top() const
Definition: GUIManager.cpp:298
External interface to the GUI system.
Definition: GUIManager.h:45
shared_ptr< CGUI > m_CurrentGUI
Definition: GUIManager.h:161
bool HasPages()
Returns whether there are any current pages.
Definition: GUIManager.cpp:64
InReaction HandleEvent(const SDL_Event_ *ev)
Pass input events to the currently active GUI page.
Definition: GUIManager.cpp:195
void SendEventToAll(const CStr &eventName)
See CGUI::SendEventToAll; applies to the currently active page.
Definition: GUIManager.cpp:256
Status ReloadChangedFiles(const VfsPath &path)
Call when a file has bee modified, to hotload pages if their .xml files changed.
Definition: GUIManager.cpp:172