IGUIEnvironment.h 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  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 IRR_I_GUI_ENVIRONMENT_H_INCLUDED
  5. #define IRR_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. \param blinkMode Bitset of when to blink (can be combined)
  230. 0 = never
  231. 1 = focus changes
  232. 2 = Left mouse button pressed down
  233. \return Pointer to the created modal. Returns 0 if an error occurred.
  234. This pointer should not be dropped. See IReferenceCounted::drop() for
  235. more information. */
  236. virtual IGUIElement* addModalScreen(IGUIElement* parent, int blinkMode = 3) = 0;
  237. //! Adds a message box.
  238. /** \param caption Text to be displayed the title of the message box.
  239. \param text Text to be displayed in the body of the message box.
  240. \param modal Defines if the dialog is modal. This means, that all other
  241. gui elements which were created before the message box cannot be used
  242. until this messagebox is removed.
  243. \param flags Flags specifying the layout of the message box using ::EMESSAGE_BOX_FLAG.
  244. Create a message box with an OK and CANCEL button for example with (EMBF_OK | EMBF_CANCEL).
  245. \param parent Parent gui element of the message box.
  246. \param id Id with which the gui element can be identified.
  247. \param image Optional texture which will be displayed beside the text as an image
  248. \return Pointer to the created message box. Returns 0 if an error
  249. occurred. This pointer should not be dropped. See
  250. IReferenceCounted::drop() for more information. */
  251. virtual IGUIWindow* addMessageBox(const wchar_t* caption, const wchar_t* text=0,
  252. bool modal = true, s32 flags = EMBF_OK, IGUIElement* parent=0, s32 id=-1, video::ITexture* image=0) = 0;
  253. //! Adds a scrollbar.
  254. /** \param horizontal Specifies if the scroll bar is drawn horizontal
  255. or vertical.
  256. \param rectangle Rectangle specifying the borders of the scrollbar.
  257. \param parent Parent gui element of the scroll bar.
  258. \param id Id to identify the gui element.
  259. \return Pointer to the created scrollbar. Returns 0 if an error
  260. occurred. This pointer should not be dropped. See
  261. IReferenceCounted::drop() for more information. */
  262. virtual IGUIScrollBar* addScrollBar(bool horizontal, const core::rect<s32>& rectangle,
  263. IGUIElement* parent=0, s32 id=-1) = 0;
  264. //! Adds an image element.
  265. /** \param image Image to be displayed.
  266. \param pos Position of the image. The width and height of the image is
  267. taken from the image.
  268. \param useAlphaChannel Sets if the image should use the alpha channel
  269. of the texture to draw itself.
  270. \param parent Parent gui element of the image.
  271. \param id Id to identify the gui element.
  272. \param text Title text of the image (not displayed).
  273. \return Pointer to the created image element. Returns 0 if an error
  274. occurred. This pointer should not be dropped. See
  275. IReferenceCounted::drop() for more information. */
  276. virtual IGUIImage* addImage(video::ITexture* image, core::position2d<s32> pos,
  277. bool useAlphaChannel=true, IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0) = 0;
  278. //! Adds an image element.
  279. /** Use IGUIImage::setImage later to set the image to be displayed.
  280. \param rectangle Rectangle specifying the borders of the image.
  281. \param parent Parent gui element of the image.
  282. \param id Id to identify the gui element.
  283. \param text Title text of the image (not displayed).
  284. \param useAlphaChannel Sets if the image should use the alpha channel
  285. of the texture to draw itself.
  286. \return Pointer to the created image element. Returns 0 if an error
  287. occurred. This pointer should not be dropped. See
  288. IReferenceCounted::drop() for more information. */
  289. virtual IGUIImage* addImage(const core::rect<s32>& rectangle,
  290. IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0, bool useAlphaChannel=true) = 0;
  291. //! Adds a checkbox element.
  292. /** \param checked Define the initial state of the check box.
  293. \param rectangle Rectangle specifying the borders of the check box.
  294. \param parent Parent gui element of the check box.
  295. \param id Id to identify the gui element.
  296. \param text Title text of the check box.
  297. \return Pointer to the created check box. Returns 0 if an error
  298. occurred. This pointer should not be dropped. See
  299. IReferenceCounted::drop() for more information. */
  300. virtual IGUICheckBox* addCheckBox(bool checked, const core::rect<s32>& rectangle,
  301. IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0) = 0;
  302. //! Adds a list box element.
  303. /** \param rectangle Rectangle specifying the borders of the list box.
  304. \param parent Parent gui element of the list box.
  305. \param id Id to identify the gui element.
  306. \param drawBackground Flag whether the background should be drawn.
  307. \return Pointer to the created list box. Returns 0 if an error occurred.
  308. This pointer should not be dropped. See IReferenceCounted::drop() for
  309. more information. */
  310. virtual IGUIListBox* addListBox(const core::rect<s32>& rectangle,
  311. IGUIElement* parent=0, s32 id=-1, bool drawBackground=false) = 0;
  312. //! Adds a tree view element.
  313. /** \param rectangle Position and dimension of list box.
  314. \param parent Parent gui element of the list box.
  315. \param id Id to identify the gui element.
  316. \param drawBackground Flag whether the background should be drawn.
  317. \param scrollBarVertical Flag whether a vertical scrollbar should be used
  318. \param scrollBarHorizontal Flag whether a horizontal scrollbar should be used
  319. \return Pointer to the created list box. Returns 0 if an error occurred.
  320. This pointer should not be dropped. See IReferenceCounted::drop() for
  321. more information. */
  322. virtual IGUITreeView* addTreeView(const core::rect<s32>& rectangle,
  323. IGUIElement* parent=0, s32 id=-1, bool drawBackground=false,
  324. bool scrollBarVertical = true, bool scrollBarHorizontal = false) = 0;
  325. //! Adds a mesh viewer. Not 100% implemented yet.
  326. /** \param rectangle Rectangle specifying the borders of the mesh viewer.
  327. \param parent Parent gui element of the mesh viewer.
  328. \param id Id to identify the gui element.
  329. \param text Title text of the mesh viewer.
  330. \return Pointer to the created mesh viewer. Returns 0 if an error
  331. occurred. This pointer should not be dropped. See
  332. IReferenceCounted::drop() for more information. */
  333. virtual IGUIMeshViewer* addMeshViewer(const core::rect<s32>& rectangle,
  334. IGUIElement* parent=0, s32 id=-1, const wchar_t* text=0) = 0;
  335. //! Adds a file open dialog.
  336. /** \param title Text to be displayed as the title of the dialog.
  337. \param modal Defines if the dialog is modal. This means, that all other
  338. gui elements which were created before the message box cannot be used
  339. until this messagebox is removed.
  340. \param parent Parent gui element of the dialog.
  341. \param id Id to identify the gui element.
  342. \param restoreCWD If set to true, the current working directory will be
  343. restored after the dialog is closed in some way. Otherwise the working
  344. directory will be the one that the file dialog was last showing.
  345. \param startDir Optional path for which the file dialog will be opened.
  346. \return Pointer to the created file open dialog. Returns 0 if an error
  347. occurred. This pointer should not be dropped. See
  348. IReferenceCounted::drop() for more information. */
  349. virtual IGUIFileOpenDialog* addFileOpenDialog(const wchar_t* title=0,
  350. bool modal=true, IGUIElement* parent=0, s32 id=-1,
  351. bool restoreCWD=false, io::path::char_type* startDir=0) = 0;
  352. //! Adds a color select dialog.
  353. /** \param title The title of the dialog.
  354. \param modal Defines if the dialog is modal. This means, that all other
  355. gui elements which were created before the dialog cannot be used
  356. until it is removed.
  357. \param parent The parent of the dialog.
  358. \param id The ID of the dialog.
  359. \return Pointer to the created file open dialog. Returns 0 if an error
  360. occurred. This pointer should not be dropped. See
  361. IReferenceCounted::drop() for more information. */
  362. virtual IGUIColorSelectDialog* addColorSelectDialog(const wchar_t* title = 0,
  363. bool modal=true, IGUIElement* parent=0, s32 id=-1) = 0;
  364. //! Adds a static text.
  365. /** \param text Text to be displayed. Can be altered after creation by SetText().
  366. \param rectangle Rectangle specifying the borders of the static text
  367. \param border Set to true if the static text should have a 3d border.
  368. \param wordWrap Enable if the text should wrap into multiple lines.
  369. \param parent Parent item of the element, e.g. a window.
  370. \param id The ID of the element.
  371. \param fillBackground Enable if the background shall be filled.
  372. Defaults to false.
  373. \return Pointer to the created static text. Returns 0 if an error
  374. occurred. This pointer should not be dropped. See
  375. IReferenceCounted::drop() for more information. */
  376. virtual IGUIStaticText* addStaticText(const wchar_t* text, const core::rect<s32>& rectangle,
  377. bool border=false, bool wordWrap=true, IGUIElement* parent=0, s32 id=-1,
  378. bool fillBackground = false) = 0;
  379. //! Adds an edit box.
  380. /** Supports Unicode input from every keyboard around the world,
  381. scrolling, copying and pasting (exchanging data with the clipboard
  382. directly), maximum character amount, marking, and all shortcuts like
  383. ctrl+X, ctrl+V, ctrl+C, shift+Left, shift+Right, Home, End, and so on.
  384. \param text Text to be displayed. Can be altered after creation
  385. by setText().
  386. \param rectangle Rectangle specifying the borders of the edit box.
  387. \param border Set to true if the edit box should have a 3d border.
  388. \param parent Parent item of the element, e.g. a window.
  389. Set it to 0 to place the edit box directly in the environment.
  390. \param id The ID of the element.
  391. \return Pointer to the created edit box. Returns 0 if an error occurred.
  392. This pointer should not be dropped. See IReferenceCounted::drop() for
  393. more information. */
  394. virtual IGUIEditBox* addEditBox(const wchar_t* text, const core::rect<s32>& rectangle,
  395. bool border=true, IGUIElement* parent=0, s32 id=-1) = 0;
  396. //! Adds a spin box.
  397. /** An edit box with up and down buttons
  398. \param text Text to be displayed. Can be altered after creation by setText().
  399. \param rectangle Rectangle specifying the borders of the spin box.
  400. \param border Set to true if the spin box should have a 3d border.
  401. \param parent Parent item of the element, e.g. a window.
  402. Set it to 0 to place the spin box directly in the environment.
  403. \param id The ID of the element.
  404. \return Pointer to the created spin box. Returns 0 if an error occurred.
  405. This pointer should not be dropped. See IReferenceCounted::drop() for
  406. more information. */
  407. virtual IGUISpinBox* addSpinBox(const wchar_t* text, const core::rect<s32>& rectangle,
  408. bool border=true,IGUIElement* parent=0, s32 id=-1) = 0;
  409. //! Adds an element for fading in or out.
  410. /** \param rectangle Rectangle specifying the borders of the fader.
  411. If the pointer is NULL, the whole screen is used.
  412. \param parent Parent item of the element, e.g. a window.
  413. \param id An identifier for the fader.
  414. \return Pointer to the created in-out-fader. Returns 0 if an error
  415. occurred. This pointer should not be dropped. See
  416. IReferenceCounted::drop() for more information. */
  417. virtual IGUIInOutFader* addInOutFader(const core::rect<s32>* rectangle=0, IGUIElement* parent=0, s32 id=-1) = 0;
  418. //! Adds a tab control to the environment.
  419. /** \param rectangle Rectangle specifying the borders of the tab control.
  420. \param parent Parent item of the element, e.g. a window.
  421. Set it to 0 to place the tab control directly in the environment.
  422. \param fillbackground Specifies if the background of the tab control
  423. should be drawn.
  424. \param border Specifies if a flat 3d border should be drawn. This is
  425. usually not necessary unless you place the control directly into
  426. the environment without a window as parent.
  427. \param id An identifier for the tab control.
  428. \return Pointer to the created tab control element. Returns 0 if an
  429. error occurred. This pointer should not be dropped. See
  430. IReferenceCounted::drop() for more information. */
  431. virtual IGUITabControl* addTabControl(const core::rect<s32>& rectangle,
  432. IGUIElement* parent=0, bool fillbackground=false,
  433. bool border=true, s32 id=-1) = 0;
  434. //! Adds tab to the environment.
  435. /** You can use this element to group other elements. This is not used
  436. for creating tabs on tab controls, please use IGUITabControl::addTab()
  437. for this instead.
  438. \param rectangle Rectangle specifying the borders of the tab.
  439. \param parent Parent item of the element, e.g. a window.
  440. Set it to 0 to place the tab directly in the environment.
  441. \param id An identifier for the tab.
  442. \return Pointer to the created tab. Returns 0 if an
  443. error occurred. This pointer should not be dropped. See
  444. IReferenceCounted::drop() for more information. */
  445. virtual IGUITab* addTab(const core::rect<s32>& rectangle,
  446. IGUIElement* parent=0, s32 id=-1) = 0;
  447. //! Adds a context menu to the environment.
  448. /** \param rectangle Rectangle specifying the borders of the menu.
  449. Note that the menu is resizing itself based on what items you add.
  450. \param parent Parent item of the element, e.g. a window.
  451. Set it to 0 to place the menu directly in the environment.
  452. \param id An identifier for the menu.
  453. \return Pointer to the created context menu. Returns 0 if an
  454. error occurred. This pointer should not be dropped. See
  455. IReferenceCounted::drop() for more information. */
  456. virtual IGUIContextMenu* addContextMenu(const core::rect<s32>& rectangle,
  457. IGUIElement* parent=0, s32 id=-1) = 0;
  458. //! Adds a menu to the environment.
  459. /** This is like the menu you can find on top of most windows in modern
  460. graphical user interfaces.
  461. \param parent Parent item of the element, e.g. a window.
  462. Set it to 0 to place the menu directly in the environment.
  463. \param id An identifier for the menu.
  464. \return Pointer to the created menu. Returns 0 if an
  465. error occurred. This pointer should not be dropped. See
  466. IReferenceCounted::drop() for more information. */
  467. virtual IGUIContextMenu* addMenu(IGUIElement* parent=0, s32 id=-1) = 0;
  468. //! Adds a toolbar to the environment.
  469. /** It is like a menu that is always placed on top of its parent, and
  470. contains buttons.
  471. \param parent Parent item of the element, e.g. a window.
  472. Set it to 0 to place the tool bar directly in the environment.
  473. \param id An identifier for the tool bar.
  474. \return Pointer to the created tool bar. Returns 0 if an
  475. error occurred. This pointer should not be dropped. See
  476. IReferenceCounted::drop() for more information. */
  477. virtual IGUIToolBar* addToolBar(IGUIElement* parent=0, s32 id=-1) = 0;
  478. //! Adds a combo box to the environment.
  479. /** \param rectangle Rectangle specifying the borders of the combo box.
  480. \param parent Parent item of the element, e.g. a window.
  481. Set it to 0 to place the combo box directly in the environment.
  482. \param id An identifier for the combo box.
  483. \return Pointer to the created combo box. Returns 0 if an
  484. error occurred. This pointer should not be dropped. See
  485. IReferenceCounted::drop() for more information. */
  486. virtual IGUIComboBox* addComboBox(const core::rect<s32>& rectangle,
  487. IGUIElement* parent=0, s32 id=-1) = 0;
  488. //! Adds a table to the environment
  489. /** \param rectangle Rectangle specifying the borders of the table.
  490. \param parent Parent item of the element, e.g. a window. Set it to 0
  491. to place the element directly in the environment.
  492. \param id An identifier for the table.
  493. \param drawBackground Flag whether the background should be drawn.
  494. \return Pointer to the created table. Returns 0 if an error occurred.
  495. This pointer should not be dropped. See IReferenceCounted::drop() for
  496. more information. */
  497. virtual IGUITable* addTable(const core::rect<s32>& rectangle,
  498. IGUIElement* parent=0, s32 id=-1, bool drawBackground=false) =0;
  499. //! Adds an element to display the information from the Irrlicht profiler
  500. /** \param rectangle Rectangle specifying the borders of the element.
  501. \param parent Parent of the element. When 0 the environment itself will
  502. be the parent.
  503. \param id An identifier for the element. */
  504. virtual IGUIProfiler* addProfilerDisplay(const core::rect<s32>& rectangle,
  505. IGUIElement* parent=0, s32 id=-1) = 0;
  506. //! Get the default element factory which can create all built-in elements
  507. /** \return Pointer to the factory.
  508. This pointer should not be dropped. See IReferenceCounted::drop() for
  509. more information. */
  510. virtual IGUIElementFactory* getDefaultGUIElementFactory() const = 0;
  511. //! Adds an element factory to the gui environment.
  512. /** Use this to extend the gui environment with new element types which
  513. it should be able to create automatically, for example when loading
  514. data from xml files.
  515. \param factoryToAdd Pointer to new factory. */
  516. virtual void registerGUIElementFactory(IGUIElementFactory* factoryToAdd) = 0;
  517. //! Get amount of registered gui element factories.
  518. /** \return Amount of registered gui element factories. */
  519. virtual u32 getRegisteredGUIElementFactoryCount() const = 0;
  520. //! Get a gui element factory by index
  521. /** \param index Index of the factory.
  522. \return Factory at given index, or 0 if no such factory exists. */
  523. virtual IGUIElementFactory* getGUIElementFactory(u32 index) const = 0;
  524. //! Adds a GUI element by its name
  525. /** Each factory is checked if it can create an element of the given
  526. name. The first match will be created.
  527. \param elementName Name of the element to be created.
  528. \param parent Parent of the new element, if not 0.
  529. \return New GUI element, or 0 if no such element exists. */
  530. virtual IGUIElement* addGUIElement(const c8* elementName, IGUIElement* parent=0) = 0;
  531. //! Saves the current gui into a file.
  532. /** \param filename Name of the file.
  533. \param start The GUIElement to start with. Root if 0.
  534. \return True if saving succeeded, else false. */
  535. virtual bool saveGUI(const io::path& filename, IGUIElement* start=0) = 0;
  536. //! Saves the current gui into a file.
  537. /** \param file The file to write to.
  538. \param start The GUIElement to start with. Root if 0.
  539. \return True if saving succeeded, else false. */
  540. virtual bool saveGUI(io::IWriteFile* file, IGUIElement* start=0) = 0;
  541. //! Loads the gui. Note that the current gui is not cleared before.
  542. /** When a parent is set the elements will be added below the parent, the parent itself does not deserialize.
  543. When the file contains skin-settings from the gui-environment those are always serialized into the
  544. guienvironment independent of the parent setting.
  545. \param filename Name of the file.
  546. \param parent Parent for the loaded GUI, root if 0.
  547. \return True if loading succeeded, else false. */
  548. virtual bool loadGUI(const io::path& filename, IGUIElement* parent=0) = 0;
  549. //! Loads the gui. Note that the current gui is not cleared before.
  550. /** When a parent is set the elements will be added below the parent, the parent itself does not deserialize.
  551. When the file contains skin-settings from the gui-environment those are always serialized into the
  552. guienvironment independent of the parent setting.
  553. \param file The file to load from.
  554. \param parent Parent for the loaded GUI, root if 0.
  555. \return True if loading succeeded, else false. */
  556. virtual bool loadGUI(io::IReadFile* file, IGUIElement* parent=0) = 0;
  557. //! Writes attributes of the gui environment
  558. virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const =0;
  559. //! Reads attributes of the gui environment
  560. virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options=0)=0;
  561. //! writes an element
  562. virtual void writeGUIElement(io::IXMLWriter* writer, IGUIElement* element) =0;
  563. //! reads an element
  564. virtual void readGUIElement(io::IXMLReader* reader, IGUIElement* element) =0;
  565. //! Find the next element which would be selected when pressing the tab-key
  566. /** If you set the focus for the result you can manually force focus-changes like they
  567. would happen otherwise by the tab-keys.
  568. \param reverse When true it will search backward (toward lower TabOrder numbers, like shift+tab)
  569. \param group When true it will search for the next tab-group (like ctrl+tab)
  570. */
  571. virtual IGUIElement* getNextElement(bool reverse=false, bool group=false) = 0;
  572. //! Set the way the gui will handle automatic focus changes
  573. /** The default is (EFF_SET_ON_LMOUSE_DOWN | EFF_SET_ON_TAB).
  574. with the left mouse button.
  575. This does not affect the setFocus function itself - users can still call that whenever they want on any element.
  576. \param flags A bitmask which is a combination of ::EFOCUS_FLAG flags.*/
  577. virtual void setFocusBehavior(u32 flags) = 0;
  578. //! Get the way the gui does handle focus changes
  579. /** \returns A bitmask which is a combination of ::EFOCUS_FLAG flags.*/
  580. virtual u32 getFocusBehavior() const = 0;
  581. //! Adds a IGUIElement to deletion queue.
  582. /** Queued elements will be removed at the end of each drawAll call.
  583. Or latest in the destructor of the GUIEnvironment.
  584. This can be used to allow an element removing itself safely in a function
  585. iterating over gui elements, like an overloaded IGUIElement::draw or
  586. IGUIElement::OnPostRender function.
  587. Note that in general just calling IGUIElement::remove() is enough.
  588. Unless you create your own GUI elements removing themselves you won't need it.
  589. \param element: Element to remove */
  590. virtual void addToDeletionQueue(IGUIElement* element) = 0;
  591. };
  592. } // end namespace gui
  593. } // end namespace irr
  594. #endif