Move static GUI<>::GetSetting operating on IGUIObject member to a IGUIObject member function, grouping it with SettingExists and AddSetting.

Differential Revision: https://code.wildfiregames.com/D2230
Tested on: gcc 9.1.0, Jenkins

This was SVN commit r22789.
This commit is contained in:
elexis 2019-08-26 12:25:07 +00:00
parent 85d01b839c
commit 92b6cdfeab
21 changed files with 273 additions and 259 deletions

View File

@ -60,10 +60,10 @@ void CButton::SetupText()
m_GeneratedTexts[0] = CGUIText(
m_pGUI,
GUI<CGUIString>::GetSetting(this, "caption"),
GUI<CStrW>::GetSetting(this, "font"),
GetSetting<CGUIString>("caption"),
GetSetting<CStrW>("font"),
m_CachedActualSize.GetWidth(),
GUI<float>::GetSetting(this, "buffer_zone"),
GetSetting<float>("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<CGUISpriteInstance>::GetSetting(this, strSprite);
CGUISpriteInstance& sprite_over = GUI<CGUISpriteInstance>::GetSetting(this, strSpriteOver);
CGUISpriteInstance& sprite_pressed = GUI<CGUISpriteInstance>::GetSetting(this, strSpritePressed);
CGUISpriteInstance& sprite_disabled = GUI<CGUISpriteInstance>::GetSetting(this, strSpriteDisabled);
CGUISpriteInstance& sprite = GetSetting<CGUISpriteInstance>(strSprite);
CGUISpriteInstance& sprite_over = GetSetting<CGUISpriteInstance>(strSpriteOver);
CGUISpriteInstance& sprite_pressed = GetSetting<CGUISpriteInstance>(strSpritePressed);
CGUISpriteInstance& sprite_disabled = GetSetting<CGUISpriteInstance>(strSpriteDisabled);
const int cell_id = GUI<int>::GetSetting(this, strCellId);
const i32 cell_id = GetSetting<i32>(strCellId);
DrawButton(m_CachedActualSize, bz, sprite, sprite_over, sprite_pressed, sprite_disabled, cell_id);

View File

@ -44,9 +44,9 @@ CChart::CChart(CGUI& pGUI)
AddSetting<CGUISeries>("series");
AddSetting<EAlign>("text_align");
m_AxisWidth = GUI<float>::GetSetting(this, "axis_width");
m_FormatX = GUI<CStrW>::GetSetting(this, "format_x");
m_FormatY = GUI<CStrW>::GetSetting(this, "format_y");
m_AxisWidth = GetSetting<float>("axis_width");
m_FormatX = GetSetting<CStrW>("format_x");
m_FormatY = GetSetting<CStrW>("format_y");
}
CChart::~CChart()
@ -60,9 +60,9 @@ void CChart::HandleMessage(SGUIMessage& Message)
{
case GUIM_SETTINGS_UPDATED:
{
m_AxisWidth = GUI<float>::GetSetting(this, "axis_width");
m_FormatX = GUI<CStrW>::GetSetting(this, "format_x");
m_FormatY = GUI<CStrW>::GetSetting(this, "format_y");
m_AxisWidth = GetSetting<float>("axis_width");
m_FormatX = GetSetting<CStrW>("format_x");
m_FormatY = GetSetting<CStrW>("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<CGUIColor>::GetSetting(this, "axis_color"), vertices);
DrawTriangleStrip(shader, GetSetting<CGUIColor>("axis_color"), vertices);
}
void CChart::Draw()
@ -182,8 +182,8 @@ CRect CChart::GetChartRect() const
void CChart::UpdateSeries()
{
const CGUISeries& pSeries = GUI<CGUISeries>::GetSetting(this, "series");
const CGUIList& pSeriesColor = GUI<CGUIList>::GetSetting(this, "series_color");
const CGUISeries& pSeries = GetSetting<CGUISeries>("series");
const CGUIList& pSeriesColor = GetSetting<CGUIList>("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<CStrW>::GetSetting(this, "font");
const float buffer_zone = GUI<float>::GetSetting(this, "buffer_zone");
const CStrW& font = GetSetting<CStrW>("font");
const float buffer_zone = GetSetting<float>("buffer_zone");
// Add Y-axis
m_FormatY = GUI<CStrW>::GetSetting(this, "format_y");
m_FormatY = GetSetting<CStrW>("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<CStrW>::GetSetting(this, "format_x");
m_FormatX = GetSetting<CStrW>("format_x");
const float width = GetChartRect().GetWidth();
if (m_EqualX)
{

View File

@ -70,10 +70,10 @@ void CCheckBox::SetupText()
m_GeneratedTexts[0] = CGUIText(
m_pGUI,
GUI<CGUIString>::GetSetting(this, "caption"),
GUI<CStrW>::GetSetting(this, "font"),
m_CachedActualSize.GetWidth() - GUI<float>::GetSetting(this, "square_side"),
GUI<float>::GetSetting(this, "buffer_zone"),
GetSetting<CGUIString>("caption"),
GetSetting<CStrW>("font"),
m_CachedActualSize.GetWidth() - GetSetting<float>("square_side"),
GetSetting<float>("buffer_zone"),
this);
}
@ -88,7 +88,7 @@ void CCheckBox::HandleMessage(SGUIMessage& Message)
case GUIM_PRESSED:
{
// Switch to opposite.
GUI<bool>::SetSetting(this, "checked", !GUI<bool>::GetSetting(this, "checked"));
GUI<bool>::SetSetting(this, "checked", !GetSetting<bool>("checked"));
break;
}
@ -99,22 +99,22 @@ void CCheckBox::HandleMessage(SGUIMessage& Message)
void CCheckBox::Draw()
{
if (GUI<bool>::GetSetting(this, "checked"))
if (GetSetting<bool>("checked"))
DrawButton(
m_CachedActualSize,
GetBufferedZ(),
GUI<CGUISpriteInstance>::GetSetting(this, "sprite2"),
GUI<CGUISpriteInstance>::GetSetting(this, "sprite2_over"),
GUI<CGUISpriteInstance>::GetSetting(this, "sprite2_pressed"),
GUI<CGUISpriteInstance>::GetSetting(this, "sprite2_disabled"),
GUI<int>::GetSetting(this, "cell_id"));
GetSetting<CGUISpriteInstance>("sprite2"),
GetSetting<CGUISpriteInstance>("sprite2_over"),
GetSetting<CGUISpriteInstance>("sprite2_pressed"),
GetSetting<CGUISpriteInstance>("sprite2_disabled"),
GetSetting<i32>("cell_id"));
else
DrawButton(
m_CachedActualSize,
GetBufferedZ(),
GUI<CGUISpriteInstance>::GetSetting(this, "sprite"),
GUI<CGUISpriteInstance>::GetSetting(this, "sprite_over"),
GUI<CGUISpriteInstance>::GetSetting(this, "sprite_pressed"),
GUI<CGUISpriteInstance>::GetSetting(this, "sprite_disabled"),
GUI<int>::GetSetting(this, "cell_id"));
GetSetting<CGUISpriteInstance>("sprite"),
GetSetting<CGUISpriteInstance>("sprite_over"),
GetSetting<CGUISpriteInstance>("sprite_pressed"),
GetSetting<CGUISpriteInstance>("sprite_disabled"),
GetSetting<i32>("cell_id"));
}

View File

@ -107,8 +107,8 @@ void CDropDown::HandleMessage(SGUIMessage& Message)
if (!GetListRect().PointInside(mouse))
break;
const CGUIList& pList = GUI<CGUIList>::GetSetting(this, "list");
const bool scrollbar = GUI<bool>::GetSetting(this, "scrollbar");
const CGUIList& pList = GetSetting<CGUIList>("list");
const bool scrollbar = GetSetting<bool>("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<bool>::GetSetting(this, "enabled"))
if (GetSetting<bool>("enabled"))
PlaySound("sound_enter");
break;
}
case GUIM_MOUSE_LEAVE:
{
m_ElementHighlight = GUI<int>::GetSetting(this, "selected");
m_ElementHighlight = GetSetting<i32>("selected");
if (GUI<bool>::GetSetting(this, "enabled"))
if (GetSetting<bool>("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<bool>::GetSetting(this, "enabled"))
if (!GetSetting<bool>("enabled"))
{
PlaySound("sound_disabled");
break;
@ -164,13 +164,13 @@ void CDropDown::HandleMessage(SGUIMessage& Message)
if (!m_Open)
{
const CGUIList& pList = GUI<CGUIList>::GetSetting(this, "list");
const CGUIList& pList = GetSetting<CGUIList>("list");
if (pList.m_Items.empty())
return;
m_Open = true;
GetScrollBar(0).SetZ(GetBufferedZ());
m_ElementHighlight = GUI<int>::GetSetting(this, "selected");
m_ElementHighlight = GetSetting<i32>("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<bool>::GetSetting(this, "enabled"))
if (m_Open || !GetSetting<bool>("enabled"))
break;
m_ElementHighlight = GUI<int>::GetSetting(this, "selected");
m_ElementHighlight = GetSetting<i32>("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<bool>::GetSetting(this, "enabled"))
if (m_Open || !GetSetting<bool>("enabled"))
break;
m_ElementHighlight = GUI<int>::GetSetting(this, "selected");
m_ElementHighlight = GetSetting<i32>("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<CGUIList>::GetSetting(this, "list");
const CGUIList& pList = GetSetting<CGUIList>("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<int>::GetSetting(this, "selected");
m_ElementHighlight = GetSetting<i32>("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<float>::GetSetting(this, "dropdown_size");
const float buffer = GUI<float>::GetSetting(this, "dropdown_buffer");
const u32 minimumVisibleItems = GUI<u32>::GetSetting(this, "minimum_visible_items");
const float size = GetSetting<float>("dropdown_size");
const float buffer = GetSetting<float>("dropdown_buffer");
const u32 minimumVisibleItems = GetSetting<u32>("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<float>::GetSetting(this, "button_width");
const bool enabled = GUI<bool>::GetSetting(this, "enabled");
const int cell_id = GUI<int>::GetSetting(this, "cell_id");
const int selected = GUI<int>::GetSetting(this, "selected");
CGUISpriteInstance& sprite = GUI<CGUISpriteInstance>::GetSetting(this, enabled ? "sprite" : "sprite_disabled");
CGUISpriteInstance& sprite2 = GUI<CGUISpriteInstance>::GetSetting(this, "sprite2");
const float button_width = GetSetting<float>("button_width");
const bool enabled = GetSetting<bool>("enabled");
const int cell_id = GetSetting<i32>("cell_id");
const int selected = GetSetting<i32>("selected");
CGUISpriteInstance& sprite = GetSetting<CGUISpriteInstance>(enabled ? "sprite" : "sprite_disabled");
CGUISpriteInstance& sprite2 = GetSetting<CGUISpriteInstance>("sprite2");
m_pGUI.DrawSprite(sprite, cell_id, bz, m_CachedActualSize);
@ -450,17 +450,17 @@ void CDropDown::Draw()
if (!enabled)
{
CGUISpriteInstance& sprite2_second = GUI<CGUISpriteInstance>::GetSetting(this, "sprite2_disabled");
CGUISpriteInstance& sprite2_second = GetSetting<CGUISpriteInstance>("sprite2_disabled");
m_pGUI.DrawSprite(sprite2_second || sprite2, cell_id, bz + 0.05f, rect);
}
else if (m_Open)
{
CGUISpriteInstance& sprite2_second = GUI<CGUISpriteInstance>::GetSetting(this, "sprite2_pressed");
CGUISpriteInstance& sprite2_second = GetSetting<CGUISpriteInstance>("sprite2_pressed");
m_pGUI.DrawSprite(sprite2_second || sprite2, cell_id, bz + 0.05f, rect);
}
else if (m_MouseHovering)
{
CGUISpriteInstance& sprite2_second = GUI<CGUISpriteInstance>::GetSetting(this, "sprite2_over");
CGUISpriteInstance& sprite2_second = GetSetting<CGUISpriteInstance>("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<CGUIColor>::GetSetting(this, enabled ? "textcolor_selected" : "textcolor_disabled");
const CGUIColor& color = GetSetting<CGUIColor>(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<bool>::GetSetting(this, "scrollbar");
bool& scrollbar = GetSetting<bool>("scrollbar");
bool old = scrollbar;
if (m_Open)

View File

@ -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<bool>::GetSetting(object, "absolute"))
if (object->GetSetting<bool>("absolute"))
// If the object is absolute, we'll have to get the parent's Z buffered,
// and add to that!
GUI<float>::SetSetting(object, "z", pParent->GetBufferedZ() + 10.f, true);

View File

@ -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<EAlign>::GetSetting(pObject, "text_align");
align = pObject->GetSetting<EAlign>("text_align");
// Go through string word by word
for (int i = 0; i < static_cast<int>(string.m_Words.size()) - 1; ++i)

View File

@ -39,8 +39,8 @@ CImage::~CImage()
void CImage::Draw()
{
m_pGUI.DrawSprite(
GUI<CGUISpriteInstance>::GetSetting(this, "sprite"),
GUI<int>::GetSetting(this, "cell_id"),
GetSetting<CGUISpriteInstance>("sprite"),
GetSetting<i32>("cell_id"),
GetBufferedZ(),
m_CachedActualSize);
}

View File

@ -82,7 +82,7 @@ void CInput::UpdateBufferPositionSetting()
void CInput::ClearComposedText()
{
CStrW& pCaption = GUI<CStrW>::GetSetting(this, "caption");
CStrW& pCaption = GetSetting<CStrW>("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<CStrW>::GetSetting(this, "caption");
CStrW& pCaption = GetSetting<CStrW>("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<CStrW>::GetSetting(this, "caption");
CStrW& pCaption = GetSetting<CStrW>("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<CStrW>::GetSetting(this, "caption");
CStrW& pCaption = GetSetting<CStrW>("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<bool>::GetSetting(this, "multiline"))
if (!GetSetting<bool>("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<int>::GetSetting(this, "max_length");
const int max_length = GetSetting<i32>("max_length");
if (max_length != 0 && static_cast<int>(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<CStrW>::GetSetting(this, "caption");
CStrW& pCaption = GetSetting<CStrW>("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<bool>::GetSetting(this, "scrollbar") &&
if (GetSetting<bool>("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<CStr>::GetSetting(this, Message.value));
GetScrollBar(0).SetScrollBarStyle(GetSetting<CStr>(Message.value));
}
if (Message.value == CStr("buffer_position"))
{
m_iBufferPos = GUI<int>::GetSetting(this, Message.value);
m_iBufferPos = GetSetting<i32>(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<bool>::GetSetting(this, "multiline"))
if (!GetSetting<bool>("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<bool>::GetSetting(this, "readonly");
m_Readonly = GetSetting<bool>("readonly");
break;
}
case GUIM_MOUSE_PRESS_LEFT:
{
// Check if we're selecting the scrollbar
if (GUI<bool>::GetSetting(this, "scrollbar") &&
GUI<bool>::GetSetting(this, "multiline") &&
if (GetSetting<bool>("scrollbar") &&
GetSetting<bool>("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<CStrW>::GetSetting(this, "caption");
const CStrW& pCaption = GetSetting<CStrW>("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<CStr>::GetSetting(this, "scrollbar_style"));
GetScrollBar(0).SetScrollBarStyle(GetSetting<CStr>("scrollbar_style"));
UpdateText();
UpdateAutoScroll();
m_Readonly = GUI<bool>::GetSetting(this, "readonly");
m_Readonly = GetSetting<bool>("readonly");
break;
}
case GUIM_GOT_FOCUS:
@ -1116,7 +1116,7 @@ void CInput::UpdateCachedSize()
IGUIObject::UpdateCachedSize();
if (GUI<bool>::GetSetting(this, "scrollbar"))
if (GetSetting<bool>("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<bool>::GetSetting(this, "scrollbar");
const float buffer_zone = GUI<float>::GetSetting(this, "buffer_zone");
const bool multiline = GUI<bool>::GetSetting(this, "multiline");
const bool mask = GUI<bool>::GetSetting(this, "mask");
const bool scrollbar = GetSetting<bool>("scrollbar");
const float buffer_zone = GetSetting<float>("buffer_zone");
const bool multiline = GetSetting<bool>("multiline");
const bool mask = GetSetting<bool>("mask");
if (scrollbar && multiline)
IGUIScrollBarOwner::Draw();
const CGUIColor& color = GUI<CGUIColor>::GetSetting(this, "textcolor");
const CGUIColor& color_selected = GUI<CGUIColor>::GetSetting(this, "textcolor_selected");
const CGUIColor& color = GetSetting<CGUIColor>("textcolor");
const CGUIColor& color_selected = GetSetting<CGUIColor>("textcolor_selected");
CStrIntern font_name(GUI<CStrW>::GetSetting(this, "font").ToUTF8());
CStrIntern font_name(GetSetting<CStrW>("font").ToUTF8());
const CStrW& pCaption = GUI<CStrW>::GetSetting(this, "caption");
const CStrW& pCaption = GetSetting<CStrW>("caption");
wchar_t mask_char = L'*';
if (mask)
{
const CStrW& maskStr = GUI<CStrW>::GetSetting(this, "mask_char");
const CStrW& maskStr = GetSetting<CStrW>("mask_char");
if (maskStr.length() > 0)
mask_char = maskStr[0];
}
CGUISpriteInstance& sprite = GUI<CGUISpriteInstance>::GetSetting(this, "sprite");
CGUISpriteInstance& sprite_selectarea = GUI<CGUISpriteInstance>::GetSetting(this, "sprite_selectarea");
CGUISpriteInstance& sprite = GetSetting<CGUISpriteInstance>("sprite");
CGUISpriteInstance& sprite_selectarea = GetSetting<CGUISpriteInstance>("sprite_selectarea");
const int cell_id = GUI<int>::GetSetting(this, "cell_id");
const int cell_id = GetSetting<i32>("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<CStrW>::GetSetting(this, "caption");
const float buffer_zone = GUI<float>::GetSetting(this, "buffer_zone");
const bool multiline = GUI<bool>::GetSetting(this, "multiline");
const bool mask = GUI<bool>::GetSetting(this, "mask");
CStrIntern font_name(GUI<CStrW>::GetSetting(this, "font").ToUTF8());
const CStrW& caption = GetSetting<CStrW>("caption");
const float buffer_zone = GetSetting<float>("buffer_zone");
const bool multiline = GetSetting<bool>("multiline");
const bool mask = GetSetting<bool>("mask");
CStrIntern font_name(GetSetting<CStrW>("font").ToUTF8());
wchar_t mask_char = L'*';
if (mask)
{
const CStrW& maskStr = GUI<CStrW>::GetSetting(this, "mask_char");
const CStrW& maskStr = GetSetting<CStrW>("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<bool>::GetSetting(this, "scrollbar"))
if (GetSetting<bool>("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<float>::GetSetting(this, "buffer_zone");
const bool multiline = GUI<bool>::GetSetting(this, "multiline");
const float buffer_zone = GetSetting<float>("buffer_zone");
const bool multiline = GetSetting<bool>("multiline");
// Return position
int retPosition;
@ -1861,12 +1861,12 @@ int CInput::GetMouseHoveringTextPosition() const
if (multiline)
{
float scroll = 0.f;
if (GUI<bool>::GetSetting(this, "scrollbar"))
if (GetSetting<bool>("scrollbar"))
scroll = GetScrollBarPos(0);
// Now get the height of the font.
// TODO: Get the real font
CFontMetrics font(CStrIntern(GUI<CStrW>::GetSetting(this, "font").ToUTF8()));
CFontMetrics font(CStrIntern(GetSetting<CStrW>("font").ToUTF8()));
float spacing = (float)font.GetLineSpacing();
// Change mouse position relative to text.
@ -1943,7 +1943,7 @@ int CInput::GetXTextPosition(const std::list<SRow>::const_iterator& current, con
void CInput::DeleteCurSelection()
{
CStrW& pCaption = GUI<CStrW>::GetSetting(this, "caption");
CStrW& pCaption = GetSetting<CStrW>("caption");
int virtualFrom;
int virtualTo;
@ -1979,9 +1979,9 @@ bool CInput::SelectingText() const
float CInput::GetTextAreaWidth()
{
const float buffer_zone = GUI<float>::GetSetting(this, "buffer_zone");
const float buffer_zone = GetSetting<float>("buffer_zone");
if (GUI<bool>::GetSetting(this, "scrollbar") && GetScrollBar(0).GetStyle())
if (GetSetting<bool>("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<float>::GetSetting(this, "buffer_zone");
const float buffer_zone = GetSetting<float>("buffer_zone");
// Autoscrolling up and down
if (GUI<bool>::GetSetting(this, "multiline"))
if (GetSetting<bool>("multiline"))
{
if (!GUI<bool>::GetSetting(this, "scrollbar"))
if (!GetSetting<bool>("scrollbar"))
return;
const float scroll = GetScrollBar(0).GetPos();
// Now get the height of the font.
// TODO: Get the real font
CFontMetrics font(CStrIntern(GUI<CStrW>::GetSetting(this, "font").ToUTF8()));
CFontMetrics font(CStrIntern(GetSetting<CStrW>("font").ToUTF8()));
float spacing = (float)font.GetLineSpacing();
//float height = font.GetHeight();

View File

@ -70,7 +70,7 @@ CList::~CList()
void CList::SetupText()
{
m_Modified = true;
const CGUIList& pList = GUI<CGUIList>::GetSetting(this, "list");
const CGUIList& pList = GetSetting<CGUIList>("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<CStrW>::GetSetting(this, "font");
const CStrW& font = GetSetting<CStrW>("font");
const bool scrollbar = GUI<bool>::GetSetting(this, "scrollbar");
const bool scrollbar = GetSetting<bool>("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<float>::GetSetting(this, "buffer_zone");
const float buffer_zone = GetSetting<float>("buffer_zone");
// Generate texts
float buffered_y = 0.f;
@ -146,7 +146,7 @@ void CList::HandleMessage(SGUIMessage& Message)
{
// TODO: Check range
if (GUI<bool>::GetSetting(this, "auto_scroll"))
if (GetSetting<bool>("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<CStr>::GetSetting(this, Message.value));
GetScrollBar(0).SetScrollBarStyle(GetSetting<CStr>(Message.value));
SetupText();
}
@ -167,7 +167,7 @@ void CList::HandleMessage(SGUIMessage& Message)
case GUIM_MOUSE_PRESS_LEFT:
{
if (!GUI<bool>::GetSetting(this, "enabled"))
if (!GetSetting<bool>("enabled"))
{
PlaySound("sound_disabled");
break;
@ -192,7 +192,7 @@ void CList::HandleMessage(SGUIMessage& Message)
case GUIM_MOUSE_LEAVE:
{
if (GUI<int>::GetSetting(this, "hovered") == -1)
if (GetSetting<i32>("hovered") == -1)
break;
GUI<int>::SetSetting(this, "hovered", -1);
@ -203,7 +203,7 @@ void CList::HandleMessage(SGUIMessage& Message)
case GUIM_MOUSE_OVER:
{
int hovered = GetHoveredItem();
if (hovered == GUI<int>::GetSetting(this, "hovered"))
if (hovered == GetSetting<i32>("hovered"))
break;
GUI<int>::SetSetting(this, "hovered", hovered);
@ -213,7 +213,7 @@ void CList::HandleMessage(SGUIMessage& Message)
case GUIM_LOAD:
{
GetScrollBar(0).SetScrollBarStyle(GUI<CStr>::GetSetting(this, "scrollbar_style"));
GetScrollBar(0).SetScrollBarStyle(GetSetting<CStr>("scrollbar_style"));
break;
}
@ -278,7 +278,7 @@ InReaction CList::ManuallyHandleEvent(const SDL_Event_* ev)
void CList::Draw()
{
DrawList(GUI<int>::GetSetting(this, "selected"), "sprite", "sprite_selectarea", "textcolor");
DrawList(GetSetting<i32>("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<bool>::GetSetting(this, "scrollbar");
const bool scrollbar = GetSetting<bool>("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<CGUISpriteInstance>::GetSetting(this, _sprite);
CGUISpriteInstance& sprite_selectarea = GUI<CGUISpriteInstance>::GetSetting(this, _sprite_selected);
CGUISpriteInstance& sprite = GetSetting<CGUISpriteInstance>(_sprite);
CGUISpriteInstance& sprite_selectarea = GetSetting<CGUISpriteInstance>(_sprite_selected);
const int cell_id = GUI<int>::GetSetting(this, "cell_id");
const int cell_id = GetSetting<i32>("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<CGUIList>::GetSetting(this, "list");
const CGUIColor& color = GUI<CGUIColor>::GetSetting(this, _textcolor);
const CGUIList& pList = GetSetting<CGUIList>("list");
const CGUIColor& color = GetSetting<CGUIColor>(_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<CGUIList>::GetSetting(this, "list");
CGUIList& pList = GetSetting<CGUIList>("list");
pList.m_Items.push_back(gui_string);
CGUIString data_string;
data_string.SetValue(data);
CGUIList& pListData = GUI<CGUIList>::GetSetting(this, "list_data");
CGUIList& pListData = GetSetting<CGUIList>("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<int>::GetSetting(this, "selected");
int selected = GetSetting<i32>("selected");
const CGUIList& pList = GUI<CGUIList>::GetSetting(this, "list");
const CGUIList& pList = GetSetting<CGUIList>("list");
if (selected != static_cast<int>(pList.m_Items.size()) - 1)
{
@ -409,7 +409,7 @@ void CList::SelectNextElement()
void CList::SelectPrevElement()
{
int selected = GUI<int>::GetSetting(this, "selected");
int selected = GetSetting<i32>("selected");
if (selected > 0)
{
@ -421,23 +421,23 @@ void CList::SelectPrevElement()
void CList::SelectFirstElement()
{
if (GUI<int>::GetSetting(this, "selected") >= 0)
if (GetSetting<i32>("selected") >= 0)
GUI<int>::SetSetting(this, "selected", 0);
}
void CList::SelectLastElement()
{
const CGUIList& pList = GUI<CGUIList>::GetSetting(this, "list");
const CGUIList& pList = GetSetting<CGUIList>("list");
const int index = static_cast<int>(pList.m_Items.size()) - 1;
if (GUI<int>::GetSetting(this, "selected") != index)
if (GetSetting<i32>("selected") != index)
GUI<int>::SetSetting(this, "selected", index);
}
void CList::UpdateAutoScroll()
{
const int selected = GUI<int>::GetSetting(this, "selected");
const bool scrollbar = GUI<bool>::GetSetting(this, "scrollbar");
const int selected = GetSetting<i32>("selected");
const bool scrollbar = GetSetting<bool>("scrollbar");
// No scrollbar, no scrolling (at least it's not made to work properly).
if (!scrollbar || selected < 0 || static_cast<std::size_t>(selected) >= m_ItemsYPositions.size())
@ -461,7 +461,7 @@ void CList::UpdateAutoScroll()
int CList::GetHoveredItem()
{
const bool scrollbar = GUI<bool>::GetSetting(this, "scrollbar");
const bool scrollbar = GetSetting<bool>("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<CGUIList>::GetSetting(this, "list");
const CGUIList& pList = GetSetting<CGUIList>("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])

View File

@ -40,7 +40,7 @@ COList::COList(CGUI& pGUI)
void COList::SetupText()
{
const CGUIList& pList = GUI<CGUIList>::GetSetting(this, "list");
const CGUIList& pList = GetSetting<CGUIList>("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<CStrW>::GetSetting(this, "font");
const bool scrollbar = GUI<bool>::GetSetting(this, "scrollbar");
const CStrW& font = GetSetting<CStrW>("font");
const bool scrollbar = GetSetting<bool>("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<float>::GetSetting(this, "buffer_zone");
const float buffer_zone = GetSetting<float>("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<CGUIList>::GetSetting(this, "list_" + column.m_Id);
CGUIList& pList_c = GetSetting<CGUIList>("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<bool>::GetSetting(this, "sortable"))
if (!GetSetting<bool>("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<CStr>::GetSetting(this, "selected_column");
int selectedColumnOrder = GUI<int>::GetSetting(this, "selected_column_order");
CStr selectedColumn = GetSetting<CStr>("selected_column");
int selectedColumnOrder = GetSetting<i32>("selected_column_order");
float xpos = 0;
for (const COListColumn& column : m_Columns)
{
if (GUI<bool>::GetSetting(this, "hidden_" + column.m_Id))
if (GetSetting<bool>("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<bool>::GetSetting(this, "scrollbar");
const bool scrollbar = GetSetting<bool>("scrollbar");
if (scrollbar)
IGUIScrollBarOwner::Draw();
CRect rect = GetListRect();
CGUISpriteInstance& sprite = GUI<CGUISpriteInstance>::GetSetting(this, _sprite);
CGUISpriteInstance& sprite_selectarea = GUI<CGUISpriteInstance>::GetSetting(this, _sprite_selected);
CGUISpriteInstance& sprite = GetSetting<CGUISpriteInstance>(_sprite);
CGUISpriteInstance& sprite_selectarea = GetSetting<CGUISpriteInstance>(_sprite_selected);
const int cell_id = GUI<int>::GetSetting(this, "cell_id");
const int cell_id = GetSetting<i32>("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<CGUISpriteInstance>::GetSetting(this, "sprite_heading");
CGUISpriteInstance& sprite_heading = GetSetting<CGUISpriteInstance>("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<bool>::GetSetting(this, "sortable");
const CStr& selectedColumn = GUI<CStr>::GetSetting(this, "selected_column");
const int selectedColumnOrder = GUI<int>::GetSetting(this, "selected_column_order");
const CGUIColor& color = GUI<CGUIColor>::GetSetting(this, _textcolor);
const bool sortable = GetSetting<bool>("sortable");
const CStr& selectedColumn = GetSetting<CStr>("selected_column");
const int selectedColumnOrder = GetSetting<i32>("selected_column_order");
const CGUIColor& color = GetSetting<CGUIColor>(_textcolor);
float xpos = 0;
for (size_t col = 0; col < m_Columns.size(); ++col)
{
if (GUI<bool>::GetSetting(this, "hidden_" + m_Columns[col].m_Id))
if (GetSetting<bool>("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<CGUISpriteInstance>::GetSetting(this, spriteName);
CGUISpriteInstance& sprite = GetSetting<CGUISpriteInstance>(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<CGUIList>::GetSetting(this, "list");
const CGUIList& pList = GetSetting<CGUIList>("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<bool>::GetSetting(this, "hidden_" + m_Columns[col].m_Id))
if (GetSetting<bool>("hidden_" + m_Columns[col].m_Id))
continue;
// Determine text position and width

View File

@ -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<float>::GetSetting(this, "caption");
const float value = GetSetting<float>("caption");
if (value > 100.f)
GUI<float>::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<CGUISpriteInstance>::GetSetting(this, "sprite_bar");
CGUISpriteInstance& sprite_background = GUI<CGUISpriteInstance>::GetSetting(this, "sprite_background");
CGUISpriteInstance& sprite_bar = GetSetting<CGUISpriteInstance>("sprite_bar");
CGUISpriteInstance& sprite_background = GetSetting<CGUISpriteInstance>("sprite_background");
float bz = GetBufferedZ();
int cell_id = 0;
const float value = GUI<float>::GetSetting(this, "caption");
const float value = GetSetting<float>("caption");
m_pGUI.DrawSprite(sprite_background, cell_id, bz, m_CachedActualSize);

View File

@ -32,10 +32,10 @@ CSlider::CSlider(CGUI& pGUI)
AddSetting<CGUISpriteInstance>("sprite_bar");
AddSetting<float>("button_width");
m_Value = GUI<float>::GetSetting(this, "value");
m_MinValue = GUI<float>::GetSetting(this, "min_value");
m_MaxValue = GUI<float>::GetSetting(this, "max_value");
m_ButtonSide = GUI<float>::GetSetting(this, "button_width");
m_Value = GetSetting<float>("value");
m_MinValue = GetSetting<float>("min_value");
m_MaxValue = GetSetting<float>("max_value");
m_ButtonSide = GetSetting<float>("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<float>::GetSetting(this, "value");
m_MinValue = GUI<float>::GetSetting(this, "min_value");
m_MaxValue = GUI<float>::GetSetting(this, "max_value");
m_ButtonSide = GUI<float>::GetSetting(this, "button_width");
m_Value = GetSetting<float>("value");
m_MinValue = GetSetting<float>("min_value");
m_MaxValue = GetSetting<float>("max_value");
m_ButtonSide = GetSetting<float>("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<CGUISpriteInstance>::GetSetting(this, "sprite_bar");
CGUISpriteInstance& sprite_button = GUI<CGUISpriteInstance>::GetSetting(this, "sprite");
const int cell_id = GUI<int>::GetSetting(this, "cell_id");
CGUISpriteInstance& sprite = GetSetting<CGUISpriteInstance>("sprite_bar");
CGUISpriteInstance& sprite_button = GetSetting<CGUISpriteInstance>("sprite");
const int cell_id = GetSetting<i32>("cell_id");
CRect slider_line(m_CachedActualSize);
slider_line.left += m_ButtonSide / 2.0f;

View File

@ -69,16 +69,16 @@ void CText::SetupText()
if (m_GeneratedTexts.empty())
return;
const bool scrollbar = GUI<bool>::GetSetting(this, "scrollbar");
const bool scrollbar = GetSetting<bool>("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<CGUIString>::GetSetting(this, "caption");
const CStrW& font = GUI<CStrW>::GetSetting(this, "font");
const float buffer_zone = GUI<float>::GetSetting(this, "buffer_zone");
const CGUIString& caption = GetSetting<CGUIString>("caption");
const CStrW& font = GetSetting<CStrW>("font");
const float buffer_zone = GetSetting<float>("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<bool>::GetSetting(this, "scroll_bottom");
const bool scroll_top = GUI<bool>::GetSetting(this, "scroll_top");
const bool scroll_bottom = GetSetting<bool>("scroll_bottom");
const bool scroll_top = GetSetting<bool>("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<CStr>::GetSetting(this, Message.value));
GetScrollBar(0).SetScrollBarStyle(GetSetting<CStr>(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<CStr>::GetSetting(this, "scrollbar_style"));
GetScrollBar(0).SetScrollBarStyle(GetSetting<CStr>("scrollbar_style"));
break;
}
@ -173,14 +173,14 @@ void CText::Draw()
{
float bz = GetBufferedZ();
const bool scrollbar = GUI<bool>::GetSetting(this, "scrollbar");
const bool scrollbar = GetSetting<bool>("scrollbar");
if (scrollbar)
IGUIScrollBarOwner::Draw();
CGUISpriteInstance& sprite = GUI<CGUISpriteInstance>::GetSetting(this, "sprite");
const int cell_id = GUI<int>::GetSetting(this, "cell_id");
const bool clip = GUI<bool>::GetSetting(this, "clip");
CGUISpriteInstance& sprite = GetSetting<CGUISpriteInstance>("sprite");
const int cell_id = GetSetting<i32>("cell_id");
const bool clip = GetSetting<bool>("clip");
m_pGUI.DrawSprite(sprite, cell_id, bz, m_CachedActualSize);
@ -207,8 +207,8 @@ void CText::Draw()
}
}
const bool enabled = GUI<bool>::GetSetting(this, "enabled");
const CGUIColor& color = GUI<CGUIColor>::GetSetting(this, enabled ? "textcolor" : "textcolor_disabled");
const bool enabled = GetSetting<bool>("enabled");
const CGUIColor& color = GetSetting<CGUIColor>(enabled ? "textcolor" : "textcolor_disabled");
if (scrollbar)
DrawText(0, color, m_CachedActualSize.TopLeft() - CPos(0.f, scroll), bz + 0.1f, cliparea);

View File

@ -65,20 +65,20 @@ void CTooltip::SetupText()
{
ENSURE(m_GeneratedTexts.size() == 1);
const CGUIString& caption = GUI<CGUIString>::GetSetting(this, "caption");
const CStrW& font = GUI<CStrW>::GetSetting(this, "font");
const float max_width = GUI<float>::GetSetting(this, "maxwidth");
const float buffer_zone = GUI<float>::GetSetting(this, "buffer_zone");
const CGUIString& caption = GetSetting<CGUIString>("caption");
const CStrW& font = GetSetting<CStrW>("font");
const float max_width = GetSetting<float>("maxwidth");
const float buffer_zone = GetSetting<float>("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<bool>::GetSetting(this, "independent") ?
const CPos& mousepos = GetSetting<bool>("independent") ?
m_pGUI.GetMousePos() :
GUI<CPos>::GetSetting(this, "_mousepos");
GetSetting<CPos>("_mousepos");
const CPos& offset = GUI<CPos>::GetSetting(this, "offset");
const CPos& offset = GetSetting<CPos>("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<EVAlign>::GetSetting(this, "anchor"))
switch (GetSetting<EVAlign>("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<CGUISpriteInstance>::GetSetting(this, "sprite");
CGUISpriteInstance& sprite = GetSetting<CGUISpriteInstance>("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<CGUIColor>::GetSetting(this, "textcolor");
const CGUIColor& color = GetSetting<CGUIColor>("textcolor");
DrawText(0, color, m_CachedActualSize.TopLeft(), z+0.1f);
}

View File

@ -87,8 +87,8 @@ bool GUITooltip::GetTooltip(IGUIObject* obj, CStr& style)
{
if (obj && obj->SettingExists("_icon_tooltip_style") && obj->MouseOverIcon())
{
style = GUI<CStr>::GetSetting(obj, "_icon_tooltip_style");
if (!GUI<CStrW>::GetSetting(obj, "_icon_tooltip").empty())
style = obj->GetSetting<CStr>("_icon_tooltip_style");
if (!obj->GetSetting<CStrW>("_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<CStr>::GetSetting(obj, "tooltip_style");
if (!GUI<CStrW>::GetSetting(obj, "tooltip").empty())
style = obj->GetSetting<CStr>("tooltip_style");
if (!obj->GetSetting<CStrW>("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<CStr>::GetSetting(tooltipobj, "use_object");
const CStr& usedObjectName = tooltipobj->GetSetting<CStr>("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<bool>::SetSetting(usedobj, "hidden", false);
const CStrW& text = GUI<CStrW>::GetSetting(obj, m_IsIconTooltip ? "_icon_tooltip" : "tooltip");
const CStrW& text = obj->GetSetting<CStrW>(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<CStr>::GetSetting(tooltipobj, "use_object");
const CStr& usedObjectName = tooltipobj->GetSetting<CStr>("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<bool>::GetSetting(tooltipobj, "hide_object"))
if (tooltipobj->GetSetting<bool>("hide_object"))
GUI<bool>::SetSetting(usedobj, "hidden", true);
}
else
GUI<bool>::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<int>::GetSetting(tooltipobj, "delay");
return tooltipobj->GetSetting<i32>("delay");
}
void GUITooltip::Update(IGUIObject* Nearest, const CPos& MousePos, CGUI& GUI)

View File

@ -80,12 +80,6 @@ void CGUISetting<T>::ToJSVal(JSContext* cx, JS::MutableHandleValue Value)
ScriptInterface::ToJSVal<T>(cx, Value, m_pSetting);
};
template <typename T>
T& GUI<T>::GetSetting(const IGUIObject* pObject, const CStr& Setting)
{
return static_cast<CGUISetting<T>* >(pObject->m_Settings.at(Setting))->m_pSetting;
}
template <typename T>
PSRETURN GUI<T>::SetSetting(IGUIObject* pObject, const CStr& Setting, T& Value, const bool& SkipMessage)
{
@ -129,7 +123,7 @@ PSRETURN GUI<T>::SetSettingWrap(IGUIObject* pObject, const CStr& Setting, const
else if (Setting == "hidden")
{
// Hiding an object requires us to reset it and all children
if (GUI<bool>::GetSetting(pObject, Setting))
if (pObject->GetSetting<bool>(Setting))
pObject->RecurseObject(nullptr, &IGUIObject::ResetStates);
}
@ -145,7 +139,6 @@ PSRETURN GUI<T>::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<T>::GetSetting(const IGUIObject* pObject, const CStr& Setting); \
template PSRETURN GUI<T>::SetSetting(IGUIObject* pObject, const CStr& Setting, T& Value, const bool& SkipMessage); \
template class CGUISetting<T>; \

View File

@ -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.

View File

@ -32,7 +32,7 @@ IGUIButtonBehavior::~IGUIButtonBehavior()
void IGUIButtonBehavior::HandleMessage(SGUIMessage& Message)
{
const bool enabled = GUI<bool>::GetSetting(this, "enabled");
const bool enabled = GetSetting<bool>("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<CGUIColor>::GetSetting(this, "textcolor");
const CGUIColor& color = GetSetting<CGUIColor>("textcolor");
if (!GUI<bool>::GetSetting(this, "enabled"))
return GUI<CGUIColor>::GetSetting(this, "textcolor_disabled") || color;
if (!GetSetting<bool>("enabled"))
return GetSetting<CGUIColor>("textcolor_disabled") || color;
if (m_MouseHovering)
{
if (m_Pressed)
return GUI<CGUIColor>::GetSetting(this, "textcolor_pressed") || color;
return GetSetting<CGUIColor>("textcolor_pressed") || color;
else
return GUI<CGUIColor>::GetSetting(this, "textcolor_over") || color;
return GetSetting<CGUIColor>("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<bool>::GetSetting(this, "enabled"))
if (!GetSetting<bool>("enabled"))
m_pGUI.DrawSprite(sprite_disabled || sprite, cell_id, z, rect);
else if (m_MouseHovering)
{

View File

@ -128,6 +128,23 @@ void IGUIObject::AddSetting(const CStr& Name)
m_Settings[Name] = new CGUISetting<T>(*this, Name);
}
bool IGUIObject::SettingExists(const CStr& Setting) const
{
return m_Settings.count(Setting) == 1;
}
template <typename T>
T& IGUIObject::GetSetting(const CStr& Setting)
{
return static_cast<CGUISetting<T>* >(m_Settings.at(Setting))->m_pSetting;
}
template <typename T>
const T& IGUIObject::GetSetting(const CStr& Setting) const
{
return static_cast<CGUISetting<T>* >(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<CClientArea>::GetSetting(this, "size");
const float aspectratio = GUI<float>::GetSetting(this, "aspectratio");
const CClientArea& ca = GetSetting<CClientArea>("size");
const float aspectratio = GetSetting<float>("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<bool>::GetSetting(this, "absolute") && m_pParent && !IsRootObject())
if (!GetSetting<bool>("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<float>::GetSetting(this, "z");
const float Z = GetSetting<float>("z");
if (GUI<bool>::GetSetting(this, "absolute"))
if (GetSetting<bool>("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<bool>::GetSetting(this, strHidden);
return GetSetting<bool>(strHidden);
}
bool IGUIObject::IsHiddenOrGhost() const
{
static const CStr strGhost("ghost");
return IsHidden() || GUI<bool>::GetSetting(this, strGhost);
return IsHidden() || GetSetting<bool>(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<CStrW>::GetSetting(this, settingName);
const CStrW& soundPath = GetSetting<CStrW>(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<T>(const CStr& Name);
#include "GUItypes.h"
#define TYPE(T) \
template void IGUIObject::AddSetting<T>(const CStr& Name); \
template T& IGUIObject::GetSetting<T>(const CStr& Setting); \
template const T& IGUIObject::GetSetting<T>(const CStr& Setting) const; \
#include "gui/GUItypes.h"
#undef TYPE

View File

@ -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 <typename T>
T& GetSetting(const CStr& Setting);
template <typename T>
const T& GetSetting(const CStr& Setting) const;
/**
* Returns whether this is object is set to be hidden.
*/

View File

@ -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<EVAlign>::GetSetting(this, "text_valign"))
switch (GetSetting<EVAlign>("text_valign"))
{
case EVAlign_Top:
TextPos.y = ObjSize.top;