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 #include "IGUIEnvironment.h"
\r
10 #include "IGUIElement.h"
\r
11 #include "irrArray.h"
\r
12 #include "IFileSystem.h"
\r
13 #include "IOSOperator.h"
\r
21 class CGUIEnvironment : public IGUIEnvironment, public IGUIElement
\r
26 CGUIEnvironment(io::IFileSystem* fs, video::IVideoDriver* driver, IOSOperator* op);
\r
29 virtual ~CGUIEnvironment();
\r
31 //! draws all gui elements
\r
32 void drawAll(bool useScreenSize) override;
\r
34 //! returns the current video driver
\r
35 video::IVideoDriver* getVideoDriver() const override;
\r
37 //! returns pointer to the filesystem
\r
38 io::IFileSystem* getFileSystem() const override;
\r
40 //! returns a pointer to the OS operator
\r
41 IOSOperator* getOSOperator() const override;
\r
43 //! posts an input event to the environment
\r
44 bool postEventFromUser(const SEvent& event) override;
\r
46 //! This sets a new event receiver for gui events. Usually you do not have to
\r
47 //! use this method, it is used by the internal engine.
\r
48 void setUserEventReceiver(IEventReceiver* evr) override;
\r
50 //! removes all elements from the environment
\r
51 void clear() override;
\r
53 //! called if an event happened.
\r
54 bool OnEvent(const SEvent& event) override;
\r
56 //! returns the current gui skin
\r
57 IGUISkin* getSkin() const override;
\r
59 //! Sets a new GUI Skin
\r
60 void setSkin(IGUISkin* skin) override;
\r
62 //! Creates a new GUI Skin based on a template.
\r
63 /** \return Returns a pointer to the created skin.
\r
64 If you no longer need the skin, you should call IGUISkin::drop().
\r
65 See IReferenceCounted::drop() for more information. */
\r
66 IGUISkin* createSkin(EGUI_SKIN_TYPE type) override;
\r
68 //! Creates the image list from the given texture.
\r
69 virtual IGUIImageList* createImageList(video::ITexture* texture,
\r
70 core::dimension2d<s32> imageSize, bool useAlphaChannel) override;
\r
72 //! returns the font
\r
73 IGUIFont* getFont(const io::path& filename) override;
\r
75 //! add an externally loaded font
\r
76 IGUIFont* addFont(const io::path& name, IGUIFont* font) override;
\r
78 //! remove loaded font
\r
79 void removeFont(IGUIFont* font) override;
\r
81 //! returns default font
\r
82 IGUIFont* getBuiltInFont() const override;
\r
84 //! returns the sprite bank
\r
85 IGUISpriteBank* getSpriteBank(const io::path& filename) override;
\r
87 //! returns the sprite bank
\r
88 IGUISpriteBank* addEmptySpriteBank(const io::path& name) override;
\r
90 //! adds an button. The returned pointer must not be dropped.
\r
91 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
93 //! adds a scrollbar. The returned pointer must not be dropped.
\r
94 virtual IGUIScrollBar* addScrollBar(bool horizontal, const core::rect<s32>& rectangle,
\r
95 IGUIElement* parent=0, s32 id=-1) override;
\r
97 //! Adds an image element.
\r
98 virtual IGUIImage* addImage(video::ITexture* image, core::position2d<s32> pos,
\r
99 bool useAlphaChannel=true, IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0) override;
\r
101 //! adds an image. The returned pointer must not be dropped.
\r
102 virtual IGUIImage* addImage(const core::rect<s32>& rectangle,
\r
103 IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0, bool useAlphaChannel=true) override;
\r
105 //! adds a checkbox
\r
106 virtual IGUICheckBox* addCheckBox(bool checked, const core::rect<s32>& rectangle,
\r
107 IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0) override;
\r
109 //! adds a list box
\r
110 virtual IGUIListBox* addListBox(const core::rect<s32>& rectangle,
\r
111 IGUIElement* parent=0, s32 id=-1, bool drawBackground=false) override;
\r
113 //! Adds a file open dialog.
\r
114 virtual IGUIFileOpenDialog* addFileOpenDialog(const wchar_t* title = 0,
\r
115 bool modal=true, IGUIElement* parent=0, s32 id=-1,
\r
116 bool restoreCWD=false, io::path::char_type* startDir=0) override;
\r
118 //! adds a static text. The returned pointer must not be dropped.
\r
119 virtual IGUIStaticText* addStaticText(const wchar_t* text, const core::rect<s32>& rectangle,
\r
120 bool border=false, bool wordWrap=true, IGUIElement* parent=0, s32 id=-1, bool drawBackground = false) override;
\r
122 //! Adds an edit box. The returned pointer must not be dropped.
\r
123 virtual IGUIEditBox* addEditBox(const wchar_t* text, const core::rect<s32>& rectangle,
\r
124 bool border=false, IGUIElement* parent=0, s32 id=-1) override;
\r
126 //! Adds a tab control to the environment.
\r
127 virtual IGUITabControl* addTabControl(const core::rect<s32>& rectangle,
\r
128 IGUIElement* parent=0, bool fillbackground=false, bool border=true, s32 id=-1) override;
\r
130 //! Adds tab to the environment.
\r
131 virtual IGUITab* addTab(const core::rect<s32>& rectangle,
\r
132 IGUIElement* parent=0, s32 id=-1) override;
\r
134 //! Adds a combo box to the environment.
\r
135 virtual IGUIComboBox* addComboBox(const core::rect<s32>& rectangle,
\r
136 IGUIElement* parent=0, s32 id=-1) override;
\r
138 //! sets the focus to an element
\r
139 bool setFocus(IGUIElement* element) override;
\r
141 //! removes the focus from an element
\r
142 bool removeFocus(IGUIElement* element) override;
\r
144 //! Returns if the element has focus
\r
145 bool hasFocus(const IGUIElement* element, bool checkSubElements=false) const override;
\r
147 //! Returns the element with the focus
\r
148 IGUIElement* getFocus() const override;
\r
150 //! Returns the element last known to be under the mouse
\r
151 IGUIElement* getHovered() const override;
\r
153 //! Returns the root gui element.
\r
154 IGUIElement* getRootGUIElement() override;
\r
156 void OnPostRender( u32 time ) override;
\r
158 //! Find the next element which would be selected when pressing the tab-key
\r
159 IGUIElement* getNextElement(bool reverse=false, bool group=false) override;
\r
161 //! Set the way the gui will handle focus changes
\r
162 void setFocusBehavior(u32 flags) override;
\r
164 //! Get the way the gui does handle focus changes
\r
165 u32 getFocusBehavior() const override;
\r
167 //! Adds a IGUIElement to deletion queue.
\r
168 void addToDeletionQueue(IGUIElement* element) override;
\r
172 //! clears the deletion queue
\r
173 void clearDeletionQueue();
\r
175 void updateHoveredElement(core::position2d<s32> mousePos);
\r
177 void loadBuiltInFont();
\r
181 io::SNamedPath NamedPath;
\r
184 bool operator < (const SFont& other) const
\r
186 return (NamedPath < other.NamedPath);
\r
192 io::SNamedPath NamedPath;
\r
193 IGUISpriteBank* Bank;
\r
195 bool operator < (const SSpriteBank& other) const
\r
197 return (NamedPath < other.NamedPath);
\r
203 IGUIStaticText* Element;
\r
212 core::array<SFont> Fonts;
\r
213 core::array<SSpriteBank> Banks;
\r
214 video::IVideoDriver* Driver;
\r
215 IGUIElement* Hovered;
\r
216 IGUIElement* HoveredNoSubelement; // subelements replaced by their parent, so you only have 'real' elements here
\r
217 IGUIElement* Focus;
\r
218 core::position2d<s32> LastHoveredMousePos;
\r
219 IGUISkin* CurrentSkin;
\r
220 io::IFileSystem* FileSystem;
\r
221 IEventReceiver* UserReceiver;
\r
222 IOSOperator* Operator;
\r
224 core::array<IGUIElement*> DeletionQueue;
\r
226 static const io::path DefaultFontName;
\r
229 } // end namespace gui
\r
230 } // end namespace irr
\r
232 #endif // __C_GUI_ENVIRONMENT_H_INCLUDED__
\r