forked from teamnwah/openmw-tes3coop
Add SharedStateButton, used in spell window and controls box to apply mouseover effect to all buttons within one row (Fixes #1986)
parent
3f0bc6eecb
commit
9a1b7cbe52
@ -0,0 +1,128 @@
|
||||
#include "sharedstatebutton.hpp"
|
||||
|
||||
namespace Gui
|
||||
{
|
||||
|
||||
SharedStateButton::SharedStateButton()
|
||||
: mIsMousePressed(false)
|
||||
, mIsMouseFocus(false)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void SharedStateButton::shutdownOverride()
|
||||
{
|
||||
ButtonGroup group = mSharedWith; // make a copy so that we don't nuke the vector during iteration
|
||||
for (ButtonGroup::iterator it = group.begin(); it != group.end(); ++it)
|
||||
{
|
||||
(*it)->shareStateWith(ButtonGroup());
|
||||
}
|
||||
}
|
||||
|
||||
void SharedStateButton::shareStateWith(ButtonGroup shared)
|
||||
{
|
||||
mSharedWith = shared;
|
||||
}
|
||||
|
||||
void SharedStateButton::onMouseButtonPressed(int _left, int _top, MyGUI::MouseButton _id)
|
||||
{
|
||||
mIsMousePressed = true;
|
||||
Base::onMouseButtonPressed(_left, _top, _id);
|
||||
updateButtonState();
|
||||
}
|
||||
|
||||
void SharedStateButton::onMouseButtonReleased(int _left, int _top, MyGUI::MouseButton _id)
|
||||
{
|
||||
mIsMousePressed = false;
|
||||
Base::onMouseButtonReleased(_left, _top, _id);
|
||||
updateButtonState();
|
||||
}
|
||||
|
||||
void SharedStateButton::onMouseSetFocus(MyGUI::Widget *_old)
|
||||
{
|
||||
mIsMouseFocus = true;
|
||||
Base::onMouseSetFocus(_old);
|
||||
updateButtonState();
|
||||
}
|
||||
|
||||
void SharedStateButton::onMouseLostFocus(MyGUI::Widget *_new)
|
||||
{
|
||||
mIsMouseFocus = false;
|
||||
Base::onMouseLostFocus(_new);
|
||||
updateButtonState();
|
||||
}
|
||||
|
||||
void SharedStateButton::baseUpdateEnable()
|
||||
{
|
||||
Base::baseUpdateEnable();
|
||||
updateButtonState();
|
||||
}
|
||||
|
||||
void SharedStateButton::setStateSelected(bool _value)
|
||||
{
|
||||
Base::setStateSelected(_value);
|
||||
updateButtonState();
|
||||
|
||||
for (ButtonGroup::iterator it = mSharedWith.begin(); it != mSharedWith.end(); ++it)
|
||||
{
|
||||
(*it)->MyGUI::Button::setStateSelected(getStateSelected());
|
||||
}
|
||||
}
|
||||
|
||||
bool SharedStateButton::_setState(const std::string &_value)
|
||||
{
|
||||
bool ret = _setWidgetState(_value);
|
||||
if (ret)
|
||||
{
|
||||
for (ButtonGroup::iterator it = mSharedWith.begin(); it != mSharedWith.end(); ++it)
|
||||
{
|
||||
(*it)->_setWidgetState(_value);
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
void SharedStateButton::updateButtonState()
|
||||
{
|
||||
if (getStateSelected())
|
||||
{
|
||||
if (!getInheritedEnabled())
|
||||
{
|
||||
if (!_setState("disabled_checked"))
|
||||
_setState("disabled");
|
||||
}
|
||||
else if (mIsMousePressed)
|
||||
{
|
||||
if (!_setState("pushed_checked"))
|
||||
_setState("pushed");
|
||||
}
|
||||
else if (mIsMouseFocus)
|
||||
{
|
||||
if (!_setState("highlighted_checked"))
|
||||
_setState("pushed");
|
||||
}
|
||||
else
|
||||
_setState("normal_checked");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!getInheritedEnabled())
|
||||
_setState("disabled");
|
||||
else if (mIsMousePressed)
|
||||
_setState("pushed");
|
||||
else if (mIsMouseFocus)
|
||||
_setState("highlighted");
|
||||
else
|
||||
_setState("normal");
|
||||
}
|
||||
}
|
||||
|
||||
void SharedStateButton::createButtonGroup(ButtonGroup group)
|
||||
{
|
||||
for (ButtonGroup::iterator it = group.begin(); it != group.end(); ++it)
|
||||
{
|
||||
(*it)->shareStateWith(group);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
#ifndef OPENMW_WIDGETS_SHAREDSTATEBUTTON_HPP
|
||||
#define OPENMW_WIDGETS_SHAREDSTATEBUTTON_HPP
|
||||
|
||||
#include <MyGUI_Button.h>
|
||||
|
||||
namespace Gui
|
||||
{
|
||||
|
||||
class SharedStateButton;
|
||||
|
||||
typedef std::vector<SharedStateButton*> ButtonGroup;
|
||||
|
||||
/// @brief A button that applies its own state changes to other widgets, to do this you define it as part of a ButtonGroup.
|
||||
class SharedStateButton : public MyGUI::Button
|
||||
{
|
||||
MYGUI_RTTI_DERIVED(SharedStateButton)
|
||||
|
||||
public:
|
||||
SharedStateButton();
|
||||
|
||||
protected:
|
||||
void updateButtonState();
|
||||
|
||||
virtual void onMouseButtonPressed(int _left, int _top, MyGUI::MouseButton _id);
|
||||
virtual void onMouseButtonReleased(int _left, int _top, MyGUI::MouseButton _id);
|
||||
virtual void onMouseSetFocus(MyGUI::Widget* _old);
|
||||
virtual void onMouseLostFocus(MyGUI::Widget* _new);
|
||||
virtual void baseUpdateEnable();
|
||||
|
||||
virtual void shutdownOverride();
|
||||
|
||||
bool _setState(const std::string &_value);
|
||||
|
||||
public:
|
||||
void shareStateWith(ButtonGroup shared);
|
||||
|
||||
/// @note The ButtonGroup connection will be destroyed when any widget in the group gets destroyed.
|
||||
static void createButtonGroup(ButtonGroup group);
|
||||
|
||||
//! Set button selected state
|
||||
void setStateSelected(bool _value);
|
||||
|
||||
private:
|
||||
ButtonGroup mSharedWith;
|
||||
|
||||
bool mIsMousePressed;
|
||||
bool mIsMouseFocus;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Reference in New Issue