75 lines
1.4 KiB
C++
75 lines
1.4 KiB
C++
#include "page_manager.h"
|
|
|
|
void PageManager::push(AppState& state, std::unique_ptr<Page> page)
|
|
{
|
|
if (!stack_.empty()) {
|
|
stack_.back()->onPause(state);
|
|
}
|
|
stack_.push_back(std::move(page));
|
|
stack_.back()->onPush(state);
|
|
}
|
|
|
|
void PageManager::pop(AppState& state)
|
|
{
|
|
if (stack_.empty()) return;
|
|
|
|
stack_.back()->onPop(state);
|
|
stack_.pop_back();
|
|
|
|
if (!stack_.empty()) {
|
|
stack_.back()->onResume(state);
|
|
}
|
|
}
|
|
|
|
void PageManager::popToRoot(AppState& state)
|
|
{
|
|
while (stack_.size() > 1) {
|
|
stack_.back()->onPop(state);
|
|
stack_.pop_back();
|
|
}
|
|
if (!stack_.empty()) {
|
|
stack_.back()->onResume(state);
|
|
}
|
|
}
|
|
|
|
void PageManager::replace(AppState& state, std::unique_ptr<Page> page)
|
|
{
|
|
if (!stack_.empty()) {
|
|
stack_.back()->onPop(state);
|
|
stack_.pop_back();
|
|
}
|
|
stack_.push_back(std::move(page));
|
|
stack_.back()->onPush(state);
|
|
}
|
|
|
|
Page* PageManager::current() const
|
|
{
|
|
return stack_.empty() ? nullptr : stack_.back().get();
|
|
}
|
|
|
|
std::size_t PageManager::depth() const
|
|
{
|
|
return stack_.size();
|
|
}
|
|
|
|
void PageManager::handleEvent(const SDL_Event& event)
|
|
{
|
|
if (!stack_.empty()) {
|
|
stack_.back()->handleEvent(event);
|
|
}
|
|
}
|
|
|
|
void PageManager::update(float dt)
|
|
{
|
|
if (!stack_.empty()) {
|
|
stack_.back()->update(dt);
|
|
}
|
|
}
|
|
|
|
void PageManager::render(SDL_Renderer* renderer)
|
|
{
|
|
if (!stack_.empty()) {
|
|
stack_.back()->render(renderer);
|
|
}
|
|
}
|