globalsinner
03-06-2010 13:18:37
Hi,
I have the following test layout file:
As you can see the button_OK has a key of type event valued at "OK_Pressed". I want an implementation so that when the user presses the button_OK above, the function will be called with the corresponding value of the event (ie. OK_Pressed, in this case). The final layout will have multiple buttons with varying event values and i would like to call a single function for these presses with the event ID as a parameter. After looking at samples and demos, I am using the following code to load the layout and set the event handler for button press.
the the corresponding function is
The code runs and compiles fine, but nothing happens when I press the OK button. Only the event handler for the top-right "X" button is working which calls the function. How do I get the other buttons within the window to work in a similar way?
I have the following test layout file:
<?xml version="1.0" encoding="utf-8"?>
<MyGUI type="Layout">
<Widget type="Window" skin="WindowCSX" position="10 10 300 100" layer="Overlapped" name="MyMainWindow">
<Widget type="StaticText" skin="StaticText" position="5 5 150 26">
<Property key="Text_TextAlign" value="Left VCenter"/>
<Property key="Widget_Caption" value="Select:"/>
</Widget>
<Widget type="Button" skin="Button" position="160 5 107 26" name="button_OK">
<Property key="Widget_Caption" value="Ok"/>
<Property key="Event" value = "OK_Pressed"/>
</Widget>
</Widget>
</MyGUI>
As you can see the button_OK has a key of type event valued at "OK_Pressed". I want an implementation so that when the user presses the button_OK above, the function will be called with the corresponding value of the event (ie. OK_Pressed, in this case). The final layout will have multiple buttons with varying event values and i would like to call a single function for these presses with the event ID as a parameter. After looking at samples and demos, I am using the following code to load the layout and set the event handler for button press.
MyGUI::LayoutManager::getInstance().load("MyMainMenu.layout");
MyGUI::WindowPtr mainWindowX = mGUI->findWidget<MyGUI::Window>("MyMainWindow");
mainWindowX->eventWindowButtonPressed = MyGUI::newDelegate(this, &menuMgr::handlePress);
the the corresponding function is
void menuMgr::handlePress(MyGUI::WidgetPtr _widget, const std::string& _name)
{
if(_name == "OK_Pressed")
{
MyGUI::WindowPtr window = _widget->castType<MyGUI::Window>();
.....
}
}
The code runs and compiles fine, but nothing happens when I press the OK button. Only the event handler for the top-right "X" button is working which calls the function. How do I get the other buttons within the window to work in a similar way?