-
Notifications
You must be signed in to change notification settings - Fork 1
/
Menu.h
69 lines (55 loc) · 1.57 KB
/
Menu.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#ifndef _MENU_H_
#define _MENU_H_
#include <stack>
#include <map>
#include <string>
#include <SDL2/SDL.h>
#include "MenuScreen.h"
namespace typing
{
typedef MenuScreenPtr (*MenuCreator)();
template<typename menuType>
MenuScreenPtr CreateMenu()
{
return MenuScreenPtr(new menuType);
}
class Menu
{
public:
// Singleton implementation
static Menu& GetMenu();
// Methods
bool Init();
void Update();
void Draw();
void OnKeyDown(SDL_Keycode keycode);
void OnType(char c);
void Activate(const std::string& menuName);
bool IsActive()
{
return m_active;
}
private:
// Typedefs
typedef std::stack<MenuScreenPtr> MenuStack;
typedef std::map<std::string, MenuCreator> MenuFactory;
typedef std::map<std::string, MenuCreator>::iterator MenuFactoryIter;
// Ctors/Dtors
Menu()
{
}
// Methods
template<typename menuType> void RegisterMenu(const std::string& menuName);
void NextMenu(const std::string& menuName);
void ClearMenuStack();
void HandleAction(MenuScreen::NextAction act);
// Singleton implementation
static std::auto_ptr<Menu> m_singleton;
// Members
MenuStack m_menuStack;
MenuFactory m_menuFactory;
bool m_active;
};
#define MENU Menu::GetMenu()
}
#endif // _MENU_H_