From 309f1d20a77408c19d2452acc69e02774a94fb0e Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Wed, 18 Nov 2009 01:51:42 +0000 Subject: [PATCH] Split gui/menu.?pp SVN-Revision: 6021 --- src/control/joystickkeyboardcontroller.cpp | 1 + src/gui/menu.cpp | 65 +-------------------- src/gui/menu.hpp | 54 +----------------- src/gui/menu_item.cpp | 92 ++++++++++++++++++++++++++++++ src/gui/menu_item.hpp | 82 ++++++++++++++++++++++++++ src/supertux/options_menu.cpp | 3 + src/supertux/profile_menu.cpp | 1 + src/supertux/title_screen.cpp | 1 + 8 files changed, 184 insertions(+), 115 deletions(-) create mode 100644 src/gui/menu_item.cpp create mode 100644 src/gui/menu_item.hpp diff --git a/src/control/joystickkeyboardcontroller.cpp b/src/control/joystickkeyboardcontroller.cpp index 6127e2df7..006fb2cb6 100644 --- a/src/control/joystickkeyboardcontroller.cpp +++ b/src/control/joystickkeyboardcontroller.cpp @@ -20,6 +20,7 @@ #include #include "gui/menu.hpp" +#include "gui/menu_item.hpp" #include "util/writer.hpp" #include "lisp/list_iterator.hpp" #include "supertux/gameconfig.hpp" diff --git a/src/gui/menu.cpp b/src/gui/menu.cpp index 158bb069b..027608868 100644 --- a/src/gui/menu.cpp +++ b/src/gui/menu.cpp @@ -14,10 +14,12 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include "gui/menu.hpp" + #include #include "control/joystickkeyboardcontroller.hpp" -#include "gui/menu.hpp" +#include "gui/menu_item.hpp" #include "supertux/main.hpp" #include "supertux/mainloop.hpp" #include "supertux/resources.hpp" @@ -27,7 +29,6 @@ static const float MENU_REPEAT_INITIAL = 0.4f; static const float MENU_REPEAT_RATE = 0.1f; -static const float FLICK_CURSOR_TIME = 0.5f; extern SDL_Surface* g_screen; @@ -162,66 +163,6 @@ Menu::recalc_pos() } } -MenuItem::MenuItem(MenuItemKind _kind, int _id) : - kind(_kind), - id(_id), - toggled(), - text(), - input(), - help(), - list(), - selected(), - target_menu(), - input_flickering() -{ - toggled = false; - selected = false; - target_menu = 0; -} - -void -MenuItem::change_text(const std::string& text_) -{ - text = text_; -} - -void -MenuItem::change_input(const std::string& text_) -{ - input = text_; -} - -void -MenuItem::set_help(const std::string& help_text) -{ - std::string overflow; - help = normal_font->wrap_to_width(help_text, 600, &overflow); - while (!overflow.empty()) - { - help += "\n"; - help += normal_font->wrap_to_width(overflow, 600, &overflow); - } -} - -std::string MenuItem::get_input_with_symbol(bool active_item) -{ - if(!active_item) { - input_flickering = true; - } else { - input_flickering = ((int) (real_time / FLICK_CURSOR_TIME)) % 2; - } - - char str[1024]; - if(input_flickering) - snprintf(str, sizeof(str), "%s ",input.c_str()); - else - snprintf(str, sizeof(str), "%s_",input.c_str()); - - std::string string = str; - - return string; -} - Menu::~Menu() { all_menus.remove(this); diff --git a/src/gui/menu.hpp b/src/gui/menu.hpp index 428244d17..8ac6db2d0 100644 --- a/src/gui/menu.hpp +++ b/src/gui/menu.hpp @@ -26,59 +26,7 @@ bool confirm_dialog(Surface* background, std::string text); -/* Kinds of menu items */ -enum MenuItemKind { - MN_ACTION, - MN_GOTO, - MN_TOGGLE, - MN_BACK, - MN_INACTIVE, - MN_TEXTFIELD, - MN_NUMFIELD, - MN_CONTROLFIELD, - MN_STRINGSELECT, - MN_LABEL, - MN_HL /* horizontal line */ -}; - -class Menu; - -class MenuItem -{ -public: - MenuItem(MenuItemKind kind, int id = -1); - - void set_help(const std::string& help_text); - - void change_text (const std::string& text); - void change_input(const std::string& text); - - static MenuItem* create(MenuItemKind kind, const std::string& text, - int init_toggle, Menu* target_menu, int id, int key); - - std::string get_input_with_symbol(bool active_item); // returns the text with an input symbol - -public: - MenuItemKind kind; - int id; // item id - bool toggled; - std::string text; - std::string input; - std::string help; - - std::vector list; // list of values for a STRINGSELECT item - size_t selected; // currently selected item - - Menu* target_menu; - -private: - /// keyboard key or joystick button - bool input_flickering; - -private: - MenuItem(const MenuItem&); - MenuItem& operator=(const MenuItem&); -}; +class MenuItem; class Menu { diff --git a/src/gui/menu_item.cpp b/src/gui/menu_item.cpp new file mode 100644 index 000000000..892c9e1e2 --- /dev/null +++ b/src/gui/menu_item.cpp @@ -0,0 +1,92 @@ +// SuperTux +// Copyright (C) 2006 Matthias Braun +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#include "gui/menu_item.hpp" + +#include + +#include "control/joystickkeyboardcontroller.hpp" +#include "supertux/main.hpp" +#include "supertux/mainloop.hpp" +#include "supertux/resources.hpp" +#include "supertux/timer.hpp" +#include "util/gettext.hpp" +#include "video/drawing_context.hpp" + +static const float FLICK_CURSOR_TIME = 0.5f; + +MenuItem::MenuItem(MenuItemKind _kind, int _id) : + kind(_kind), + id(_id), + toggled(), + text(), + input(), + help(), + list(), + selected(), + target_menu(), + input_flickering() +{ + toggled = false; + selected = false; + target_menu = 0; +} + +void +MenuItem::change_text(const std::string& text_) +{ + text = text_; +} + +void +MenuItem::change_input(const std::string& text_) +{ + input = text_; +} + +void +MenuItem::set_help(const std::string& help_text) +{ + std::string overflow; + help = normal_font->wrap_to_width(help_text, 600, &overflow); + while (!overflow.empty()) + { + help += "\n"; + help += normal_font->wrap_to_width(overflow, 600, &overflow); + } +} + +std::string +MenuItem::get_input_with_symbol(bool active_item) +{ + if(!active_item) { + input_flickering = true; + } else { + input_flickering = ((int) (real_time / FLICK_CURSOR_TIME)) % 2; + } + + char str[1024]; + if(input_flickering) + snprintf(str, sizeof(str), "%s ",input.c_str()); + else + snprintf(str, sizeof(str), "%s_",input.c_str()); + + std::string string = str; + + return string; +} + +/* EOF */ diff --git a/src/gui/menu_item.hpp b/src/gui/menu_item.hpp new file mode 100644 index 000000000..dcebc2ac5 --- /dev/null +++ b/src/gui/menu_item.hpp @@ -0,0 +1,82 @@ +// SuperTux +// Copyright (C) 2006 Matthias Braun +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +#ifndef HEADER_SUPERTUX_GUI_MENU_ITEM_HPP +#define HEADER_SUPERTUX_GUI_MENU_ITEM_HPP + +#include +#include +#include + +#include "gui/menu.hpp" +#include "gui/mousecursor.hpp" +#include "video/font.hpp" + +/* Kinds of menu items */ +enum MenuItemKind { + MN_ACTION, + MN_GOTO, + MN_TOGGLE, + MN_BACK, + MN_INACTIVE, + MN_TEXTFIELD, + MN_NUMFIELD, + MN_CONTROLFIELD, + MN_STRINGSELECT, + MN_LABEL, + MN_HL /* horizontal line */ +}; + +class MenuItem +{ +public: + MenuItem(MenuItemKind kind, int id = -1); + + void set_help(const std::string& help_text); + + void change_text (const std::string& text); + void change_input(const std::string& text); + + static MenuItem* create(MenuItemKind kind, const std::string& text, + int init_toggle, Menu* target_menu, int id, int key); + + std::string get_input_with_symbol(bool active_item); // returns the text with an input symbol + +public: + MenuItemKind kind; + int id; // item id + bool toggled; + std::string text; + std::string input; + std::string help; + + std::vector list; // list of values for a STRINGSELECT item + size_t selected; // currently selected item + + Menu* target_menu; + +private: + /// keyboard key or joystick button + bool input_flickering; + +private: + MenuItem(const MenuItem&); + MenuItem& operator=(const MenuItem&); +}; + +#endif + +/* EOF */ diff --git a/src/supertux/options_menu.cpp b/src/supertux/options_menu.cpp index 355102baa..06556bdd6 100644 --- a/src/supertux/options_menu.cpp +++ b/src/supertux/options_menu.cpp @@ -15,9 +15,12 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . +#include "supertux/options_menu.hpp" + #include "audio/sound_manager.hpp" #include "control/joystickkeyboardcontroller.hpp" #include "gui/menu.hpp" +#include "gui/menu_item.hpp" #include "supertux/gameconfig.hpp" #include "supertux/main.hpp" #include "supertux/profile_menu.hpp" diff --git a/src/supertux/profile_menu.cpp b/src/supertux/profile_menu.cpp index 87734b08b..9ae1ff7cf 100644 --- a/src/supertux/profile_menu.cpp +++ b/src/supertux/profile_menu.cpp @@ -15,6 +15,7 @@ // along with this program. If not, see . #include "gui/menu.hpp" +#include "gui/menu_item.hpp" #include "supertux/gameconfig.hpp" #include "util/gettext.hpp" diff --git a/src/supertux/title_screen.cpp b/src/supertux/title_screen.cpp index da5049fb5..55fb4e909 100644 --- a/src/supertux/title_screen.cpp +++ b/src/supertux/title_screen.cpp @@ -25,6 +25,7 @@ #include "addon/addon_manager.hpp" #include "audio/sound_manager.hpp" #include "gui/menu.hpp" +#include "gui/menu_item.hpp" #include "lisp/parser.hpp" #include "lisp/lisp.hpp" #include "object/camera.hpp" -- 2.11.0