mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-07-04 05:55:47 -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 "gui/CGUIColor.h"
|
||||||
#include "lib/ogl.h"
|
#include "lib/ogl.h"
|
||||||
|
|
||||||
CButton::CButton()
|
CButton::CButton(CGUI* pGUI)
|
||||||
|
: IGUIObject(pGUI)
|
||||||
{
|
{
|
||||||
AddSetting(GUIST_float, "buffer_zone");
|
AddSetting(GUIST_float, "buffer_zone");
|
||||||
AddSetting(GUIST_CGUIString, "caption");
|
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.
|
* 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
|
||||||
|
|
@ -31,7 +31,7 @@ class CButton : public IGUIButtonBehavior, public IGUITextOwner
|
||||||
GUI_OBJECT(CButton)
|
GUI_OBJECT(CButton)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CButton();
|
CButton(CGUI* pGUI);
|
||||||
virtual ~CButton();
|
virtual ~CButton();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,8 @@
|
||||||
|
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
CChart::CChart()
|
CChart::CChart(CGUI* pGUI)
|
||||||
|
: IGUIObject(pGUI)
|
||||||
{
|
{
|
||||||
AddSetting(GUIST_CGUIColor, "axis_color");
|
AddSetting(GUIST_CGUIColor, "axis_color");
|
||||||
AddSetting(GUIST_float, "axis_width");
|
AddSetting(GUIST_float, "axis_width");
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ class CChart : public IGUITextOwner
|
||||||
GUI_OBJECT(CChart)
|
GUI_OBJECT(CChart)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CChart();
|
CChart(CGUI* pGUI);
|
||||||
virtual ~CChart();
|
virtual ~CChart();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,8 @@
|
||||||
* TODO: Since there is no call to DrawText, the checkbox won't render any text.
|
* 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.
|
* 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_float, "buffer_zone");
|
||||||
AddSetting(GUIST_CGUIString, "caption");
|
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.
|
* 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
|
||||||
|
|
@ -32,7 +32,7 @@ class CCheckBox : public IGUIButtonBehavior, public IGUITextOwner
|
||||||
GUI_OBJECT(CCheckBox)
|
GUI_OBJECT(CCheckBox)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CCheckBox();
|
CCheckBox(CGUI* pGUI);
|
||||||
virtual ~CCheckBox();
|
virtual ~CCheckBox();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,9 @@
|
||||||
#include "ps/CLogger.h"
|
#include "ps/CLogger.h"
|
||||||
#include "soundmanager/ISoundManager.h"
|
#include "soundmanager/ISoundManager.h"
|
||||||
|
|
||||||
CDropDown::CDropDown()
|
CDropDown::CDropDown(CGUI* pGUI)
|
||||||
: m_Open(false), m_HideScrollBar(false), m_ElementHighlight(-1)
|
: CList(pGUI), IGUIObject(pGUI),
|
||||||
|
m_Open(false), m_HideScrollBar(false), m_ElementHighlight(-1)
|
||||||
{
|
{
|
||||||
AddSetting(GUIST_float, "button_width");
|
AddSetting(GUIST_float, "button_width");
|
||||||
AddSetting(GUIST_float, "dropdown_size");
|
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.
|
* 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
|
||||||
|
|
@ -50,7 +50,7 @@ class CDropDown : public CList
|
||||||
GUI_OBJECT(CDropDown)
|
GUI_OBJECT(CDropDown)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CDropDown();
|
CDropDown(CGUI* pGUI);
|
||||||
virtual ~CDropDown();
|
virtual ~CDropDown();
|
||||||
|
|
||||||
// virtual void ResetStates() { IGUIButtonBehavior::ResetStates(); }
|
// virtual void ResetStates() { IGUIButtonBehavior::ResetStates(); }
|
||||||
|
|
|
||||||
|
|
@ -290,8 +290,8 @@ CGUI::CGUI(const shared_ptr<ScriptRuntime>& runtime)
|
||||||
|
|
||||||
GuiScriptingInit(*m_ScriptInterface);
|
GuiScriptingInit(*m_ScriptInterface);
|
||||||
m_ScriptInterface->LoadGlobalScripts();
|
m_ScriptInterface->LoadGlobalScripts();
|
||||||
m_BaseObject = new CGUIDummyObject;
|
|
||||||
m_BaseObject->SetGUI(this);
|
m_BaseObject = new CGUIDummyObject(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
CGUI::~CGUI()
|
CGUI::~CGUI()
|
||||||
|
|
@ -305,12 +305,10 @@ CGUI::~CGUI()
|
||||||
IGUIObject* CGUI::ConstructObject(const CStr& str)
|
IGUIObject* CGUI::ConstructObject(const CStr& str)
|
||||||
{
|
{
|
||||||
if (m_ObjectTypes.count(str) > 0)
|
if (m_ObjectTypes.count(str) > 0)
|
||||||
return (*m_ObjectTypes[str])();
|
return (*m_ObjectTypes[str])(this);
|
||||||
else
|
|
||||||
{
|
// Error reporting will be handled with the nullptr return.
|
||||||
// Error reporting will be handled with the NULL return.
|
return nullptr;
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGUI::Initialize()
|
void CGUI::Initialize()
|
||||||
|
|
@ -401,9 +399,6 @@ void CGUI::AddObject(IGUIObject* pObject)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// Add CGUI pointer
|
|
||||||
GUI<CGUI*>::RecurseObject(0, pObject, &IGUIObject::SetGUI, this);
|
|
||||||
|
|
||||||
m_BaseObject->AddChild(pObject);
|
m_BaseObject->AddChild(pObject);
|
||||||
|
|
||||||
// Cache tree
|
// Cache tree
|
||||||
|
|
@ -1148,8 +1143,6 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec
|
||||||
|
|
||||||
CStr action = CStr(child.GetAttributes().GetNamedItem(attr_on));
|
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);
|
object->RegisterScriptHandler(action.LowerCase(), code, this);
|
||||||
}
|
}
|
||||||
else if (element_name == elmt_repeat)
|
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)
|
void CGUI::Xeromyces_ReadTooltip(XMBElement Element, CXeromyces* pFile)
|
||||||
{
|
{
|
||||||
IGUIObject* object = new CTooltip;
|
IGUIObject* object = new CTooltip(this);
|
||||||
|
|
||||||
for (XMBAttribute attr : Element.GetAttributes())
|
for (XMBAttribute attr : Element.GetAttributes())
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -71,7 +71,7 @@ class CGUI
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Private typedefs
|
// Private typedefs
|
||||||
typedef IGUIObject *(*ConstructObjectFunction)();
|
using ConstructObjectFunction = IGUIObject* (*)(CGUI*);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CGUI(const shared_ptr<ScriptRuntime>& runtime);
|
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.
|
* 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
|
||||||
|
|
@ -24,7 +24,8 @@
|
||||||
#include "ps/CLogger.h"
|
#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.
|
* 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
|
||||||
|
|
@ -48,7 +48,7 @@ A GUI ScrollBar
|
||||||
class CGUIScrollBarVertical : public IGUIScrollBar
|
class CGUIScrollBarVertical : public IGUIScrollBar
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CGUIScrollBarVertical();
|
CGUIScrollBarVertical(CGUI* pGUI);
|
||||||
virtual ~CGUIScrollBarVertical();
|
virtual ~CGUIScrollBarVertical();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (C) 2015 Wildfire Games.
|
/* Copyright (C) 2019 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
|
||||||
|
|
@ -23,7 +23,8 @@
|
||||||
|
|
||||||
#include "lib/ogl.h"
|
#include "lib/ogl.h"
|
||||||
|
|
||||||
CImage::CImage()
|
CImage::CImage(CGUI* pGUI)
|
||||||
|
: IGUIObject(pGUI)
|
||||||
{
|
{
|
||||||
AddSetting(GUIST_CGUISpriteInstance, "sprite");
|
AddSetting(GUIST_CGUISpriteInstance, "sprite");
|
||||||
AddSetting(GUIST_int, "cell_id");
|
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.
|
* 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
|
||||||
|
|
@ -37,7 +37,7 @@ class CImage : public IGUIObject
|
||||||
GUI_OBJECT(CImage)
|
GUI_OBJECT(CImage)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CImage();
|
CImage(CGUI* pGUI);
|
||||||
virtual ~CImage();
|
virtual ~CImage();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
||||||
|
|
@ -39,8 +39,9 @@
|
||||||
|
|
||||||
extern int g_yres;
|
extern int g_yres;
|
||||||
|
|
||||||
CInput::CInput()
|
CInput::CInput(CGUI* pGUI)
|
||||||
: m_iBufferPos(-1), m_iBufferPos_Tail(-1), m_SelectingText(false), m_HorizontalScroll(0.f),
|
: 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_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)
|
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);
|
CFG_GET_VAL("gui.cursorblinkrate", m_CursorBlinkRate);
|
||||||
|
|
||||||
CGUIScrollBarVertical* bar = new CGUIScrollBarVertical();
|
CGUIScrollBarVertical* bar = new CGUIScrollBarVertical(pGUI);
|
||||||
bar->SetRightAligned(true);
|
bar->SetRightAligned(true);
|
||||||
AddScrollBar(bar);
|
AddScrollBar(bar);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (C) 2017 Wildfire Games.
|
/* Copyright (C) 2019 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
|
||||||
|
|
@ -38,7 +38,7 @@ protected: // forwards
|
||||||
struct SRow;
|
struct SRow;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CInput();
|
CInput(CGUI* pGUI);
|
||||||
virtual ~CInput();
|
virtual ~CInput();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -27,11 +27,11 @@
|
||||||
#include "soundmanager/ISoundManager.h"
|
#include "soundmanager/ISoundManager.h"
|
||||||
|
|
||||||
|
|
||||||
CList::CList()
|
CList::CList(CGUI* pGUI)
|
||||||
: m_Modified(false), m_PrevSelectedItem(-1), m_LastItemClickTime(0)
|
: IGUIObject(pGUI), IGUIScrollBarOwner(pGUI),
|
||||||
|
m_Modified(false), m_PrevSelectedItem(-1), m_LastItemClickTime(0)
|
||||||
{
|
{
|
||||||
// Add sprite_disabled! TODO
|
// Add sprite_disabled! TODO
|
||||||
|
|
||||||
AddSetting(GUIST_float, "buffer_zone");
|
AddSetting(GUIST_float, "buffer_zone");
|
||||||
AddSetting(GUIST_CStrW, "font");
|
AddSetting(GUIST_CStrW, "font");
|
||||||
AddSetting(GUIST_bool, "scrollbar");
|
AddSetting(GUIST_bool, "scrollbar");
|
||||||
|
|
@ -60,7 +60,7 @@ CList::CList()
|
||||||
GUI<bool>::SetSetting(this, "auto_scroll", false);
|
GUI<bool>::SetSetting(this, "auto_scroll", false);
|
||||||
|
|
||||||
// Add scroll-bar
|
// Add scroll-bar
|
||||||
CGUIScrollBarVertical* bar = new CGUIScrollBarVertical();
|
CGUIScrollBarVertical* bar = new CGUIScrollBarVertical(pGUI);
|
||||||
bar->SetRightAligned(true);
|
bar->SetRightAligned(true);
|
||||||
AddScrollBar(bar);
|
AddScrollBar(bar);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (C) 2017 Wildfire Games.
|
/* Copyright (C) 2019 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
|
||||||
|
|
@ -34,7 +34,7 @@ class CList : public IGUIScrollBarOwner, public IGUITextOwner
|
||||||
GUI_OBJECT(CList)
|
GUI_OBJECT(CList)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CList();
|
CList(CGUI* pGUI);
|
||||||
virtual ~CList();
|
virtual ~CList();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,8 @@
|
||||||
const float SORT_SPRITE_DIM = 16.0f;
|
const float SORT_SPRITE_DIM = 16.0f;
|
||||||
const CPos COLUMN_SHIFT = CPos(0, 4);
|
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_CGUISpriteInstance, "sprite_heading");
|
||||||
AddSetting(GUIST_bool, "sortable"); // The actual sorting is done in JS for more versatility
|
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)
|
GUI_OBJECT(COList)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
COList();
|
COList(CGUI* pGUI);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void SetupText();
|
void SetupText();
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (C) 2015 Wildfire Games.
|
/* Copyright (C) 2019 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
|
||||||
|
|
@ -22,7 +22,8 @@
|
||||||
|
|
||||||
#include "lib/ogl.h"
|
#include "lib/ogl.h"
|
||||||
|
|
||||||
CProgressBar::CProgressBar()
|
CProgressBar::CProgressBar(CGUI* pGUI)
|
||||||
|
: IGUIObject(pGUI)
|
||||||
{
|
{
|
||||||
AddSetting(GUIST_CGUISpriteInstance, "sprite_background");
|
AddSetting(GUIST_CGUISpriteInstance, "sprite_background");
|
||||||
AddSetting(GUIST_CGUISpriteInstance, "sprite_bar");
|
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.
|
* 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
|
||||||
|
|
@ -30,7 +30,7 @@ class CProgressBar : public IGUIObject
|
||||||
GUI_OBJECT(CProgressBar)
|
GUI_OBJECT(CProgressBar)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CProgressBar();
|
CProgressBar(CGUI* pGUI);
|
||||||
virtual ~CProgressBar();
|
virtual ~CProgressBar();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (C) 2015 Wildfire Games.
|
/* Copyright (C) 2019 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
|
||||||
|
|
@ -21,6 +21,11 @@
|
||||||
|
|
||||||
#include "GUI.h"
|
#include "GUI.h"
|
||||||
|
|
||||||
|
CRadioButton::CRadioButton(CGUI* pGUI)
|
||||||
|
: CCheckBox(pGUI), IGUIObject(pGUI)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void CRadioButton::HandleMessage(SGUIMessage& Message)
|
void CRadioButton::HandleMessage(SGUIMessage& Message)
|
||||||
{
|
{
|
||||||
// Important
|
// Important
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
/* Copyright (C) 2015 Wildfire Games.
|
/* Copyright (C) 2019 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
|
||||||
|
|
@ -32,6 +32,8 @@ class CRadioButton : public CCheckBox
|
||||||
GUI_OBJECT(CRadioButton)
|
GUI_OBJECT(CRadioButton)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
CRadioButton(CGUI* pGUI);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see IGUIObject#HandleMessage()
|
* @see IGUIObject#HandleMessage()
|
||||||
*/
|
*/
|
||||||
|
|
|
||||||
|
|
@ -22,8 +22,8 @@
|
||||||
#include "ps/CLogger.h"
|
#include "ps/CLogger.h"
|
||||||
|
|
||||||
|
|
||||||
CSlider::CSlider()
|
CSlider::CSlider(CGUI* pGUI)
|
||||||
: m_IsPressed(false), m_ButtonSide(0)
|
: IGUIObject(pGUI), m_IsPressed(false), m_ButtonSide(0)
|
||||||
{
|
{
|
||||||
AddSetting(GUIST_float, "value");
|
AddSetting(GUIST_float, "value");
|
||||||
AddSetting(GUIST_float, "min_value");
|
AddSetting(GUIST_float, "min_value");
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ class CSlider : public IGUIObject
|
||||||
GUI_OBJECT(CSlider)
|
GUI_OBJECT(CSlider)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CSlider();
|
CSlider(CGUI* pGUI);
|
||||||
virtual ~CSlider();
|
virtual ~CSlider();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,8 @@
|
||||||
#include "gui/GUI.h"
|
#include "gui/GUI.h"
|
||||||
#include "lib/ogl.h"
|
#include "lib/ogl.h"
|
||||||
|
|
||||||
CText::CText()
|
CText::CText(CGUI* pGUI)
|
||||||
|
: IGUIObject(pGUI), IGUIScrollBarOwner(pGUI)
|
||||||
{
|
{
|
||||||
AddSetting(GUIST_float, "buffer_zone");
|
AddSetting(GUIST_float, "buffer_zone");
|
||||||
AddSetting(GUIST_CGUIString, "caption");
|
AddSetting(GUIST_CGUIString, "caption");
|
||||||
|
|
@ -51,7 +52,7 @@ CText::CText()
|
||||||
GUI<bool>::SetSetting(this, "clip", true);
|
GUI<bool>::SetSetting(this, "clip", true);
|
||||||
|
|
||||||
// Add scroll-bar
|
// Add scroll-bar
|
||||||
CGUIScrollBarVertical* bar = new CGUIScrollBarVertical();
|
CGUIScrollBarVertical* bar = new CGUIScrollBarVertical(pGUI);
|
||||||
bar->SetRightAligned(true);
|
bar->SetRightAligned(true);
|
||||||
AddScrollBar(bar);
|
AddScrollBar(bar);
|
||||||
|
|
||||||
|
|
@ -65,11 +66,9 @@ CText::~CText()
|
||||||
|
|
||||||
void CText::SetupText()
|
void CText::SetupText()
|
||||||
{
|
{
|
||||||
if (!GetGUI())
|
if (m_GeneratedTexts.empty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ENSURE(m_GeneratedTexts.size()>=1);
|
|
||||||
|
|
||||||
CStrW font;
|
CStrW font;
|
||||||
if (GUI<CStrW>::GetSetting(this, "font", font) != PSRETURN_OK || font.empty())
|
if (GUI<CStrW>::GetSetting(this, "font", font) != PSRETURN_OK || font.empty())
|
||||||
// Use the default if none is specified
|
// 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.
|
* 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
|
||||||
|
|
@ -30,7 +30,7 @@ class CText : public IGUIScrollBarOwner, public IGUITextOwner
|
||||||
GUI_OBJECT(CText)
|
GUI_OBJECT(CText)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CText();
|
CText(CGUI* pGUI);
|
||||||
virtual ~CText();
|
virtual ~CText();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,8 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
CTooltip::CTooltip()
|
CTooltip::CTooltip(CGUI* pGUI)
|
||||||
|
: IGUIObject(pGUI)
|
||||||
{
|
{
|
||||||
// If the tooltip is an object by itself:
|
// If the tooltip is an object by itself:
|
||||||
AddSetting(GUIST_float, "buffer_zone");
|
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.
|
* 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
|
||||||
|
|
@ -28,7 +28,7 @@ class CTooltip : public IGUITextOwner
|
||||||
GUI_OBJECT(CTooltip)
|
GUI_OBJECT(CTooltip)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CTooltip();
|
CTooltip(CGUI* pGUI);
|
||||||
virtual ~CTooltip();
|
virtual ~CTooltip();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
||||||
|
|
@ -49,7 +49,8 @@ class IGUIObject;
|
||||||
// Setup an object's ConstructObject function
|
// Setup an object's ConstructObject function
|
||||||
#define GUI_OBJECT(obj) \
|
#define GUI_OBJECT(obj) \
|
||||||
public: \
|
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()
|
IGUIObject::IGUIObject(CGUI* pGUI)
|
||||||
: m_pGUI(NULL), m_pParent(NULL), m_MouseHovering(false), m_LastClickTime()
|
: m_pGUI(pGUI), m_pParent(NULL), m_MouseHovering(false), m_LastClickTime()
|
||||||
{
|
{
|
||||||
AddSetting(GUIST_bool, "enabled");
|
AddSetting(GUIST_bool, "enabled");
|
||||||
AddSetting(GUIST_bool, "hidden");
|
AddSetting(GUIST_bool, "hidden");
|
||||||
|
|
@ -81,19 +81,13 @@ IGUIObject::~IGUIObject()
|
||||||
debug_warn(L"Invalid setting type");
|
debug_warn(L"Invalid setting type");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_pGUI)
|
if (!m_ScriptHandlers.empty())
|
||||||
JS_RemoveExtraGCRootsTracer(m_pGUI->GetScriptInterface()->GetJSRuntime(), Trace, this);
|
JS_RemoveExtraGCRootsTracer(m_pGUI->GetScriptInterface()->GetJSRuntime(), Trace, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-------------------------------------------------------------------
|
//-------------------------------------------------------------------
|
||||||
// Functions
|
// 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)
|
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)
|
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!");
|
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);
|
m_ScriptHandlers[Action] = JS::Heap<JSObject*>(Function);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -564,6 +560,8 @@ bool IGUIObject::IsRootObject() const
|
||||||
|
|
||||||
void IGUIObject::TraceMember(JSTracer* trc)
|
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)
|
for (std::pair<const CStr, JS::Heap<JSObject*>>& handler : m_ScriptHandlers)
|
||||||
JS_CallObjectTracer(trc, &handler.second, "IGUIObject::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);
|
friend bool JSI_IGUIObject::getTextSize(JSContext* cx, uint argc, JS::Value* vp);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IGUIObject();
|
IGUIObject(CGUI* pGUI);
|
||||||
virtual ~IGUIObject();
|
virtual ~IGUIObject();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -332,8 +332,6 @@ protected:
|
||||||
*/
|
*/
|
||||||
virtual float GetBufferedZ() const;
|
virtual float GetBufferedZ() const;
|
||||||
|
|
||||||
void SetGUI(CGUI* const& pGUI);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set parent of this object
|
* Set parent of this object
|
||||||
*/
|
*/
|
||||||
|
|
@ -516,7 +514,7 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// An object can't function stand alone
|
// An object can't function stand alone
|
||||||
CGUI *m_pGUI;
|
CGUI* m_pGUI;
|
||||||
|
|
||||||
// Internal storage for registered script handlers.
|
// Internal storage for registered script handlers.
|
||||||
std::map<CStr, JS::Heap<JSObject*> > m_ScriptHandlers;
|
std::map<CStr, JS::Heap<JSObject*> > m_ScriptHandlers;
|
||||||
|
|
@ -535,6 +533,7 @@ class CGUIDummyObject : public IGUIObject
|
||||||
GUI_OBJECT(CGUIDummyObject)
|
GUI_OBJECT(CGUIDummyObject)
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
CGUIDummyObject(CGUI* pGUI) : IGUIObject(pGUI) {}
|
||||||
|
|
||||||
virtual void Draw() {}
|
virtual void Draw() {}
|
||||||
// Empty can never be hovered. It is only a category.
|
// 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.
|
* 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
|
||||||
|
|
@ -20,7 +20,9 @@
|
||||||
#include "GUI.h"
|
#include "GUI.h"
|
||||||
#include "maths/MathUtil.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_X(300.f), m_Y(300.f),
|
||||||
m_ScrollRange(1.f), m_ScrollSpace(0.f), // MaxPos: not 0, due to division.
|
m_ScrollRange(1.f), m_ScrollSpace(0.f), // MaxPos: not 0, due to division.
|
||||||
m_Length(200.f), m_Width(20.f),
|
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.
|
* 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
|
||||||
|
|
@ -155,7 +155,7 @@ struct SGUIScrollBarStyle
|
||||||
class IGUIScrollBar
|
class IGUIScrollBar
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
IGUIScrollBar();
|
IGUIScrollBar(CGUI* m_pGUI);
|
||||||
virtual ~IGUIScrollBar();
|
virtual ~IGUIScrollBar();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
@ -246,12 +246,6 @@ public:
|
||||||
*/
|
*/
|
||||||
CGUI* GetGUI() const;
|
CGUI* GetGUI() const;
|
||||||
|
|
||||||
/**
|
|
||||||
* Set GUI pointer
|
|
||||||
* @param pGUI pointer to CGUI object.
|
|
||||||
*/
|
|
||||||
void SetGUI(CGUI* pGUI) { m_pGUI = pGUI; }
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set Width
|
* Set Width
|
||||||
* @param width Width
|
* @param width Width
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,8 @@
|
||||||
|
|
||||||
#include "GUI.h"
|
#include "GUI.h"
|
||||||
|
|
||||||
IGUIScrollBarOwner::IGUIScrollBarOwner()
|
IGUIScrollBarOwner::IGUIScrollBarOwner(CGUI* pGUI)
|
||||||
|
: IGUIObject(pGUI)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -40,7 +41,6 @@ void IGUIScrollBarOwner::ResetStates()
|
||||||
void IGUIScrollBarOwner::AddScrollBar(IGUIScrollBar* scrollbar)
|
void IGUIScrollBarOwner::AddScrollBar(IGUIScrollBar* scrollbar)
|
||||||
{
|
{
|
||||||
scrollbar->SetHostObject(this);
|
scrollbar->SetHostObject(this);
|
||||||
scrollbar->SetGUI(GetGUI());
|
|
||||||
m_ScrollBars.push_back(scrollbar);
|
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.
|
* 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
|
||||||
|
|
@ -35,7 +35,7 @@ class IGUIScrollBarOwner : virtual public IGUIObject
|
||||||
friend class IGUIScrollBar;
|
friend class IGUIScrollBar;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
IGUIScrollBarOwner();
|
IGUIScrollBarOwner(CGUI* pGUI);
|
||||||
virtual ~IGUIScrollBarOwner();
|
virtual ~IGUIScrollBarOwner();
|
||||||
|
|
||||||
virtual void Draw();
|
virtual void Draw();
|
||||||
|
|
|
||||||
|
|
@ -62,7 +62,8 @@ static unsigned int ScaleColor(unsigned int color, float x)
|
||||||
return (0xff000000 | b | g<<8 | r<<16);
|
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_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_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)
|
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.
|
* 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
|
||||||
|
|
@ -29,7 +29,7 @@ class CMiniMap : public IGUIObject
|
||||||
{
|
{
|
||||||
GUI_OBJECT(CMiniMap)
|
GUI_OBJECT(CMiniMap)
|
||||||
public:
|
public:
|
||||||
CMiniMap();
|
CMiniMap(CGUI* pGUI);
|
||||||
virtual ~CMiniMap();
|
virtual ~CMiniMap();
|
||||||
protected:
|
protected:
|
||||||
virtual void Draw();
|
virtual void Draw();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue