Add focus callback to GUI engine

This commit is contained in:
Marianne Gagnon 2015-01-15 20:18:31 -05:00
parent d3708ba798
commit 84821ad604
2 changed files with 10 additions and 3 deletions

View File

@ -311,6 +311,9 @@ namespace GUIEngine
* Can be used to set focus for instance.
*/
virtual void onDialogClose() {}
/** Callback called when focus changes */
virtual void onFocusChanged(Widget* previous, Widget* focus, int playerID) {}
};
class CutsceneScreen : public Screen

View File

@ -255,10 +255,11 @@ void Widget::setFocusForPlayer(const int playerID)
assert(m_magic_number == 0xCAFEC001);
// Unset focus flag on previous widget that had focus
if (GUIEngine::getFocusForPlayer(playerID) != NULL)
Widget* previous_focus = GUIEngine::getFocusForPlayer(playerID);
if (previous_focus != NULL)
{
GUIEngine::getFocusForPlayer(playerID)->unfocused(playerID, this);
GUIEngine::getFocusForPlayer(playerID)->m_player_focus[playerID] = false;
previous_focus->unfocused(playerID, this);
previous_focus->m_player_focus[playerID] = false;
}
m_player_focus[playerID] = true;
@ -266,6 +267,9 @@ void Widget::setFocusForPlayer(const int playerID)
// Callback
this->focused(playerID);
Screen* screen = GUIEngine::getCurrentScreen();
screen->onFocusChanged(previous_focus, this, playerID);
}
// -----------------------------------------------------------------------------