X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=src%2Fapp%2Fapp.cpp;h=8817d1f75bf821d48f58c5c1b6726f735bb60d53;hb=5cd73a8f2b40e59ec13aa2a6af33bc8e2a6b9a6c;hp=f3c9115faedf3b50c96002efe1c231ee0e0547ed;hpb=7bb75960dbf9bfdee9ac865384aca81791b3da5c;p=blank.git diff --git a/src/app/app.cpp b/src/app/app.cpp index f3c9115..8817d1f 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -96,9 +96,6 @@ void Application::HandleEvents() { void Application::Handle(const SDL_Event &event) { switch (event.type) { - case SDL_QUIT: - env.state.PopAll(); - break; case SDL_WINDOWEVENT: Handle(event.window); break; @@ -148,18 +145,41 @@ void Application::Render() { void Application::PushState(State *s) { + if (!states.empty()) { + states.top()->OnPause(); + } states.emplace(s); + ++s->ref_count; + if (s->ref_count == 1) { + s->OnEnter(); + } + s->OnResume(); } State *Application::PopState() { State *s = states.top(); states.pop(); + s->OnPause(); + s->OnExit(); + if (!states.empty()) { + states.top()->OnResume(); + } return s; } State *Application::SwitchState(State *s_new) { State *s_old = states.top(); states.top() = s_new; + --s_old->ref_count; + ++s_new->ref_count; + s_old->OnPause(); + if (s_old->ref_count == 0) { + s_old->OnExit(); + } + if (s_new->ref_count == 1) { + s_new->OnEnter(); + } + s_new->OnResume(); return s_old; } @@ -199,7 +219,9 @@ void StateControl::Commit(Application &app) { Assets::Assets(const string &base) : fonts(base + "fonts/") , sounds(base + "sounds/") -, textures(base + "textures/") { +, textures(base + "textures/") +, large_ui_font(LoadFont("DejaVuSans", 24)) +, small_ui_font(LoadFont("DejaVuSans", 16)) { }