| 1 | //  SuperTux | 
|---|
| 2 | //  Copyright (C) 2015 Hume2 <teratux.mail@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/item_back.hpp" | 
|---|
| 18 |  | 
|---|
| 19 | #include "gui/menu_manager.hpp" | 
|---|
| 20 | #include "supertux/colorscheme.hpp" | 
|---|
| 21 | #include "supertux/resources.hpp" | 
|---|
| 22 | #include "video/drawing_context.hpp" | 
|---|
| 23 | #include "video/surface.hpp" | 
|---|
| 24 |  | 
|---|
| 25 | ItemBack::ItemBack(const std::string& text, int id) : | 
|---|
| 26 | MenuItem(text, id) | 
|---|
| 27 | { | 
|---|
| 28 | } | 
|---|
| 29 |  | 
|---|
| 30 | void | 
|---|
| 31 | ItemBack::draw(DrawingContext& context, const Vector& pos, int , bool active) | 
|---|
| 32 | { | 
|---|
| 33 | float text_width = Resources::normal_font->get_text_width(get_text()); | 
|---|
| 34 | context.color().draw_text(Resources::normal_font, get_text(), | 
|---|
| 35 | Vector( pos.x + static_cast<float>(menu_width) / 2.0f, | 
|---|
| 36 | pos.y - static_cast<float>(int(Resources::normal_font->get_height()/2))), | 
|---|
| 37 | ALIGN_CENTER, LAYER_GUI, active ? ColorScheme::Menu::active_color : get_color()); | 
|---|
| 38 | context.color().draw_surface(Resources::back, | 
|---|
| 39 | Vector(pos.x + static_cast<float>(menu_width) / 2.0f + text_width / 2.0f  + 16.0f, | 
|---|
| 40 | pos.y - 8.0f), | 
|---|
| 41 | LAYER_GUI); | 
|---|
| 42 | } | 
|---|
| 43 |  | 
|---|
| 44 | int | 
|---|
| 45 | ItemBack::get_width() const { | 
|---|
| 46 | return static_cast<int>(Resources::normal_font->get_text_width(get_text())) + 32 + Resources::back->get_width(); | 
|---|
| 47 | } | 
|---|
| 48 |  | 
|---|
| 49 | void | 
|---|
| 50 | ItemBack::(const MenuAction& action) { | 
|---|
| 51 | if (action == MenuAction::HIT) { | 
|---|
| 52 | if (MenuManager::instance().current_menu()->on_back_action()) | 
|---|
| 53 | MenuManager::instance().pop_menu(); | 
|---|
| 54 | } | 
|---|
| 55 | } | 
|---|
| 56 | /* EOF */ | 
|---|
| 57 |  | 
|---|