2019-03-18 15:15:40 -07:00
|
|
|
/* Copyright (C) 2019 Wildfire Games.
|
2009-04-18 10:00:33 -07:00
|
|
|
* This file is part of 0 A.D.
|
|
|
|
|
*
|
|
|
|
|
* 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
|
|
|
|
|
* the Free Software Foundation, either version 2 of the License, or
|
|
|
|
|
* (at your option) any later version.
|
|
|
|
|
*
|
|
|
|
|
* 0 A.D. is distributed in the hope that it will be useful,
|
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
|
*
|
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
|
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
*/
|
|
|
|
|
|
2003-11-23 18:18:41 -08:00
|
|
|
/*
|
2017-08-28 03:27:36 -07:00
|
|
|
* The base class of an object.
|
|
|
|
|
* All objects are derived from this class.
|
|
|
|
|
* 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.
|
|
|
|
|
*/
|
2003-11-23 18:18:41 -08:00
|
|
|
|
2007-05-07 09:33:24 -07:00
|
|
|
#ifndef INCLUDED_IGUIOBJECT
|
|
|
|
|
#define INCLUDED_IGUIOBJECT
|
2003-11-23 18:18:41 -08:00
|
|
|
|
2019-10-02 02:44:00 -07:00
|
|
|
#include "gui/Scripting/JSInterface_IGUIObject.h"
|
|
|
|
|
#include "gui/SettingTypes/CGUISize.h"
|
2019-10-01 05:46:55 -07:00
|
|
|
#include "gui/SGUIMessage.h"
|
2015-08-21 10:08:41 -07:00
|
|
|
#include "lib/input.h" // just for IN_PASS
|
2005-08-14 16:50:37 -07:00
|
|
|
#include "ps/XML/Xeromyces.h"
|
2005-04-07 02:13:10 -07:00
|
|
|
|
2019-09-20 06:11:18 -07:00
|
|
|
#include <map>
|
2015-08-21 10:08:41 -07:00
|
|
|
#include <string>
|
|
|
|
|
#include <vector>
|
2004-07-08 08:23:47 -07:00
|
|
|
|
2019-10-01 05:46:55 -07:00
|
|
|
class CGUI;
|
|
|
|
|
class IGUIObject;
|
2019-08-03 19:20:08 -07:00
|
|
|
class IGUISetting;
|
2004-12-15 13:24:46 -08:00
|
|
|
|
2019-10-01 05:46:55 -07:00
|
|
|
using map_pObjects = std::map<CStr, IGUIObject*>;
|
|
|
|
|
|
|
|
|
|
#define GUI_OBJECT(obj) \
|
|
|
|
|
public: \
|
|
|
|
|
static IGUIObject* ConstructObject(CGUI& pGUI) \
|
|
|
|
|
{ return new obj(pGUI); }
|
|
|
|
|
|
2003-11-23 18:18:41 -08:00
|
|
|
/**
|
|
|
|
|
* GUI object such as a button or an input-box.
|
|
|
|
|
* Abstract data type !
|
|
|
|
|
*/
|
|
|
|
|
class IGUIObject
|
|
|
|
|
{
|
|
|
|
|
friend class CGUI;
|
|
|
|
|
|
2004-07-08 08:23:47 -07:00
|
|
|
// Allow getProperty to access things like GetParent()
|
2015-01-24 06:46:52 -08:00
|
|
|
friend bool JSI_IGUIObject::getProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp);
|
Upgrade SpiderMonkey to version 45.0.2, refs #4893.
- Various build changes, in particular NSPR is not needed on Unix
anymore
- Add js/Initialization.h to source/scriptinterface/ScriptEngine.h
- Use nullptr instead of JS::NullPtr(), see
https://bugzilla.mozilla.org/show_bug.cgi?id=1164602
- Remove `JS::RuntimeOptionsRef.varObjFix`, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1171177
- Remove uses of `AutoIdArray`, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1191529
- `JS_InternUCStringN` has been renamed, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1178581
- `JS::Evaluate` now takes scope chains explicitly, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1097987
- Array functions (such as `JS_IsArrayObject`) are fallible and output
to params, see https://bugzilla.mozilla.org/show_bug.cgi?id=f3d35d8
- Remove `JSCLASS_CACHED_PROTO_WIDTH` workaround in our code, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1236373
- Remove compile'n go (`setCompileAndGo`) and replace it by
`setIsRunOnce` which will become the default in the future, see
https://bugzilla.mozilla.org/show_bug.cgi?id=679939
- Mark shared memory in direct access operations
(`JS_GetUint16ArrayData` and `JS_GetUint8ArrayData`), see
https://bugzilla.mozilla.org/show_bug.cgi?id=1176214
- Use new `JS::ObjectOpResult`, see
https://bugzilla.mozilla.org/show_bug.cgi?id=1113369
Thanks to wraitii, elexis, Krinkle and historic_bruno for contributions
and comments, and to gentz, madpilot, s0600204 and Stan for testing and
indirect contributions.
Differential Revision: https://code.wildfiregames.com/D1510
This was SVN commit r22627.
2019-08-07 15:37:43 -07:00
|
|
|
friend bool JSI_IGUIObject::setProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp, JS::ObjectOpResult& result);
|
2019-10-28 04:35:04 -07:00
|
|
|
friend bool JSI_IGUIObject::deleteProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::ObjectOpResult& result);
|
2017-08-28 03:27:36 -07:00
|
|
|
friend bool JSI_IGUIObject::getComputedSize(JSContext* cx, uint argc, JS::Value* vp);
|
2004-07-08 08:23:47 -07:00
|
|
|
|
2003-11-23 18:18:41 -08:00
|
|
|
public:
|
Use NONCOPYABLE for most GUI classes and structs to have the compiler indicate unintended copies, refs 3028551b91 / D2163.
That is CChartData, CGUIList, CGUISeries, COListColumn, GUITooltip,
SGUIMessage, SSpriteCall, STextCall, SFeedback, IGUISetting,
CGUISetting, GUI, IGUIObject, IGUIScrollBar.
Drop copying GetSetting and SetSetting template functions for CGUIList,
CGUISeries, CClientArea, CGUIString.
Stop copying COListColumn.
Drop copying GUI<CClientArea>::GetSetting call in
IGUIObject::UpdateCachedSize() and four copying
GUI<CGUIString>::GetSetting calls in SetupText() functions.
Delete unused GUIRenderer IGLState class from 849f50a500 obsolete since
1f5b8f1c9a.
Differential Revision: https://code.wildfiregames.com/D2164
This was SVN commit r22638.
2019-08-09 17:04:17 -07:00
|
|
|
NONCOPYABLE(IGUIObject);
|
|
|
|
|
|
2019-08-21 03:12:33 -07:00
|
|
|
IGUIObject(CGUI& pGUI);
|
2003-11-23 18:18:41 -08:00
|
|
|
virtual ~IGUIObject();
|
2004-07-08 08:23:47 -07:00
|
|
|
|
2003-11-23 18:18:41 -08:00
|
|
|
/**
|
|
|
|
|
* This function checks if the mouse is hovering the
|
|
|
|
|
* rectangle that the base setting "size" makes.
|
|
|
|
|
* Although it is virtual, so one could derive
|
|
|
|
|
* an object from CButton, which changes only this
|
|
|
|
|
* to checking the circle that "size" makes.
|
|
|
|
|
*
|
2019-10-05 02:58:31 -07:00
|
|
|
* This function also returns true if there is a different
|
|
|
|
|
* GUI object shown on top of this one.
|
2003-11-23 18:18:41 -08:00
|
|
|
*/
|
2019-08-22 16:51:10 -07:00
|
|
|
virtual bool IsMouseOver() const;
|
2003-11-23 18:18:41 -08:00
|
|
|
|
2019-10-05 02:58:31 -07:00
|
|
|
/**
|
|
|
|
|
* This function returns true if the mouse is hovering
|
|
|
|
|
* over this GUI object and if this GUI object is the
|
|
|
|
|
* topmost object in that screen location.
|
|
|
|
|
* For example when hovering dropdown list items, the
|
|
|
|
|
* buttons beneath the list won't return true here.
|
|
|
|
|
*/
|
|
|
|
|
virtual bool IsMouseHovering() const { return m_MouseHovering; }
|
|
|
|
|
|
2010-10-29 21:02:42 -07:00
|
|
|
/**
|
|
|
|
|
* Test if mouse position is over an icon
|
|
|
|
|
*/
|
|
|
|
|
virtual bool MouseOverIcon();
|
|
|
|
|
|
2003-11-23 18:18:41 -08:00
|
|
|
//--------------------------------------------------------
|
|
|
|
|
/** @name Leaf Functions */
|
|
|
|
|
//--------------------------------------------------------
|
|
|
|
|
//@{
|
|
|
|
|
|
|
|
|
|
/// Get object name, name is unique
|
2006-07-20 07:37:58 -07:00
|
|
|
const CStr& GetName() const { return m_Name; }
|
2003-11-23 18:18:41 -08:00
|
|
|
|
|
|
|
|
/// Get object name
|
2004-06-18 07:07:06 -07:00
|
|
|
void SetName(const CStr& Name) { m_Name = Name; }
|
2003-11-23 18:18:41 -08:00
|
|
|
|
2004-08-30 19:09:58 -07:00
|
|
|
// Get Presentable name.
|
|
|
|
|
// Will change all internally set names to something like "<unnamed object>"
|
|
|
|
|
CStr GetPresentableName() const;
|
|
|
|
|
|
2003-11-23 18:18:41 -08:00
|
|
|
/**
|
2019-10-11 09:20:50 -07:00
|
|
|
* Builds the object hierarchy with references.
|
2003-11-23 18:18:41 -08:00
|
|
|
*/
|
2019-10-11 09:20:50 -07:00
|
|
|
void AddChild(IGUIObject& pChild);
|
2003-11-23 18:18:41 -08:00
|
|
|
|
2019-08-21 06:22:25 -07:00
|
|
|
/**
|
|
|
|
|
* Return all child objects of the current object.
|
2015-08-21 10:08:41 -07:00
|
|
|
*/
|
2019-08-22 16:51:10 -07:00
|
|
|
const std::vector<IGUIObject*>& GetChildren() const { return m_Children; }
|
2003-11-23 18:18:41 -08:00
|
|
|
|
|
|
|
|
//@}
|
|
|
|
|
//--------------------------------------------------------
|
|
|
|
|
/** @name Settings Management */
|
|
|
|
|
//--------------------------------------------------------
|
|
|
|
|
//@{
|
|
|
|
|
|
2019-09-30 07:08:14 -07:00
|
|
|
/**
|
|
|
|
|
* Registers the given setting variables with the GUI object.
|
|
|
|
|
* 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, T& Value);
|
|
|
|
|
|
2003-11-23 18:18:41 -08:00
|
|
|
/**
|
2019-08-03 19:20:08 -07:00
|
|
|
* Returns whether there is a setting with the given name registered.
|
2003-11-23 18:18:41 -08:00
|
|
|
*
|
|
|
|
|
* @param Setting setting name
|
|
|
|
|
* @return True if settings exist.
|
|
|
|
|
*/
|
2004-06-18 07:07:06 -07:00
|
|
|
bool SettingExists(const CStr& Setting) const;
|
2015-08-21 10:08:41 -07:00
|
|
|
|
2019-08-26 05:25:07 -07:00
|
|
|
/**
|
|
|
|
|
* 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;
|
|
|
|
|
|
Move static GUI<>::SetSetting operating on IGUIObject to a member IGUIObject::SetSetting.
Remove PSERROR codes from SetSetting (let std::map throw an out_of_range
if a caller wants to Set a setting that doesn't exist without having
checked with SettingExists, equal to GetSetting from 92b6cdfeab).
That also simplifies std::function SetSettingWrap construct from
0a7d0ecdde to void IGUIObject::SettingChanged.
Don't trigger debug_warn or exceptions in GUITooltip::ShowTooltip if the
XML author specified wrong tooltip input, and dodge another
dynamic_cast.
Rename existing IGUIObject::SetSetting to
IGUIObject::SetSettingFromString and comment that it is purposed for
parsing XML files.
Remove SetSetting default value, so that authors are made aware
explicitly of the need to decide the function broadcasting a message,
refs d87057b1c0, 719f2d7967, ...
Change const bool& SkipMessage to const bool SendMessage, so that a
positive value relates to a positive action.
Clean AddSettings whitespace and integer types.
Differential Revision: https://code.wildfiregames.com/D2231
Tested on: gcc 9.1.0, clang 8.0.1, Jenkins
Comments By: Philip on IRC on 2010-07-24 on GUIUtil being ugly, in case
that one counts
This was SVN commit r22796.
2019-08-28 04:21:11 -07:00
|
|
|
/**
|
|
|
|
|
* Set a setting by string, regardless of what type it is.
|
|
|
|
|
* Used to parse setting values from XML files.
|
|
|
|
|
* For example a CRect(10,10,20,20) is created from "10 10 20 20".
|
|
|
|
|
* Returns false if the conversion fails, otherwise true.
|
|
|
|
|
*/
|
|
|
|
|
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);
|
|
|
|
|
|
2019-09-30 07:08:14 -07:00
|
|
|
/**
|
|
|
|
|
* Returns whether this object is set to be hidden or ghost.
|
|
|
|
|
*/
|
|
|
|
|
bool IsEnabled() const;
|
|
|
|
|
|
2019-08-21 06:22:25 -07:00
|
|
|
/**
|
|
|
|
|
* Returns whether this is object is set to be hidden.
|
|
|
|
|
*/
|
2019-08-22 16:51:10 -07:00
|
|
|
bool IsHidden() const;
|
2019-08-21 06:22:25 -07:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns whether this object is set to be hidden or ghost.
|
|
|
|
|
*/
|
2019-08-22 16:51:10 -07:00
|
|
|
bool IsHiddenOrGhost() const;
|
2019-08-21 06:22:25 -07:00
|
|
|
|
2019-09-30 07:08:14 -07:00
|
|
|
/**
|
|
|
|
|
* Retrieves the configured sound filename from the given setting name and plays that once.
|
|
|
|
|
*/
|
|
|
|
|
void PlaySound(const CStrW& soundPath) const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Send event to this GUI object (HandleMessage and ScriptEvent)
|
|
|
|
|
*
|
|
|
|
|
* @param type Type of GUI message to be handled
|
|
|
|
|
* @param EventName String representation of event name
|
|
|
|
|
* @return IN_HANDLED if event was handled, or IN_PASS if skipped
|
|
|
|
|
*/
|
|
|
|
|
InReaction SendEvent(EGUIMessageType type, const CStr& EventName);
|
|
|
|
|
|
2003-11-24 09:13:37 -08:00
|
|
|
/**
|
|
|
|
|
* All sizes are relative to resolution, and the calculation
|
|
|
|
|
* is not wanted in real time, therefore it is cached, update
|
|
|
|
|
* the cached size with this function.
|
|
|
|
|
*/
|
2010-04-19 12:43:05 -07:00
|
|
|
virtual void UpdateCachedSize();
|
2003-11-24 09:13:37 -08:00
|
|
|
|
2019-07-27 19:39:52 -07:00
|
|
|
/**
|
|
|
|
|
* Reset internal state of this object.
|
|
|
|
|
*/
|
|
|
|
|
virtual void ResetStates();
|
|
|
|
|
|
2004-07-08 08:23:47 -07:00
|
|
|
/**
|
|
|
|
|
* Set the script handler for a particular object-specific action
|
|
|
|
|
*
|
|
|
|
|
* @param Action Name of action
|
|
|
|
|
* @param Code Javascript code to execute when the action occurs
|
|
|
|
|
* @param pGUI GUI instance to associate the script with
|
|
|
|
|
*/
|
2019-08-21 03:12:33 -07:00
|
|
|
void RegisterScriptHandler(const CStr& Action, const CStr& Code, CGUI& pGUI);
|
2015-08-21 10:08:41 -07:00
|
|
|
|
2019-08-02 05:18:30 -07:00
|
|
|
/**
|
2019-09-30 07:08:14 -07:00
|
|
|
* Inheriting classes may append JS functions to the JS object representing this class.
|
2019-08-02 05:18:30 -07:00
|
|
|
*/
|
2019-09-30 07:08:14 -07:00
|
|
|
virtual void RegisterScriptFunctions() {}
|
2019-08-02 05:18:30 -07:00
|
|
|
|
2007-06-08 15:56:01 -07:00
|
|
|
/**
|
|
|
|
|
* Retrieves the JSObject representing this GUI object.
|
|
|
|
|
*/
|
|
|
|
|
JSObject* GetJSObject();
|
2004-07-08 08:23:47 -07:00
|
|
|
|
2003-11-23 18:18:41 -08:00
|
|
|
//@}
|
|
|
|
|
protected:
|
|
|
|
|
//--------------------------------------------------------
|
|
|
|
|
/** @name Called by CGUI and friends
|
|
|
|
|
*
|
|
|
|
|
* Methods that the CGUI will call using
|
|
|
|
|
* its friendship, these should not
|
|
|
|
|
* be called by user.
|
|
|
|
|
* These functions' security are a lot
|
|
|
|
|
* what constitutes the GUI's
|
|
|
|
|
*/
|
|
|
|
|
//--------------------------------------------------------
|
|
|
|
|
//@{
|
|
|
|
|
|
2010-08-11 14:04:09 -07:00
|
|
|
public:
|
2003-11-23 18:18:41 -08:00
|
|
|
/**
|
|
|
|
|
* This function is called with different messages
|
|
|
|
|
* for instance when the mouse enters the object.
|
|
|
|
|
*
|
2003-12-26 22:26:03 -08:00
|
|
|
* @param Message GUI Message
|
2003-11-23 18:18:41 -08:00
|
|
|
*/
|
2011-04-28 13:42:11 -07:00
|
|
|
virtual void HandleMessage(SGUIMessage& UNUSED(Message)) {}
|
2003-11-23 18:18:41 -08:00
|
|
|
|
2019-08-21 06:22:25 -07:00
|
|
|
/**
|
|
|
|
|
* Calls an IGUIObject member function recursively on this object and its children.
|
|
|
|
|
* Aborts recursion at IGUIObjects that have the isRestricted function return true.
|
|
|
|
|
* The arguments of the callback function must be references.
|
|
|
|
|
*/
|
|
|
|
|
template<typename... Args>
|
2019-08-22 16:51:10 -07:00
|
|
|
void RecurseObject(bool(IGUIObject::*isRestricted)() const, void(IGUIObject::*callbackFunction)(Args... args), Args&&... args)
|
2019-08-21 06:22:25 -07:00
|
|
|
{
|
2019-09-18 13:51:45 -07:00
|
|
|
if (!IsBaseObject())
|
2019-08-21 06:22:25 -07:00
|
|
|
{
|
|
|
|
|
if (isRestricted && (this->*isRestricted)())
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
(this->*callbackFunction)(args...);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (IGUIObject* const& obj : m_Children)
|
|
|
|
|
obj->RecurseObject(isRestricted, callbackFunction, args...);
|
|
|
|
|
}
|
|
|
|
|
|
2010-08-11 14:04:09 -07:00
|
|
|
protected:
|
2003-11-23 18:18:41 -08:00
|
|
|
/**
|
|
|
|
|
* Draws the object.
|
|
|
|
|
*/
|
2015-08-21 10:08:41 -07:00
|
|
|
virtual void Draw() = 0;
|
2003-11-23 18:18:41 -08:00
|
|
|
|
2004-10-14 03:09:26 -07:00
|
|
|
/**
|
2006-08-26 14:52:18 -07:00
|
|
|
* Some objects need to handle the SDL_Event_ manually.
|
2004-10-14 03:09:26 -07:00
|
|
|
* For instance the input box.
|
|
|
|
|
*
|
|
|
|
|
* Only the object with focus will have this function called.
|
|
|
|
|
*
|
2005-10-20 10:44:56 -07:00
|
|
|
* Returns either IN_PASS or IN_HANDLED. If IN_HANDLED, then
|
2004-10-14 03:09:26 -07:00
|
|
|
* the key won't be passed on and processed by other handlers.
|
|
|
|
|
* This is used for keys that the GUI uses.
|
|
|
|
|
*/
|
2006-08-26 14:52:18 -07:00
|
|
|
virtual InReaction ManuallyHandleEvent(const SDL_Event_* UNUSED(ev)) { return IN_PASS; }
|
2004-10-14 03:09:26 -07:00
|
|
|
|
2003-12-26 22:26:03 -08:00
|
|
|
/**
|
|
|
|
|
* Loads a style.
|
|
|
|
|
*/
|
2019-08-27 09:03:24 -07:00
|
|
|
void LoadStyle(const CStr& StyleName);
|
2003-12-26 22:26:03 -08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns not the Z value, but the actual buffered Z value, i.e. if it's
|
|
|
|
|
* defined relative, then it will check its parent's Z value and add
|
|
|
|
|
* the relativity.
|
|
|
|
|
*
|
|
|
|
|
* @return Actual Z value on the screen.
|
|
|
|
|
*/
|
2004-05-28 21:06:50 -07:00
|
|
|
virtual float GetBufferedZ() const;
|
2003-12-26 22:26:03 -08:00
|
|
|
|
2011-04-28 13:42:11 -07:00
|
|
|
/**
|
|
|
|
|
* Set parent of this object
|
|
|
|
|
*/
|
2015-08-21 10:08:41 -07:00
|
|
|
void SetParent(IGUIObject* pParent) { m_pParent = pParent; }
|
|
|
|
|
|
2010-08-11 14:04:09 -07:00
|
|
|
public:
|
2019-07-27 19:39:52 -07:00
|
|
|
|
2019-08-21 03:12:33 -07:00
|
|
|
CGUI& GetGUI() { return m_pGUI; }
|
|
|
|
|
const CGUI& GetGUI() const { return m_pGUI; }
|
2010-08-13 06:50:03 -07:00
|
|
|
|
2004-10-14 03:09:26 -07:00
|
|
|
/**
|
|
|
|
|
* Take focus!
|
|
|
|
|
*/
|
|
|
|
|
void SetFocus();
|
|
|
|
|
|
2010-08-11 14:04:09 -07:00
|
|
|
protected:
|
2004-10-14 03:09:26 -07:00
|
|
|
/**
|
|
|
|
|
* Check if object is focused.
|
|
|
|
|
*/
|
|
|
|
|
bool IsFocused() const;
|
|
|
|
|
|
2003-11-23 18:18:41 -08:00
|
|
|
/**
|
|
|
|
|
* <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
|
|
|
|
|
* the top-node (the object that isn't a real object), this
|
2019-09-22 16:28:25 -07:00
|
|
|
* will return nullptr, so that the top-node's children are
|
2003-11-23 18:18:41 -08:00
|
|
|
* seemingly parentless.
|
|
|
|
|
*
|
|
|
|
|
* @return Pointer to parent
|
|
|
|
|
*/
|
2015-08-21 10:08:41 -07:00
|
|
|
IGUIObject* GetParent() const;
|
2003-12-26 22:26:03 -08:00
|
|
|
|
2005-04-07 02:13:10 -07:00
|
|
|
/**
|
2010-07-21 10:53:38 -07:00
|
|
|
* Handle additional children to the \<object\>-tag. In IGUIObject, this function does
|
|
|
|
|
* nothing. In CList and CDropDown, it handles the \<item\>, used to build the data.
|
2005-04-07 02:13:10 -07:00
|
|
|
*
|
|
|
|
|
* Returning false means the object doesn't recognize the child. Should be reported.
|
|
|
|
|
* Notice 'false' is default, because an object not using this function, should not
|
|
|
|
|
* have any additional children (and this function should never be called).
|
|
|
|
|
*/
|
2015-08-21 10:08:41 -07:00
|
|
|
virtual bool HandleAdditionalChildren(const XMBElement& UNUSED(child), CXeromyces* UNUSED(pFile))
|
|
|
|
|
{
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2005-04-07 02:13:10 -07:00
|
|
|
|
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 05:49:59 -07:00
|
|
|
/**
|
|
|
|
|
* Allow the GUI object to process after all child items were handled.
|
|
|
|
|
* Useful to avoid iterator invalidation with push_back calls.
|
|
|
|
|
*/
|
|
|
|
|
virtual void AdditionalChildrenHandled() {}
|
|
|
|
|
|
2003-11-24 09:13:37 -08:00
|
|
|
/**
|
|
|
|
|
* Cached size, real size m_Size is actually dependent on resolution
|
|
|
|
|
* and can have different *real* outcomes, this is the real outcome
|
|
|
|
|
* cached to avoid slow calculations in real time.
|
|
|
|
|
*/
|
|
|
|
|
CRect m_CachedActualSize;
|
|
|
|
|
|
2004-07-08 08:23:47 -07:00
|
|
|
/**
|
|
|
|
|
* Execute the script for a particular action.
|
|
|
|
|
* Does nothing if no script has been registered for that action.
|
2010-09-11 12:49:21 -07:00
|
|
|
* The mouse coordinates will be passed as the first argument.
|
2004-07-08 08:23:47 -07:00
|
|
|
*
|
|
|
|
|
* @param Action Name of action
|
|
|
|
|
*/
|
|
|
|
|
void ScriptEvent(const CStr& Action);
|
|
|
|
|
|
2010-09-11 12:49:21 -07:00
|
|
|
/**
|
|
|
|
|
* Execute the script for a particular action.
|
|
|
|
|
* Does nothing if no script has been registered for that action.
|
|
|
|
|
*
|
|
|
|
|
* @param Action Name of action
|
2019-07-19 14:15:04 -07:00
|
|
|
* @param paramData JS::HandleValueArray arguments to pass to the event.
|
2010-09-11 12:49:21 -07:00
|
|
|
*/
|
2019-08-21 06:22:25 -07:00
|
|
|
void ScriptEvent(const CStr& Action, const JS::HandleValueArray& paramData);
|
2010-09-11 12:49:21 -07:00
|
|
|
|
2019-10-28 04:35:04 -07:00
|
|
|
/**
|
|
|
|
|
* Assigns a JS function to the event name.
|
|
|
|
|
*/
|
2014-08-08 06:41:47 -07:00
|
|
|
void SetScriptHandler(const CStr& Action, JS::HandleObject Function);
|
2004-07-08 08:23:47 -07:00
|
|
|
|
2019-10-28 04:35:04 -07:00
|
|
|
/**
|
|
|
|
|
* Deletes an event handler assigned to the given name, if such a handler exists.
|
|
|
|
|
*/
|
|
|
|
|
void UnsetScriptHandler(const CStr& Action);
|
|
|
|
|
|
2012-05-02 15:57:35 -07:00
|
|
|
/**
|
|
|
|
|
* Inputes the object that is currently hovered, this function
|
|
|
|
|
* updates this object accordingly (i.e. if it's the object
|
|
|
|
|
* being inputted one thing happens, and not, another).
|
|
|
|
|
*
|
2019-09-22 16:28:25 -07:00
|
|
|
* @param pMouseOver Object that is currently hovered, can be nullptr too!
|
2012-05-02 15:57:35 -07:00
|
|
|
*/
|
2015-08-21 10:08:41 -07:00
|
|
|
void UpdateMouseOver(IGUIObject* const& pMouseOver);
|
2012-05-02 15:57:35 -07:00
|
|
|
|
2003-11-23 18:18:41 -08:00
|
|
|
//@}
|
|
|
|
|
private:
|
|
|
|
|
//--------------------------------------------------------
|
|
|
|
|
/** @name Internal functions */
|
|
|
|
|
//--------------------------------------------------------
|
|
|
|
|
//@{
|
2015-08-21 10:08:41 -07:00
|
|
|
|
2019-09-30 07:08:14 -07:00
|
|
|
/**
|
|
|
|
|
* Creates the JS object representing this page upon first use.
|
|
|
|
|
*/
|
|
|
|
|
void CreateJSObject();
|
|
|
|
|
|
Move static GUI<>::SetSetting operating on IGUIObject to a member IGUIObject::SetSetting.
Remove PSERROR codes from SetSetting (let std::map throw an out_of_range
if a caller wants to Set a setting that doesn't exist without having
checked with SettingExists, equal to GetSetting from 92b6cdfeab).
That also simplifies std::function SetSettingWrap construct from
0a7d0ecdde to void IGUIObject::SettingChanged.
Don't trigger debug_warn or exceptions in GUITooltip::ShowTooltip if the
XML author specified wrong tooltip input, and dodge another
dynamic_cast.
Rename existing IGUIObject::SetSetting to
IGUIObject::SetSettingFromString and comment that it is purposed for
parsing XML files.
Remove SetSetting default value, so that authors are made aware
explicitly of the need to decide the function broadcasting a message,
refs d87057b1c0, 719f2d7967, ...
Change const bool& SkipMessage to const bool SendMessage, so that a
positive value relates to a positive action.
Clean AddSettings whitespace and integer types.
Differential Revision: https://code.wildfiregames.com/D2231
Tested on: gcc 9.1.0, clang 8.0.1, Jenkins
Comments By: Philip on IRC on 2010-07-24 on GUIUtil being ugly, in case
that one counts
This was SVN commit r22796.
2019-08-28 04:21:11 -07:00
|
|
|
/**
|
|
|
|
|
* Updates some internal data depending on the setting changed.
|
|
|
|
|
*/
|
2019-09-04 08:29:36 -07:00
|
|
|
void PreSettingChange(const CStr& Setting);
|
Move static GUI<>::SetSetting operating on IGUIObject to a member IGUIObject::SetSetting.
Remove PSERROR codes from SetSetting (let std::map throw an out_of_range
if a caller wants to Set a setting that doesn't exist without having
checked with SettingExists, equal to GetSetting from 92b6cdfeab).
That also simplifies std::function SetSettingWrap construct from
0a7d0ecdde to void IGUIObject::SettingChanged.
Don't trigger debug_warn or exceptions in GUITooltip::ShowTooltip if the
XML author specified wrong tooltip input, and dodge another
dynamic_cast.
Rename existing IGUIObject::SetSetting to
IGUIObject::SetSettingFromString and comment that it is purposed for
parsing XML files.
Remove SetSetting default value, so that authors are made aware
explicitly of the need to decide the function broadcasting a message,
refs d87057b1c0, 719f2d7967, ...
Change const bool& SkipMessage to const bool SendMessage, so that a
positive value relates to a positive action.
Clean AddSettings whitespace and integer types.
Differential Revision: https://code.wildfiregames.com/D2231
Tested on: gcc 9.1.0, clang 8.0.1, Jenkins
Comments By: Philip on IRC on 2010-07-24 on GUIUtil being ugly, in case
that one counts
This was SVN commit r22796.
2019-08-28 04:21:11 -07:00
|
|
|
void SettingChanged(const CStr& Setting, const bool SendMessage);
|
|
|
|
|
|
2003-11-23 18:18:41 -08:00
|
|
|
/**
|
|
|
|
|
* Inputs a reference pointer, checks if the new inputted object
|
|
|
|
|
* if hovered, if so, then check if this's Z value is greater
|
|
|
|
|
* than the inputted object... If so then the object is closer
|
|
|
|
|
* and we'll replace the pointer with this.
|
2019-09-22 16:28:25 -07:00
|
|
|
* Also Notice input can be nullptr, which means the Z value demand
|
|
|
|
|
* is out. NOTICE you can't input nullptr as const so you'll have
|
|
|
|
|
* to set an object to nullptr.
|
2003-11-23 18:18:41 -08:00
|
|
|
*
|
|
|
|
|
* @param pObject Object pointer, can be either the old one, or
|
|
|
|
|
* the new one.
|
|
|
|
|
*/
|
2015-08-21 10:08:41 -07:00
|
|
|
void ChooseMouseOverAndClosest(IGUIObject*& pObject);
|
2003-11-23 18:18:41 -08:00
|
|
|
|
2019-09-18 13:51:45 -07:00
|
|
|
/**
|
|
|
|
|
* Returns whether this is the object all other objects are descendants of.
|
|
|
|
|
*/
|
|
|
|
|
bool IsBaseObject() const;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns whether this object is a child of the base object.
|
|
|
|
|
*/
|
2005-07-20 16:49:39 -07:00
|
|
|
bool IsRootObject() const;
|
|
|
|
|
|
2015-08-21 10:08:41 -07:00
|
|
|
static void Trace(JSTracer* trc, void* data)
|
2015-01-24 06:46:52 -08:00
|
|
|
{
|
|
|
|
|
reinterpret_cast<IGUIObject*>(data)->TraceMember(trc);
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-21 10:08:41 -07:00
|
|
|
void TraceMember(JSTracer* trc);
|
2015-01-24 06:46:52 -08:00
|
|
|
|
2019-09-22 16:28:25 -07:00
|
|
|
// Variables
|
2003-11-23 18:18:41 -08:00
|
|
|
protected:
|
2004-10-14 03:09:26 -07:00
|
|
|
// Name of object
|
2019-09-22 16:28:25 -07:00
|
|
|
CStr m_Name;
|
2003-11-23 18:18:41 -08:00
|
|
|
|
2019-09-22 16:28:25 -07:00
|
|
|
// Constructed on the heap, will be destroyed along with the the CGUI
|
2019-10-01 05:46:55 -07:00
|
|
|
std::vector<IGUIObject*> m_Children;
|
2003-11-23 18:18:41 -08:00
|
|
|
|
2004-10-14 03:09:26 -07:00
|
|
|
// Pointer to parent
|
2019-09-22 16:28:25 -07:00
|
|
|
IGUIObject* m_pParent;
|
2014-03-07 14:43:57 -08:00
|
|
|
|
2006-01-21 03:07:25 -08:00
|
|
|
//This represents the last click time for each mouse button
|
|
|
|
|
double m_LastClickTime[6];
|
2003-11-23 18:18:41 -08:00
|
|
|
|
2003-11-30 23:06:55 -08:00
|
|
|
/**
|
2019-10-05 02:58:31 -07:00
|
|
|
* This variable is true if the mouse is hovering this object and
|
|
|
|
|
* this object is the topmost object shown in this location.
|
2003-11-30 23:06:55 -08:00
|
|
|
*/
|
2019-09-22 16:28:25 -07:00
|
|
|
bool m_MouseHovering;
|
2003-11-23 18:18:41 -08:00
|
|
|
|
2004-05-28 21:06:50 -07:00
|
|
|
/**
|
|
|
|
|
* Settings pool, all an object's settings are located here
|
|
|
|
|
*/
|
2019-08-03 19:20:08 -07:00
|
|
|
std::map<CStr, IGUISetting*> m_Settings;
|
2003-11-23 18:18:41 -08:00
|
|
|
|
2004-10-14 03:09:26 -07:00
|
|
|
// An object can't function stand alone
|
2019-08-21 03:12:33 -07:00
|
|
|
CGUI& m_pGUI;
|
2005-03-30 14:33:10 -08:00
|
|
|
|
|
|
|
|
// Internal storage for registered script handlers.
|
2019-09-22 16:28:25 -07:00
|
|
|
std::map<CStr, JS::Heap<JSObject*> > m_ScriptHandlers;
|
2015-08-21 10:08:41 -07:00
|
|
|
|
2007-06-08 15:56:01 -07:00
|
|
|
// Cached JSObject representing this GUI object
|
2019-09-22 16:28:25 -07:00
|
|
|
JS::PersistentRootedObject m_JSObject;
|
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 05:49:59 -07:00
|
|
|
|
|
|
|
|
// Cache references to settings for performance
|
|
|
|
|
bool m_Enabled;
|
|
|
|
|
bool m_Hidden;
|
2019-10-01 08:06:13 -07:00
|
|
|
CGUISize m_Size;
|
Change GUI Object Setting values to be members of the IGUIObject inheriting class, rename AddSetting to RegisterSetting.
Improves performance for Draw calls by 3-5% according to a shady
benchmark.
Improves memory layout, since the values are not on the heap anymore but
in the using class.
Reduces complexity of the implementation and increases type safety.
Allows specifying default values at setting value construction time,
refs D2242.
Inspired by Vladislav introducing members that cached GetSetting values
in c016a74309/D325, refs #4039, ee38f0db37/D763, refs 4225,
a1c4c23ce4/D474, D406, which were formerly proposed to be removed in
D2241.
Differential Revision: https://code.wildfiregames.com/D2313
Tested on: clang 8.0.1, gcc 9.1.0, Jenkins vs2015
Comments By: Vladislav
This was SVN commit r23005.
2019-09-27 05:49:59 -07:00
|
|
|
CStr m_Style;
|
|
|
|
|
CStr m_Hotkey;
|
|
|
|
|
float m_Z;
|
|
|
|
|
bool m_Absolute;
|
|
|
|
|
bool m_Ghost;
|
|
|
|
|
float m_AspectRatio;
|
|
|
|
|
CStrW m_Tooltip;
|
|
|
|
|
CStr m_TooltipStyle;
|
2003-11-23 18:18:41 -08:00
|
|
|
};
|
|
|
|
|
|
2015-08-21 10:08:41 -07:00
|
|
|
#endif // INCLUDED_IGUIOBJECT
|