]> git.lizzy.rs Git - irrlicht.git/blob - source/Irrlicht/CGUIEnvironment.h
2a6097c06afc2bce106174c243a46430c6b0571d
[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 #include "IGUIEnvironment.h"\r
10 #include "IGUIElement.h"\r
11 #include "irrArray.h"\r
12 #include "IFileSystem.h"\r
13 #include "IOSOperator.h"\r
14 \r
15 namespace irr\r
16 {\r
17 \r
18 namespace gui\r
19 {\r
20 \r
21 class CGUIEnvironment : public IGUIEnvironment, public IGUIElement\r
22 {\r
23 public:\r
24 \r
25         //! constructor\r
26         CGUIEnvironment(io::IFileSystem* fs, video::IVideoDriver* driver, IOSOperator* op);\r
27 \r
28         //! destructor\r
29         virtual ~CGUIEnvironment();\r
30 \r
31         //! draws all gui elements\r
32         void drawAll(bool useScreenSize) override;\r
33 \r
34         //! returns the current video driver\r
35         video::IVideoDriver* getVideoDriver() const override;\r
36 \r
37         //! returns pointer to the filesystem\r
38         io::IFileSystem* getFileSystem() const override;\r
39 \r
40         //! returns a pointer to the OS operator\r
41         IOSOperator* getOSOperator() const override;\r
42 \r
43         //! posts an input event to the environment\r
44         bool postEventFromUser(const SEvent& event) override;\r
45 \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
49 \r
50         //! removes all elements from the environment\r
51         void clear() override;\r
52 \r
53         //! called if an event happened.\r
54         bool OnEvent(const SEvent& event) override;\r
55 \r
56         //! returns the current gui skin\r
57         IGUISkin* getSkin() const override;\r
58 \r
59         //! Sets a new GUI Skin\r
60         void setSkin(IGUISkin* skin) override;\r
61 \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
67 \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
71 \r
72         //! returns the font\r
73         IGUIFont* getFont(const io::path& filename) override;\r
74 \r
75         //! add an externally loaded font\r
76         IGUIFont* addFont(const io::path& name, IGUIFont* font) override;\r
77 \r
78         //! remove loaded font\r
79         void removeFont(IGUIFont* font) override;\r
80 \r
81         //! returns default font\r
82         IGUIFont* getBuiltInFont() const override;\r
83 \r
84         //! returns the sprite bank\r
85         IGUISpriteBank* getSpriteBank(const io::path& filename) override;\r
86 \r
87         //! returns the sprite bank\r
88         IGUISpriteBank* addEmptySpriteBank(const io::path& name) override;\r
89 \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
92 \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
96 \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
100 \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
104 \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
108 \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
112 \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
117 \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
121 \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
125 \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
129 \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
133 \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
137 \r
138         //! sets the focus to an element\r
139         bool setFocus(IGUIElement* element) override;\r
140 \r
141         //! removes the focus from an element\r
142         bool removeFocus(IGUIElement* element) override;\r
143 \r
144         //! Returns if the element has focus\r
145         bool hasFocus(const IGUIElement* element, bool checkSubElements=false) const override;\r
146 \r
147         //! Returns the element with the focus\r
148         IGUIElement* getFocus() const override;\r
149 \r
150         //! Returns the element last known to be under the mouse\r
151         IGUIElement* getHovered() const override;\r
152 \r
153         //! Returns the root gui element.\r
154         IGUIElement* getRootGUIElement() override;\r
155 \r
156         void OnPostRender( u32 time ) override;\r
157 \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
160 \r
161         //! Set the way the gui will handle focus changes\r
162         void setFocusBehavior(u32 flags) override;\r
163 \r
164         //! Get the way the gui does handle focus changes\r
165         u32 getFocusBehavior() const override;\r
166 \r
167         //! Adds a IGUIElement to deletion queue.\r
168         void addToDeletionQueue(IGUIElement* element) override;\r
169 \r
170 private:\r
171 \r
172         //! clears the deletion queue\r
173         void clearDeletionQueue();\r
174 \r
175         void updateHoveredElement(core::position2d<s32> mousePos);\r
176 \r
177         void loadBuiltInFont();\r
178 \r
179         struct SFont\r
180         {\r
181                 io::SNamedPath NamedPath;\r
182                 IGUIFont* Font;\r
183 \r
184                 bool operator < (const SFont& other) const\r
185                 {\r
186                         return (NamedPath < other.NamedPath);\r
187                 }\r
188         };\r
189 \r
190         struct SSpriteBank\r
191         {\r
192                 io::SNamedPath NamedPath;\r
193                 IGUISpriteBank* Bank;\r
194 \r
195                 bool operator < (const SSpriteBank& other) const\r
196                 {\r
197                         return (NamedPath < other.NamedPath);\r
198                 }\r
199         };\r
200 \r
201         struct SToolTip\r
202         {\r
203                 IGUIStaticText* Element;\r
204                 u32 LastTime;\r
205                 u32 EnterTime;\r
206                 u32 LaunchTime;\r
207                 u32 RelaunchTime;\r
208         };\r
209 \r
210         SToolTip ToolTip;\r
211 \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
223         u32 FocusFlags;\r
224         core::array<IGUIElement*> DeletionQueue;\r
225 \r
226         static const io::path DefaultFontName;\r
227 };\r
228 \r
229 } // end namespace gui\r
230 } // end namespace irr\r
231 \r
232 #endif // __C_GUI_ENVIRONMENT_H_INCLUDED__\r