recieve events from a menu

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
enforceman
Posts: 26
Joined: Sat Jan 03, 2004 3:43 pm

recieve events from a menu

Post by enforceman »

Hi!

I added some menu like this:


IGUIContextMenu* mainMenu = guienv->addMenu();
// file Menu
s32 idFileMenu = mainMenu->addItem(L"file", 10, true);

How can I check if the user has clicked on the menu item?

Thank you
regards, Tom
Mercior
Posts: 100
Joined: Tue Feb 24, 2004 1:53 am
Location: UK
Contact:

Post by Mercior »

This is the code I use for my context menu:

Code: Select all

OnEvent(SEvent event)
{
if (event.EventType == EET_GUI_EVENT && event.GUIEvent.EventType == EGET_MENU_ITEM_SELECTED)
	{
		// Menu events
		s32 menuidx = ((IGUIContextMenu *)event.GUIEvent.Caller)->getSelectedItem();
		s32 mid = ((IGUIContextMenu *)event.GUIEvent.Caller)->getItemCommandId(menuidx);
Note that this gets the command ID of the selected item (IE this will call back with command ID's of items within your menu, like "file->new", It will not call back when the user has just selected "file". If you want to check for the user clicking on "file" then give your main menu an ID and check for that ID in OnEvent()

Code: Select all

mainMenu->setID(100);
...
s32 menuidx = event.GUIEvent.Caller->getID();
Post Reply