1// SuperTux
2// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3// 2015 Hume2 <teratux.mail@gmail.com>
4//
5// This program is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18#include "gui/menu_item.hpp"
19
20#include "supertux/colorscheme.hpp"
21#include "supertux/resources.hpp"
22#include "video/drawing_context.hpp"
23
24//static const float FLICK_CURSOR_TIME = 0.5f;
25
26MenuItem::MenuItem(const std::string& text, int id) :
27 m_id(id),
28 m_text(text),
29 m_help()
30{
31}
32
33MenuItem::~MenuItem() {
34
35}
36
37void
38MenuItem::set_help(const std::string& help_text)
39{
40 std::string overflow;
41 m_help = Resources::normal_font->wrap_to_width(help_text, 600, &overflow);
42 while (!overflow.empty())
43 {
44 m_help += "\n";
45 m_help += Resources::normal_font->wrap_to_width(overflow, 600, &overflow);
46 }
47}
48
49void
50MenuItem::draw(DrawingContext& context, const Vector& pos, int menu_width, bool active)
51{
52 context.color().draw_text(Resources::normal_font, m_text,
53 Vector( pos.x + static_cast<float>(menu_width) / 2.0f,
54 pos.y - static_cast<float>(Resources::normal_font->get_height()) / 2.0f ),
55 ALIGN_CENTER, LAYER_GUI, active ? ColorScheme::Menu::active_color : get_color());
56}
57
58Color
59MenuItem::get_color() const {
60 return ColorScheme::Menu::default_color;
61}
62
63int
64MenuItem::get_width() const {
65 return static_cast<int>(Resources::normal_font->get_text_width(m_text)) + 16;
66}
67
68/* EOF */
69