]> git.lizzy.rs Git - irrlicht.git/blob - source/Irrlicht/CGUIEnvironment.h
Merging r6196 through r6248 from trunk to ogl-es branch
[irrlicht.git] / source / Irrlicht / CGUIEnvironment.h
1 // Copyright (C) 2002-2012 Nikolaus Gebhardt\r
2 // This file is part of the "Irrlicht Engine".\r
3 // For conditions of distribution and use, see copyright notice in irrlicht.h\r
4 \r
5 #ifndef __C_GUI_ENVIRONMENT_H_INCLUDED__\r
6 #define __C_GUI_ENVIRONMENT_H_INCLUDED__\r
7 \r
8 #include "IrrCompileConfig.h"\r
9 #ifdef _IRR_COMPILE_WITH_GUI_\r
10 \r
11 #include "IGUIEnvironment.h"\r
12 #include "IGUIElement.h"\r
13 #include "irrArray.h"\r
14 #include "IFileSystem.h"\r
15 #include "IOSOperator.h"\r
16 \r
17 namespace irr\r
18 {\r
19 \r
20 namespace gui\r
21 {\r
22 \r
23 class CGUIEnvironment : public IGUIEnvironment, public IGUIElement\r
24 {\r
25 public:\r
26 \r
27         //! constructor\r
28         CGUIEnvironment(io::IFileSystem* fs, video::IVideoDriver* driver, IOSOperator* op);\r
29 \r
30         //! destructor\r
31         virtual ~CGUIEnvironment();\r
32 \r
33         //! draws all gui elements\r
34         virtual void drawAll(bool useScreenSize) _IRR_OVERRIDE_;\r
35 \r
36         //! returns the current video driver\r
37         virtual video::IVideoDriver* getVideoDriver() const _IRR_OVERRIDE_;\r
38 \r
39         //! returns pointer to the filesystem\r
40         virtual io::IFileSystem* getFileSystem() const _IRR_OVERRIDE_;\r
41 \r
42         //! returns a pointer to the OS operator\r
43         virtual IOSOperator* getOSOperator() const _IRR_OVERRIDE_;\r
44 \r
45         //! posts an input event to the environment\r
46         virtual bool postEventFromUser(const SEvent& event) _IRR_OVERRIDE_;\r
47 \r
48         //! This sets a new event receiver for gui events. Usually you do not have to\r
49         //! use this method, it is used by the internal engine.\r
50         virtual void setUserEventReceiver(IEventReceiver* evr) _IRR_OVERRIDE_;\r
51 \r
52         //! removes all elements from the environment\r
53         virtual void clear() _IRR_OVERRIDE_;\r
54 \r
55         //! called if an event happened.\r
56         virtual bool OnEvent(const SEvent& event) _IRR_OVERRIDE_;\r
57 \r
58         //! returns the current gui skin\r
59         virtual IGUISkin* getSkin() const _IRR_OVERRIDE_;\r
60 \r
61         //! Sets a new GUI Skin\r
62         virtual void setSkin(IGUISkin* skin) _IRR_OVERRIDE_;\r
63 \r
64         //! Creates a new GUI Skin based on a template.\r
65         /** \return Returns a pointer to the created skin.\r
66         If you no longer need the skin, you should call IGUISkin::drop().\r
67         See IReferenceCounted::drop() for more information. */\r
68         virtual IGUISkin* createSkin(EGUI_SKIN_TYPE type) _IRR_OVERRIDE_;\r
69 \r
70         //! Creates the image list from the given texture.\r
71         virtual IGUIImageList* createImageList(video::ITexture* texture,\r
72                                         core::dimension2d<s32> imageSize, bool useAlphaChannel) _IRR_OVERRIDE_;\r
73 \r
74         //! returns the font\r
75         virtual IGUIFont* getFont(const io::path& filename) _IRR_OVERRIDE_;\r
76 \r
77         //! add an externally loaded font\r
78         virtual IGUIFont* addFont(const io::path& name, IGUIFont* font) _IRR_OVERRIDE_;\r
79 \r
80         //! remove loaded font\r
81         virtual void removeFont(IGUIFont* font) _IRR_OVERRIDE_;\r
82 \r
83         //! returns default font\r
84         virtual IGUIFont* getBuiltInFont() const _IRR_OVERRIDE_;\r
85 \r
86         //! returns the sprite bank\r
87         virtual IGUISpriteBank* getSpriteBank(const io::path& filename) _IRR_OVERRIDE_;\r
88 \r
89         //! returns the sprite bank\r
90         virtual IGUISpriteBank* addEmptySpriteBank(const io::path& name) _IRR_OVERRIDE_;\r
91 \r
92         //! adds an button. The returned pointer must not be dropped.\r
93         virtual IGUIButton* addButton(const core::rect<s32>& rectangle, IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0,const wchar_t* tooltiptext = 0) _IRR_OVERRIDE_;\r
94 \r
95         //! adds a window. The returned pointer must not be dropped.\r
96         virtual IGUIWindow* addWindow(const core::rect<s32>& rectangle, bool modal = false,\r
97                 const wchar_t* text=0, IGUIElement* parent=0, s32 id=-1) _IRR_OVERRIDE_;\r
98 \r
99         //! adds a modal screen. The returned pointer must not be dropped.\r
100         virtual IGUIElement* addModalScreen(IGUIElement* parent, int blinkMode) _IRR_OVERRIDE_;\r
101 \r
102         //! Adds a message box.\r
103         virtual IGUIWindow* addMessageBox(const wchar_t* caption, const wchar_t* text=0,\r
104                 bool modal = true, s32 flag = EMBF_OK, IGUIElement* parent=0, s32 id=-1, video::ITexture* image=0) _IRR_OVERRIDE_;\r
105 \r
106         //! adds a scrollbar. The returned pointer must not be dropped.\r
107         virtual IGUIScrollBar* addScrollBar(bool horizontal, const core::rect<s32>& rectangle,\r
108                 IGUIElement* parent=0, s32 id=-1) _IRR_OVERRIDE_;\r
109 \r
110         //! Adds an image element.\r
111         virtual IGUIImage* addImage(video::ITexture* image, core::position2d<s32> pos,\r
112                 bool useAlphaChannel=true, IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0) _IRR_OVERRIDE_;\r
113 \r
114         //! adds an image. The returned pointer must not be dropped.\r
115         virtual IGUIImage* addImage(const core::rect<s32>& rectangle,\r
116                 IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0, bool useAlphaChannel=true) _IRR_OVERRIDE_;\r
117 \r
118         //! adds a checkbox\r
119         virtual IGUICheckBox* addCheckBox(bool checked, const core::rect<s32>& rectangle,\r
120                 IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0) _IRR_OVERRIDE_;\r
121 \r
122         //! adds a list box\r
123         virtual IGUIListBox* addListBox(const core::rect<s32>& rectangle,\r
124                 IGUIElement* parent=0, s32 id=-1, bool drawBackground=false) _IRR_OVERRIDE_;\r
125 \r
126         //! adds a tree view\r
127         virtual IGUITreeView* addTreeView(const core::rect<s32>& rectangle,\r
128                 IGUIElement* parent=0, s32 id=-1, bool drawBackground=false,\r
129                 bool scrollBarVertical = true, bool scrollBarHorizontal = false) _IRR_OVERRIDE_;\r
130 \r
131         //! adds an mesh viewer. The returned pointer must not be dropped.\r
132         virtual IGUIMeshViewer* addMeshViewer(const core::rect<s32>& rectangle,\r
133                 IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0) _IRR_OVERRIDE_;\r
134 \r
135         //! Adds a file open dialog.\r
136         virtual IGUIFileOpenDialog* addFileOpenDialog(const wchar_t* title = 0,\r
137                         bool modal=true, IGUIElement* parent=0, s32 id=-1,\r
138                         bool restoreCWD=false, io::path::char_type* startDir=0) _IRR_OVERRIDE_;\r
139 \r
140         //! Adds a color select dialog.\r
141         virtual IGUIColorSelectDialog* addColorSelectDialog(const wchar_t* title = 0,\r
142                 bool modal=true, IGUIElement* parent=0, s32 id=-1) _IRR_OVERRIDE_;\r
143 \r
144         //! adds a static text. The returned pointer must not be dropped.\r
145         virtual IGUIStaticText* addStaticText(const wchar_t* text, const core::rect<s32>& rectangle,\r
146                 bool border=false, bool wordWrap=true, IGUIElement* parent=0, s32 id=-1, bool drawBackground = false) _IRR_OVERRIDE_;\r
147 \r
148         //! Adds an edit box. The returned pointer must not be dropped.\r
149         virtual IGUIEditBox* addEditBox(const wchar_t* text, const core::rect<s32>& rectangle,\r
150                 bool border=false, IGUIElement* parent=0, s32 id=-1) _IRR_OVERRIDE_;\r
151 \r
152         //! Adds a spin box to the environment\r
153         virtual IGUISpinBox* addSpinBox(const wchar_t* text, const core::rect<s32>& rectangle,\r
154                 bool border=false,IGUIElement* parent=0, s32 id=-1) _IRR_OVERRIDE_;\r
155 \r
156         //! Adds a tab control to the environment.\r
157         virtual IGUITabControl* addTabControl(const core::rect<s32>& rectangle,\r
158                 IGUIElement* parent=0, bool fillbackground=false, bool border=true, s32 id=-1) _IRR_OVERRIDE_;\r
159 \r
160         //! Adds tab to the environment.\r
161         virtual IGUITab* addTab(const core::rect<s32>& rectangle,\r
162                 IGUIElement* parent=0, s32 id=-1) _IRR_OVERRIDE_;\r
163 \r
164         //! Adds a context menu to the environment.\r
165         virtual IGUIContextMenu* addContextMenu(const core::rect<s32>& rectangle,\r
166                 IGUIElement* parent=0, s32 id=-1) _IRR_OVERRIDE_;\r
167 \r
168         //! Adds a menu to the environment.\r
169         virtual IGUIContextMenu* addMenu(IGUIElement* parent=0, s32 id=-1) _IRR_OVERRIDE_;\r
170 \r
171         //! Adds a toolbar to the environment. It is like a menu is always placed on top\r
172         //! in its parent, and contains buttons.\r
173         virtual IGUIToolBar* addToolBar(IGUIElement* parent=0, s32 id=-1) _IRR_OVERRIDE_;\r
174 \r
175         //! Adds a combo box to the environment.\r
176         virtual IGUIComboBox* addComboBox(const core::rect<s32>& rectangle,\r
177                 IGUIElement* parent=0, s32 id=-1) _IRR_OVERRIDE_;\r
178 \r
179         //! Adds a table element.\r
180         virtual IGUITable* addTable(const core::rect<s32>& rectangle,\r
181                 IGUIElement* parent=0, s32 id=-1, bool drawBackground=false) _IRR_OVERRIDE_;\r
182 \r
183         //! Adds an element to display the information from the Irrlicht profiler\r
184         virtual IGUIProfiler* addProfilerDisplay(const core::rect<s32>& rectangle,\r
185                 IGUIElement* parent=0, s32 id=-1) _IRR_OVERRIDE_;\r
186 \r
187         //! sets the focus to an element\r
188         virtual bool setFocus(IGUIElement* element) _IRR_OVERRIDE_;\r
189 \r
190         //! removes the focus from an element\r
191         virtual bool removeFocus(IGUIElement* element) _IRR_OVERRIDE_;\r
192 \r
193         //! Returns if the element has focus\r
194         virtual bool hasFocus(const IGUIElement* element, bool checkSubElements=false) const _IRR_OVERRIDE_;\r
195 \r
196         //! Returns the element with the focus\r
197         virtual IGUIElement* getFocus() const _IRR_OVERRIDE_;\r
198 \r
199         //! Returns the element last known to be under the mouse\r
200         virtual IGUIElement* getHovered() const _IRR_OVERRIDE_;\r
201 \r
202         //! Adds an element for fading in or out.\r
203         virtual IGUIInOutFader* addInOutFader(const core::rect<s32>* rectangle=0, IGUIElement* parent=0, s32 id=-1) _IRR_OVERRIDE_;\r
204 \r
205         //! Returns the root gui element.\r
206         virtual IGUIElement* getRootGUIElement() _IRR_OVERRIDE_;\r
207 \r
208         virtual void OnPostRender( u32 time ) _IRR_OVERRIDE_;\r
209 \r
210         //! Returns the default element factory which can create all built in elements\r
211         virtual IGUIElementFactory* getDefaultGUIElementFactory() const _IRR_OVERRIDE_;\r
212 \r
213         //! Adds an element factory to the gui environment.\r
214         /** Use this to extend the gui environment with new element types which it should be\r
215         able to create automatically, for example when loading data from xml files. */\r
216         virtual void registerGUIElementFactory(IGUIElementFactory* factoryToAdd) _IRR_OVERRIDE_;\r
217 \r
218         //! Returns amount of registered scene node factories.\r
219         virtual u32 getRegisteredGUIElementFactoryCount() const _IRR_OVERRIDE_;\r
220 \r
221         //! Returns a scene node factory by index\r
222         virtual IGUIElementFactory* getGUIElementFactory(u32 index) const _IRR_OVERRIDE_;\r
223 \r
224         //! Adds a GUI Element by its name\r
225         virtual IGUIElement* addGUIElement(const c8* elementName, IGUIElement* parent=0) _IRR_OVERRIDE_;\r
226 \r
227         //! Saves the current gui into a file.\r
228         /** \param filename: Name of the file.\r
229         \param start: The element to start saving from.\r
230         if not specified, the root element will be used */\r
231         virtual bool saveGUI( const io::path& filename, IGUIElement* start=0) _IRR_OVERRIDE_;\r
232 \r
233         //! Saves the current gui into a file.\r
234         /** \param file: The file to save the GUI to.\r
235         \param start: The element to start saving from.\r
236         if not specified, the root element will be used */\r
237         virtual bool saveGUI(io::IWriteFile* file, IGUIElement* start=0) _IRR_OVERRIDE_;\r
238 \r
239         //! Loads the gui. Note that the current gui is not cleared before.\r
240         /** \param filename: Name of the file.\r
241         \param parent: The parent of all loaded GUI elements,\r
242         if not specified, the root element will be used */\r
243         virtual bool loadGUI(const io::path& filename, IGUIElement* parent=0) _IRR_OVERRIDE_;\r
244 \r
245         //! Loads the gui. Note that the current gui is not cleared before.\r
246         /** \param file: IReadFile to load the GUI from\r
247         \param parent: The parent of all loaded GUI elements,\r
248         if not specified, the root element will be used */\r
249         virtual bool loadGUI(io::IReadFile* file, IGUIElement* parent=0) _IRR_OVERRIDE_;\r
250 \r
251         //! Writes attributes of the environment\r
252         virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const _IRR_OVERRIDE_;\r
253 \r
254         //! Reads attributes of the environment.\r
255         virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0) _IRR_OVERRIDE_;\r
256 \r
257         //! Find the next element which would be selected when pressing the tab-key\r
258         virtual IGUIElement* getNextElement(bool reverse=false, bool group=false) _IRR_OVERRIDE_;\r
259 \r
260         //! Set the way the gui will handle focus changes\r
261         virtual void setFocusBehavior(u32 flags) _IRR_OVERRIDE_;\r
262 \r
263         //! Get the way the gui does handle focus changes\r
264         virtual u32 getFocusBehavior() const _IRR_OVERRIDE_;\r
265 \r
266         //! Adds a IGUIElement to deletion queue.\r
267         virtual void addToDeletionQueue(IGUIElement* element) _IRR_OVERRIDE_;\r
268 \r
269 private:\r
270 \r
271         //! clears the deletion queue\r
272         void clearDeletionQueue();\r
273 \r
274         void updateHoveredElement(core::position2d<s32> mousePos);\r
275 \r
276         void loadBuiltInFont();\r
277 \r
278         struct SFont\r
279         {\r
280                 io::SNamedPath NamedPath;\r
281                 IGUIFont* Font;\r
282 \r
283                 bool operator < (const SFont& other) const\r
284                 {\r
285                         return (NamedPath < other.NamedPath);\r
286                 }\r
287         };\r
288 \r
289         struct SSpriteBank\r
290         {\r
291                 io::SNamedPath NamedPath;\r
292                 IGUISpriteBank* Bank;\r
293 \r
294                 bool operator < (const SSpriteBank& other) const\r
295                 {\r
296                         return (NamedPath < other.NamedPath);\r
297                 }\r
298         };\r
299 \r
300         struct SToolTip\r
301         {\r
302                 IGUIStaticText* Element;\r
303                 u32 LastTime;\r
304                 u32 EnterTime;\r
305                 u32 LaunchTime;\r
306                 u32 RelaunchTime;\r
307         };\r
308 \r
309         SToolTip ToolTip;\r
310 \r
311         core::array<IGUIElementFactory*> GUIElementFactoryList;\r
312 \r
313         core::array<SFont> Fonts;\r
314         core::array<SSpriteBank> Banks;\r
315         video::IVideoDriver* Driver;\r
316         IGUIElement* Hovered;\r
317         IGUIElement* HoveredNoSubelement;       // subelements replaced by their parent, so you only have 'real' elements here\r
318         IGUIElement* Focus;\r
319         core::position2d<s32> LastHoveredMousePos;\r
320         IGUISkin* CurrentSkin;\r
321         io::IFileSystem* FileSystem;\r
322         IEventReceiver* UserReceiver;\r
323         IOSOperator* Operator;\r
324         u32 FocusFlags;\r
325         core::array<IGUIElement*> DeletionQueue;\r
326 \r
327         static const io::path DefaultFontName;\r
328 };\r
329 \r
330 } // end namespace gui\r
331 } // end namespace irr\r
332 \r
333 #endif // _IRR_COMPILE_WITH_GUI_\r
334 \r
335 #endif // __C_GUI_ENVIRONMENT_H_INCLUDED__\r
336 \r
337 \r