mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 05:13:58 -07:00
Pass the GUI page pointer CGUI* to the IGUIObject and derived classes upon construction, instead of on stray cases.
Call JS_AddExtraGCRootsTracer and JS_RemoveExtraGCRootsTracer depending
on JS::Heap use instead of on CGUI page link setup.
GUIObjects should be able to access the GUI page independent of the
scripting (for example to obtain PredefinedColors, refs D2108).
Refs: D2108, c02a7e1a7b
Comments By: wraitii
This was SVN commit r22587.
This commit is contained in:
parent
eab4f9fdde
commit
2c47fbd66a
39 changed files with 104 additions and 100 deletions
|
|
@ -22,7 +22,8 @@
|
|||
#include "gui/CGUIColor.h"
|
||||
#include "lib/ogl.h"
|
||||
|
||||
CButton::CButton()
|
||||
CButton::CButton(CGUI* pGUI)
|
||||
: IGUIObject(pGUI)
|
||||
{
|
||||
AddSetting(GUIST_float, "buffer_zone");
|
||||
AddSetting(GUIST_CGUIString, "caption");
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 2015 Wildfire Games.
|
||||
/* 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
|
||||
|
|
@ -31,7 +31,7 @@ class CButton : public IGUIButtonBehavior, public IGUITextOwner
|
|||
GUI_OBJECT(CButton)
|
||||
|
||||
public:
|
||||
CButton();
|
||||
CButton(CGUI* pGUI);
|
||||
virtual ~CButton();
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -29,7 +29,8 @@
|
|||
|
||||
#include <cmath>
|
||||
|
||||
CChart::CChart()
|
||||
CChart::CChart(CGUI* pGUI)
|
||||
: IGUIObject(pGUI)
|
||||
{
|
||||
AddSetting(GUIST_CGUIColor, "axis_color");
|
||||
AddSetting(GUIST_float, "axis_width");
|
||||
|
|
|
|||
|
|
@ -41,7 +41,7 @@ class CChart : public IGUITextOwner
|
|||
GUI_OBJECT(CChart)
|
||||
|
||||
public:
|
||||
CChart();
|
||||
CChart(CGUI* pGUI);
|
||||
virtual ~CChart();
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -28,7 +28,8 @@
|
|||
* TODO: Since there is no call to DrawText, the checkbox won't render any text.
|
||||
* Thus the font, caption, textcolor and other settings have no effect.
|
||||
*/
|
||||
CCheckBox::CCheckBox()
|
||||
CCheckBox::CCheckBox(CGUI* pGUI)
|
||||
: IGUIObject(pGUI)
|
||||
{
|
||||
AddSetting(GUIST_float, "buffer_zone");
|
||||
AddSetting(GUIST_CGUIString, "caption");
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 2015 Wildfire Games.
|
||||
/* 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
|
||||
|
|
@ -32,7 +32,7 @@ class CCheckBox : public IGUIButtonBehavior, public IGUITextOwner
|
|||
GUI_OBJECT(CCheckBox)
|
||||
|
||||
public:
|
||||
CCheckBox();
|
||||
CCheckBox(CGUI* pGUI);
|
||||
virtual ~CCheckBox();
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -26,8 +26,9 @@
|
|||
#include "ps/CLogger.h"
|
||||
#include "soundmanager/ISoundManager.h"
|
||||
|
||||
CDropDown::CDropDown()
|
||||
: m_Open(false), m_HideScrollBar(false), m_ElementHighlight(-1)
|
||||
CDropDown::CDropDown(CGUI* pGUI)
|
||||
: CList(pGUI), IGUIObject(pGUI),
|
||||
m_Open(false), m_HideScrollBar(false), m_ElementHighlight(-1)
|
||||
{
|
||||
AddSetting(GUIST_float, "button_width");
|
||||
AddSetting(GUIST_float, "dropdown_size");
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 2017 Wildfire Games.
|
||||
/* 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
|
||||
|
|
@ -50,7 +50,7 @@ class CDropDown : public CList
|
|||
GUI_OBJECT(CDropDown)
|
||||
|
||||
public:
|
||||
CDropDown();
|
||||
CDropDown(CGUI* pGUI);
|
||||
virtual ~CDropDown();
|
||||
|
||||
// virtual void ResetStates() { IGUIButtonBehavior::ResetStates(); }
|
||||
|
|
|
|||
|
|
@ -290,8 +290,8 @@ CGUI::CGUI(const shared_ptr<ScriptRuntime>& runtime)
|
|||
|
||||
GuiScriptingInit(*m_ScriptInterface);
|
||||
m_ScriptInterface->LoadGlobalScripts();
|
||||
m_BaseObject = new CGUIDummyObject;
|
||||
m_BaseObject->SetGUI(this);
|
||||
|
||||
m_BaseObject = new CGUIDummyObject(this);
|
||||
}
|
||||
|
||||
CGUI::~CGUI()
|
||||
|
|
@ -305,12 +305,10 @@ CGUI::~CGUI()
|
|||
IGUIObject* CGUI::ConstructObject(const CStr& str)
|
||||
{
|
||||
if (m_ObjectTypes.count(str) > 0)
|
||||
return (*m_ObjectTypes[str])();
|
||||
else
|
||||
{
|
||||
// Error reporting will be handled with the NULL return.
|
||||
return NULL;
|
||||
}
|
||||
return (*m_ObjectTypes[str])(this);
|
||||
|
||||
// Error reporting will be handled with the nullptr return.
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void CGUI::Initialize()
|
||||
|
|
@ -401,9 +399,6 @@ void CGUI::AddObject(IGUIObject* pObject)
|
|||
{
|
||||
try
|
||||
{
|
||||
// Add CGUI pointer
|
||||
GUI<CGUI*>::RecurseObject(0, pObject, &IGUIObject::SetGUI, this);
|
||||
|
||||
m_BaseObject->AddChild(pObject);
|
||||
|
||||
// Cache tree
|
||||
|
|
@ -1148,8 +1143,6 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec
|
|||
|
||||
CStr action = CStr(child.GetAttributes().GetNamedItem(attr_on));
|
||||
|
||||
// We need to set the GUI this object belongs to because RegisterScriptHandler requires an associated GUI.
|
||||
object->SetGUI(this);
|
||||
object->RegisterScriptHandler(action.LowerCase(), code, this);
|
||||
}
|
||||
else if (element_name == elmt_repeat)
|
||||
|
|
@ -1732,7 +1725,7 @@ void CGUI::Xeromyces_ReadIcon(XMBElement Element, CXeromyces* pFile)
|
|||
|
||||
void CGUI::Xeromyces_ReadTooltip(XMBElement Element, CXeromyces* pFile)
|
||||
{
|
||||
IGUIObject* object = new CTooltip;
|
||||
IGUIObject* object = new CTooltip(this);
|
||||
|
||||
for (XMBAttribute attr : Element.GetAttributes())
|
||||
{
|
||||
|
|
|
|||
|
|
@ -71,7 +71,7 @@ class CGUI
|
|||
|
||||
private:
|
||||
// Private typedefs
|
||||
typedef IGUIObject *(*ConstructObjectFunction)();
|
||||
using ConstructObjectFunction = IGUIObject* (*)(CGUI*);
|
||||
|
||||
public:
|
||||
CGUI(const shared_ptr<ScriptRuntime>& runtime);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 2016 Wildfire Games.
|
||||
/* 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
|
||||
|
|
@ -24,7 +24,8 @@
|
|||
#include "ps/CLogger.h"
|
||||
|
||||
|
||||
CGUIScrollBarVertical::CGUIScrollBarVertical()
|
||||
CGUIScrollBarVertical::CGUIScrollBarVertical(CGUI* pGUI)
|
||||
: IGUIScrollBar(pGUI)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 2015 Wildfire Games.
|
||||
/* 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
|
||||
|
|
@ -48,7 +48,7 @@ A GUI ScrollBar
|
|||
class CGUIScrollBarVertical : public IGUIScrollBar
|
||||
{
|
||||
public:
|
||||
CGUIScrollBarVertical();
|
||||
CGUIScrollBarVertical(CGUI* pGUI);
|
||||
virtual ~CGUIScrollBarVertical();
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 2015 Wildfire Games.
|
||||
/* 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
|
||||
|
|
@ -23,7 +23,8 @@
|
|||
|
||||
#include "lib/ogl.h"
|
||||
|
||||
CImage::CImage()
|
||||
CImage::CImage(CGUI* pGUI)
|
||||
: IGUIObject(pGUI)
|
||||
{
|
||||
AddSetting(GUIST_CGUISpriteInstance, "sprite");
|
||||
AddSetting(GUIST_int, "cell_id");
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 2015 Wildfire Games.
|
||||
/* 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
|
||||
|
|
@ -37,7 +37,7 @@ class CImage : public IGUIObject
|
|||
GUI_OBJECT(CImage)
|
||||
|
||||
public:
|
||||
CImage();
|
||||
CImage(CGUI* pGUI);
|
||||
virtual ~CImage();
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -39,8 +39,9 @@
|
|||
|
||||
extern int g_yres;
|
||||
|
||||
CInput::CInput()
|
||||
: m_iBufferPos(-1), m_iBufferPos_Tail(-1), m_SelectingText(false), m_HorizontalScroll(0.f),
|
||||
CInput::CInput(CGUI* pGUI)
|
||||
: IGUIObject(pGUI), IGUIScrollBarOwner(pGUI),
|
||||
m_iBufferPos(-1), m_iBufferPos_Tail(-1), m_SelectingText(false), m_HorizontalScroll(0.f),
|
||||
m_PrevTime(0.0), m_CursorVisState(true), m_CursorBlinkRate(0.5), m_ComposingText(false),
|
||||
m_iComposedLength(0), m_iComposedPos(0), m_iInsertPos(0), m_Readonly(false)
|
||||
{
|
||||
|
|
@ -65,7 +66,7 @@ CInput::CInput()
|
|||
|
||||
CFG_GET_VAL("gui.cursorblinkrate", m_CursorBlinkRate);
|
||||
|
||||
CGUIScrollBarVertical* bar = new CGUIScrollBarVertical();
|
||||
CGUIScrollBarVertical* bar = new CGUIScrollBarVertical(pGUI);
|
||||
bar->SetRightAligned(true);
|
||||
AddScrollBar(bar);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 2017 Wildfire Games.
|
||||
/* 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
|
||||
|
|
@ -38,7 +38,7 @@ protected: // forwards
|
|||
struct SRow;
|
||||
|
||||
public:
|
||||
CInput();
|
||||
CInput(CGUI* pGUI);
|
||||
virtual ~CInput();
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -27,11 +27,11 @@
|
|||
#include "soundmanager/ISoundManager.h"
|
||||
|
||||
|
||||
CList::CList()
|
||||
: m_Modified(false), m_PrevSelectedItem(-1), m_LastItemClickTime(0)
|
||||
CList::CList(CGUI* pGUI)
|
||||
: IGUIObject(pGUI), IGUIScrollBarOwner(pGUI),
|
||||
m_Modified(false), m_PrevSelectedItem(-1), m_LastItemClickTime(0)
|
||||
{
|
||||
// Add sprite_disabled! TODO
|
||||
|
||||
AddSetting(GUIST_float, "buffer_zone");
|
||||
AddSetting(GUIST_CStrW, "font");
|
||||
AddSetting(GUIST_bool, "scrollbar");
|
||||
|
|
@ -60,7 +60,7 @@ CList::CList()
|
|||
GUI<bool>::SetSetting(this, "auto_scroll", false);
|
||||
|
||||
// Add scroll-bar
|
||||
CGUIScrollBarVertical* bar = new CGUIScrollBarVertical();
|
||||
CGUIScrollBarVertical* bar = new CGUIScrollBarVertical(pGUI);
|
||||
bar->SetRightAligned(true);
|
||||
AddScrollBar(bar);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 2017 Wildfire Games.
|
||||
/* 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
|
||||
|
|
@ -34,7 +34,7 @@ class CList : public IGUIScrollBarOwner, public IGUITextOwner
|
|||
GUI_OBJECT(CList)
|
||||
|
||||
public:
|
||||
CList();
|
||||
CList(CGUI* pGUI);
|
||||
virtual ~CList();
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -27,7 +27,8 @@
|
|||
const float SORT_SPRITE_DIM = 16.0f;
|
||||
const CPos COLUMN_SHIFT = CPos(0, 4);
|
||||
|
||||
COList::COList() : CList()
|
||||
COList::COList(CGUI* pGUI)
|
||||
: CList(pGUI), IGUIObject(pGUI)
|
||||
{
|
||||
AddSetting(GUIST_CGUISpriteInstance, "sprite_heading");
|
||||
AddSetting(GUIST_bool, "sortable"); // The actual sorting is done in JS for more versatility
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ class COList : public CList
|
|||
GUI_OBJECT(COList)
|
||||
|
||||
public:
|
||||
COList();
|
||||
COList(CGUI* pGUI);
|
||||
|
||||
protected:
|
||||
void SetupText();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 2015 Wildfire Games.
|
||||
/* 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
|
||||
|
|
@ -22,7 +22,8 @@
|
|||
|
||||
#include "lib/ogl.h"
|
||||
|
||||
CProgressBar::CProgressBar()
|
||||
CProgressBar::CProgressBar(CGUI* pGUI)
|
||||
: IGUIObject(pGUI)
|
||||
{
|
||||
AddSetting(GUIST_CGUISpriteInstance, "sprite_background");
|
||||
AddSetting(GUIST_CGUISpriteInstance, "sprite_bar");
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 2015 Wildfire Games.
|
||||
/* 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
|
||||
|
|
@ -30,7 +30,7 @@ class CProgressBar : public IGUIObject
|
|||
GUI_OBJECT(CProgressBar)
|
||||
|
||||
public:
|
||||
CProgressBar();
|
||||
CProgressBar(CGUI* pGUI);
|
||||
virtual ~CProgressBar();
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 2015 Wildfire Games.
|
||||
/* 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
|
||||
|
|
@ -21,6 +21,11 @@
|
|||
|
||||
#include "GUI.h"
|
||||
|
||||
CRadioButton::CRadioButton(CGUI* pGUI)
|
||||
: CCheckBox(pGUI), IGUIObject(pGUI)
|
||||
{
|
||||
}
|
||||
|
||||
void CRadioButton::HandleMessage(SGUIMessage& Message)
|
||||
{
|
||||
// Important
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 2015 Wildfire Games.
|
||||
/* 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
|
||||
|
|
@ -32,6 +32,8 @@ class CRadioButton : public CCheckBox
|
|||
GUI_OBJECT(CRadioButton)
|
||||
|
||||
public:
|
||||
CRadioButton(CGUI* pGUI);
|
||||
|
||||
/**
|
||||
* @see IGUIObject#HandleMessage()
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@
|
|||
#include "ps/CLogger.h"
|
||||
|
||||
|
||||
CSlider::CSlider()
|
||||
: m_IsPressed(false), m_ButtonSide(0)
|
||||
CSlider::CSlider(CGUI* pGUI)
|
||||
: IGUIObject(pGUI), m_IsPressed(false), m_ButtonSide(0)
|
||||
{
|
||||
AddSetting(GUIST_float, "value");
|
||||
AddSetting(GUIST_float, "min_value");
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ class CSlider : public IGUIObject
|
|||
GUI_OBJECT(CSlider)
|
||||
|
||||
public:
|
||||
CSlider();
|
||||
CSlider(CGUI* pGUI);
|
||||
virtual ~CSlider();
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -23,7 +23,8 @@
|
|||
#include "gui/GUI.h"
|
||||
#include "lib/ogl.h"
|
||||
|
||||
CText::CText()
|
||||
CText::CText(CGUI* pGUI)
|
||||
: IGUIObject(pGUI), IGUIScrollBarOwner(pGUI)
|
||||
{
|
||||
AddSetting(GUIST_float, "buffer_zone");
|
||||
AddSetting(GUIST_CGUIString, "caption");
|
||||
|
|
@ -51,7 +52,7 @@ CText::CText()
|
|||
GUI<bool>::SetSetting(this, "clip", true);
|
||||
|
||||
// Add scroll-bar
|
||||
CGUIScrollBarVertical* bar = new CGUIScrollBarVertical();
|
||||
CGUIScrollBarVertical* bar = new CGUIScrollBarVertical(pGUI);
|
||||
bar->SetRightAligned(true);
|
||||
AddScrollBar(bar);
|
||||
|
||||
|
|
@ -65,11 +66,9 @@ CText::~CText()
|
|||
|
||||
void CText::SetupText()
|
||||
{
|
||||
if (!GetGUI())
|
||||
if (m_GeneratedTexts.empty())
|
||||
return;
|
||||
|
||||
ENSURE(m_GeneratedTexts.size()>=1);
|
||||
|
||||
CStrW font;
|
||||
if (GUI<CStrW>::GetSetting(this, "font", font) != PSRETURN_OK || font.empty())
|
||||
// Use the default if none is specified
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 2015 Wildfire Games.
|
||||
/* 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
|
||||
|
|
@ -30,7 +30,7 @@ class CText : public IGUIScrollBarOwner, public IGUITextOwner
|
|||
GUI_OBJECT(CText)
|
||||
|
||||
public:
|
||||
CText();
|
||||
CText(CGUI* pGUI);
|
||||
virtual ~CText();
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -22,7 +22,8 @@
|
|||
|
||||
#include <algorithm>
|
||||
|
||||
CTooltip::CTooltip()
|
||||
CTooltip::CTooltip(CGUI* pGUI)
|
||||
: IGUIObject(pGUI)
|
||||
{
|
||||
// If the tooltip is an object by itself:
|
||||
AddSetting(GUIST_float, "buffer_zone");
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 2015 Wildfire Games.
|
||||
/* 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
|
||||
|
|
@ -28,7 +28,7 @@ class CTooltip : public IGUITextOwner
|
|||
GUI_OBJECT(CTooltip)
|
||||
|
||||
public:
|
||||
CTooltip();
|
||||
CTooltip(CGUI* pGUI);
|
||||
virtual ~CTooltip();
|
||||
|
||||
protected:
|
||||
|
|
|
|||
|
|
@ -49,7 +49,8 @@ class IGUIObject;
|
|||
// Setup an object's ConstructObject function
|
||||
#define GUI_OBJECT(obj) \
|
||||
public: \
|
||||
static IGUIObject* ConstructObject() { return new obj(); }
|
||||
static IGUIObject* ConstructObject(CGUI* pGUI) \
|
||||
{ return new obj(pGUI); }
|
||||
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -46,8 +46,8 @@ void SGUISetting::Init(IGUIObject& pObject, const CStr& Name)
|
|||
};
|
||||
}
|
||||
|
||||
IGUIObject::IGUIObject()
|
||||
: m_pGUI(NULL), m_pParent(NULL), m_MouseHovering(false), m_LastClickTime()
|
||||
IGUIObject::IGUIObject(CGUI* pGUI)
|
||||
: m_pGUI(pGUI), m_pParent(NULL), m_MouseHovering(false), m_LastClickTime()
|
||||
{
|
||||
AddSetting(GUIST_bool, "enabled");
|
||||
AddSetting(GUIST_bool, "hidden");
|
||||
|
|
@ -81,19 +81,13 @@ IGUIObject::~IGUIObject()
|
|||
debug_warn(L"Invalid setting type");
|
||||
}
|
||||
|
||||
if (m_pGUI)
|
||||
if (!m_ScriptHandlers.empty())
|
||||
JS_RemoveExtraGCRootsTracer(m_pGUI->GetScriptInterface()->GetJSRuntime(), Trace, this);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------------------
|
||||
// Functions
|
||||
//-------------------------------------------------------------------
|
||||
void IGUIObject::SetGUI(CGUI* const& pGUI)
|
||||
{
|
||||
if (!m_pGUI)
|
||||
JS_AddExtraGCRootsTracer(pGUI->GetScriptInterface()->GetJSRuntime(), Trace, this);
|
||||
m_pGUI = pGUI;
|
||||
}
|
||||
|
||||
void IGUIObject::AddChild(IGUIObject* pChild)
|
||||
{
|
||||
|
|
@ -452,9 +446,11 @@ void IGUIObject::RegisterScriptHandler(const CStr& Action, const CStr& Code, CGU
|
|||
|
||||
void IGUIObject::SetScriptHandler(const CStr& Action, JS::HandleObject Function)
|
||||
{
|
||||
// m_ScriptHandlers is only rooted after SetGUI() has been called (which sets up the GC trace callbacks),
|
||||
// so we can't safely store objects in it if the GUI hasn't been set yet.
|
||||
ENSURE(m_pGUI && "A GUI must be associated with the GUIObject before adding ScriptHandlers!");
|
||||
|
||||
if (m_ScriptHandlers.empty())
|
||||
JS_AddExtraGCRootsTracer(m_pGUI->GetScriptInterface()->GetJSRuntime(), Trace, this);
|
||||
|
||||
m_ScriptHandlers[Action] = JS::Heap<JSObject*>(Function);
|
||||
}
|
||||
|
||||
|
|
@ -564,6 +560,8 @@ bool IGUIObject::IsRootObject() const
|
|||
|
||||
void IGUIObject::TraceMember(JSTracer* trc)
|
||||
{
|
||||
// Please ensure to adapt the Tracer enabling and disabling in accordance with the GC things traced!
|
||||
|
||||
for (std::pair<const CStr, JS::Heap<JSObject*>>& handler : m_ScriptHandlers)
|
||||
JS_CallObjectTracer(trc, &handler.second, "IGUIObject::m_ScriptHandlers");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ class IGUIObject
|
|||
friend bool JSI_IGUIObject::getTextSize(JSContext* cx, uint argc, JS::Value* vp);
|
||||
|
||||
public:
|
||||
IGUIObject();
|
||||
IGUIObject(CGUI* pGUI);
|
||||
virtual ~IGUIObject();
|
||||
|
||||
/**
|
||||
|
|
@ -332,8 +332,6 @@ protected:
|
|||
*/
|
||||
virtual float GetBufferedZ() const;
|
||||
|
||||
void SetGUI(CGUI* const& pGUI);
|
||||
|
||||
/**
|
||||
* Set parent of this object
|
||||
*/
|
||||
|
|
@ -516,7 +514,7 @@ protected:
|
|||
|
||||
private:
|
||||
// An object can't function stand alone
|
||||
CGUI *m_pGUI;
|
||||
CGUI* m_pGUI;
|
||||
|
||||
// Internal storage for registered script handlers.
|
||||
std::map<CStr, JS::Heap<JSObject*> > m_ScriptHandlers;
|
||||
|
|
@ -535,6 +533,7 @@ 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.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 2015 Wildfire Games.
|
||||
/* 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
|
||||
|
|
@ -20,7 +20,9 @@
|
|||
#include "GUI.h"
|
||||
#include "maths/MathUtil.h"
|
||||
|
||||
IGUIScrollBar::IGUIScrollBar() : m_pStyle(NULL), m_pGUI(NULL),
|
||||
IGUIScrollBar::IGUIScrollBar(CGUI* m_pGUI)
|
||||
: m_pGUI(m_pGUI),
|
||||
m_pStyle(NULL),
|
||||
m_X(300.f), m_Y(300.f),
|
||||
m_ScrollRange(1.f), m_ScrollSpace(0.f), // MaxPos: not 0, due to division.
|
||||
m_Length(200.f), m_Width(20.f),
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 2017 Wildfire Games.
|
||||
/* 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
|
||||
|
|
@ -155,7 +155,7 @@ struct SGUIScrollBarStyle
|
|||
class IGUIScrollBar
|
||||
{
|
||||
public:
|
||||
IGUIScrollBar();
|
||||
IGUIScrollBar(CGUI* m_pGUI);
|
||||
virtual ~IGUIScrollBar();
|
||||
|
||||
public:
|
||||
|
|
@ -246,12 +246,6 @@ public:
|
|||
*/
|
||||
CGUI* GetGUI() const;
|
||||
|
||||
/**
|
||||
* Set GUI pointer
|
||||
* @param pGUI pointer to CGUI object.
|
||||
*/
|
||||
void SetGUI(CGUI* pGUI) { m_pGUI = pGUI; }
|
||||
|
||||
/**
|
||||
* Set Width
|
||||
* @param width Width
|
||||
|
|
|
|||
|
|
@ -19,7 +19,8 @@
|
|||
|
||||
#include "GUI.h"
|
||||
|
||||
IGUIScrollBarOwner::IGUIScrollBarOwner()
|
||||
IGUIScrollBarOwner::IGUIScrollBarOwner(CGUI* pGUI)
|
||||
: IGUIObject(pGUI)
|
||||
{
|
||||
}
|
||||
|
||||
|
|
@ -40,7 +41,6 @@ void IGUIScrollBarOwner::ResetStates()
|
|||
void IGUIScrollBarOwner::AddScrollBar(IGUIScrollBar* scrollbar)
|
||||
{
|
||||
scrollbar->SetHostObject(this);
|
||||
scrollbar->SetGUI(GetGUI());
|
||||
m_ScrollBars.push_back(scrollbar);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 2015 Wildfire Games.
|
||||
/* 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
|
||||
|
|
@ -35,7 +35,7 @@ class IGUIScrollBarOwner : virtual public IGUIObject
|
|||
friend class IGUIScrollBar;
|
||||
|
||||
public:
|
||||
IGUIScrollBarOwner();
|
||||
IGUIScrollBarOwner(CGUI* pGUI);
|
||||
virtual ~IGUIScrollBarOwner();
|
||||
|
||||
virtual void Draw();
|
||||
|
|
|
|||
|
|
@ -62,7 +62,8 @@ static unsigned int ScaleColor(unsigned int color, float x)
|
|||
return (0xff000000 | b | g<<8 | r<<16);
|
||||
}
|
||||
|
||||
CMiniMap::CMiniMap() :
|
||||
CMiniMap::CMiniMap(CGUI* pGUI) :
|
||||
IGUIObject(pGUI),
|
||||
m_TerrainTexture(0), m_TerrainData(0), m_MapSize(0), m_Terrain(0), m_TerrainDirty(true), m_MapScale(1.f),
|
||||
m_EntitiesDrawn(0), m_IndexArray(GL_STATIC_DRAW), m_VertexArray(GL_DYNAMIC_DRAW),
|
||||
m_NextBlinkTime(0.0), m_PingDuration(25.0), m_BlinkState(false), m_WaterHeight(0.0)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/* Copyright (C) 2017 Wildfire Games.
|
||||
/* 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
|
||||
|
|
@ -29,7 +29,7 @@ class CMiniMap : public IGUIObject
|
|||
{
|
||||
GUI_OBJECT(CMiniMap)
|
||||
public:
|
||||
CMiniMap();
|
||||
CMiniMap(CGUI* pGUI);
|
||||
virtual ~CMiniMap();
|
||||
protected:
|
||||
virtual void Draw();
|
||||
|
|
|
|||
Loading…
Reference in a new issue