supertux
menu_item.hpp
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 #ifndef HEADER_SUPERTUX_GUI_MENU_ITEM_HPP
19 #define HEADER_SUPERTUX_GUI_MENU_ITEM_HPP
20 
21 #include "gui/menu.hpp"
22 
23 class MenuItem
24 {
25 public:
26  MenuItem(const std::string& text, int id = -1);
27  virtual ~MenuItem();
28 
29  int get_id() const { return m_id; }
30 
31  void set_help(const std::string& help_text);
32  const std::string& get_help() const { return m_help; }
33 
34  void set_text(const std::string& text) { m_text = text; }
35  const std::string& get_text() const { return m_text; }
36 
38  virtual void draw(DrawingContext&, const Vector& pos, int menu_width, bool active);
39 
42  virtual bool skippable() const {
43  return false;
44  }
45 
47  virtual int get_width() const;
48 
50  virtual void process_action(const MenuAction& action) { }
51 
53  virtual void event(const SDL_Event& ev) { }
54 
55  virtual Color get_color() const;
56 
58  virtual bool no_other_action() const {
59  return false;
60  }
61 
64  virtual bool changes_width() const {
65  return false;
66  }
67 
68 private:
69  int m_id;
70  std::string m_text;
71  std::string m_help;
72 
73 private:
74  MenuItem(const MenuItem&) = delete;
75  MenuItem& operator=(const MenuItem&) = delete;
76 };
77 
78 #endif
79 
80 /* EOF */
virtual void event(const SDL_Event &ev)
Processes the given event.
Definition: menu_item.hpp:53
Simple two dimensional vector.
Definition: vector.hpp:24
virtual int get_width() const
Returns the minimum width of the menu item.
Definition: menu_item.cpp:64
virtual void process_action(const MenuAction &action)
Processes the menu action.
Definition: menu_item.hpp:50
Definition: menu_item.hpp:23
virtual bool skippable() const
Returns true when the menu item has no action and therefore can be skipped.
Definition: menu_item.hpp:42
virtual void draw(DrawingContext &, const Vector &pos, int menu_width, bool active)
Draws the menu item.
Definition: menu_item.cpp:50
Definition: color.hpp:25
virtual bool no_other_action() const
Returns true when the MenuManager shouldn&#39;t do anything else.
Definition: menu_item.hpp:58
virtual bool changes_width() const
Returns true when the width must be recalculated when an action is processed.
Definition: menu_item.hpp:64
This class provides functions for drawing things on screen.
Definition: drawing_context.hpp:42