| 1 | // SuperTux |
| 2 | // Copyright (C) 2006 Matthias Braun <matze@braunis.de> |
| 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 | #ifndef HEADER_SUPERTUX_GUI_MENU_HPP |
| 18 | #define |
| 19 | |
| 20 | #include <functional> |
| 21 | #include <memory> |
| 22 | #include <SDL.h> |
| 23 | |
| 24 | #include "gui/menu_action.hpp" |
| 25 | #include "math/vector.hpp" |
| 26 | #include "video/color.hpp" |
| 27 | |
| 28 | class Controller; |
| 29 | class DrawingContext; |
| 30 | class ItemAction; |
| 31 | class ItemBack; |
| 32 | class ItemBadguySelect; |
| 33 | class ItemColor; |
| 34 | class ItemColorChannel; |
| 35 | class ItemColorDisplay; |
| 36 | class ItemControlField; |
| 37 | class ItemFile; |
| 38 | class ItemGoTo; |
| 39 | class ItemHorizontalLine; |
| 40 | class ItemInactive; |
| 41 | class ItemIntField; |
| 42 | class ItemLabel; |
| 43 | class ItemFloatField; |
| 44 | class ItemScript; |
| 45 | class ItemScriptLine; |
| 46 | class ItemStringSelect; |
| 47 | class ItemTextField; |
| 48 | class ItemToggle; |
| 49 | class ; |
| 50 | |
| 51 | class |
| 52 | { |
| 53 | public: |
| 54 | (); |
| 55 | virtual (); |
| 56 | |
| 57 | virtual void (MenuItem& item) = 0; |
| 58 | |
| 59 | /** Executed before the menu is exited |
| 60 | @return true if it should perform the back action, false if it shouldn't */ |
| 61 | virtual bool () { return true; } |
| 62 | |
| 63 | /** Perform actions to bring the menu up to date with configuration changes */ |
| 64 | virtual void () {} |
| 65 | |
| 66 | virtual void (); |
| 67 | |
| 68 | ItemHorizontalLine& (); |
| 69 | ItemLabel& (const std::string& text); |
| 70 | ItemAction& (int id, const std::string& text); |
| 71 | ItemAction& (const std::string& text, std::function<void()> callback); |
| 72 | ItemToggle& (int id, const std::string& text, bool* toggled); |
| 73 | ItemToggle& (int id, const std::string& text, |
| 74 | std::function<bool()> get_func, |
| 75 | std::function<void(bool)> set_func); |
| 76 | ItemInactive& (const std::string& text); |
| 77 | ItemBack& (const std::string& text, int id = -1); |
| 78 | ItemGoTo& (const std::string& text, int , int id = -1); |
| 79 | ItemControlField& (int id, const std::string& text, const std::string& mapping = "" ); |
| 80 | ItemStringSelect& (int id, const std::string& text, int* selected, const std::vector<std::string>& strings); |
| 81 | ItemTextField& (const std::string& text, std::string* input, int id = -1); |
| 82 | ItemScript& (const std::string& text, std::string* script, int id = -1); |
| 83 | ItemScriptLine& (std::string* input, int id = -1); |
| 84 | ItemIntField& (const std::string& text, int* input, int id = -1); |
| 85 | ItemFloatField& (const std::string& text, float* input, int id = -1); |
| 86 | ItemBadguySelect& (const std::string& text, std::vector<std::string>* badguys, int id = -1); |
| 87 | ItemFile& (const std::string& text, std::string* input, const std::vector<std::string>& extensions, |
| 88 | const std::string& basedir, int id = -1); |
| 89 | |
| 90 | ItemColor& (const std::string& text, Color* color, int id = -1); |
| 91 | ItemColorDisplay& (Color* color, int id = -1); |
| 92 | ItemColorChannel& (float* input, Color channel, int id = -1, |
| 93 | bool is_linear = false); |
| 94 | |
| 95 | void (const Controller& controller); |
| 96 | |
| 97 | /** Remove all entries from the menu */ |
| 98 | void (); |
| 99 | |
| 100 | MenuItem& (int index) { return *(m_items[index]); } |
| 101 | |
| 102 | MenuItem& (int id); |
| 103 | const MenuItem& (int id) const; |
| 104 | |
| 105 | int () const; |
| 106 | void (int id); |
| 107 | |
| 108 | void (DrawingContext& context); |
| 109 | Vector () const { return m_pos; } |
| 110 | void (float x, float y); |
| 111 | |
| 112 | void (const SDL_Event& event); |
| 113 | |
| 114 | float () const; |
| 115 | float () const; |
| 116 | |
| 117 | protected: |
| 118 | /** returns true when the text is more important than action */ |
| 119 | virtual bool () const; |
| 120 | |
| 121 | MenuItem& (std::unique_ptr<MenuItem> ); |
| 122 | MenuItem& (std::unique_ptr<MenuItem> , int pos_); |
| 123 | void (int pos_); |
| 124 | |
| 125 | private: |
| 126 | void (const MenuAction& ); |
| 127 | void (const SDL_Event& event); |
| 128 | void (DrawingContext& context, int index); |
| 129 | /** Recalculates the width for this menu */ |
| 130 | void (); |
| 131 | |
| 132 | private: |
| 133 | /** position of the menu (ie. center of the menu, not top/left) */ |
| 134 | Vector ; |
| 135 | |
| 136 | /* input implementation variables */ |
| 137 | int ; |
| 138 | char ; |
| 139 | float ; |
| 140 | float ; |
| 141 | |
| 142 | public: |
| 143 | std::vector<std::unique_ptr<MenuItem> > ; |
| 144 | |
| 145 | private: |
| 146 | int ; |
| 147 | |
| 148 | protected: |
| 149 | int ; |
| 150 | |
| 151 | private: |
| 152 | (const Menu&) = delete; |
| 153 | Menu& (const Menu&) = delete; |
| 154 | }; |
| 155 | |
| 156 | #endif |
| 157 | |
| 158 | /* EOF */ |
| 159 | |