00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef HEADER_SUPERTUX_GUI_MENU_HPP
00018 #define HEADER_SUPERTUX_GUI_MENU_HPP
00019
00020 #include <list>
00021 #include <memory>
00022 #include <SDL.h>
00023
00024 #include "math/vector.hpp"
00025 #include "video/color.hpp"
00026 #include "video/surface_ptr.hpp"
00027
00028 class DrawingContext;
00029 class MenuItem;
00030
00031 bool confirm_dialog(Surface* background, std::string text);
00032
00033 class Menu
00034 {
00035 static Color default_color;
00036 static Color active_color;
00037 static Color inactive_color;
00038 static Color label_color;
00039 static Color field_color;
00040 private:
00041
00042 enum MenuAction {
00043 MENU_ACTION_NONE = -1,
00044 MENU_ACTION_UP,
00045 MENU_ACTION_DOWN,
00046 MENU_ACTION_LEFT,
00047 MENU_ACTION_RIGHT,
00048 MENU_ACTION_HIT,
00049 MENU_ACTION_INPUT,
00050 MENU_ACTION_REMOVE,
00051 MENU_ACTION_BACK
00052 };
00053
00054 public:
00055 Menu();
00056 virtual ~Menu();
00057
00058 MenuItem* add_hl();
00059 MenuItem* add_label(const std::string& text);
00060 MenuItem* add_entry(int id, const std::string& text);
00061 MenuItem* add_toggle(int id, const std::string& text, bool toggled = false);
00062 MenuItem* add_inactive(int id, const std::string& text);
00063 MenuItem* add_back(const std::string& text);
00064 MenuItem* add_submenu(const std::string& text, Menu* submenu, int id = -1);
00065 MenuItem* add_controlfield(int id, const std::string& text,
00066 const std::string& mapping = "");
00067 MenuItem* add_string_select(int id, const std::string& text);
00068
00069 virtual void menu_action(MenuItem* item);
00070
00071 void update();
00072
00074 void clear();
00075
00078 int check ();
00079
00080 virtual void check_menu() =0;
00081
00082 MenuItem& get_item(int index)
00083 {
00084 return *(items[index]);
00085 }
00086
00087 MenuItem& get_item_by_id(int id);
00088 const MenuItem& get_item_by_id(int id) const;
00089
00090 int get_active_item_id();
00091 void set_active_item(int id);
00092
00093 void draw(DrawingContext& context);
00094 void set_pos(float x, float y, float rw = 0, float rh = 0);
00095
00096 void event(const SDL_Event& event);
00097
00098 bool is_toggled(int id) const;
00099 void set_toggled(int id, bool toggled);
00100
00101 Menu* get_parent() const;
00102
00103 protected:
00104 void additem(MenuItem* pmenu_item);
00105 float get_width() const;
00106 float get_height() const;
00107
00108 private:
00109 void check_controlfield_change_event(const SDL_Event& event);
00110 void draw_item(DrawingContext& context, int index);
00111
00112 private:
00115 int hit_item;
00116
00117
00118 Vector pos;
00119
00121 MenuAction menuaction;
00122
00123
00124 int delete_character;
00125 char mn_input_char;
00126 float menu_repeat_time;
00127
00128 public:
00129 bool close;
00130
00131 std::vector<MenuItem*> items;
00132
00133 public:
00134 float effect_progress;
00135 float effect_start_time;
00136
00137 private:
00138 int arrange_left;
00139 int active_item;
00140
00141 SurfacePtr checkbox;
00142 SurfacePtr checkbox_checked;
00143 SurfacePtr back;
00144 SurfacePtr arrow_left;
00145 SurfacePtr arrow_right;
00146 };
00147
00148 #endif
00149
00150