Defragment IGUIButtonBehavior Settings.

Moves the AddSetting sound calls from CButton and CCheckbox to
IGUIButtonBehavior, since the latter is the only class to use them.
Moves ChooseColor from IGUIButtonBehavior to CButton, since that's the
only class to use it and the only class registering the dependent
Settings following b1422137e5 (refs d412b2010b / D2314)

Initialize m_PressedRight in the constructor to prevent undefined
behavior in possible future code following 0d204037b6, refs #1028.
Remove unused soundPath variable following 0e26503cc6 / D2209.

Differential Revision: https://code.wildfiregames.com/D2318
Tested on: clang 8.0.1, Jenkins

This was SVN commit r22969.
This commit is contained in:
elexis 2019-09-22 14:53:27 +00:00
parent e771ff40ea
commit 7bb0f2ea69
6 changed files with 33 additions and 45 deletions

View File

@ -29,11 +29,6 @@ CButton::CButton(CGUI& pGUI)
AddSetting<CGUIString>("caption");
AddSetting<i32>("cell_id");
AddSetting<CStrW>("font");
AddSetting<CStrW>("sound_disabled");
AddSetting<CStrW>("sound_enter");
AddSetting<CStrW>("sound_leave");
AddSetting<CStrW>("sound_pressed");
AddSetting<CStrW>("sound_released");
AddSetting<CGUISpriteInstance>("sprite");
AddSetting<CGUISpriteInstance>("sprite_over");
AddSetting<CGUISpriteInstance>("sprite_pressed");
@ -97,3 +92,19 @@ void CButton::Draw()
DrawText(0, ChooseColor(), m_TextPos, bz + 0.1f);
}
const CGUIColor& CButton::ChooseColor()
{
const CGUIColor& color = GetSetting<CGUIColor>("textcolor");
if (!GetSetting<bool>("enabled"))
return GetSetting<CGUIColor>("textcolor_disabled") || color;
if (!m_MouseHovering)
return color;
if (m_Pressed)
return GetSetting<CGUIColor>("textcolor_pressed") || color;
return GetSetting<CGUIColor>("textcolor_over") || color;
}

View File

@ -52,6 +52,11 @@ protected:
*/
void SetupText();
/**
* Picks the text color depending on current object settings.
*/
const CGUIColor& ChooseColor();
/**
* Placement of text.
*/

View File

@ -24,11 +24,6 @@ CCheckBox::CCheckBox(CGUI& pGUI)
{
AddSetting<i32>("cell_id");
AddSetting<bool>("checked");
AddSetting<CStrW>("sound_disabled");
AddSetting<CStrW>("sound_enter");
AddSetting<CStrW>("sound_leave");
AddSetting<CStrW>("sound_pressed");
AddSetting<CStrW>("sound_released");
AddSetting<CGUISpriteInstance>("sprite");
AddSetting<CGUISpriteInstance>("sprite_over");
AddSetting<CGUISpriteInstance>("sprite_pressed");

View File

@ -51,8 +51,6 @@ public:
CDropDown(CGUI& pGUI);
virtual ~CDropDown();
// virtual void ResetStates() { IGUIButtonBehavior::ResetStates(); }
/**
* @see IGUIObject#HandleMessage()
*/

View File

@ -17,13 +17,21 @@
#include "precompiled.h"
#include "IGUIButtonBehavior.h"
#include "gui/CGUI.h"
#include "gui/CGUISprite.h"
#include "gui/IGUIButtonBehavior.h"
IGUIButtonBehavior::IGUIButtonBehavior(CGUI& pGUI)
: IGUIObject(pGUI), m_Pressed(false)
: IGUIObject(pGUI),
m_Pressed(false),
m_PressedRight(false)
{
AddSetting<CStrW>("sound_disabled");
AddSetting<CStrW>("sound_enter");
AddSetting<CStrW>("sound_leave");
AddSetting<CStrW>("sound_pressed");
AddSetting<CStrW>("sound_released");
}
IGUIButtonBehavior::~IGUIButtonBehavior()
@ -34,7 +42,6 @@ void IGUIButtonBehavior::HandleMessage(SGUIMessage& Message)
{
const bool enabled = GetSetting<bool>("enabled");
CStrW soundPath;
// TODO Gee: easier access functions
switch (Message.type)
{
@ -118,25 +125,6 @@ void IGUIButtonBehavior::HandleMessage(SGUIMessage& Message)
}
}
const CGUIColor& IGUIButtonBehavior::ChooseColor()
{
// Yes, the object must possess these settings. They are standard
const CGUIColor& color = GetSetting<CGUIColor>("textcolor");
if (!GetSetting<bool>("enabled"))
return GetSetting<CGUIColor>("textcolor_disabled") || color;
if (m_MouseHovering)
{
if (m_Pressed)
return GetSetting<CGUIColor>("textcolor_pressed") || color;
else
return GetSetting<CGUIColor>("textcolor_over") || color;
}
return color;
}
void IGUIButtonBehavior::DrawButton(const CRect& rect, const float& z, CGUISpriteInstance& sprite, CGUISpriteInstance& sprite_over, CGUISpriteInstance& sprite_pressed, CGUISpriteInstance& sprite_disabled, int cell_id)
{
if (!GetSetting<bool>("enabled"))

View File

@ -65,15 +65,6 @@ public:
*/
void DrawButton(const CRect& rect, const float& z, CGUISpriteInstance& sprite, CGUISpriteInstance& sprite_over, CGUISpriteInstance& sprite_pressed, CGUISpriteInstance& sprite_disabled, int cell_id);
/**
* Choosing which color of the following according to object enabled/hovered/pressed status:
* textcolor_disabled -- disabled
* textcolor_pressed -- pressed
* textcolor_over -- hovered
*/
const CGUIColor& ChooseColor();
protected:
/**
* @see IGUIObject#ResetStates()
@ -93,8 +84,8 @@ protected:
* area, as long as you release it within the button area... Anyway
* this lets us know we are done with step one (clicking).
*/
bool m_Pressed;
bool m_PressedRight;
bool m_Pressed;
bool m_PressedRight;
};
#endif // INCLUDED_IGUIBUTTONBEHAVIOR