#include <Display/Display.hpp>
#include <Utilities/Utilities.hpp>

std::stack<std::shared_ptr<Display>> Display::navStack;

void Display::fastUpdate()
{
    // NOP
}

void Display::onEvent(SDL_Event &event)
{
    if (event.type == SDL_EVENT_KEY_DOWN)
    {
        switch (event.key.key)
        {
        case SDLK_ESCAPE:
            onQuit();
            break;
        case SDLK_F11:
            GraphicsContext::instance->toggleFullscreen();
            break;
        }
    }
    else if (event.type == SDL_EVENT_WINDOW_RESIZED)
    {
        GraphicsContext::instance->onResized();
    }
    else if (event.type == SDL_EVENT_QUIT)
    {
        onQuit();
    }
}

void Display::onQuit()
{
    endGame();
}

void Display::onExposed()
{
    // NOP
}

bool Display::isKeyDown(SDL_Scancode keyCode)
{
    const bool *keyboardState = SDL_GetKeyboardState(NULL);
    return keyboardState[keyCode] != 0;
}

std::shared_ptr<Display> Display::getCurrent()
{
    return navStack.top();
}

void Display::navPop()
{
    navStack.pop();
    navStack.top()->onExposed();
}