diff -r af2a16dbbbd0 lib/irrlicht/include/IGUIContextMenu.h --- a/lib/irrlicht/include/IGUIContextMenu.h Wed Sep 23 15:16:14 2009 +0200 +++ b/lib/irrlicht/include/IGUIContextMenu.h Wed Sep 23 15:17:40 2009 +0200 @@ -57,6 +57,22 @@ namespace gui \param checked: Specifies if the menu item should be initially checked. \return Returns the index of the new item */ virtual u32 addItem(const wchar_t* text, s32 commandId=-1, bool enabled=true, + bool hasSubMenu=false, bool checked=false, bool autoChecking=false) = 0; + + //! Insert a menu item at specified position. + /** \param idx: Position to insert the new element, + should be smaller than itemcount otherwise the item is added to the end. + \param text: Text of menu item. Set this to 0 to create + an separator instead of a real item, which is the same like + calling addSeparator(); + \param commandId: Command id of menu item, a simple id you may + set to whatever you want. + \param enabled: Specifies if the menu item should be enabled. + \param hasSubMenu: Set this to true if there should be a submenu + at this item. You can acess this submenu via getSubMenu(). + \param checked: Specifies if the menu item should be initially checked. + \return Returns the index of the new item */ + virtual u32 insertItem(u32 idx, const wchar_t* text, s32 commandId=-1, bool enabled=true, bool hasSubMenu=false, bool checked=false, bool autoChecking=false) = 0; //! Find a item which has the given CommandId starting from given index diff -r af2a16dbbbd0 lib/irrlicht/source/Irrlicht/CGUIContextMenu.cpp --- a/lib/irrlicht/source/Irrlicht/CGUIContextMenu.cpp Wed Sep 23 15:16:14 2009 +0200 +++ b/lib/irrlicht/source/Irrlicht/CGUIContextMenu.cpp Wed Sep 23 15:17:40 2009 +0200 @@ -72,7 +72,14 @@ u32 CGUIContextMenu::getItemCount() cons //! Adds a menu item. -u32 CGUIContextMenu::addItem(const wchar_t* text, s32 id, bool enabled, bool hasSubMenu, bool checked, bool autoChecking) +u32 CGUIContextMenu::addItem(const wchar_t* text, s32 commandId, bool enabled, bool hasSubMenu, bool checked, bool autoChecking) +{ + return insertItem(Items.size(), text, commandId, enabled, hasSubMenu, checked, autoChecking); +} + +//! Insert a menu item at specified position. +u32 CGUIContextMenu::insertItem(u32 idx, const wchar_t* text, s32 commandId, bool enabled, + bool hasSubMenu, bool checked, bool autoChecking) { SItem s; s.Enabled = enabled; @@ -81,19 +88,28 @@ u32 CGUIContextMenu::addItem(const wchar s.Text = text; s.IsSeparator = (text == 0); s.SubMenu = 0; - s.CommandId = id; + s.CommandId = commandId; if (hasSubMenu) { - s.SubMenu = new CGUIContextMenu(Environment, this, id, + s.SubMenu = new CGUIContextMenu(Environment, this, commandId, core::rect(0,0,100,100), false, false); s.SubMenu->setVisible(false); } - Items.push_back(s); + u32 result = idx; + if ( idx < Items.size() ) + { + Items.insert(s, idx); + } + else + { + Items.push_back(s); + result = Items.size() - 1; + } recalculateSize(); - return Items.size() - 1; + return result; } s32 CGUIContextMenu::findItemWithCommandId(s32 commandId, u32 idxStartSearch) const diff -r af2a16dbbbd0 lib/irrlicht/source/Irrlicht/CGUIContextMenu.h --- a/lib/irrlicht/source/Irrlicht/CGUIContextMenu.h Wed Sep 23 15:16:14 2009 +0200 +++ b/lib/irrlicht/source/Irrlicht/CGUIContextMenu.h Wed Sep 23 15:17:40 2009 +0200 @@ -43,6 +43,10 @@ namespace gui //! Adds a menu item. virtual u32 addItem(const wchar_t* text, s32 commandid, bool enabled, bool hasSubMenu, bool checked, bool autoChecking); + + //! Insert a menu item at specified position. + virtual u32 insertItem(u32 idx, const wchar_t* text, s32 commandId, bool enabled, + bool hasSubMenu, bool checked, bool autoChecking); //! Find a item which has the given CommandId starting from given index //! return -1 if no such item was found