IGUIEnvironment.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  1. // Copyright (C) 2002-2012 Nikolaus Gebhardt
  2. // This file is part of the "Irrlicht Engine".
  3. // For conditions of distribution and use, see copyright notice in irrlicht.h
  4. #ifndef __I_GUI_ENVIRONMENT_H_INCLUDED__
  5. #define __I_GUI_ENVIRONMENT_H_INCLUDED__
  6. #include "IReferenceCounted.h"
  7. #include "IGUISkin.h"
  8. #include "rect.h"
  9. #include "EMessageBoxFlags.h"
  10. #include "EFocusFlags.h"
  11. #include "IEventReceiver.h"
  12. #include "IXMLReader.h"
  13. #include "IXMLWriter.h"
  14. #include "path.h"
  15. namespace irr
  16. {
  17. class IOSOperator;
  18. class IEventReceiver;
  19. namespace io
  20. {
  21. class IReadFile;
  22. class IWriteFile;
  23. class IFileSystem;
  24. } // end namespace io
  25. namespace video
  26. {
  27. class IVideoDriver;
  28. class ITexture;
  29. } // end namespace video
  30. namespace gui
  31. {
  32. class IGUIElement;
  33. class IGUIFont;
  34. class IGUISpriteBank;
  35. class IGUIScrollBar;
  36. class IGUIImage;
  37. class IGUIMeshViewer;
  38. class IGUICheckBox;
  39. class IGUIListBox;
  40. class IGUITreeView;
  41. class IGUIImageList;
  42. class IGUIFileOpenDialog;
  43. class IGUIColorSelectDialog;
  44. class IGUIInOutFader;
  45. class IGUIStaticText;
  46. class IGUIEditBox;
  47. class IGUISpinBox;
  48. class IGUITabControl;
  49. class IGUITab;
  50. class IGUITable;
  51. class IGUIContextMenu;
  52. class IGUIComboBox;
  53. class IGUIToolBar;
  54. class IGUIButton;
  55. class IGUIWindow;
  56. class IGUIProfiler;
  57. class IGUIElementFactory;
  58. //! GUI Environment. Used as factory and manager of all other GUI elements.
  59. /** \par This element can create the following events of type EGUI_EVENT_TYPE (which are passed on to focused sub-elements):
  60. \li EGET_ELEMENT_FOCUS_LOST
  61. \li EGET_ELEMENT_FOCUSED
  62. \li EGET_ELEMENT_LEFT
  63. \li EGET_ELEMENT_HOVERED
  64. */
  65. class IGUIEnvironment : public virtual IReferenceCounted
  66. {
  67. public:
  68. //! Draws all gui elements by traversing the GUI environment starting at the root node.
  69. /** \param When true ensure the GuiEnvironment (aka the RootGUIElement) has the same size as the current driver screensize.
  70. Can be set to false to control that size yourself, p.E when not the full size should be used for UI. */
  71. virtual void drawAll(bool useScreenSize=true) = 0;
  72. //! Sets the focus to an element.
  73. /** Causes a EGET_ELEMENT_FOCUS_LOST event followed by a
  74. EGET_ELEMENT_FOCUSED event. If someone absorbed either of the events,
  75. then the focus will not be changed.
  76. \param element Pointer to the element which shall get the focus.
  77. \return True on success, false on failure */
  78. virtual bool setFocus(IGUIElement* element) = 0;
  79. //! Returns the element which holds the focus.
  80. /** \return Pointer to the element with focus. */
  81. virtual IGUIElement* getFocus() const = 0;
  82. //! Returns the element which was last under the mouse cursor
  83. /** NOTE: This information is updated _after_ the user-eventreceiver
  84. received it's mouse-events. To find the hovered element while catching
  85. mouse events you have to use instead:
  86. IGUIEnvironment::getRootGUIElement()->getElementFromPoint(mousePos);
  87. \return Pointer to the element under the mouse. */
  88. virtual IGUIElement* getHovered() const = 0;
  89. //! Removes the focus from an element.
  90. /** Causes a EGET_ELEMENT_FOCUS_LOST event. If the event is absorbed
  91. then the focus will not be changed.
  92. \param element Pointer to the element which shall lose the focus.
  93. \return True on success, false on failure */
  94. virtual bool removeFocus(IGUIElement* element) = 0;
  95. //! Returns whether the element has focus
  96. /** \param element Pointer to the element which is tested.
  97. \param checkSubElements When true and focus is on a sub-element of element then it will still count as focused and return true
  98. \return True if the element has focus, else false. */
  99. virtual bool hasFocus(const IGUIElement* element, bool checkSubElements=false) const = 0;
  100. //! Returns the current video driver.
  101. /** \return Pointer to the video driver. */
  102. virtual video::IVideoDriver* getVideoDriver() const = 0;
  103. //! Returns the file system.
  104. /** \return Pointer to the file system. */
  105. virtual io::IFileSystem* getFileSystem() const = 0;
  106. //! returns a pointer to the OS operator
  107. /** \return Pointer to the OS operator. */
  108. virtual IOSOperator* getOSOperator() const = 0;
  109. //! Removes all elements from the environment.
  110. virtual void clear() = 0;
  111. //! Posts an input event to the environment.
  112. /** Usually you do not have to
  113. use this method, it is used by the engine internally.
  114. \param event The event to post.
  115. \return True if succeeded, else false. */
  116. virtual bool postEventFromUser(const SEvent& event) = 0;
  117. //! This sets a new event receiver for gui events.
  118. /** Usually you do not have to
  119. use this method, it is used by the engine internally.
  120. \param evr Pointer to the new receiver. */
  121. virtual void setUserEventReceiver(IEventReceiver* evr) = 0;
  122. //! Returns pointer to the current gui skin.
  123. /** \return Pointer to the GUI skin. */
  124. virtual IGUISkin* getSkin() const = 0;
  125. //! Sets a new GUI Skin
  126. /** You can use this to change the appearance of the whole GUI
  127. Environment. You can set one of the built-in skins or implement your
  128. own class derived from IGUISkin and enable it using this method.
  129. To set for example the built-in Windows classic skin, use the following
  130. code:
  131. \code
  132. gui::IGUISkin* newskin = environment->createSkin(gui::EGST_WINDOWS_CLASSIC);
  133. environment->setSkin(newskin);
  134. newskin->drop();
  135. \endcode
  136. \param skin New skin to use.
  137. */
  138. virtual void setSkin(IGUISkin* skin) = 0;
  139. //! Creates a new GUI Skin based on a template.
  140. /** Use setSkin() to set the created skin.
  141. \param type The type of the new skin.
  142. \return Pointer to the created skin.
  143. If you no longer need it, you should call IGUISkin::drop().
  144. See IReferenceCounted::drop() for more information. */
  145. virtual IGUISkin* createSkin(EGUI_SKIN_TYPE type) = 0;
  146. //! Creates the image list from the given texture.
  147. /** \param texture Texture to split into images
  148. \param imageSize Dimension of each image
  149. \param useAlphaChannel Flag whether alpha channel of the texture should be honored.
  150. \return Pointer to the font. Returns 0 if the font could not be loaded.
  151. This pointer should not be dropped. See IReferenceCounted::drop() for
  152. more information. */
  153. virtual IGUIImageList* createImageList( video::ITexture* texture,
  154. core::dimension2d<s32> imageSize,
  155. bool useAlphaChannel ) = 0;
  156. //! Returns pointer to the font with the specified filename.
  157. /** Loads the font if it was not loaded before.
  158. \param filename Filename of the Font.
  159. \return Pointer to the font. Returns 0 if the font could not be loaded.
  160. This pointer should not be dropped. See IReferenceCounted::drop() for
  161. more information. */
  162. virtual IGUIFont* getFont(const io::path& filename) = 0;
  163. //! Adds an externally loaded font to the font list.
  164. /** This method allows to attach an already loaded font to the list of
  165. existing fonts. The font is grabbed if non-null and adding was successful.
  166. \param name Name the font should be stored as.
  167. \param font Pointer to font to add.
  168. \return Pointer to the font stored. This can differ from given parameter if the name previously existed. */
  169. virtual IGUIFont* addFont(const io::path& name, IGUIFont* font) = 0;
  170. //! remove loaded font
  171. virtual void removeFont(IGUIFont* font) = 0;
  172. //! Returns the default built-in font.
  173. /** \return Pointer to the default built-in font.
  174. This pointer should not be dropped. See IReferenceCounted::drop() for
  175. more information. */
  176. virtual IGUIFont* getBuiltInFont() const = 0;
  177. //! Returns pointer to the sprite bank which was added with addEmptySpriteBank
  178. /** TODO: This should load files in the future, but not implemented so far.
  179. \param filename Name of a spritebank added with addEmptySpriteBank
  180. \return Pointer to the sprite bank. Returns 0 if it could not be loaded.
  181. This pointer should not be dropped. See IReferenceCounted::drop() for more information. */
  182. virtual IGUISpriteBank* getSpriteBank(const io::path& filename) = 0;
  183. //! Adds an empty sprite bank to the manager
  184. /** \param name Name of the new sprite bank.
  185. \return Pointer to the sprite bank.
  186. This pointer should not be dropped. See IReferenceCounted::drop() for more information. */
  187. virtual IGUISpriteBank* addEmptySpriteBank(const io::path& name) = 0;
  188. //! Returns the root gui element.
  189. /** This is the first gui element, the (direct or indirect) parent of all
  190. other gui elements. It is a valid IGUIElement, with dimensions the same
  191. size as the screen.
  192. \return Pointer to the root element of the GUI. The returned pointer
  193. should not be dropped. See IReferenceCounted::drop() for more
  194. information. */
  195. virtual IGUIElement* getRootGUIElement() = 0;
  196. //! Adds a button element.
  197. /** \param rectangle Rectangle specifying the borders of the button.
  198. \param parent Parent gui element of the button.
  199. \param id Id with which the gui element can be identified.
  200. \param text Text displayed on the button.
  201. \param tooltiptext Text displayed in the tooltip.
  202. \return Pointer to the created button. Returns 0 if an error occurred.
  203. This pointer should not be dropped. See IReferenceCounted::drop() for
  204. more information. */
  205. virtual IGUIButton* addButton(const core::rect<s32>& rectangle,
  206. IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0, const wchar_t* tooltiptext = 0) = 0;
  207. //! Adds an empty window element.
  208. /** \param rectangle Rectangle specifying the borders of the window.
  209. \param modal Defines if the dialog is modal. This means, that all other
  210. gui elements which were created before the window cannot be used until
  211. it is removed.
  212. \param text Text displayed as the window title.
  213. \param parent Parent gui element of the window.
  214. \param id Id with which the gui element can be identified.
  215. \return Pointer to the created window. Returns 0 if an error occurred.
  216. This pointer should not be dropped. See IReferenceCounted::drop() for
  217. more information. */
  218. virtual IGUIWindow* addWindow(const core::rect<s32>& rectangle, bool modal = false,
  219. const wchar_t* text=0, IGUIElement* parent=0, s32 id=-1) = 0;
  220. //! Adds a modal screen.
  221. /** Input focus stays with children of the modal screen.
  222. If you have some window x which should keep the input focus you
  223. do something like: addModalScreen()->addChild(x). And x will then get the focus
  224. and not lose it anymore.
  225. The modal screen removes itself when it no longer has any children.
  226. Note that it usually works badly to pass the modal screen already as parent when creating
  227. a new element. It's better to add that new element later to the modal screen with addChild.
  228. \param parent Parent gui element of the modal.
  229. \return Pointer to the created modal. Returns 0 if an error occurred.
  230. This pointer should not be dropped. See IReferenceCounted::drop() for
  231. more information. */
  232. virtual IGUIElement* addModalScreen(IGUIElement* parent) = 0;
  233. //! Adds a message box.
  234. /** \param caption Text to be displayed the title of the message box.
  235. \param text Text to be displayed in the body of the message box.
  236. \param modal Defines if the dialog is modal. This means, that all other
  237. gui elements which were created before the message box cannot be used
  238. until this messagebox is removed.
  239. \param flags Flags specifying the layout of the message box using ::EMESSAGE_BOX_FLAG.
  240. Create a message box with an OK and CANCEL button for example with (EMBF_OK | EMBF_CANCEL).
  241. \param parent Parent gui element of the message box.
  242. \param id Id with which the gui element can be identified.
  243. \param image Optional texture which will be displayed beside the text as an image
  244. \return Pointer to the created message box. Returns 0 if an error
  245. occurred. This pointer should not be dropped. See
  246. IReferenceCounted::drop() for more information. */
  247. virtual IGUIWindow* addMessageBox(const wchar_t* caption, const wchar_t* text=0,
  248. bool modal = true, s32 flags = EMBF_OK, IGUIElement* parent=0, s32 id=-1, video::ITexture* image=0) = 0;
  249. //! Adds a scrollbar.
  250. /** \param horizontal Specifies if the scroll bar is drawn horizontal
  251. or vertical.
  252. \param rectangle Rectangle specifying the borders of the scrollbar.
  253. \param parent Parent gui element of the scroll bar.
  254. \param id Id to identify the gui element.
  255. \return Pointer to the created scrollbar. Returns 0 if an error
  256. occurred. This pointer should not be dropped. See
  257. IReferenceCounted::drop() for more information. */
  258. virtual IGUIScrollBar* addScrollBar(bool horizontal, const core::rect<s32>& rectangle,
  259. IGUIElement* parent=0, s32 id=-1) = 0;
  260. //! Adds an image element.
  261. /** \param image Image to be displayed.
  262. \param pos Position of the image. The width and height of the image is
  263. taken from the image.
  264. \param useAlphaChannel Sets if the image should use the alpha channel
  265. of the texture to draw itself.
  266. \param parent Parent gui element of the image.
  267. \param id Id to identify the gui element.
  268. \param text Title text of the image (not displayed).
  269. \return Pointer to the created image element. Returns 0 if an error
  270. occurred. This pointer should not be dropped. See
  271. IReferenceCounted::drop() for more information. */
  272. virtual IGUIImage* addImage(video::ITexture* image, core::position2d<s32> pos,
  273. bool useAlphaChannel=true, IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0) = 0;
  274. //! Adds an image element.
  275. /** Use IGUIImage::setImage later to set the image to be displayed.
  276. \param rectangle Rectangle specifying the borders of the image.
  277. \param parent Parent gui element of the image.
  278. \param id Id to identify the gui element.
  279. \param text Title text of the image (not displayed).
  280. \param useAlphaChannel Sets if the image should use the alpha channel
  281. of the texture to draw itself.
  282. \return Pointer to the created image element. Returns 0 if an error
  283. occurred. This pointer should not be dropped. See
  284. IReferenceCounted::drop() for more information. */
  285. virtual IGUIImage* addImage(const core::rect<s32>& rectangle,
  286. IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0, bool useAlphaChannel=true) = 0;
  287. //! Adds a checkbox element.
  288. /** \param checked Define the initial state of the check box.
  289. \param rectangle Rectangle specifying the borders of the check box.
  290. \param parent Parent gui element of the check box.
  291. \param id Id to identify the gui element.
  292. \param text Title text of the check box.
  293. \return Pointer to the created check box. Returns 0 if an error
  294. occurred. This pointer should not be dropped. See
  295. IReferenceCounted::drop() for more information. */
  296. virtual IGUICheckBox* addCheckBox(bool checked, const core::rect<s32>& rectangle,
  297. IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0) = 0;
  298. //! Adds a list box element.
  299. /** \param rectangle Rectangle specifying the borders of the list box.
  300. \param parent Parent gui element of the list box.
  301. \param id Id to identify the gui element.
  302. \param drawBackground Flag whether the background should be drawn.
  303. \return Pointer to the created list box. Returns 0 if an error occurred.
  304. This pointer should not be dropped. See IReferenceCounted::drop() for
  305. more information. */
  306. virtual IGUIListBox* addListBox(const core::rect<s32>& rectangle,
  307. IGUIElement* parent=0, s32 id=-1, bool drawBackground=false) = 0;
  308. //! Adds a tree view element.
  309. /** \param rectangle Position and dimension of list box.
  310. \param parent Parent gui element of the list box.
  311. \param id Id to identify the gui element.
  312. \param drawBackground Flag whether the background should be drawn.
  313. \param scrollBarVertical Flag whether a vertical scrollbar should be used
  314. \param scrollBarHorizontal Flag whether a horizontal scrollbar should be used
  315. \return Pointer to the created list box. Returns 0 if an error occurred.
  316. This pointer should not be dropped. See IReferenceCounted::drop() for
  317. more information. */
  318. virtual IGUITreeView* addTreeView(const core::rect<s32>& rectangle,
  319. IGUIElement* parent=0, s32 id=-1, bool drawBackground=false,
  320. bool scrollBarVertical = true, bool scrollBarHorizontal = false) = 0;
  321. //! Adds a mesh viewer. Not 100% implemented yet.
  322. /** \param rectangle Rectangle specifying the borders of the mesh viewer.
  323. \param parent Parent gui element of the mesh viewer.
  324. \param id Id to identify the gui element.
  325. \param text Title text of the mesh viewer.
  326. \return Pointer to the created mesh viewer. Returns 0 if an error
  327. occurred. This pointer should not be dropped. See
  328. IReferenceCounted::drop() for more information. */
  329. virtual IGUIMeshViewer* addMeshViewer(const core::rect<s32>& rectangle,
  330. IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0) = 0;
  331. //! Adds a file open dialog.
  332. /** \param title Text to be displayed as the title of the dialog.
  333. \param modal Defines if the dialog is modal. This means, that all other
  334. gui elements which were created before the message box cannot be used
  335. until this messagebox is removed.
  336. \param parent Parent gui element of the dialog.
  337. \param id Id to identify the gui element.
  338. \param restoreCWD If set to true, the current working directory will be
  339. restored after the dialog is closed in some way. Otherwise the working
  340. directory will be the one that the file dialog was last showing.
  341. \param startDir Optional path for which the file dialog will be opened.
  342. \return Pointer to the created file open dialog. Returns 0 if an error
  343. occurred. This pointer should not be dropped. See
  344. IReferenceCounted::drop() for more information. */
  345. virtual IGUIFileOpenDialog* addFileOpenDialog(const wchar_t* title=0,
  346. bool modal=true, IGUIElement* parent=0, s32 id=-1,
  347. bool restoreCWD=false, io::path::char_type* startDir=0) = 0;
  348. //! Adds a color select dialog.
  349. /** \param title The title of the dialog.
  350. \param modal Defines if the dialog is modal. This means, that all other
  351. gui elements which were created before the dialog cannot be used
  352. until it is removed.
  353. \param parent The parent of the dialog.
  354. \param id The ID of the dialog.
  355. \return Pointer to the created file open dialog. Returns 0 if an error
  356. occurred. This pointer should not be dropped. See
  357. IReferenceCounted::drop() for more information. */
  358. virtual IGUIColorSelectDialog* addColorSelectDialog(const wchar_t* title = 0,
  359. bool modal=true, IGUIElement* parent=0, s32 id=-1) = 0;
  360. //! Adds a static text.
  361. /** \param text Text to be displayed. Can be altered after creation by SetText().
  362. \param rectangle Rectangle specifying the borders of the static text
  363. \param border Set to true if the static text should have a 3d border.
  364. \param wordWrap Enable if the text should wrap into multiple lines.
  365. \param parent Parent item of the element, e.g. a window.
  366. \param id The ID of the element.
  367. \param fillBackground Enable if the background shall be filled.
  368. Defaults to false.
  369. \return Pointer to the created static text. Returns 0 if an error
  370. occurred. This pointer should not be dropped. See
  371. IReferenceCounted::drop() for more information. */
  372. virtual IGUIStaticText* addStaticText(const wchar_t* text, const core::rect<s32>& rectangle,
  373. bool border=false, bool wordWrap=true, IGUIElement* parent=0, s32 id=-1,
  374. bool fillBackground = false) = 0;
  375. //! Adds an edit box.
  376. /** Supports Unicode input from every keyboard around the world,
  377. scrolling, copying and pasting (exchanging data with the clipboard
  378. directly), maximum character amount, marking, and all shortcuts like
  379. ctrl+X, ctrl+V, ctrl+C, shift+Left, shift+Right, Home, End, and so on.
  380. \param text Text to be displayed. Can be altered after creation
  381. by setText().
  382. \param rectangle Rectangle specifying the borders of the edit box.
  383. \param border Set to true if the edit box should have a 3d border.
  384. \param parent Parent item of the element, e.g. a window.
  385. Set it to 0 to place the edit box directly in the environment.
  386. \param id The ID of the element.
  387. \return Pointer to the created edit box. Returns 0 if an error occurred.
  388. This pointer should not be dropped. See IReferenceCounted::drop() for
  389. more information. */
  390. virtual IGUIEditBox* addEditBox(const wchar_t* text, const core::rect<s32>& rectangle,
  391. bool border=true, IGUIElement* parent=0, s32 id=-1) = 0;
  392. //! Adds a spin box.
  393. /** An edit box with up and down buttons
  394. \param text Text to be displayed. Can be altered after creation by setText().
  395. \param rectangle Rectangle specifying the borders of the spin box.
  396. \param border Set to true if the spin box should have a 3d border.
  397. \param parent Parent item of the element, e.g. a window.
  398. Set it to 0 to place the spin box directly in the environment.
  399. \param id The ID of the element.
  400. \return Pointer to the created spin box. Returns 0 if an error occurred.
  401. This pointer should not be dropped. See IReferenceCounted::drop() for
  402. more information. */
  403. virtual IGUISpinBox* addSpinBox(const wchar_t* text, const core::rect<s32>& rectangle,
  404. bool border=true,IGUIElement* parent=0, s32 id=-1) = 0;
  405. //! Adds an element for fading in or out.
  406. /** \param rectangle Rectangle specifying the borders of the fader.
  407. If the pointer is NULL, the whole screen is used.
  408. \param parent Parent item of the element, e.g. a window.
  409. \param id An identifier for the fader.
  410. \return Pointer to the created in-out-fader. Returns 0 if an error
  411. occurred. This pointer should not be dropped. See
  412. IReferenceCounted::drop() for more information. */
  413. virtual IGUIInOutFader* addInOutFader(const core::rect<s32>* rectangle=0, IGUIElement* parent=0, s32 id=-1) = 0;
  414. //! Adds a tab control to the environment.
  415. /** \param rectangle Rectangle specifying the borders of the tab control.
  416. \param parent Parent item of the element, e.g. a window.
  417. Set it to 0 to place the tab control directly in the environment.
  418. \param fillbackground Specifies if the background of the tab control
  419. should be drawn.
  420. \param border Specifies if a flat 3d border should be drawn. This is
  421. usually not necessary unless you place the control directly into
  422. the environment without a window as parent.
  423. \param id An identifier for the tab control.
  424. \return Pointer to the created tab control element. Returns 0 if an
  425. error occurred. This pointer should not be dropped. See
  426. IReferenceCounted::drop() for more information. */
  427. virtual IGUITabControl* addTabControl(const core::rect<s32>& rectangle,
  428. IGUIElement* parent=0, bool fillbackground=false,
  429. bool border=true, s32 id=-1) = 0;
  430. //! Adds tab to the environment.
  431. /** You can use this element to group other elements. This is not used
  432. for creating tabs on tab controls, please use IGUITabControl::addTab()
  433. for this instead.
  434. \param rectangle Rectangle specifying the borders of the tab.
  435. \param parent Parent item of the element, e.g. a window.
  436. Set it to 0 to place the tab directly in the environment.
  437. \param id An identifier for the tab.
  438. \return Pointer to the created tab. Returns 0 if an
  439. error occurred. This pointer should not be dropped. See
  440. IReferenceCounted::drop() for more information. */
  441. virtual IGUITab* addTab(const core::rect<s32>& rectangle,
  442. IGUIElement* parent=0, s32 id=-1) = 0;
  443. //! Adds a context menu to the environment.
  444. /** \param rectangle Rectangle specifying the borders of the menu.
  445. Note that the menu is resizing itself based on what items you add.
  446. \param parent Parent item of the element, e.g. a window.
  447. Set it to 0 to place the menu directly in the environment.
  448. \param id An identifier for the menu.
  449. \return Pointer to the created context menu. Returns 0 if an
  450. error occurred. This pointer should not be dropped. See
  451. IReferenceCounted::drop() for more information. */
  452. virtual IGUIContextMenu* addContextMenu(const core::rect<s32>& rectangle,
  453. IGUIElement* parent=0, s32 id=-1) = 0;
  454. //! Adds a menu to the environment.
  455. /** This is like the menu you can find on top of most windows in modern
  456. graphical user interfaces.
  457. \param parent Parent item of the element, e.g. a window.
  458. Set it to 0 to place the menu directly in the environment.
  459. \param id An identifier for the menu.
  460. \return Pointer to the created menu. Returns 0 if an
  461. error occurred. This pointer should not be dropped. See
  462. IReferenceCounted::drop() for more information. */
  463. virtual IGUIContextMenu* addMenu(IGUIElement* parent=0, s32 id=-1) = 0;
  464. //! Adds a toolbar to the environment.
  465. /** It is like a menu that is always placed on top of its parent, and
  466. contains buttons.
  467. \param parent Parent item of the element, e.g. a window.
  468. Set it to 0 to place the tool bar directly in the environment.
  469. \param id An identifier for the tool bar.
  470. \return Pointer to the created tool bar. Returns 0 if an
  471. error occurred. This pointer should not be dropped. See
  472. IReferenceCounted::drop() for more information. */
  473. virtual IGUIToolBar* addToolBar(IGUIElement* parent=0, s32 id=-1) = 0;
  474. //! Adds a combo box to the environment.
  475. /** \param rectangle Rectangle specifying the borders of the combo box.
  476. \param parent Parent item of the element, e.g. a window.
  477. Set it to 0 to place the combo box directly in the environment.
  478. \param id An identifier for the combo box.
  479. \return Pointer to the created combo box. Returns 0 if an
  480. error occurred. This pointer should not be dropped. See
  481. IReferenceCounted::drop() for more information. */
  482. virtual IGUIComboBox* addComboBox(const core::rect<s32>& rectangle,
  483. IGUIElement* parent=0, s32 id=-1) = 0;
  484. //! Adds a table to the environment
  485. /** \param rectangle Rectangle specifying the borders of the table.
  486. \param parent Parent item of the element, e.g. a window. Set it to 0
  487. to place the element directly in the environment.
  488. \param id An identifier for the table.
  489. \param drawBackground Flag whether the background should be drawn.
  490. \return Pointer to the created table. Returns 0 if an error occurred.
  491. This pointer should not be dropped. See IReferenceCounted::drop() for
  492. more information. */
  493. virtual IGUITable* addTable(const core::rect<s32>& rectangle,
  494. IGUIElement* parent=0, s32 id=-1, bool drawBackground=false) =0;
  495. //! Adds an element to display the information from the Irrlicht profiler
  496. /** \param rectangle Rectangle specifying the borders of the element.
  497. \param parent Parent of the element. When 0 the environment itself will
  498. be the parent.
  499. \param id An identifier for the element. */
  500. virtual IGUIProfiler* addProfilerDisplay(const core::rect<s32>& rectangle,
  501. IGUIElement* parent=0, s32 id=-1) = 0;
  502. //! Get the default element factory which can create all built-in elements
  503. /** \return Pointer to the factory.
  504. This pointer should not be dropped. See IReferenceCounted::drop() for
  505. more information. */
  506. virtual IGUIElementFactory* getDefaultGUIElementFactory() const = 0;
  507. //! Adds an element factory to the gui environment.
  508. /** Use this to extend the gui environment with new element types which
  509. it should be able to create automatically, for example when loading
  510. data from xml files.
  511. \param factoryToAdd Pointer to new factory. */
  512. virtual void registerGUIElementFactory(IGUIElementFactory* factoryToAdd) = 0;
  513. //! Get amount of registered gui element factories.
  514. /** \return Amount of registered gui element factories. */
  515. virtual u32 getRegisteredGUIElementFactoryCount() const = 0;
  516. //! Get a gui element factory by index
  517. /** \param index Index of the factory.
  518. \return Factory at given index, or 0 if no such factory exists. */
  519. virtual IGUIElementFactory* getGUIElementFactory(u32 index) const = 0;
  520. //! Adds a GUI element by its name
  521. /** Each factory is checked if it can create an element of the given
  522. name. The first match will be created.
  523. \param elementName Name of the element to be created.
  524. \param parent Parent of the new element, if not 0.
  525. \return New GUI element, or 0 if no such element exists. */
  526. virtual IGUIElement* addGUIElement(const c8* elementName, IGUIElement* parent=0) = 0;
  527. //! Saves the current gui into a file.
  528. /** \param filename Name of the file.
  529. \param start The GUIElement to start with. Root if 0.
  530. \return True if saving succeeded, else false. */
  531. virtual bool saveGUI(const io::path& filename, IGUIElement* start=0) = 0;
  532. //! Saves the current gui into a file.
  533. /** \param file The file to write to.
  534. \param start The GUIElement to start with. Root if 0.
  535. \return True if saving succeeded, else false. */
  536. virtual bool saveGUI(io::IWriteFile* file, IGUIElement* start=0) = 0;
  537. //! Loads the gui. Note that the current gui is not cleared before.
  538. /** When a parent is set the elements will be added below the parent, the parent itself does not deserialize.
  539. When the file contains skin-settings from the gui-environment those are always serialized into the
  540. guienvironment independent of the parent setting.
  541. \param filename Name of the file.
  542. \param parent Parent for the loaded GUI, root if 0.
  543. \return True if loading succeeded, else false. */
  544. virtual bool loadGUI(const io::path& filename, IGUIElement* parent=0) = 0;
  545. //! Loads the gui. Note that the current gui is not cleared before.
  546. /** When a parent is set the elements will be added below the parent, the parent itself does not deserialize.
  547. When the file contains skin-settings from the gui-environment those are always serialized into the
  548. guienvironment independent of the parent setting.
  549. \param file The file to load from.
  550. \param parent Parent for the loaded GUI, root if 0.
  551. \return True if loading succeeded, else false. */
  552. virtual bool loadGUI(io::IReadFile* file, IGUIElement* parent=0) = 0;
  553. //! Writes attributes of the gui environment
  554. virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const =0;
  555. //! Reads attributes of the gui environment
  556. virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0)=0;
  557. //! writes an element
  558. virtual void writeGUIElement(io::IXMLWriter* writer, IGUIElement* element) =0;
  559. //! reads an element
  560. virtual void readGUIElement(io::IXMLReader* reader, IGUIElement* element) =0;
  561. //! Find the next element which would be selected when pressing the tab-key
  562. /** If you set the focus for the result you can manually force focus-changes like they
  563. would happen otherwise by the tab-keys.
  564. \param reverse When true it will search backward (toward lower TabOrder numbers, like shift+tab)
  565. \param group When true it will search for the next tab-group (like ctrl+tab)
  566. */
  567. virtual IGUIElement* getNextElement(bool reverse=false, bool group=false) = 0;
  568. //! Set the way the gui will handle automatic focus changes
  569. /** The default is (EFF_SET_ON_LMOUSE_DOWN | EFF_SET_ON_TAB).
  570. with the left mouse button.
  571. This does not affect the setFocus function itself - users can still call that whenever they want on any element.
  572. \param flags A bitmask which is a combination of ::EFOCUS_FLAG flags.*/
  573. virtual void setFocusBehavior(u32 flags) = 0;
  574. //! Get the way the gui does handle focus changes
  575. /** \returns A bitmask which is a combination of ::EFOCUS_FLAG flags.*/
  576. virtual u32 getFocusBehavior() const = 0;
  577. //! Adds a IGUIElement to deletion queue.
  578. /** Queued elements will be removed at the end of each drawAll call.
  579. Or latest in the destructor of the GUIEnvironment.
  580. This can be used to allow an element removing itself safely in a function
  581. iterating over gui elements, like an overloaded IGUIElement::draw or
  582. IGUIElement::OnPostRender function.
  583. Note that in general just calling IGUIElement::remove() is enough.
  584. Unless you create your own GUI elements removing themselves you won't need it.
  585. \param element: Element to remove */
  586. virtual void addToDeletionQueue(IGUIElement* element) = 0;
  587. };
  588. } // end namespace gui
  589. } // end namespace irr
  590. #endif