]> git.lizzy.rs Git - irrlicht.git/blob - source/Irrlicht/CGUIEnvironment.h
ab745865b66dfd72250620113bc51c23e35ab1c3
[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         void drawAll(bool useScreenSize) override;\r
35 \r
36         //! returns the current video driver\r
37         video::IVideoDriver* getVideoDriver() const override;\r
38 \r
39         //! returns pointer to the filesystem\r
40         io::IFileSystem* getFileSystem() const override;\r
41 \r
42         //! returns a pointer to the OS operator\r
43         IOSOperator* getOSOperator() const override;\r
44 \r
45         //! posts an input event to the environment\r
46         bool postEventFromUser(const SEvent& event) 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         void setUserEventReceiver(IEventReceiver* evr) override;\r
51 \r
52         //! removes all elements from the environment\r
53         void clear() override;\r
54 \r
55         //! called if an event happened.\r
56         bool OnEvent(const SEvent& event) override;\r
57 \r
58         //! returns the current gui skin\r
59         IGUISkin* getSkin() const override;\r
60 \r
61         //! Sets a new GUI Skin\r
62         void setSkin(IGUISkin* skin) 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         IGUISkin* createSkin(EGUI_SKIN_TYPE type) 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) override;\r
73 \r
74         //! returns the font\r
75         IGUIFont* getFont(const io::path& filename) override;\r
76 \r
77         //! add an externally loaded font\r
78         IGUIFont* addFont(const io::path& name, IGUIFont* font) override;\r
79 \r
80         //! remove loaded font\r
81         void removeFont(IGUIFont* font) override;\r
82 \r
83         //! returns default font\r
84         IGUIFont* getBuiltInFont() const override;\r
85 \r
86         //! returns the sprite bank\r
87         IGUISpriteBank* getSpriteBank(const io::path& filename) override;\r
88 \r
89         //! returns the sprite bank\r
90         IGUISpriteBank* addEmptySpriteBank(const io::path& name) override;\r
91 \r
92         //! adds an button. The returned pointer must not be dropped.\r
93         IGUIButton* addButton(const core::rect<s32>& rectangle, IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0,const wchar_t* tooltiptext = 0) override;\r
94 \r
95         //! adds a scrollbar. The returned pointer must not be dropped.\r
96         virtual IGUIScrollBar* addScrollBar(bool horizontal, const core::rect<s32>& rectangle,\r
97                 IGUIElement* parent=0, s32 id=-1) override;\r
98 \r
99         //! Adds an image element.\r
100         virtual IGUIImage* addImage(video::ITexture* image, core::position2d<s32> pos,\r
101                 bool useAlphaChannel=true, IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0) override;\r
102 \r
103         //! adds an image. The returned pointer must not be dropped.\r
104         virtual IGUIImage* addImage(const core::rect<s32>& rectangle,\r
105                 IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0, bool useAlphaChannel=true) override;\r
106 \r
107         //! adds a checkbox\r
108         virtual IGUICheckBox* addCheckBox(bool checked, const core::rect<s32>& rectangle,\r
109                 IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0) override;\r
110 \r
111         //! adds a list box\r
112         virtual IGUIListBox* addListBox(const core::rect<s32>& rectangle,\r
113                 IGUIElement* parent=0, s32 id=-1, bool drawBackground=false) override;\r
114 \r
115         //! Adds a file open dialog.\r
116         virtual IGUIFileOpenDialog* addFileOpenDialog(const wchar_t* title = 0,\r
117                         bool modal=true, IGUIElement* parent=0, s32 id=-1,\r
118                         bool restoreCWD=false, io::path::char_type* startDir=0) override;\r
119 \r
120         //! adds a static text. The returned pointer must not be dropped.\r
121         virtual IGUIStaticText* addStaticText(const wchar_t* text, const core::rect<s32>& rectangle,\r
122                 bool border=false, bool wordWrap=true, IGUIElement* parent=0, s32 id=-1, bool drawBackground = false) override;\r
123 \r
124         //! Adds an edit box. The returned pointer must not be dropped.\r
125         virtual IGUIEditBox* addEditBox(const wchar_t* text, const core::rect<s32>& rectangle,\r
126                 bool border=false, IGUIElement* parent=0, s32 id=-1) override;\r
127 \r
128         //! Adds a tab control to the environment.\r
129         virtual IGUITabControl* addTabControl(const core::rect<s32>& rectangle,\r
130                 IGUIElement* parent=0, bool fillbackground=false, bool border=true, s32 id=-1) override;\r
131 \r
132         //! Adds tab to the environment.\r
133         virtual IGUITab* addTab(const core::rect<s32>& rectangle,\r
134                 IGUIElement* parent=0, s32 id=-1) override;\r
135 \r
136         //! Adds a combo box to the environment.\r
137         virtual IGUIComboBox* addComboBox(const core::rect<s32>& rectangle,\r
138                 IGUIElement* parent=0, s32 id=-1) override;\r
139 \r
140         //! sets the focus to an element\r
141         bool setFocus(IGUIElement* element) override;\r
142 \r
143         //! removes the focus from an element\r
144         bool removeFocus(IGUIElement* element) override;\r
145 \r
146         //! Returns if the element has focus\r
147         bool hasFocus(const IGUIElement* element, bool checkSubElements=false) const override;\r
148 \r
149         //! Returns the element with the focus\r
150         IGUIElement* getFocus() const override;\r
151 \r
152         //! Returns the element last known to be under the mouse\r
153         IGUIElement* getHovered() const override;\r
154 \r
155         //! Returns the root gui element.\r
156         IGUIElement* getRootGUIElement() override;\r
157 \r
158         void OnPostRender( u32 time ) override;\r
159 \r
160         //! Find the next element which would be selected when pressing the tab-key\r
161         IGUIElement* getNextElement(bool reverse=false, bool group=false) override;\r
162 \r
163         //! Set the way the gui will handle focus changes\r
164         void setFocusBehavior(u32 flags) override;\r
165 \r
166         //! Get the way the gui does handle focus changes\r
167         u32 getFocusBehavior() const override;\r
168 \r
169         //! Adds a IGUIElement to deletion queue.\r
170         void addToDeletionQueue(IGUIElement* element) override;\r
171 \r
172 private:\r
173 \r
174         //! clears the deletion queue\r
175         void clearDeletionQueue();\r
176 \r
177         void updateHoveredElement(core::position2d<s32> mousePos);\r
178 \r
179         void loadBuiltInFont();\r
180 \r
181         struct SFont\r
182         {\r
183                 io::SNamedPath NamedPath;\r
184                 IGUIFont* Font;\r
185 \r
186                 bool operator < (const SFont& other) const\r
187                 {\r
188                         return (NamedPath < other.NamedPath);\r
189                 }\r
190         };\r
191 \r
192         struct SSpriteBank\r
193         {\r
194                 io::SNamedPath NamedPath;\r
195                 IGUISpriteBank* Bank;\r
196 \r
197                 bool operator < (const SSpriteBank& other) const\r
198                 {\r
199                         return (NamedPath < other.NamedPath);\r
200                 }\r
201         };\r
202 \r
203         struct SToolTip\r
204         {\r
205                 IGUIStaticText* Element;\r
206                 u32 LastTime;\r
207                 u32 EnterTime;\r
208                 u32 LaunchTime;\r
209                 u32 RelaunchTime;\r
210         };\r
211 \r
212         SToolTip ToolTip;\r
213 \r
214         core::array<SFont> Fonts;\r
215         core::array<SSpriteBank> Banks;\r
216         video::IVideoDriver* Driver;\r
217         IGUIElement* Hovered;\r
218         IGUIElement* HoveredNoSubelement;       // subelements replaced by their parent, so you only have 'real' elements here\r
219         IGUIElement* Focus;\r
220         core::position2d<s32> LastHoveredMousePos;\r
221         IGUISkin* CurrentSkin;\r
222         io::IFileSystem* FileSystem;\r
223         IEventReceiver* UserReceiver;\r
224         IOSOperator* Operator;\r
225         u32 FocusFlags;\r
226         core::array<IGUIElement*> DeletionQueue;\r
227 \r
228         static const io::path DefaultFontName;\r
229 };\r
230 \r
231 } // end namespace gui\r
232 } // end namespace irr\r
233 \r
234 #endif // _IRR_COMPILE_WITH_GUI_\r
235 \r
236 #endif // __C_GUI_ENVIRONMENT_H_INCLUDED__\r
237 \r
238 \r