Hi,
After my previous post I learned that I had to associate a Panel with an event handler in order to use relative coordinates. My attempts here are within the multi state game template found in the gledplay distribution.
Now I'm attempting to build panels dynamically where a Panel will have zero or more Panels, which each in turn will have zero or more Panels themselves. The quantity of both levels of Panels needs to change dynamically.
The documentation for the Panel class shows examples of creating Panels within the onNextFrame event.
This seems to be an inefficient approach (I'm just guessing, not accusing) and contradictory to the EventHandler onNextFrame documentation which simply states that drawing should be done here
Also, within this method there is no access to the current state for the application, and therefore I don't seem to have the ability to assign an event handler to any newly created Panel.
Can someone please provide some clarification on the differences of the documented approaches for onNextFrame (is it ok to be constructing objects and so forth), and also, how to go about creating Panels with associated event handlers at runtime?
Thanks.
After my previous post I learned that I had to associate a Panel with an event handler in order to use relative coordinates. My attempts here are within the multi state game template found in the gledplay distribution.
Now I'm attempting to build panels dynamically where a Panel will have zero or more Panels, which each in turn will have zero or more Panels themselves. The quantity of both levels of Panels needs to change dynamically.
The documentation for the Panel class shows examples of creating Panels within the onNextFrame event.
- Code:
HRESULT LaurasQuest::onNextFrame(Surface* pBackBuffer)
{
Panel mainPanel(pBackBuffer);
Panel inventory, playerMenu, msgConsole;
mainPanel.addChild(inventory, Utility::Rect(0, 20, 280, 240));
mainPanel.addChild(playerMenu, Utility::Rect(280, 0, 320, 240));
mainPanel.addChild(msgConsole, Utility::Rect(0, 0, 280, 60));
drawInventory(inventory);
drawPlayerMenu(playerMenu);
drawMsgConsole(msgConsole);
}
This seems to be an inefficient approach (I'm just guessing, not accusing) and contradictory to the EventHandler onNextFrame documentation which simply states that drawing should be done here
- Code:
HRESULT TestApplication::onNextFrame(Surface* pBackBuffer, Panel* panel)
{
pBackBuffer->fillRect(RGB(128,128,128));
pBackBuffer->drawText(120, 100, Font::getSystemFontWithBorder(),
Font::CENTER_ALIGN, TEXT("Hello World!"));
return ReturnCode::OK;
}
Also, within this method there is no access to the current state for the application, and therefore I don't seem to have the ability to assign an event handler to any newly created Panel.
Can someone please provide some clarification on the differences of the documented approaches for onNextFrame (is it ok to be constructing objects and so forth), and also, how to go about creating Panels with associated event handlers at runtime?
Thanks.