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
5 #ifndef __C_GUI_ENVIRONMENT_H_INCLUDED__
\r
6 #define __C_GUI_ENVIRONMENT_H_INCLUDED__
\r
8 #include "IrrCompileConfig.h"
\r
9 #ifdef _IRR_COMPILE_WITH_GUI_
\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
23 class CGUIEnvironment : public IGUIEnvironment, public IGUIElement
\r
28 CGUIEnvironment(io::IFileSystem* fs, video::IVideoDriver* driver, IOSOperator* op);
\r
31 virtual ~CGUIEnvironment();
\r
33 //! draws all gui elements
\r
34 virtual void drawAll(bool useScreenSize) _IRR_OVERRIDE_;
\r
36 //! returns the current video driver
\r
37 virtual video::IVideoDriver* getVideoDriver() const _IRR_OVERRIDE_;
\r
39 //! returns pointer to the filesystem
\r
40 virtual io::IFileSystem* getFileSystem() const _IRR_OVERRIDE_;
\r
42 //! returns a pointer to the OS operator
\r
43 virtual IOSOperator* getOSOperator() const _IRR_OVERRIDE_;
\r
45 //! posts an input event to the environment
\r
46 virtual bool postEventFromUser(const SEvent& event) _IRR_OVERRIDE_;
\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
52 //! removes all elements from the environment
\r
53 virtual void clear() _IRR_OVERRIDE_;
\r
55 //! called if an event happened.
\r
56 virtual bool OnEvent(const SEvent& event) _IRR_OVERRIDE_;
\r
58 //! returns the current gui skin
\r
59 virtual IGUISkin* getSkin() const _IRR_OVERRIDE_;
\r
61 //! Sets a new GUI Skin
\r
62 virtual void setSkin(IGUISkin* skin) _IRR_OVERRIDE_;
\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
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
74 //! returns the font
\r
75 virtual IGUIFont* getFont(const io::path& filename) _IRR_OVERRIDE_;
\r
77 //! add an externally loaded font
\r
78 virtual IGUIFont* addFont(const io::path& name, IGUIFont* font) _IRR_OVERRIDE_;
\r
80 //! remove loaded font
\r
81 virtual void removeFont(IGUIFont* font) _IRR_OVERRIDE_;
\r
83 //! returns default font
\r
84 virtual IGUIFont* getBuiltInFont() const _IRR_OVERRIDE_;
\r
86 //! returns the sprite bank
\r
87 virtual IGUISpriteBank* getSpriteBank(const io::path& filename) _IRR_OVERRIDE_;
\r
89 //! returns the sprite bank
\r
90 virtual IGUISpriteBank* addEmptySpriteBank(const io::path& name) _IRR_OVERRIDE_;
\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
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
99 //! adds a modal screen. The returned pointer must not be dropped.
\r
100 virtual IGUIElement* addModalScreen(IGUIElement* parent, int blinkMode) _IRR_OVERRIDE_;
\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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
168 //! Adds a menu to the environment.
\r
169 virtual IGUIContextMenu* addMenu(IGUIElement* parent=0, s32 id=-1) _IRR_OVERRIDE_;
\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
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
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
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
187 //! sets the focus to an element
\r
188 virtual bool setFocus(IGUIElement* element) _IRR_OVERRIDE_;
\r
190 //! removes the focus from an element
\r
191 virtual bool removeFocus(IGUIElement* element) _IRR_OVERRIDE_;
\r
193 //! Returns if the element has focus
\r
194 virtual bool hasFocus(const IGUIElement* element, bool checkSubElements=false) const _IRR_OVERRIDE_;
\r
196 //! Returns the element with the focus
\r
197 virtual IGUIElement* getFocus() const _IRR_OVERRIDE_;
\r
199 //! Returns the element last known to be under the mouse
\r
200 virtual IGUIElement* getHovered() const _IRR_OVERRIDE_;
\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
205 //! Returns the root gui element.
\r
206 virtual IGUIElement* getRootGUIElement() _IRR_OVERRIDE_;
\r
208 virtual void OnPostRender( u32 time ) _IRR_OVERRIDE_;
\r
210 //! Returns the default element factory which can create all built in elements
\r
211 virtual IGUIElementFactory* getDefaultGUIElementFactory() const _IRR_OVERRIDE_;
\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
218 //! Returns amount of registered scene node factories.
\r
219 virtual u32 getRegisteredGUIElementFactoryCount() const _IRR_OVERRIDE_;
\r
221 //! Returns a scene node factory by index
\r
222 virtual IGUIElementFactory* getGUIElementFactory(u32 index) const _IRR_OVERRIDE_;
\r
224 //! Adds a GUI Element by its name
\r
225 virtual IGUIElement* addGUIElement(const c8* elementName, IGUIElement* parent=0) _IRR_OVERRIDE_;
\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
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
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
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
251 //! Writes attributes of the environment
\r
252 virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const _IRR_OVERRIDE_;
\r
254 //! Reads attributes of the environment.
\r
255 virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0) _IRR_OVERRIDE_;
\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
260 //! Set the way the gui will handle focus changes
\r
261 virtual void setFocusBehavior(u32 flags) _IRR_OVERRIDE_;
\r
263 //! Get the way the gui does handle focus changes
\r
264 virtual u32 getFocusBehavior() const _IRR_OVERRIDE_;
\r
266 //! Adds a IGUIElement to deletion queue.
\r
267 virtual void addToDeletionQueue(IGUIElement* element) _IRR_OVERRIDE_;
\r
271 //! clears the deletion queue
\r
272 void clearDeletionQueue();
\r
274 void updateHoveredElement(core::position2d<s32> mousePos);
\r
276 void loadBuiltInFont();
\r
280 io::SNamedPath NamedPath;
\r
283 bool operator < (const SFont& other) const
\r
285 return (NamedPath < other.NamedPath);
\r
291 io::SNamedPath NamedPath;
\r
292 IGUISpriteBank* Bank;
\r
294 bool operator < (const SSpriteBank& other) const
\r
296 return (NamedPath < other.NamedPath);
\r
302 IGUIStaticText* Element;
\r
311 core::array<IGUIElementFactory*> GUIElementFactoryList;
\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
325 core::array<IGUIElement*> DeletionQueue;
\r
327 static const io::path DefaultFontName;
\r
330 } // end namespace gui
\r
331 } // end namespace irr
\r
333 #endif // _IRR_COMPILE_WITH_GUI_
\r
335 #endif // __C_GUI_ENVIRONMENT_H_INCLUDED__
\r