MyGUI_Button.cpp
Go to the documentation of this file.
/*
* This source file is part of MyGUI. For the latest info, see http://mygui.info/
* Distributed under the MIT License
* (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
*/
#include "MyGUI_Precompiled.h"
#include "MyGUI_Button.h"
#include "MyGUI_ResourceSkin.h"
#include "MyGUI_ImageBox.h"
#include "MyGUI_InputManager.h"
namespace MyGUI
{
void Button::initialiseOverride()
{
Base::initialiseOverride();
assignWidget(mImage, "Image");
}
void Button::shutdownOverride()
{
mImage = nullptr;
Base::shutdownOverride();
}
void Button::onKeySetFocus(Widget* _old)
{
_setKeyFocus(true);
Base::onKeySetFocus(_old);
}
void Button::onKeyLostFocus(Widget* _new)
{
_setKeyFocus(false);
Base::onKeyLostFocus(_new);
}
void Button::onMouseSetFocus(Widget* _old)
{
_setMouseFocus(true);
Base::onMouseSetFocus(_old);
}
void Button::onMouseLostFocus(Widget* _new)
{
_setMouseFocus(false);
Base::onMouseLostFocus(_new);
}
void Button::onMouseButtonPressed(int _left, int _top, MouseButton _id)
{
if (_id == MouseButton::Left)
{
mIsMousePressed = true;
updateButtonState();
}
Base::onMouseButtonPressed(_left, _top, _id);
}
void Button::onMouseButtonReleased(int _left, int _top, MouseButton _id)
{
if (_id == MouseButton::Left)
{
mIsMousePressed = false;
updateButtonState();
}
Base::onMouseButtonReleased(_left, _top, _id);
}
void Button::updateButtonState()
{
if (mStateSelected)
{
if (!getInheritedEnabled())
{
if (!_setState("disabled_checked"))
_setState("disabled");
}
else if (mIsMousePressed)
{
if (!_setState("pushed_checked"))
_setState("pushed");
}
else if (mIsMouseFocus || mIsKeyFocus)
{
if (!_setState("highlighted_checked"))
_setState("pushed");
}
else
{
if (!_setState("normal_checked"))
_setState("pushed");
}
}
else
{
if (!getInheritedEnabled())
_setState("disabled");
else if (mIsMousePressed)
_setState("pushed");
else if (mIsMouseFocus || mIsKeyFocus)
_setState("highlighted");
else
_setState("normal");
}
}
void Button::setStateSelected(bool _check)
{
if (mStateSelected == _check)
return;
mStateSelected = _check;
updateButtonState();
}
void Button::_setKeyFocus(bool _focus)
{
mIsKeyFocus = _focus;
updateButtonState();
}
void Button::_setMouseFocus(bool _focus)
{
mIsMouseFocus = _focus;
updateButtonState();
}
void Button::baseUpdateEnable()
{
updateButtonState();
if (!getInheritedEnabled())
{
mIsKeyFocus = false;
mIsMouseFocus = false;
}
}
void Button::setModeImage(bool _value)
{
mModeImage = _value;
updateButtonState();
}
bool Button::_setState(std::string_view _value)
{
if (mModeImage)
{
if (mImage)
mImage->setItemName(_value);
_setWidgetState(_value);
return true;
}
return _setWidgetState(_value);
}
void Button::setImageResource(std::string_view _name)
{
if (mImage)
mImage->setItemResource(_name);
updateButtonState();
}
void Button::setImageGroup(std::string_view _name)
{
if (mImage)
mImage->setItemGroup(_name);
updateButtonState();
}
void Button::setImageName(std::string_view _name)
{
if (mImage)
mImage->setItemName(_name);
}
void Button::setPropertyOverride(std::string_view _key, std::string_view _value)
{
if (_key == "StateSelected")
setStateSelected(utility::parseValue<bool>(_value));
else if (_key == "ModeImage")
setModeImage(utility::parseValue<bool>(_value));
else if (_key == "ImageResource")
setImageResource(_value);
else if (_key == "ImageGroup")
setImageGroup(_value);
else if (_key == "ImageName")
setImageName(_value);
else
{
Base::setPropertyOverride(_key, _value);
return;
}
eventChangeProperty(this, _key, _value);
}
bool Button::getStateSelected() const
{
return mStateSelected;
}
bool Button::getModeImage() const
{
return mModeImage;
}
ImageBox* Button::_getImageBox() const
{
return mImage;
}
} // namespace MyGUI
MyGUI_Button.h
MyGUI_ImageBox.h
MyGUI_InputManager.h
MyGUI_Precompiled.h
MyGUI_ResourceSkin.h
MyGUI::Button::onMouseSetFocus
void onMouseSetFocus(Widget *_old) override
Definition MyGUI_Button.cpp:45
MyGUI::Button::_setMouseFocus
void _setMouseFocus(bool _focus)
Definition MyGUI_Button.cpp:134
MyGUI::Button::_setState
bool _setState(std::string_view _value)
Definition MyGUI_Button.cpp:156
MyGUI::Button::onMouseButtonReleased
void onMouseButtonReleased(int _left, int _top, MouseButton _id) override
Definition MyGUI_Button.cpp:70
MyGUI::Button::onKeyLostFocus
void onKeyLostFocus(Widget *_new) override
Definition MyGUI_Button.cpp:38
MyGUI::Button::onMouseButtonPressed
void onMouseButtonPressed(int _left, int _top, MouseButton _id) override
Definition MyGUI_Button.cpp:59
MyGUI::Button::setImageName
void setImageName(std::string_view _name)
Definition MyGUI_Button.cpp:184
MyGUI::Button::onKeySetFocus
void onKeySetFocus(Widget *_old) override
Definition MyGUI_Button.cpp:31
MyGUI::Button::getStateSelected
bool getStateSelected() const
Get buton selected.
Definition MyGUI_Button.cpp:221
MyGUI::Button::getModeImage
bool getModeImage() const
Definition MyGUI_Button.cpp:226
MyGUI::Button::_getImageBox
ImageBox * _getImageBox() const
Definition MyGUI_Button.cpp:231
MyGUI::Button::setPropertyOverride
void setPropertyOverride(std::string_view _key, std::string_view _value) override
Definition MyGUI_Button.cpp:190
MyGUI::Button::shutdownOverride
void shutdownOverride() override
Definition MyGUI_Button.cpp:24
MyGUI::Button::baseUpdateEnable
void baseUpdateEnable() override
Definition MyGUI_Button.cpp:140
MyGUI::Button::setImageResource
void setImageResource(std::string_view _name)
Definition MyGUI_Button.cpp:170
MyGUI::Button::setStateSelected
void setStateSelected(bool _check)
Set button selected state.
Definition MyGUI_Button.cpp:119
MyGUI::Button::initialiseOverride
void initialiseOverride() override
Definition MyGUI_Button.cpp:16
MyGUI::Button::setModeImage
void setModeImage(bool _value)
Definition MyGUI_Button.cpp:150
MyGUI::Button::onMouseLostFocus
void onMouseLostFocus(Widget *_new) override
Definition MyGUI_Button.cpp:52
MyGUI::Button::setImageGroup
void setImageGroup(std::string_view _name)
Definition MyGUI_Button.cpp:177
MyGUI::Button::_setKeyFocus
void _setKeyFocus(bool _focus)
Definition MyGUI_Button.cpp:128
MyGUI::ImageBox
widget description should be here.
Definition MyGUI_ImageBox.h:22
MyGUI::Widget
widget description should be here.
Definition MyGUI_Widget.h:40
MyGUI::Widget::getInheritedEnabled
bool getInheritedEnabled() const
Definition MyGUI_Widget.cpp:1412
MyGUI::Widget::eventChangeProperty
EventHandle_WidgetStringString eventChangeProperty
Definition MyGUI_Widget.h:324
MyGUI::Widget::_setWidgetState
bool _setWidgetState(std::string_view _state)
Definition MyGUI_Widget.cpp:406
MyGUI::Widget::assignWidget
void assignWidget(T *&_widget, std::string_view _name)
Definition MyGUI_Widget.h:413
MyGUI::utility::parseValue
T parseValue(std::string_view _value)
Definition MyGUI_StringUtility.h:60
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::MouseButton
Definition MyGUI_MouseButton.h:16
MyGUI::MouseButton::Left
@ Left
Definition MyGUI_MouseButton.h:21