Added some initial dialog code, doesn't do anything yet
[supertux.git] / src / gui / dialog.cpp
1 //  SuperTux
2 //  Copyright (C) 2014 Ingo Ruhnke <grumbel@gmail.com>
3 //
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.
8 //
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.
13 //
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/>.
16
17 #include "gui/dialog.hpp"
18
19 #include "control/controller.hpp"
20 #include "supertux/resources.hpp"
21 #include "video/drawing_context.hpp"
22
23 Dialog::Dialog() :
24   m_text("<no-text>"),
25   m_buttons(),
26   m_selected_button()
27 {
28 }
29
30 void
31 Dialog::add_button(const std::string& text)
32 {
33   m_buttons.push_back(text);
34 }
35
36 void
37 Dialog::process_input(const Controller& controller)
38 {
39   if (controller.pressed(Controller::LEFT))
40   {
41     m_selected_button -= 1;
42     m_selected_button = std::max(m_selected_button, 0);
43   }
44
45   if (controller.pressed(Controller::RIGHT))
46   {
47     m_selected_button += 1;
48     m_selected_button = std::min(m_selected_button, static_cast<int>(m_buttons.size()) - 1);
49   }     
50 }
51
52 void
53 Dialog::draw(DrawingContext& ctx)
54 {
55   for(int i = 0; i < static_cast<int>(m_buttons.size()); ++i)
56   {
57     if (i == m_selected_button)
58     {
59       // highlight
60     }
61     ctx.draw_text(Resources::normal_font, m_buttons[i],
62                   Vector(100, 100),
63                   ALIGN_CENTER, LAYER_GUI);
64   }
65 }
66
67 /* EOF */