95 lines
2 KiB
C++
95 lines
2 KiB
C++
#pragma once
|
|
|
|
#ifndef _SAMPLEMENU_H_
|
|
#define _SAMPLEMENU_H_
|
|
|
|
#define CIN_MENU (GEAR_CFG_PLATFORM == GEAR_PLATFORM_WIN32 || GEAR_CFG_PLATFORM == GEAR_PLATFORM_WIN64)
|
|
|
|
#if CIN_MENU == 1
|
|
|
|
#include <iostream>
|
|
using namespace std;
|
|
static void cinCallBack(void* menu);
|
|
|
|
#endif
|
|
|
|
#include "gear.h"
|
|
|
|
// This class make the ultimate assumption that everything you pass is good. Don't mess with it.
|
|
class Menu
|
|
{
|
|
public:
|
|
|
|
typedef void(*doSomething)(void*);
|
|
|
|
// Construction/Destruction
|
|
Menu();
|
|
Menu(Menu* parent, Gear::S32 no, Gear::GearString name, doSomething cb = 0, Gear::Bool ReturnToParent = Gear::False);
|
|
~Menu();
|
|
|
|
// Method
|
|
void AddMenu(Menu* menu);
|
|
void Execute(void* param);
|
|
void Return();
|
|
|
|
// Getter
|
|
inline Gear::S32 GetNo()
|
|
{
|
|
return m_no;
|
|
}
|
|
|
|
inline Menu* GetParent()
|
|
{
|
|
return m_parent;
|
|
}
|
|
|
|
inline const Gear::GearString& GetName()
|
|
{
|
|
return m_name;
|
|
}
|
|
|
|
inline Menu* GetChildByIndex(Gear::S32 index)
|
|
{
|
|
if ((size_t)index >= 0 && (size_t)index < m_menu.Size())
|
|
return m_menu[index];
|
|
return this;
|
|
}
|
|
|
|
inline Gear::Bool IsLeaf()
|
|
{
|
|
return m_menu.Size() == 0;
|
|
}
|
|
|
|
inline static Menu* GetCurrentMenu()
|
|
{
|
|
return m_currentMenu;
|
|
}
|
|
|
|
// Setter
|
|
inline static void SetCurrentMenu(Menu* menu)
|
|
{
|
|
// Will reset the m_Shown to False, so that the menu can be seen again
|
|
if (m_currentMenu)
|
|
m_currentMenu->m_Shown = Gear::False;
|
|
if (menu)
|
|
m_currentMenu = menu;
|
|
}
|
|
|
|
private:
|
|
|
|
// Members
|
|
|
|
Gear::GearVector<Menu*> m_menu;
|
|
|
|
Menu* m_parent;
|
|
Gear::S32 m_no;
|
|
Gear::GearString m_name;
|
|
doSomething m_cb;
|
|
Gear::Bool m_ReturnToParent; // When finishing execution, return to param automatically
|
|
|
|
Gear::Bool m_Shown; // True if the menu (not a menu leaf) has already been shown once (that is useful when using gamepad to poll for input)
|
|
|
|
static Menu* m_currentMenu;
|
|
};
|
|
|
|
#endif // #define _SAMPLEMENU_H_
|