Changeset View
Changeset View
Standalone View
Standalone View
source/gui/CGUI.h
Show All 29 Lines | |||||
#include "gui/SGUIStyle.h" | #include "gui/SGUIStyle.h" | ||||
#include "lib/input.h" | #include "lib/input.h" | ||||
#include "ps/Shapes.h" | #include "ps/Shapes.h" | ||||
#include "ps/XML/Xeromyces.h" | #include "ps/XML/Xeromyces.h" | ||||
#include "scriptinterface/ScriptInterface.h" | #include "scriptinterface/ScriptInterface.h" | ||||
#include <map> | #include <map> | ||||
#include <set> | #include <set> | ||||
#include <unordered_map> | |||||
#include <unordered_set> | #include <unordered_set> | ||||
#include <vector> | #include <vector> | ||||
extern const double SELECT_DBLCLICK_RATE; | extern const double SELECT_DBLCLICK_RATE; | ||||
class CGUISpriteInstance; | class CGUISpriteInstance; | ||||
class CGUISprite; | class CGUISprite; | ||||
class IGUIObject; | class IGUIObject; | ||||
struct SGUIImageEffects; | struct SGUIImageEffects; | ||||
struct SGUIScrollBarStyle; | struct SGUIScrollBarStyle; | ||||
namespace js { class BaseProxyHandler; } | |||||
/** | /** | ||||
* 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); | ||||
private: | private: | ||||
▲ Show 20 Lines • Show All 175 Lines • ▼ Show 20 Lines | public: | ||||
*/ | */ | ||||
bool HasPreDefinedColor(const CStr& name) const { return (m_PreDefinedColors.find(name) != m_PreDefinedColors.end()); } | bool HasPreDefinedColor(const CStr& name) const { return (m_PreDefinedColors.find(name) != m_PreDefinedColors.end()); } | ||||
/** | /** | ||||
* Resolve the predefined color if it exists, otherwise throws an exception. | * Resolve the predefined color if it exists, otherwise throws an exception. | ||||
*/ | */ | ||||
const CGUIColor& GetPreDefinedColor(const CStr& name) const { return m_PreDefinedColors.at(name); } | const CGUIColor& GetPreDefinedColor(const CStr& name) const { return m_PreDefinedColors.at(name); } | ||||
const void* GetProxyData(const js::BaseProxyHandler* ptr) const { return m_ProxyData.at(ptr); } | |||||
shared_ptr<ScriptInterface> GetScriptInterface() { return m_ScriptInterface; }; | shared_ptr<ScriptInterface> GetScriptInterface() { return m_ScriptInterface; }; | ||||
private: | private: | ||||
/** | /** | ||||
* The CGUI takes ownership of the child object and links the parent with the child. | * The CGUI takes ownership of the child object and links the parent with the child. | ||||
* Returns false on failure to take over ownership of the child object. | * Returns false on failure to take over ownership of the child object. | ||||
*/ | */ | ||||
bool AddObject(IGUIObject& parent, IGUIObject& child); | bool AddObject(IGUIObject& parent, IGUIObject& child); | ||||
▲ Show 20 Lines • Show All 346 Lines • ▼ Show 20 Lines | private: | ||||
/** | /** | ||||
* 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; | std::map<CStr, ConstructObjectFunction> m_ObjectTypes; | ||||
/** | /** | ||||
* This is intended to store the JS Functions returned when accessing some object properties. | |||||
* It's not a great solution, but I can't find a better one at the moment. | |||||
* The problem is that these functions are per-scriptInterface, and proxy handlers aren't. | |||||
* So we know what we want to store, but we don't really have anywhere to store it. | |||||
* It would be simpler to recreate the functions on every JS call, but that is slower | |||||
* (this may or may not matter now and in the future). | |||||
* Another alternative would be to store them on each proxied object, but that wastes memory. | |||||
*/ | |||||
std::unordered_map<const js::BaseProxyHandler*, void*> m_ProxyData; | |||||
/** | |||||
* 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; | ||||
/** | /** | ||||
* Map from hotkey names to maps of eventNames to functions that are triggered | * Map from hotkey names to maps of eventNames to functions that are triggered | ||||
▲ Show 20 Lines • Show All 53 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator