Move GUI<>::FallBackSprite and GUI<>::FallBackColor to CGUIColor::operator|| and CGUISpriteInstance::operator||.
Leaves only setting management in GUIutil.h. Differential Revision: https://code.wildfiregames.com/D2185 This was SVN commit r22689.
This commit is contained in:
parent
4e55808cf9
commit
9985fcf5bd
@ -43,6 +43,14 @@ struct CColor
|
||||
CColor() : r(-1.f), g(-1.f), b(-1.f), a(1.f) {}
|
||||
CColor(float cr, float cg, float cb, float ca) : r(cr), g(cg), b(cb), a(ca) {}
|
||||
|
||||
/**
|
||||
* Returns whether this has been set to a valid color.
|
||||
*/
|
||||
operator bool() const
|
||||
{
|
||||
return r >= 0 && g >= 0 && b >= 0 && a >= 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to parse @p Value as a color. Returns true on success, false otherwise.
|
||||
* @param value Should be "r g b" or "r g b a" where each value is an integer in [0,255].
|
||||
|
@ -493,7 +493,7 @@ void CDropDown::Draw()
|
||||
GUI<CGUIColor>::GetSetting(this, enabled ? "textcolor_selected" : "textcolor_disabled", color);
|
||||
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, enabled ? "sprite" : "sprite_disabled", sprite);
|
||||
GetGUI()->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize);
|
||||
m_pGUI->DrawSprite(*sprite, cell_id, bz, m_CachedActualSize);
|
||||
|
||||
if (button_width > 0.f)
|
||||
{
|
||||
@ -503,20 +503,20 @@ void CDropDown::Draw()
|
||||
if (!enabled)
|
||||
{
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite2_disabled", sprite2_second);
|
||||
GetGUI()->DrawSprite(GUI<>::FallBackSprite(*sprite2_second, *sprite2), cell_id, bz+0.05f, rect);
|
||||
m_pGUI->DrawSprite(*sprite2_second || *sprite2, cell_id, bz + 0.05f, rect);
|
||||
}
|
||||
else if (m_Open)
|
||||
{
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite2_pressed", sprite2_second);
|
||||
GetGUI()->DrawSprite(GUI<>::FallBackSprite(*sprite2_second, *sprite2), cell_id, bz+0.05f, rect);
|
||||
m_pGUI->DrawSprite(*sprite2_second || *sprite2, cell_id, bz + 0.05f, rect);
|
||||
}
|
||||
else if (m_MouseHovering)
|
||||
{
|
||||
GUI<CGUISpriteInstance>::GetSettingPointer(this, "sprite2_over", sprite2_second);
|
||||
GetGUI()->DrawSprite(GUI<>::FallBackSprite(*sprite2_second, *sprite2), cell_id, bz+0.05f, rect);
|
||||
m_pGUI->DrawSprite(*sprite2_second || *sprite2, cell_id, bz + 0.05f, rect);
|
||||
}
|
||||
else
|
||||
GetGUI()->DrawSprite(*sprite2, cell_id, bz+0.05f, rect);
|
||||
m_pGUI->DrawSprite(*sprite2, cell_id, bz + 0.05f, rect);
|
||||
}
|
||||
|
||||
if (selected != -1) // TODO: Maybe check validity completely?
|
||||
|
@ -353,7 +353,7 @@ void CGUI::Draw()
|
||||
void CGUI::DrawSprite(const CGUISpriteInstance& Sprite, int CellID, const float& Z, const CRect& Rect, const CRect& UNUSED(Clipping))
|
||||
{
|
||||
// If the sprite doesn't exist (name == ""), don't bother drawing anything
|
||||
if (Sprite.IsEmpty())
|
||||
if (!Sprite)
|
||||
return;
|
||||
|
||||
// TODO: Clipping?
|
||||
|
@ -32,6 +32,16 @@ struct CGUIColor : CColor
|
||||
|
||||
CGUIColor(float r, float g, float b, float a) : CColor(r, g, b, a) {}
|
||||
|
||||
/**
|
||||
* Returns this color if it has been set, otherwise the given fallback color.
|
||||
*/
|
||||
const CGUIColor& operator||(const CGUIColor& fallback) const
|
||||
{
|
||||
if (*this)
|
||||
return *this;
|
||||
return fallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load color depending on current GUI page.
|
||||
*/
|
||||
|
@ -57,11 +57,11 @@ void CGUIScrollBarVertical::Draw()
|
||||
return;
|
||||
}
|
||||
|
||||
if (GetGUI() && IsVisible())
|
||||
if (IsVisible())
|
||||
{
|
||||
CRect outline = GetOuterRect();
|
||||
|
||||
GetGUI()->DrawSprite(
|
||||
m_pGUI->DrawSprite(
|
||||
GetStyle()->m_SpriteBackVertical,
|
||||
0,
|
||||
m_Z+0.1f,
|
||||
@ -81,9 +81,9 @@ void CGUIScrollBarVertical::Draw()
|
||||
if (m_ButtonMinusHovered)
|
||||
{
|
||||
if (m_ButtonMinusPressed)
|
||||
button_top = &GUI<>::FallBackSprite(GetStyle()->m_SpriteButtonTopPressed, GetStyle()->m_SpriteButtonTop);
|
||||
button_top = &(GetStyle()->m_SpriteButtonTopPressed || GetStyle()->m_SpriteButtonTop);
|
||||
else
|
||||
button_top = &GUI<>::FallBackSprite(GetStyle()->m_SpriteButtonTopOver, GetStyle()->m_SpriteButtonTop);
|
||||
button_top = &(GetStyle()->m_SpriteButtonTopOver || GetStyle()->m_SpriteButtonTop);
|
||||
}
|
||||
else
|
||||
button_top = &GetStyle()->m_SpriteButtonTop;
|
||||
@ -91,14 +91,14 @@ void CGUIScrollBarVertical::Draw()
|
||||
if (m_ButtonPlusHovered)
|
||||
{
|
||||
if (m_ButtonPlusPressed)
|
||||
button_bottom = &GUI<>::FallBackSprite(GetStyle()->m_SpriteButtonBottomPressed, GetStyle()->m_SpriteButtonBottom);
|
||||
button_bottom = &(GetStyle()->m_SpriteButtonBottomPressed || GetStyle()->m_SpriteButtonBottom);
|
||||
else
|
||||
button_bottom = &GUI<>::FallBackSprite(GetStyle()->m_SpriteButtonBottomOver, GetStyle()->m_SpriteButtonBottom);
|
||||
button_bottom = &(GetStyle()->m_SpriteButtonBottomOver || GetStyle()->m_SpriteButtonBottom);
|
||||
}
|
||||
else
|
||||
button_bottom = &GetStyle()->m_SpriteButtonBottom;
|
||||
|
||||
GetGUI()->DrawSprite(
|
||||
m_pGUI->DrawSprite(
|
||||
*button_top,
|
||||
0,
|
||||
m_Z+0.2f,
|
||||
@ -110,7 +110,7 @@ void CGUIScrollBarVertical::Draw()
|
||||
)
|
||||
);
|
||||
|
||||
GetGUI()->DrawSprite(
|
||||
m_pGUI->DrawSprite(
|
||||
*button_bottom,
|
||||
0,
|
||||
m_Z+0.2f,
|
||||
@ -123,7 +123,7 @@ void CGUIScrollBarVertical::Draw()
|
||||
);
|
||||
}
|
||||
|
||||
GetGUI()->DrawSprite(
|
||||
m_pGUI->DrawSprite(
|
||||
GetStyle()->m_SpriteBarVertical,
|
||||
0,
|
||||
m_Z + 0.2f,
|
||||
|
@ -41,11 +41,6 @@ void CGUISpriteInstance::Draw(const CGUI* pGUI, const CRect& Size, int CellID, s
|
||||
GUIRenderer::Draw(m_DrawCallCache, Z);
|
||||
}
|
||||
|
||||
bool CGUISpriteInstance::IsEmpty() const
|
||||
{
|
||||
return m_SpriteName.empty();
|
||||
}
|
||||
|
||||
// Plus a load of constructors / assignment operators, which don't copy the
|
||||
// DrawCall cache (to avoid losing track of who has allocated various bits
|
||||
// of data):
|
||||
|
@ -162,8 +162,31 @@ public:
|
||||
CGUISpriteInstance(const CStr& SpriteName);
|
||||
|
||||
void Draw(const CGUI* pGUI, const CRect& Size, int CellID, std::map<CStr, const CGUISprite*>& Sprites, float Z) const;
|
||||
bool IsEmpty() const;
|
||||
|
||||
/**
|
||||
* Whether this Sprite has no texture name set.
|
||||
*/
|
||||
operator bool() const { return !m_SpriteName.empty(); };
|
||||
|
||||
/**
|
||||
* Returns this spirte if it has been set, otherwise the given fallback sprite.
|
||||
*/
|
||||
const CGUISpriteInstance& operator||(const CGUISpriteInstance& fallback) const
|
||||
{
|
||||
if (*this)
|
||||
return *this;
|
||||
return fallback;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sprite texture name.
|
||||
*/
|
||||
const CStr& GetName() const { return m_SpriteName; }
|
||||
|
||||
/**
|
||||
* Changes the texture name.
|
||||
* Use as rarely as possible, because it clears the draw cache.
|
||||
*/
|
||||
void SetName(const CStr& SpriteName);
|
||||
|
||||
private:
|
||||
|
@ -165,34 +165,6 @@ public:
|
||||
*/
|
||||
static PSRETURN SetSetting(IGUIObject* pObject, const CStr& Setting, const T& Value, const bool& SkipMessage = false);
|
||||
|
||||
/**
|
||||
* This will return the value of the first sprite if it's not null,
|
||||
* if it is null, it will return the value of the second sprite, if
|
||||
* that one is null, then null it is.
|
||||
*
|
||||
* @param prim Primary sprite that should be used
|
||||
* @param sec Secondary sprite if Primary should fail
|
||||
* @return Resulting string
|
||||
*/
|
||||
static const CGUISpriteInstance& FallBackSprite(const CGUISpriteInstance& prim, const CGUISpriteInstance& sec)
|
||||
{
|
||||
return (prim.IsEmpty() ? sec : prim);
|
||||
}
|
||||
|
||||
/**
|
||||
* Same principle as FallBackSprite
|
||||
*
|
||||
* @param prim Primary color that should be used
|
||||
* @param sec Secondary color if Primary should fail
|
||||
* @return Resulting color
|
||||
* @see FallBackSprite
|
||||
*/
|
||||
static CGUIColor FallBackColor(const CGUIColor& prim, const CGUIColor& sec)
|
||||
{
|
||||
// CGUIColor() == null.
|
||||
return ((prim!=CGUIColor())?(prim):(sec));
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a value by setting and object name using a real
|
||||
* datatype as input.
|
||||
|
@ -145,19 +145,19 @@ CGUIColor IGUIButtonBehavior::ChooseColor()
|
||||
if (!enabled)
|
||||
{
|
||||
GUI<CGUIColor>::GetSetting(this, "textcolor_disabled", color2);
|
||||
return GUI<>::FallBackColor(color2, color);
|
||||
return color2 || color;
|
||||
}
|
||||
else if (m_MouseHovering)
|
||||
{
|
||||
if (m_Pressed)
|
||||
{
|
||||
GUI<CGUIColor>::GetSetting(this, "textcolor_pressed", color2);
|
||||
return GUI<>::FallBackColor(color2, color);
|
||||
return color2 || color;
|
||||
}
|
||||
else
|
||||
{
|
||||
GUI<CGUIColor>::GetSetting(this, "textcolor_over", color2);
|
||||
return GUI<>::FallBackColor(color2, color);
|
||||
return color2 || color;
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -170,14 +170,14 @@ void IGUIButtonBehavior::DrawButton(const CRect& rect, const float& z, CGUISprit
|
||||
GUI<bool>::GetSetting(this, "enabled", enabled);
|
||||
|
||||
if (!enabled)
|
||||
GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_disabled, sprite), cell_id, z, rect);
|
||||
m_pGUI->DrawSprite(sprite_disabled || sprite, cell_id, z, rect);
|
||||
else if (m_MouseHovering)
|
||||
{
|
||||
if (m_Pressed)
|
||||
GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_pressed, sprite), cell_id, z, rect);
|
||||
m_pGUI->DrawSprite(sprite_pressed || sprite, cell_id, z, rect);
|
||||
else
|
||||
GetGUI()->DrawSprite(GUI<>::FallBackSprite(sprite_over, sprite), cell_id, z, rect);
|
||||
m_pGUI->DrawSprite(sprite_over || sprite, cell_id, z, rect);
|
||||
}
|
||||
else
|
||||
GetGUI()->DrawSprite(sprite, cell_id, z, rect);
|
||||
m_pGUI->DrawSprite(sprite, cell_id, z, rect);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user