Index: source/gui/CButton.h =================================================================== --- source/gui/CButton.h +++ source/gui/CButton.h @@ -37,24 +37,27 @@ /** * @see IGUIObject#ResetStates() */ - virtual void ResetStates() { IGUIButtonBehavior::ResetStates(); } + virtual void ResetStates() override { IGUIButtonBehavior::ResetStates(); } /** * @see IGUIObject#HandleMessage() */ - virtual void HandleMessage(SGUIMessage& Message); + virtual void HandleMessage(SGUIMessage& Message) override; /** * Draws the Button */ - virtual void Draw(); + virtual void Draw() override; + + virtual void AddSettings() override; protected: + /** * Sets up text, should be called every time changes has been * made that can change the visual. */ - void SetupText(); + virtual void SetupText() override; /** * Placement of text. Index: source/gui/CButton.cpp =================================================================== --- source/gui/CButton.cpp +++ source/gui/CButton.cpp @@ -25,6 +25,15 @@ CButton::CButton(CGUI* pGUI) : IGUIObject(pGUI), IGUIButtonBehavior(pGUI), IGUITextOwner(pGUI) { + AddText(new SGUIText()); +} + +CButton::~CButton() +{ +} + +void CButton::AddSettings() +{ AddSetting(GUIST_float, "buffer_zone"); AddSetting(GUIST_CGUIString, "caption"); AddSetting(GUIST_int, "cell_id"); @@ -47,12 +56,7 @@ AddSetting(GUIST_CStrW, "tooltip"); AddSetting(GUIST_CStr, "tooltip_style"); - // Add text - AddText(new SGUIText()); -} - -CButton::~CButton() -{ + IGUIObject::AddSettings(); } void CButton::SetupText() Index: source/gui/CChart.h =================================================================== --- source/gui/CChart.h +++ source/gui/CChart.h @@ -44,22 +44,25 @@ CChart(CGUI* pGUI); virtual ~CChart(); + virtual void AddSettings() override; + protected: + /** * @see IGUIObject#HandleMessage() */ - virtual void HandleMessage(SGUIMessage& Message); + virtual void HandleMessage(SGUIMessage& Message) override; /** * Draws the Chart */ - virtual void Draw(); + virtual void Draw() override; virtual CRect GetChartRect() const; void UpdateSeries(); - void SetupText(); + virtual void SetupText() override; std::vector m_Series; Index: source/gui/CChart.cpp =================================================================== --- source/gui/CChart.cpp +++ source/gui/CChart.cpp @@ -32,6 +32,14 @@ CChart::CChart(CGUI* pGUI) : IGUIObject(pGUI), IGUITextOwner(pGUI) { +} + +CChart::~CChart() +{ +} + +void CChart::AddSettings() +{ AddSetting(GUIST_CGUIColor, "axis_color"); AddSetting(GUIST_float, "axis_width"); AddSetting(GUIST_float, "buffer_zone"); @@ -45,10 +53,8 @@ GUI::GetSetting(this, "axis_width", m_AxisWidth); GUI::GetSetting(this, "format_x", m_FormatX); GUI::GetSetting(this, "format_y", m_FormatY); -} -CChart::~CChart() -{ + IGUIObject::AddSettings(); } void CChart::HandleMessage(SGUIMessage& Message) Index: source/gui/CCheckBox.h =================================================================== --- source/gui/CCheckBox.h +++ source/gui/CCheckBox.h @@ -38,24 +38,27 @@ /** * @see IGUIObject#ResetStates() */ - virtual void ResetStates() { IGUIButtonBehavior::ResetStates(); } + virtual void ResetStates() override { IGUIButtonBehavior::ResetStates(); } /** * @see IGUIObject#HandleMessage() */ - virtual void HandleMessage(SGUIMessage& Message); + virtual void HandleMessage(SGUIMessage& Message) override; /** * Draws the control */ - virtual void Draw(); + virtual void Draw() override; + + virtual void AddSettings() override; protected: + /** * Sets up text, should be called every time changes has been * made that can change the visual. */ - void SetupText(); + virtual void SetupText() override; }; #endif // INCLUDED_CCHECKBOX Index: source/gui/CCheckBox.cpp =================================================================== --- source/gui/CCheckBox.cpp +++ source/gui/CCheckBox.cpp @@ -31,6 +31,15 @@ CCheckBox::CCheckBox(CGUI* pGUI) : IGUIObject(pGUI), IGUITextOwner(pGUI), IGUIButtonBehavior(pGUI) { + AddText(new SGUIText()); +} + +CCheckBox::~CCheckBox() +{ +} + +void CCheckBox::AddSettings() +{ AddSetting(GUIST_float, "buffer_zone"); AddSetting(GUIST_CGUIString, "caption"); AddSetting(GUIST_int, "cell_id"); @@ -57,11 +66,7 @@ AddSetting(GUIST_CStrW, "tooltip"); AddSetting(GUIST_CStr, "tooltip_style"); - AddText(new SGUIText()); -} - -CCheckBox::~CCheckBox() -{ + IGUIObject::AddSettings(); } void CCheckBox::SetupText() Index: source/gui/CDropDown.h =================================================================== --- source/gui/CDropDown.h +++ source/gui/CDropDown.h @@ -53,49 +53,50 @@ CDropDown(CGUI* pGUI); virtual ~CDropDown(); -// virtual void ResetStates() { IGUIButtonBehavior::ResetStates(); } - /** * @see IGUIObject#HandleMessage() */ - virtual void HandleMessage(SGUIMessage& Message); + virtual void HandleMessage(SGUIMessage& Message) override; /** * Handle events manually to catch keyboard inputting. */ - virtual InReaction ManuallyHandleEvent(const SDL_Event_* ev); + virtual InReaction ManuallyHandleEvent(const SDL_Event_* ev) override; /** * Draws the Button */ - virtual void Draw(); + virtual void Draw() override; // This is one of the few classes we actually need to redefine this function // this is because the size of the control changes whether it is open // or closed. - virtual bool MouseOver(); + virtual bool MouseOver() override; + + virtual float GetBufferedZ() const override; - virtual float GetBufferedZ() const; + virtual void AddSettings() override; protected: + /** * If the size changed, the texts have to be updated as * the word wrapping depends on the size. */ - virtual void UpdateCachedSize(); + virtual void UpdateCachedSize() override; /** * Sets up text, should be called every time changes has been * made that can change the visual. */ - void SetupText(); + virtual void SetupText() override; // Sets up the cached GetListRect. Decided whether it should // have a scrollbar, and so on. virtual void SetupListRect(); // Specify a new List rectangle. - virtual CRect GetListRect() const; + virtual CRect GetListRect() const override; /** * Placement of text. Index: source/gui/CDropDown.cpp =================================================================== --- source/gui/CDropDown.cpp +++ source/gui/CDropDown.cpp @@ -30,6 +30,14 @@ : CList(pGUI), IGUIObject(pGUI), m_Open(false), m_HideScrollBar(false), m_ElementHighlight(-1) { +} + +CDropDown::~CDropDown() +{ +} + +void CDropDown::AddSettings() +{ AddSetting(GUIST_float, "button_width"); AddSetting(GUIST_float, "dropdown_size"); AddSetting(GUIST_float, "dropdown_buffer"); @@ -55,14 +63,12 @@ AddSetting(GUIST_CGUIColor, "textcolor_selected"); AddSetting(GUIST_CGUIColor, "textcolor_disabled"); + CList::AddSettings(); + // Scrollbar is forced to be true. GUI::SetSetting(this, "scrollbar", true); } -CDropDown::~CDropDown() -{ -} - void CDropDown::SetupText() { SetupListRect(); Index: source/gui/CGUI.cpp =================================================================== --- source/gui/CGUI.cpp +++ source/gui/CGUI.cpp @@ -291,7 +291,7 @@ GuiScriptingInit(*m_ScriptInterface); m_ScriptInterface->LoadGlobalScripts(); - m_BaseObject = new CGUIDummyObject(this); + m_BaseObject = CGUIDummyObject::ConstructObject(this); } CGUI::~CGUI() @@ -364,23 +364,9 @@ void CGUI::Destroy() { - // We can use the map to delete all - // now we don't want to cancel all if one Destroy fails for (const std::pair& p : m_pAllObjects) - { - try - { - p.second->Destroy(); - } - catch (PSERROR_GUI& e) - { - UNUSED2(e); - debug_warn(L"CGUI::Destroy error"); - // TODO Gee: Handle - } - delete p.second; - } + m_pAllObjects.clear(); for (const std::pair& p : m_Sprites) @@ -1725,7 +1711,7 @@ void CGUI::Xeromyces_ReadTooltip(XMBElement Element, CXeromyces* pFile) { - IGUIObject* object = new CTooltip(this); + IGUIObject* object = CTooltip::ConstructObject(this); for (XMBAttribute attr : Element.GetAttributes()) { Index: source/gui/CGUIScrollBarVertical.h =================================================================== --- source/gui/CGUIScrollBarVertical.h +++ source/gui/CGUIScrollBarVertical.h @@ -55,7 +55,7 @@ /** * Draw the scroll-bar */ - virtual void Draw(); + virtual void Draw() override; /** * If an object that contains a scrollbar has got messages, send @@ -64,22 +64,22 @@ * * @see IGUIObject#HandleMessage() */ - virtual void HandleMessage(SGUIMessage& Message); + virtual void HandleMessage(SGUIMessage& Message) override; /** * Set m_Pos with g_mouse_x/y input, i.e. when dragging. */ - virtual void SetPosFromMousePos(const CPos& mouse); + virtual void SetPosFromMousePos(const CPos& mouse) override; /** * @see IGUIScrollBar#HoveringButtonMinus */ - virtual bool HoveringButtonMinus(const CPos& mouse); + virtual bool HoveringButtonMinus(const CPos& mouse) override; /** * @see IGUIScrollBar#HoveringButtonPlus */ - virtual bool HoveringButtonPlus(const CPos& mouse); + virtual bool HoveringButtonPlus(const CPos& mouse) override; /** * Set Right Aligned @@ -91,14 +91,14 @@ * Get the rectangle of the actual BAR. * @return Rectangle, CRect */ - virtual CRect GetBarRect() const; + virtual CRect GetBarRect() const override; /** * Get the rectangle of the outline of the scrollbar, every component of the * scroll-bar should be inside this area. * @return Rectangle, CRect */ - virtual CRect GetOuterRect() const; + virtual CRect GetOuterRect() const override; protected: /** Index: source/gui/CImage.h =================================================================== --- source/gui/CImage.h +++ source/gui/CImage.h @@ -40,11 +40,16 @@ CImage(CGUI* pGUI); virtual ~CImage(); + virtual void AddSettings() override; + protected: + /** * Draws the Image */ - virtual void Draw(); + virtual void Draw() override; + + virtual void HandleMessage(SGUIMessage& UNUSED(Message)) override {}; }; #endif // INCLUDED_CIMAGE Index: source/gui/CImage.cpp =================================================================== --- source/gui/CImage.cpp +++ source/gui/CImage.cpp @@ -26,14 +26,20 @@ CImage::CImage(CGUI* pGUI) : IGUIObject(pGUI) { +} + +CImage::~CImage() +{ +} + +void CImage::AddSettings() +{ AddSetting(GUIST_CGUISpriteInstance, "sprite"); AddSetting(GUIST_int, "cell_id"); AddSetting(GUIST_CStrW, "tooltip"); AddSetting(GUIST_CStr, "tooltip_style"); -} -CImage::~CImage() -{ + IGUIObject::AddSettings(); } void CImage::Draw() Index: source/gui/CInput.h =================================================================== --- source/gui/CInput.h +++ source/gui/CInput.h @@ -41,10 +41,12 @@ CInput(CGUI* pGUI); virtual ~CInput(); + virtual void AddSettings() override; + /** * @see IGUIObject#ResetStates() */ - virtual void ResetStates() { IGUIScrollBarOwner::ResetStates(); } + virtual void ResetStates() override { IGUIScrollBarOwner::ResetStates(); } // Check where the mouse is hovering, and get the appropriate text position. // return is the text-position index. @@ -58,12 +60,12 @@ /** * @see IGUIObject#HandleMessage() */ - virtual void HandleMessage(SGUIMessage& Message); + virtual void HandleMessage(SGUIMessage& Message) override; /** * Handle events manually to catch keyboard inputting. */ - virtual InReaction ManuallyHandleEvent(const SDL_Event_* ev); + virtual InReaction ManuallyHandleEvent(const SDL_Event_* ev) override; /** * Handle events manually to catch keys which change the text. @@ -83,12 +85,12 @@ /** * @see IGUIObject#UpdateCachedSize() */ - virtual void UpdateCachedSize(); + virtual void UpdateCachedSize() override; /** * Draws the Text */ - virtual void Draw(); + virtual void Draw() override; /** * Calculate m_CharacterPosition Index: source/gui/CInput.cpp =================================================================== --- source/gui/CInput.cpp +++ source/gui/CInput.cpp @@ -45,6 +45,19 @@ 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) { + CFG_GET_VAL("gui.cursorblinkrate", m_CursorBlinkRate); + + CGUIScrollBarVertical* bar = new CGUIScrollBarVertical(pGUI); + bar->SetRightAligned(true); + AddScrollBar(bar); +} + +CInput::~CInput() +{ +} + +void CInput::AddSettings() +{ AddSetting(GUIST_int, "buffer_position"); AddSetting(GUIST_float, "buffer_zone"); AddSetting(GUIST_CStrW, "caption"); @@ -64,15 +77,7 @@ AddSetting(GUIST_CStrW, "tooltip"); AddSetting(GUIST_CStr, "tooltip_style"); - CFG_GET_VAL("gui.cursorblinkrate", m_CursorBlinkRate); - - CGUIScrollBarVertical* bar = new CGUIScrollBarVertical(pGUI); - bar->SetRightAligned(true); - AddScrollBar(bar); -} - -CInput::~CInput() -{ + IGUIObject::AddSettings(); } void CInput::UpdateBufferPositionSetting() Index: source/gui/CList.h =================================================================== --- source/gui/CList.h +++ source/gui/CList.h @@ -40,34 +40,37 @@ /** * @see IGUIObject#ResetStates() */ - virtual void ResetStates() { IGUIScrollBarOwner::ResetStates(); } + virtual void ResetStates() override { IGUIScrollBarOwner::ResetStates(); } /** * Adds an item last to the list. */ virtual void AddItem(const CStrW& str, const CStrW& data); + virtual void AddSettings() override; + protected: + /** * Sets up text, should be called every time changes has been * made that can change the visual. */ - virtual void SetupText(); + virtual void SetupText() override; /** * @see IGUIObject#HandleMessage() */ - virtual void HandleMessage(SGUIMessage& Message); + virtual void HandleMessage(SGUIMessage& Message) override; /** * Handle events manually to catch keyboard inputting. */ - virtual InReaction ManuallyHandleEvent(const SDL_Event_* ev); + virtual InReaction ManuallyHandleEvent(const SDL_Event_* ev) override; /** * Draws the List box */ - virtual void Draw(); + virtual void Draw() override; /** * Easy select elements functions @@ -80,7 +83,7 @@ /** * Handle the \ tag. */ - virtual bool HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile); + virtual bool HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile) override; // Called every time the auto-scrolling should be checked. void UpdateAutoScroll(); Index: source/gui/CList.cpp =================================================================== --- source/gui/CList.cpp +++ source/gui/CList.cpp @@ -31,6 +31,18 @@ : IGUIObject(pGUI), IGUITextOwner(pGUI), IGUIScrollBarOwner(pGUI), m_Modified(false), m_PrevSelectedItem(-1), m_LastItemClickTime(0) { + // Add scroll-bar + CGUIScrollBarVertical* bar = new CGUIScrollBarVertical(pGUI); + bar->SetRightAligned(true); + AddScrollBar(bar); +} + +CList::~CList() +{ +} + +void CList::AddSettings() +{ // Add sprite_disabled! TODO AddSetting(GUIST_float, "buffer_zone"); AddSetting(GUIST_CStrW, "font"); @@ -59,14 +71,7 @@ GUI::SetSetting(this, "hovered", -1); GUI::SetSetting(this, "auto_scroll", false); - // Add scroll-bar - CGUIScrollBarVertical* bar = new CGUIScrollBarVertical(pGUI); - bar->SetRightAligned(true); - AddScrollBar(bar); -} - -CList::~CList() -{ + IGUIObject::AddSettings(); } void CList::SetupText() Index: source/gui/COList.h =================================================================== --- source/gui/COList.h +++ source/gui/COList.h @@ -47,18 +47,20 @@ public: COList(CGUI* pGUI); + virtual void AddSettings() override; + protected: - void SetupText(); - void HandleMessage(SGUIMessage& Message); + virtual void SetupText() override; + void HandleMessage(SGUIMessage& Message) override; /** * Handle the \ tag. */ - virtual bool HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile); + virtual bool HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile) override; - void DrawList(const int& selected, const CStr& _sprite, const CStr& _sprite_selected, const CStr& _textcolor); + void DrawList(const int& selected, const CStr& _sprite, const CStr& _sprite_selected, const CStr& _textcolor) override; - virtual CRect GetListRect() const; + virtual CRect GetListRect() const override; /** * Available columns. Index: source/gui/COList.cpp =================================================================== --- source/gui/COList.cpp +++ source/gui/COList.cpp @@ -30,6 +30,10 @@ COList::COList(CGUI* pGUI) : CList(pGUI), IGUIObject(pGUI) { +} + +void COList::AddSettings() +{ AddSetting(GUIST_CGUISpriteInstance, "sprite_heading"); AddSetting(GUIST_bool, "sortable"); // The actual sorting is done in JS for more versatility AddSetting(GUIST_CStr, "selected_column"); @@ -37,6 +41,8 @@ AddSetting(GUIST_CGUISpriteInstance, "sprite_asc"); // Show the order of sorting AddSetting(GUIST_CGUISpriteInstance, "sprite_desc"); AddSetting(GUIST_CGUISpriteInstance, "sprite_not_sorted"); + + CList::AddSettings(); } void COList::SetupText() Index: source/gui/CProgressBar.h =================================================================== --- source/gui/CProgressBar.h +++ source/gui/CProgressBar.h @@ -33,17 +33,20 @@ CProgressBar(CGUI* pGUI); virtual ~CProgressBar(); + virtual void AddSettings() override; + protected: + /** * Draws the progress bar */ - virtual void Draw(); + virtual void Draw() override; // If caption is set, make sure it's within the interval 0-100 /** * @see IGUIObject#HandleMessage() */ - void HandleMessage(SGUIMessage& Message); + void HandleMessage(SGUIMessage& Message) override; }; #endif // INCLUDED_CPROGRESSBAR Index: source/gui/CProgressBar.cpp =================================================================== --- source/gui/CProgressBar.cpp +++ source/gui/CProgressBar.cpp @@ -25,22 +25,25 @@ CProgressBar::CProgressBar(CGUI* pGUI) : IGUIObject(pGUI) { +} + +CProgressBar::~CProgressBar() +{ +} + +void CProgressBar::AddSettings() +{ AddSetting(GUIST_CGUISpriteInstance, "sprite_background"); AddSetting(GUIST_CGUISpriteInstance, "sprite_bar"); AddSetting(GUIST_float, "caption"); // aka value from 0 to 100 AddSetting(GUIST_CStrW, "tooltip"); AddSetting(GUIST_CStr, "tooltip_style"); -} -CProgressBar::~CProgressBar() -{ + IGUIObject::AddSettings(); } void CProgressBar::HandleMessage(SGUIMessage& Message) { - // Important - IGUIObject::HandleMessage(Message); - switch (Message.type) { case GUIM_SETTINGS_UPDATED: Index: source/gui/CRadioButton.h =================================================================== --- source/gui/CRadioButton.h +++ source/gui/CRadioButton.h @@ -37,7 +37,7 @@ /** * @see IGUIObject#HandleMessage() */ - virtual void HandleMessage(SGUIMessage& Message); + virtual void HandleMessage(SGUIMessage& Message) override; }; #endif // INCLUDED_CRADIOBUTTON Index: source/gui/CSlider.h =================================================================== --- source/gui/CSlider.h +++ source/gui/CSlider.h @@ -29,14 +29,16 @@ CSlider(CGUI* pGUI); virtual ~CSlider(); + virtual void AddSettings() override; + protected: /** * @see IGUIObject#HandleMessage() */ - virtual void HandleMessage(SGUIMessage& Message); + virtual void HandleMessage(SGUIMessage& Message) override; - virtual void Draw(); + virtual void Draw() override; /** * Change settings and send the script event Index: source/gui/CSlider.cpp =================================================================== --- source/gui/CSlider.cpp +++ source/gui/CSlider.cpp @@ -25,6 +25,14 @@ CSlider::CSlider(CGUI* pGUI) : IGUIObject(pGUI), m_IsPressed(false), m_ButtonSide(0) { +} + +CSlider::~CSlider() +{ +} + +void CSlider::AddSettings() +{ AddSetting(GUIST_float, "value"); AddSetting(GUIST_float, "min_value"); AddSetting(GUIST_float, "max_value"); @@ -38,10 +46,8 @@ GUI::GetSetting(this, "max_value", m_MaxValue); GUI::GetSetting(this, "button_width", m_ButtonSide); m_Value = Clamp(m_Value, m_MinValue, m_MaxValue); -} -CSlider::~CSlider() -{ + IGUIObject::AddSettings(); } float CSlider::GetSliderRatio() const Index: source/gui/CText.h =================================================================== --- source/gui/CText.h +++ source/gui/CText.h @@ -36,29 +36,32 @@ /** * @see IGUIObject#ResetStates() */ - virtual void ResetStates() { IGUIScrollBarOwner::ResetStates(); } + virtual void ResetStates() override { IGUIScrollBarOwner::ResetStates(); } /** * Test if mouse position is over an icon */ - virtual bool MouseOverIcon(); + virtual bool MouseOverIcon() override; + + virtual void AddSettings() override; protected: + /** * Sets up text, should be called every time changes has been * made that can change the visual. */ - void SetupText(); + virtual void SetupText() override; /** * @see IGUIObject#HandleMessage() */ - virtual void HandleMessage(SGUIMessage& Message); + virtual void HandleMessage(SGUIMessage& Message) override; /** * Draws the Text */ - virtual void Draw(); + virtual void Draw() override; /** * Placement of text. Ignored when scrollbars are active. Index: source/gui/CText.cpp =================================================================== --- source/gui/CText.cpp +++ source/gui/CText.cpp @@ -26,6 +26,21 @@ CText::CText(CGUI* pGUI) : IGUIObject(pGUI), IGUIScrollBarOwner(pGUI), IGUITextOwner(pGUI) { + // Add scroll-bar + CGUIScrollBarVertical* bar = new CGUIScrollBarVertical(pGUI); + bar->SetRightAligned(true); + AddScrollBar(bar); + + // Add text + AddText(new SGUIText()); +} + +CText::~CText() +{ +} + +void CText::AddSettings() +{ AddSetting(GUIST_float, "buffer_zone"); AddSetting(GUIST_CGUIString, "caption"); AddSetting(GUIST_int, "cell_id"); @@ -51,17 +66,7 @@ GUI::SetSetting(this, "scrollbar", false); GUI::SetSetting(this, "clip", true); - // Add scroll-bar - CGUIScrollBarVertical* bar = new CGUIScrollBarVertical(pGUI); - bar->SetRightAligned(true); - AddScrollBar(bar); - - // Add text - AddText(new SGUIText()); -} - -CText::~CText() -{ + IGUIObject::AddSettings(); } void CText::SetupText() Index: source/gui/CTooltip.h =================================================================== --- source/gui/CTooltip.h +++ source/gui/CTooltip.h @@ -31,15 +31,18 @@ CTooltip(CGUI* pGUI); virtual ~CTooltip(); + virtual void AddSettings() override; + protected: - void SetupText(); + + virtual void SetupText() override; /** * @see IGUIObject#HandleMessage() */ - virtual void HandleMessage(SGUIMessage& Message); + virtual void HandleMessage(SGUIMessage& Message) override; - virtual void Draw(); + virtual void Draw() override; }; #endif // INCLUDED_CTOOLTIP Index: source/gui/CTooltip.cpp =================================================================== --- source/gui/CTooltip.cpp +++ source/gui/CTooltip.cpp @@ -25,6 +25,17 @@ CTooltip::CTooltip(CGUI* pGUI) : IGUIObject(pGUI), IGUITextOwner(pGUI) { + // Set up a blank piece of text, to be replaced with a more + // interesting message later + AddText(new SGUIText()); +} + +CTooltip::~CTooltip() +{ +} + +void CTooltip::AddSettings() +{ // If the tooltip is an object by itself: AddSetting(GUIST_float, "buffer_zone"); AddSetting(GUIST_CGUIString, "caption"); @@ -52,13 +63,7 @@ GUI::SetSetting(this, "anchor", EVAlign_Bottom); GUI::SetSetting(this, "text_align", EAlign_Left); - // Set up a blank piece of text, to be replaced with a more - // interesting message later - AddText(new SGUIText()); -} - -CTooltip::~CTooltip() -{ + IGUIObject::AddSettings(); } void CTooltip::SetupText() Index: source/gui/GUIbase.h =================================================================== --- source/gui/GUIbase.h +++ source/gui/GUIbase.h @@ -47,10 +47,14 @@ // Object settings setups // Setup an object's ConstructObject function -#define GUI_OBJECT(obj) \ -public: \ - static IGUIObject* ConstructObject(CGUI* pGUI) \ - { return new obj(pGUI); } +#define GUI_OBJECT(obj) \ +public: \ + static IGUIObject* ConstructObject(CGUI* pGUI) \ + { \ + IGUIObject* foo = static_cast(new obj(pGUI)); \ + foo->AddSettings(); \ + return foo; \ + } /** Index: source/gui/GUIutil.cpp =================================================================== --- source/gui/GUIutil.cpp +++ source/gui/GUIutil.cpp @@ -299,6 +299,7 @@ LOGWARNING("setting %s was not found on object %s", Setting.c_str(), pObject->GetPresentableName().c_str()); + throw; return PSRETURN_GUI_InvalidSetting; } @@ -365,6 +366,7 @@ LOGWARNING("setting %s was not found on object %s", Setting.c_str(), pObject->GetPresentableName().c_str()); + throw; return PSRETURN_GUI_InvalidSetting; } Index: source/gui/IGUIButtonBehavior.h =================================================================== --- source/gui/IGUIButtonBehavior.h +++ source/gui/IGUIButtonBehavior.h @@ -55,7 +55,7 @@ /** * @see IGUIObject#HandleMessage() */ - virtual void HandleMessage(SGUIMessage& Message); + virtual void HandleMessage(SGUIMessage& Message) override; /** * This is a function that lets a button being drawn, @@ -85,11 +85,17 @@ CGUIColor ChooseColor(); + /** + * The inheriting classes are to add settings relevant to button behavior. + */ + virtual void AddSettings() override = 0; + protected: + /** * @see IGUIObject#ResetStates() */ - virtual void ResetStates() + virtual void ResetStates() override { // Notify the gui that we aren't hovered anymore UpdateMouseOver(NULL); Index: source/gui/IGUIObject.h =================================================================== --- source/gui/IGUIObject.h +++ source/gui/IGUIObject.h @@ -253,6 +253,12 @@ */ JSObject* GetJSObject(); + /** + * This informs the GUI Object which settings will be available. + * This is public because it is accessed from the ConstructObject function. + */ + virtual void AddSettings(); + //@} protected: //-------------------------------------------------------- @@ -275,20 +281,18 @@ */ void AddSetting(const EGUISettingType& Type, const CStr& Name); - /** - * Calls Destroy on all children, and deallocates all memory. - * MEGA TODO Should it destroy it's children? - */ - virtual void Destroy(); - public: /** * This function is called with different messages * for instance when the mouse enters the object. * + * This function has to be implemented as long as AddSettings calls this from the base constructor, + * because the derived class was not constructed when the base class constructor is called and thus calls this. + * * @param Message GUI Message */ - virtual void HandleMessage(SGUIMessage& UNUSED(Message)) {} + //virtual void HandleMessage(SGUIMessage& UNUSED(Message)) {} + virtual void HandleMessage(SGUIMessage& Message) = 0; protected: /** @@ -545,9 +549,11 @@ public: CGUIDummyObject(CGUI* pGUI) : IGUIObject(pGUI) {} - virtual void Draw() {} + virtual void Draw() override {} // Empty can never be hovered. It is only a category. - virtual bool MouseOver() { return false; } + virtual bool MouseOver() override { return false; } + + virtual void HandleMessage(SGUIMessage& UNUSED(Message)) override {} }; #endif // INCLUDED_IGUIOBJECT Index: source/gui/IGUIObject.cpp =================================================================== --- source/gui/IGUIObject.cpp +++ source/gui/IGUIObject.cpp @@ -49,23 +49,8 @@ IGUIObject::IGUIObject(CGUI* pGUI) : m_pGUI(pGUI), m_pParent(NULL), m_MouseHovering(false), m_LastClickTime() { - AddSetting(GUIST_bool, "enabled"); - AddSetting(GUIST_bool, "hidden"); - AddSetting(GUIST_CClientArea, "size"); - AddSetting(GUIST_CStr, "style"); - AddSetting(GUIST_CStr, "hotkey"); - AddSetting(GUIST_float, "z"); - AddSetting(GUIST_bool, "absolute"); - AddSetting(GUIST_bool, "ghost"); - AddSetting(GUIST_float, "aspectratio"); - AddSetting(GUIST_CStrW, "tooltip"); - AddSetting(GUIST_CStr, "tooltip_style"); - - // Setup important defaults - GUI::SetSetting(this, "hidden", false); - GUI::SetSetting(this, "ghost", false); - GUI::SetSetting(this, "enabled", true); - GUI::SetSetting(this, "absolute", true); + // Notice that the base constructor is called prior to the derived constructors. + // Overridden functions in derived classes will not be called from the constructor. } IGUIObject::~IGUIObject() @@ -85,6 +70,27 @@ JS_RemoveExtraGCRootsTracer(m_pGUI->GetScriptInterface()->GetJSRuntime(), Trace, this); } +void IGUIObject::AddSettings() +{ + AddSetting(GUIST_bool, "enabled"); + AddSetting(GUIST_bool, "hidden"); + AddSetting(GUIST_CClientArea, "size"); + AddSetting(GUIST_CStr, "style"); + AddSetting(GUIST_CStr, "hotkey"); + AddSetting(GUIST_float, "z"); + AddSetting(GUIST_bool, "absolute"); + AddSetting(GUIST_bool, "ghost"); + AddSetting(GUIST_float, "aspectratio"); + AddSetting(GUIST_CStrW, "tooltip"); + AddSetting(GUIST_CStr, "tooltip_style"); + + // Setup important defaults + GUI::SetSetting(this, "hidden", false); + GUI::SetSetting(this, "ghost", false); + GUI::SetSetting(this, "enabled", true); + GUI::SetSetting(this, "absolute", true); +} + //------------------------------------------------------------------- // Functions //------------------------------------------------------------------- @@ -145,11 +151,6 @@ } } -void IGUIObject::Destroy() -{ - // Is there anything besides the children to destroy? -} - void IGUIObject::AddSetting(const EGUISettingType& Type, const CStr& Name) { // Is name already taken? Index: source/gui/IGUIScrollBarOwner.h =================================================================== --- source/gui/IGUIScrollBarOwner.h +++ source/gui/IGUIScrollBarOwner.h @@ -38,17 +38,17 @@ IGUIScrollBarOwner(CGUI* pGUI); virtual ~IGUIScrollBarOwner(); - virtual void Draw(); + virtual void Draw() override; /** * @see IGUIObject#HandleMessage() */ - virtual void HandleMessage(SGUIMessage& Message); + virtual void HandleMessage(SGUIMessage& Message) override; /** * @see IGUIObject#ResetStates() */ - virtual void ResetStates(); + virtual void ResetStates() override; /** * Interface for the m_ScrollBar to use. @@ -75,6 +75,11 @@ */ virtual float GetScrollBarPos(const int index) const; + /** + * This does not add any settings. + */ + virtual void AddSettings() override = 0; + protected: /** Index: source/gui/IGUITextOwner.h =================================================================== --- source/gui/IGUITextOwner.h +++ source/gui/IGUITextOwner.h @@ -59,17 +59,17 @@ /** * Subscribe the custom JS methods. */ - void CreateJSObject() override; + virtual void CreateJSObject() override; /** * @see IGUIObject#HandleMessage() */ - virtual void HandleMessage(SGUIMessage& Message); + virtual void HandleMessage(SGUIMessage& Message) override; /** * @see IGUIObject#UpdateCachedSize() */ - virtual void UpdateCachedSize(); + virtual void UpdateCachedSize() override; /** * Draws the Text. @@ -86,13 +86,18 @@ /** * Test if mouse position is over an icon */ - virtual bool MouseOverIcon(); + virtual bool MouseOverIcon() override; /** * Workaround to avoid a dynamic_cast which can be 80 times slower than this. */ virtual void* GetTextOwner() override { return this; } + /** + * The inheriting classes are supposed to add settings relevant to text. + */ + virtual void AddSettings() override = 0; + protected: /** Index: source/gui/MiniMap.h =================================================================== --- source/gui/MiniMap.h +++ source/gui/MiniMap.h @@ -31,18 +31,21 @@ public: CMiniMap(CGUI* pGUI); virtual ~CMiniMap(); + virtual void AddSettings() override; + protected: - virtual void Draw(); + + virtual void Draw() override; /** * @see IGUIObject#HandleMessage() */ - virtual void HandleMessage(SGUIMessage& Message); + virtual void HandleMessage(SGUIMessage& Message) override; /** * @see IGUIObject#MouseOver() */ - virtual bool MouseOver(); + virtual bool MouseOver() override; // create the minimap textures void CreateTextures(); Index: source/gui/MiniMap.cpp =================================================================== --- source/gui/MiniMap.cpp +++ source/gui/MiniMap.cpp @@ -68,8 +68,6 @@ 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) { - AddSetting(GUIST_CStrW, "tooltip"); - AddSetting(GUIST_CStr, "tooltip_style"); m_Clicking = false; m_MouseHovering = false; @@ -139,6 +137,14 @@ Destroy(); } +void CMiniMap::AddSettings() +{ + AddSetting(GUIST_CStrW, "tooltip"); + AddSetting(GUIST_CStr, "tooltip_style"); + + IGUIObject::AddSettings(); +} + void CMiniMap::HandleMessage(SGUIMessage& Message) { switch (Message.type)