00001
00002
00003
00004
00005 #ifndef MENU_H
00006 #define MENU_H
00007
00008 #include "gui/Command.h"
00009 #include "gui/GUI.h"
00010
00011 #include <vector>
00012 #include <map>
00013
00014 namespace gui {
00015
00016 class SubMenu;
00017 class MenuBase;
00018
00019 class Menu {
00020
00021
00022
00023
00024
00025
00026
00027
00028 public:
00029 friend class SubMenu;
00030
00031 Menu(GUI&);
00032
00033
00034 ~Menu();
00035
00036 SubMenu& subMenu(const std::string& label);
00037
00038
00039 SubMenu& file_menu();
00040
00041
00042 void add_button(const std::string& label, Command* cmd);
00043
00044
00045 void register_key(char key, Command* cmd);
00046
00047
00048 bool strike(char c);
00049
00050
00051
00052 void query(const std::string& ask, int* value);
00053
00054
00055 void query(const std::string& ask, double* value, int count=1);
00056
00057
00058 void query(const std::string& ask, float* value);
00059
00060
00061 void query(const std::string& ask, std::string* value);
00062
00063
00064 void run(bool paused=true);
00065
00066
00067
00068 void check_messages();
00069
00070
00071 void add(MenuBase* client);
00072
00073
00074 static Menu* instance(Menu* m=0);
00075
00076 private:
00077
00078 class Node{
00079
00080 };
00081
00082
00083 void addCommand(const std::string& label, Command* command);
00084 GUI::Toggle* addToggle(const std::string& label, bool state, Command* set, Command* unset);
00085 Node* beginMenu(const std::string&, Node* subnode=0);
00086 void setMenu(Node* m);
00087 void endMenu();
00088 void addSeparator();
00089 void quit();
00090
00091 static Menu* s_instance;
00092
00093 GUI& m_gui;
00094
00095 SubMenu* m_fileMenu;
00096
00097
00098 typedef std::map<char, Command*, std::less<char> > KeyCommandMap;
00099 KeyCommandMap m_key_map;
00100
00101
00102 typedef std::vector<MenuBase* > ClientList;
00103 ClientList m_clients;
00104
00105
00106 std::vector<SubMenu*> m_sub_menus;
00107
00108
00109 std::vector<Command*> m_commands;
00110
00111 };
00112
00113 template< class T >
00114 class SimpleDialogBox : public Command {
00115
00116
00117 public:
00118 SimpleDialogBox(Menu* m, std::string& q, T* t)
00119 : m_menu(m),
00120 m_question(q),
00121 m_t(t){}
00122 void execute(){m_menu->query(m_question, m_t);}
00123 private:
00124 Menu* m_menu;
00125 std::string m_question;
00126 T* m_t;
00127 };
00128
00129 class MenuBase {
00130
00131 public:
00132 MenuBase(){}
00133 virtual void finishSetup(){};
00134 virtual void quit(){};
00135 };
00136
00137 template< class T >
00138 class MenuClient : public MenuBase {
00139
00140
00141
00142
00143
00144 public:
00145 MenuClient(T* t):m_t(t){}
00146
00147
00148 void finishSetup(){m_t->finishSetup();}
00149 void quit(){m_t->quit();}
00150
00151 friend class Menu;
00152 private:
00153 T* m_t;
00154 };
00155
00156 inline void Menu::add(MenuBase* client){ m_clients.push_back(client);}
00157
00158 }
00159 #endif
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169