Beispiel #1
0
void State::handleEvent(const SDL_Event& e) {
    auto& m = getCurrentMenu();
    if (!m) return;

    switch (e.type) {
    case SDL_MOUSEBUTTONUP:
        if (e.button.button == SDL_BUTTON_LEFT)
                m->click(e.button.x, e.button.y);
            break;

        case SDL_MOUSEMOTION:
            m->hover(e.motion.x, e.motion.y);
            break;

        case SDL_KEYDOWN:
            switch (e.key.keysym.sym) {
                case SDLK_UP:
                    m->move(-1);
                    break;

                case SDLK_DOWN:
                    m->move(1);
                    break;

                case SDLK_RETURN:
                    m->activate();
                    break;
            }
    }
}
Beispiel #2
0
 inline bool isInMenu() { return getCurrentMenu() != nullptr; }
Beispiel #3
0
void State::draw(GameRenderer& r) {
    auto& menu = getCurrentMenu();
    if (menu) {
        menu->draw(r);
    }
}