diff --git a/source/gui/CButton.cpp b/source/gui/CButton.cpp index 403acacaaf..b6c0cb7311 100644 --- a/source/gui/CButton.cpp +++ b/source/gui/CButton.cpp @@ -60,10 +60,10 @@ void CButton::SetupText() m_GeneratedTexts[0] = CGUIText( m_pGUI, - GUI::GetSetting(this, "caption"), - GUI::GetSetting(this, "font"), + GetSetting("caption"), + GetSetting("font"), m_CachedActualSize.GetWidth(), - GUI::GetSetting(this, "buffer_zone"), + GetSetting("buffer_zone"), this); CalculateTextPosition(m_CachedActualSize, m_TextPos, m_GeneratedTexts[0]); @@ -88,12 +88,12 @@ void CButton::Draw() static const CStr strSpriteDisabled("sprite_disabled"); static const CStr strCellId("cell_id"); - CGUISpriteInstance& sprite = GUI::GetSetting(this, strSprite); - CGUISpriteInstance& sprite_over = GUI::GetSetting(this, strSpriteOver); - CGUISpriteInstance& sprite_pressed = GUI::GetSetting(this, strSpritePressed); - CGUISpriteInstance& sprite_disabled = GUI::GetSetting(this, strSpriteDisabled); + CGUISpriteInstance& sprite = GetSetting(strSprite); + CGUISpriteInstance& sprite_over = GetSetting(strSpriteOver); + CGUISpriteInstance& sprite_pressed = GetSetting(strSpritePressed); + CGUISpriteInstance& sprite_disabled = GetSetting(strSpriteDisabled); - const int cell_id = GUI::GetSetting(this, strCellId); + const i32 cell_id = GetSetting(strCellId); DrawButton(m_CachedActualSize, bz, sprite, sprite_over, sprite_pressed, sprite_disabled, cell_id); diff --git a/source/gui/CChart.cpp b/source/gui/CChart.cpp index 577f0d925a..6cacb2d344 100644 --- a/source/gui/CChart.cpp +++ b/source/gui/CChart.cpp @@ -44,9 +44,9 @@ CChart::CChart(CGUI& pGUI) AddSetting("series"); AddSetting("text_align"); - m_AxisWidth = GUI::GetSetting(this, "axis_width"); - m_FormatX = GUI::GetSetting(this, "format_x"); - m_FormatY = GUI::GetSetting(this, "format_y"); + m_AxisWidth = GetSetting("axis_width"); + m_FormatX = GetSetting("format_x"); + m_FormatY = GetSetting("format_y"); } CChart::~CChart() @@ -60,9 +60,9 @@ void CChart::HandleMessage(SGUIMessage& Message) { case GUIM_SETTINGS_UPDATED: { - m_AxisWidth = GUI::GetSetting(this, "axis_width"); - m_FormatX = GUI::GetSetting(this, "format_x"); - m_FormatY = GUI::GetSetting(this, "format_y"); + m_AxisWidth = GetSetting("axis_width"); + m_FormatX = GetSetting("format_x"); + m_FormatY = GetSetting("format_y"); UpdateSeries(); break; @@ -108,7 +108,7 @@ void CChart::DrawAxes(const CShaderProgramPtr& shader) const ADD(m_CachedActualSize.left, m_CachedActualSize.top); ADD(rect.left, rect.top - m_AxisWidth); #undef ADD - DrawTriangleStrip(shader, GUI::GetSetting(this, "axis_color"), vertices); + DrawTriangleStrip(shader, GetSetting("axis_color"), vertices); } void CChart::Draw() @@ -182,8 +182,8 @@ CRect CChart::GetChartRect() const void CChart::UpdateSeries() { - const CGUISeries& pSeries = GUI::GetSetting(this, "series"); - const CGUIList& pSeriesColor = GUI::GetSetting(this, "series_color"); + const CGUISeries& pSeries = GetSetting("series"); + const CGUIList& pSeriesColor = GetSetting("series_color"); m_Series.clear(); m_Series.resize(pSeries.m_Series.size()); @@ -209,11 +209,11 @@ void CChart::SetupText() if (m_Series.empty()) return; - const CStrW& font = GUI::GetSetting(this, "font"); - const float buffer_zone = GUI::GetSetting(this, "buffer_zone"); + const CStrW& font = GetSetting("font"); + const float buffer_zone = GetSetting("buffer_zone"); // Add Y-axis - m_FormatY = GUI::GetSetting(this, "format_y"); + m_FormatY = GetSetting("format_y"); const float height = GetChartRect().GetHeight(); // TODO: split values depend on the format; if (m_EqualY) @@ -230,7 +230,7 @@ void CChart::SetupText() } // Add X-axis - m_FormatX = GUI::GetSetting(this, "format_x"); + m_FormatX = GetSetting("format_x"); const float width = GetChartRect().GetWidth(); if (m_EqualX) { diff --git a/source/gui/CCheckBox.cpp b/source/gui/CCheckBox.cpp index 67266a2b2e..5e28a5b2cf 100644 --- a/source/gui/CCheckBox.cpp +++ b/source/gui/CCheckBox.cpp @@ -70,10 +70,10 @@ void CCheckBox::SetupText() m_GeneratedTexts[0] = CGUIText( m_pGUI, - GUI::GetSetting(this, "caption"), - GUI::GetSetting(this, "font"), - m_CachedActualSize.GetWidth() - GUI::GetSetting(this, "square_side"), - GUI::GetSetting(this, "buffer_zone"), + GetSetting("caption"), + GetSetting("font"), + m_CachedActualSize.GetWidth() - GetSetting("square_side"), + GetSetting("buffer_zone"), this); } @@ -88,7 +88,7 @@ void CCheckBox::HandleMessage(SGUIMessage& Message) case GUIM_PRESSED: { // Switch to opposite. - GUI::SetSetting(this, "checked", !GUI::GetSetting(this, "checked")); + GUI::SetSetting(this, "checked", !GetSetting("checked")); break; } @@ -99,22 +99,22 @@ void CCheckBox::HandleMessage(SGUIMessage& Message) void CCheckBox::Draw() { - if (GUI::GetSetting(this, "checked")) + if (GetSetting("checked")) DrawButton( m_CachedActualSize, GetBufferedZ(), - GUI::GetSetting(this, "sprite2"), - GUI::GetSetting(this, "sprite2_over"), - GUI::GetSetting(this, "sprite2_pressed"), - GUI::GetSetting(this, "sprite2_disabled"), - GUI::GetSetting(this, "cell_id")); + GetSetting("sprite2"), + GetSetting("sprite2_over"), + GetSetting("sprite2_pressed"), + GetSetting("sprite2_disabled"), + GetSetting("cell_id")); else DrawButton( m_CachedActualSize, GetBufferedZ(), - GUI::GetSetting(this, "sprite"), - GUI::GetSetting(this, "sprite_over"), - GUI::GetSetting(this, "sprite_pressed"), - GUI::GetSetting(this, "sprite_disabled"), - GUI::GetSetting(this, "cell_id")); + GetSetting("sprite"), + GetSetting("sprite_over"), + GetSetting("sprite_pressed"), + GetSetting("sprite_disabled"), + GetSetting("cell_id")); } diff --git a/source/gui/CDropDown.cpp b/source/gui/CDropDown.cpp index ca10d8eae2..47dd2c596f 100644 --- a/source/gui/CDropDown.cpp +++ b/source/gui/CDropDown.cpp @@ -107,8 +107,8 @@ void CDropDown::HandleMessage(SGUIMessage& Message) if (!GetListRect().PointInside(mouse)) break; - const CGUIList& pList = GUI::GetSetting(this, "list"); - const bool scrollbar = GUI::GetSetting(this, "scrollbar"); + const CGUIList& pList = GetSetting("list"); + const bool scrollbar = GetSetting("scrollbar"); const float scroll = scrollbar ? GetScrollBar(0).GetPos() : 0.f; CRect rect = GetListRect(); @@ -138,16 +138,16 @@ void CDropDown::HandleMessage(SGUIMessage& Message) case GUIM_MOUSE_ENTER: { - if (GUI::GetSetting(this, "enabled")) + if (GetSetting("enabled")) PlaySound("sound_enter"); break; } case GUIM_MOUSE_LEAVE: { - m_ElementHighlight = GUI::GetSetting(this, "selected"); + m_ElementHighlight = GetSetting("selected"); - if (GUI::GetSetting(this, "enabled")) + if (GetSetting("enabled")) PlaySound("sound_leave"); break; } @@ -156,7 +156,7 @@ void CDropDown::HandleMessage(SGUIMessage& Message) // a mouse click to open the dropdown, also the coordinates are changed. case GUIM_MOUSE_PRESS_LEFT: { - if (!GUI::GetSetting(this, "enabled")) + if (!GetSetting("enabled")) { PlaySound("sound_disabled"); break; @@ -164,13 +164,13 @@ void CDropDown::HandleMessage(SGUIMessage& Message) if (!m_Open) { - const CGUIList& pList = GUI::GetSetting(this, "list"); + const CGUIList& pList = GetSetting("list"); if (pList.m_Items.empty()) return; m_Open = true; GetScrollBar(0).SetZ(GetBufferedZ()); - m_ElementHighlight = GUI::GetSetting(this, "selected"); + m_ElementHighlight = GetSetting("selected"); // Start at the position of the selected item, if possible. GetScrollBar(0).SetPos(m_ItemsYPositions.empty() ? 0 : m_ItemsYPositions[m_ElementHighlight] - 60); @@ -206,10 +206,10 @@ void CDropDown::HandleMessage(SGUIMessage& Message) case GUIM_MOUSE_WHEEL_DOWN: { // Don't switch elements by scrolling when open, causes a confusing interaction between this and the scrollbar. - if (m_Open || !GUI::GetSetting(this, "enabled")) + if (m_Open || !GetSetting("enabled")) break; - m_ElementHighlight = GUI::GetSetting(this, "selected"); + m_ElementHighlight = GetSetting("selected"); if (m_ElementHighlight + 1 >= (int)m_ItemsYPositions.size() - 1) break; @@ -222,10 +222,10 @@ void CDropDown::HandleMessage(SGUIMessage& Message) case GUIM_MOUSE_WHEEL_UP: { // Don't switch elements by scrolling when open, causes a confusing interaction between this and the scrollbar. - if (m_Open || !GUI::GetSetting(this, "enabled")) + if (m_Open || !GetSetting("enabled")) break; - m_ElementHighlight = GUI::GetSetting(this, "selected"); + m_ElementHighlight = GetSetting("selected"); if (m_ElementHighlight - 1 < 0) break; @@ -306,7 +306,7 @@ InReaction CDropDown::ManuallyHandleEvent(const SDL_Event_* ev) m_TimeOfLastInput = timer_Time(); - const CGUIList& pList = GUI::GetSetting(this, "list"); + const CGUIList& pList = GetSetting("list"); // let's look for the closest element // basically it's alphabetic order and "as many letters as we can get". int closest = -1; @@ -348,7 +348,7 @@ InReaction CDropDown::ManuallyHandleEvent(const SDL_Event_* ev) result = IN_HANDLED; if (update_highlight) - m_ElementHighlight = GUI::GetSetting(this, "selected"); + m_ElementHighlight = GetSetting("selected"); return result; } @@ -359,9 +359,9 @@ void CDropDown::SetupListRect() extern float g_GuiScale; const float yres = g_yres / g_GuiScale; - const float size = GUI::GetSetting(this, "dropdown_size"); - const float buffer = GUI::GetSetting(this, "dropdown_buffer"); - const u32 minimumVisibleItems = GUI::GetSetting(this, "minimum_visible_items"); + const float size = GetSetting("dropdown_size"); + const float buffer = GetSetting("dropdown_buffer"); + const u32 minimumVisibleItems = GetSetting("minimum_visible_items"); if (m_ItemsYPositions.empty()) { @@ -434,12 +434,12 @@ bool CDropDown::IsMouseOver() const void CDropDown::Draw() { const float bz = GetBufferedZ(); - const float button_width = GUI::GetSetting(this, "button_width"); - const bool enabled = GUI::GetSetting(this, "enabled"); - const int cell_id = GUI::GetSetting(this, "cell_id"); - const int selected = GUI::GetSetting(this, "selected"); - CGUISpriteInstance& sprite = GUI::GetSetting(this, enabled ? "sprite" : "sprite_disabled"); - CGUISpriteInstance& sprite2 = GUI::GetSetting(this, "sprite2"); + const float button_width = GetSetting("button_width"); + const bool enabled = GetSetting("enabled"); + const int cell_id = GetSetting("cell_id"); + const int selected = GetSetting("selected"); + CGUISpriteInstance& sprite = GetSetting(enabled ? "sprite" : "sprite_disabled"); + CGUISpriteInstance& sprite2 = GetSetting("sprite2"); m_pGUI.DrawSprite(sprite, cell_id, bz, m_CachedActualSize); @@ -450,17 +450,17 @@ void CDropDown::Draw() if (!enabled) { - CGUISpriteInstance& sprite2_second = GUI::GetSetting(this, "sprite2_disabled"); + CGUISpriteInstance& sprite2_second = GetSetting("sprite2_disabled"); m_pGUI.DrawSprite(sprite2_second || sprite2, cell_id, bz + 0.05f, rect); } else if (m_Open) { - CGUISpriteInstance& sprite2_second = GUI::GetSetting(this, "sprite2_pressed"); + CGUISpriteInstance& sprite2_second = GetSetting("sprite2_pressed"); m_pGUI.DrawSprite(sprite2_second || sprite2, cell_id, bz + 0.05f, rect); } else if (m_MouseHovering) { - CGUISpriteInstance& sprite2_second = GUI::GetSetting(this, "sprite2_over"); + CGUISpriteInstance& sprite2_second = GetSetting("sprite2_over"); m_pGUI.DrawSprite(sprite2_second || sprite2, cell_id, bz + 0.05f, rect); } else @@ -472,14 +472,14 @@ void CDropDown::Draw() CRect cliparea(m_CachedActualSize.left, m_CachedActualSize.top, m_CachedActualSize.right-button_width, m_CachedActualSize.bottom); - const CGUIColor& color = GUI::GetSetting(this, enabled ? "textcolor_selected" : "textcolor_disabled"); + const CGUIColor& color = GetSetting(enabled ? "textcolor_selected" : "textcolor_disabled"); CPos pos(m_CachedActualSize.left, m_CachedActualSize.top); DrawText(selected, color, pos, bz+0.1f, cliparea); } // Disable scrollbar during drawing without sending a setting-changed message - bool& scrollbar = GUI::GetSetting(this, "scrollbar"); + bool& scrollbar = GetSetting("scrollbar"); bool old = scrollbar; if (m_Open) diff --git a/source/gui/CGUI.cpp b/source/gui/CGUI.cpp index c51f366de3..3902d745cc 100644 --- a/source/gui/CGUI.cpp +++ b/source/gui/CGUI.cpp @@ -864,7 +864,7 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec if (!ManuallySetZ) { // Set it automatically to 10 plus its parents - if (GUI::GetSetting(object, "absolute")) + if (object->GetSetting("absolute")) // If the object is absolute, we'll have to get the parent's Z buffered, // and add to that! GUI::SetSetting(object, "z", pParent->GetBufferedZ() + 10.f, true); diff --git a/source/gui/CGUIText.cpp b/source/gui/CGUIText.cpp index 909f502251..a5316f3578 100644 --- a/source/gui/CGUIText.cpp +++ b/source/gui/CGUIText.cpp @@ -80,7 +80,7 @@ CGUIText::CGUIText(const CGUI& pGUI, const CGUIString& string, const CStrW& Font // to run through the TextCalls a second time in the CalculateTextPosition method again EAlign align = EAlign_Left; if (pObject->SettingExists("text_align")) - align = GUI::GetSetting(pObject, "text_align"); + align = pObject->GetSetting("text_align"); // Go through string word by word for (int i = 0; i < static_cast(string.m_Words.size()) - 1; ++i) diff --git a/source/gui/CImage.cpp b/source/gui/CImage.cpp index 42098857a8..2c39e52740 100644 --- a/source/gui/CImage.cpp +++ b/source/gui/CImage.cpp @@ -39,8 +39,8 @@ CImage::~CImage() void CImage::Draw() { m_pGUI.DrawSprite( - GUI::GetSetting(this, "sprite"), - GUI::GetSetting(this, "cell_id"), + GetSetting("sprite"), + GetSetting("cell_id"), GetBufferedZ(), m_CachedActualSize); } diff --git a/source/gui/CInput.cpp b/source/gui/CInput.cpp index a26bc0efab..b3bc6afb56 100644 --- a/source/gui/CInput.cpp +++ b/source/gui/CInput.cpp @@ -82,7 +82,7 @@ void CInput::UpdateBufferPositionSetting() void CInput::ClearComposedText() { - CStrW& pCaption = GUI::GetSetting(this, "caption"); + CStrW& pCaption = GetSetting("caption"); pCaption.erase(m_iInsertPos, m_iComposedLength); m_iBufferPos = m_iInsertPos; UpdateBufferPositionSetting(); @@ -111,7 +111,7 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev) return IN_PASS; // Text has been committed, either single key presses or through an IME - CStrW& pCaption = GUI::GetSetting(this, "caption"); + CStrW& pCaption = GetSetting("caption"); std::wstring text = wstring_from_utf8(ev->ev.text.text); m_WantedX = 0.0f; @@ -148,7 +148,7 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev) // Text is being composed with an IME // TODO: indicate this by e.g. underlining the uncommitted text - CStrW& pCaption = GUI::GetSetting(this, "caption"); + CStrW& pCaption = GetSetting("caption"); const char* rawText = ev->ev.edit.text; int rawLength = strlen(rawText); std::wstring wtext = wstring_from_utf8(rawText); @@ -199,7 +199,7 @@ InReaction CInput::ManuallyHandleEvent(const SDL_Event_* ev) // Since the GUI framework doesn't handle to set settings // in Unicode (CStrW), we'll simply retrieve the actual // pointer and edit that. - CStrW& pCaption = GUI::GetSetting(this, "caption"); + CStrW& pCaption = GetSetting("caption"); SDL_Keycode keyCode = ev->ev.key.keysym.sym; ManuallyImmutableHandleKeyDownEvent(keyCode, pCaption); @@ -287,7 +287,7 @@ void CInput::ManuallyMutableHandleKeyDownEvent(const SDL_Keycode keyCode, CStrW& { // 'Return' should do a Press event for single liners (e.g. submitting forms) // otherwise a '\n' character will be added. - if (!GUI::GetSetting(this, "multiline")) + if (!GetSetting("multiline")) { SendEvent(GUIM_PRESSED, "press"); break; @@ -304,7 +304,7 @@ void CInput::ManuallyMutableHandleKeyDownEvent(const SDL_Keycode keyCode, CStrW& return; // check max length - const int max_length = GUI::GetSetting(this, "max_length"); + const int max_length = GetSetting("max_length"); if (max_length != 0 && static_cast(pCaption.length()) >= max_length) break; @@ -568,7 +568,7 @@ void CInput::ManuallyImmutableHandleKeyDownEvent(const SDL_Keycode keyCode, CStr InReaction CInput::ManuallyHandleHotkeyEvent(const SDL_Event_* ev) { - CStrW& pCaption = GUI::GetSetting(this, "caption"); + CStrW& pCaption = GetSetting("caption"); bool shiftKeyPressed = g_keys[SDLK_RSHIFT] || g_keys[SDLK_LSHIFT]; @@ -838,7 +838,7 @@ void CInput::HandleMessage(SGUIMessage& Message) { // Update scroll-bar // TODO Gee: (2004-09-01) Is this really updated each time it should? - if (GUI::GetSetting(this, "scrollbar") && + if (GetSetting("scrollbar") && (Message.value == CStr("size") || Message.value == CStr("z") || Message.value == CStr("absolute"))) @@ -852,12 +852,12 @@ void CInput::HandleMessage(SGUIMessage& Message) // Update scrollbar if (Message.value == CStr("scrollbar_style")) { - GetScrollBar(0).SetScrollBarStyle(GUI::GetSetting(this, Message.value)); + GetScrollBar(0).SetScrollBarStyle(GetSetting(Message.value)); } if (Message.value == CStr("buffer_position")) { - m_iBufferPos = GUI::GetSetting(this, Message.value); + m_iBufferPos = GetSetting(Message.value); m_iBufferPos_Tail = -1; // position change resets selection } @@ -874,7 +874,7 @@ void CInput::HandleMessage(SGUIMessage& Message) if (Message.value == CStr("multiline")) { - if (!GUI::GetSetting(this, "multiline")) + if (!GetSetting("multiline")) GetScrollBar(0).SetLength(0.f); else GetScrollBar(0).SetLength(m_CachedActualSize.bottom - m_CachedActualSize.top); @@ -885,15 +885,15 @@ void CInput::HandleMessage(SGUIMessage& Message) UpdateAutoScroll(); if (Message.value == CStr("readonly")) - m_Readonly = GUI::GetSetting(this, "readonly"); + m_Readonly = GetSetting("readonly"); break; } case GUIM_MOUSE_PRESS_LEFT: { // Check if we're selecting the scrollbar - if (GUI::GetSetting(this, "scrollbar") && - GUI::GetSetting(this, "multiline") && + if (GetSetting("scrollbar") && + GetSetting("multiline") && GetScrollBar(0).GetStyle()) { if (m_pGUI.GetMousePos().x > m_CachedActualSize.right - GetScrollBar(0).GetStyle()->m_Width) @@ -926,7 +926,7 @@ void CInput::HandleMessage(SGUIMessage& Message) if (m_ComposingText) break; - const CStrW& pCaption = GUI::GetSetting(this, "caption"); + const CStrW& pCaption = GetSetting("caption"); if (pCaption.empty()) break; @@ -1059,12 +1059,12 @@ void CInput::HandleMessage(SGUIMessage& Message) GetScrollBar(0).SetY(m_CachedActualSize.top); GetScrollBar(0).SetZ(GetBufferedZ()); GetScrollBar(0).SetLength(m_CachedActualSize.bottom - m_CachedActualSize.top); - GetScrollBar(0).SetScrollBarStyle(GUI::GetSetting(this, "scrollbar_style")); + GetScrollBar(0).SetScrollBarStyle(GetSetting("scrollbar_style")); UpdateText(); UpdateAutoScroll(); - m_Readonly = GUI::GetSetting(this, "readonly"); + m_Readonly = GetSetting("readonly"); break; } case GUIM_GOT_FOCUS: @@ -1116,7 +1116,7 @@ void CInput::UpdateCachedSize() IGUIObject::UpdateCachedSize(); - if (GUI::GetSetting(this, "scrollbar")) + if (GetSetting("scrollbar")) { GetScrollBar(0).SetX(m_CachedActualSize.right); GetScrollBar(0).SetY(m_CachedActualSize.top); @@ -1144,33 +1144,33 @@ void CInput::Draw() m_CursorVisState = true; // First call draw on ScrollBarOwner - const bool scrollbar = GUI::GetSetting(this, "scrollbar"); - const float buffer_zone = GUI::GetSetting(this, "buffer_zone"); - const bool multiline = GUI::GetSetting(this, "multiline"); - const bool mask = GUI::GetSetting(this, "mask"); + const bool scrollbar = GetSetting("scrollbar"); + const float buffer_zone = GetSetting("buffer_zone"); + const bool multiline = GetSetting("multiline"); + const bool mask = GetSetting("mask"); if (scrollbar && multiline) IGUIScrollBarOwner::Draw(); - const CGUIColor& color = GUI::GetSetting(this, "textcolor"); - const CGUIColor& color_selected = GUI::GetSetting(this, "textcolor_selected"); + const CGUIColor& color = GetSetting("textcolor"); + const CGUIColor& color_selected = GetSetting("textcolor_selected"); - CStrIntern font_name(GUI::GetSetting(this, "font").ToUTF8()); + CStrIntern font_name(GetSetting("font").ToUTF8()); - const CStrW& pCaption = GUI::GetSetting(this, "caption"); + const CStrW& pCaption = GetSetting("caption"); wchar_t mask_char = L'*'; if (mask) { - const CStrW& maskStr = GUI::GetSetting(this, "mask_char"); + const CStrW& maskStr = GetSetting("mask_char"); if (maskStr.length() > 0) mask_char = maskStr[0]; } - CGUISpriteInstance& sprite = GUI::GetSetting(this, "sprite"); - CGUISpriteInstance& sprite_selectarea = GUI::GetSetting(this, "sprite_selectarea"); + CGUISpriteInstance& sprite = GetSetting("sprite"); + CGUISpriteInstance& sprite_selectarea = GetSetting("sprite_selectarea"); - const int cell_id = GUI::GetSetting(this, "cell_id"); + const int cell_id = GetSetting("cell_id"); m_pGUI.DrawSprite(sprite, cell_id, bz, m_CachedActualSize); @@ -1490,16 +1490,16 @@ void CInput::Draw() void CInput::UpdateText(int from, int to_before, int to_after) { - const CStrW& caption = GUI::GetSetting(this, "caption"); - const float buffer_zone = GUI::GetSetting(this, "buffer_zone"); - const bool multiline = GUI::GetSetting(this, "multiline"); - const bool mask = GUI::GetSetting(this, "mask"); - CStrIntern font_name(GUI::GetSetting(this, "font").ToUTF8()); + const CStrW& caption = GetSetting("caption"); + const float buffer_zone = GetSetting("buffer_zone"); + const bool multiline = GetSetting("multiline"); + const bool mask = GetSetting("mask"); + CStrIntern font_name(GetSetting("font").ToUTF8()); wchar_t mask_char = L'*'; if (mask) { - const CStrW& maskStr = GUI::GetSetting(this, "mask_char"); + const CStrW& maskStr = GetSetting("mask_char"); if (maskStr.length() > 0) mask_char = maskStr[0]; } @@ -1836,7 +1836,7 @@ void CInput::UpdateText(int from, int to_before, int to_after) // add the final row (even if empty) m_CharacterPositions.insert(current_line, row); - if (GUI::GetSetting(this, "scrollbar")) + if (GetSetting("scrollbar")) { GetScrollBar(0).SetScrollRange(m_CharacterPositions.size() * font.GetLineSpacing() + buffer_zone*2.f); GetScrollBar(0).SetScrollSpace(m_CachedActualSize.GetHeight()); @@ -1848,8 +1848,8 @@ int CInput::GetMouseHoveringTextPosition() const if (m_CharacterPositions.empty()) return 0; - const float buffer_zone = GUI::GetSetting(this, "buffer_zone"); - const bool multiline = GUI::GetSetting(this, "multiline"); + const float buffer_zone = GetSetting("buffer_zone"); + const bool multiline = GetSetting("multiline"); // Return position int retPosition; @@ -1861,12 +1861,12 @@ int CInput::GetMouseHoveringTextPosition() const if (multiline) { float scroll = 0.f; - if (GUI::GetSetting(this, "scrollbar")) + if (GetSetting("scrollbar")) scroll = GetScrollBarPos(0); // Now get the height of the font. // TODO: Get the real font - CFontMetrics font(CStrIntern(GUI::GetSetting(this, "font").ToUTF8())); + CFontMetrics font(CStrIntern(GetSetting("font").ToUTF8())); float spacing = (float)font.GetLineSpacing(); // Change mouse position relative to text. @@ -1943,7 +1943,7 @@ int CInput::GetXTextPosition(const std::list::const_iterator& current, con void CInput::DeleteCurSelection() { - CStrW& pCaption = GUI::GetSetting(this, "caption"); + CStrW& pCaption = GetSetting("caption"); int virtualFrom; int virtualTo; @@ -1979,9 +1979,9 @@ bool CInput::SelectingText() const float CInput::GetTextAreaWidth() { - const float buffer_zone = GUI::GetSetting(this, "buffer_zone"); + const float buffer_zone = GetSetting("buffer_zone"); - if (GUI::GetSetting(this, "scrollbar") && GetScrollBar(0).GetStyle()) + if (GetSetting("scrollbar") && GetScrollBar(0).GetStyle()) return m_CachedActualSize.GetWidth() - buffer_zone*2.f - GetScrollBar(0).GetStyle()->m_Width; else return m_CachedActualSize.GetWidth() - buffer_zone*2.f; @@ -1989,19 +1989,19 @@ float CInput::GetTextAreaWidth() void CInput::UpdateAutoScroll() { - const float buffer_zone = GUI::GetSetting(this, "buffer_zone"); + const float buffer_zone = GetSetting("buffer_zone"); // Autoscrolling up and down - if (GUI::GetSetting(this, "multiline")) + if (GetSetting("multiline")) { - if (!GUI::GetSetting(this, "scrollbar")) + if (!GetSetting("scrollbar")) return; const float scroll = GetScrollBar(0).GetPos(); // Now get the height of the font. // TODO: Get the real font - CFontMetrics font(CStrIntern(GUI::GetSetting(this, "font").ToUTF8())); + CFontMetrics font(CStrIntern(GetSetting("font").ToUTF8())); float spacing = (float)font.GetLineSpacing(); //float height = font.GetHeight(); diff --git a/source/gui/CList.cpp b/source/gui/CList.cpp index bb25d48175..e1259c8374 100644 --- a/source/gui/CList.cpp +++ b/source/gui/CList.cpp @@ -70,7 +70,7 @@ CList::~CList() void CList::SetupText() { m_Modified = true; - const CGUIList& pList = GUI::GetSetting(this, "list"); + const CGUIList& pList = GetSetting("list"); //ENSURE(m_GeneratedTexts.size()>=1); @@ -81,16 +81,16 @@ void CList::SetupText() // continuously, or even often, so it'll probably be okay. m_GeneratedTexts.clear(); - const CStrW& font = GUI::GetSetting(this, "font"); + const CStrW& font = GetSetting("font"); - const bool scrollbar = GUI::GetSetting(this, "scrollbar"); + const bool scrollbar = GetSetting("scrollbar"); float width = GetListRect().GetWidth(); // remove scrollbar if applicable if (scrollbar && GetScrollBar(0).GetStyle()) width -= GetScrollBar(0).GetStyle()->m_Width; - const float buffer_zone = GUI::GetSetting(this, "buffer_zone"); + const float buffer_zone = GetSetting("buffer_zone"); // Generate texts float buffered_y = 0.f; @@ -146,7 +146,7 @@ void CList::HandleMessage(SGUIMessage& Message) { // TODO: Check range - if (GUI::GetSetting(this, "auto_scroll")) + if (GetSetting("auto_scroll")) UpdateAutoScroll(); // TODO only works if lower-case, shouldn't it be made case sensitive instead? @@ -159,7 +159,7 @@ void CList::HandleMessage(SGUIMessage& Message) // Update scrollbar if (Message.value == "scrollbar_style") { - GetScrollBar(0).SetScrollBarStyle(GUI::GetSetting(this, Message.value)); + GetScrollBar(0).SetScrollBarStyle(GetSetting(Message.value)); SetupText(); } @@ -167,7 +167,7 @@ void CList::HandleMessage(SGUIMessage& Message) case GUIM_MOUSE_PRESS_LEFT: { - if (!GUI::GetSetting(this, "enabled")) + if (!GetSetting("enabled")) { PlaySound("sound_disabled"); break; @@ -192,7 +192,7 @@ void CList::HandleMessage(SGUIMessage& Message) case GUIM_MOUSE_LEAVE: { - if (GUI::GetSetting(this, "hovered") == -1) + if (GetSetting("hovered") == -1) break; GUI::SetSetting(this, "hovered", -1); @@ -203,7 +203,7 @@ void CList::HandleMessage(SGUIMessage& Message) case GUIM_MOUSE_OVER: { int hovered = GetHoveredItem(); - if (hovered == GUI::GetSetting(this, "hovered")) + if (hovered == GetSetting("hovered")) break; GUI::SetSetting(this, "hovered", hovered); @@ -213,7 +213,7 @@ void CList::HandleMessage(SGUIMessage& Message) case GUIM_LOAD: { - GetScrollBar(0).SetScrollBarStyle(GUI::GetSetting(this, "scrollbar_style")); + GetScrollBar(0).SetScrollBarStyle(GetSetting("scrollbar_style")); break; } @@ -278,7 +278,7 @@ InReaction CList::ManuallyHandleEvent(const SDL_Event_* ev) void CList::Draw() { - DrawList(GUI::GetSetting(this, "selected"), "sprite", "sprite_selectarea", "textcolor"); + DrawList(GetSetting("selected"), "sprite", "sprite_selectarea", "textcolor"); } void CList::DrawList(const int& selected, const CStr& _sprite, const CStr& _sprite_selected, const CStr& _textcolor) @@ -286,7 +286,7 @@ void CList::DrawList(const int& selected, const CStr& _sprite, const CStr& _spri float bz = GetBufferedZ(); // First call draw on ScrollBarOwner - const bool scrollbar = GUI::GetSetting(this, "scrollbar"); + const bool scrollbar = GetSetting("scrollbar"); if (scrollbar) IGUIScrollBarOwner::Draw(); @@ -294,10 +294,10 @@ void CList::DrawList(const int& selected, const CStr& _sprite, const CStr& _spri { CRect rect = GetListRect(); - CGUISpriteInstance& sprite = GUI::GetSetting(this, _sprite); - CGUISpriteInstance& sprite_selectarea = GUI::GetSetting(this, _sprite_selected); + CGUISpriteInstance& sprite = GetSetting(_sprite); + CGUISpriteInstance& sprite_selectarea = GetSetting(_sprite_selected); - const int cell_id = GUI::GetSetting(this, "cell_id"); + const int cell_id = GetSetting("cell_id"); m_pGUI.DrawSprite(sprite, cell_id, bz, rect); float scroll = 0.f; @@ -334,8 +334,8 @@ void CList::DrawList(const int& selected, const CStr& _sprite, const CStr& _spri } } - const CGUIList& pList = GUI::GetSetting(this, "list"); - const CGUIColor& color = GUI::GetSetting(this, _textcolor); + const CGUIList& pList = GetSetting("list"); + const CGUIColor& color = GetSetting(_textcolor); for (size_t i = 0; i < pList.m_Items.size(); ++i) { @@ -368,12 +368,12 @@ void CList::AddItem(const CStrW& str, const CStrW& data) gui_string.SetValue(str); // Do not send a settings-changed message - CGUIList& pList = GUI::GetSetting(this, "list"); + CGUIList& pList = GetSetting("list"); pList.m_Items.push_back(gui_string); CGUIString data_string; data_string.SetValue(data); - CGUIList& pListData = GUI::GetSetting(this, "list_data"); + CGUIList& pListData = GetSetting("list_data"); pListData.m_Items.push_back(data_string); // TODO Temp @@ -395,9 +395,9 @@ bool CList::HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile) void CList::SelectNextElement() { - int selected = GUI::GetSetting(this, "selected"); + int selected = GetSetting("selected"); - const CGUIList& pList = GUI::GetSetting(this, "list"); + const CGUIList& pList = GetSetting("list"); if (selected != static_cast(pList.m_Items.size()) - 1) { @@ -409,7 +409,7 @@ void CList::SelectNextElement() void CList::SelectPrevElement() { - int selected = GUI::GetSetting(this, "selected"); + int selected = GetSetting("selected"); if (selected > 0) { @@ -421,23 +421,23 @@ void CList::SelectPrevElement() void CList::SelectFirstElement() { - if (GUI::GetSetting(this, "selected") >= 0) + if (GetSetting("selected") >= 0) GUI::SetSetting(this, "selected", 0); } void CList::SelectLastElement() { - const CGUIList& pList = GUI::GetSetting(this, "list"); + const CGUIList& pList = GetSetting("list"); const int index = static_cast(pList.m_Items.size()) - 1; - if (GUI::GetSetting(this, "selected") != index) + if (GetSetting("selected") != index) GUI::SetSetting(this, "selected", index); } void CList::UpdateAutoScroll() { - const int selected = GUI::GetSetting(this, "selected"); - const bool scrollbar = GUI::GetSetting(this, "scrollbar"); + const int selected = GetSetting("selected"); + const bool scrollbar = GetSetting("scrollbar"); // No scrollbar, no scrolling (at least it's not made to work properly). if (!scrollbar || selected < 0 || static_cast(selected) >= m_ItemsYPositions.size()) @@ -461,7 +461,7 @@ void CList::UpdateAutoScroll() int CList::GetHoveredItem() { - const bool scrollbar = GUI::GetSetting(this, "scrollbar"); + const bool scrollbar = GetSetting("scrollbar"); const float scroll = scrollbar ? GetScrollBar(0).GetPos() : 0.f; const CRect& rect = GetListRect(); @@ -474,7 +474,7 @@ int CList::GetHoveredItem() mouse.x <= GetScrollBar(0).GetOuterRect().right) return -1; - const CGUIList& pList = GUI::GetSetting(this, "list"); + const CGUIList& pList = GetSetting("list"); for (size_t i = 0; i < pList.m_Items.size(); ++i) if (mouse.y >= rect.top + m_ItemsYPositions[i] && mouse.y < rect.top + m_ItemsYPositions[i + 1]) diff --git a/source/gui/COList.cpp b/source/gui/COList.cpp index 2a40fecb6c..4d4fd6db69 100644 --- a/source/gui/COList.cpp +++ b/source/gui/COList.cpp @@ -40,7 +40,7 @@ COList::COList(CGUI& pGUI) void COList::SetupText() { - const CGUIList& pList = GUI::GetSetting(this, "list"); + const CGUIList& pList = GetSetting("list"); m_ItemsYPositions.resize(pList.m_Items.size() + 1); // Delete all generated texts. Some could probably be saved, @@ -48,15 +48,15 @@ void COList::SetupText() // continuously, or even often, so it'll probably be okay. m_GeneratedTexts.clear(); - const CStrW& font = GUI::GetSetting(this, "font"); - const bool scrollbar = GUI::GetSetting(this, "scrollbar"); + const CStrW& font = GetSetting("font"); + const bool scrollbar = GetSetting("scrollbar"); m_TotalAvailableColumnWidth = GetListRect().GetWidth(); // remove scrollbar if applicable if (scrollbar && GetScrollBar(0).GetStyle()) m_TotalAvailableColumnWidth -= GetScrollBar(0).GetStyle()->m_Width; - const float buffer_zone = GUI::GetSetting(this, "buffer_zone"); + const float buffer_zone = GetSetting("buffer_zone"); m_HeadingHeight = SORT_SPRITE_DIM; // At least the size of the sorting sprite @@ -86,7 +86,7 @@ void COList::SetupText() if (column.m_Width > 0 && column.m_Width < 1) width *= m_TotalAvailableColumnWidth; - CGUIList& pList_c = GUI::GetSetting(this, "list_" + column.m_Id); + CGUIList& pList_c = GetSetting("list_" + column.m_Id); CGUIText* text; if (!pList_c.m_Items[i].GetOriginalString().empty()) text = &AddText(pList_c.m_Items[i], font, width, buffer_zone, this); @@ -131,7 +131,7 @@ void COList::HandleMessage(SGUIMessage& Message) // If somebody clicks on the column heading case GUIM_MOUSE_PRESS_LEFT: { - if (!GUI::GetSetting(this, "sortable")) + if (!GetSetting("sortable")) return; const CPos& mouse = m_pGUI.GetMousePos(); @@ -139,13 +139,13 @@ void COList::HandleMessage(SGUIMessage& Message) return; // Copies, so that these settings are only modfied via SetSettings later. - CStr selectedColumn = GUI::GetSetting(this, "selected_column"); - int selectedColumnOrder = GUI::GetSetting(this, "selected_column_order"); + CStr selectedColumn = GetSetting("selected_column"); + int selectedColumnOrder = GetSetting("selected_column_order"); float xpos = 0; for (const COListColumn& column : m_Columns) { - if (GUI::GetSetting(this, "hidden_" + column.m_Id)) + if (GetSetting("hidden_" + column.m_Id)) continue; float width = column.m_Width; @@ -286,17 +286,17 @@ bool COList::HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile void COList::DrawList(const int& selected, const CStr& _sprite, const CStr& _sprite_selected, const CStr& _textcolor) { const float bz = GetBufferedZ(); - const bool scrollbar = GUI::GetSetting(this, "scrollbar"); + const bool scrollbar = GetSetting("scrollbar"); if (scrollbar) IGUIScrollBarOwner::Draw(); CRect rect = GetListRect(); - CGUISpriteInstance& sprite = GUI::GetSetting(this, _sprite); - CGUISpriteInstance& sprite_selectarea = GUI::GetSetting(this, _sprite_selected); + CGUISpriteInstance& sprite = GetSetting(_sprite); + CGUISpriteInstance& sprite_selectarea = GetSetting(_sprite_selected); - const int cell_id = GUI::GetSetting(this, "cell_id"); + const int cell_id = GetSetting("cell_id"); m_pGUI.DrawSprite(sprite, cell_id, bz, rect); @@ -339,21 +339,21 @@ void COList::DrawList(const int& selected, const CStr& _sprite, const CStr& _spr } // Draw line above column header - CGUISpriteInstance& sprite_heading = GUI::GetSetting(this, "sprite_heading"); + CGUISpriteInstance& sprite_heading = GetSetting("sprite_heading"); CRect rect_head(m_CachedActualSize.left, m_CachedActualSize.top, m_CachedActualSize.right, m_CachedActualSize.top + m_HeadingHeight); m_pGUI.DrawSprite(sprite_heading, cell_id, bz, rect_head); // Draw column headers - const bool sortable = GUI::GetSetting(this, "sortable"); - const CStr& selectedColumn = GUI::GetSetting(this, "selected_column"); - const int selectedColumnOrder = GUI::GetSetting(this, "selected_column_order"); - const CGUIColor& color = GUI::GetSetting(this, _textcolor); + const bool sortable = GetSetting("sortable"); + const CStr& selectedColumn = GetSetting("selected_column"); + const int selectedColumnOrder = GetSetting("selected_column_order"); + const CGUIColor& color = GetSetting(_textcolor); float xpos = 0; for (size_t col = 0; col < m_Columns.size(); ++col) { - if (GUI::GetSetting(this, "hidden_" + m_Columns[col].m_Id)) + if (GetSetting("hidden_" + m_Columns[col].m_Id)) continue; // Check if it's a decimal value, and if so, assume relative positioning. @@ -380,7 +380,7 @@ void COList::DrawList(const int& selected, const CStr& _sprite, const CStr& _spr else spriteName = "sprite_not_sorted"; - CGUISpriteInstance& sprite = GUI::GetSetting(this, spriteName); + CGUISpriteInstance& sprite = GetSetting(spriteName); m_pGUI.DrawSprite(sprite, cell_id, bz + 0.1f, CRect(leftTopCorner + CPos(width - SORT_SPRITE_DIM, 0), leftTopCorner + CPos(width, SORT_SPRITE_DIM))); } @@ -390,7 +390,7 @@ void COList::DrawList(const int& selected, const CStr& _sprite, const CStr& _spr } // Draw list items for each column - const CGUIList& pList = GUI::GetSetting(this, "list"); + const CGUIList& pList = GetSetting("list"); const size_t objectsCount = m_Columns.size(); for (size_t i = 0; i < pList.m_Items.size(); ++i) { @@ -418,7 +418,7 @@ void COList::DrawList(const int& selected, const CStr& _sprite, const CStr& _spr xpos = 0; for (size_t col = 0; col < objectsCount; ++col) { - if (GUI::GetSetting(this, "hidden_" + m_Columns[col].m_Id)) + if (GetSetting("hidden_" + m_Columns[col].m_Id)) continue; // Determine text position and width diff --git a/source/gui/CProgressBar.cpp b/source/gui/CProgressBar.cpp index a6fbc0f5d9..9298003eb2 100644 --- a/source/gui/CProgressBar.cpp +++ b/source/gui/CProgressBar.cpp @@ -48,7 +48,7 @@ void CProgressBar::HandleMessage(SGUIMessage& Message) // TODO Gee: (2004-09-01) Is this really updated each time it should? if (Message.value == CStr("caption")) { - const float value = GUI::GetSetting(this, "caption"); + const float value = GetSetting("caption"); if (value > 100.f) GUI::SetSetting(this, "caption", 100.f); else if (value < 0.f) @@ -62,13 +62,13 @@ void CProgressBar::HandleMessage(SGUIMessage& Message) void CProgressBar::Draw() { - CGUISpriteInstance& sprite_bar = GUI::GetSetting(this, "sprite_bar"); - CGUISpriteInstance& sprite_background = GUI::GetSetting(this, "sprite_background"); + CGUISpriteInstance& sprite_bar = GetSetting("sprite_bar"); + CGUISpriteInstance& sprite_background = GetSetting("sprite_background"); float bz = GetBufferedZ(); int cell_id = 0; - const float value = GUI::GetSetting(this, "caption"); + const float value = GetSetting("caption"); m_pGUI.DrawSprite(sprite_background, cell_id, bz, m_CachedActualSize); diff --git a/source/gui/CSlider.cpp b/source/gui/CSlider.cpp index 3101614e60..d5fcec6abc 100644 --- a/source/gui/CSlider.cpp +++ b/source/gui/CSlider.cpp @@ -32,10 +32,10 @@ CSlider::CSlider(CGUI& pGUI) AddSetting("sprite_bar"); AddSetting("button_width"); - m_Value = GUI::GetSetting(this, "value"); - m_MinValue = GUI::GetSetting(this, "min_value"); - m_MaxValue = GUI::GetSetting(this, "max_value"); - m_ButtonSide = GUI::GetSetting(this, "button_width"); + m_Value = GetSetting("value"); + m_MinValue = GetSetting("min_value"); + m_MaxValue = GetSetting("max_value"); + m_ButtonSide = GetSetting("button_width"); m_Value = Clamp(m_Value, m_MinValue, m_MaxValue); } @@ -61,10 +61,10 @@ void CSlider::HandleMessage(SGUIMessage& Message) { case GUIM_SETTINGS_UPDATED: { - m_Value = GUI::GetSetting(this, "value"); - m_MinValue = GUI::GetSetting(this, "min_value"); - m_MaxValue = GUI::GetSetting(this, "max_value"); - m_ButtonSide = GUI::GetSetting(this, "button_width"); + m_Value = GetSetting("value"); + m_MinValue = GetSetting("min_value"); + m_MaxValue = GetSetting("max_value"); + m_ButtonSide = GetSetting("button_width"); m_Value = Clamp(m_Value, m_MinValue, m_MaxValue); break; @@ -115,9 +115,9 @@ void CSlider::HandleMessage(SGUIMessage& Message) void CSlider::Draw() { - CGUISpriteInstance& sprite = GUI::GetSetting(this, "sprite_bar"); - CGUISpriteInstance& sprite_button = GUI::GetSetting(this, "sprite"); - const int cell_id = GUI::GetSetting(this, "cell_id"); + CGUISpriteInstance& sprite = GetSetting("sprite_bar"); + CGUISpriteInstance& sprite_button = GetSetting("sprite"); + const int cell_id = GetSetting("cell_id"); CRect slider_line(m_CachedActualSize); slider_line.left += m_ButtonSide / 2.0f; diff --git a/source/gui/CText.cpp b/source/gui/CText.cpp index de651af556..79dead3281 100644 --- a/source/gui/CText.cpp +++ b/source/gui/CText.cpp @@ -69,16 +69,16 @@ void CText::SetupText() if (m_GeneratedTexts.empty()) return; - const bool scrollbar = GUI::GetSetting(this, "scrollbar"); + const bool scrollbar = GetSetting("scrollbar"); float width = m_CachedActualSize.GetWidth(); // remove scrollbar if applicable if (scrollbar && GetScrollBar(0).GetStyle()) width -= GetScrollBar(0).GetStyle()->m_Width; - const CGUIString& caption = GUI::GetSetting(this, "caption"); - const CStrW& font = GUI::GetSetting(this, "font"); - const float buffer_zone = GUI::GetSetting(this, "buffer_zone"); + const CGUIString& caption = GetSetting("caption"); + const CStrW& font = GetSetting("font"); + const float buffer_zone = GetSetting("buffer_zone"); m_GeneratedTexts[0] = CGUIText(m_pGUI, caption, font, width, buffer_zone, this); @@ -88,8 +88,8 @@ void CText::SetupText() // Setup scrollbar if (scrollbar) { - const bool scroll_bottom = GUI::GetSetting(this, "scroll_bottom"); - const bool scroll_top = GUI::GetSetting(this, "scroll_top"); + const bool scroll_bottom = GetSetting("scroll_bottom"); + const bool scroll_top = GetSetting("scroll_top"); // If we are currently scrolled to the bottom of the text, // then add more lines of text, update the scrollbar so we @@ -128,7 +128,7 @@ void CText::HandleMessage(SGUIMessage& Message) // Update scrollbar if (Message.value == "scrollbar_style") { - GetScrollBar(0).SetScrollBarStyle(GUI::GetSetting(this, Message.value)); + GetScrollBar(0).SetScrollBarStyle(GetSetting(Message.value)); SetupText(); } @@ -158,7 +158,7 @@ void CText::HandleMessage(SGUIMessage& Message) GetScrollBar(0).SetY(m_CachedActualSize.top); GetScrollBar(0).SetZ(GetBufferedZ()); GetScrollBar(0).SetLength(m_CachedActualSize.bottom - m_CachedActualSize.top); - GetScrollBar(0).SetScrollBarStyle(GUI::GetSetting(this, "scrollbar_style")); + GetScrollBar(0).SetScrollBarStyle(GetSetting("scrollbar_style")); break; } @@ -173,14 +173,14 @@ void CText::Draw() { float bz = GetBufferedZ(); - const bool scrollbar = GUI::GetSetting(this, "scrollbar"); + const bool scrollbar = GetSetting("scrollbar"); if (scrollbar) IGUIScrollBarOwner::Draw(); - CGUISpriteInstance& sprite = GUI::GetSetting(this, "sprite"); - const int cell_id = GUI::GetSetting(this, "cell_id"); - const bool clip = GUI::GetSetting(this, "clip"); + CGUISpriteInstance& sprite = GetSetting("sprite"); + const int cell_id = GetSetting("cell_id"); + const bool clip = GetSetting("clip"); m_pGUI.DrawSprite(sprite, cell_id, bz, m_CachedActualSize); @@ -207,8 +207,8 @@ void CText::Draw() } } - const bool enabled = GUI::GetSetting(this, "enabled"); - const CGUIColor& color = GUI::GetSetting(this, enabled ? "textcolor" : "textcolor_disabled"); + const bool enabled = GetSetting("enabled"); + const CGUIColor& color = GetSetting(enabled ? "textcolor" : "textcolor_disabled"); if (scrollbar) DrawText(0, color, m_CachedActualSize.TopLeft() - CPos(0.f, scroll), bz + 0.1f, cliparea); diff --git a/source/gui/CTooltip.cpp b/source/gui/CTooltip.cpp index 76296ccdec..4db2aa9108 100644 --- a/source/gui/CTooltip.cpp +++ b/source/gui/CTooltip.cpp @@ -65,20 +65,20 @@ void CTooltip::SetupText() { ENSURE(m_GeneratedTexts.size() == 1); - const CGUIString& caption = GUI::GetSetting(this, "caption"); - const CStrW& font = GUI::GetSetting(this, "font"); - const float max_width = GUI::GetSetting(this, "maxwidth"); - const float buffer_zone = GUI::GetSetting(this, "buffer_zone"); + const CGUIString& caption = GetSetting("caption"); + const CStrW& font = GetSetting("font"); + const float max_width = GetSetting("maxwidth"); + const float buffer_zone = GetSetting("buffer_zone"); m_GeneratedTexts[0] = CGUIText(m_pGUI, caption, font, max_width, buffer_zone, this); // Position the tooltip relative to the mouse: - const CPos& mousepos = GUI::GetSetting(this, "independent") ? + const CPos& mousepos = GetSetting("independent") ? m_pGUI.GetMousePos() : - GUI::GetSetting(this, "_mousepos"); + GetSetting("_mousepos"); - const CPos& offset = GUI::GetSetting(this, "offset"); + const CPos& offset = GetSetting("offset"); float textwidth = m_GeneratedTexts[0].GetSize().cx; float textheight = m_GeneratedTexts[0].GetSize().cy; @@ -87,7 +87,7 @@ void CTooltip::SetupText() size.pixel.left = mousepos.x + offset.x; size.pixel.right = size.pixel.left + textwidth; - switch (GUI::GetSetting(this, "anchor")) + switch (GetSetting("anchor")) { case EVAlign_Top: size.pixel.top = mousepos.y + offset.y; @@ -135,7 +135,7 @@ void CTooltip::Draw() { float z = 900.f; // TODO: Find a nicer way of putting the tooltip on top of everything else - CGUISpriteInstance& sprite = GUI::GetSetting(this, "sprite"); + CGUISpriteInstance& sprite = GetSetting("sprite"); // Normally IGUITextOwner will handle this updating but since SetupText can modify the position // we need to call it now *before* we do the rest of the drawing @@ -147,6 +147,6 @@ void CTooltip::Draw() m_pGUI.DrawSprite(sprite, 0, z, m_CachedActualSize); - const CGUIColor& color = GUI::GetSetting(this, "textcolor"); + const CGUIColor& color = GetSetting("textcolor"); DrawText(0, color, m_CachedActualSize.TopLeft(), z+0.1f); } diff --git a/source/gui/GUITooltip.cpp b/source/gui/GUITooltip.cpp index 54baeb1fc5..158fc96c84 100644 --- a/source/gui/GUITooltip.cpp +++ b/source/gui/GUITooltip.cpp @@ -87,8 +87,8 @@ bool GUITooltip::GetTooltip(IGUIObject* obj, CStr& style) { if (obj && obj->SettingExists("_icon_tooltip_style") && obj->MouseOverIcon()) { - style = GUI::GetSetting(obj, "_icon_tooltip_style"); - if (!GUI::GetSetting(obj, "_icon_tooltip").empty()) + style = obj->GetSetting("_icon_tooltip_style"); + if (!obj->GetSetting("_icon_tooltip").empty()) { if (style.empty()) style = "default"; @@ -99,8 +99,8 @@ bool GUITooltip::GetTooltip(IGUIObject* obj, CStr& style) if (obj && obj->SettingExists("tooltip_style")) { - style = GUI::GetSetting(obj, "tooltip_style"); - if (!GUI::GetSetting(obj, "tooltip").empty()) + style = obj->GetSetting("tooltip_style"); + if (!obj->GetSetting("tooltip").empty()) { if (style.empty()) style = "default"; @@ -128,7 +128,7 @@ void GUITooltip::ShowTooltip(IGUIObject* obj, const CPos& pos, const CStr& style IGUIObject* usedobj = tooltipobj; // object actually used to display the tooltip in - const CStr& usedObjectName = GUI::GetSetting(tooltipobj, "use_object"); + const CStr& usedObjectName = tooltipobj->GetSetting("use_object"); if (!usedObjectName.empty()) { usedobj = pGUI.FindObjectByName(usedObjectName); @@ -143,7 +143,7 @@ void GUITooltip::ShowTooltip(IGUIObject* obj, const CPos& pos, const CStr& style GUI::SetSetting(usedobj, "hidden", false); - const CStrW& text = GUI::GetSetting(obj, m_IsIconTooltip ? "_icon_tooltip" : "tooltip"); + const CStrW& text = obj->GetSetting(m_IsIconTooltip ? "_icon_tooltip" : "tooltip"); if (usedobj->SetSetting("caption", text) != PSRETURN_OK) debug_warn(L"Failed to set tooltip caption"); @@ -164,7 +164,7 @@ void GUITooltip::HideTooltip(const CStr& style, CGUI& pGUI) return; } - const CStr& usedObjectName = GUI::GetSetting(tooltipobj, "use_object"); + const CStr& usedObjectName = tooltipobj->GetSetting("use_object"); if (!usedObjectName.empty()) { IGUIObject* usedobj = pGUI.FindObjectByName(usedObjectName); @@ -178,14 +178,14 @@ void GUITooltip::HideTooltip(const CStr& style, CGUI& pGUI) SGUIMessage msg(GUIM_SETTINGS_UPDATED, "caption"); usedobj->HandleMessage(msg); - if (GUI::GetSetting(tooltipobj, "hide_object")) + if (tooltipobj->GetSetting("hide_object")) GUI::SetSetting(usedobj, "hidden", true); } else GUI::SetSetting(tooltipobj, "hidden", true); } -static int GetTooltipDelay(const CStr& style, CGUI& pGUI) +static i32 GetTooltipDelay(const CStr& style, CGUI& pGUI) { IGUIObject* tooltipobj = pGUI.FindObjectByName("__tooltip_" + style); @@ -195,7 +195,7 @@ static int GetTooltipDelay(const CStr& style, CGUI& pGUI) return 500; } - return GUI::GetSetting(tooltipobj, "delay"); + return tooltipobj->GetSetting("delay"); } void GUITooltip::Update(IGUIObject* Nearest, const CPos& MousePos, CGUI& GUI) diff --git a/source/gui/GUIutil.cpp b/source/gui/GUIutil.cpp index d77a11c8df..14cd673ab5 100644 --- a/source/gui/GUIutil.cpp +++ b/source/gui/GUIutil.cpp @@ -80,12 +80,6 @@ void CGUISetting::ToJSVal(JSContext* cx, JS::MutableHandleValue Value) ScriptInterface::ToJSVal(cx, Value, m_pSetting); }; -template -T& GUI::GetSetting(const IGUIObject* pObject, const CStr& Setting) -{ - return static_cast* >(pObject->m_Settings.at(Setting))->m_pSetting; -} - template PSRETURN GUI::SetSetting(IGUIObject* pObject, const CStr& Setting, T& Value, const bool& SkipMessage) { @@ -129,7 +123,7 @@ PSRETURN GUI::SetSettingWrap(IGUIObject* pObject, const CStr& Setting, const else if (Setting == "hidden") { // Hiding an object requires us to reset it and all children - if (GUI::GetSetting(pObject, Setting)) + if (pObject->GetSetting(Setting)) pObject->RecurseObject(nullptr, &IGUIObject::ResetStates); } @@ -145,7 +139,6 @@ PSRETURN GUI::SetSettingWrap(IGUIObject* pObject, const CStr& Setting, const // Instantiate templated functions: // These functions avoid copies by working with a reference and move semantics. #define TYPE(T) \ - template T& GUI::GetSetting(const IGUIObject* pObject, const CStr& Setting); \ template PSRETURN GUI::SetSetting(IGUIObject* pObject, const CStr& Setting, T& Value, const bool& SkipMessage); \ template class CGUISetting; \ diff --git a/source/gui/GUIutil.h b/source/gui/GUIutil.h index 4032621098..fd6c657fd8 100644 --- a/source/gui/GUIutil.h +++ b/source/gui/GUIutil.h @@ -79,7 +79,9 @@ public: */ void ToJSVal(JSContext* cx, JS::MutableHandleValue Value) override; -private: + /** + * These members are public because they are either unmodifiable or free to be modified. + */ /** * The object that stores this setting. @@ -92,7 +94,7 @@ private: const CStr m_Name; /** - * Holds the value of the setting.. + * Holds the value of the setting. */ T m_pSetting; }; @@ -107,15 +109,6 @@ class GUI public: NONCOPYABLE(GUI); - /** - * Get a mutable reference to the setting. - * If no such setting exists, an exception of type std::out_of_range is thrown. - * Use SettingExists if a safeguard is needed. - * - * If the value is modified, there is no GUIM_SETTINGS_UPDATED message sent. - * SetSetting should be used to modify the value if there is a use for the message. - */ - static T& GetSetting(const IGUIObject* pObject, const CStr& Setting); /** * Sets a value by name using a real datatype as input. diff --git a/source/gui/IGUIButtonBehavior.cpp b/source/gui/IGUIButtonBehavior.cpp index 8f43f3aa29..63ce70e1d1 100644 --- a/source/gui/IGUIButtonBehavior.cpp +++ b/source/gui/IGUIButtonBehavior.cpp @@ -32,7 +32,7 @@ IGUIButtonBehavior::~IGUIButtonBehavior() void IGUIButtonBehavior::HandleMessage(SGUIMessage& Message) { - const bool enabled = GUI::GetSetting(this, "enabled"); + const bool enabled = GetSetting("enabled"); CStrW soundPath; // TODO Gee: easier access functions @@ -121,17 +121,17 @@ void IGUIButtonBehavior::HandleMessage(SGUIMessage& Message) const CGUIColor& IGUIButtonBehavior::ChooseColor() { // Yes, the object must possess these settings. They are standard - const CGUIColor& color = GUI::GetSetting(this, "textcolor"); + const CGUIColor& color = GetSetting("textcolor"); - if (!GUI::GetSetting(this, "enabled")) - return GUI::GetSetting(this, "textcolor_disabled") || color; + if (!GetSetting("enabled")) + return GetSetting("textcolor_disabled") || color; if (m_MouseHovering) { if (m_Pressed) - return GUI::GetSetting(this, "textcolor_pressed") || color; + return GetSetting("textcolor_pressed") || color; else - return GUI::GetSetting(this, "textcolor_over") || color; + return GetSetting("textcolor_over") || color; } return color; @@ -139,7 +139,7 @@ const CGUIColor& IGUIButtonBehavior::ChooseColor() void IGUIButtonBehavior::DrawButton(const CRect& rect, const float& z, CGUISpriteInstance& sprite, CGUISpriteInstance& sprite_over, CGUISpriteInstance& sprite_pressed, CGUISpriteInstance& sprite_disabled, int cell_id) { - if (!GUI::GetSetting(this, "enabled")) + if (!GetSetting("enabled")) m_pGUI.DrawSprite(sprite_disabled || sprite, cell_id, z, rect); else if (m_MouseHovering) { diff --git a/source/gui/IGUIObject.cpp b/source/gui/IGUIObject.cpp index adab56727e..e9d34a677c 100644 --- a/source/gui/IGUIObject.cpp +++ b/source/gui/IGUIObject.cpp @@ -128,6 +128,23 @@ void IGUIObject::AddSetting(const CStr& Name) m_Settings[Name] = new CGUISetting(*this, Name); } +bool IGUIObject::SettingExists(const CStr& Setting) const +{ + return m_Settings.count(Setting) == 1; +} + +template +T& IGUIObject::GetSetting(const CStr& Setting) +{ + return static_cast* >(m_Settings.at(Setting))->m_pSetting; +} + +template +const T& IGUIObject::GetSetting(const CStr& Setting) const +{ + return static_cast* >(m_Settings.at(Setting))->m_pSetting; +} + bool IGUIObject::IsMouseOver() const { return m_CachedActualSize.PointInside(m_pGUI.GetMousePos()); @@ -159,11 +176,6 @@ void IGUIObject::UpdateMouseOver(IGUIObject* const& pMouseOver) } } -bool IGUIObject::SettingExists(const CStr& Setting) const -{ - return m_Settings.count(Setting) == 1; -} - PSRETURN IGUIObject::SetSetting(const CStr& Setting, const CStrW& Value, const bool& SkipMessage) { if (!SettingExists(Setting)) @@ -216,13 +228,13 @@ void IGUIObject::ResetStates() void IGUIObject::UpdateCachedSize() { - const CClientArea& ca = GUI::GetSetting(this, "size"); - const float aspectratio = GUI::GetSetting(this, "aspectratio"); + const CClientArea& ca = GetSetting("size"); + const float aspectratio = GetSetting("aspectratio"); // If absolute="false" and the object has got a parent, // use its cached size instead of the screen. Notice // it must have just been cached for it to work. - if (!GUI::GetSetting(this, "absolute") && m_pParent && !IsRootObject()) + if (!GetSetting("absolute") && m_pParent && !IsRootObject()) m_CachedActualSize = ca.GetClientArea(m_pParent->m_CachedActualSize); else m_CachedActualSize = ca.GetClientArea(CRect(0.f, 0.f, g_xres / g_GuiScale, g_yres / g_GuiScale)); @@ -274,9 +286,9 @@ void IGUIObject::LoadStyle(const SGUIStyle& Style) float IGUIObject::GetBufferedZ() const { - const float Z = GUI::GetSetting(this, "z"); + const float Z = GetSetting("z"); - if (GUI::GetSetting(this, "absolute")) + if (GetSetting("absolute")) return Z; { @@ -421,13 +433,13 @@ bool IGUIObject::IsHidden() const // Statically initialise some strings, so we don't have to do // lots of allocation every time this function is called static const CStr strHidden("hidden"); - return GUI::GetSetting(this, strHidden); + return GetSetting(strHidden); } bool IGUIObject::IsHiddenOrGhost() const { static const CStr strGhost("ghost"); - return IsHidden() || GUI::GetSetting(this, strGhost); + return IsHidden() || GetSetting(strGhost); } void IGUIObject::PlaySound(const CStr& settingName) const @@ -435,7 +447,7 @@ void IGUIObject::PlaySound(const CStr& settingName) const if (!g_SoundManager) return; - const CStrW& soundPath = GUI::GetSetting(this, settingName); + const CStrW& soundPath = GetSetting(settingName); if (!soundPath.empty()) g_SoundManager->PlayAsUI(soundPath.c_str(), false); @@ -478,6 +490,11 @@ void IGUIObject::TraceMember(JSTracer* trc) } // Instantiate templated functions: -#define TYPE(T) template void IGUIObject::AddSetting(const CStr& Name); -#include "GUItypes.h" +#define TYPE(T) \ + template void IGUIObject::AddSetting(const CStr& Name); \ + template T& IGUIObject::GetSetting(const CStr& Setting); \ + template const T& IGUIObject::GetSetting(const CStr& Setting) const; \ + +#include "gui/GUItypes.h" + #undef TYPE diff --git a/source/gui/IGUIObject.h b/source/gui/IGUIObject.h index d0efae63ca..357c347eb7 100644 --- a/source/gui/IGUIObject.h +++ b/source/gui/IGUIObject.h @@ -148,6 +148,17 @@ public: */ bool SettingExists(const CStr& Setting) const; + /** + * Get a mutable reference to the setting. + * If no such setting exists, an exception of type std::out_of_range is thrown. + * If the value is modified, there is no GUIM_SETTINGS_UPDATED message sent. + */ + template + T& GetSetting(const CStr& Setting); + + template + const T& GetSetting(const CStr& Setting) const; + /** * Returns whether this is object is set to be hidden. */ diff --git a/source/gui/IGUITextOwner.cpp b/source/gui/IGUITextOwner.cpp index c678d08a28..bb0d348ec2 100644 --- a/source/gui/IGUITextOwner.cpp +++ b/source/gui/IGUITextOwner.cpp @@ -107,7 +107,7 @@ void IGUITextOwner::CalculateTextPosition(CRect& ObjSize, CPos& TextPos, CGUITex // loop through all of the TextCall objects again. TextPos.x = ObjSize.left; - switch (GUI::GetSetting(this, "text_valign")) + switch (GetSetting("text_valign")) { case EVAlign_Top: TextPos.y = ObjSize.top;