Changeset View
Changeset View
Standalone View
Standalone View
source/gui/CGUI.h
Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | |||||
/** | /** | ||||
* The main object that represents a whole GUI page. | * The main object that represents a whole GUI page. | ||||
*/ | */ | ||||
class CGUI | class CGUI | ||||
{ | { | ||||
NONCOPYABLE(CGUI); | NONCOPYABLE(CGUI); | ||||
friend class JSI_GUI::GUIProxy; | |||||
friend class IGUIObject; | |||||
private: | private: | ||||
// Private typedefs | // Private typedefs | ||||
using ConstructObjectFunction = IGUIObject* (*)(CGUI&); | using ConstructObjectFunction = IGUIObject* (*)(CGUI&); | ||||
public: | public: | ||||
CGUI(const shared_ptr<ScriptRuntime>& runtime); | CGUI(const shared_ptr<ScriptRuntime>& runtime); | ||||
~CGUI(); | ~CGUI(); | ||||
▲ Show 20 Lines • Show All 125 Lines • ▼ Show 20 Lines | public: | ||||
* AddObjectType("button", &CButton::ConstructObject); | * AddObjectType("button", &CButton::ConstructObject); | ||||
* @endcode | * @endcode | ||||
* | * | ||||
* @param str Reference name of object type | * @param str Reference name of object type | ||||
* @param pFunc Pointer of function ConstuctObject() in the object | * @param pFunc Pointer of function ConstuctObject() in the object | ||||
* | * | ||||
* @see CGUI#ConstructObject() | * @see CGUI#ConstructObject() | ||||
*/ | */ | ||||
void AddObjectType(const CStr& str, ConstructObjectFunction pFunc) { m_ObjectTypes[str] = pFunc; } | void AddObjectType(const CStr& str, ConstructObjectFunction pFunc, std::unique_ptr<JSI_GUI::GUIObjectFactory>&& JSFactory); | ||||
/** | /** | ||||
* Update Resolution, should be called every time the resolution | * Update Resolution, should be called every time the resolution | ||||
* of the OpenGL screen has been changed, this is because it needs | * of the OpenGL screen has been changed, this is because it needs | ||||
* to re-cache all its actual sizes | * to re-cache all its actual sizes | ||||
* | * | ||||
* Needs no input since screen resolution is global. | * Needs no input since screen resolution is global. | ||||
* | * | ||||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Lines | private: | ||||
* say you input "button", then it will construct a | * say you input "button", then it will construct a | ||||
* CGUIObjet* as a CButton. | * CGUIObjet* as a CButton. | ||||
* | * | ||||
* @param str Name of object type | * @param str Name of object type | ||||
* @return Newly constructed IGUIObject (but constructed as a subclass) | * @return Newly constructed IGUIObject (but constructed as a subclass) | ||||
*/ | */ | ||||
IGUIObject* ConstructObject(const CStr& str); | IGUIObject* ConstructObject(const CStr& str); | ||||
JSObject* ConstructJSObject(const CStr& str); | |||||
public: | public: | ||||
/** | /** | ||||
* Get Focused Object. | * Get Focused Object. | ||||
*/ | */ | ||||
IGUIObject* GetFocusedObject() { return m_FocusedObject; } | IGUIObject* GetFocusedObject() { return m_FocusedObject; } | ||||
/** | /** | ||||
* Change focus to new object. | * Change focus to new object. | ||||
▲ Show 20 Lines • Show All 324 Lines • ▼ Show 20 Lines | private: | ||||
*/ | */ | ||||
int m_InternalNameNumber; | int m_InternalNameNumber; | ||||
/** | /** | ||||
* Function pointers to functions that constructs | * Function pointers to functions that constructs | ||||
* IGUIObjects by name... For instance m_ObjectTypes["button"] | * IGUIObjects by name... For instance m_ObjectTypes["button"] | ||||
* is filled with a function that will "return new CButton();" | * is filled with a function that will "return new CButton();" | ||||
*/ | */ | ||||
std::map<CStr, ConstructObjectFunction> m_ObjectTypes; | struct ObjectFactory { | ||||
ConstructObjectFunction constructObject; | |||||
std::unique_ptr<JSI_GUI::GUIObjectFactory> guiObjectFactory; | |||||
}; | |||||
std::map<CStr, ObjectFactory> m_ObjectTypes; | |||||
/** | /** | ||||
* Map from hotkey names to objects that listen to the hotkey. | * Map from hotkey names to objects that listen to the hotkey. | ||||
* (This is an optimisation to avoid recursing over the whole GUI | * (This is an optimisation to avoid recursing over the whole GUI | ||||
* tree every time a hotkey is pressed). | * tree every time a hotkey is pressed). | ||||
*/ | */ | ||||
std::map<CStr, std::vector<IGUIObject*> > m_HotkeyObjects; | std::map<CStr, std::vector<IGUIObject*> > m_HotkeyObjects; | ||||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator