Changeset View
Changeset View
Standalone View
Standalone View
source/gui/ObjectBases/IGUIObject.h
Show All 19 Lines | |||||
* All objects are derived from this class. | * All objects are derived from this class. | ||||
* It's an abstract data type, so it can't be used per se. | * It's an abstract data type, so it can't be used per se. | ||||
* Also contains a Dummy object which is used for completely blank objects. | * Also contains a Dummy object which is used for completely blank objects. | ||||
*/ | */ | ||||
#ifndef INCLUDED_IGUIOBJECT | #ifndef INCLUDED_IGUIOBJECT | ||||
#define INCLUDED_IGUIOBJECT | #define INCLUDED_IGUIOBJECT | ||||
#include "gui/CGUISetting.h" | |||||
#include "gui/SettingTypes/CGUISize.h" | #include "gui/SettingTypes/CGUISize.h" | ||||
#include "gui/SGUIMessage.h" | #include "gui/SGUIMessage.h" | ||||
#include "lib/input.h" // just for IN_PASS | #include "lib/input.h" // just for IN_PASS | ||||
#include "ps/XML/Xeromyces.h" | #include "ps/XML/Xeromyces.h" | ||||
#include "scriptinterface/ScriptTypes.h" | #include "scriptinterface/ScriptTypes.h" | ||||
#include <map> | #include <map> | ||||
#include <vector> | #include <vector> | ||||
Show All 14 Lines | |||||
/** | /** | ||||
* GUI object such as a button or an input-box. | * GUI object such as a button or an input-box. | ||||
* Abstract data type ! | * Abstract data type ! | ||||
*/ | */ | ||||
class IGUIObject | class IGUIObject | ||||
{ | { | ||||
friend class CGUI; | friend class CGUI; | ||||
// For triggering message update handlers. | |||||
friend class IGUISetting; | |||||
// Allow getProperty to access things like GetParent() | // Allow getProperty to access things like GetParent() | ||||
template <typename T> | template <typename T> | ||||
friend class JSI_GUIProxy; | friend class JSI_GUIProxy; | ||||
public: | public: | ||||
NONCOPYABLE(IGUIObject); | NONCOPYABLE(IGUIObject); | ||||
IGUIObject(CGUI& pGUI); | IGUIObject(CGUI& pGUI); | ||||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Lines | public: | ||||
//@} | //@} | ||||
//-------------------------------------------------------- | //-------------------------------------------------------- | ||||
/** @name Settings Management */ | /** @name Settings Management */ | ||||
//-------------------------------------------------------- | //-------------------------------------------------------- | ||||
//@{ | //@{ | ||||
/** | /** | ||||
* Registers the given setting variables with the GUI object. | * Registers the given setting with the GUI object. | ||||
* Enable XML and JS to modify the given variable. | * Enable XML and JS to modify the given variable. | ||||
* | |||||
* @param Type Setting type | |||||
* @param Name Setting reference name | |||||
*/ | */ | ||||
template<typename T> | void RegisterSetting(const CStr& Name, IGUISetting* setting); | ||||
void RegisterSetting(const CStr& Name, T& Value); | void ReregisterSetting(const CStr& Name, IGUISetting* setting); | ||||
/** | /** | ||||
* Returns whether there is a setting with the given name registered. | * Returns whether there is a setting with the given name registered. | ||||
* | * | ||||
* @param Setting setting name | * @param Setting setting name | ||||
* @return True if settings exist. | * @return True if settings exist. | ||||
*/ | */ | ||||
bool SettingExists(const CStr& Setting) const; | bool SettingExists(const CStr& Setting) const; | ||||
/** | /** | ||||
* Get a mutable reference to the setting. | |||||
* If no such setting exists, an exception of type std::out_of_range is thrown. | |||||
* If the value is modified, there is no GUIM_SETTINGS_UPDATED message sent. | |||||
*/ | |||||
template <typename T> | |||||
T& GetSetting(const CStr& Setting); | |||||
template <typename T> | |||||
const T& GetSetting(const CStr& Setting) const; | |||||
/** | |||||
* Set a setting by string, regardless of what type it is. | * Set a setting by string, regardless of what type it is. | ||||
* Used to parse setting values from XML files. | * Used to parse setting values from XML files. | ||||
* For example a CRect(10,10,20,20) is created from "10 10 20 20". | * For example a CRect(10,10,20,20) is created from "10 10 20 20". | ||||
* Returns false if the conversion fails, otherwise true. | * @return false if the setting does not exist or the conversion fails, otherwise true. | ||||
*/ | */ | ||||
bool SetSettingFromString(const CStr& Setting, const CStrW& Value, const bool SendMessage); | bool SetSettingFromString(const CStr& Setting, const CStrW& Value, const bool SendMessage); | ||||
/** | /** | ||||
* Assigns the given value to the setting identified by the given name. | |||||
* Uses move semantics, so do not read from Value after this call. | |||||
* | |||||
* @param SendMessage If true, a GUIM_SETTINGS_UPDATED message will be broadcasted to all GUI objects. | |||||
*/ | |||||
template <typename T> | |||||
void SetSetting(const CStr& Setting, T& Value, const bool SendMessage); | |||||
/** | |||||
* This variant will copy the value. | |||||
*/ | |||||
template <typename T> | |||||
void SetSetting(const CStr& Setting, const T& Value, const bool SendMessage); | |||||
/** | |||||
* Returns whether this object is set to be hidden or ghost. | * Returns whether this object is set to be hidden or ghost. | ||||
*/ | */ | ||||
bool IsEnabled() const; | bool IsEnabled() const; | ||||
/** | /** | ||||
* Returns whether this is object is set to be hidden. | * Returns whether this is object is set to be hidden. | ||||
*/ | */ | ||||
bool IsHidden() const; | bool IsHidden() const; | ||||
void SetHidden(bool hidden) { m_Hidden.Set(hidden, true); } | |||||
/** | /** | ||||
* Returns whether this object is set to be hidden or ghost. | * Returns whether this object is set to be hidden or ghost. | ||||
*/ | */ | ||||
bool IsHiddenOrGhost() const; | bool IsHiddenOrGhost() const; | ||||
const CStrW& GetTooltip() const { return m_Tooltip; } | |||||
const CStr& GetTooltipStyle() const { return m_TooltipStyle; } | |||||
/** | /** | ||||
* Retrieves the configured sound filename from the given setting name and plays that once. | * Retrieves the configured sound filename from the given setting name and plays that once. | ||||
*/ | */ | ||||
void PlaySound(const CStrW& soundPath) const; | void PlaySound(const CStrW& soundPath) const; | ||||
/** | /** | ||||
* Send event to this GUI object (HandleMessage and ScriptEvent) | * Send event to this GUI object (HandleMessage and ScriptEvent) | ||||
* | * | ||||
▲ Show 20 Lines • Show All 338 Lines • ▼ Show 20 Lines | protected: | ||||
CGUI& m_pGUI; | CGUI& m_pGUI; | ||||
// Internal storage for registered script handlers. | // Internal storage for registered script handlers. | ||||
std::map<CStr, JS::Heap<JSObject*> > m_ScriptHandlers; | std::map<CStr, JS::Heap<JSObject*> > m_ScriptHandlers; | ||||
// Cached JSObject representing this GUI object. | // Cached JSObject representing this GUI object. | ||||
std::unique_ptr<IGUIProxyObject> m_JSObject; | std::unique_ptr<IGUIProxyObject> m_JSObject; | ||||
// Cache references to settings for performance | CGUISimpleSetting<bool> m_Enabled; | ||||
bool m_Enabled; | CGUISimpleSetting<bool> m_Hidden; | ||||
bool m_Hidden; | CGUISimpleSetting<CGUISize> m_Size; | ||||
CGUISize m_Size; | CGUISimpleSetting<CStr> m_Style; | ||||
CStr m_Style; | CGUISimpleSetting<CStr> m_Hotkey; | ||||
CStr m_Hotkey; | CGUISimpleSetting<float> m_Z; | ||||
float m_Z; | CGUISimpleSetting<bool> m_Absolute; | ||||
bool m_Absolute; | CGUISimpleSetting<bool> m_Ghost; | ||||
bool m_Ghost; | CGUISimpleSetting<float> m_AspectRatio; | ||||
float m_AspectRatio; | CGUISimpleSetting<CStrW> m_Tooltip; | ||||
CStrW m_Tooltip; | CGUISimpleSetting<CStr> m_TooltipStyle; | ||||
CStr m_TooltipStyle; | |||||
}; | }; | ||||
#endif // INCLUDED_IGUIOBJECT | #endif // INCLUDED_IGUIOBJECT |
Wildfire Games · Phabricator