]> git.lizzy.rs Git - irrlicht.git/blob - include/IGUIEnvironment.h
Add back LightManager
[irrlicht.git] / include / IGUIEnvironment.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 __I_GUI_ENVIRONMENT_H_INCLUDED__\r
6 #define __I_GUI_ENVIRONMENT_H_INCLUDED__\r
7 \r
8 #include "IReferenceCounted.h"\r
9 #include "IGUISkin.h"\r
10 #include "rect.h"\r
11 #include "EFocusFlags.h"\r
12 #include "IEventReceiver.h"\r
13 #include "path.h"\r
14 \r
15 namespace irr\r
16 {\r
17         class IOSOperator;\r
18         class IEventReceiver;\r
19 \r
20         namespace io\r
21         {\r
22                 class IReadFile;\r
23                 class IWriteFile;\r
24                 class IFileSystem;\r
25         } // end namespace io\r
26         namespace video\r
27         {\r
28                 class IVideoDriver;\r
29                 class ITexture;\r
30         } // end namespace video\r
31 \r
32 namespace gui\r
33 {\r
34 \r
35 class IGUIElement;\r
36 class IGUIFont;\r
37 class IGUISpriteBank;\r
38 class IGUIScrollBar;\r
39 class IGUIImage;\r
40 class IGUICheckBox;\r
41 class IGUIListBox;\r
42 class IGUIImageList;\r
43 class IGUIFileOpenDialog;\r
44 class IGUIStaticText;\r
45 class IGUIEditBox;\r
46 class IGUITabControl;\r
47 class IGUITab;\r
48 class IGUIComboBox;\r
49 class IGUIButton;\r
50 class IGUIWindow;\r
51 \r
52 //! GUI Environment. Used as factory and manager of all other GUI elements.\r
53 /** \par This element can create the following events of type EGUI_EVENT_TYPE (which are passed on to focused sub-elements):\r
54 \li EGET_ELEMENT_FOCUS_LOST\r
55 \li EGET_ELEMENT_FOCUSED\r
56 \li EGET_ELEMENT_LEFT\r
57 \li EGET_ELEMENT_HOVERED\r
58 */\r
59 class IGUIEnvironment : public virtual IReferenceCounted\r
60 {\r
61 public:\r
62 \r
63         //! Draws all gui elements by traversing the GUI environment starting at the root node.\r
64         /** \param  When true ensure the GuiEnvironment (aka the RootGUIElement) has the same size as the current driver screensize. \r
65                     Can be set to false to control that size yourself, p.E when not the full size should be used for UI. */\r
66         virtual void drawAll(bool useScreenSize=true) = 0;\r
67 \r
68         //! Sets the focus to an element.\r
69         /** Causes a EGET_ELEMENT_FOCUS_LOST event followed by a\r
70         EGET_ELEMENT_FOCUSED event. If someone absorbed either of the events,\r
71         then the focus will not be changed.\r
72         \param element Pointer to the element which shall get the focus.\r
73         \return True on success, false on failure */\r
74         virtual bool setFocus(IGUIElement* element) = 0;\r
75 \r
76         //! Returns the element which holds the focus.\r
77         /** \return Pointer to the element with focus. */\r
78         virtual IGUIElement* getFocus() const = 0;\r
79 \r
80         //! Returns the element which was last under the mouse cursor\r
81         /** NOTE: This information is updated _after_ the user-eventreceiver\r
82         received it's mouse-events. To find the hovered element while catching\r
83         mouse events you have to use instead:\r
84         IGUIEnvironment::getRootGUIElement()->getElementFromPoint(mousePos);\r
85         \return Pointer to the element under the mouse. */\r
86         virtual IGUIElement* getHovered() const = 0;\r
87 \r
88         //! Removes the focus from an element.\r
89         /** Causes a EGET_ELEMENT_FOCUS_LOST event. If the event is absorbed\r
90         then the focus will not be changed.\r
91         \param element Pointer to the element which shall lose the focus.\r
92         \return True on success, false on failure */\r
93         virtual bool removeFocus(IGUIElement* element) = 0;\r
94 \r
95         //! Returns whether the element has focus\r
96         /** \param element Pointer to the element which is tested.\r
97         \param checkSubElements When true and focus is on a sub-element of element then it will still count as focused and return true\r
98         \return True if the element has focus, else false. */\r
99         virtual bool hasFocus(const IGUIElement* element, bool checkSubElements=false) const = 0;\r
100 \r
101         //! Returns the current video driver.\r
102         /** \return Pointer to the video driver. */\r
103         virtual video::IVideoDriver* getVideoDriver() const = 0;\r
104 \r
105         //! Returns the file system.\r
106         /** \return Pointer to the file system. */\r
107         virtual io::IFileSystem* getFileSystem() const = 0;\r
108 \r
109         //! returns a pointer to the OS operator\r
110         /** \return Pointer to the OS operator. */\r
111         virtual IOSOperator* getOSOperator() const = 0;\r
112 \r
113         //! Removes all elements from the environment.\r
114         virtual void clear() = 0;\r
115 \r
116         //! Posts an input event to the environment.\r
117         /** Usually you do not have to\r
118         use this method, it is used by the engine internally.\r
119         \param event The event to post.\r
120         \return True if succeeded, else false. */\r
121         virtual bool postEventFromUser(const SEvent& event) = 0;\r
122 \r
123         //! This sets a new event receiver for gui events.\r
124         /** Usually you do not have to\r
125         use this method, it is used by the engine internally.\r
126         \param evr Pointer to the new receiver. */\r
127         virtual void setUserEventReceiver(IEventReceiver* evr) = 0;\r
128 \r
129         //! Returns pointer to the current gui skin.\r
130         /** \return Pointer to the GUI skin. */\r
131         virtual IGUISkin* getSkin() const = 0;\r
132 \r
133         //! Sets a new GUI Skin\r
134         /** You can use this to change the appearance of the whole GUI\r
135         Environment. You can set one of the built-in skins or implement your\r
136         own class derived from IGUISkin and enable it using this method.\r
137         To set for example the built-in Windows classic skin, use the following\r
138         code:\r
139         \code\r
140         gui::IGUISkin* newskin = environment->createSkin(gui::EGST_WINDOWS_CLASSIC);\r
141         environment->setSkin(newskin);\r
142         newskin->drop();\r
143         \endcode\r
144         \param skin New skin to use.\r
145         */\r
146         virtual void setSkin(IGUISkin* skin) = 0;\r
147 \r
148         //! Creates a new GUI Skin based on a template.\r
149         /** Use setSkin() to set the created skin.\r
150         \param type The type of the new skin.\r
151         \return Pointer to the created skin.\r
152         If you no longer need it, you should call IGUISkin::drop().\r
153         See IReferenceCounted::drop() for more information. */\r
154         virtual IGUISkin* createSkin(EGUI_SKIN_TYPE type) = 0;\r
155 \r
156 \r
157         //! Creates the image list from the given texture.\r
158         /** \param texture Texture to split into images\r
159         \param imageSize Dimension of each image\r
160         \param useAlphaChannel Flag whether alpha channel of the texture should be honored.\r
161         \return Pointer to the font. Returns 0 if the font could not be loaded.\r
162         This pointer should not be dropped. See IReferenceCounted::drop() for\r
163         more information. */\r
164         virtual IGUIImageList* createImageList( video::ITexture* texture,\r
165                                         core::dimension2d<s32> imageSize,\r
166                                         bool useAlphaChannel ) = 0;\r
167 \r
168         //! Returns pointer to the font with the specified filename.\r
169         /** Loads the font if it was not loaded before.\r
170         \param filename Filename of the Font.\r
171         \return Pointer to the font. Returns 0 if the font could not be loaded.\r
172         This pointer should not be dropped. See IReferenceCounted::drop() for\r
173         more information. */\r
174         virtual IGUIFont* getFont(const io::path& filename) = 0;\r
175 \r
176         //! Adds an externally loaded font to the font list.\r
177         /** This method allows to attach an already loaded font to the list of\r
178         existing fonts. The font is grabbed if non-null and adding was successful.\r
179         \param name Name the font should be stored as.\r
180         \param font Pointer to font to add.\r
181         \return Pointer to the font stored. This can differ from given parameter if the name previously existed. */\r
182         virtual IGUIFont* addFont(const io::path& name, IGUIFont* font) = 0;\r
183 \r
184         //! remove loaded font\r
185         virtual void removeFont(IGUIFont* font) = 0;\r
186 \r
187         //! Returns the default built-in font.\r
188         /** \return Pointer to the default built-in font.\r
189         This pointer should not be dropped. See IReferenceCounted::drop() for\r
190         more information. */\r
191         virtual IGUIFont* getBuiltInFont() const = 0;\r
192 \r
193         //! Returns pointer to the sprite bank which was added with addEmptySpriteBank\r
194         /** TODO: This should load files in the future, but not implemented so far.\r
195         \param filename Name of a spritebank added with addEmptySpriteBank\r
196         \return Pointer to the sprite bank. Returns 0 if it could not be loaded.\r
197         This pointer should not be dropped. See IReferenceCounted::drop() for more information. */\r
198         virtual IGUISpriteBank* getSpriteBank(const io::path& filename) = 0;\r
199 \r
200         //! Adds an empty sprite bank to the manager\r
201         /** \param name Name of the new sprite bank.\r
202         \return Pointer to the sprite bank.\r
203         This pointer should not be dropped. See IReferenceCounted::drop() for more information. */\r
204         virtual IGUISpriteBank* addEmptySpriteBank(const io::path& name) = 0;\r
205 \r
206         //! Returns the root gui element.\r
207         /** This is the first gui element, the (direct or indirect) parent of all\r
208         other gui elements. It is a valid IGUIElement, with dimensions the same\r
209         size as the screen.\r
210         \return Pointer to the root element of the GUI. The returned pointer\r
211         should not be dropped. See IReferenceCounted::drop() for more\r
212         information. */\r
213         virtual IGUIElement* getRootGUIElement() = 0;\r
214 \r
215         //! Adds a button element.\r
216         /** \param rectangle Rectangle specifying the borders of the button.\r
217         \param parent Parent gui element of the button.\r
218         \param id Id with which the gui element can be identified.\r
219         \param text Text displayed on the button.\r
220         \param tooltiptext Text displayed in the tooltip.\r
221         \return Pointer to the created button. Returns 0 if an error occurred.\r
222         This pointer should not be dropped. See IReferenceCounted::drop() for\r
223         more information. */\r
224         virtual IGUIButton* addButton(const core::rect<s32>& rectangle,\r
225                 IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0, const wchar_t* tooltiptext = 0) = 0;\r
226 \r
227         //! Adds a scrollbar.\r
228         /** \param horizontal Specifies if the scroll bar is drawn horizontal\r
229         or vertical.\r
230         \param rectangle Rectangle specifying the borders of the scrollbar.\r
231         \param parent Parent gui element of the scroll bar.\r
232         \param id Id to identify the gui element.\r
233         \return Pointer to the created scrollbar. Returns 0 if an error\r
234         occurred. This pointer should not be dropped. See\r
235         IReferenceCounted::drop() for more information. */\r
236         virtual IGUIScrollBar* addScrollBar(bool horizontal, const core::rect<s32>& rectangle,\r
237                 IGUIElement* parent=0, s32 id=-1) = 0;\r
238 \r
239         //! Adds an image element.\r
240         /** \param image Image to be displayed.\r
241         \param pos Position of the image. The width and height of the image is\r
242         taken from the image.\r
243         \param useAlphaChannel Sets if the image should use the alpha channel\r
244         of the texture to draw itself.\r
245         \param parent Parent gui element of the image.\r
246         \param id Id to identify the gui element.\r
247         \param text Title text of the image (not displayed).\r
248         \return Pointer to the created image element. Returns 0 if an error\r
249         occurred. This pointer should not be dropped. See\r
250         IReferenceCounted::drop() for more information. */\r
251         virtual IGUIImage* addImage(video::ITexture* image, core::position2d<s32> pos,\r
252                 bool useAlphaChannel=true, IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0) = 0;\r
253 \r
254         //! Adds an image element.\r
255         /** Use IGUIImage::setImage later to set the image to be displayed.\r
256         \param rectangle Rectangle specifying the borders of the image.\r
257         \param parent Parent gui element of the image.\r
258         \param id Id to identify the gui element.\r
259         \param text Title text of the image (not displayed).\r
260         \param useAlphaChannel Sets if the image should use the alpha channel\r
261         of the texture to draw itself.\r
262         \return Pointer to the created image element. Returns 0 if an error\r
263         occurred. This pointer should not be dropped. See\r
264         IReferenceCounted::drop() for more information. */\r
265         virtual IGUIImage* addImage(const core::rect<s32>& rectangle,\r
266                 IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0, bool useAlphaChannel=true) = 0;\r
267 \r
268         //! Adds a checkbox element.\r
269         /** \param checked Define the initial state of the check box.\r
270         \param rectangle Rectangle specifying the borders of the check box.\r
271         \param parent Parent gui element of the check box.\r
272         \param id Id to identify the gui element.\r
273         \param text Title text of the check box.\r
274         \return Pointer to the created check box. Returns 0 if an error\r
275         occurred. This pointer should not be dropped. See\r
276         IReferenceCounted::drop() for more information. */\r
277         virtual IGUICheckBox* addCheckBox(bool checked, const core::rect<s32>& rectangle,\r
278                 IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0) = 0;\r
279 \r
280         //! Adds a list box element.\r
281         /** \param rectangle Rectangle specifying the borders of the list box.\r
282         \param parent Parent gui element of the list box.\r
283         \param id Id to identify the gui element.\r
284         \param drawBackground Flag whether the background should be drawn.\r
285         \return Pointer to the created list box. Returns 0 if an error occurred.\r
286         This pointer should not be dropped. See IReferenceCounted::drop() for\r
287         more information. */\r
288         virtual IGUIListBox* addListBox(const core::rect<s32>& rectangle,\r
289                 IGUIElement* parent=0, s32 id=-1, bool drawBackground=false) = 0;\r
290 \r
291         //! Adds a file open dialog.\r
292         /** \param title Text to be displayed as the title of the dialog.\r
293         \param modal Defines if the dialog is modal. This means, that all other\r
294         gui elements which were created before the message box cannot be used\r
295         until this messagebox is removed.\r
296         \param parent Parent gui element of the dialog.\r
297         \param id Id to identify the gui element.\r
298         \param restoreCWD If set to true, the current working directory will be\r
299         restored after the dialog is closed in some way. Otherwise the working\r
300         directory will be the one that the file dialog was last showing.\r
301         \param startDir Optional path for which the file dialog will be opened.\r
302         \return Pointer to the created file open dialog. Returns 0 if an error\r
303         occurred. This pointer should not be dropped. See\r
304         IReferenceCounted::drop() for more information. */\r
305         virtual IGUIFileOpenDialog* addFileOpenDialog(const wchar_t* title=0,\r
306                 bool modal=true, IGUIElement* parent=0, s32 id=-1,\r
307                 bool restoreCWD=false, io::path::char_type* startDir=0) = 0;\r
308 \r
309         //! Adds a static text.\r
310         /** \param text Text to be displayed. Can be altered after creation by SetText().\r
311         \param rectangle Rectangle specifying the borders of the static text\r
312         \param border Set to true if the static text should have a 3d border.\r
313         \param wordWrap Enable if the text should wrap into multiple lines.\r
314         \param parent Parent item of the element, e.g. a window.\r
315         \param id The ID of the element.\r
316         \param fillBackground Enable if the background shall be filled.\r
317         Defaults to false.\r
318         \return Pointer to the created static text. Returns 0 if an error\r
319         occurred. This pointer should not be dropped. See\r
320         IReferenceCounted::drop() for more information. */\r
321         virtual IGUIStaticText* addStaticText(const wchar_t* text, const core::rect<s32>& rectangle,\r
322                 bool border=false, bool wordWrap=true, IGUIElement* parent=0, s32 id=-1,\r
323                 bool fillBackground = false) = 0;\r
324 \r
325         //! Adds an edit box.\r
326         /** Supports Unicode input from every keyboard around the world,\r
327         scrolling, copying and pasting (exchanging data with the clipboard\r
328         directly), maximum character amount, marking, and all shortcuts like\r
329         ctrl+X, ctrl+V, ctrl+C, shift+Left, shift+Right, Home, End, and so on.\r
330         \param text Text to be displayed. Can be altered after creation\r
331         by setText().\r
332         \param rectangle Rectangle specifying the borders of the edit box.\r
333         \param border Set to true if the edit box should have a 3d border.\r
334         \param parent Parent item of the element, e.g. a window.\r
335         Set it to 0 to place the edit box directly in the environment.\r
336         \param id The ID of the element.\r
337         \return Pointer to the created edit box. Returns 0 if an error occurred.\r
338         This pointer should not be dropped. See IReferenceCounted::drop() for\r
339         more information. */\r
340         virtual IGUIEditBox* addEditBox(const wchar_t* text, const core::rect<s32>& rectangle,\r
341                 bool border=true, IGUIElement* parent=0, s32 id=-1) = 0;\r
342 \r
343         //! Adds a tab control to the environment.\r
344         /** \param rectangle Rectangle specifying the borders of the tab control.\r
345         \param parent Parent item of the element, e.g. a window.\r
346         Set it to 0 to place the tab control directly in the environment.\r
347         \param fillbackground Specifies if the background of the tab control\r
348         should be drawn.\r
349         \param border Specifies if a flat 3d border should be drawn. This is\r
350         usually not necessary unless you place the control directly into\r
351         the environment without a window as parent.\r
352         \param id An identifier for the tab control.\r
353         \return Pointer to the created tab control element. Returns 0 if an\r
354         error occurred. This pointer should not be dropped. See\r
355         IReferenceCounted::drop() for more information. */\r
356         virtual IGUITabControl* addTabControl(const core::rect<s32>& rectangle,\r
357                 IGUIElement* parent=0, bool fillbackground=false,\r
358                 bool border=true, s32 id=-1) = 0;\r
359 \r
360         //! Adds tab to the environment.\r
361         /** You can use this element to group other elements. This is not used\r
362         for creating tabs on tab controls, please use IGUITabControl::addTab()\r
363         for this instead.\r
364         \param rectangle Rectangle specifying the borders of the tab.\r
365         \param parent Parent item of the element, e.g. a window.\r
366         Set it to 0 to place the tab directly in the environment.\r
367         \param id An identifier for the tab.\r
368         \return Pointer to the created tab. Returns 0 if an\r
369         error occurred. This pointer should not be dropped. See\r
370         IReferenceCounted::drop() for more information. */\r
371         virtual IGUITab* addTab(const core::rect<s32>& rectangle,\r
372                 IGUIElement* parent=0, s32 id=-1) = 0;\r
373 \r
374         //! Adds a combo box to the environment.\r
375         /** \param rectangle Rectangle specifying the borders of the combo box.\r
376         \param parent Parent item of the element, e.g. a window.\r
377         Set it to 0 to place the combo box directly in the environment.\r
378         \param id An identifier for the combo box.\r
379         \return Pointer to the created combo box. Returns 0 if an\r
380         error occurred. This pointer should not be dropped. See\r
381         IReferenceCounted::drop() for more information. */\r
382         virtual IGUIComboBox* addComboBox(const core::rect<s32>& rectangle,\r
383                 IGUIElement* parent=0, s32 id=-1) = 0;\r
384 \r
385         //! Find the next element which would be selected when pressing the tab-key\r
386         /** If you set the focus for the result you can manually force focus-changes like they\r
387         would happen otherwise by the tab-keys.\r
388         \param reverse When true it will search backward (toward lower TabOrder numbers, like shift+tab)\r
389         \param group When true it will search for the next tab-group (like ctrl+tab)\r
390         */\r
391         virtual IGUIElement* getNextElement(bool reverse=false, bool group=false) = 0;\r
392 \r
393         //! Set the way the gui will handle automatic focus changes\r
394         /** The default is (EFF_SET_ON_LMOUSE_DOWN | EFF_SET_ON_TAB).\r
395         with the left mouse button.\r
396         This does not affect the setFocus function itself - users can still call that whenever they want on any element.\r
397         \param flags A bitmask which is a combination of ::EFOCUS_FLAG flags.*/\r
398         virtual void setFocusBehavior(u32 flags) = 0;\r
399 \r
400         //! Get the way the gui does handle focus changes\r
401         /** \returns A bitmask which is a combination of ::EFOCUS_FLAG flags.*/\r
402         virtual u32 getFocusBehavior() const = 0;\r
403 \r
404         //! Adds a IGUIElement to deletion queue.\r
405         /** Queued elements will be removed at the end of each drawAll call.\r
406         Or latest in the destructor of the GUIEnvironment.\r
407         This can be used to allow an element removing itself safely in a function \r
408         iterating over gui elements, like an overloaded IGUIElement::draw or \r
409         IGUIElement::OnPostRender function.\r
410         Note that in general just calling IGUIElement::remove() is enough. \r
411         Unless you create your own GUI elements removing themselves you won't need it.\r
412         \param element: Element to remove */\r
413         virtual void addToDeletionQueue(IGUIElement* element) = 0;\r
414 };\r
415 \r
416 \r
417 } // end namespace gui\r
418 } // end namespace irr\r
419 \r
420 #endif\r
421 \r