Index: ps/trunk/source/gui/CButton.cpp =================================================================== --- ps/trunk/source/gui/CButton.cpp +++ ps/trunk/source/gui/CButton.cpp @@ -64,13 +64,12 @@ // TODO Gee: (2004-08-14) Default should not be hard-coded, but be in styles! font = L"default"; - CGUIString* caption = nullptr; - GUI::GetSettingPointer(this, "caption", caption); + 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, caption, font, m_CachedActualSize.GetWidth(), buffer_zone, this); CalculateTextPosition(m_CachedActualSize, m_TextPos, m_GeneratedTexts[0]); } @@ -86,10 +85,6 @@ { float bz = GetBufferedZ(); - CGUISpriteInstance* sprite; - CGUISpriteInstance* sprite_over; - CGUISpriteInstance* sprite_pressed; - CGUISpriteInstance* sprite_disabled; int cell_id; // Statically initialise some strings, so we don't have to do @@ -100,19 +95,14 @@ static const CStr strSpriteDisabled("sprite_disabled"); static const CStr strCellId("cell_id"); - GUI::GetSettingPointer(this, strSprite, sprite); - GUI::GetSettingPointer(this, strSpriteOver, sprite_over); - GUI::GetSettingPointer(this, strSpritePressed, sprite_pressed); - GUI::GetSettingPointer(this, strSpriteDisabled, sprite_disabled); + 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); + GUI::GetSetting(this, strCellId, cell_id); - DrawButton(m_CachedActualSize, - bz, - *sprite, - *sprite_over, - *sprite_pressed, - *sprite_disabled, - cell_id); + DrawButton(m_CachedActualSize, bz, sprite, sprite_over, sprite_pressed, sprite_disabled, cell_id); CGUIColor color = ChooseColor(); DrawText(0, color, m_TextPos, bz+0.1f); Index: ps/trunk/source/gui/CChart.cpp =================================================================== --- ps/trunk/source/gui/CChart.cpp +++ ps/trunk/source/gui/CChart.cpp @@ -184,22 +184,19 @@ void CChart::UpdateSeries() { - CGUISeries* pSeries; - GUI::GetSettingPointer(this, "series", pSeries); - - CGUIList* pSeriesColor; - GUI::GetSettingPointer(this, "series_color", pSeriesColor); + const CGUISeries& pSeries = GUI::GetSetting(this, "series"); + const CGUIList& pSeriesColor = GUI::GetSetting(this, "series_color"); m_Series.clear(); - m_Series.resize(pSeries->m_Series.size()); - for (size_t i = 0; i < pSeries->m_Series.size(); ++i) + m_Series.resize(pSeries.m_Series.size()); + for (size_t i = 0; i < pSeries.m_Series.size(); ++i) { CChartData& data = m_Series[i]; - if (i < pSeriesColor->m_Items.size() && !data.m_Color.ParseString(m_pGUI, pSeriesColor->m_Items[i].GetOriginalString().ToUTF8(), 0)) - LOGWARNING("GUI: Error parsing 'series_color' (\"%s\")", utf8_from_wstring(pSeriesColor->m_Items[i].GetOriginalString())); + if (i < pSeriesColor.m_Items.size() && !data.m_Color.ParseString(m_pGUI, pSeriesColor.m_Items[i].GetOriginalString().ToUTF8(), 0)) + LOGWARNING("GUI: Error parsing 'series_color' (\"%s\")", utf8_from_wstring(pSeriesColor.m_Items[i].GetOriginalString())); - data.m_Points = pSeries->m_Series[i]; + data.m_Points = pSeries.m_Series[i]; } UpdateBounds(); Index: ps/trunk/source/gui/CCheckBox.cpp =================================================================== --- ps/trunk/source/gui/CCheckBox.cpp +++ ps/trunk/source/gui/CCheckBox.cpp @@ -77,12 +77,11 @@ float square_side; GUI::GetSetting(this, "square_side", square_side); - CGUIString* caption = nullptr; - GUI::GetSettingPointer(this, "caption", caption); + 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() - square_side, 0.f, this); + m_GeneratedTexts[0] = CGUIText(m_pGUI, caption, font, m_CachedActualSize.GetWidth() - square_side, 0.f, this); } void CCheckBox::HandleMessage(SGUIMessage& Message) @@ -111,37 +110,22 @@ void CCheckBox::Draw() { - float bz = GetBufferedZ(); - bool checked; - int cell_id; - CGUISpriteInstance* sprite; - CGUISpriteInstance* sprite_over; - CGUISpriteInstance* sprite_pressed; - CGUISpriteInstance* sprite_disabled; - - GUI::GetSetting(this, "checked", checked); - GUI::GetSetting(this, "cell_id", cell_id); - - if (checked) - { - GUI::GetSettingPointer(this, "sprite2", sprite); - GUI::GetSettingPointer(this, "sprite2_over", sprite_over); - GUI::GetSettingPointer(this, "sprite2_pressed", sprite_pressed); - GUI::GetSettingPointer(this, "sprite2_disabled", sprite_disabled); - } + if (GUI::GetSetting(this, "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")); else - { - GUI::GetSettingPointer(this, "sprite", sprite); - GUI::GetSettingPointer(this, "sprite_over", sprite_over); - GUI::GetSettingPointer(this, "sprite_pressed", sprite_pressed); - GUI::GetSettingPointer(this, "sprite_disabled", sprite_disabled); - } - - DrawButton(m_CachedActualSize, - bz, - *sprite, - *sprite_over, - *sprite_pressed, - *sprite_disabled, - cell_id); + 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")); } Index: ps/trunk/source/gui/CDropDown.cpp =================================================================== --- ps/trunk/source/gui/CDropDown.cpp +++ ps/trunk/source/gui/CDropDown.cpp @@ -109,9 +109,8 @@ break; bool scrollbar; - CGUIList* pList; + const CGUIList& pList = GUI::GetSetting(this, "list"); GUI::GetSetting(this, "scrollbar", scrollbar); - GUI::GetSettingPointer(this, "list", pList); float scroll = 0.f; if (scrollbar) scroll = GetScrollBar(0).GetPos(); @@ -119,7 +118,7 @@ CRect rect = GetListRect(); mouse.y += scroll; int set = -1; - for (int i = 0; i < (int)pList->m_Items.size(); ++i) + for (int i = 0; i < static_cast(pList.m_Items.size()); ++i) { if (mouse.y >= rect.top + m_ItemsYPositions[i] && mouse.y < rect.top + m_ItemsYPositions[i+1] && @@ -185,9 +184,8 @@ if (!m_Open) { - CGUIList* pList; - GUI::GetSettingPointer(this, "list", pList); - if (pList->m_Items.empty()) + const CGUIList& pList = GUI::GetSetting(this, "list"); + if (pList.m_Items.empty()) return; m_Open = true; @@ -343,20 +341,19 @@ m_TimeOfLastInput = timer_Time(); - CGUIList* pList; - GUI::GetSettingPointer(this, "list", pList); + const CGUIList& pList = GUI::GetSetting(this, "list"); // let's look for the closest element // basically it's alphabetic order and "as many letters as we can get". int closest = -1; int bestIndex = -1; int difference = 1250; - for (int i = 0; i < (int)pList->m_Items.size(); ++i) + for (int i = 0; i < static_cast(pList.m_Items.size()); ++i) { int indexOfDifference = 0; int diff = 0; for (size_t j = 0; j < m_InputBuffer.length(); ++j) { - diff = std::abs((int)(pList->m_Items[i].GetRawString().LowerCase()[j]) - (int)m_InputBuffer[j]); + diff = std::abs(static_cast(pList.m_Items[i].GetRawString().LowerCase()[j]) - static_cast(m_InputBuffer[j])); if (diff == 0) indexOfDifference = j+1; else @@ -478,22 +475,20 @@ GUI::GetSetting(this, "dropdown_size", dropdown_size); GUI::GetSetting(this, "button_width", button_width); - CGUISpriteInstance* sprite; - CGUISpriteInstance* sprite2; - CGUISpriteInstance* sprite2_second; int cell_id, selected = 0; CGUIColor color; bool enabled; GUI::GetSetting(this, "enabled", enabled); - GUI::GetSettingPointer(this, "sprite2", sprite2); + 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); GUI::GetSetting(this, enabled ? "textcolor_selected" : "textcolor_disabled", color); - GUI::GetSettingPointer(this, enabled ? "sprite" : "sprite_disabled", sprite); - m_pGUI->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize); + m_pGUI->DrawSprite(sprite, cell_id, bz, m_CachedActualSize); if (button_width > 0.f) { @@ -502,21 +497,21 @@ if (!enabled) { - GUI::GetSettingPointer(this, "sprite2_disabled", sprite2_second); - m_pGUI->DrawSprite(*sprite2_second || *sprite2, cell_id, bz + 0.05f, rect); + CGUISpriteInstance& sprite2_second = GUI::GetSetting(this, "sprite2_disabled"); + m_pGUI->DrawSprite(sprite2_second || sprite2, cell_id, bz + 0.05f, rect); } else if (m_Open) { - GUI::GetSettingPointer(this, "sprite2_pressed", sprite2_second); - m_pGUI->DrawSprite(*sprite2_second || *sprite2, cell_id, bz + 0.05f, rect); + CGUISpriteInstance& sprite2_second = GUI::GetSetting(this, "sprite2_pressed"); + m_pGUI->DrawSprite(sprite2_second || sprite2, cell_id, bz + 0.05f, rect); } else if (m_MouseHovering) { - GUI::GetSettingPointer(this, "sprite2_over", sprite2_second); - m_pGUI->DrawSprite(*sprite2_second || *sprite2, cell_id, bz + 0.05f, rect); + CGUISpriteInstance& sprite2_second = GUI::GetSetting(this, "sprite2_over"); + m_pGUI->DrawSprite(sprite2_second || sprite2, cell_id, bz + 0.05f, rect); } else - m_pGUI->DrawSprite(*sprite2, cell_id, bz + 0.05f, rect); + m_pGUI->DrawSprite(sprite2, cell_id, bz + 0.05f, rect); } if (selected != -1) // TODO: Maybe check validity completely? @@ -528,21 +523,19 @@ DrawText(selected, color, pos, bz+0.1f, cliparea); } - bool* scrollbar = NULL; - bool old; - GUI::GetSettingPointer(this, "scrollbar", scrollbar); - - old = *scrollbar; + // Disable scrollbar during drawing without sending a setting-changed message + bool& scrollbar = GUI::GetSetting(this, "scrollbar"); + bool old = scrollbar; if (m_Open) { if (m_HideScrollBar) - *scrollbar = false; + scrollbar = false; DrawList(m_ElementHighlight, "sprite_list", "sprite_selectarea", "textcolor"); if (m_HideScrollBar) - *scrollbar = old; + scrollbar = old; } } Index: ps/trunk/source/gui/CImage.cpp =================================================================== --- ps/trunk/source/gui/CImage.cpp +++ ps/trunk/source/gui/CImage.cpp @@ -40,10 +40,9 @@ { float bz = GetBufferedZ(); - CGUISpriteInstance* sprite; int cell_id; - GUI::GetSettingPointer(this, "sprite", sprite); GUI::GetSetting(this, "cell_id", cell_id); - GetGUI()->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize); + CGUISpriteInstance& sprite = GUI::GetSetting(this, "sprite"); + m_pGUI->DrawSprite(sprite, cell_id, bz, m_CachedActualSize); } Index: ps/trunk/source/gui/CInput.h =================================================================== --- ps/trunk/source/gui/CInput.h +++ ps/trunk/source/gui/CInput.h @@ -68,12 +68,12 @@ /** * Handle events manually to catch keys which change the text. */ - virtual void ManuallyMutableHandleKeyDownEvent(const SDL_Keycode keyCode, CStrW* pCaption); + virtual void ManuallyMutableHandleKeyDownEvent(const SDL_Keycode keyCode, CStrW& pCaption); /** * Handle events manually to catch keys which don't change the text. */ - virtual void ManuallyImmutableHandleKeyDownEvent(const SDL_Keycode keyCode, CStrW* pCaption); + virtual void ManuallyImmutableHandleKeyDownEvent(const SDL_Keycode keyCode, CStrW& pCaption); /** * Handle hotkey events (called by ManuallyHandleEvent) Index: ps/trunk/source/gui/CInput.cpp =================================================================== --- ps/trunk/source/gui/CInput.cpp +++ ps/trunk/source/gui/CInput.cpp @@ -82,10 +82,8 @@ void CInput::ClearComposedText() { - CStrW* pCaption = nullptr; - GUI::GetSettingPointer(this, "caption", pCaption); - - pCaption->erase(m_iInsertPos, m_iComposedLength); + CStrW& pCaption = GUI::GetSetting(this, "caption"); + pCaption.erase(m_iInsertPos, m_iComposedLength); m_iBufferPos = m_iInsertPos; UpdateBufferPositionSetting(); m_iComposedLength = 0; @@ -113,8 +111,7 @@ return IN_PASS; // Text has been committed, either single key presses or through an IME - CStrW* pCaption = nullptr; - GUI::GetSettingPointer(this, "caption", pCaption); + CStrW& pCaption = GUI::GetSetting(this, "caption"); std::wstring text = wstring_from_utf8(ev->ev.text.text); m_WantedX = 0.0f; @@ -128,10 +125,10 @@ m_ComposingText = false; } - if (m_iBufferPos == (int)pCaption->length()) - pCaption->append(text); + if (m_iBufferPos == static_cast(pCaption.length())) + pCaption.append(text); else - pCaption->insert(m_iBufferPos, text); + pCaption.insert(m_iBufferPos, text); UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+1); @@ -151,8 +148,7 @@ // Text is being composed with an IME // TODO: indicate this by e.g. underlining the uncommitted text - CStrW* pCaption = nullptr; - GUI::GetSettingPointer(this, "caption", pCaption); + CStrW& pCaption = GUI::GetSetting(this, "caption"); const char* rawText = ev->ev.edit.text; int rawLength = strlen(rawText); std::wstring wtext = wstring_from_utf8(rawText); @@ -175,7 +171,7 @@ m_ComposingText = ev->ev.edit.start != 0 || rawLength != 0; if (m_ComposingText) { - pCaption->insert(m_iInsertPos, wtext); + pCaption.insert(m_iInsertPos, wtext); // The text buffer is limited to SDL_TEXTEDITINGEVENT_TEXT_SIZE bytes, yet start // increases without limit, so don't let it advance beyond the composed text length @@ -203,8 +199,7 @@ // 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 = nullptr; - GUI::GetSettingPointer(this, "caption", pCaption); + CStrW& pCaption = GUI::GetSetting(this, "caption"); SDL_Keycode keyCode = ev->ev.key.keysym.sym; ManuallyImmutableHandleKeyDownEvent(keyCode, pCaption); @@ -220,7 +215,7 @@ } } -void CInput::ManuallyMutableHandleKeyDownEvent(const SDL_Keycode keyCode, CStrW* pCaption) +void CInput::ManuallyMutableHandleKeyDownEvent(const SDL_Keycode keyCode, CStrW& pCaption) { if (m_Readonly) return; @@ -246,14 +241,15 @@ { m_iBufferPos_Tail = -1; - if (pCaption->empty() || m_iBufferPos == 0) + if (pCaption.empty() || m_iBufferPos == 0) break; - if (m_iBufferPos == (int)pCaption->length()) - *pCaption = pCaption->Left((long)pCaption->length() - 1); + if (m_iBufferPos == static_cast(pCaption.length())) + pCaption = pCaption.Left(static_cast(pCaption.length()) - 1); else - *pCaption = pCaption->Left(m_iBufferPos - 1) + - pCaption->Right((long)pCaption->length() - m_iBufferPos); + pCaption = + pCaption.Left(m_iBufferPos - 1) + + pCaption.Right(static_cast(pCaption.length()) - m_iBufferPos); --m_iBufferPos; @@ -272,11 +268,12 @@ DeleteCurSelection(); else { - if (pCaption->empty() || m_iBufferPos == (int)pCaption->length()) + if (pCaption.empty() || m_iBufferPos == static_cast(pCaption.length())) break; - *pCaption = pCaption->Left(m_iBufferPos) + - pCaption->Right((long)pCaption->length() - (m_iBufferPos + 1)); + pCaption = + pCaption.Left(m_iBufferPos) + + pCaption.Right(static_cast(pCaption.length()) - (m_iBufferPos + 1)); UpdateText(m_iBufferPos, m_iBufferPos + 1, m_iBufferPos); } @@ -311,7 +308,7 @@ // check max length int max_length; GUI::GetSetting(this, "max_length", max_length); - if (max_length != 0 && (int)pCaption->length() >= max_length) + if (max_length != 0 && static_cast(pCaption.length()) >= max_length) break; m_WantedX = 0.0f; @@ -320,11 +317,12 @@ DeleteCurSelection(); m_iBufferPos_Tail = -1; - if (m_iBufferPos == (int)pCaption->length()) - *pCaption += cooked; + if (m_iBufferPos == static_cast(pCaption.length())) + pCaption += cooked; else - *pCaption = pCaption->Left(m_iBufferPos) + cooked + - pCaption->Right((long)pCaption->length() - m_iBufferPos); + pCaption = + pCaption.Left(m_iBufferPos) + cooked + + pCaption.Right(static_cast(pCaption.length()) - m_iBufferPos); UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos + 1); @@ -337,7 +335,7 @@ } } -void CInput::ManuallyImmutableHandleKeyDownEvent(const SDL_Keycode keyCode, CStrW* pCaption) +void CInput::ManuallyImmutableHandleKeyDownEvent(const SDL_Keycode keyCode, CStrW& pCaption) { bool shiftKeyPressed = g_keys[SDLK_RSHIFT] || g_keys[SDLK_LSHIFT]; @@ -377,7 +375,7 @@ m_iBufferPos_Tail = m_iBufferPos; } - m_iBufferPos = (long)pCaption->length(); + m_iBufferPos = static_cast(pCaption.length()); m_WantedX = 0.0f; UpdateAutoScroll(); @@ -440,7 +438,7 @@ else if (!SelectingText()) m_iBufferPos_Tail = m_iBufferPos; - if (m_iBufferPos < (int)pCaption->length()) + if (m_iBufferPos < static_cast(pCaption.length())) ++m_iBufferPos; } else @@ -573,8 +571,7 @@ InReaction CInput::ManuallyHandleHotkeyEvent(const SDL_Event_* ev) { - CStrW* pCaption = nullptr; - GUI::GetSettingPointer(this, "caption", pCaption); + CStrW& pCaption = GUI::GetSetting(this, "caption"); bool shiftKeyPressed = g_keys[SDLK_RSHIFT] || g_keys[SDLK_LSHIFT]; @@ -593,11 +590,12 @@ if (SelectingText()) DeleteCurSelection(); - if (m_iBufferPos == (int)pCaption->length()) - *pCaption += text; + if (m_iBufferPos == static_cast(pCaption.length())) + pCaption += text; else - *pCaption = pCaption->Left(m_iBufferPos) + text + - pCaption->Right((long) pCaption->length()-m_iBufferPos); + pCaption = + pCaption.Left(m_iBufferPos) + text + + pCaption.Right(static_cast(pCaption.length()) - m_iBufferPos); UpdateText(m_iBufferPos, m_iBufferPos, m_iBufferPos+1); @@ -635,7 +633,7 @@ virtualTo = m_iBufferPos; } - CStrW text = (pCaption->Left(virtualTo)).Right(virtualTo - virtualFrom); + CStrW text = (pCaption.Left(virtualTo)).Right(virtualTo - virtualFrom); sys_clipboard_set(&text[0]); @@ -659,10 +657,10 @@ if (SelectingText()) DeleteCurSelection(); - if (!pCaption->empty() && m_iBufferPos != 0) + if (!pCaption.empty() && m_iBufferPos != 0) { m_iBufferPos_Tail = m_iBufferPos; - CStrW searchString = pCaption->Left(m_iBufferPos); + CStrW searchString = pCaption.Left(m_iBufferPos); // If we are starting in whitespace, adjust position until we get a non whitespace while (m_iBufferPos > 0) @@ -705,22 +703,22 @@ if (SelectingText()) DeleteCurSelection(); - if (!pCaption->empty() && m_iBufferPos < (int)pCaption->length()) + if (!pCaption.empty() && m_iBufferPos < static_cast(pCaption.length())) { // Delete the word to the right of the cursor m_iBufferPos_Tail = m_iBufferPos; // Delete chars to the right unit we hit whitespace - while (++m_iBufferPos < (int)pCaption->length()) + while (++m_iBufferPos < static_cast(pCaption.length())) { - if (iswspace((*pCaption)[m_iBufferPos]) || iswpunct((*pCaption)[m_iBufferPos])) + if (iswspace(pCaption[m_iBufferPos]) || iswpunct(pCaption[m_iBufferPos])) break; } // Eliminate any whitespace behind the word we just deleted - while (m_iBufferPos < (int)pCaption->length()) + while (m_iBufferPos < static_cast(pCaption.length())) { - if (!iswspace((*pCaption)[m_iBufferPos])) + if (!iswspace(pCaption[m_iBufferPos])) break; ++m_iBufferPos; @@ -743,9 +741,9 @@ else if (!SelectingText()) m_iBufferPos_Tail = m_iBufferPos; - if (!pCaption->empty() && m_iBufferPos != 0) + if (!pCaption.empty() && m_iBufferPos != 0) { - CStrW searchString = pCaption->Left(m_iBufferPos); + CStrW searchString = pCaption.Left(m_iBufferPos); // If we are starting in whitespace, adjust position until we get a non whitespace while (m_iBufferPos > 0) @@ -796,19 +794,19 @@ else if (!SelectingText()) m_iBufferPos_Tail = m_iBufferPos; - if (!pCaption->empty() && m_iBufferPos < (int)pCaption->length()) + if (!pCaption.empty() && m_iBufferPos < static_cast(pCaption.length())) { // Select chars to the right until we hit whitespace - while (++m_iBufferPos < (int)pCaption->length()) + while (++m_iBufferPos < static_cast(pCaption.length())) { - if (iswspace((*pCaption)[m_iBufferPos]) || iswpunct((*pCaption)[m_iBufferPos])) + if (iswspace(pCaption[m_iBufferPos]) || iswpunct(pCaption[m_iBufferPos])) break; } // Also select any whitespace following the word we just selected - while (m_iBufferPos < (int)pCaption->length()) + while (m_iBufferPos < static_cast(pCaption.length())) { - if (!iswspace((*pCaption)[m_iBufferPos])) + if (!iswspace(pCaption[m_iBufferPos])) break; ++m_iBufferPos; @@ -942,23 +940,22 @@ if (m_ComposingText) break; - CStrW* pCaption = nullptr; - GUI::GetSettingPointer(this, "caption", pCaption); + const CStrW& pCaption = GUI::GetSetting(this, "caption"); - if (pCaption->empty()) + if (pCaption.empty()) break; m_iBufferPos = m_iBufferPos_Tail = GetMouseHoveringTextPosition(); - if (m_iBufferPos >= (int)pCaption->length()) - m_iBufferPos = m_iBufferPos_Tail = pCaption->length() - 1; + if (m_iBufferPos >= (int)pCaption.length()) + m_iBufferPos = m_iBufferPos_Tail = pCaption.length() - 1; // See if we are clicking over whitespace - if (iswspace((*pCaption)[m_iBufferPos])) + if (iswspace(pCaption[m_iBufferPos])) { // see if we are in a section of whitespace greater than one character - if ((m_iBufferPos + 1 < (int) pCaption->length() && iswspace((*pCaption)[m_iBufferPos + 1])) || - (m_iBufferPos - 1 > 0 && iswspace((*pCaption)[m_iBufferPos - 1]))) + if ((m_iBufferPos + 1 < (int) pCaption.length() && iswspace(pCaption[m_iBufferPos + 1])) || + (m_iBufferPos - 1 > 0 && iswspace(pCaption[m_iBufferPos - 1]))) { // // We are clicking in an area with more than one whitespace character @@ -968,7 +965,7 @@ // skip the whitespace while (m_iBufferPos > 0) { - if (!iswspace((*pCaption)[m_iBufferPos - 1])) + if (!iswspace(pCaption[m_iBufferPos - 1])) break; m_iBufferPos--; @@ -976,52 +973,52 @@ // now go until we hit white space or punctuation while (m_iBufferPos > 0) { - if (iswspace((*pCaption)[m_iBufferPos - 1])) + if (iswspace(pCaption[m_iBufferPos - 1])) break; m_iBufferPos--; - if (iswpunct((*pCaption)[m_iBufferPos])) + if (iswpunct(pCaption[m_iBufferPos])) break; } // [2] Then the right // go right until we are not in whitespace - while (++m_iBufferPos_Tail < (int)pCaption->length()) + while (++m_iBufferPos_Tail < static_cast(pCaption.length())) { - if (!iswspace((*pCaption)[m_iBufferPos_Tail])) + if (!iswspace(pCaption[m_iBufferPos_Tail])) break; } - if (m_iBufferPos_Tail == (int)pCaption->length()) + if (m_iBufferPos_Tail == static_cast(pCaption.length())) break; // now go to the right until we hit whitespace or punctuation - while (++m_iBufferPos_Tail < (int)pCaption->length()) + while (++m_iBufferPos_Tail < static_cast(pCaption.length())) { - if (iswspace((*pCaption)[m_iBufferPos_Tail]) || iswpunct((*pCaption)[m_iBufferPos_Tail])) + if (iswspace(pCaption[m_iBufferPos_Tail]) || iswpunct(pCaption[m_iBufferPos_Tail])) break; } } else { // single whitespace so select word to the right - while (++m_iBufferPos_Tail < (int)pCaption->length()) + while (++m_iBufferPos_Tail < static_cast(pCaption.length())) { - if (!iswspace((*pCaption)[m_iBufferPos_Tail])) + if (!iswspace(pCaption[m_iBufferPos_Tail])) break; } - if (m_iBufferPos_Tail == (int)pCaption->length()) + if (m_iBufferPos_Tail == static_cast(pCaption.length())) break; // Don't include the leading whitespace m_iBufferPos = m_iBufferPos_Tail; // now go to the right until we hit whitespace or punctuation - while (++m_iBufferPos_Tail < (int)pCaption->length()) + while (++m_iBufferPos_Tail < static_cast(pCaption.length())) { - if (iswspace((*pCaption)[m_iBufferPos_Tail]) || iswpunct((*pCaption)[m_iBufferPos_Tail])) + if (iswspace(pCaption[m_iBufferPos_Tail]) || iswpunct(pCaption[m_iBufferPos_Tail])) break; } } @@ -1032,17 +1029,17 @@ // go until we hit white space or punctuation while (m_iBufferPos > 0) { - if (iswspace((*pCaption)[m_iBufferPos - 1])) + if (iswspace(pCaption[m_iBufferPos - 1])) break; m_iBufferPos--; - if (iswpunct((*pCaption)[m_iBufferPos])) + if (iswpunct(pCaption[m_iBufferPos])) break; } // go to the right until we hit whitespace or punctuation - while (++m_iBufferPos_Tail < (int)pCaption->length()) - if (iswspace((*pCaption)[m_iBufferPos_Tail]) || iswpunct((*pCaption)[m_iBufferPos_Tail])) + while (++m_iBufferPos_Tail < static_cast(pCaption.length())) + if (iswspace(pCaption[m_iBufferPos_Tail]) || iswpunct(pCaption[m_iBufferPos_Tail])) break; } UpdateAutoScroll(); @@ -1185,9 +1182,7 @@ GUI::GetSetting(this, "textcolor_selected", color_selected); CStrIntern font_name(font_name_w.ToUTF8()); - // Get pointer of caption, it might be very large, and we don't - // want to copy it continuously. - CStrW* pCaption = NULL; + const CStrW& pCaption = GUI::GetSetting(this, "caption"); wchar_t mask_char = L'*'; if (mask) { @@ -1196,19 +1191,14 @@ if (maskStr.length() > 0) mask_char = maskStr[0]; } - else - GUI::GetSettingPointer(this, "caption", pCaption); - CGUISpriteInstance* sprite = NULL; - CGUISpriteInstance* sprite_selectarea = NULL; - int cell_id; - - GUI::GetSettingPointer(this, "sprite", sprite); - GUI::GetSettingPointer(this, "sprite_selectarea", sprite_selectarea); + CGUISpriteInstance& sprite = GUI::GetSetting(this, "sprite"); + CGUISpriteInstance& sprite_selectarea = GUI::GetSetting(this, "sprite_selectarea"); + int cell_id; GUI::GetSetting(this, "cell_id", cell_id); - GetGUI()->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize); + m_pGUI->DrawSprite(sprite, cell_id, bz, m_CachedActualSize); float scroll = 0.f; if (scrollbar && multiline) @@ -1397,14 +1387,13 @@ rect.right = m_CachedActualSize.right; } - if (sprite_selectarea) - GetGUI()->DrawSprite(*sprite_selectarea, cell_id, bz+0.05f, rect); + m_pGUI->DrawSprite(sprite_selectarea, cell_id, bz+0.05f, rect); } if (i < (int)it->m_ListOfX.size()) { if (!mask) - x_pointer += (float)font.GetCharacterWidth((*pCaption)[it->m_ListStart + i]); + x_pointer += (float)font.GetCharacterWidth(pCaption[it->m_ListStart + i]); else x_pointer += (float)font.GetCharacterWidth(mask_char); } @@ -1490,7 +1479,7 @@ if (i != (int)it->m_ListOfX.size()) { if (!mask) - textRenderer.PrintfAdvance(L"%lc", (*pCaption)[it->m_ListStart + i]); + textRenderer.PrintfAdvance(L"%lc", pCaption[it->m_ListStart + i]); else textRenderer.PrintfAdvance(L"%lc", mask_char); } @@ -1997,8 +1986,7 @@ void CInput::DeleteCurSelection() { - CStrW* pCaption = nullptr; - GUI::GetSettingPointer(this, "caption", pCaption); + CStrW& pCaption = GUI::GetSetting(this, "caption"); int virtualFrom; int virtualTo; @@ -2014,8 +2002,9 @@ virtualTo = m_iBufferPos; } - *pCaption = pCaption->Left(virtualFrom) + - pCaption->Right((long)pCaption->length() - virtualTo); + pCaption = + pCaption.Left(virtualFrom) + + pCaption.Right(static_cast(pCaption.length()) - virtualTo); UpdateText(virtualFrom, virtualTo, virtualFrom); Index: ps/trunk/source/gui/CList.cpp =================================================================== --- ps/trunk/source/gui/CList.cpp +++ ps/trunk/source/gui/CList.cpp @@ -72,12 +72,11 @@ void CList::SetupText() { m_Modified = true; - CGUIList* pList; - GUI::GetSettingPointer(this, "list", pList); + const CGUIList& pList = GUI::GetSetting(this, "list"); //ENSURE(m_GeneratedTexts.size()>=1); - m_ItemsYPositions.resize(pList->m_Items.size()+1); + m_ItemsYPositions.resize(pList.m_Items.size() + 1); // Delete all generated texts. Some could probably be saved, // but this is easier, and this function will never be called @@ -104,12 +103,12 @@ // Generate texts float buffered_y = 0.f; - for (size_t i = 0; i < pList->m_Items.size(); ++i) + for (size_t i = 0; i < pList.m_Items.size(); ++i) { CGUIText* text; - if (!pList->m_Items[i].GetOriginalString().empty()) - text = &AddText(pList->m_Items[i], font, width, buffer_zone, this); + if (!pList.m_Items[i].GetOriginalString().empty()) + text = &AddText(pList.m_Items[i], font, width, buffer_zone, this); else { // Minimum height of a space character of the current font size @@ -122,7 +121,7 @@ buffered_y += text->GetSize().cy; } - m_ItemsYPositions[pList->m_Items.size()] = buffered_y; + m_ItemsYPositions[pList.m_Items.size()] = buffered_y; // Setup scrollbar if (scrollbar) @@ -330,17 +329,11 @@ { CRect rect = GetListRect(); - CGUISpriteInstance* sprite = NULL; - CGUISpriteInstance* sprite_selectarea = NULL; - int cell_id; - GUI::GetSettingPointer(this, _sprite, sprite); - GUI::GetSettingPointer(this, _sprite_selected, sprite_selectarea); - GUI::GetSetting(this, "cell_id", cell_id); + CGUISpriteInstance& sprite = GUI::GetSetting(this, _sprite); + CGUISpriteInstance& sprite_selectarea = GUI::GetSetting(this, _sprite_selected); - CGUIList* pList; - GUI::GetSettingPointer(this, "list", pList); - - GetGUI()->DrawSprite(*sprite, cell_id, bz, rect); + const int cell_id = GUI::GetSetting(this, "cell_id"); + m_pGUI->DrawSprite(sprite, cell_id, bz, rect); float scroll = 0.f; if (scrollbar) @@ -372,14 +365,16 @@ rect_sel.left = GetScrollBar(0).GetOuterRect().right; } - GetGUI()->DrawSprite(*sprite_selectarea, cell_id, bz+0.05f, rect_sel); + m_pGUI->DrawSprite(sprite_selectarea, cell_id, bz+0.05f, rect_sel); } } CGUIColor color; GUI::GetSetting(this, _textcolor, color); - for (size_t i = 0; i < pList->m_Items.size(); ++i) + const CGUIList& pList = GUI::GetSetting(this, "list"); + + for (size_t i = 0; i < pList.m_Items.size(); ++i) { if (m_ItemsYPositions[i+1] - scroll < 0 || m_ItemsYPositions[i] - scroll > rect.GetHeight()) @@ -406,18 +401,17 @@ void CList::AddItem(const CStrW& str, const CStrW& data) { - CGUIList* pList; - CGUIList* pListData; - GUI::GetSettingPointer(this, "list", pList); - GUI::GetSettingPointer(this, "list_data", pListData); - CGUIString gui_string; gui_string.SetValue(str); - pList->m_Items.push_back(gui_string); + + // Do not send a settings-changed message + CGUIList& pList = GUI::GetSetting(this, "list"); + pList.m_Items.push_back(gui_string); CGUIString data_string; data_string.SetValue(data); - pListData->m_Items.push_back(data_string); + CGUIList& pListData = GUI::GetSetting(this, "list_data"); + pListData.m_Items.push_back(data_string); // TODO Temp SetupText(); @@ -438,13 +432,11 @@ void CList::SelectNextElement() { - int selected; - GUI::GetSetting(this, "selected", selected); + int selected = GUI::GetSetting(this, "selected"); - CGUIList* pList; - GUI::GetSettingPointer(this, "list", pList); + const CGUIList& pList = GUI::GetSetting(this, "list"); - if (selected != (int)pList->m_Items.size()-1) + if (selected != static_cast(pList.m_Items.size()) - 1) { ++selected; GUI::SetSetting(this, "selected", selected); @@ -457,8 +449,7 @@ void CList::SelectPrevElement() { - int selected; - GUI::GetSetting(this, "selected", selected); + int selected = GUI::GetSetting(this, "selected"); if (selected > 0) { @@ -473,38 +464,29 @@ void CList::SelectFirstElement() { - int selected; - GUI::GetSetting(this, "selected", selected); - - if (selected >= 0) + if (GUI::GetSetting(this, "selected") >= 0) GUI::SetSetting(this, "selected", 0); } void CList::SelectLastElement() { - int selected; - GUI::GetSetting(this, "selected", selected); - - CGUIList* pList; - GUI::GetSettingPointer(this, "list", pList); + const CGUIList& pList = GUI::GetSetting(this, "list"); + const int index = static_cast(pList.m_Items.size()) - 1; - if (selected != (int)pList->m_Items.size()-1) - GUI::SetSetting(this, "selected", (int)pList->m_Items.size()-1); + if (GUI::GetSetting(this, "selected") != index) + GUI::SetSetting(this, "selected", index); } void CList::UpdateAutoScroll() { - int selected; - bool scrollbar; - float scroll; - GUI::GetSetting(this, "selected", selected); - GUI::GetSetting(this, "scrollbar", scrollbar); + const int selected = GUI::GetSetting(this, "selected"); + const bool scrollbar = GUI::GetSetting(this, "scrollbar"); // No scrollbar, no scrolling (at least it's not made to work properly). - if (!scrollbar || selected < 0 || (std::size_t) selected >= m_ItemsYPositions.size()) + if (!scrollbar || selected < 0 || static_cast(selected) >= m_ItemsYPositions.size()) return; - scroll = GetScrollBar(0).GetPos(); + float scroll = GetScrollBar(0).GetPos(); // Check upper boundary if (m_ItemsYPositions[selected] < scroll) @@ -522,13 +504,8 @@ int CList::GetHoveredItem() { - bool scrollbar; - CGUIList* pList; - GUI::GetSetting(this, "scrollbar", scrollbar); - GUI::GetSettingPointer(this, "list", pList); - 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; const CRect& rect = GetListRect(); CPos mouse = m_pGUI->GetMousePos(); @@ -540,7 +517,8 @@ mouse.x <= GetScrollBar(0).GetOuterRect().right) return -1; - for (size_t i = 0; i < pList->m_Items.size(); ++i) + const CGUIList& pList = GUI::GetSetting(this, "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]) return i; Index: ps/trunk/source/gui/COList.cpp =================================================================== --- ps/trunk/source/gui/COList.cpp +++ ps/trunk/source/gui/COList.cpp @@ -41,10 +41,8 @@ void COList::SetupText() { - CGUIList* pList; - GUI::GetSettingPointer(this, "list", pList); - - m_ItemsYPositions.resize(pList->m_Items.size() + 1); + const CGUIList& pList = GUI::GetSetting(this, "list"); + m_ItemsYPositions.resize(pList.m_Items.size() + 1); // Delete all generated texts. Some could probably be saved, // but this is easier, and this function will never be called @@ -86,7 +84,7 @@ // Generate texts float buffered_y = 0.f; - for (size_t i = 0; i < pList->m_Items.size(); ++i) + for (size_t i = 0; i < pList.m_Items.size(); ++i) { m_ItemsYPositions[i] = buffered_y; float shift = 0.0f; @@ -96,11 +94,10 @@ if (column.m_Width > 0 && column.m_Width < 1) width *= m_TotalAvailableColumnWidth; - CGUIList* pList_c; - GUI::GetSettingPointer(this, "list_" + column.m_Id, pList_c); + CGUIList& pList_c = GUI::GetSetting(this, "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); + if (!pList_c.m_Items[i].GetOriginalString().empty()) + text = &AddText(pList_c.m_Items[i], font, width, buffer_zone, this); else { // Minimum height of a space character of the current font size @@ -113,7 +110,7 @@ buffered_y += shift; } - m_ItemsYPositions[pList->m_Items.size()] = buffered_y; + m_ItemsYPositions[pList.m_Items.size()] = buffered_y; if (scrollbar) { @@ -316,17 +313,13 @@ CRect rect = GetListRect(); - CGUISpriteInstance* sprite = NULL; - CGUISpriteInstance* sprite_selectarea = NULL; + CGUISpriteInstance& sprite = GUI::GetSetting(this, _sprite); + CGUISpriteInstance& sprite_selectarea = GUI::GetSetting(this, _sprite_selected); + int cell_id; - GUI::GetSettingPointer(this, _sprite, sprite); - GUI::GetSettingPointer(this, _sprite_selected, sprite_selectarea); GUI::GetSetting(this, "cell_id", cell_id); - CGUIList* pList; - GUI::GetSettingPointer(this, "list", pList); - - GetGUI()->DrawSprite(*sprite, cell_id, bz, rect); + m_pGUI->DrawSprite(sprite, cell_id, bz, rect); float scroll = 0.f; if (scrollbar) @@ -362,16 +355,15 @@ } // Draw item selection - GetGUI()->DrawSprite(*sprite_selectarea, cell_id, bz+0.05f, rect_sel); + m_pGUI->DrawSprite(sprite_selectarea, cell_id, bz+0.05f, rect_sel); } } // Draw line above column header - CGUISpriteInstance* sprite_heading = NULL; - GUI::GetSettingPointer(this, "sprite_heading", sprite_heading); + CGUISpriteInstance& sprite_heading = GUI::GetSetting(this, "sprite_heading"); CRect rect_head(m_CachedActualSize.left, m_CachedActualSize.top, m_CachedActualSize.right, m_CachedActualSize.top + m_HeadingHeight); - GetGUI()->DrawSprite(*sprite_heading, cell_id, bz, rect_head); + m_pGUI->DrawSprite(sprite_heading, cell_id, bz, rect_head); // Draw column headers bool sortable; @@ -404,21 +396,22 @@ // Draw sort arrows in colum header if (sortable) { - CGUISpriteInstance* sprite; + CStr spriteName; if (selectedColumn == m_Columns[col].m_Id) { if (selectedColumnOrder == 0) LOGERROR("selected_column_order must not be 0"); if (selectedColumnOrder != -1) - GUI::GetSettingPointer(this, "sprite_asc", sprite); + spriteName = "sprite_asc"; else - GUI::GetSettingPointer(this, "sprite_desc", sprite); + spriteName = "sprite_desc"; } else - GUI::GetSettingPointer(this, "sprite_not_sorted", sprite); + spriteName = "sprite_not_sorted"; - GetGUI()->DrawSprite(*sprite, cell_id, bz + 0.1f, CRect(leftTopCorner + CPos(width - SORT_SPRITE_DIM, 0), leftTopCorner + CPos(width, SORT_SPRITE_DIM))); + CGUISpriteInstance& sprite = GUI::GetSetting(this, spriteName); + m_pGUI->DrawSprite(sprite, cell_id, bz + 0.1f, CRect(leftTopCorner + CPos(width - SORT_SPRITE_DIM, 0), leftTopCorner + CPos(width, SORT_SPRITE_DIM))); } // Draw column header text @@ -427,8 +420,9 @@ } // Draw list items for each column + const CGUIList& pList = GUI::GetSetting(this, "list"); const size_t objectsCount = m_Columns.size(); - for (size_t i = 0; i < pList->m_Items.size(); ++i) + for (size_t i = 0; i < pList.m_Items.size(); ++i) { if (m_ItemsYPositions[i+1] - scroll < 0 || m_ItemsYPositions[i] - scroll > rect.GetHeight()) Index: ps/trunk/source/gui/CProgressBar.cpp =================================================================== --- ps/trunk/source/gui/CProgressBar.cpp +++ ps/trunk/source/gui/CProgressBar.cpp @@ -64,20 +64,19 @@ void CProgressBar::Draw() { + CGUISpriteInstance& sprite_bar = GUI::GetSetting(this, "sprite_bar"); + CGUISpriteInstance& sprite_background = GUI::GetSetting(this, "sprite_background"); + float bz = GetBufferedZ(); - CGUISpriteInstance* sprite_background; - CGUISpriteInstance* sprite_bar; int cell_id = 0; float value = 0; - GUI::GetSettingPointer(this, "sprite_background", sprite_background); - GUI::GetSettingPointer(this, "sprite_bar", sprite_bar); GUI::GetSetting(this, "caption", value); - GetGUI()->DrawSprite(*sprite_background, cell_id, bz, m_CachedActualSize); + m_pGUI->DrawSprite(sprite_background, cell_id, bz, m_CachedActualSize); // Get size of bar (notice it is drawn slightly closer, to appear above the background) CRect bar_size(m_CachedActualSize.left, m_CachedActualSize.top, m_CachedActualSize.left+m_CachedActualSize.GetWidth()*(value/100.f), m_CachedActualSize.bottom); - GetGUI()->DrawSprite(*sprite_bar, cell_id, bz+0.01f, bar_size); + m_pGUI->DrawSprite(sprite_bar, cell_id, bz+0.01f, bar_size); } Index: ps/trunk/source/gui/CSlider.cpp =================================================================== --- ps/trunk/source/gui/CSlider.cpp +++ ps/trunk/source/gui/CSlider.cpp @@ -113,19 +113,18 @@ void CSlider::Draw() { - CGUISpriteInstance* sprite; - CGUISpriteInstance* sprite_button; + CGUISpriteInstance& sprite = GUI::GetSetting(this, "sprite_bar"); + CGUISpriteInstance& sprite_button = GUI::GetSetting(this, "sprite"); + int cell_id; - GUI::GetSettingPointer(this, "sprite_bar", sprite); - GUI::GetSettingPointer(this, "sprite", sprite_button); GUI::GetSetting(this, "cell_id", cell_id); CRect slider_line(m_CachedActualSize); slider_line.left += m_ButtonSide / 2.0f; slider_line.right -= m_ButtonSide / 2.0f; float bz = GetBufferedZ(); - GetGUI()->DrawSprite(*sprite, cell_id, bz, slider_line); - GetGUI()->DrawSprite(*sprite_button, cell_id, bz, GetButtonRect()); + m_pGUI->DrawSprite(sprite, cell_id, bz, slider_line); + m_pGUI->DrawSprite(sprite_button, cell_id, bz, GetButtonRect()); } void CSlider::UpdateValue() Index: ps/trunk/source/gui/CText.cpp =================================================================== --- ps/trunk/source/gui/CText.cpp +++ ps/trunk/source/gui/CText.cpp @@ -75,9 +75,6 @@ // TODO Gee: (2004-08-14) Don't define standard like this. Do it with the default style. font = L"default"; - CGUIString* caption = nullptr; - GUI::GetSettingPointer(this, "caption", caption); - bool scrollbar; GUI::GetSetting(this, "scrollbar", scrollbar); @@ -86,10 +83,10 @@ if (scrollbar && GetScrollBar(0).GetStyle()) width -= GetScrollBar(0).GetStyle()->m_Width; + const CGUIString& caption = GUI::GetSetting(this, "caption"); + const float buffer_zone = GUI::GetSetting(this, "buffer_zone"); - float buffer_zone = 0.f; - GUI::GetSetting(this, "buffer_zone", buffer_zone); - m_GeneratedTexts[0] = CGUIText(m_pGUI, *caption, font, width, buffer_zone, this); + m_GeneratedTexts[0] = CGUIText(m_pGUI, caption, font, width, buffer_zone, this); if (!scrollbar) CalculateTextPosition(m_CachedActualSize, m_TextPos, m_GeneratedTexts[0]); @@ -198,14 +195,14 @@ // Draw scrollbar IGUIScrollBarOwner::Draw(); - CGUISpriteInstance* sprite; + CGUISpriteInstance& sprite = GUI::GetSetting(this, "sprite"); + int cell_id; bool clip; - GUI::GetSettingPointer(this, "sprite", sprite); GUI::GetSetting(this, "cell_id", cell_id); GUI::GetSetting(this, "clip", clip); - GetGUI()->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize); + m_pGUI->DrawSprite(sprite, cell_id, bz, m_CachedActualSize); float scroll = 0.f; if (scrollbar) Index: ps/trunk/source/gui/CTooltip.cpp =================================================================== --- ps/trunk/source/gui/CTooltip.cpp +++ ps/trunk/source/gui/CTooltip.cpp @@ -72,13 +72,12 @@ float buffer_zone = 0.f; GUI::GetSetting(this, "buffer_zone", buffer_zone); - CGUIString* caption = nullptr; - GUI::GetSettingPointer(this, "caption", caption); + const CGUIString& caption = GUI::GetSetting(this, "caption"); float max_width = 0.f; GUI::GetSetting(this, "maxwidth", max_width); - m_GeneratedTexts[0] = CGUIText(m_pGUI, *caption, font, max_width, buffer_zone, this); + m_GeneratedTexts[0] = CGUIText(m_pGUI, caption, font, max_width, buffer_zone, this); // Position the tooltip relative to the mouse: @@ -149,8 +148,7 @@ { float z = 900.f; // TODO: Find a nicer way of putting the tooltip on top of everything else - CGUISpriteInstance* sprite; - GUI::GetSettingPointer(this, "sprite", sprite); + CGUISpriteInstance& sprite = GUI::GetSetting(this, "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 @@ -160,7 +158,7 @@ m_GeneratedTextsValid = true; } - GetGUI()->DrawSprite(*sprite, 0, z, m_CachedActualSize); + m_pGUI->DrawSprite(sprite, 0, z, m_CachedActualSize); CGUIColor color; GUI::GetSetting(this, "textcolor", color); Index: ps/trunk/source/gui/GUIutil.h =================================================================== --- ps/trunk/source/gui/GUIutil.h +++ ps/trunk/source/gui/GUIutil.h @@ -132,12 +132,27 @@ public: NONCOPYABLE(GUI); + /** + * Determines whether a setting with the given name is registered. + * This function may be used as a safeguard for GetSetting. + */ + static bool HasSetting(const IGUIObject* pObject, const CStr& Setting); + + /** + * 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. + * 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); + // 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); /** - * Retrieves a setting by name from object pointer + * Copy-assigns the current setting value to the given reference. * * @param pObject Object pointer * @param Setting Setting by name @@ -147,10 +162,6 @@ /** * Sets a value by name using a real datatype as input. - * - * This is the official way of setting a setting, no other - * way should only cautiously be used! - * * This variant will use the move-assignment. * * @param pObject Object pointer Index: ps/trunk/source/gui/GUIutil.cpp =================================================================== --- ps/trunk/source/gui/GUIutil.cpp +++ ps/trunk/source/gui/GUIutil.cpp @@ -326,6 +326,18 @@ } template +bool GUI::HasSetting(const IGUIObject* pObject, const CStr& Setting) +{ + return pObject->m_Settings.count(Setting) != 0; +} + +template +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; @@ -406,6 +418,8 @@ // Instantiate templated functions: // These functions avoid copies by working with a pointer and move semantics. #define TYPE(T) \ + template bool GUI::HasSetting(const IGUIObject* pObject, const CStr& Setting); \ + template T& GUI::GetSetting(const IGUIObject* pObject, const CStr& Setting); \ template PSRETURN GUI::GetSettingPointer(const IGUIObject* pObject, const CStr& Setting, T*& Value); \ template PSRETURN GUI::SetSetting(IGUIObject* pObject, const CStr& Setting, T& Value, const bool& SkipMessage); \ template class CGUISetting; \ Index: ps/trunk/source/gui/IGUIObject.cpp =================================================================== --- ps/trunk/source/gui/IGUIObject.cpp +++ ps/trunk/source/gui/IGUIObject.cpp @@ -222,16 +222,15 @@ float aspectratio = 0.f; GUI::GetSetting(this, "aspectratio", aspectratio); - CClientArea* ca; - GUI::GetSettingPointer(this, "size", ca); + const CClientArea& ca = GUI::GetSetting(this, "size"); // 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()) - m_CachedActualSize = ca->GetClientArea(m_pParent->m_CachedActualSize); + 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)); + m_CachedActualSize = ca.GetClientArea(CRect(0.f, 0.f, g_xres / g_GuiScale, g_yres / g_GuiScale)); // In a few cases, GUI objects have to resize to fill the screen // but maintain a constant aspect ratio.