diff --git a/source/gui/CButton.cpp b/source/gui/CButton.cpp index d0f8a918a5..403acacaaf 100644 --- a/source/gui/CButton.cpp +++ b/source/gui/CButton.cpp @@ -58,18 +58,13 @@ void CButton::SetupText() { ENSURE(m_GeneratedTexts.size() == 1); - CStrW font; - if (GUI::GetSetting(this, "font", font) != PSRETURN_OK || font.empty()) - // Use the default if none is specified - // TODO Gee: (2004-08-14) Default should not be hard-coded, but be in styles! - font = L"default"; - - const CGUIString& caption = GUI::GetSetting(this, "caption"); - - float buffer_zone = 0.f; - GUI::GetSetting(this, "buffer_zone", buffer_zone); - - m_GeneratedTexts[0] = CGUIText(m_pGUI, caption, font, m_CachedActualSize.GetWidth(), buffer_zone, this); + m_GeneratedTexts[0] = CGUIText( + m_pGUI, + GUI::GetSetting(this, "caption"), + GUI::GetSetting(this, "font"), + m_CachedActualSize.GetWidth(), + GUI::GetSetting(this, "buffer_zone"), + this); CalculateTextPosition(m_CachedActualSize, m_TextPos, m_GeneratedTexts[0]); } @@ -83,9 +78,7 @@ void CButton::HandleMessage(SGUIMessage& Message) void CButton::Draw() { - float bz = GetBufferedZ(); - - int cell_id; + const float bz = GetBufferedZ(); // Statically initialise some strings, so we don't have to do // lots of allocation every time this function is called @@ -100,7 +93,7 @@ void CButton::Draw() CGUISpriteInstance& sprite_pressed = GUI::GetSetting(this, strSpritePressed); CGUISpriteInstance& sprite_disabled = GUI::GetSetting(this, strSpriteDisabled); - GUI::GetSetting(this, strCellId, cell_id); + const int cell_id = GUI::GetSetting(this, 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 2c42b0b14a..577f0d925a 100644 --- a/source/gui/CChart.cpp +++ b/source/gui/CChart.cpp @@ -44,9 +44,9 @@ CChart::CChart(CGUI& pGUI) AddSetting("series"); AddSetting("text_align"); - GUI::GetSetting(this, "axis_width", m_AxisWidth); - GUI::GetSetting(this, "format_x", m_FormatX); - GUI::GetSetting(this, "format_y", m_FormatY); + m_AxisWidth = GUI::GetSetting(this, "axis_width"); + m_FormatX = GUI::GetSetting(this, "format_x"); + m_FormatY = GUI::GetSetting(this, "format_y"); } CChart::~CChart() @@ -60,9 +60,9 @@ void CChart::HandleMessage(SGUIMessage& Message) { case GUIM_SETTINGS_UPDATED: { - GUI::GetSetting(this, "axis_width", m_AxisWidth); - GUI::GetSetting(this, "format_x", m_FormatX); - GUI::GetSetting(this, "format_y", m_FormatY); + m_AxisWidth = GUI::GetSetting(this, "axis_width"); + m_FormatX = GUI::GetSetting(this, "format_x"); + m_FormatY = GUI::GetSetting(this, "format_y"); UpdateSeries(); break; @@ -210,12 +210,10 @@ void CChart::SetupText() return; const CStrW& font = GUI::GetSetting(this, "font"); - - float buffer_zone = 0.f; - GUI::GetSetting(this, "buffer_zone", buffer_zone); + const float buffer_zone = GUI::GetSetting(this, "buffer_zone"); // Add Y-axis - GUI::GetSetting(this, "format_y", m_FormatY); + m_FormatY = GUI::GetSetting(this, "format_y"); const float height = GetChartRect().GetHeight(); // TODO: split values depend on the format; if (m_EqualY) @@ -232,7 +230,7 @@ void CChart::SetupText() } // Add X-axis - GUI::GetSetting(this, "format_x", m_FormatX); + m_FormatX = GUI::GetSetting(this, "format_x"); const float width = GetChartRect().GetWidth(); if (m_EqualX) { diff --git a/source/gui/CCheckBox.cpp b/source/gui/CCheckBox.cpp index 65a8716882..67266a2b2e 100644 --- a/source/gui/CCheckBox.cpp +++ b/source/gui/CCheckBox.cpp @@ -68,15 +68,13 @@ void CCheckBox::SetupText() { ENSURE(m_GeneratedTexts.size() == 1); - float square_side; - GUI::GetSetting(this, "square_side", square_side); - - const CGUIString& caption = GUI::GetSetting(this, "caption"); - const CStrW& font = GUI::GetSetting(this, "font"); - - float buffer_zone = 0.f; - GUI::GetSetting(this, "buffer_zone", buffer_zone); - m_GeneratedTexts[0] = CGUIText(m_pGUI, caption, font, m_CachedActualSize.GetWidth() - square_side, 0.f, this); + 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"), + this); } void CCheckBox::HandleMessage(SGUIMessage& Message) @@ -89,12 +87,8 @@ void CCheckBox::HandleMessage(SGUIMessage& Message) { case GUIM_PRESSED: { - bool checked; - // Switch to opposite. - GUI::GetSetting(this, "checked", checked); - checked = !checked; - GUI::SetSetting(this, "checked", checked); + GUI::SetSetting(this, "checked", !GUI::GetSetting(this, "checked")); break; } diff --git a/source/gui/CDropDown.cpp b/source/gui/CDropDown.cpp index 2e5e83d25f..ca10d8eae2 100644 --- a/source/gui/CDropDown.cpp +++ b/source/gui/CDropDown.cpp @@ -107,12 +107,9 @@ void CDropDown::HandleMessage(SGUIMessage& Message) if (!GetListRect().PointInside(mouse)) break; - bool scrollbar; const CGUIList& pList = GUI::GetSetting(this, "list"); - GUI::GetSetting(this, "scrollbar", scrollbar); - float scroll = 0.f; - if (scrollbar) - scroll = GetScrollBar(0).GetPos(); + const bool scrollbar = GUI::GetSetting(this, "scrollbar"); + const float scroll = scrollbar ? GetScrollBar(0).GetPos() : 0.f; CRect rect = GetListRect(); mouse.y += scroll; @@ -141,20 +138,16 @@ void CDropDown::HandleMessage(SGUIMessage& Message) case GUIM_MOUSE_ENTER: { - bool enabled; - GUI::GetSetting(this, "enabled", enabled); - if (enabled) + if (GUI::GetSetting(this, "enabled")) PlaySound("sound_enter"); break; } case GUIM_MOUSE_LEAVE: { - GUI::GetSetting(this, "selected", m_ElementHighlight); + m_ElementHighlight = GUI::GetSetting(this, "selected"); - bool enabled; - GUI::GetSetting(this, "enabled", enabled); - if (enabled) + if (GUI::GetSetting(this, "enabled")) PlaySound("sound_leave"); break; } @@ -163,9 +156,7 @@ void CDropDown::HandleMessage(SGUIMessage& Message) // a mouse click to open the dropdown, also the coordinates are changed. case GUIM_MOUSE_PRESS_LEFT: { - bool enabled; - GUI::GetSetting(this, "enabled", enabled); - if (!enabled) + if (!GUI::GetSetting(this, "enabled")) { PlaySound("sound_disabled"); break; @@ -179,7 +170,7 @@ void CDropDown::HandleMessage(SGUIMessage& Message) m_Open = true; GetScrollBar(0).SetZ(GetBufferedZ()); - GUI::GetSetting(this, "selected", m_ElementHighlight); + m_ElementHighlight = GUI::GetSetting(this, "selected"); // Start at the position of the selected item, if possible. GetScrollBar(0).SetPos(m_ItemsYPositions.empty() ? 0 : m_ItemsYPositions[m_ElementHighlight] - 60); @@ -214,14 +205,12 @@ void CDropDown::HandleMessage(SGUIMessage& Message) case GUIM_MOUSE_WHEEL_DOWN: { - bool enabled; - GUI::GetSetting(this, "enabled", enabled); - // Don't switch elements by scrolling when open, causes a confusing interaction between this and the scrollbar. - if (m_Open || !enabled) + if (m_Open || !GUI::GetSetting(this, "enabled")) break; - GUI::GetSetting(this, "selected", m_ElementHighlight); + m_ElementHighlight = GUI::GetSetting(this, "selected"); + if (m_ElementHighlight + 1 >= (int)m_ItemsYPositions.size() - 1) break; @@ -232,14 +221,11 @@ void CDropDown::HandleMessage(SGUIMessage& Message) case GUIM_MOUSE_WHEEL_UP: { - bool enabled; - GUI::GetSetting(this, "enabled", enabled); - // Don't switch elements by scrolling when open, causes a confusing interaction between this and the scrollbar. - if (m_Open || !enabled) + if (m_Open || !GUI::GetSetting(this, "enabled")) break; - GUI::GetSetting(this, "selected", m_ElementHighlight); + m_ElementHighlight = GUI::GetSetting(this, "selected"); if (m_ElementHighlight - 1 < 0) break; @@ -362,7 +348,7 @@ InReaction CDropDown::ManuallyHandleEvent(const SDL_Event_* ev) result = IN_HANDLED; if (update_highlight) - GUI::GetSetting(this, "selected", m_ElementHighlight); + m_ElementHighlight = GUI::GetSetting(this, "selected"); return result; } @@ -371,12 +357,11 @@ void CDropDown::SetupListRect() { extern int g_yres; extern float g_GuiScale; - float size, buffer, yres; - yres = g_yres / g_GuiScale; - u32 minimumVisibleItems; - GUI::GetSetting(this, "dropdown_size", size); - GUI::GetSetting(this, "dropdown_buffer", buffer); - GUI::GetSetting(this, "minimum_visible_items", minimumVisibleItems); + 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"); if (m_ItemsYPositions.empty()) { @@ -448,23 +433,14 @@ bool CDropDown::IsMouseOver() const void CDropDown::Draw() { - float bz = GetBufferedZ(); - - float dropdown_size, button_width; - GUI::GetSetting(this, "dropdown_size", dropdown_size); - GUI::GetSetting(this, "button_width", button_width); - - int cell_id, selected = 0; - - bool enabled; - GUI::GetSetting(this, "enabled", enabled); - + 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"); - GUI::GetSetting(this, "cell_id", cell_id); - GUI::GetSetting(this, "selected", selected); - m_pGUI.DrawSprite(sprite, cell_id, bz, m_CachedActualSize); if (button_width > 0.f) diff --git a/source/gui/CGUI.cpp b/source/gui/CGUI.cpp index f7531dec44..c51f366de3 100644 --- a/source/gui/CGUI.cpp +++ b/source/gui/CGUI.cpp @@ -864,10 +864,7 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec if (!ManuallySetZ) { // Set it automatically to 10 plus its parents - bool absolute; - GUI::GetSetting(object, "absolute", absolute); - - if (absolute) + if (GUI::GetSetting(object, "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 5204c0a3f6..909f502251 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")) - GUI::GetSetting(pObject, "text_align", align); + align = GUI::GetSetting(pObject, "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 4ffc582dfd..42098857a8 100644 --- a/source/gui/CImage.cpp +++ b/source/gui/CImage.cpp @@ -38,11 +38,9 @@ CImage::~CImage() void CImage::Draw() { - float bz = GetBufferedZ(); - - int cell_id; - GUI::GetSetting(this, "cell_id", cell_id); - - CGUISpriteInstance& sprite = GUI::GetSetting(this, "sprite"); - m_pGUI.DrawSprite(sprite, cell_id, bz, m_CachedActualSize); + m_pGUI.DrawSprite( + GUI::GetSetting(this, "sprite"), + GUI::GetSetting(this, "cell_id"), + GetBufferedZ(), + m_CachedActualSize); } diff --git a/source/gui/CInput.cpp b/source/gui/CInput.cpp index eff3375503..a26bc0efab 100644 --- a/source/gui/CInput.cpp +++ b/source/gui/CInput.cpp @@ -287,9 +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. - bool multiline; - GUI::GetSetting(this, "multiline", multiline); - if (!multiline) + if (!GUI::GetSetting(this, "multiline")) { SendEvent(GUIM_PRESSED, "press"); break; @@ -306,8 +304,7 @@ void CInput::ManuallyMutableHandleKeyDownEvent(const SDL_Keycode keyCode, CStrW& return; // check max length - int max_length; - GUI::GetSetting(this, "max_length", max_length); + const int max_length = GUI::GetSetting(this, "max_length"); if (max_length != 0 && static_cast(pCaption.length()) >= max_length) break; @@ -839,12 +836,9 @@ void CInput::HandleMessage(SGUIMessage& Message) { case GUIM_SETTINGS_UPDATED: { - bool scrollbar; - GUI::GetSetting(this, "scrollbar", scrollbar); - // Update scroll-bar // TODO Gee: (2004-09-01) Is this really updated each time it should? - if (scrollbar && + if (GUI::GetSetting(this, "scrollbar") && (Message.value == CStr("size") || Message.value == CStr("z") || Message.value == CStr("absolute"))) @@ -858,15 +852,12 @@ void CInput::HandleMessage(SGUIMessage& Message) // Update scrollbar if (Message.value == CStr("scrollbar_style")) { - CStr scrollbar_style; - GUI::GetSetting(this, Message.value, scrollbar_style); - - GetScrollBar(0).SetScrollBarStyle(scrollbar_style); + GetScrollBar(0).SetScrollBarStyle(GUI::GetSetting(this, Message.value)); } if (Message.value == CStr("buffer_position")) { - GUI::GetSetting(this, Message.value, m_iBufferPos); + m_iBufferPos = GUI::GetSetting(this, Message.value); m_iBufferPos_Tail = -1; // position change resets selection } @@ -883,10 +874,7 @@ void CInput::HandleMessage(SGUIMessage& Message) if (Message.value == CStr("multiline")) { - bool multiline; - GUI::GetSetting(this, "multiline", multiline); - - if (!multiline) + if (!GUI::GetSetting(this, "multiline")) GetScrollBar(0).SetLength(0.f); else GetScrollBar(0).SetLength(m_CachedActualSize.bottom - m_CachedActualSize.top); @@ -897,18 +885,16 @@ void CInput::HandleMessage(SGUIMessage& Message) UpdateAutoScroll(); if (Message.value == CStr("readonly")) - GUI::GetSetting(this, "readonly", m_Readonly); + m_Readonly = GUI::GetSetting(this, "readonly"); break; } case GUIM_MOUSE_PRESS_LEFT: { - bool scrollbar, multiline; - GUI::GetSetting(this, "scrollbar", scrollbar); - GUI::GetSetting(this, "multiline", multiline); - // Check if we're selecting the scrollbar - if (GetScrollBar(0).GetStyle() && multiline) + if (GUI::GetSetting(this, "scrollbar") && + GUI::GetSetting(this, "multiline") && + GetScrollBar(0).GetStyle()) { if (m_pGUI.GetMousePos().x > m_CachedActualSize.right - GetScrollBar(0).GetStyle()->m_Width) break; @@ -1073,15 +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); - - CStr scrollbar_style; - GUI::GetSetting(this, "scrollbar_style", scrollbar_style); - GetScrollBar(0).SetScrollBarStyle(scrollbar_style); + GetScrollBar(0).SetScrollBarStyle(GUI::GetSetting(this, "scrollbar_style")); UpdateText(); UpdateAutoScroll(); - GUI::GetSetting(this, "readonly", m_Readonly); + m_Readonly = GUI::GetSetting(this, "readonly"); break; } case GUIM_GOT_FOCUS: @@ -1133,9 +1116,7 @@ void CInput::UpdateCachedSize() IGUIObject::UpdateCachedSize(); - bool scrollbar; - GUI::GetSetting(this, "scrollbar", scrollbar); - if (scrollbar) + if (GUI::GetSetting(this, "scrollbar")) { GetScrollBar(0).SetX(m_CachedActualSize.right); GetScrollBar(0).SetY(m_CachedActualSize.top); @@ -1163,30 +1144,25 @@ void CInput::Draw() m_CursorVisState = true; // First call draw on ScrollBarOwner - bool scrollbar; - float buffer_zone; - bool multiline; - bool mask; - GUI::GetSetting(this, "scrollbar", scrollbar); - GUI::GetSetting(this, "buffer_zone", buffer_zone); - GUI::GetSetting(this, "multiline", multiline); - GUI::GetSetting(this, "mask", mask); + 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"); if (scrollbar && multiline) IGUIScrollBarOwner::Draw(); - CStrW font_name_w; - GUI::GetSetting(this, "font", font_name_w); const CGUIColor& color = GUI::GetSetting(this, "textcolor"); const CGUIColor& color_selected = GUI::GetSetting(this, "textcolor_selected"); - CStrIntern font_name(font_name_w.ToUTF8()); + + CStrIntern font_name(GUI::GetSetting(this, "font").ToUTF8()); const CStrW& pCaption = GUI::GetSetting(this, "caption"); wchar_t mask_char = L'*'; if (mask) { - CStrW maskStr; - GUI::GetSetting(this, "mask_char", maskStr); + const CStrW& maskStr = GUI::GetSetting(this, "mask_char"); + if (maskStr.length() > 0) mask_char = maskStr[0]; } @@ -1194,8 +1170,7 @@ void CInput::Draw() CGUISpriteInstance& sprite = GUI::GetSetting(this, "sprite"); CGUISpriteInstance& sprite_selectarea = GUI::GetSetting(this, "sprite_selectarea"); - int cell_id; - GUI::GetSetting(this, "cell_id", cell_id); + const int cell_id = GUI::GetSetting(this, "cell_id"); m_pGUI.DrawSprite(sprite, cell_id, bz, m_CachedActualSize); @@ -1515,23 +1490,16 @@ void CInput::Draw() void CInput::UpdateText(int from, int to_before, int to_after) { - CStrW caption; - CStrW font_name_w; - float buffer_zone; - bool multiline; - bool mask; - GUI::GetSetting(this, "font", font_name_w); - GUI::GetSetting(this, "caption", caption); - GUI::GetSetting(this, "buffer_zone", buffer_zone); - GUI::GetSetting(this, "multiline", multiline); - GUI::GetSetting(this, "mask", mask); - CStrIntern font_name(font_name_w.ToUTF8()); + 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()); wchar_t mask_char = L'*'; if (mask) { - CStrW maskStr; - GUI::GetSetting(this, "mask_char", maskStr); + const CStrW& maskStr = GUI::GetSetting(this, "mask_char"); if (maskStr.length() > 0) mask_char = maskStr[0]; } @@ -1868,9 +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); - bool scrollbar; - GUI::GetSetting(this, "scrollbar", scrollbar); - if (scrollbar) + if (GUI::GetSetting(this, "scrollbar")) { GetScrollBar(0).SetScrollRange(m_CharacterPositions.size() * font.GetLineSpacing() + buffer_zone*2.f); GetScrollBar(0).SetScrollSpace(m_CachedActualSize.GetHeight()); @@ -1882,33 +1848,25 @@ 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"); + // Return position int retPosition; - float buffer_zone; - bool multiline; - GUI::GetSetting(this, "buffer_zone", buffer_zone); - GUI::GetSetting(this, "multiline", multiline); - std::list::const_iterator current = m_CharacterPositions.begin(); CPos mouse = m_pGUI.GetMousePos(); if (multiline) { - CStrW font_name_w; - bool scrollbar; - GUI::GetSetting(this, "font", font_name_w); - GUI::GetSetting(this, "scrollbar", scrollbar); - CStrIntern font_name(font_name_w.ToUTF8()); - float scroll = 0.f; - if (scrollbar) + if (GUI::GetSetting(this, "scrollbar")) scroll = GetScrollBarPos(0); // Now get the height of the font. // TODO: Get the real font - CFontMetrics font(font_name); + CFontMetrics font(CStrIntern(GUI::GetSetting(this, "font").ToUTF8())); float spacing = (float)font.GetLineSpacing(); // Change mouse position relative to text. @@ -2021,12 +1979,9 @@ bool CInput::SelectingText() const float CInput::GetTextAreaWidth() { - bool scrollbar; - float buffer_zone; - GUI::GetSetting(this, "scrollbar", scrollbar); - GUI::GetSetting(this, "buffer_zone", buffer_zone); + const float buffer_zone = GUI::GetSetting(this, "buffer_zone"); - if (scrollbar && GetScrollBar(0).GetStyle()) + if (GUI::GetSetting(this, "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; @@ -2034,29 +1989,19 @@ float CInput::GetTextAreaWidth() void CInput::UpdateAutoScroll() { - float buffer_zone; - bool multiline; - GUI::GetSetting(this, "buffer_zone", buffer_zone); - GUI::GetSetting(this, "multiline", multiline); + const float buffer_zone = GUI::GetSetting(this, "buffer_zone"); // Autoscrolling up and down - if (multiline) + if (GUI::GetSetting(this, "multiline")) { - CStrW font_name_w; - bool scrollbar; - GUI::GetSetting(this, "font", font_name_w); - GUI::GetSetting(this, "scrollbar", scrollbar); - CStrIntern font_name(font_name_w.ToUTF8()); - - float scroll = 0.f; - if (!scrollbar) + if (!GUI::GetSetting(this, "scrollbar")) return; - scroll = GetScrollBar(0).GetPos(); + const float scroll = GetScrollBar(0).GetPos(); // Now get the height of the font. // TODO: Get the real font - CFontMetrics font(font_name); + CFontMetrics font(CStrIntern(GUI::GetSetting(this, "font").ToUTF8())); float spacing = (float)font.GetLineSpacing(); //float height = font.GetHeight(); diff --git a/source/gui/CList.cpp b/source/gui/CList.cpp index 89b655c46a..bb25d48175 100644 --- a/source/gui/CList.cpp +++ b/source/gui/CList.cpp @@ -83,16 +83,14 @@ void CList::SetupText() const CStrW& font = GUI::GetSetting(this, "font"); - bool scrollbar; - GUI::GetSetting(this, "scrollbar", scrollbar); + const bool scrollbar = GUI::GetSetting(this, "scrollbar"); float width = GetListRect().GetWidth(); // remove scrollbar if applicable if (scrollbar && GetScrollBar(0).GetStyle()) width -= GetScrollBar(0).GetStyle()->m_Width; - float buffer_zone = 0.f; - GUI::GetSetting(this, "buffer_zone", buffer_zone); + const float buffer_zone = GUI::GetSetting(this, "buffer_zone"); // Generate texts float buffered_y = 0.f; @@ -148,11 +146,7 @@ void CList::HandleMessage(SGUIMessage& Message) { // TODO: Check range - bool auto_scroll; - - GUI::GetSetting(this, "auto_scroll", auto_scroll); - - if (auto_scroll) + if (GUI::GetSetting(this, "auto_scroll")) UpdateAutoScroll(); // TODO only works if lower-case, shouldn't it be made case sensitive instead? @@ -165,11 +159,7 @@ void CList::HandleMessage(SGUIMessage& Message) // Update scrollbar if (Message.value == "scrollbar_style") { - CStr scrollbar_style; - GUI::GetSetting(this, Message.value, scrollbar_style); - - GetScrollBar(0).SetScrollBarStyle(scrollbar_style); - + GetScrollBar(0).SetScrollBarStyle(GUI::GetSetting(this, Message.value)); SetupText(); } @@ -177,9 +167,7 @@ void CList::HandleMessage(SGUIMessage& Message) case GUIM_MOUSE_PRESS_LEFT: { - bool enabled; - GUI::GetSetting(this, "enabled", enabled); - if (!enabled) + if (!GUI::GetSetting(this, "enabled")) { PlaySound("sound_disabled"); break; @@ -204,9 +192,7 @@ void CList::HandleMessage(SGUIMessage& Message) case GUIM_MOUSE_LEAVE: { - int hoveredSetting = -1; - GUI::GetSetting(this, "hovered", hoveredSetting); - if (hoveredSetting == -1) + if (GUI::GetSetting(this, "hovered") == -1) break; GUI::SetSetting(this, "hovered", -1); @@ -216,11 +202,8 @@ void CList::HandleMessage(SGUIMessage& Message) case GUIM_MOUSE_OVER: { - int hoveredSetting = -1; - GUI::GetSetting(this, "hovered", hoveredSetting); - int hovered = GetHoveredItem(); - if (hovered == hoveredSetting) + if (hovered == GUI::GetSetting(this, "hovered")) break; GUI::SetSetting(this, "hovered", hovered); @@ -230,9 +213,7 @@ void CList::HandleMessage(SGUIMessage& Message) case GUIM_LOAD: { - CStr scrollbar_style; - GUI::GetSetting(this, "scrollbar_style", scrollbar_style); - GetScrollBar(0).SetScrollBarStyle(scrollbar_style); + GetScrollBar(0).SetScrollBarStyle(GUI::GetSetting(this, "scrollbar_style")); break; } @@ -297,10 +278,7 @@ InReaction CList::ManuallyHandleEvent(const SDL_Event_* ev) void CList::Draw() { - int selected; - GUI::GetSetting(this, "selected", selected); - - DrawList(selected, "sprite", "sprite_selectarea", "textcolor"); + DrawList(GUI::GetSetting(this, "selected"), "sprite", "sprite_selectarea", "textcolor"); } void CList::DrawList(const int& selected, const CStr& _sprite, const CStr& _sprite_selected, const CStr& _textcolor) @@ -308,8 +286,7 @@ void CList::DrawList(const int& selected, const CStr& _sprite, const CStr& _spri float bz = GetBufferedZ(); // First call draw on ScrollBarOwner - bool scrollbar; - GUI::GetSetting(this, "scrollbar", scrollbar); + const bool scrollbar = GUI::GetSetting(this, "scrollbar"); if (scrollbar) IGUIScrollBarOwner::Draw(); diff --git a/source/gui/COList.cpp b/source/gui/COList.cpp index b5f6bc2666..2a40fecb6c 100644 --- a/source/gui/COList.cpp +++ b/source/gui/COList.cpp @@ -49,17 +49,14 @@ void COList::SetupText() m_GeneratedTexts.clear(); const CStrW& font = GUI::GetSetting(this, "font"); - - bool scrollbar; - GUI::GetSetting(this, "scrollbar", scrollbar); + const bool scrollbar = GUI::GetSetting(this, "scrollbar"); m_TotalAvailableColumnWidth = GetListRect().GetWidth(); // remove scrollbar if applicable if (scrollbar && GetScrollBar(0).GetStyle()) m_TotalAvailableColumnWidth -= GetScrollBar(0).GetStyle()->m_Width; - float buffer_zone = 0.f; - GUI::GetSetting(this, "buffer_zone", buffer_zone); + const float buffer_zone = GUI::GetSetting(this, "buffer_zone"); m_HeadingHeight = SORT_SPRITE_DIM; // At least the size of the sorting sprite @@ -134,26 +131,21 @@ void COList::HandleMessage(SGUIMessage& Message) // If somebody clicks on the column heading case GUIM_MOUSE_PRESS_LEFT: { - bool sortable; - GUI::GetSetting(this, "sortable", sortable); - if (!sortable) + if (!GUI::GetSetting(this, "sortable")) return; const CPos& mouse = m_pGUI.GetMousePos(); if (!m_CachedActualSize.PointInside(mouse)) return; - CStr selectedColumn; - GUI::GetSetting(this, "selected_column", selectedColumn); - int selectedColumnOrder; - GUI::GetSetting(this, "selected_column_order", selectedColumnOrder); + // 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"); float xpos = 0; for (const COListColumn& column : m_Columns) { - bool hidden = false; - GUI::GetSetting(this, "hidden_" + column.m_Id, hidden); - if (hidden) + if (GUI::GetSetting(this, "hidden_" + column.m_Id)) continue; float width = column.m_Width; @@ -172,10 +164,11 @@ void COList::HandleMessage(SGUIMessage& Message) } else selectedColumnOrder = -selectedColumnOrder; - GUI::SetSetting(this, "selected_column", column.m_Id); - GUI::SetSetting(this, "selected_column_order", selectedColumnOrder); - ScriptEvent("selectioncolumnchange"); + GUI::SetSetting(this, "selected_column", selectedColumn); + GUI::SetSetting(this, "selected_column_order", selectedColumnOrder); + + ScriptEvent("selectioncolumnchange"); PlaySound("sound_selected"); return; } @@ -292,10 +285,8 @@ bool COList::HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile void COList::DrawList(const int& selected, const CStr& _sprite, const CStr& _sprite_selected, const CStr& _textcolor) { - float bz = GetBufferedZ(); - - bool scrollbar; - GUI::GetSetting(this, "scrollbar", scrollbar); + const float bz = GetBufferedZ(); + const bool scrollbar = GUI::GetSetting(this, "scrollbar"); if (scrollbar) IGUIScrollBarOwner::Draw(); @@ -305,8 +296,7 @@ void COList::DrawList(const int& selected, const CStr& _sprite, const CStr& _spr CGUISpriteInstance& sprite = GUI::GetSetting(this, _sprite); CGUISpriteInstance& sprite_selectarea = GUI::GetSetting(this, _sprite_selected); - int cell_id; - GUI::GetSetting(this, "cell_id", cell_id); + const int cell_id = GUI::GetSetting(this, "cell_id"); m_pGUI.DrawSprite(sprite, cell_id, bz, rect); @@ -355,23 +345,15 @@ void COList::DrawList(const int& selected, const CStr& _sprite, const CStr& _spr m_pGUI.DrawSprite(sprite_heading, cell_id, bz, rect_head); // Draw column headers - bool sortable; - GUI::GetSetting(this, "sortable", sortable); - - CStr selectedColumn; - GUI::GetSetting(this, "selected_column", selectedColumn); - - int selectedColumnOrder; - GUI::GetSetting(this, "selected_column_order", selectedColumnOrder); - + 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); float xpos = 0; for (size_t col = 0; col < m_Columns.size(); ++col) { - bool hidden = false; - GUI::GetSetting(this, "hidden_" + m_Columns[col].m_Id, hidden); - if (hidden) + if (GUI::GetSetting(this, "hidden_" + m_Columns[col].m_Id)) continue; // Check if it's a decimal value, and if so, assume relative positioning. @@ -436,9 +418,7 @@ void COList::DrawList(const int& selected, const CStr& _sprite, const CStr& _spr xpos = 0; for (size_t col = 0; col < objectsCount; ++col) { - bool hidden = false; - GUI::GetSetting(this, "hidden_" + m_Columns[col].m_Id, hidden); - if (hidden) + if (GUI::GetSetting(this, "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 c4862a0013..a6fbc0f5d9 100644 --- a/source/gui/CProgressBar.cpp +++ b/source/gui/CProgressBar.cpp @@ -48,12 +48,10 @@ void CProgressBar::HandleMessage(SGUIMessage& Message) // TODO Gee: (2004-09-01) Is this really updated each time it should? if (Message.value == CStr("caption")) { - float value; - GUI::GetSetting(this, "caption", value); + const float value = GUI::GetSetting(this, "caption"); if (value > 100.f) GUI::SetSetting(this, "caption", 100.f); - else - if (value < 0.f) + else if (value < 0.f) GUI::SetSetting(this, "caption", 0.f); } break; @@ -70,8 +68,7 @@ void CProgressBar::Draw() float bz = GetBufferedZ(); int cell_id = 0; - float value = 0; - GUI::GetSetting(this, "caption", value); + const float value = GUI::GetSetting(this, "caption"); m_pGUI.DrawSprite(sprite_background, cell_id, bz, m_CachedActualSize); diff --git a/source/gui/CSlider.cpp b/source/gui/CSlider.cpp index 78653a2ba2..3101614e60 100644 --- a/source/gui/CSlider.cpp +++ b/source/gui/CSlider.cpp @@ -32,10 +32,11 @@ CSlider::CSlider(CGUI& pGUI) AddSetting("sprite_bar"); AddSetting("button_width"); - GUI::GetSetting(this, "value", m_Value); - GUI::GetSetting(this, "min_value", m_MinValue); - GUI::GetSetting(this, "max_value", m_MaxValue); - GUI::GetSetting(this, "button_width", m_ButtonSide); + 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 = Clamp(m_Value, m_MinValue, m_MaxValue); } @@ -60,10 +61,11 @@ void CSlider::HandleMessage(SGUIMessage& Message) { case GUIM_SETTINGS_UPDATED: { - GUI::GetSetting(this, "value", m_Value); - GUI::GetSetting(this, "min_value", m_MinValue); - GUI::GetSetting(this, "max_value", m_MaxValue); - GUI::GetSetting(this, "button_width", m_ButtonSide); + 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 = Clamp(m_Value, m_MinValue, m_MaxValue); break; } @@ -115,9 +117,7 @@ void CSlider::Draw() { CGUISpriteInstance& sprite = GUI::GetSetting(this, "sprite_bar"); CGUISpriteInstance& sprite_button = GUI::GetSetting(this, "sprite"); - - int cell_id; - GUI::GetSetting(this, "cell_id", cell_id); + const int cell_id = GUI::GetSetting(this, "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 5a62accadd..de651af556 100644 --- a/source/gui/CText.cpp +++ b/source/gui/CText.cpp @@ -69,8 +69,7 @@ void CText::SetupText() if (m_GeneratedTexts.empty()) return; - bool scrollbar; - GUI::GetSetting(this, "scrollbar", scrollbar); + const bool scrollbar = GUI::GetSetting(this, "scrollbar"); float width = m_CachedActualSize.GetWidth(); // remove scrollbar if applicable @@ -89,9 +88,8 @@ void CText::SetupText() // Setup scrollbar if (scrollbar) { - bool scroll_top = false, scroll_bottom = false; - GUI::GetSetting(this, "scroll_bottom", scroll_bottom); - GUI::GetSetting(this, "scroll_top", scroll_top); + const bool scroll_bottom = GUI::GetSetting(this, "scroll_bottom"); + const bool scroll_top = GUI::GetSetting(this, "scroll_top"); // If we are currently scrolled to the bottom of the text, // then add more lines of text, update the scrollbar so we @@ -130,11 +128,7 @@ void CText::HandleMessage(SGUIMessage& Message) // Update scrollbar if (Message.value == "scrollbar_style") { - CStr scrollbar_style; - GUI::GetSetting(this, Message.value, scrollbar_style); - - GetScrollBar(0).SetScrollBarStyle(scrollbar_style); - + GetScrollBar(0).SetScrollBarStyle(GUI::GetSetting(this, Message.value)); SetupText(); } @@ -164,10 +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); - - CStr scrollbar_style; - GUI::GetSetting(this, "scrollbar_style", scrollbar_style); - GetScrollBar(0).SetScrollBarStyle(scrollbar_style); + GetScrollBar(0).SetScrollBarStyle(GUI::GetSetting(this, "scrollbar_style")); break; } @@ -182,20 +173,14 @@ void CText::Draw() { float bz = GetBufferedZ(); - // First call draw on ScrollBarOwner - bool scrollbar; - GUI::GetSetting(this, "scrollbar", scrollbar); + const bool scrollbar = GUI::GetSetting(this, "scrollbar"); if (scrollbar) - // Draw scrollbar IGUIScrollBarOwner::Draw(); CGUISpriteInstance& sprite = GUI::GetSetting(this, "sprite"); - - int cell_id; - bool clip; - GUI::GetSetting(this, "cell_id", cell_id); - GUI::GetSetting(this, "clip", clip); + const int cell_id = GUI::GetSetting(this, "cell_id"); + const bool clip = GUI::GetSetting(this, "clip"); m_pGUI.DrawSprite(sprite, cell_id, bz, m_CachedActualSize); @@ -222,9 +207,7 @@ void CText::Draw() } } - bool enabled; - GUI::GetSetting(this, "enabled", enabled); - + const bool enabled = GUI::GetSetting(this, "enabled"); const CGUIColor& color = GUI::GetSetting(this, enabled ? "textcolor" : "textcolor_disabled"); if (scrollbar) diff --git a/source/gui/CTooltip.cpp b/source/gui/CTooltip.cpp index 83a243c00a..76296ccdec 100644 --- a/source/gui/CTooltip.cpp +++ b/source/gui/CTooltip.cpp @@ -65,31 +65,20 @@ void CTooltip::SetupText() { ENSURE(m_GeneratedTexts.size() == 1); - float buffer_zone = 0.f; - GUI::GetSetting(this, "buffer_zone", buffer_zone); - const CGUIString& caption = GUI::GetSetting(this, "caption"); const CStrW& font = GUI::GetSetting(this, "font"); - - float max_width = 0.f; - GUI::GetSetting(this, "maxwidth", max_width); + const float max_width = GUI::GetSetting(this, "maxwidth"); + const float buffer_zone = GUI::GetSetting(this, "buffer_zone"); m_GeneratedTexts[0] = CGUIText(m_pGUI, caption, font, max_width, buffer_zone, this); // Position the tooltip relative to the mouse: - CPos mousepos, offset; - EVAlign anchor; - bool independent; + const CPos& mousepos = GUI::GetSetting(this, "independent") ? + m_pGUI.GetMousePos() : + GUI::GetSetting(this, "_mousepos"); - GUI::GetSetting(this, "independent", independent); - if (independent) - mousepos = m_pGUI.GetMousePos(); - else - GUI::GetSetting(this, "_mousepos", mousepos); - - GUI::GetSetting(this, "offset", offset); - GUI::GetSetting(this, "anchor", anchor); + const CPos& offset = GUI::GetSetting(this, "offset"); float textwidth = m_GeneratedTexts[0].GetSize().cx; float textheight = m_GeneratedTexts[0].GetSize().cy; @@ -97,7 +86,8 @@ void CTooltip::SetupText() CClientArea size; size.pixel.left = mousepos.x + offset.x; size.pixel.right = size.pixel.left + textwidth; - switch (anchor) + + switch (GUI::GetSetting(this, "anchor")) { case EVAlign_Top: size.pixel.top = mousepos.y + offset.y; diff --git a/source/gui/GUITooltip.cpp b/source/gui/GUITooltip.cpp index 0733651f92..54baeb1fc5 100644 --- a/source/gui/GUITooltip.cpp +++ b/source/gui/GUITooltip.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 @@ -85,29 +85,28 @@ const double CooldownTime = 0.25; // TODO: Don't hard-code this value bool GUITooltip::GetTooltip(IGUIObject* obj, CStr& style) { - CStrW text; - - if (obj && obj->SettingExists("_icon_tooltip_style") && obj->MouseOverIcon() && - GUI::GetSetting(obj, "_icon_tooltip_style", style) == PSRETURN_OK && - GUI::GetSetting(obj, "_icon_tooltip", text) == PSRETURN_OK && !text.empty()) + if (obj && obj->SettingExists("_icon_tooltip_style") && obj->MouseOverIcon()) { - if (style.empty()) - style = "default"; - - m_IsIconTooltip = true; - return true; + style = GUI::GetSetting(obj, "_icon_tooltip_style"); + if (!GUI::GetSetting(obj, "_icon_tooltip").empty()) + { + if (style.empty()) + style = "default"; + m_IsIconTooltip = true; + return true; + } } - if (obj && obj->SettingExists("tooltip_style") && - GUI::GetSetting(obj, "tooltip_style", style) == PSRETURN_OK && - GUI::GetSetting(obj, "tooltip", text) == PSRETURN_OK && - !text.empty()) + if (obj && obj->SettingExists("tooltip_style")) { - if (style.empty()) - style = "default"; - - m_IsIconTooltip = false; - return true; + style = GUI::GetSetting(obj, "tooltip_style"); + if (!GUI::GetSetting(obj, "tooltip").empty()) + { + if (style.empty()) + style = "default"; + m_IsIconTooltip = false; + return true; + } } return false; @@ -129,9 +128,8 @@ void GUITooltip::ShowTooltip(IGUIObject* obj, const CPos& pos, const CStr& style IGUIObject* usedobj = tooltipobj; // object actually used to display the tooltip in - CStr usedObjectName; - if (GUI::GetSetting(tooltipobj, "use_object", usedObjectName) == PSRETURN_OK && - !usedObjectName.empty()) + const CStr& usedObjectName = GUI::GetSetting(tooltipobj, "use_object"); + if (!usedObjectName.empty()) { usedobj = pGUI.FindObjectByName(usedObjectName); if (!usedobj) @@ -145,14 +143,7 @@ void GUITooltip::ShowTooltip(IGUIObject* obj, const CPos& pos, const CStr& style GUI::SetSetting(usedobj, "hidden", false); - CStrW text; - if (m_IsIconTooltip) - { - if (GUI::GetSetting(obj, "_icon_tooltip", text) != PSRETURN_OK) - debug_warn(L"Failed to retrieve icon tooltip text"); - } - else if (GUI::GetSetting(obj, "tooltip", text) != PSRETURN_OK) - debug_warn(L"Failed to retrieve tooltip text"); + const CStrW& text = GUI::GetSetting(obj, m_IsIconTooltip ? "_icon_tooltip" : "tooltip"); if (usedobj->SetSetting("caption", text) != PSRETURN_OK) debug_warn(L"Failed to set tooltip caption"); @@ -173,9 +164,8 @@ void GUITooltip::HideTooltip(const CStr& style, CGUI& pGUI) return; } - CStr usedObjectName; - if (GUI::GetSetting(tooltipobj, "use_object", usedObjectName) == PSRETURN_OK && - !usedObjectName.empty()) + const CStr& usedObjectName = GUI::GetSetting(tooltipobj, "use_object"); + if (!usedObjectName.empty()) { IGUIObject* usedobj = pGUI.FindObjectByName(usedObjectName); if (!usedobj) @@ -188,10 +178,7 @@ void GUITooltip::HideTooltip(const CStr& style, CGUI& pGUI) SGUIMessage msg(GUIM_SETTINGS_UPDATED, "caption"); usedobj->HandleMessage(msg); - bool hideobject = true; - GUI::GetSetting(tooltipobj, "hide_object", hideobject); - - if (hideobject) + if (GUI::GetSetting(tooltipobj, "hide_object")) GUI::SetSetting(usedobj, "hidden", true); } else @@ -200,16 +187,15 @@ void GUITooltip::HideTooltip(const CStr& style, CGUI& pGUI) static int GetTooltipDelay(const CStr& style, CGUI& pGUI) { - int delay = 500; // default value (in msec) - IGUIObject* tooltipobj = pGUI.FindObjectByName("__tooltip_" + style); + if (!tooltipobj) { LOGERROR("Cannot find tooltip object named '%s'", style.c_str()); - return delay; + return 500; } - GUI::GetSetting(tooltipobj, "delay", delay); - return delay; + + return GUI::GetSetting(tooltipobj, "delay"); } void GUITooltip::Update(IGUIObject* Nearest, const CPos& MousePos, CGUI& GUI) diff --git a/source/gui/GUIutil.cpp b/source/gui/GUIutil.cpp index b1ba900900..975f154816 100644 --- a/source/gui/GUIutil.cpp +++ b/source/gui/GUIutil.cpp @@ -116,16 +116,6 @@ T& GUI::GetSetting(const IGUIObject* pObject, const CStr& Setting) return static_cast* >(pObject->m_Settings.at(Setting))->m_pSetting; } -template -PSRETURN GUI::GetSetting(const IGUIObject* pObject, const CStr& Setting, T& Value) -{ - T* v = NULL; - PSRETURN ret = GetSettingPointer(pObject, Setting, v); - if (ret == PSRETURN_OK) - Value = *v; - return ret; -} - template PSRETURN GUI::SetSetting(IGUIObject* pObject, const CStr& Setting, T& Value, const bool& SkipMessage) { @@ -196,7 +186,6 @@ PSRETURN GUI::SetSettingWrap(IGUIObject* pObject, const CStr& Setting, const // Copying functions - discouraged except for primitives. #define TYPE(T) \ - template PSRETURN GUI::GetSetting(const IGUIObject* pObject, const CStr& Setting, T& Value); \ template PSRETURN GUI::SetSetting(IGUIObject* pObject, const CStr& Setting, const T& Value, const bool& SkipMessage); \ #define GUITYPE_IGNORE_NONCOPYABLE diff --git a/source/gui/GUIutil.h b/source/gui/GUIutil.h index 27cad72320..fc13d8d6a9 100644 --- a/source/gui/GUIutil.h +++ b/source/gui/GUIutil.h @@ -135,19 +135,8 @@ public: */ static T& GetSetting(const IGUIObject* pObject, const CStr& Setting); - // Like GetSetting (below), but doesn't make a copy of the value - // (so it can be modified later) static PSRETURN GetSettingPointer(const IGUIObject* pObject, const CStr& Setting, T*& Value); - /** - * Copy-assigns the current setting value to the given reference. - * - * @param pObject Object pointer - * @param Setting Setting by name - * @param Value Stores value here, note type T! - */ - static PSRETURN GetSetting(const IGUIObject* pObject, const CStr& Setting, T& Value); - /** * Sets a value by name using a real datatype as input. * This variant will use the move-assignment. diff --git a/source/gui/IGUIButtonBehavior.cpp b/source/gui/IGUIButtonBehavior.cpp index b89d67483b..8f43f3aa29 100644 --- a/source/gui/IGUIButtonBehavior.cpp +++ b/source/gui/IGUIButtonBehavior.cpp @@ -32,8 +32,8 @@ IGUIButtonBehavior::~IGUIButtonBehavior() void IGUIButtonBehavior::HandleMessage(SGUIMessage& Message) { - bool enabled; - GUI::GetSetting(this, "enabled", enabled); + const bool enabled = GUI::GetSetting(this, "enabled"); + CStrW soundPath; // TODO Gee: easier access functions switch (Message.type) @@ -123,10 +123,7 @@ const CGUIColor& IGUIButtonBehavior::ChooseColor() // Yes, the object must possess these settings. They are standard const CGUIColor& color = GUI::GetSetting(this, "textcolor"); - bool enabled; - GUI::GetSetting(this, "enabled", enabled); - - if (!enabled) + if (!GUI::GetSetting(this, "enabled")) return GUI::GetSetting(this, "textcolor_disabled") || color; if (m_MouseHovering) @@ -142,10 +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) { - bool enabled; - GUI::GetSetting(this, "enabled", enabled); - - if (!enabled) + if (!GUI::GetSetting(this, "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 1c808b11a8..adab56727e 100644 --- a/source/gui/IGUIObject.cpp +++ b/source/gui/IGUIObject.cpp @@ -216,18 +216,13 @@ void IGUIObject::ResetStates() void IGUIObject::UpdateCachedSize() { - bool absolute; - GUI::GetSetting(this, "absolute", absolute); - - float aspectratio = 0.f; - GUI::GetSetting(this, "aspectratio", aspectratio); - const CClientArea& ca = GUI::GetSetting(this, "size"); + const float aspectratio = GUI::GetSetting(this, "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 (absolute == false && m_pParent && !IsRootObject()) + if (!GUI::GetSetting(this, "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)); @@ -279,15 +274,11 @@ void IGUIObject::LoadStyle(const SGUIStyle& Style) float IGUIObject::GetBufferedZ() const { - bool absolute; - GUI::GetSetting(this, "absolute", absolute); + const float Z = GUI::GetSetting(this, "z"); - float Z; - GUI::GetSetting(this, "z", Z); - - if (absolute) + if (GUI::GetSetting(this, "absolute")) return Z; - else + { if (GetParent()) return GetParent()->GetBufferedZ() + Z; diff --git a/source/gui/IGUITextOwner.cpp b/source/gui/IGUITextOwner.cpp index eb8ef85972..c678d08a28 100644 --- a/source/gui/IGUITextOwner.cpp +++ b/source/gui/IGUITextOwner.cpp @@ -103,14 +103,11 @@ void IGUITextOwner::DrawText(size_t index, const CGUIColor& color, const CPos& p void IGUITextOwner::CalculateTextPosition(CRect& ObjSize, CPos& TextPos, CGUIText& Text) { - EVAlign valign; - GUI::GetSetting(this, "text_valign", valign); - // The horizontal Alignment is now computed in GenerateText in order to not have to // loop through all of the TextCall objects again. TextPos.x = ObjSize.left; - switch (valign) + switch (GUI::GetSetting(this, "text_valign")) { case EVAlign_Top: TextPos.y = ObjSize.top;