Add on_scene_enter & on_scene_exit

This commit is contained in:
Nikita Lisitsa 2020-09-13 11:11:58 +03:00
parent 29827743f6
commit e97812dcaf
2 changed files with 9 additions and 1 deletions

View file

@ -9,6 +9,9 @@ namespace psemek::app
{ {
virtual ~scene() = 0; virtual ~scene() = 0;
virtual void on_scene_enter() {}
virtual void on_scene_exit() {}
virtual void on_resize(int width, int height) {} virtual void on_resize(int width, int height) {}
virtual void on_focus_gained() {} virtual void on_focus_gained() {}
virtual void on_focus_lost() {} virtual void on_focus_lost() {}

View file

@ -198,6 +198,7 @@ namespace psemek::app
void app::run() void app::run()
{ {
impl().running = true; impl().running = true;
impl().get_scene()->on_scene_enter();
while (running()) while (running())
{ {
poll_events(); poll_events();
@ -221,9 +222,13 @@ namespace psemek::app
scene * app::set_scene(scene * s) scene * app::set_scene(scene * s)
{ {
impl().had_initial_resize = false; impl().get_scene()->on_scene_exit();
impl().had_initial_resize = false;
std::swap(s, impl().current_scene); std::swap(s, impl().current_scene);
impl().get_scene()->on_scene_enter();
return s; return s;
} }