forked from mirror/openmw-tes3mp
Adjust ImageButton to accept key focus and use the 'highlighted' texture
This commit is contained in:
parent
c11fe6788f
commit
1ad14b232f
2 changed files with 57 additions and 8 deletions
|
@ -5,6 +5,15 @@
|
||||||
namespace Gui
|
namespace Gui
|
||||||
{
|
{
|
||||||
|
|
||||||
|
ImageButton::ImageButton()
|
||||||
|
: Base()
|
||||||
|
, mMouseFocus(false)
|
||||||
|
, mMousePress(false)
|
||||||
|
, mKeyFocus(false)
|
||||||
|
{
|
||||||
|
setNeedKeyFocus(true);
|
||||||
|
}
|
||||||
|
|
||||||
void ImageButton::setPropertyOverride(const std::string &_key, const std::string &_value)
|
void ImageButton::setPropertyOverride(const std::string &_key, const std::string &_value)
|
||||||
{
|
{
|
||||||
if (_key == "ImageHighlighted")
|
if (_key == "ImageHighlighted")
|
||||||
|
@ -24,22 +33,36 @@ namespace Gui
|
||||||
}
|
}
|
||||||
void ImageButton::onMouseSetFocus(Widget* _old)
|
void ImageButton::onMouseSetFocus(Widget* _old)
|
||||||
{
|
{
|
||||||
setImageTexture(mImageHighlighted);
|
mMouseFocus = true;
|
||||||
ImageBox::onMouseSetFocus(_old);
|
updateImage();
|
||||||
|
Base::onMouseSetFocus(_old);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageButton::onMouseLostFocus(Widget* _new)
|
void ImageButton::onMouseLostFocus(Widget* _new)
|
||||||
{
|
{
|
||||||
setImageTexture(mImageNormal);
|
mMouseFocus = false;
|
||||||
ImageBox::onMouseLostFocus(_new);
|
updateImage();
|
||||||
|
Base::onMouseLostFocus(_new);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImageButton::onMouseButtonPressed(int _left, int _top, MyGUI::MouseButton _id)
|
void ImageButton::onMouseButtonPressed(int _left, int _top, MyGUI::MouseButton _id)
|
||||||
{
|
{
|
||||||
if (_id == MyGUI::MouseButton::Left)
|
if (_id == MyGUI::MouseButton::Left)
|
||||||
setImageTexture(mImagePushed);
|
{
|
||||||
|
mMousePress = true;
|
||||||
|
updateImage();
|
||||||
|
}
|
||||||
|
Base::onMouseButtonPressed(_left, _top, _id);
|
||||||
|
}
|
||||||
|
|
||||||
ImageBox::onMouseButtonPressed(_left, _top, _id);
|
void ImageButton::updateImage()
|
||||||
|
{
|
||||||
|
if (mMousePress)
|
||||||
|
setImageTexture(mImagePushed);
|
||||||
|
else if (mMouseFocus || mKeyFocus)
|
||||||
|
setImageTexture(mImageHighlighted);
|
||||||
|
else
|
||||||
|
setImageTexture(mImageNormal);
|
||||||
}
|
}
|
||||||
|
|
||||||
MyGUI::IntSize ImageButton::getRequestedSize()
|
MyGUI::IntSize ImageButton::getRequestedSize()
|
||||||
|
@ -70,8 +93,23 @@ namespace Gui
|
||||||
void ImageButton::onMouseButtonReleased(int _left, int _top, MyGUI::MouseButton _id)
|
void ImageButton::onMouseButtonReleased(int _left, int _top, MyGUI::MouseButton _id)
|
||||||
{
|
{
|
||||||
if (_id == MyGUI::MouseButton::Left)
|
if (_id == MyGUI::MouseButton::Left)
|
||||||
setImageTexture(mImageHighlighted);
|
{
|
||||||
|
mMousePress = false;
|
||||||
|
updateImage();
|
||||||
|
}
|
||||||
|
|
||||||
ImageBox::onMouseButtonReleased(_left, _top, _id);
|
Base::onMouseButtonReleased(_left, _top, _id);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImageButton::onKeySetFocus(MyGUI::Widget *_old)
|
||||||
|
{
|
||||||
|
mKeyFocus = true;
|
||||||
|
updateImage();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ImageButton::onKeyLostFocus(MyGUI::Widget *_new)
|
||||||
|
{
|
||||||
|
mKeyFocus = false;
|
||||||
|
updateImage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,19 +16,30 @@ namespace Gui
|
||||||
public:
|
public:
|
||||||
MyGUI::IntSize getRequestedSize();
|
MyGUI::IntSize getRequestedSize();
|
||||||
|
|
||||||
|
ImageButton();
|
||||||
|
|
||||||
/// Set mImageNormal, mImageHighlighted and mImagePushed based on file convention (image_idle.ext, image_over.ext and image_pressed.ext)
|
/// Set mImageNormal, mImageHighlighted and mImagePushed based on file convention (image_idle.ext, image_over.ext and image_pressed.ext)
|
||||||
void setImage(const std::string& image);
|
void setImage(const std::string& image);
|
||||||
|
|
||||||
|
private:
|
||||||
|
void updateImage();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void setPropertyOverride(const std::string& _key, const std::string& _value);
|
virtual void setPropertyOverride(const std::string& _key, const std::string& _value);
|
||||||
virtual void onMouseLostFocus(MyGUI::Widget* _new);
|
virtual void onMouseLostFocus(MyGUI::Widget* _new);
|
||||||
virtual void onMouseSetFocus(MyGUI::Widget* _old);
|
virtual void onMouseSetFocus(MyGUI::Widget* _old);
|
||||||
virtual void onMouseButtonPressed(int _left, int _top, MyGUI::MouseButton _id);
|
virtual void onMouseButtonPressed(int _left, int _top, MyGUI::MouseButton _id);
|
||||||
virtual void onMouseButtonReleased(int _left, int _top, MyGUI::MouseButton _id);
|
virtual void onMouseButtonReleased(int _left, int _top, MyGUI::MouseButton _id);
|
||||||
|
virtual void onKeySetFocus(MyGUI::Widget* _old);
|
||||||
|
virtual void onKeyLostFocus(MyGUI::Widget* _new);
|
||||||
|
|
||||||
std::string mImageHighlighted;
|
std::string mImageHighlighted;
|
||||||
std::string mImageNormal;
|
std::string mImageNormal;
|
||||||
std::string mImagePushed;
|
std::string mImagePushed;
|
||||||
|
|
||||||
|
bool mMouseFocus;
|
||||||
|
bool mMousePress;
|
||||||
|
bool mKeyFocus;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue