diff -r f2eb59ed5a4a lib/irrlicht/include/IGUIContextMenu.h --- a/lib/irrlicht/include/IGUIContextMenu.h Wed Sep 23 01:11:02 2009 +0200 +++ b/lib/irrlicht/include/IGUIContextMenu.h Wed Sep 23 01:15:04 2009 +0200 @@ -11,6 +11,21 @@ namespace irr { namespace gui { + //! Close behaviour. + //! Default is ECMC_REMOVE + enum ECONTEXT_MENU_CLOSE + { + //! do nothing - menu stays open + ECMC_IGNORE = 0, + + //! remove the gui element + ECMC_REMOVE = 1, + + //! call setVisible(false) + ECMC_HIDE = 2, + + // note to implementors - this is planned as bitset, so continue with 4 if you need to add further flags. + }; //! GUI Context menu interface. class IGUIContextMenu : public IGUIElement @@ -20,6 +35,12 @@ namespace gui //! constructor IGUIContextMenu(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect rectangle) : IGUIElement(EGUIET_CONTEXT_MENU, environment, parent, id, rectangle) {} + + //! set behaviour when menus are closed + virtual void setCloseHandling(ECONTEXT_MENU_CLOSE onClose) = 0; + + //! get current behaviour when the menue will be closed + virtual ECONTEXT_MENU_CLOSE getCloseHandling() const = 0; //! Get amount of menu items virtual u32 getItemCount() const = 0; diff -r f2eb59ed5a4a lib/irrlicht/source/Irrlicht/CGUIContextMenu.cpp --- a/lib/irrlicht/source/Irrlicht/CGUIContextMenu.cpp Wed Sep 23 01:11:02 2009 +0200 +++ b/lib/irrlicht/source/Irrlicht/CGUIContextMenu.cpp Wed Sep 23 01:15:04 2009 +0200 @@ -25,6 +25,7 @@ CGUIContextMenu::CGUIContextMenu(IGUIEnv core::rect rectangle, bool getFocus, bool allowFocus) : IGUIContextMenu(environment, parent, id, rectangle), EventParent(0), LastFont(0), HighLighted(-1), ChangeTime(0), AllowFocus(allowFocus) + , CloseHandling(ECMC_REMOVE) { #ifdef _DEBUG setDebugName("CGUIContextMenu"); @@ -51,6 +52,17 @@ CGUIContextMenu::~CGUIContextMenu() LastFont->drop(); } +//! set behaviour when menus are closed +void CGUIContextMenu::setCloseHandling(ECONTEXT_MENU_CLOSE onClose) +{ + CloseHandling = onClose; +} + +//! get current behaviour when the menue will be closed +ECONTEXT_MENU_CLOSE CGUIContextMenu::getCloseHandling() const +{ + return CloseHandling; +} //! Returns amount of menu items u32 CGUIContextMenu::getItemCount() const @@ -269,7 +281,16 @@ bool CGUIContextMenu::OnEvent(const SEve { // set event parent of submenus setEventParent(Parent); - remove(); + + if ( CloseHandling & ECMC_HIDE ) + { + setVisible(false); + } + if ( CloseHandling & ECMC_REMOVE ) + { + remove(); + } + return false; } break; @@ -686,6 +707,8 @@ void CGUIContextMenu::serializeAttribute out->addInt("ParentItem", i); } + out->addInt("CloseHandling", (s32)CloseHandling); + // write out the item list out->addInt("ItemCount", Items.size()); @@ -726,6 +749,7 @@ void CGUIContextMenu::deserializeAttribu if (Parent && ( Parent->getType() == EGUIET_CONTEXT_MENU || Parent->getType() == EGUIET_MENU ) ) ((CGUIContextMenu*)Parent)->setSubMenu(in->getAttributeAsInt("ParentItem"),this); + CloseHandling = (ECONTEXT_MENU_CLOSE)in->getAttributeAsInt("CloseHandling"); removeAllItems(); diff -r f2eb59ed5a4a lib/irrlicht/source/Irrlicht/CGUIContextMenu.h --- a/lib/irrlicht/source/Irrlicht/CGUIContextMenu.h Wed Sep 23 01:11:02 2009 +0200 +++ b/lib/irrlicht/source/Irrlicht/CGUIContextMenu.h Wed Sep 23 01:15:04 2009 +0200 @@ -30,6 +30,12 @@ namespace gui //! destructor virtual ~CGUIContextMenu(); + + //! set behaviour when menus are closed + virtual void setCloseHandling(ECONTEXT_MENU_CLOSE onClose); + + //! get current behaviour when the menue will be closed + virtual ECONTEXT_MENU_CLOSE getCloseHandling() const; //! Returns amount of menu items virtual u32 getItemCount() const; @@ -150,6 +156,7 @@ namespace gui core::position2d Pos; IGUIElement* EventParent; IGUIFont *LastFont; + ECONTEXT_MENU_CLOSE CloseHandling; s32 HighLighted; u32 ChangeTime; bool AllowFocus;