Changeset View
Changeset View
Standalone View
Standalone View
source/gui/ObjectBases/IGUIObject.h
/* Copyright (C) 2019 Wildfire Games. | /* Copyright (C) 2019 Wildfire Games. | ||||
Silier: ^ | |||||
* 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 All 26 Lines | |||||
#include <vector> | #include <vector> | ||||
class CGUI; | class CGUI; | ||||
class IGUIObject; | class IGUIObject; | ||||
class IGUISetting; | class IGUISetting; | ||||
using map_pObjects = std::map<CStr, IGUIObject*>; | using map_pObjects = std::map<CStr, IGUIObject*>; | ||||
#define GUI_OBJECT(obj) \ | #define BASE_GUI_OBJECT(obj, xmlName_, JSFactoryType) \ | ||||
StanUnsubmitted Not Done Inline ActionsDo we really need that macro? Stan: Do we really need that macro? | |||||
wraitiiAuthorUnsubmitted Done Inline ActionsYes because IGuiObject uses it, whereas derived objects use GUI_OBJECT wraitii: Yes because IGuiObject uses it, whereas derived objects use GUI_OBJECT | |||||
public: \ | protected: \ | ||||
friend class CGUI; \ | |||||
friend class JSI_GUI::GUIProxy; \ | |||||
friend class JSI_GUI::JSFactoryType; \ | |||||
\ | |||||
static constexpr const char* xmlName = xmlName_; \ | |||||
virtual CStr GetObjectType() { return xmlName_; }; \ | |||||
\ | |||||
using JSFactory = JSI_GUI::JSFactoryType; | |||||
#define GUI_OBJECT(obj, xmlName_, JSFactoryType) \ | |||||
BASE_GUI_OBJECT(obj, xmlName_, JSFactoryType) \ | |||||
static IGUIObject* ConstructObject(CGUI& pGUI) \ | static IGUIObject* ConstructObject(CGUI& pGUI) \ | ||||
{ return new obj(pGUI); } | { return new obj(pGUI); }; | ||||
/** | /** | ||||
* 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; | BASE_GUI_OBJECT(IGUIObject, "empty", GUIObjectFactory); | ||||
// Allow getProperty to access things like GetParent() | |||||
friend bool JSI_IGUIObject::getProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp); | |||||
friend bool JSI_IGUIObject::setProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::MutableHandleValue vp, JS::ObjectOpResult& result); | |||||
friend bool JSI_IGUIObject::deleteProperty(JSContext* cx, JS::HandleObject obj, JS::HandleId id, JS::ObjectOpResult& result); | |||||
friend bool JSI_IGUIObject::getComputedSize(JSContext* cx, uint argc, JS::Value* vp); | |||||
public: | public: | ||||
NONCOPYABLE(IGUIObject); | NONCOPYABLE(IGUIObject); | ||||
IGUIObject(CGUI& pGUI); | IGUIObject(CGUI& pGUI); | ||||
virtual ~IGUIObject(); | virtual ~IGUIObject(); | ||||
/** | /** | ||||
▲ Show 20 Lines • Show All 165 Lines • ▼ Show 20 Lines | public: | ||||
*/ | */ | ||||
virtual void RegisterScriptFunctions() {} | virtual void RegisterScriptFunctions() {} | ||||
/** | /** | ||||
* Retrieves the JSObject representing this GUI object. | * Retrieves the JSObject representing this GUI object. | ||||
*/ | */ | ||||
JSObject* GetJSObject(); | JSObject* GetJSObject(); | ||||
protected: | |||||
/** | |||||
* When creating the JS counterpart of a GUI Object, | |||||
* we may need to set the private data to the derived 'this', | |||||
* and not the base 'this', otherwise derived proxies | |||||
* won't be able to call the derived-only functions. | |||||
* Perhaps TODO: I think the virtual call could be CRPT-ed out. | |||||
*/ | |||||
virtual void SetPrivateData(); | |||||
public: | |||||
std::string toString() const; | |||||
StanUnsubmitted Not Done Inline ActionsMaybe we could use CStr? Stan: Maybe we could use CStr? | |||||
wraitiiAuthorUnsubmitted Done Inline ActionsI haven't actually changed the signature wraitii: I haven't actually changed the signature | |||||
void focus(); | |||||
StanUnsubmitted Not Done Inline ActionsNot sure but conventions says PascalCase even though this is for js? Stan: Not sure but conventions says PascalCase even though this is for js? | |||||
wraitiiAuthorUnsubmitted Done Inline ActionsLikewise, haven't really cleaned up those functions wraitii: Likewise, haven't really cleaned up those functions | |||||
void blur(); | |||||
CRect getComputedSize(); | |||||
//@} | //@} | ||||
protected: | protected: | ||||
//-------------------------------------------------------- | //-------------------------------------------------------- | ||||
/** @name Called by CGUI and friends | /** @name Called by CGUI and friends | ||||
* | * | ||||
* Methods that the CGUI will call using | * Methods that the CGUI will call using | ||||
* its friendship, these should not | * its friendship, these should not | ||||
* be called by user. | * be called by user. | ||||
▲ Show 20 Lines • Show All 182 Lines • ▼ Show 20 Lines | protected: | ||||
void UpdateMouseOver(IGUIObject* const& pMouseOver); | void UpdateMouseOver(IGUIObject* const& pMouseOver); | ||||
//@} | //@} | ||||
private: | private: | ||||
//-------------------------------------------------------- | //-------------------------------------------------------- | ||||
/** @name Internal functions */ | /** @name Internal functions */ | ||||
//-------------------------------------------------------- | //-------------------------------------------------------- | ||||
//@{ | //@{ | ||||
/** | /** | ||||
Not Done Inline Actionspure virtual? Stan: pure virtual? | |||||
Done Inline Actionsdef not, it's implement in IGUIObject.cpp wraitii: def not, it's implement in IGUIObject.cpp | |||||
* Creates the JS object representing this page upon first use. | |||||
*/ | |||||
void CreateJSObject(); | |||||
/** | |||||
* Updates some internal data depending on the setting changed. | * Updates some internal data depending on the setting changed. | ||||
*/ | */ | ||||
void PreSettingChange(const CStr& Setting); | void PreSettingChange(const CStr& Setting); | ||||
void SettingChanged(const CStr& Setting, const bool SendMessage); | void SettingChanged(const CStr& Setting, const bool SendMessage); | ||||
/** | /** | ||||
* 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 | ||||
▲ Show 20 Lines • Show All 81 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
^