|
@@ -0,0 +1,63 @@
|
|
|
+#ifndef MENU_H_INCLUDED
|
|
|
+#define MENU_H_INCLUDED
|
|
|
+
|
|
|
+#include <map>
|
|
|
+#include <string>
|
|
|
+
|
|
|
+typedef int (*menuFuncPtr)();
|
|
|
+
|
|
|
+struct MenuItem
|
|
|
+{
|
|
|
+ std::string title;
|
|
|
+ menuFuncPtr item;
|
|
|
+
|
|
|
+ MenuItem(const std::string _title, const menuFuncPtr _item) : title(_title), item(_item) {};
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+typedef std::map<char, MenuItem> menuMap;
|
|
|
+typedef menuMap::iterator menuMapIt;
|
|
|
+typedef menuMap::const_iterator menuMapCIt;
|
|
|
+typedef menuMap::value_type menuMapValue;
|
|
|
+typedef menuMap::key_type menuMapKey;
|
|
|
+typedef menuMap::mapped_type menuMapItem;
|
|
|
+
|
|
|
+class CMenu
|
|
|
+{
|
|
|
+ protected:
|
|
|
+ std::string m_Title;
|
|
|
+ std::string m_Prefix;
|
|
|
+ std::string m_Divider;
|
|
|
+
|
|
|
+ menuMap m_MenuMap;
|
|
|
+
|
|
|
+ static const char STR_DEFAULT_TITLE[];
|
|
|
+ static const char STR_DEFAULT_PREFIX[];
|
|
|
+ static const char STR_DEFAULT_DIVIDER[];
|
|
|
+
|
|
|
+ public:
|
|
|
+ CMenu() : m_Title(STR_DEFAULT_TITLE),
|
|
|
+ m_Prefix(STR_DEFAULT_PREFIX),
|
|
|
+ m_Divider(STR_DEFAULT_DIVIDER) {};
|
|
|
+ CMenu(const std::string _title) : m_Title(_title),
|
|
|
+ m_Prefix(STR_DEFAULT_PREFIX),
|
|
|
+ m_Divider(STR_DEFAULT_DIVIDER) {};
|
|
|
+
|
|
|
+ virtual ~CMenu() {};
|
|
|
+
|
|
|
+ virtual bool addItem(const menuMapValue &_item);
|
|
|
+ virtual bool addItem(const menuMapKey _key, const menuMapItem &_item);
|
|
|
+ virtual bool addItem(const menuMapKey _key, const std::string _title, const menuFuncPtr _item);
|
|
|
+
|
|
|
+ virtual void draw() const;
|
|
|
+ virtual int selectItem() const;
|
|
|
+
|
|
|
+ virtual void setTitle(const std::string _title) {m_Title = _title;}
|
|
|
+ virtual void setPrefix(const std::string _prefix) {m_Prefix = _prefix;}
|
|
|
+ virtual void setDivider(const std::string _divider) {m_Divider = _divider;}
|
|
|
+
|
|
|
+ private:
|
|
|
+ CMenu(const CMenu& _copy) {};
|
|
|
+ CMenu& operator=(const CMenu& _copy) {return *this;};
|
|
|
+};
|
|
|
+#endif // MENU_H_INCLUDED
|