IGUIContextMenu.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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_CONTEXT_MENU_H_INCLUDED__
  5. #define __I_GUI_CONTEXT_MENU_H_INCLUDED__
  6. #include "IGUIElement.h"
  7. namespace irr
  8. {
  9. namespace gui
  10. {
  11. //! Close behavior.
  12. //! Default is ECMC_REMOVE
  13. enum ECONTEXT_MENU_CLOSE
  14. {
  15. //! do nothing - menu stays open
  16. ECMC_IGNORE = 0,
  17. //! remove the gui element
  18. ECMC_REMOVE = 1,
  19. //! call setVisible(false)
  20. ECMC_HIDE = 2
  21. // note to implementers - this is planned as bitset, so continue with 4 if you need to add further flags.
  22. };
  23. //! GUI Context menu interface.
  24. /** \par This element can create the following events of type EGUI_EVENT_TYPE:
  25. \li EGET_ELEMENT_CLOSED
  26. \li EGET_MENU_ITEM_SELECTED
  27. */
  28. class IGUIContextMenu : public IGUIElement
  29. {
  30. public:
  31. //! constructor
  32. IGUIContextMenu(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle)
  33. : IGUIElement(EGUIET_CONTEXT_MENU, environment, parent, id, rectangle) {}
  34. //! set behavior when menus are closed
  35. virtual void setCloseHandling(ECONTEXT_MENU_CLOSE onClose) = 0;
  36. //! get current behavior when the menu will be closed
  37. virtual ECONTEXT_MENU_CLOSE getCloseHandling() const = 0;
  38. //! Get amount of menu items
  39. virtual u32 getItemCount() const = 0;
  40. //! Adds a menu item.
  41. /** \param text: Text of menu item. Set this to 0 to create
  42. an separator instead of a real item, which is the same like
  43. calling addSeparator();
  44. \param commandId: Command id of menu item, a simple id you may
  45. set to whatever you want.
  46. \param enabled: Specifies if the menu item should be enabled.
  47. \param hasSubMenu: Set this to true if there should be a submenu
  48. at this item. You can access this submenu via getSubMenu().
  49. \param checked: Specifies if the menu item should be initially checked.
  50. \param autoChecking: Specifies if the item should be checked by clicking
  51. \return Returns the index of the new item */
  52. virtual u32 addItem(const wchar_t* text, s32 commandId=-1, bool enabled=true,
  53. bool hasSubMenu=false, bool checked=false, bool autoChecking=false) = 0;
  54. //! Insert a menu item at specified position.
  55. /** \param idx: Position to insert the new element,
  56. should be smaller than itemcount otherwise the item is added to the end.
  57. \param text: Text of menu item. Set this to 0 to create
  58. an separator instead of a real item, which is the same like
  59. calling addSeparator();
  60. \param commandId: Command id of menu item, a simple id you may
  61. set to whatever you want.
  62. \param enabled: Specifies if the menu item should be enabled.
  63. \param hasSubMenu: Set this to true if there should be a submenu
  64. at this item. You can access this submenu via getSubMenu().
  65. \param checked: Specifies if the menu item should be initially checked.
  66. \param autoChecking: Specifies if the item should be checked by clicking
  67. \return Returns the index of the new item */
  68. virtual u32 insertItem(u32 idx, const wchar_t* text, s32 commandId=-1, bool enabled=true,
  69. bool hasSubMenu=false, bool checked=false, bool autoChecking=false) = 0;
  70. //! Find an item by its CommandID
  71. /**
  72. \param commandId: We are looking for the first item which has this commandID
  73. \param idxStartSearch: Start searching from this index.
  74. \return Returns the index of the item when found or otherwise -1. */
  75. virtual s32 findItemWithCommandId(s32 commandId, u32 idxStartSearch=0) const = 0;
  76. //! Adds a separator item to the menu
  77. virtual void addSeparator() = 0;
  78. //! Get text of the menu item.
  79. /** \param idx: Zero based index of the menu item */
  80. virtual const wchar_t* getItemText(u32 idx) const = 0;
  81. //! Sets text of the menu item.
  82. /** \param idx: Zero based index of the menu item
  83. \param text: New text of the item. */
  84. virtual void setItemText(u32 idx, const wchar_t* text) = 0;
  85. //! Check if a menu item is enabled
  86. /** \param idx: Zero based index of the menu item */
  87. virtual bool isItemEnabled(u32 idx) const = 0;
  88. //! Sets if the menu item should be enabled.
  89. /** \param idx: Zero based index of the menu item
  90. \param enabled: True if it is enabled, otherwise false. */
  91. virtual void setItemEnabled(u32 idx, bool enabled) = 0;
  92. //! Sets if the menu item should be checked.
  93. /** \param idx: Zero based index of the menu item
  94. \param enabled: True if it is enabled, otherwise false. */
  95. virtual void setItemChecked(u32 idx, bool enabled) = 0;
  96. //! Check if a menu item is checked
  97. /** \param idx: Zero based index of the menu item */
  98. virtual bool isItemChecked(u32 idx) const = 0;
  99. //! Removes a menu item
  100. /** \param idx: Zero based index of the menu item */
  101. virtual void removeItem(u32 idx) = 0;
  102. //! Removes all menu items
  103. virtual void removeAllItems() = 0;
  104. //! Get the selected item in the menu
  105. /** \return Index of the selected item, -1 if none selected. */
  106. virtual s32 getSelectedItem() const = 0;
  107. //! Get the command id of a menu item
  108. /** \param idx: Zero based index of the menu item */
  109. virtual s32 getItemCommandId(u32 idx) const = 0;
  110. //! Sets the command id of a menu item
  111. /** \param idx: Zero based index of the menu item
  112. \param id: Command id of menu item, a simple id you may
  113. set to whatever you want. */
  114. virtual void setItemCommandId(u32 idx, s32 id) = 0;
  115. //! Get a pointer to the submenu of an item.
  116. /** 0 is returned if there is no submenu
  117. \param idx: Zero based index of the menu item
  118. \return Returns a pointer to the submenu of an item. */
  119. virtual IGUIContextMenu* getSubMenu(u32 idx) const = 0;
  120. //! should the element change the checked status on clicking
  121. virtual void setItemAutoChecking(u32 idx, bool autoChecking) = 0;
  122. //! does the element change the checked status on clicking
  123. virtual bool getItemAutoChecking(u32 idx) const = 0;
  124. //! When an eventparent is set it receives events instead of the usual parent element
  125. virtual void setEventParent(IGUIElement *parent) = 0;
  126. };
  127. } // end namespace gui
  128. } // end namespace irr
  129. #endif