Replace copy-assigning GUI<T>::GetSetting from c2a71e41bf
with the reference returning GetSetting from 3dfa23cd25
.
Avoids one or two dozen unoptimizable string copies and two CPos copies, mostly in SetupText. The reference return allows to mark values as const where the previous one prevented that. This also reveals unused variables where the previous code hid them. Thus use unused variable "buffer_zone" in the otherwise unused (sinceb1422137e5
, refs0f807c643a
) CCheckBox::SetupText() fromb5f6d19332
and use the unused variable "scrollbar" in CInput GUIM_MOUSE_PRESS_LEFT from4113aa0a36
. Refs unintentionally copied DrawCall cache due to GetSetting copying inc19f3608a5
, fixed in8f4f8e240f
. Differential Revision: https://code.wildfiregames.com/D2215 This was SVN commit r22765.
This commit is contained in:
parent
4d77bd6542
commit
040624acff
@ -58,18 +58,13 @@ void CButton::SetupText()
|
||||
{
|
||||
ENSURE(m_GeneratedTexts.size() == 1);
|
||||
|
||||
CStrW font;
|
||||
if (GUI<CStrW>::GetSetting(this, "font", font) != PSRETURN_OK || font.empty())
|
||||
// Use the default if none is specified
|
||||
// TODO Gee: (2004-08-14) Default should not be hard-coded, but be in styles!
|
||||
font = L"default";
|
||||
|
||||
const CGUIString& caption = GUI<CGUIString>::GetSetting(this, "caption");
|
||||
|
||||
float buffer_zone = 0.f;
|
||||
GUI<float>::GetSetting(this, "buffer_zone", buffer_zone);
|
||||
|
||||
m_GeneratedTexts[0] = CGUIText(m_pGUI, caption, font, m_CachedActualSize.GetWidth(), buffer_zone, this);
|
||||
m_GeneratedTexts[0] = CGUIText(
|
||||
m_pGUI,
|
||||
GUI<CGUIString>::GetSetting(this, "caption"),
|
||||
GUI<CStrW>::GetSetting(this, "font"),
|
||||
m_CachedActualSize.GetWidth(),
|
||||
GUI<float>::GetSetting(this, "buffer_zone"),
|
||||
this);
|
||||
|
||||
CalculateTextPosition(m_CachedActualSize, m_TextPos, m_GeneratedTexts[0]);
|
||||
}
|
||||
@ -83,9 +78,7 @@ void CButton::HandleMessage(SGUIMessage& Message)
|
||||
|
||||
void CButton::Draw()
|
||||
{
|
||||
float bz = GetBufferedZ();
|
||||
|
||||
int cell_id;
|
||||
const float bz = GetBufferedZ();
|
||||
|
||||
// Statically initialise some strings, so we don't have to do
|
||||
// lots of allocation every time this function is called
|
||||
@ -100,7 +93,7 @@ void CButton::Draw()
|
||||
CGUISpriteInstance& sprite_pressed = GUI<CGUISpriteInstance>::GetSetting(this, strSpritePressed);
|
||||
CGUISpriteInstance& sprite_disabled = GUI<CGUISpriteInstance>::GetSetting(this, strSpriteDisabled);
|
||||
|
||||
GUI<int>::GetSetting(this, strCellId, cell_id);
|
||||
const int cell_id = GUI<int>::GetSetting(this, strCellId);
|
||||
|
||||
DrawButton(m_CachedActualSize, bz, sprite, sprite_over, sprite_pressed, sprite_disabled, cell_id);
|
||||
|
||||
|
@ -44,9 +44,9 @@ CChart::CChart(CGUI& pGUI)
|
||||
AddSetting<CGUISeries>("series");
|
||||
AddSetting<EAlign>("text_align");
|
||||
|
||||
GUI<float>::GetSetting(this, "axis_width", m_AxisWidth);
|
||||
GUI<CStrW>::GetSetting(this, "format_x", m_FormatX);
|
||||
GUI<CStrW>::GetSetting(this, "format_y", m_FormatY);
|
||||
m_AxisWidth = GUI<float>::GetSetting(this, "axis_width");
|
||||
m_FormatX = GUI<CStrW>::GetSetting(this, "format_x");
|
||||
m_FormatY = GUI<CStrW>::GetSetting(this, "format_y");
|
||||
}
|
||||
|
||||
CChart::~CChart()
|
||||
@ -60,9 +60,9 @@ void CChart::HandleMessage(SGUIMessage& Message)
|
||||
{
|
||||
case GUIM_SETTINGS_UPDATED:
|
||||
{
|
||||
GUI<float>::GetSetting(this, "axis_width", m_AxisWidth);
|
||||
GUI<CStrW>::GetSetting(this, "format_x", m_FormatX);
|
||||
GUI<CStrW>::GetSetting(this, "format_y", m_FormatY);
|
||||
m_AxisWidth = GUI<float>::GetSetting(this, "axis_width");
|
||||
m_FormatX = GUI<CStrW>::GetSetting(this, "format_x");
|
||||
m_FormatY = GUI<CStrW>::GetSetting(this, "format_y");
|
||||
|
||||
UpdateSeries();
|
||||
break;
|
||||
@ -210,12 +210,10 @@ void CChart::SetupText()
|
||||
return;
|
||||
|
||||
const CStrW& font = GUI<CStrW>::GetSetting(this, "font");
|
||||
|
||||
float buffer_zone = 0.f;
|
||||
GUI<float>::GetSetting(this, "buffer_zone", buffer_zone);
|
||||
const float buffer_zone = GUI<float>::GetSetting(this, "buffer_zone");
|
||||
|
||||
// Add Y-axis
|
||||
GUI<CStrW>::GetSetting(this, "format_y", m_FormatY);
|
||||
m_FormatY = GUI<CStrW>::GetSetting(this, "format_y");
|
||||
const float height = GetChartRect().GetHeight();
|
||||
// TODO: split values depend on the format;
|
||||
if (m_EqualY)
|
||||
@ -232,7 +230,7 @@ void CChart::SetupText()
|
||||
}
|
||||
|
||||
// Add X-axis
|
||||
GUI<CStrW>::GetSetting(this, "format_x", m_FormatX);
|
||||
m_FormatX = GUI<CStrW>::GetSetting(this, "format_x");
|
||||
const float width = GetChartRect().GetWidth();
|
||||
if (m_EqualX)
|
||||
{
|
||||
|
@ -68,15 +68,13 @@ void CCheckBox::SetupText()
|
||||
{
|
||||
ENSURE(m_GeneratedTexts.size() == 1);
|
||||
|
||||
float square_side;
|
||||
GUI<float>::GetSetting(this, "square_side", square_side);
|
||||
|
||||
const CGUIString& caption = GUI<CGUIString>::GetSetting(this, "caption");
|
||||
const CStrW& font = GUI<CStrW>::GetSetting(this, "font");
|
||||
|
||||
float buffer_zone = 0.f;
|
||||
GUI<float>::GetSetting(this, "buffer_zone", buffer_zone);
|
||||
m_GeneratedTexts[0] = CGUIText(m_pGUI, caption, font, m_CachedActualSize.GetWidth() - square_side, 0.f, this);
|
||||
m_GeneratedTexts[0] = CGUIText(
|
||||
m_pGUI,
|
||||
GUI<CGUIString>::GetSetting(this, "caption"),
|
||||
GUI<CStrW>::GetSetting(this, "font"),
|
||||
m_CachedActualSize.GetWidth() - GUI<float>::GetSetting(this, "square_side"),
|
||||
GUI<float>::GetSetting(this, "buffer_zone"),
|
||||
this);
|
||||
}
|
||||
|
||||
void CCheckBox::HandleMessage(SGUIMessage& Message)
|
||||
@ -89,12 +87,8 @@ void CCheckBox::HandleMessage(SGUIMessage& Message)
|
||||
{
|
||||
case GUIM_PRESSED:
|
||||
{
|
||||
bool checked;
|
||||
|
||||
// Switch to opposite.
|
||||
GUI<bool>::GetSetting(this, "checked", checked);
|
||||
checked = !checked;
|
||||
GUI<bool>::SetSetting(this, "checked", checked);
|
||||
GUI<bool>::SetSetting(this, "checked", !GUI<bool>::GetSetting(this, "checked"));
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -107,12 +107,9 @@ void CDropDown::HandleMessage(SGUIMessage& Message)
|
||||
if (!GetListRect().PointInside(mouse))
|
||||
break;
|
||||
|
||||
bool scrollbar;
|
||||
const CGUIList& pList = GUI<CGUIList>::GetSetting(this, "list");
|
||||
GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
|
||||
float scroll = 0.f;
|
||||
if (scrollbar)
|
||||
scroll = GetScrollBar(0).GetPos();
|
||||
const bool scrollbar = GUI<bool>::GetSetting(this, "scrollbar");
|
||||
const float scroll = scrollbar ? GetScrollBar(0).GetPos() : 0.f;
|
||||
|
||||
CRect rect = GetListRect();
|
||||
mouse.y += scroll;
|
||||
@ -141,20 +138,16 @@ void CDropDown::HandleMessage(SGUIMessage& Message)
|
||||
|
||||
case GUIM_MOUSE_ENTER:
|
||||
{
|
||||
bool enabled;
|
||||
GUI<bool>::GetSetting(this, "enabled", enabled);
|
||||
if (enabled)
|
||||
if (GUI<bool>::GetSetting(this, "enabled"))
|
||||
PlaySound("sound_enter");
|
||||
break;
|
||||
}
|
||||
|
||||
case GUIM_MOUSE_LEAVE:
|
||||
{
|
||||
GUI<int>::GetSetting(this, "selected", m_ElementHighlight);
|
||||
m_ElementHighlight = GUI<int>::GetSetting(this, "selected");
|
||||
|
||||
bool enabled;
|
||||
GUI<bool>::GetSetting(this, "enabled", enabled);
|
||||
if (enabled)
|
||||
if (GUI<bool>::GetSetting(this, "enabled"))
|
||||
PlaySound("sound_leave");
|
||||
break;
|
||||
}
|
||||
@ -163,9 +156,7 @@ void CDropDown::HandleMessage(SGUIMessage& Message)
|
||||
// a mouse click to open the dropdown, also the coordinates are changed.
|
||||
case GUIM_MOUSE_PRESS_LEFT:
|
||||
{
|
||||
bool enabled;
|
||||
GUI<bool>::GetSetting(this, "enabled", enabled);
|
||||
if (!enabled)
|
||||
if (!GUI<bool>::GetSetting(this, "enabled"))
|
||||
{
|
||||
PlaySound("sound_disabled");
|
||||
break;
|
||||
@ -179,7 +170,7 @@ void CDropDown::HandleMessage(SGUIMessage& Message)
|
||||
|
||||
m_Open = true;
|
||||
GetScrollBar(0).SetZ(GetBufferedZ());
|
||||
GUI<int>::GetSetting(this, "selected", m_ElementHighlight);
|
||||
m_ElementHighlight = GUI<int>::GetSetting(this, "selected");
|
||||
|
||||
// Start at the position of the selected item, if possible.
|
||||
GetScrollBar(0).SetPos(m_ItemsYPositions.empty() ? 0 : m_ItemsYPositions[m_ElementHighlight] - 60);
|
||||
@ -214,14 +205,12 @@ void CDropDown::HandleMessage(SGUIMessage& Message)
|
||||
|
||||
case GUIM_MOUSE_WHEEL_DOWN:
|
||||
{
|
||||
bool enabled;
|
||||
GUI<bool>::GetSetting(this, "enabled", enabled);
|
||||
|
||||
// Don't switch elements by scrolling when open, causes a confusing interaction between this and the scrollbar.
|
||||
if (m_Open || !enabled)
|
||||
if (m_Open || !GUI<bool>::GetSetting(this, "enabled"))
|
||||
break;
|
||||
|
||||
GUI<int>::GetSetting(this, "selected", m_ElementHighlight);
|
||||
m_ElementHighlight = GUI<int>::GetSetting(this, "selected");
|
||||
|
||||
if (m_ElementHighlight + 1 >= (int)m_ItemsYPositions.size() - 1)
|
||||
break;
|
||||
|
||||
@ -232,14 +221,11 @@ void CDropDown::HandleMessage(SGUIMessage& Message)
|
||||
|
||||
case GUIM_MOUSE_WHEEL_UP:
|
||||
{
|
||||
bool enabled;
|
||||
GUI<bool>::GetSetting(this, "enabled", enabled);
|
||||
|
||||
// Don't switch elements by scrolling when open, causes a confusing interaction between this and the scrollbar.
|
||||
if (m_Open || !enabled)
|
||||
if (m_Open || !GUI<bool>::GetSetting(this, "enabled"))
|
||||
break;
|
||||
|
||||
GUI<int>::GetSetting(this, "selected", m_ElementHighlight);
|
||||
m_ElementHighlight = GUI<int>::GetSetting(this, "selected");
|
||||
if (m_ElementHighlight - 1 < 0)
|
||||
break;
|
||||
|
||||
@ -362,7 +348,7 @@ InReaction CDropDown::ManuallyHandleEvent(const SDL_Event_* ev)
|
||||
result = IN_HANDLED;
|
||||
|
||||
if (update_highlight)
|
||||
GUI<int>::GetSetting(this, "selected", m_ElementHighlight);
|
||||
m_ElementHighlight = GUI<int>::GetSetting(this, "selected");
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -371,12 +357,11 @@ void CDropDown::SetupListRect()
|
||||
{
|
||||
extern int g_yres;
|
||||
extern float g_GuiScale;
|
||||
float size, buffer, yres;
|
||||
yres = g_yres / g_GuiScale;
|
||||
u32 minimumVisibleItems;
|
||||
GUI<float>::GetSetting(this, "dropdown_size", size);
|
||||
GUI<float>::GetSetting(this, "dropdown_buffer", buffer);
|
||||
GUI<u32>::GetSetting(this, "minimum_visible_items", minimumVisibleItems);
|
||||
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");
|
||||
|
||||
if (m_ItemsYPositions.empty())
|
||||
{
|
||||
@ -448,23 +433,14 @@ bool CDropDown::IsMouseOver() const
|
||||
|
||||
void CDropDown::Draw()
|
||||
{
|
||||
float bz = GetBufferedZ();
|
||||
|
||||
float dropdown_size, button_width;
|
||||
GUI<float>::GetSetting(this, "dropdown_size", dropdown_size);
|
||||
GUI<float>::GetSetting(this, "button_width", button_width);
|
||||
|
||||
int cell_id, selected = 0;
|
||||
|
||||
bool enabled;
|
||||
GUI<bool>::GetSetting(this, "enabled", enabled);
|
||||
|
||||
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");
|
||||
|
||||
GUI<int>::GetSetting(this, "cell_id", cell_id);
|
||||
GUI<int>::GetSetting(this, "selected", selected);
|
||||
|
||||
m_pGUI.DrawSprite(sprite, cell_id, bz, m_CachedActualSize);
|
||||
|
||||
if (button_width > 0.f)
|
||||
|
@ -864,10 +864,7 @@ void CGUI::Xeromyces_ReadObject(XMBElement Element, CXeromyces* pFile, IGUIObjec
|
||||
if (!ManuallySetZ)
|
||||
{
|
||||
// Set it automatically to 10 plus its parents
|
||||
bool absolute;
|
||||
GUI<bool>::GetSetting(object, "absolute", absolute);
|
||||
|
||||
if (absolute)
|
||||
if (GUI<bool>::GetSetting(object, "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);
|
||||
|
@ -80,7 +80,7 @@ CGUIText::CGUIText(const CGUI& pGUI, const CGUIString& string, const CStrW& Font
|
||||
// to run through the TextCalls a second time in the CalculateTextPosition method again
|
||||
EAlign align = EAlign_Left;
|
||||
if (pObject->SettingExists("text_align"))
|
||||
GUI<EAlign>::GetSetting(pObject, "text_align", align);
|
||||
align = GUI<EAlign>::GetSetting(pObject, "text_align");
|
||||
|
||||
// Go through string word by word
|
||||
for (int i = 0; i < static_cast<int>(string.m_Words.size()) - 1; ++i)
|
||||
|
@ -38,11 +38,9 @@ CImage::~CImage()
|
||||
|
||||
void CImage::Draw()
|
||||
{
|
||||
float bz = GetBufferedZ();
|
||||
|
||||
int cell_id;
|
||||
GUI<int>::GetSetting(this, "cell_id", cell_id);
|
||||
|
||||
CGUISpriteInstance& sprite = GUI<CGUISpriteInstance>::GetSetting(this, "sprite");
|
||||
m_pGUI.DrawSprite(sprite, cell_id, bz, m_CachedActualSize);
|
||||
m_pGUI.DrawSprite(
|
||||
GUI<CGUISpriteInstance>::GetSetting(this, "sprite"),
|
||||
GUI<int>::GetSetting(this, "cell_id"),
|
||||
GetBufferedZ(),
|
||||
m_CachedActualSize);
|
||||
}
|
||||
|
@ -287,9 +287,7 @@ void CInput::ManuallyMutableHandleKeyDownEvent(const SDL_Keycode keyCode, CStrW&
|
||||
{
|
||||
// 'Return' should do a Press event for single liners (e.g. submitting forms)
|
||||
// otherwise a '\n' character will be added.
|
||||
bool multiline;
|
||||
GUI<bool>::GetSetting(this, "multiline", multiline);
|
||||
if (!multiline)
|
||||
if (!GUI<bool>::GetSetting(this, "multiline"))
|
||||
{
|
||||
SendEvent(GUIM_PRESSED, "press");
|
||||
break;
|
||||
@ -306,8 +304,7 @@ void CInput::ManuallyMutableHandleKeyDownEvent(const SDL_Keycode keyCode, CStrW&
|
||||
return;
|
||||
|
||||
// check max length
|
||||
int max_length;
|
||||
GUI<int>::GetSetting(this, "max_length", max_length);
|
||||
const int max_length = GUI<int>::GetSetting(this, "max_length");
|
||||
if (max_length != 0 && static_cast<int>(pCaption.length()) >= max_length)
|
||||
break;
|
||||
|
||||
@ -839,12 +836,9 @@ void CInput::HandleMessage(SGUIMessage& Message)
|
||||
{
|
||||
case GUIM_SETTINGS_UPDATED:
|
||||
{
|
||||
bool scrollbar;
|
||||
GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
|
||||
|
||||
// Update scroll-bar
|
||||
// TODO Gee: (2004-09-01) Is this really updated each time it should?
|
||||
if (scrollbar &&
|
||||
if (GUI<bool>::GetSetting(this, "scrollbar") &&
|
||||
(Message.value == CStr("size") ||
|
||||
Message.value == CStr("z") ||
|
||||
Message.value == CStr("absolute")))
|
||||
@ -858,15 +852,12 @@ void CInput::HandleMessage(SGUIMessage& Message)
|
||||
// Update scrollbar
|
||||
if (Message.value == CStr("scrollbar_style"))
|
||||
{
|
||||
CStr scrollbar_style;
|
||||
GUI<CStr>::GetSetting(this, Message.value, scrollbar_style);
|
||||
|
||||
GetScrollBar(0).SetScrollBarStyle(scrollbar_style);
|
||||
GetScrollBar(0).SetScrollBarStyle(GUI<CStr>::GetSetting(this, Message.value));
|
||||
}
|
||||
|
||||
if (Message.value == CStr("buffer_position"))
|
||||
{
|
||||
GUI<int>::GetSetting(this, Message.value, m_iBufferPos);
|
||||
m_iBufferPos = GUI<int>::GetSetting(this, Message.value);
|
||||
m_iBufferPos_Tail = -1; // position change resets selection
|
||||
}
|
||||
|
||||
@ -883,10 +874,7 @@ void CInput::HandleMessage(SGUIMessage& Message)
|
||||
|
||||
if (Message.value == CStr("multiline"))
|
||||
{
|
||||
bool multiline;
|
||||
GUI<bool>::GetSetting(this, "multiline", multiline);
|
||||
|
||||
if (!multiline)
|
||||
if (!GUI<bool>::GetSetting(this, "multiline"))
|
||||
GetScrollBar(0).SetLength(0.f);
|
||||
else
|
||||
GetScrollBar(0).SetLength(m_CachedActualSize.bottom - m_CachedActualSize.top);
|
||||
@ -897,18 +885,16 @@ void CInput::HandleMessage(SGUIMessage& Message)
|
||||
UpdateAutoScroll();
|
||||
|
||||
if (Message.value == CStr("readonly"))
|
||||
GUI<bool>::GetSetting(this, "readonly", m_Readonly);
|
||||
m_Readonly = GUI<bool>::GetSetting(this, "readonly");
|
||||
|
||||
break;
|
||||
}
|
||||
case GUIM_MOUSE_PRESS_LEFT:
|
||||
{
|
||||
bool scrollbar, multiline;
|
||||
GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
|
||||
GUI<bool>::GetSetting(this, "multiline", multiline);
|
||||
|
||||
// Check if we're selecting the scrollbar
|
||||
if (GetScrollBar(0).GetStyle() && multiline)
|
||||
if (GUI<bool>::GetSetting(this, "scrollbar") &&
|
||||
GUI<bool>::GetSetting(this, "multiline") &&
|
||||
GetScrollBar(0).GetStyle())
|
||||
{
|
||||
if (m_pGUI.GetMousePos().x > m_CachedActualSize.right - GetScrollBar(0).GetStyle()->m_Width)
|
||||
break;
|
||||
@ -1073,15 +1059,12 @@ void CInput::HandleMessage(SGUIMessage& Message)
|
||||
GetScrollBar(0).SetY(m_CachedActualSize.top);
|
||||
GetScrollBar(0).SetZ(GetBufferedZ());
|
||||
GetScrollBar(0).SetLength(m_CachedActualSize.bottom - m_CachedActualSize.top);
|
||||
|
||||
CStr scrollbar_style;
|
||||
GUI<CStr>::GetSetting(this, "scrollbar_style", scrollbar_style);
|
||||
GetScrollBar(0).SetScrollBarStyle(scrollbar_style);
|
||||
GetScrollBar(0).SetScrollBarStyle(GUI<CStr>::GetSetting(this, "scrollbar_style"));
|
||||
|
||||
UpdateText();
|
||||
UpdateAutoScroll();
|
||||
|
||||
GUI<bool>::GetSetting(this, "readonly", m_Readonly);
|
||||
m_Readonly = GUI<bool>::GetSetting(this, "readonly");
|
||||
break;
|
||||
}
|
||||
case GUIM_GOT_FOCUS:
|
||||
@ -1133,9 +1116,7 @@ void CInput::UpdateCachedSize()
|
||||
|
||||
IGUIObject::UpdateCachedSize();
|
||||
|
||||
bool scrollbar;
|
||||
GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
|
||||
if (scrollbar)
|
||||
if (GUI<bool>::GetSetting(this, "scrollbar"))
|
||||
{
|
||||
GetScrollBar(0).SetX(m_CachedActualSize.right);
|
||||
GetScrollBar(0).SetY(m_CachedActualSize.top);
|
||||
@ -1163,30 +1144,25 @@ void CInput::Draw()
|
||||
m_CursorVisState = true;
|
||||
|
||||
// First call draw on ScrollBarOwner
|
||||
bool scrollbar;
|
||||
float buffer_zone;
|
||||
bool multiline;
|
||||
bool mask;
|
||||
GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
|
||||
GUI<float>::GetSetting(this, "buffer_zone", buffer_zone);
|
||||
GUI<bool>::GetSetting(this, "multiline", multiline);
|
||||
GUI<bool>::GetSetting(this, "mask", mask);
|
||||
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");
|
||||
|
||||
if (scrollbar && multiline)
|
||||
IGUIScrollBarOwner::Draw();
|
||||
|
||||
CStrW font_name_w;
|
||||
GUI<CStrW>::GetSetting(this, "font", font_name_w);
|
||||
const CGUIColor& color = GUI<CGUIColor>::GetSetting(this, "textcolor");
|
||||
const CGUIColor& color_selected = GUI<CGUIColor>::GetSetting(this, "textcolor_selected");
|
||||
CStrIntern font_name(font_name_w.ToUTF8());
|
||||
|
||||
CStrIntern font_name(GUI<CStrW>::GetSetting(this, "font").ToUTF8());
|
||||
|
||||
const CStrW& pCaption = GUI<CStrW>::GetSetting(this, "caption");
|
||||
wchar_t mask_char = L'*';
|
||||
if (mask)
|
||||
{
|
||||
CStrW maskStr;
|
||||
GUI<CStrW>::GetSetting(this, "mask_char", maskStr);
|
||||
const CStrW& maskStr = GUI<CStrW>::GetSetting(this, "mask_char");
|
||||
|
||||
if (maskStr.length() > 0)
|
||||
mask_char = maskStr[0];
|
||||
}
|
||||
@ -1194,8 +1170,7 @@ void CInput::Draw()
|
||||
CGUISpriteInstance& sprite = GUI<CGUISpriteInstance>::GetSetting(this, "sprite");
|
||||
CGUISpriteInstance& sprite_selectarea = GUI<CGUISpriteInstance>::GetSetting(this, "sprite_selectarea");
|
||||
|
||||
int cell_id;
|
||||
GUI<int>::GetSetting(this, "cell_id", cell_id);
|
||||
const int cell_id = GUI<int>::GetSetting(this, "cell_id");
|
||||
|
||||
m_pGUI.DrawSprite(sprite, cell_id, bz, m_CachedActualSize);
|
||||
|
||||
@ -1515,23 +1490,16 @@ void CInput::Draw()
|
||||
|
||||
void CInput::UpdateText(int from, int to_before, int to_after)
|
||||
{
|
||||
CStrW caption;
|
||||
CStrW font_name_w;
|
||||
float buffer_zone;
|
||||
bool multiline;
|
||||
bool mask;
|
||||
GUI<CStrW>::GetSetting(this, "font", font_name_w);
|
||||
GUI<CStrW>::GetSetting(this, "caption", caption);
|
||||
GUI<float>::GetSetting(this, "buffer_zone", buffer_zone);
|
||||
GUI<bool>::GetSetting(this, "multiline", multiline);
|
||||
GUI<bool>::GetSetting(this, "mask", mask);
|
||||
CStrIntern font_name(font_name_w.ToUTF8());
|
||||
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());
|
||||
|
||||
wchar_t mask_char = L'*';
|
||||
if (mask)
|
||||
{
|
||||
CStrW maskStr;
|
||||
GUI<CStrW>::GetSetting(this, "mask_char", maskStr);
|
||||
const CStrW& maskStr = GUI<CStrW>::GetSetting(this, "mask_char");
|
||||
if (maskStr.length() > 0)
|
||||
mask_char = maskStr[0];
|
||||
}
|
||||
@ -1868,9 +1836,7 @@ void CInput::UpdateText(int from, int to_before, int to_after)
|
||||
// add the final row (even if empty)
|
||||
m_CharacterPositions.insert(current_line, row);
|
||||
|
||||
bool scrollbar;
|
||||
GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
|
||||
if (scrollbar)
|
||||
if (GUI<bool>::GetSetting(this, "scrollbar"))
|
||||
{
|
||||
GetScrollBar(0).SetScrollRange(m_CharacterPositions.size() * font.GetLineSpacing() + buffer_zone*2.f);
|
||||
GetScrollBar(0).SetScrollSpace(m_CachedActualSize.GetHeight());
|
||||
@ -1882,33 +1848,25 @@ int CInput::GetMouseHoveringTextPosition() const
|
||||
if (m_CharacterPositions.empty())
|
||||
return 0;
|
||||
|
||||
const float buffer_zone = GUI<float>::GetSetting(this, "buffer_zone");
|
||||
const bool multiline = GUI<bool>::GetSetting(this, "multiline");
|
||||
|
||||
// Return position
|
||||
int retPosition;
|
||||
|
||||
float buffer_zone;
|
||||
bool multiline;
|
||||
GUI<float>::GetSetting(this, "buffer_zone", buffer_zone);
|
||||
GUI<bool>::GetSetting(this, "multiline", multiline);
|
||||
|
||||
std::list<SRow>::const_iterator current = m_CharacterPositions.begin();
|
||||
|
||||
CPos mouse = m_pGUI.GetMousePos();
|
||||
|
||||
if (multiline)
|
||||
{
|
||||
CStrW font_name_w;
|
||||
bool scrollbar;
|
||||
GUI<CStrW>::GetSetting(this, "font", font_name_w);
|
||||
GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
|
||||
CStrIntern font_name(font_name_w.ToUTF8());
|
||||
|
||||
float scroll = 0.f;
|
||||
if (scrollbar)
|
||||
if (GUI<bool>::GetSetting(this, "scrollbar"))
|
||||
scroll = GetScrollBarPos(0);
|
||||
|
||||
// Now get the height of the font.
|
||||
// TODO: Get the real font
|
||||
CFontMetrics font(font_name);
|
||||
CFontMetrics font(CStrIntern(GUI<CStrW>::GetSetting(this, "font").ToUTF8()));
|
||||
float spacing = (float)font.GetLineSpacing();
|
||||
|
||||
// Change mouse position relative to text.
|
||||
@ -2021,12 +1979,9 @@ bool CInput::SelectingText() const
|
||||
|
||||
float CInput::GetTextAreaWidth()
|
||||
{
|
||||
bool scrollbar;
|
||||
float buffer_zone;
|
||||
GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
|
||||
GUI<float>::GetSetting(this, "buffer_zone", buffer_zone);
|
||||
const float buffer_zone = GUI<float>::GetSetting(this, "buffer_zone");
|
||||
|
||||
if (scrollbar && GetScrollBar(0).GetStyle())
|
||||
if (GUI<bool>::GetSetting(this, "scrollbar") && GetScrollBar(0).GetStyle())
|
||||
return m_CachedActualSize.GetWidth() - buffer_zone*2.f - GetScrollBar(0).GetStyle()->m_Width;
|
||||
else
|
||||
return m_CachedActualSize.GetWidth() - buffer_zone*2.f;
|
||||
@ -2034,29 +1989,19 @@ float CInput::GetTextAreaWidth()
|
||||
|
||||
void CInput::UpdateAutoScroll()
|
||||
{
|
||||
float buffer_zone;
|
||||
bool multiline;
|
||||
GUI<float>::GetSetting(this, "buffer_zone", buffer_zone);
|
||||
GUI<bool>::GetSetting(this, "multiline", multiline);
|
||||
const float buffer_zone = GUI<float>::GetSetting(this, "buffer_zone");
|
||||
|
||||
// Autoscrolling up and down
|
||||
if (multiline)
|
||||
if (GUI<bool>::GetSetting(this, "multiline"))
|
||||
{
|
||||
CStrW font_name_w;
|
||||
bool scrollbar;
|
||||
GUI<CStrW>::GetSetting(this, "font", font_name_w);
|
||||
GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
|
||||
CStrIntern font_name(font_name_w.ToUTF8());
|
||||
|
||||
float scroll = 0.f;
|
||||
if (!scrollbar)
|
||||
if (!GUI<bool>::GetSetting(this, "scrollbar"))
|
||||
return;
|
||||
|
||||
scroll = GetScrollBar(0).GetPos();
|
||||
const float scroll = GetScrollBar(0).GetPos();
|
||||
|
||||
// Now get the height of the font.
|
||||
// TODO: Get the real font
|
||||
CFontMetrics font(font_name);
|
||||
CFontMetrics font(CStrIntern(GUI<CStrW>::GetSetting(this, "font").ToUTF8()));
|
||||
float spacing = (float)font.GetLineSpacing();
|
||||
//float height = font.GetHeight();
|
||||
|
||||
|
@ -83,16 +83,14 @@ void CList::SetupText()
|
||||
|
||||
const CStrW& font = GUI<CStrW>::GetSetting(this, "font");
|
||||
|
||||
bool scrollbar;
|
||||
GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
|
||||
const bool scrollbar = GUI<bool>::GetSetting(this, "scrollbar");
|
||||
|
||||
float width = GetListRect().GetWidth();
|
||||
// remove scrollbar if applicable
|
||||
if (scrollbar && GetScrollBar(0).GetStyle())
|
||||
width -= GetScrollBar(0).GetStyle()->m_Width;
|
||||
|
||||
float buffer_zone = 0.f;
|
||||
GUI<float>::GetSetting(this, "buffer_zone", buffer_zone);
|
||||
const float buffer_zone = GUI<float>::GetSetting(this, "buffer_zone");
|
||||
|
||||
// Generate texts
|
||||
float buffered_y = 0.f;
|
||||
@ -148,11 +146,7 @@ void CList::HandleMessage(SGUIMessage& Message)
|
||||
{
|
||||
// TODO: Check range
|
||||
|
||||
bool auto_scroll;
|
||||
|
||||
GUI<bool>::GetSetting(this, "auto_scroll", auto_scroll);
|
||||
|
||||
if (auto_scroll)
|
||||
if (GUI<bool>::GetSetting(this, "auto_scroll"))
|
||||
UpdateAutoScroll();
|
||||
|
||||
// TODO only works if lower-case, shouldn't it be made case sensitive instead?
|
||||
@ -165,11 +159,7 @@ void CList::HandleMessage(SGUIMessage& Message)
|
||||
// Update scrollbar
|
||||
if (Message.value == "scrollbar_style")
|
||||
{
|
||||
CStr scrollbar_style;
|
||||
GUI<CStr>::GetSetting(this, Message.value, scrollbar_style);
|
||||
|
||||
GetScrollBar(0).SetScrollBarStyle(scrollbar_style);
|
||||
|
||||
GetScrollBar(0).SetScrollBarStyle(GUI<CStr>::GetSetting(this, Message.value));
|
||||
SetupText();
|
||||
}
|
||||
|
||||
@ -177,9 +167,7 @@ void CList::HandleMessage(SGUIMessage& Message)
|
||||
|
||||
case GUIM_MOUSE_PRESS_LEFT:
|
||||
{
|
||||
bool enabled;
|
||||
GUI<bool>::GetSetting(this, "enabled", enabled);
|
||||
if (!enabled)
|
||||
if (!GUI<bool>::GetSetting(this, "enabled"))
|
||||
{
|
||||
PlaySound("sound_disabled");
|
||||
break;
|
||||
@ -204,9 +192,7 @@ void CList::HandleMessage(SGUIMessage& Message)
|
||||
|
||||
case GUIM_MOUSE_LEAVE:
|
||||
{
|
||||
int hoveredSetting = -1;
|
||||
GUI<int>::GetSetting(this, "hovered", hoveredSetting);
|
||||
if (hoveredSetting == -1)
|
||||
if (GUI<int>::GetSetting(this, "hovered") == -1)
|
||||
break;
|
||||
|
||||
GUI<int>::SetSetting(this, "hovered", -1);
|
||||
@ -216,11 +202,8 @@ void CList::HandleMessage(SGUIMessage& Message)
|
||||
|
||||
case GUIM_MOUSE_OVER:
|
||||
{
|
||||
int hoveredSetting = -1;
|
||||
GUI<int>::GetSetting(this, "hovered", hoveredSetting);
|
||||
|
||||
int hovered = GetHoveredItem();
|
||||
if (hovered == hoveredSetting)
|
||||
if (hovered == GUI<int>::GetSetting(this, "hovered"))
|
||||
break;
|
||||
|
||||
GUI<int>::SetSetting(this, "hovered", hovered);
|
||||
@ -230,9 +213,7 @@ void CList::HandleMessage(SGUIMessage& Message)
|
||||
|
||||
case GUIM_LOAD:
|
||||
{
|
||||
CStr scrollbar_style;
|
||||
GUI<CStr>::GetSetting(this, "scrollbar_style", scrollbar_style);
|
||||
GetScrollBar(0).SetScrollBarStyle(scrollbar_style);
|
||||
GetScrollBar(0).SetScrollBarStyle(GUI<CStr>::GetSetting(this, "scrollbar_style"));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -297,10 +278,7 @@ InReaction CList::ManuallyHandleEvent(const SDL_Event_* ev)
|
||||
|
||||
void CList::Draw()
|
||||
{
|
||||
int selected;
|
||||
GUI<int>::GetSetting(this, "selected", selected);
|
||||
|
||||
DrawList(selected, "sprite", "sprite_selectarea", "textcolor");
|
||||
DrawList(GUI<int>::GetSetting(this, "selected"), "sprite", "sprite_selectarea", "textcolor");
|
||||
}
|
||||
|
||||
void CList::DrawList(const int& selected, const CStr& _sprite, const CStr& _sprite_selected, const CStr& _textcolor)
|
||||
@ -308,8 +286,7 @@ void CList::DrawList(const int& selected, const CStr& _sprite, const CStr& _spri
|
||||
float bz = GetBufferedZ();
|
||||
|
||||
// First call draw on ScrollBarOwner
|
||||
bool scrollbar;
|
||||
GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
|
||||
const bool scrollbar = GUI<bool>::GetSetting(this, "scrollbar");
|
||||
|
||||
if (scrollbar)
|
||||
IGUIScrollBarOwner::Draw();
|
||||
|
@ -49,17 +49,14 @@ void COList::SetupText()
|
||||
m_GeneratedTexts.clear();
|
||||
|
||||
const CStrW& font = GUI<CStrW>::GetSetting(this, "font");
|
||||
|
||||
bool scrollbar;
|
||||
GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
|
||||
const bool scrollbar = GUI<bool>::GetSetting(this, "scrollbar");
|
||||
|
||||
m_TotalAvailableColumnWidth = GetListRect().GetWidth();
|
||||
// remove scrollbar if applicable
|
||||
if (scrollbar && GetScrollBar(0).GetStyle())
|
||||
m_TotalAvailableColumnWidth -= GetScrollBar(0).GetStyle()->m_Width;
|
||||
|
||||
float buffer_zone = 0.f;
|
||||
GUI<float>::GetSetting(this, "buffer_zone", buffer_zone);
|
||||
const float buffer_zone = GUI<float>::GetSetting(this, "buffer_zone");
|
||||
|
||||
m_HeadingHeight = SORT_SPRITE_DIM; // At least the size of the sorting sprite
|
||||
|
||||
@ -134,26 +131,21 @@ void COList::HandleMessage(SGUIMessage& Message)
|
||||
// If somebody clicks on the column heading
|
||||
case GUIM_MOUSE_PRESS_LEFT:
|
||||
{
|
||||
bool sortable;
|
||||
GUI<bool>::GetSetting(this, "sortable", sortable);
|
||||
if (!sortable)
|
||||
if (!GUI<bool>::GetSetting(this, "sortable"))
|
||||
return;
|
||||
|
||||
const CPos& mouse = m_pGUI.GetMousePos();
|
||||
if (!m_CachedActualSize.PointInside(mouse))
|
||||
return;
|
||||
|
||||
CStr selectedColumn;
|
||||
GUI<CStr>::GetSetting(this, "selected_column", selectedColumn);
|
||||
int selectedColumnOrder;
|
||||
GUI<int>::GetSetting(this, "selected_column_order", selectedColumnOrder);
|
||||
// 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");
|
||||
|
||||
float xpos = 0;
|
||||
for (const COListColumn& column : m_Columns)
|
||||
{
|
||||
bool hidden = false;
|
||||
GUI<bool>::GetSetting(this, "hidden_" + column.m_Id, hidden);
|
||||
if (hidden)
|
||||
if (GUI<bool>::GetSetting(this, "hidden_" + column.m_Id))
|
||||
continue;
|
||||
|
||||
float width = column.m_Width;
|
||||
@ -172,10 +164,11 @@ void COList::HandleMessage(SGUIMessage& Message)
|
||||
}
|
||||
else
|
||||
selectedColumnOrder = -selectedColumnOrder;
|
||||
GUI<CStr>::SetSetting(this, "selected_column", column.m_Id);
|
||||
GUI<int>::SetSetting(this, "selected_column_order", selectedColumnOrder);
|
||||
ScriptEvent("selectioncolumnchange");
|
||||
|
||||
GUI<CStr>::SetSetting(this, "selected_column", selectedColumn);
|
||||
GUI<int>::SetSetting(this, "selected_column_order", selectedColumnOrder);
|
||||
|
||||
ScriptEvent("selectioncolumnchange");
|
||||
PlaySound("sound_selected");
|
||||
return;
|
||||
}
|
||||
@ -292,10 +285,8 @@ bool COList::HandleAdditionalChildren(const XMBElement& child, CXeromyces* pFile
|
||||
|
||||
void COList::DrawList(const int& selected, const CStr& _sprite, const CStr& _sprite_selected, const CStr& _textcolor)
|
||||
{
|
||||
float bz = GetBufferedZ();
|
||||
|
||||
bool scrollbar;
|
||||
GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
|
||||
const float bz = GetBufferedZ();
|
||||
const bool scrollbar = GUI<bool>::GetSetting(this, "scrollbar");
|
||||
|
||||
if (scrollbar)
|
||||
IGUIScrollBarOwner::Draw();
|
||||
@ -305,8 +296,7 @@ void COList::DrawList(const int& selected, const CStr& _sprite, const CStr& _spr
|
||||
CGUISpriteInstance& sprite = GUI<CGUISpriteInstance>::GetSetting(this, _sprite);
|
||||
CGUISpriteInstance& sprite_selectarea = GUI<CGUISpriteInstance>::GetSetting(this, _sprite_selected);
|
||||
|
||||
int cell_id;
|
||||
GUI<int>::GetSetting(this, "cell_id", cell_id);
|
||||
const int cell_id = GUI<int>::GetSetting(this, "cell_id");
|
||||
|
||||
m_pGUI.DrawSprite(sprite, cell_id, bz, rect);
|
||||
|
||||
@ -355,23 +345,15 @@ void COList::DrawList(const int& selected, const CStr& _sprite, const CStr& _spr
|
||||
m_pGUI.DrawSprite(sprite_heading, cell_id, bz, rect_head);
|
||||
|
||||
// Draw column headers
|
||||
bool sortable;
|
||||
GUI<bool>::GetSetting(this, "sortable", sortable);
|
||||
|
||||
CStr selectedColumn;
|
||||
GUI<CStr>::GetSetting(this, "selected_column", selectedColumn);
|
||||
|
||||
int selectedColumnOrder;
|
||||
GUI<int>::GetSetting(this, "selected_column_order", selectedColumnOrder);
|
||||
|
||||
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);
|
||||
|
||||
float xpos = 0;
|
||||
for (size_t col = 0; col < m_Columns.size(); ++col)
|
||||
{
|
||||
bool hidden = false;
|
||||
GUI<bool>::GetSetting(this, "hidden_" + m_Columns[col].m_Id, hidden);
|
||||
if (hidden)
|
||||
if (GUI<bool>::GetSetting(this, "hidden_" + m_Columns[col].m_Id))
|
||||
continue;
|
||||
|
||||
// Check if it's a decimal value, and if so, assume relative positioning.
|
||||
@ -436,9 +418,7 @@ void COList::DrawList(const int& selected, const CStr& _sprite, const CStr& _spr
|
||||
xpos = 0;
|
||||
for (size_t col = 0; col < objectsCount; ++col)
|
||||
{
|
||||
bool hidden = false;
|
||||
GUI<bool>::GetSetting(this, "hidden_" + m_Columns[col].m_Id, hidden);
|
||||
if (hidden)
|
||||
if (GUI<bool>::GetSetting(this, "hidden_" + m_Columns[col].m_Id))
|
||||
continue;
|
||||
|
||||
// Determine text position and width
|
||||
|
@ -48,12 +48,10 @@ void CProgressBar::HandleMessage(SGUIMessage& Message)
|
||||
// TODO Gee: (2004-09-01) Is this really updated each time it should?
|
||||
if (Message.value == CStr("caption"))
|
||||
{
|
||||
float value;
|
||||
GUI<float>::GetSetting(this, "caption", value);
|
||||
const float value = GUI<float>::GetSetting(this, "caption");
|
||||
if (value > 100.f)
|
||||
GUI<float>::SetSetting(this, "caption", 100.f);
|
||||
else
|
||||
if (value < 0.f)
|
||||
else if (value < 0.f)
|
||||
GUI<float>::SetSetting(this, "caption", 0.f);
|
||||
}
|
||||
break;
|
||||
@ -70,8 +68,7 @@ void CProgressBar::Draw()
|
||||
float bz = GetBufferedZ();
|
||||
|
||||
int cell_id = 0;
|
||||
float value = 0;
|
||||
GUI<float>::GetSetting(this, "caption", value);
|
||||
const float value = GUI<float>::GetSetting(this, "caption");
|
||||
|
||||
m_pGUI.DrawSprite(sprite_background, cell_id, bz, m_CachedActualSize);
|
||||
|
||||
|
@ -32,10 +32,11 @@ CSlider::CSlider(CGUI& pGUI)
|
||||
AddSetting<CGUISpriteInstance>("sprite_bar");
|
||||
AddSetting<float>("button_width");
|
||||
|
||||
GUI<float>::GetSetting(this, "value", m_Value);
|
||||
GUI<float>::GetSetting(this, "min_value", m_MinValue);
|
||||
GUI<float>::GetSetting(this, "max_value", m_MaxValue);
|
||||
GUI<float>::GetSetting(this, "button_width", m_ButtonSide);
|
||||
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 = Clamp(m_Value, m_MinValue, m_MaxValue);
|
||||
}
|
||||
|
||||
@ -60,10 +61,11 @@ void CSlider::HandleMessage(SGUIMessage& Message)
|
||||
{
|
||||
case GUIM_SETTINGS_UPDATED:
|
||||
{
|
||||
GUI<float>::GetSetting(this, "value", m_Value);
|
||||
GUI<float>::GetSetting(this, "min_value", m_MinValue);
|
||||
GUI<float>::GetSetting(this, "max_value", m_MaxValue);
|
||||
GUI<float>::GetSetting(this, "button_width", m_ButtonSide);
|
||||
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 = Clamp(m_Value, m_MinValue, m_MaxValue);
|
||||
break;
|
||||
}
|
||||
@ -115,9 +117,7 @@ void CSlider::Draw()
|
||||
{
|
||||
CGUISpriteInstance& sprite = GUI<CGUISpriteInstance>::GetSetting(this, "sprite_bar");
|
||||
CGUISpriteInstance& sprite_button = GUI<CGUISpriteInstance>::GetSetting(this, "sprite");
|
||||
|
||||
int cell_id;
|
||||
GUI<int>::GetSetting(this, "cell_id", cell_id);
|
||||
const int cell_id = GUI<int>::GetSetting(this, "cell_id");
|
||||
|
||||
CRect slider_line(m_CachedActualSize);
|
||||
slider_line.left += m_ButtonSide / 2.0f;
|
||||
|
@ -69,8 +69,7 @@ void CText::SetupText()
|
||||
if (m_GeneratedTexts.empty())
|
||||
return;
|
||||
|
||||
bool scrollbar;
|
||||
GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
|
||||
const bool scrollbar = GUI<bool>::GetSetting(this, "scrollbar");
|
||||
|
||||
float width = m_CachedActualSize.GetWidth();
|
||||
// remove scrollbar if applicable
|
||||
@ -89,9 +88,8 @@ void CText::SetupText()
|
||||
// Setup scrollbar
|
||||
if (scrollbar)
|
||||
{
|
||||
bool scroll_top = false, scroll_bottom = false;
|
||||
GUI<bool>::GetSetting(this, "scroll_bottom", scroll_bottom);
|
||||
GUI<bool>::GetSetting(this, "scroll_top", scroll_top);
|
||||
const bool scroll_bottom = GUI<bool>::GetSetting(this, "scroll_bottom");
|
||||
const bool scroll_top = GUI<bool>::GetSetting(this, "scroll_top");
|
||||
|
||||
// If we are currently scrolled to the bottom of the text,
|
||||
// then add more lines of text, update the scrollbar so we
|
||||
@ -130,11 +128,7 @@ void CText::HandleMessage(SGUIMessage& Message)
|
||||
// Update scrollbar
|
||||
if (Message.value == "scrollbar_style")
|
||||
{
|
||||
CStr scrollbar_style;
|
||||
GUI<CStr>::GetSetting(this, Message.value, scrollbar_style);
|
||||
|
||||
GetScrollBar(0).SetScrollBarStyle(scrollbar_style);
|
||||
|
||||
GetScrollBar(0).SetScrollBarStyle(GUI<CStr>::GetSetting(this, Message.value));
|
||||
SetupText();
|
||||
}
|
||||
|
||||
@ -164,10 +158,7 @@ void CText::HandleMessage(SGUIMessage& Message)
|
||||
GetScrollBar(0).SetY(m_CachedActualSize.top);
|
||||
GetScrollBar(0).SetZ(GetBufferedZ());
|
||||
GetScrollBar(0).SetLength(m_CachedActualSize.bottom - m_CachedActualSize.top);
|
||||
|
||||
CStr scrollbar_style;
|
||||
GUI<CStr>::GetSetting(this, "scrollbar_style", scrollbar_style);
|
||||
GetScrollBar(0).SetScrollBarStyle(scrollbar_style);
|
||||
GetScrollBar(0).SetScrollBarStyle(GUI<CStr>::GetSetting(this, "scrollbar_style"));
|
||||
break;
|
||||
}
|
||||
|
||||
@ -182,20 +173,14 @@ void CText::Draw()
|
||||
{
|
||||
float bz = GetBufferedZ();
|
||||
|
||||
// First call draw on ScrollBarOwner
|
||||
bool scrollbar;
|
||||
GUI<bool>::GetSetting(this, "scrollbar", scrollbar);
|
||||
const bool scrollbar = GUI<bool>::GetSetting(this, "scrollbar");
|
||||
|
||||
if (scrollbar)
|
||||
// Draw scrollbar
|
||||
IGUIScrollBarOwner::Draw();
|
||||
|
||||
CGUISpriteInstance& sprite = GUI<CGUISpriteInstance>::GetSetting(this, "sprite");
|
||||
|
||||
int cell_id;
|
||||
bool clip;
|
||||
GUI<int>::GetSetting(this, "cell_id", cell_id);
|
||||
GUI<bool>::GetSetting(this, "clip", clip);
|
||||
const int cell_id = GUI<int>::GetSetting(this, "cell_id");
|
||||
const bool clip = GUI<bool>::GetSetting(this, "clip");
|
||||
|
||||
m_pGUI.DrawSprite(sprite, cell_id, bz, m_CachedActualSize);
|
||||
|
||||
@ -222,9 +207,7 @@ void CText::Draw()
|
||||
}
|
||||
}
|
||||
|
||||
bool enabled;
|
||||
GUI<bool>::GetSetting(this, "enabled", enabled);
|
||||
|
||||
const bool enabled = GUI<bool>::GetSetting(this, "enabled");
|
||||
const CGUIColor& color = GUI<CGUIColor>::GetSetting(this, enabled ? "textcolor" : "textcolor_disabled");
|
||||
|
||||
if (scrollbar)
|
||||
|
@ -65,31 +65,20 @@ void CTooltip::SetupText()
|
||||
{
|
||||
ENSURE(m_GeneratedTexts.size() == 1);
|
||||
|
||||
float buffer_zone = 0.f;
|
||||
GUI<float>::GetSetting(this, "buffer_zone", buffer_zone);
|
||||
|
||||
const CGUIString& caption = GUI<CGUIString>::GetSetting(this, "caption");
|
||||
const CStrW& font = GUI<CStrW>::GetSetting(this, "font");
|
||||
|
||||
float max_width = 0.f;
|
||||
GUI<float>::GetSetting(this, "maxwidth", max_width);
|
||||
const float max_width = GUI<float>::GetSetting(this, "maxwidth");
|
||||
const float buffer_zone = GUI<float>::GetSetting(this, "buffer_zone");
|
||||
|
||||
m_GeneratedTexts[0] = CGUIText(m_pGUI, caption, font, max_width, buffer_zone, this);
|
||||
|
||||
// Position the tooltip relative to the mouse:
|
||||
|
||||
CPos mousepos, offset;
|
||||
EVAlign anchor;
|
||||
bool independent;
|
||||
const CPos& mousepos = GUI<bool>::GetSetting(this, "independent") ?
|
||||
m_pGUI.GetMousePos() :
|
||||
GUI<CPos>::GetSetting(this, "_mousepos");
|
||||
|
||||
GUI<bool>::GetSetting(this, "independent", independent);
|
||||
if (independent)
|
||||
mousepos = m_pGUI.GetMousePos();
|
||||
else
|
||||
GUI<CPos>::GetSetting(this, "_mousepos", mousepos);
|
||||
|
||||
GUI<CPos>::GetSetting(this, "offset", offset);
|
||||
GUI<EVAlign>::GetSetting(this, "anchor", anchor);
|
||||
const CPos& offset = GUI<CPos>::GetSetting(this, "offset");
|
||||
|
||||
float textwidth = m_GeneratedTexts[0].GetSize().cx;
|
||||
float textheight = m_GeneratedTexts[0].GetSize().cy;
|
||||
@ -97,7 +86,8 @@ void CTooltip::SetupText()
|
||||
CClientArea size;
|
||||
size.pixel.left = mousepos.x + offset.x;
|
||||
size.pixel.right = size.pixel.left + textwidth;
|
||||
switch (anchor)
|
||||
|
||||
switch (GUI<EVAlign>::GetSetting(this, "anchor"))
|
||||
{
|
||||
case EVAlign_Top:
|
||||
size.pixel.top = mousepos.y + offset.y;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (C) 2016 Wildfire Games.
|
||||
/* Copyright (C) 2019 Wildfire Games.
|
||||
* This file is part of 0 A.D.
|
||||
*
|
||||
* 0 A.D. is free software: you can redistribute it and/or modify
|
||||
@ -85,30 +85,29 @@ const double CooldownTime = 0.25; // TODO: Don't hard-code this value
|
||||
|
||||
bool GUITooltip::GetTooltip(IGUIObject* obj, CStr& style)
|
||||
{
|
||||
CStrW text;
|
||||
|
||||
if (obj && obj->SettingExists("_icon_tooltip_style") && obj->MouseOverIcon() &&
|
||||
GUI<CStr>::GetSetting(obj, "_icon_tooltip_style", style) == PSRETURN_OK &&
|
||||
GUI<CStrW>::GetSetting(obj, "_icon_tooltip", text) == PSRETURN_OK && !text.empty())
|
||||
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())
|
||||
{
|
||||
if (style.empty())
|
||||
style = "default";
|
||||
|
||||
m_IsIconTooltip = true;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (obj && obj->SettingExists("tooltip_style") &&
|
||||
GUI<CStr>::GetSetting(obj, "tooltip_style", style) == PSRETURN_OK &&
|
||||
GUI<CStrW>::GetSetting(obj, "tooltip", text) == PSRETURN_OK &&
|
||||
!text.empty())
|
||||
if (obj && obj->SettingExists("tooltip_style"))
|
||||
{
|
||||
style = GUI<CStr>::GetSetting(obj, "tooltip_style");
|
||||
if (!GUI<CStrW>::GetSetting(obj, "tooltip").empty())
|
||||
{
|
||||
if (style.empty())
|
||||
style = "default";
|
||||
|
||||
m_IsIconTooltip = false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@ -129,9 +128,8 @@ void GUITooltip::ShowTooltip(IGUIObject* obj, const CPos& pos, const CStr& style
|
||||
|
||||
IGUIObject* usedobj = tooltipobj; // object actually used to display the tooltip in
|
||||
|
||||
CStr usedObjectName;
|
||||
if (GUI<CStr>::GetSetting(tooltipobj, "use_object", usedObjectName) == PSRETURN_OK &&
|
||||
!usedObjectName.empty())
|
||||
const CStr& usedObjectName = GUI<CStr>::GetSetting(tooltipobj, "use_object");
|
||||
if (!usedObjectName.empty())
|
||||
{
|
||||
usedobj = pGUI.FindObjectByName(usedObjectName);
|
||||
if (!usedobj)
|
||||
@ -145,14 +143,7 @@ void GUITooltip::ShowTooltip(IGUIObject* obj, const CPos& pos, const CStr& style
|
||||
|
||||
GUI<bool>::SetSetting(usedobj, "hidden", false);
|
||||
|
||||
CStrW text;
|
||||
if (m_IsIconTooltip)
|
||||
{
|
||||
if (GUI<CStrW>::GetSetting(obj, "_icon_tooltip", text) != PSRETURN_OK)
|
||||
debug_warn(L"Failed to retrieve icon tooltip text");
|
||||
}
|
||||
else if (GUI<CStrW>::GetSetting(obj, "tooltip", text) != PSRETURN_OK)
|
||||
debug_warn(L"Failed to retrieve tooltip text");
|
||||
const CStrW& text = GUI<CStrW>::GetSetting(obj, m_IsIconTooltip ? "_icon_tooltip" : "tooltip");
|
||||
|
||||
if (usedobj->SetSetting("caption", text) != PSRETURN_OK)
|
||||
debug_warn(L"Failed to set tooltip caption");
|
||||
@ -173,9 +164,8 @@ void GUITooltip::HideTooltip(const CStr& style, CGUI& pGUI)
|
||||
return;
|
||||
}
|
||||
|
||||
CStr usedObjectName;
|
||||
if (GUI<CStr>::GetSetting(tooltipobj, "use_object", usedObjectName) == PSRETURN_OK &&
|
||||
!usedObjectName.empty())
|
||||
const CStr& usedObjectName = GUI<CStr>::GetSetting(tooltipobj, "use_object");
|
||||
if (!usedObjectName.empty())
|
||||
{
|
||||
IGUIObject* usedobj = pGUI.FindObjectByName(usedObjectName);
|
||||
if (!usedobj)
|
||||
@ -188,10 +178,7 @@ void GUITooltip::HideTooltip(const CStr& style, CGUI& pGUI)
|
||||
SGUIMessage msg(GUIM_SETTINGS_UPDATED, "caption");
|
||||
usedobj->HandleMessage(msg);
|
||||
|
||||
bool hideobject = true;
|
||||
GUI<bool>::GetSetting(tooltipobj, "hide_object", hideobject);
|
||||
|
||||
if (hideobject)
|
||||
if (GUI<bool>::GetSetting(tooltipobj, "hide_object"))
|
||||
GUI<bool>::SetSetting(usedobj, "hidden", true);
|
||||
}
|
||||
else
|
||||
@ -200,16 +187,15 @@ void GUITooltip::HideTooltip(const CStr& style, CGUI& pGUI)
|
||||
|
||||
static int GetTooltipDelay(const CStr& style, CGUI& pGUI)
|
||||
{
|
||||
int delay = 500; // default value (in msec)
|
||||
|
||||
IGUIObject* tooltipobj = pGUI.FindObjectByName("__tooltip_" + style);
|
||||
|
||||
if (!tooltipobj)
|
||||
{
|
||||
LOGERROR("Cannot find tooltip object named '%s'", style.c_str());
|
||||
return delay;
|
||||
return 500;
|
||||
}
|
||||
GUI<int>::GetSetting(tooltipobj, "delay", delay);
|
||||
return delay;
|
||||
|
||||
return GUI<int>::GetSetting(tooltipobj, "delay");
|
||||
}
|
||||
|
||||
void GUITooltip::Update(IGUIObject* Nearest, const CPos& MousePos, CGUI& GUI)
|
||||
|
@ -116,16 +116,6 @@ 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>::GetSetting(const IGUIObject* pObject, const CStr& Setting, T& Value)
|
||||
{
|
||||
T* v = NULL;
|
||||
PSRETURN ret = GetSettingPointer(pObject, Setting, v);
|
||||
if (ret == PSRETURN_OK)
|
||||
Value = *v;
|
||||
return ret;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
PSRETURN GUI<T>::SetSetting(IGUIObject* pObject, const CStr& Setting, T& Value, const bool& SkipMessage)
|
||||
{
|
||||
@ -196,7 +186,6 @@ PSRETURN GUI<T>::SetSettingWrap(IGUIObject* pObject, const CStr& Setting, const
|
||||
|
||||
// Copying functions - discouraged except for primitives.
|
||||
#define TYPE(T) \
|
||||
template PSRETURN GUI<T>::GetSetting(const IGUIObject* pObject, const CStr& Setting, T& Value); \
|
||||
template PSRETURN GUI<T>::SetSetting(IGUIObject* pObject, const CStr& Setting, const T& Value, const bool& SkipMessage); \
|
||||
|
||||
#define GUITYPE_IGNORE_NONCOPYABLE
|
||||
|
@ -135,19 +135,8 @@ public:
|
||||
*/
|
||||
static T& GetSetting(const IGUIObject* pObject, const CStr& Setting);
|
||||
|
||||
// Like GetSetting (below), but doesn't make a copy of the value
|
||||
// (so it can be modified later)
|
||||
static PSRETURN GetSettingPointer(const IGUIObject* pObject, const CStr& Setting, T*& Value);
|
||||
|
||||
/**
|
||||
* Copy-assigns the current setting value to the given reference.
|
||||
*
|
||||
* @param pObject Object pointer
|
||||
* @param Setting Setting by name
|
||||
* @param Value Stores value here, note type T!
|
||||
*/
|
||||
static PSRETURN GetSetting(const IGUIObject* pObject, const CStr& Setting, T& Value);
|
||||
|
||||
/**
|
||||
* Sets a value by name using a real datatype as input.
|
||||
* This variant will use the move-assignment.
|
||||
|
@ -32,8 +32,8 @@ IGUIButtonBehavior::~IGUIButtonBehavior()
|
||||
|
||||
void IGUIButtonBehavior::HandleMessage(SGUIMessage& Message)
|
||||
{
|
||||
bool enabled;
|
||||
GUI<bool>::GetSetting(this, "enabled", enabled);
|
||||
const bool enabled = GUI<bool>::GetSetting(this, "enabled");
|
||||
|
||||
CStrW soundPath;
|
||||
// TODO Gee: easier access functions
|
||||
switch (Message.type)
|
||||
@ -123,10 +123,7 @@ const CGUIColor& IGUIButtonBehavior::ChooseColor()
|
||||
// Yes, the object must possess these settings. They are standard
|
||||
const CGUIColor& color = GUI<CGUIColor>::GetSetting(this, "textcolor");
|
||||
|
||||
bool enabled;
|
||||
GUI<bool>::GetSetting(this, "enabled", enabled);
|
||||
|
||||
if (!enabled)
|
||||
if (!GUI<bool>::GetSetting(this, "enabled"))
|
||||
return GUI<CGUIColor>::GetSetting(this, "textcolor_disabled") || color;
|
||||
|
||||
if (m_MouseHovering)
|
||||
@ -142,10 +139,7 @@ const CGUIColor& IGUIButtonBehavior::ChooseColor()
|
||||
|
||||
void IGUIButtonBehavior::DrawButton(const CRect& rect, const float& z, CGUISpriteInstance& sprite, CGUISpriteInstance& sprite_over, CGUISpriteInstance& sprite_pressed, CGUISpriteInstance& sprite_disabled, int cell_id)
|
||||
{
|
||||
bool enabled;
|
||||
GUI<bool>::GetSetting(this, "enabled", enabled);
|
||||
|
||||
if (!enabled)
|
||||
if (!GUI<bool>::GetSetting(this, "enabled"))
|
||||
m_pGUI.DrawSprite(sprite_disabled || sprite, cell_id, z, rect);
|
||||
else if (m_MouseHovering)
|
||||
{
|
||||
|
@ -216,18 +216,13 @@ void IGUIObject::ResetStates()
|
||||
|
||||
void IGUIObject::UpdateCachedSize()
|
||||
{
|
||||
bool absolute;
|
||||
GUI<bool>::GetSetting(this, "absolute", absolute);
|
||||
|
||||
float aspectratio = 0.f;
|
||||
GUI<float>::GetSetting(this, "aspectratio", aspectratio);
|
||||
|
||||
const CClientArea& ca = GUI<CClientArea>::GetSetting(this, "size");
|
||||
const float aspectratio = GUI<float>::GetSetting(this, "aspectratio");
|
||||
|
||||
// If absolute="false" and the object has got a parent,
|
||||
// use its cached size instead of the screen. Notice
|
||||
// it must have just been cached for it to work.
|
||||
if (absolute == false && m_pParent && !IsRootObject())
|
||||
if (!GUI<bool>::GetSetting(this, "absolute") && m_pParent && !IsRootObject())
|
||||
m_CachedActualSize = ca.GetClientArea(m_pParent->m_CachedActualSize);
|
||||
else
|
||||
m_CachedActualSize = ca.GetClientArea(CRect(0.f, 0.f, g_xres / g_GuiScale, g_yres / g_GuiScale));
|
||||
@ -279,15 +274,11 @@ void IGUIObject::LoadStyle(const SGUIStyle& Style)
|
||||
|
||||
float IGUIObject::GetBufferedZ() const
|
||||
{
|
||||
bool absolute;
|
||||
GUI<bool>::GetSetting(this, "absolute", absolute);
|
||||
const float Z = GUI<float>::GetSetting(this, "z");
|
||||
|
||||
float Z;
|
||||
GUI<float>::GetSetting(this, "z", Z);
|
||||
|
||||
if (absolute)
|
||||
if (GUI<bool>::GetSetting(this, "absolute"))
|
||||
return Z;
|
||||
else
|
||||
|
||||
{
|
||||
if (GetParent())
|
||||
return GetParent()->GetBufferedZ() + Z;
|
||||
|
@ -103,14 +103,11 @@ void IGUITextOwner::DrawText(size_t index, const CGUIColor& color, const CPos& p
|
||||
|
||||
void IGUITextOwner::CalculateTextPosition(CRect& ObjSize, CPos& TextPos, CGUIText& Text)
|
||||
{
|
||||
EVAlign valign;
|
||||
GUI<EVAlign>::GetSetting(this, "text_valign", valign);
|
||||
|
||||
// The horizontal Alignment is now computed in GenerateText in order to not have to
|
||||
// loop through all of the TextCall objects again.
|
||||
TextPos.x = ObjSize.left;
|
||||
|
||||
switch (valign)
|
||||
switch (GUI<EVAlign>::GetSetting(this, "text_valign"))
|
||||
{
|
||||
case EVAlign_Top:
|
||||
TextPos.y = ObjSize.top;
|
||||
|
Loading…
Reference in New Issue
Block a user