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 void drawAll(bool useScreenSize) override;
\r
36 //! returns the current video driver
\r
37 video::IVideoDriver* getVideoDriver() const override;
\r
39 //! returns pointer to the filesystem
\r
40 io::IFileSystem* getFileSystem() const override;
\r
42 //! returns a pointer to the OS operator
\r
43 IOSOperator* getOSOperator() const override;
\r
45 //! posts an input event to the environment
\r
46 bool postEventFromUser(const SEvent& event) 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 void setUserEventReceiver(IEventReceiver* evr) override;
\r
52 //! removes all elements from the environment
\r
53 void clear() override;
\r
55 //! called if an event happened.
\r
56 bool OnEvent(const SEvent& event) override;
\r
58 //! returns the current gui skin
\r
59 IGUISkin* getSkin() const override;
\r
61 //! Sets a new GUI Skin
\r
62 void setSkin(IGUISkin* skin) 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 IGUISkin* createSkin(EGUI_SKIN_TYPE type) 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) override;
\r
74 //! returns the font
\r
75 IGUIFont* getFont(const io::path& filename) override;
\r
77 //! add an externally loaded font
\r
78 IGUIFont* addFont(const io::path& name, IGUIFont* font) override;
\r
80 //! remove loaded font
\r
81 void removeFont(IGUIFont* font) override;
\r
83 //! returns default font
\r
84 IGUIFont* getBuiltInFont() const override;
\r
86 //! returns the sprite bank
\r
87 IGUISpriteBank* getSpriteBank(const io::path& filename) override;
\r
89 //! returns the sprite bank
\r
90 IGUISpriteBank* addEmptySpriteBank(const io::path& name) override;
\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
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
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
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
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
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
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
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
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
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
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
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
140 //! sets the focus to an element
\r
141 bool setFocus(IGUIElement* element) override;
\r
143 //! removes the focus from an element
\r
144 bool removeFocus(IGUIElement* element) override;
\r
146 //! Returns if the element has focus
\r
147 bool hasFocus(const IGUIElement* element, bool checkSubElements=false) const override;
\r
149 //! Returns the element with the focus
\r
150 IGUIElement* getFocus() const override;
\r
152 //! Returns the element last known to be under the mouse
\r
153 IGUIElement* getHovered() const override;
\r
155 //! Returns the root gui element.
\r
156 IGUIElement* getRootGUIElement() override;
\r
158 void OnPostRender( u32 time ) override;
\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
163 //! Set the way the gui will handle focus changes
\r
164 void setFocusBehavior(u32 flags) override;
\r
166 //! Get the way the gui does handle focus changes
\r
167 u32 getFocusBehavior() const override;
\r
169 //! Adds a IGUIElement to deletion queue.
\r
170 void addToDeletionQueue(IGUIElement* element) override;
\r
174 //! clears the deletion queue
\r
175 void clearDeletionQueue();
\r
177 void updateHoveredElement(core::position2d<s32> mousePos);
\r
179 void loadBuiltInFont();
\r
183 io::SNamedPath NamedPath;
\r
186 bool operator < (const SFont& other) const
\r
188 return (NamedPath < other.NamedPath);
\r
194 io::SNamedPath NamedPath;
\r
195 IGUISpriteBank* Bank;
\r
197 bool operator < (const SSpriteBank& other) const
\r
199 return (NamedPath < other.NamedPath);
\r
205 IGUIStaticText* Element;
\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
226 core::array<IGUIElement*> DeletionQueue;
\r
228 static const io::path DefaultFontName;
\r
231 } // end namespace gui
\r
232 } // end namespace irr
\r
234 #endif // _IRR_COMPILE_WITH_GUI_
\r
236 #endif // __C_GUI_ENVIRONMENT_H_INCLUDED__
\r