xml for menus

querry43

29-07-2008 03:07:48

I would like to describe menus entirely from xml, but I'm not sure how to setup the popup menu items. Digging through the code, I wasn't able to find a way to do this. Is this currently possible? Is it planned?

Here is my working example which programmatically creates popup menu items:

<?xml version="1.0" encoding="UTF-8"?>
<MyGUI type="Layout">
<Widget type="MenuBar" skin="MenuBar" position="0 0 800 20" align="ALIGN_LEFT ALIGN_HSTRETCH" layer="Main" name="Menu" >
<Property key="MenuBar_AddItem" value="File" />
<Property key="MenuBar_AddItem" value="Edit" />
</Widget>
</MyGUI>

void initialize()
{
...
MyGUI::MenuBarPtr menuBar = mGUI->findWidget<MyGUI::MenuBar>("Menu");
menuBar->getItemMenu(0)->addItem("Quit");
menuBar->getItemMenu(0)->eventPopupMenuAccept = MyGUI::newDelegate(this, &TerrainFrameListener::handleMenu);
...
}

void handleMenu(MyGUI::WidgetPtr _sender, size_t index)
{
switch(index)
{
case 0:
this->exit = true;
break;
}
}


Thanks.

PS: How do I get the menu item to de-select after I have triggered an eventPopupMenuAccept?

my.name

29-07-2008 09:33:12

menu is alpha version

Altren

29-07-2008 12:59:36

I would like to describe menus entirely from xml, but I'm not sure how to setup the popup menu items. Digging through the code, I wasn't able to find a way to do this. Is this currently possible? Is it planned?I'm working on it. Still thinking how to make it Ñ

querry43

29-07-2008 22:58:35

menu is alpha version
I'm not afraid; I'm running the OSX build. It actually works fairly well at current, but I'll keep my eye out for API changes.


I'm working on it. Still thinking how to make it Ñ

Altren

30-07-2008 12:26:42

It may be confusing to use the item index for handling menu actions. If names were used, items could be arbitrarily re-arranged or even removed in the XML without altering code.Yes, I'm planning to make it as you said.
If I do not assign eventPopupMenuAccept handler, it fades and deselects automatically. If I assign a handler, then it fades, but the MenuBar item, "File" in this example, will stay selected until the next time I click it. The screenshot is from the code above with an extra item for demonstration.



I'm not sure how old my codebase is; I'm using the version found in this thread:
http://www.ogre3d.org/phpBB2addons/viewtopic.php?t=7533&start=0&postdays=0&postorder=asc&highlight=&sid=ce193664e1d3d7c4af509e6f4e2718c6
I think it's because of not latest version (there's lots of changes in MenuBar and PopupMenu).