menu_item.hpp 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. #ifndef HEADER_SUPERTUX_GUI_MENU_ITEM_HPP
  18. #define HEADER_SUPERTUX_GUI_MENU_ITEM_HPP
  19. #include "gui/menu.hpp"
  20. class MenuItem
  21. {
  22. public:
  23. MenuItem(const std::string& text, int id = -1);
  24. virtual ~MenuItem();
  25. int get_id() const { return m_id; }
  26. void set_help(const std::string& help_text);
  27. const std::string& get_help() const { return m_help; }
  28. void set_text(const std::string& text) { m_text = text; }
  29. const std::string& get_text() const { return m_text; }
  30. void set_font(const FontPtr font) { m_font = font; }
  31. const FontPtr& get_font() const { return m_font; }
  32. /** Draws the menu item. */
  33. virtual void draw(DrawingContext&, const Vector& pos, int menu_width, bool active);
  34. virtual void on_window_resize() {}
  35. /** Returns true when the menu item has no action and therefore can be skipped.
  36. Useful for labels and horizontal lines.*/
  37. virtual bool skippable() const {
  38. return false;
  39. }
  40. /** Returns the distance between the items above and below the current
  41. menu item. */
  42. virtual float get_distance() const { return 0.f; }
  43. /** Returns the minimum width of the menu item. */
  44. virtual int get_width() const;
  45. /** Returns height of menu item. */
  46. virtual int get_height() const { return 24; }
  47. /** Processes the menu action. */
  48. virtual void process_action(const MenuAction& action) { }
  49. /** Processes the given event. */
  50. virtual void event(const SDL_Event& ev) { }
  51. virtual Color get_color() const;
  52. /** Returns true when the MenuManager shouldn't do anything else. */
  53. virtual bool no_other_action() const {
  54. return false;
  55. }
  56. /** Returns true when the width must be recalculated when an action is
  57. processed */
  58. virtual bool changes_width() const {
  59. return false;
  60. }
  61. /** Returns true when the item should have a blink effect, provided by the menu,
  62. when active. */
  63. virtual bool select_blink() const { return true; }
  64. private:
  65. int m_id;
  66. std::string m_text;
  67. std::string m_help;
  68. FontPtr m_font;
  69. private:
  70. MenuItem(const MenuItem&) = delete;
  71. MenuItem& operator=(const MenuItem&) = delete;
  72. };
  73. #endif
  74. /* EOF */