2 // Copyright (C) 2014 Ingo Ruhnke <grumbel@gmail.com>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "gui/dialog.hpp"
19 #include "control/controller.hpp"
20 #include "supertux/resources.hpp"
21 #include "video/drawing_context.hpp"
31 Dialog::add_button(const std::string& text)
33 m_buttons.push_back(text);
37 Dialog::process_input(const Controller& controller)
39 if (controller.pressed(Controller::LEFT))
41 m_selected_button -= 1;
42 m_selected_button = std::max(m_selected_button, 0);
45 if (controller.pressed(Controller::RIGHT))
47 m_selected_button += 1;
48 m_selected_button = std::min(m_selected_button, static_cast<int>(m_buttons.size()) - 1);
53 Dialog::draw(DrawingContext& ctx)
55 for(int i = 0; i < static_cast<int>(m_buttons.size()); ++i)
57 if (i == m_selected_button)
61 ctx.draw_text(Resources::normal_font, m_buttons[i],
63 ALIGN_CENTER, LAYER_GUI);