void Dialog::process_input(const Controller& controller) { if (controller.pressed(Controller::LEFT)) { m_selected_button -= 1; m_selected_button = std::max(m_selected_button, 0); } if (controller.pressed(Controller::RIGHT)) { m_selected_button += 1; m_selected_button = std::min(m_selected_button, static_cast<int>(m_buttons.size()) - 1); } if (controller.pressed(Controller::ACTION) || controller.pressed(Controller::MENU_SELECT)) { on_button_click(m_selected_button); } if (m_cancel_button != -1 && (controller.pressed(Controller::ESCAPE) || controller.pressed(Controller::MENU_BACK))) { on_button_click(m_cancel_button); } }
void Dialog::event(const SDL_Event& ev) { if (m_passive) // Passive dialogs don't accept events return; switch (ev.type) { case SDL_MOUSEBUTTONDOWN: if (ev.button.button == SDL_BUTTON_LEFT) { Vector mouse_pos = VideoSystem::current()->get_viewport().to_logical(ev.motion.x, ev.motion.y); int new_button = get_button_at(mouse_pos); if (new_button != -1) { m_selected_button = new_button; on_button_click(m_selected_button); } } break; case SDL_MOUSEMOTION: { Vector mouse_pos = VideoSystem::current()->get_viewport().to_logical(ev.motion.x, ev.motion.y); int new_button = get_button_at(mouse_pos); if (new_button != -1) { m_selected_button = new_button; if (MouseCursor::current()) MouseCursor::current()->set_state(MouseCursorState::LINK); } else { if (MouseCursor::current()) MouseCursor::current()->set_state(MouseCursorState::NORMAL); } } break; default: break; } }
void Dialog::event(const SDL_Event& ev) { switch(ev.type) { case SDL_MOUSEBUTTONDOWN: if(ev.button.button == SDL_BUTTON_LEFT) { Vector mouse_pos = VideoSystem::current()->get_renderer().to_logical(ev.motion.x, ev.motion.y); int new_button = get_button_at(mouse_pos); if (new_button != -1) { m_selected_button = new_button; on_button_click(m_selected_button); } } break; case SDL_MOUSEMOTION: { Vector mouse_pos = VideoSystem::current()->get_renderer().to_logical(ev.motion.x, ev.motion.y); int new_button = get_button_at(mouse_pos); if (new_button != -1) { m_selected_button = new_button; if(MouseCursor::current()) MouseCursor::current()->set_state(MC_LINK); } else { if(MouseCursor::current()) MouseCursor::current()->set_state(MC_NORMAL); } } break; default: break; } }