Changeset View
Changeset View
Standalone View
Standalone View
source/gui/IGUIObject.h
/* Copyright (C) 2017 Wildfire Games. | /* Copyright (C) 2018 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | |||||
* A GUI Setting is anything that can be inputted from XML as | * A GUI Setting is anything that can be inputted from XML as | ||||
* \<object\>-attributes (with exceptions). For instance: | * \<object\>-attributes (with exceptions). For instance: | ||||
* \<object style="null"\> | * \<object style="null"\> | ||||
* | * | ||||
* "style" will be a SGUISetting. | * "style" will be a SGUISetting. | ||||
*/ | */ | ||||
struct SGUISetting | struct SGUISetting | ||||
{ | { | ||||
SGUISetting() : m_pSetting(NULL) {} | SGUISetting() : m_pSetting(nullptr) {} | ||||
void *m_pSetting; | void *m_pSetting; | ||||
EGUISettingType m_Type; | EGUISettingType m_Type; | ||||
}; | }; | ||||
/** | /** | ||||
* 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 ! | ||||
▲ Show 20 Lines • Show All 239 Lines • ▼ Show 20 Lines | protected: | ||||
void SetParent(IGUIObject* pParent) { m_pParent = pParent; } | void SetParent(IGUIObject* pParent) { m_pParent = pParent; } | ||||
/** | /** | ||||
* Reset internal state of this object | * Reset internal state of this object | ||||
*/ | */ | ||||
virtual void ResetStates() | virtual void ResetStates() | ||||
{ | { | ||||
// Notify the gui that we aren't hovered anymore | // Notify the gui that we aren't hovered anymore | ||||
UpdateMouseOver(NULL); | UpdateMouseOver(nullptr); | ||||
} | } | ||||
public: | public: | ||||
CGUI* GetGUI() { return m_pGUI; } | CGUI* GetGUI() { return m_pGUI; } | ||||
const CGUI* GetGUI() const { return m_pGUI; } | const CGUI* GetGUI() const { return m_pGUI; } | ||||
/** | /** | ||||
* Take focus! | * Take focus! | ||||
*/ | */ | ||||
void SetFocus(); | void SetFocus(); | ||||
protected: | protected: | ||||
/** | /** | ||||
* Check if object is focused. | * Check if object is focused. | ||||
*/ | */ | ||||
bool IsFocused() const; | bool IsFocused() const; | ||||
/** | /** | ||||
* <b>NOTE!</b> This will not just return m_pParent, when that is | * <b>NOTE!</b> This will not just return m_pParent, when that is | ||||
* need use it! There is one exception to it, when the parent is | * need use it! There is one exception to it, when the parent is | ||||
* the top-node (the object that isn't a real object), this | * the top-node (the object that isn't a real object), this | ||||
* will return NULL, so that the top-node's children are | * will return nullptr, so that the top-node's children are | ||||
* seemingly parentless. | * seemingly parentless. | ||||
* | * | ||||
* @return Pointer to parent | * @return Pointer to parent | ||||
*/ | */ | ||||
IGUIObject* GetParent() const; | IGUIObject* GetParent() const; | ||||
/** | /** | ||||
* Get Mouse from CGUI. | * Get Mouse from CGUI. | ||||
▲ Show 20 Lines • Show All 50 Lines • ▼ Show 20 Lines | protected: | ||||
void SetScriptHandler(const CStr& Action, JS::HandleObject Function); | void SetScriptHandler(const CStr& Action, JS::HandleObject Function); | ||||
/** | /** | ||||
* Inputes the object that is currently hovered, this function | * Inputes the object that is currently hovered, this function | ||||
* updates this object accordingly (i.e. if it's the object | * updates this object accordingly (i.e. if it's the object | ||||
* being inputted one thing happens, and not, another). | * being inputted one thing happens, and not, another). | ||||
* | * | ||||
* @param pMouseOver Object that is currently hovered, | * @param pMouseOver Object that is currently hovered, | ||||
* can OF COURSE be NULL too! | * can OF COURSE be nullptr too! | ||||
*/ | */ | ||||
void UpdateMouseOver(IGUIObject* const& pMouseOver); | void UpdateMouseOver(IGUIObject* const& pMouseOver); | ||||
//@} | //@} | ||||
private: | private: | ||||
//-------------------------------------------------------- | //-------------------------------------------------------- | ||||
/** @name Internal functions */ | /** @name Internal functions */ | ||||
//-------------------------------------------------------- | //-------------------------------------------------------- | ||||
//@{ | //@{ | ||||
/** | /** | ||||
* Inputs a reference pointer, checks if the new inputted object | * Inputs a reference pointer, checks if the new inputted object | ||||
* if hovered, if so, then check if this's Z value is greater | * if hovered, if so, then check if this's Z value is greater | ||||
* than the inputted object... If so then the object is closer | * than the inputted object... If so then the object is closer | ||||
* and we'll replace the pointer with this. | * and we'll replace the pointer with this. | ||||
* Also Notice input can be NULL, which means the Z value demand | * Also Notice input can be nullptr, which means the Z value demand | ||||
* is out. NOTICE you can't input NULL as const so you'll have | * is out. NOTICE you can't input nullptr as const so you'll have | ||||
* to set an object to NULL. | * to set an object to nullptr. | ||||
* | * | ||||
* @param pObject Object pointer, can be either the old one, or | * @param pObject Object pointer, can be either the old one, or | ||||
* the new one. | * the new one. | ||||
*/ | */ | ||||
void ChooseMouseOverAndClosest(IGUIObject*& pObject); | void ChooseMouseOverAndClosest(IGUIObject*& pObject); | ||||
// Is the object a Root object, in philosophy, this means it | // Is the object a Root object, in philosophy, this means it | ||||
// has got no parent, and technically, it's got the m_BaseObject | // has got no parent, and technically, it's got the m_BaseObject | ||||
▲ Show 20 Lines • Show All 89 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator