diff --git a/source/gui/CButton.cpp b/source/gui/CButton.cpp index 50137be283..5f65bba844 100644 --- a/source/gui/CButton.cpp +++ b/source/gui/CButton.cpp @@ -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"); diff --git a/source/gui/CButton.h b/source/gui/CButton.h index 3d66d959a9..55ab574836 100644 --- a/source/gui/CButton.h +++ b/source/gui/CButton.h @@ -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(); /** diff --git a/source/gui/CChart.cpp b/source/gui/CChart.cpp index 7359a823d6..3c9ff30d2c 100644 --- a/source/gui/CChart.cpp +++ b/source/gui/CChart.cpp @@ -29,7 +29,8 @@ #include -CChart::CChart() +CChart::CChart(CGUI* pGUI) + : IGUIObject(pGUI) { AddSetting(GUIST_CGUIColor, "axis_color"); AddSetting(GUIST_float, "axis_width"); diff --git a/source/gui/CChart.h b/source/gui/CChart.h index d9f3ef6bc8..3dbd2ad57c 100644 --- a/source/gui/CChart.h +++ b/source/gui/CChart.h @@ -41,7 +41,7 @@ class CChart : public IGUITextOwner GUI_OBJECT(CChart) public: - CChart(); + CChart(CGUI* pGUI); virtual ~CChart(); protected: diff --git a/source/gui/CCheckBox.cpp b/source/gui/CCheckBox.cpp index 143af3ca19..662b7d5d3c 100644 --- a/source/gui/CCheckBox.cpp +++ b/source/gui/CCheckBox.cpp @@ -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"); diff --git a/source/gui/CCheckBox.h b/source/gui/CCheckBox.h index f924e75801..0766fa3c73 100644 --- a/source/gui/CCheckBox.h +++ b/source/gui/CCheckBox.h @@ -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(); /** diff --git a/source/gui/CDropDown.cpp b/source/gui/CDropDown.cpp index 2027291bd3..c143409874 100644 --- a/source/gui/CDropDown.cpp +++ b/source/gui/CDropDown.cpp @@ -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"); diff --git a/source/gui/CDropDown.h b/source/gui/CDropDown.h index f52492a140..8079db825e 100644 --- a/source/gui/CDropDown.h +++ b/source/gui/CDropDown.h @@ -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(); } diff --git a/source/gui/CGUI.cpp b/source/gui/CGUI.cpp index f18e6ff021..c79bca61b9 100644 --- a/source/gui/CGUI.cpp +++ b/source/gui/CGUI.cpp @@ -290,8 +290,8 @@ CGUI::CGUI(const shared_ptr& 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::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()) { diff --git a/source/gui/CGUI.h b/source/gui/CGUI.h index b6648f65aa..634becd7d1 100644 --- a/source/gui/CGUI.h +++ b/source/gui/CGUI.h @@ -71,7 +71,7 @@ class CGUI private: // Private typedefs - typedef IGUIObject *(*ConstructObjectFunction)(); + using ConstructObjectFunction = IGUIObject* (*)(CGUI*); public: CGUI(const shared_ptr& runtime); diff --git a/source/gui/CGUIScrollBarVertical.cpp b/source/gui/CGUIScrollBarVertical.cpp index f10e684f2a..571fbd0836 100644 --- a/source/gui/CGUIScrollBarVertical.cpp +++ b/source/gui/CGUIScrollBarVertical.cpp @@ -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) { } diff --git a/source/gui/CGUIScrollBarVertical.h b/source/gui/CGUIScrollBarVertical.h index 0c77ea430d..2a4704eca4 100644 --- a/source/gui/CGUIScrollBarVertical.h +++ b/source/gui/CGUIScrollBarVertical.h @@ -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: diff --git a/source/gui/CImage.cpp b/source/gui/CImage.cpp index 1c2ae63bf9..390608a848 100644 --- a/source/gui/CImage.cpp +++ b/source/gui/CImage.cpp @@ -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"); diff --git a/source/gui/CImage.h b/source/gui/CImage.h index 54271492c8..53c4824b69 100644 --- a/source/gui/CImage.h +++ b/source/gui/CImage.h @@ -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: diff --git a/source/gui/CInput.cpp b/source/gui/CInput.cpp index 5c34878079..778e127323 100644 --- a/source/gui/CInput.cpp +++ b/source/gui/CInput.cpp @@ -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); } diff --git a/source/gui/CInput.h b/source/gui/CInput.h index 5b0c367f34..9ebd6c5d7f 100644 --- a/source/gui/CInput.h +++ b/source/gui/CInput.h @@ -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(); /** diff --git a/source/gui/CList.cpp b/source/gui/CList.cpp index d859999393..ba8390910f 100644 --- a/source/gui/CList.cpp +++ b/source/gui/CList.cpp @@ -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::SetSetting(this, "auto_scroll", false); // Add scroll-bar - CGUIScrollBarVertical* bar = new CGUIScrollBarVertical(); + CGUIScrollBarVertical* bar = new CGUIScrollBarVertical(pGUI); bar->SetRightAligned(true); AddScrollBar(bar); } diff --git a/source/gui/CList.h b/source/gui/CList.h index ab046fb020..c420579250 100644 --- a/source/gui/CList.h +++ b/source/gui/CList.h @@ -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(); /** diff --git a/source/gui/COList.cpp b/source/gui/COList.cpp index 8f2ef117ae..15795fae0f 100644 --- a/source/gui/COList.cpp +++ b/source/gui/COList.cpp @@ -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 diff --git a/source/gui/COList.h b/source/gui/COList.h index 14e52a6521..ebafbe1cda 100644 --- a/source/gui/COList.h +++ b/source/gui/COList.h @@ -45,7 +45,7 @@ class COList : public CList GUI_OBJECT(COList) public: - COList(); + COList(CGUI* pGUI); protected: void SetupText(); diff --git a/source/gui/CProgressBar.cpp b/source/gui/CProgressBar.cpp index 009fb683b0..456141caae 100644 --- a/source/gui/CProgressBar.cpp +++ b/source/gui/CProgressBar.cpp @@ -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"); diff --git a/source/gui/CProgressBar.h b/source/gui/CProgressBar.h index 3f34db539f..ceafdd4fb0 100644 --- a/source/gui/CProgressBar.h +++ b/source/gui/CProgressBar.h @@ -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: diff --git a/source/gui/CRadioButton.cpp b/source/gui/CRadioButton.cpp index 97b3e0b76a..69ddb98774 100644 --- a/source/gui/CRadioButton.cpp +++ b/source/gui/CRadioButton.cpp @@ -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 diff --git a/source/gui/CRadioButton.h b/source/gui/CRadioButton.h index e9227f7bca..ed1e571983 100644 --- a/source/gui/CRadioButton.h +++ b/source/gui/CRadioButton.h @@ -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() */ diff --git a/source/gui/CSlider.cpp b/source/gui/CSlider.cpp index c945555666..62729db3bd 100644 --- a/source/gui/CSlider.cpp +++ b/source/gui/CSlider.cpp @@ -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"); diff --git a/source/gui/CSlider.h b/source/gui/CSlider.h index 202248040d..6edb101f9c 100644 --- a/source/gui/CSlider.h +++ b/source/gui/CSlider.h @@ -26,7 +26,7 @@ class CSlider : public IGUIObject GUI_OBJECT(CSlider) public: - CSlider(); + CSlider(CGUI* pGUI); virtual ~CSlider(); protected: diff --git a/source/gui/CText.cpp b/source/gui/CText.cpp index 5777217fe3..8cfa2ec27d 100644 --- a/source/gui/CText.cpp +++ b/source/gui/CText.cpp @@ -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::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::GetSetting(this, "font", font) != PSRETURN_OK || font.empty()) // Use the default if none is specified diff --git a/source/gui/CText.h b/source/gui/CText.h index 81d18b0fdd..3ac7850589 100644 --- a/source/gui/CText.h +++ b/source/gui/CText.h @@ -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(); /** diff --git a/source/gui/CTooltip.cpp b/source/gui/CTooltip.cpp index f35df9e4fe..5130c98b51 100644 --- a/source/gui/CTooltip.cpp +++ b/source/gui/CTooltip.cpp @@ -22,7 +22,8 @@ #include -CTooltip::CTooltip() +CTooltip::CTooltip(CGUI* pGUI) + : IGUIObject(pGUI) { // If the tooltip is an object by itself: AddSetting(GUIST_float, "buffer_zone"); diff --git a/source/gui/CTooltip.h b/source/gui/CTooltip.h index c317fcc333..4e2eaec724 100644 --- a/source/gui/CTooltip.h +++ b/source/gui/CTooltip.h @@ -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: diff --git a/source/gui/GUIbase.h b/source/gui/GUIbase.h index d394bdaf8c..49e4511103 100644 --- a/source/gui/GUIbase.h +++ b/source/gui/GUIbase.h @@ -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); } /** diff --git a/source/gui/IGUIObject.cpp b/source/gui/IGUIObject.cpp index c98d1668c4..936645d3f7 100644 --- a/source/gui/IGUIObject.cpp +++ b/source/gui/IGUIObject.cpp @@ -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(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>& handler : m_ScriptHandlers) JS_CallObjectTracer(trc, &handler.second, "IGUIObject::m_ScriptHandlers"); } diff --git a/source/gui/IGUIObject.h b/source/gui/IGUIObject.h index dd4d8848e6..a0af96f7ef 100644 --- a/source/gui/IGUIObject.h +++ b/source/gui/IGUIObject.h @@ -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 > 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. diff --git a/source/gui/IGUIScrollBar.cpp b/source/gui/IGUIScrollBar.cpp index b3fdcdc83c..955f24ef02 100644 --- a/source/gui/IGUIScrollBar.cpp +++ b/source/gui/IGUIScrollBar.cpp @@ -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), diff --git a/source/gui/IGUIScrollBar.h b/source/gui/IGUIScrollBar.h index 34afeacbfc..a59962189a 100644 --- a/source/gui/IGUIScrollBar.h +++ b/source/gui/IGUIScrollBar.h @@ -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 diff --git a/source/gui/IGUIScrollBarOwner.cpp b/source/gui/IGUIScrollBarOwner.cpp index 41460e3316..f83e4ba45f 100644 --- a/source/gui/IGUIScrollBarOwner.cpp +++ b/source/gui/IGUIScrollBarOwner.cpp @@ -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); } diff --git a/source/gui/IGUIScrollBarOwner.h b/source/gui/IGUIScrollBarOwner.h index e22addaf70..28ddc912a0 100644 --- a/source/gui/IGUIScrollBarOwner.h +++ b/source/gui/IGUIScrollBarOwner.h @@ -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(); diff --git a/source/gui/MiniMap.cpp b/source/gui/MiniMap.cpp index 0683807917..67fc4224d9 100644 --- a/source/gui/MiniMap.cpp +++ b/source/gui/MiniMap.cpp @@ -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) diff --git a/source/gui/MiniMap.h b/source/gui/MiniMap.h index 8e8d785c61..74aea6c229 100644 --- a/source/gui/MiniMap.h +++ b/source/gui/MiniMap.h @@ -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();