Move CGUIDummyObject class used for empty GUI objects to a separate file, and put the according CGUI page base object on the stack.
Differential Revision: https://code.wildfiregames.com/D2206 Tested on: clang 8.0.1., Jenkins This was SVN commit r22931.
This commit is contained in:
parent
b88e7d8368
commit
a936cc618a
@ -19,6 +19,7 @@
|
||||
|
||||
#include "CDropDown.h"
|
||||
|
||||
#include "gui/CGUI.h"
|
||||
#include "gui/CGUIColor.h"
|
||||
#include "lib/external_libraries/libsdl.h"
|
||||
#include "lib/ogl.h"
|
||||
|
@ -20,7 +20,7 @@
|
||||
#include <stdarg.h>
|
||||
#include <string>
|
||||
|
||||
#include "GUI.h"
|
||||
#include "CGUI.h"
|
||||
|
||||
// Types - when including them into the engine.
|
||||
#include "CButton.h"
|
||||
@ -102,7 +102,7 @@ InReaction CGUI::HandleEvent(const SDL_Event_* ev)
|
||||
m_MousePos = CPos((float)ev->ev.motion.x / g_GuiScale, (float)ev->ev.motion.y / g_GuiScale);
|
||||
|
||||
SGUIMessage msg(GUIM_MOUSE_MOTION);
|
||||
m_BaseObject->RecurseObject(&IGUIObject::IsHiddenOrGhost, &IGUIObject::HandleMessage, msg);
|
||||
m_BaseObject.RecurseObject(&IGUIObject::IsHiddenOrGhost, &IGUIObject::HandleMessage, msg);
|
||||
}
|
||||
|
||||
// Update m_MouseButtons. (BUTTONUP is handled later.)
|
||||
@ -143,7 +143,7 @@ InReaction CGUI::HandleEvent(const SDL_Event_* ev)
|
||||
// Now we'll call UpdateMouseOver on *all* objects,
|
||||
// we'll input the one hovered, and they will each
|
||||
// update their own data and send messages accordingly
|
||||
m_BaseObject->RecurseObject(&IGUIObject::IsHiddenOrGhost, &IGUIObject::UpdateMouseOver, static_cast<IGUIObject* const&>(pNearest));
|
||||
m_BaseObject.RecurseObject(&IGUIObject::IsHiddenOrGhost, &IGUIObject::UpdateMouseOver, static_cast<IGUIObject* const&>(pNearest));
|
||||
|
||||
if (ev->ev.type == SDL_MOUSEBUTTONDOWN)
|
||||
{
|
||||
@ -204,10 +204,10 @@ InReaction CGUI::HandleEvent(const SDL_Event_* ev)
|
||||
}
|
||||
|
||||
// Reset all states on all visible objects
|
||||
m_BaseObject->RecurseObject(&IGUIObject::IsHidden, &IGUIObject::ResetStates);
|
||||
m_BaseObject.RecurseObject(&IGUIObject::IsHidden, &IGUIObject::ResetStates);
|
||||
|
||||
// Since the hover state will have been reset, we reload it.
|
||||
m_BaseObject->RecurseObject(&IGUIObject::IsHiddenOrGhost, &IGUIObject::UpdateMouseOver, static_cast<IGUIObject* const&>(pNearest));
|
||||
m_BaseObject.RecurseObject(&IGUIObject::IsHiddenOrGhost, &IGUIObject::UpdateMouseOver, static_cast<IGUIObject* const&>(pNearest));
|
||||
}
|
||||
}
|
||||
catch (PSERROR_GUI& e)
|
||||
@ -260,7 +260,7 @@ InReaction CGUI::HandleEvent(const SDL_Event_* ev)
|
||||
void CGUI::TickObjects()
|
||||
{
|
||||
const CStr action = "tick";
|
||||
m_BaseObject->RecurseObject(nullptr, &IGUIObject::ScriptEvent, action);
|
||||
m_BaseObject.RecurseObject(nullptr, &IGUIObject::ScriptEvent, action);
|
||||
|
||||
m_Tooltip.Update(FindObjectUnderMouse(), m_MousePos, *this);
|
||||
}
|
||||
@ -275,33 +275,28 @@ void CGUI::SendEventToAll(const CStr& EventName)
|
||||
// leading to a similar problem.
|
||||
// now fixed; case is irrelevant since all are converted to lower.
|
||||
const CStr EventNameLower = EventName.LowerCase();
|
||||
m_BaseObject->RecurseObject(nullptr, &IGUIObject::ScriptEvent, EventNameLower);
|
||||
m_BaseObject.RecurseObject(nullptr, &IGUIObject::ScriptEvent, EventNameLower);
|
||||
}
|
||||
|
||||
void CGUI::SendEventToAll(const CStr& EventName, const JS::HandleValueArray& paramData)
|
||||
{
|
||||
const CStr EventNameLower = EventName.LowerCase();
|
||||
m_BaseObject->RecurseObject(nullptr, &IGUIObject::ScriptEvent, EventNameLower, paramData);
|
||||
m_BaseObject.RecurseObject(nullptr, &IGUIObject::ScriptEvent, EventNameLower, paramData);
|
||||
}
|
||||
|
||||
CGUI::CGUI(const shared_ptr<ScriptRuntime>& runtime)
|
||||
: m_MouseButtons(0), m_FocusedObject(NULL), m_InternalNameNumber(0)
|
||||
: m_MouseButtons(0), m_FocusedObject(nullptr), m_InternalNameNumber(0), m_BaseObject(*this)
|
||||
{
|
||||
m_ScriptInterface.reset(new ScriptInterface("Engine", "GUIPage", runtime));
|
||||
m_ScriptInterface->SetCallbackData(this);
|
||||
|
||||
GuiScriptingInit(*m_ScriptInterface);
|
||||
m_ScriptInterface->LoadGlobalScripts();
|
||||
|
||||
m_BaseObject = new CGUIDummyObject(*this);
|
||||
}
|
||||
|
||||
CGUI::~CGUI()
|
||||
{
|
||||
Destroy();
|
||||
|
||||
if (m_BaseObject)
|
||||
delete m_BaseObject;
|
||||
}
|
||||
|
||||
IGUIObject* CGUI::ConstructObject(const CStr& str)
|
||||
@ -343,7 +338,7 @@ void CGUI::Draw()
|
||||
|
||||
try
|
||||
{
|
||||
m_BaseObject->RecurseObject(&IGUIObject::IsHidden, &IGUIObject::Draw);
|
||||
m_BaseObject.RecurseObject(&IGUIObject::IsHidden, &IGUIObject::Draw);
|
||||
}
|
||||
catch (PSERROR_GUI& e)
|
||||
{
|
||||
@ -392,14 +387,14 @@ void CGUI::Destroy()
|
||||
void CGUI::UpdateResolution()
|
||||
{
|
||||
// Update ALL cached
|
||||
m_BaseObject->RecurseObject(nullptr, &IGUIObject::UpdateCachedSize);
|
||||
m_BaseObject.RecurseObject(nullptr, &IGUIObject::UpdateCachedSize);
|
||||
}
|
||||
|
||||
void CGUI::AddObject(IGUIObject* pObject)
|
||||
{
|
||||
try
|
||||
{
|
||||
m_BaseObject->AddChild(pObject);
|
||||
m_BaseObject.AddChild(pObject);
|
||||
|
||||
// Cache tree
|
||||
pObject->RecurseObject(nullptr, &IGUIObject::UpdateCachedSize);
|
||||
@ -421,7 +416,7 @@ void CGUI::UpdateObjects()
|
||||
try
|
||||
{
|
||||
// Fill freshly
|
||||
m_BaseObject->RecurseObject(nullptr, &IGUIObject::AddToPointersMap, AllObjects);
|
||||
m_BaseObject.RecurseObject(nullptr, &IGUIObject::AddToPointersMap, AllObjects);
|
||||
}
|
||||
catch (PSERROR_GUI&)
|
||||
{
|
||||
@ -446,10 +441,10 @@ IGUIObject* CGUI::FindObjectByName(const CStr& Name) const
|
||||
return it->second;
|
||||
}
|
||||
|
||||
IGUIObject* CGUI::FindObjectUnderMouse() const
|
||||
IGUIObject* CGUI::FindObjectUnderMouse()
|
||||
{
|
||||
IGUIObject* pNearest = NULL;
|
||||
m_BaseObject->RecurseObject(&IGUIObject::IsHiddenOrGhost, &IGUIObject::ChooseMouseOverAndClosest, pNearest);
|
||||
m_BaseObject.RecurseObject(&IGUIObject::IsHiddenOrGhost, &IGUIObject::ChooseMouseOverAndClosest, pNearest);
|
||||
return pNearest;
|
||||
}
|
||||
|
||||
@ -588,7 +583,7 @@ void CGUI::Xeromyces_ReadRootObjects(XMBElement Element, CXeromyces* pFile, boos
|
||||
Xeromyces_ReadScript(child, pFile, Paths);
|
||||
else
|
||||
// Read in this whole object into the GUI
|
||||
Xeromyces_ReadObject(child, pFile, m_BaseObject, subst, Paths, 0);
|
||||
Xeromyces_ReadObject(child, pFile, &m_BaseObject, subst, Paths, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@ -917,7 +912,7 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec
|
||||
|
||||
try
|
||||
{
|
||||
if (pParent == m_BaseObject)
|
||||
if (pParent == &m_BaseObject)
|
||||
AddObject(object);
|
||||
else
|
||||
pParent->AddChild(object);
|
||||
|
@ -23,9 +23,9 @@
|
||||
#ifndef INCLUDED_CGUI
|
||||
#define INCLUDED_CGUI
|
||||
|
||||
#include "GUITooltip.h"
|
||||
#include "GUIbase.h"
|
||||
|
||||
#include "gui/GUITooltip.h"
|
||||
#include "gui/GUIbase.h"
|
||||
#include "gui/CGUIDummyObject.h"
|
||||
#include "lib/input.h"
|
||||
#include "ps/Shapes.h"
|
||||
#include "ps/XML/Xeromyces.h"
|
||||
@ -50,8 +50,6 @@ struct SGUIStyle
|
||||
std::map<CStr, CStrW> m_SettingsDefaults;
|
||||
};
|
||||
|
||||
class JSObject; // The GUI stores a JSObject*, so needs to know that JSObject exists
|
||||
class IGUIObject;
|
||||
class CGUISpriteInstance;
|
||||
struct CGUIColor;
|
||||
class CGUIText;
|
||||
@ -60,7 +58,6 @@ class CGUIString;
|
||||
class CGUISprite;
|
||||
struct SGUIImageEffects;
|
||||
struct SGUIScrollBarStyle;
|
||||
class GUITooltip;
|
||||
|
||||
/**
|
||||
* The main object that represents a whole GUI page.
|
||||
@ -162,7 +159,7 @@ public:
|
||||
/**
|
||||
* Return the object which is an ancestor of every other GUI object.
|
||||
*/
|
||||
IGUIObject* GetBaseObject() const { return m_BaseObject; };
|
||||
CGUIDummyObject& GetBaseObject() { return m_BaseObject; };
|
||||
|
||||
/**
|
||||
* Checks if object exists and return true or false accordingly
|
||||
@ -184,7 +181,7 @@ public:
|
||||
/**
|
||||
* Returns the GUI object under the mouse, or NULL if none.
|
||||
*/
|
||||
IGUIObject* FindObjectUnderMouse() const;
|
||||
IGUIObject* FindObjectUnderMouse();
|
||||
|
||||
/**
|
||||
* Returns the current screen coordinates of the cursor.
|
||||
@ -600,7 +597,7 @@ private:
|
||||
* Base Object, all its children are considered parentless
|
||||
* because this is not a real object per se.
|
||||
*/
|
||||
IGUIObject* m_BaseObject;
|
||||
CGUIDummyObject m_BaseObject;
|
||||
|
||||
/**
|
||||
* Focused object!
|
||||
|
49
source/gui/CGUIDummyObject.h
Normal file
49
source/gui/CGUIDummyObject.h
Normal file
@ -0,0 +1,49 @@
|
||||
/* Copyright (C) 2019 Wildfire Games.
|
||||
* 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/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This is the top class of the whole GUI, all objects
|
||||
* and settings are stored within this class.
|
||||
*/
|
||||
|
||||
#ifndef INCLUDED_CGUIDUMMYOBJECT
|
||||
#define INCLUDED_CGUIDUMMYOBJECT
|
||||
|
||||
#include "gui/IGUIObject.h"
|
||||
|
||||
/**
|
||||
* Dummy object are used for the base object and objects of type "empty".
|
||||
*/
|
||||
class CGUIDummyObject : public IGUIObject
|
||||
{
|
||||
GUI_OBJECT(CGUIDummyObject)
|
||||
|
||||
public:
|
||||
CGUIDummyObject(CGUI& pGUI) : IGUIObject(pGUI) {}
|
||||
|
||||
virtual void Draw() {}
|
||||
|
||||
/**
|
||||
* Empty can never be hovered. It is only a category.
|
||||
*/
|
||||
virtual bool IsMouseOver() const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
#endif // INCLUDED_CGUIDUMMYOBJECT
|
@ -20,6 +20,7 @@
|
||||
#include "CGUIScrollBarVertical.h"
|
||||
|
||||
#include "GUI.h"
|
||||
#include "CGUI.h"
|
||||
|
||||
#include "ps/CLogger.h"
|
||||
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include "CGUISetting.h"
|
||||
|
||||
#include "gui/CGUI.h"
|
||||
#include "gui/GUI.h"
|
||||
|
||||
template<typename T>
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "CGUIString.h"
|
||||
|
||||
#include "graphics/FontMetrics.h"
|
||||
#include "gui/CGUI.h"
|
||||
#include "gui/GUI.h"
|
||||
#include "lib/utf8.h"
|
||||
#include "ps/CLogger.h"
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include "CGUIText.h"
|
||||
|
||||
#include "gui/CGUI.h"
|
||||
#include "gui/CGUIString.h"
|
||||
#include "gui/IGUIObject.h"
|
||||
#include "graphics/FontMetrics.h"
|
||||
|
@ -19,8 +19,8 @@
|
||||
|
||||
#include "CImage.h"
|
||||
|
||||
#include "GUI.h"
|
||||
|
||||
#include "gui/CGUI.h"
|
||||
#include "gui/GUI.h"
|
||||
#include "lib/ogl.h"
|
||||
|
||||
CImage::CImage(CGUI& pGUI)
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include "CInput.h"
|
||||
|
||||
#include "gui/CGUI.h"
|
||||
#include "gui/CGUIScrollBarVertical.h"
|
||||
#include "gui/GUI.h"
|
||||
#include "graphics/FontMetrics.h"
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include "CList.h"
|
||||
|
||||
#include "gui/CGUI.h"
|
||||
#include "gui/CGUIColor.h"
|
||||
#include "gui/CGUIScrollBarVertical.h"
|
||||
#include "lib/external_libraries/libsdl.h"
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include "COList.h"
|
||||
|
||||
#include "gui/CGUI.h"
|
||||
#include "gui/CGUIColor.h"
|
||||
#include "i18n/L10n.h"
|
||||
#include "ps/CLogger.h"
|
||||
|
@ -17,9 +17,10 @@
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "GUI.h"
|
||||
#include "CProgressBar.h"
|
||||
|
||||
#include "gui/CGUI.h"
|
||||
#include "gui/GUI.h"
|
||||
#include "lib/ogl.h"
|
||||
|
||||
CProgressBar::CProgressBar(CGUI& pGUI)
|
||||
|
@ -16,8 +16,11 @@
|
||||
*/
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "CSlider.h"
|
||||
#include "GUI.h"
|
||||
|
||||
#include "gui/CGUI.h"
|
||||
#include "gui/GUI.h"
|
||||
#include "lib/ogl.h"
|
||||
|
||||
CSlider::CSlider(CGUI& pGUI)
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include "CText.h"
|
||||
|
||||
#include "gui/CGUI.h"
|
||||
#include "gui/CGUIScrollBarVertical.h"
|
||||
#include "gui/GUI.h"
|
||||
#include "lib/ogl.h"
|
||||
|
@ -19,6 +19,8 @@
|
||||
|
||||
#include "GUI.h"
|
||||
|
||||
#include "gui/CGUI.h"
|
||||
|
||||
IGUIButtonBehavior::IGUIButtonBehavior(CGUI& pGUI)
|
||||
: IGUIObject(pGUI), m_Pressed(false)
|
||||
{
|
||||
|
@ -19,6 +19,7 @@
|
||||
|
||||
#include "GUI.h"
|
||||
|
||||
#include "gui/CGUI.h"
|
||||
#include "gui/CGUISetting.h"
|
||||
#include "gui/scripting/JSInterface_GUITypes.h"
|
||||
#include "gui/scripting/JSInterface_IGUIObject.h"
|
||||
@ -516,9 +517,14 @@ bool IGUIObject::IsFocused() const
|
||||
return m_pGUI.GetFocusedObject() == this;
|
||||
}
|
||||
|
||||
bool IGUIObject::IsBaseObject() const
|
||||
{
|
||||
return this == &m_pGUI.GetBaseObject();
|
||||
}
|
||||
|
||||
bool IGUIObject::IsRootObject() const
|
||||
{
|
||||
return m_pParent == m_pGUI.GetBaseObject();
|
||||
return m_pParent == &m_pGUI.GetBaseObject();
|
||||
}
|
||||
|
||||
void IGUIObject::TraceMember(JSTracer* trc)
|
||||
|
@ -25,9 +25,6 @@
|
||||
#ifndef INCLUDED_IGUIOBJECT
|
||||
#define INCLUDED_IGUIOBJECT
|
||||
|
||||
#include "IGUIObject.h"
|
||||
|
||||
#include "gui/CGUI.h"
|
||||
#include "gui/GUIbase.h"
|
||||
#include "gui/scripting/JSInterface_IGUIObject.h"
|
||||
#include "lib/input.h" // just for IN_PASS
|
||||
@ -268,7 +265,7 @@ public:
|
||||
template<typename... Args>
|
||||
void RecurseObject(bool(IGUIObject::*isRestricted)() const, void(IGUIObject::*callbackFunction)(Args... args), Args&&... args)
|
||||
{
|
||||
if (this != m_pGUI.GetBaseObject())
|
||||
if (!IsBaseObject())
|
||||
{
|
||||
if (isRestricted && (this->*isRestricted)())
|
||||
return;
|
||||
@ -445,9 +442,14 @@ private:
|
||||
*/
|
||||
void ChooseMouseOverAndClosest(IGUIObject*& pObject);
|
||||
|
||||
// Is the object a Root object, in philosophy, this means it
|
||||
// has got no parent, and technically, it's got the m_BaseObject
|
||||
// as parent.
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
bool IsRootObject() const;
|
||||
|
||||
static void Trace(JSTracer* trc, void* data)
|
||||
@ -512,21 +514,4 @@ protected:
|
||||
JS::PersistentRootedObject m_JSObject;
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Dummy object used primarily for the root object
|
||||
* or objects of type 'empty'
|
||||
*/
|
||||
class CGUIDummyObject : public IGUIObject
|
||||
{
|
||||
GUI_OBJECT(CGUIDummyObject)
|
||||
|
||||
public:
|
||||
CGUIDummyObject(CGUI& pGUI) : IGUIObject(pGUI) {}
|
||||
|
||||
virtual void Draw() {}
|
||||
// Empty can never be hovered. It is only a category.
|
||||
virtual bool IsMouseOver() const { return false; }
|
||||
};
|
||||
|
||||
#endif // INCLUDED_IGUIOBJECT
|
||||
|
@ -18,6 +18,8 @@
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "GUI.h"
|
||||
|
||||
#include "gui/CGUI.h"
|
||||
#include "maths/MathUtil.h"
|
||||
|
||||
IGUIScrollBar::IGUIScrollBar(CGUI& pGUI)
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "precompiled.h"
|
||||
|
||||
#include "GUI.h"
|
||||
#include "gui/CGUI.h"
|
||||
|
||||
IGUIScrollBarOwner::IGUIScrollBarOwner(CGUI& pGUI)
|
||||
: IGUIObject(pGUI)
|
||||
|
@ -20,6 +20,7 @@
|
||||
#include "IGUITextOwner.h"
|
||||
|
||||
#include "gui/GUI.h"
|
||||
#include "gui/CGUI.h"
|
||||
#include "gui/scripting/JSInterface_IGUITextOwner.h"
|
||||
|
||||
#include <math.h>
|
||||
|
@ -28,6 +28,7 @@
|
||||
#include "graphics/TerrainTextureEntry.h"
|
||||
#include "graphics/TerrainTextureManager.h"
|
||||
#include "graphics/TerritoryTexture.h"
|
||||
#include "gui/CGUI.h"
|
||||
#include "gui/GUI.h"
|
||||
#include "gui/GUIManager.h"
|
||||
#include "gui/GUIMatrix.h"
|
||||
|
@ -35,6 +35,7 @@
|
||||
#include "graphics/MapReader.h"
|
||||
#include "graphics/MaterialManager.h"
|
||||
#include "graphics/TerrainTextureManager.h"
|
||||
#include "gui/CGUI.h"
|
||||
#include "gui/GUI.h"
|
||||
#include "gui/GUIManager.h"
|
||||
#include "i18n/L10n.h"
|
||||
|
@ -26,6 +26,7 @@
|
||||
#include "graphics/GameView.h"
|
||||
#include "gui/GUIManager.h"
|
||||
#include "gui/GUI.h"
|
||||
#include "gui/CGUI.h"
|
||||
#include "lib/external_libraries/libsdl.h"
|
||||
#include "lib/sysdep/cpu.h"
|
||||
#include "maths/MathUtil.h"
|
||||
|
Loading…
Reference in New Issue
Block a user