1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-08-11 17:51:04 +00:00

Add more visual feedback for button states (#8916)

- Add style properties for overriding the the hovered/pressed state
  - By default, hovered buttons are a lighter version of the base color
  - By default, pressed buttons are a darker version of the base color
- Add hovered bg image support for image buttons (style property)
This commit is contained in:
Hugues Ross 2019-10-12 12:44:23 -04:00 committed by SmallJoker
parent 894008ce6f
commit 69a2099c04
10 changed files with 151 additions and 39 deletions

View file

@ -712,6 +712,13 @@ void GUIFormSpecMenu::parseButton(parserData* data, const std::string &element,
if (style.isNotDefault(StyleSpec::BGCOLOR)) {
e->setColor(style.getColor(StyleSpec::BGCOLOR));
}
if (style.isNotDefault(StyleSpec::BGCOLOR_HOVERED)) {
e->setHoveredColor(style.getColor(StyleSpec::BGCOLOR_HOVERED));
}
if (style.isNotDefault(StyleSpec::BGCOLOR_PRESSED)) {
e->setPressedColor(style.getColor(StyleSpec::BGCOLOR_PRESSED));
}
if (style.isNotDefault(StyleSpec::TEXTCOLOR)) {
e->setOverrideColor(style.getColor(StyleSpec::TEXTCOLOR));
}
@ -720,11 +727,17 @@ void GUIFormSpecMenu::parseButton(parserData* data, const std::string &element,
if (style.isNotDefault(StyleSpec::BGIMG)) {
std::string image_name = style.get(StyleSpec::BGIMG, "");
std::string hovered_image_name = style.get(StyleSpec::BGIMG_HOVERED, "");
std::string pressed_image_name = style.get(StyleSpec::BGIMG_PRESSED, "");
video::ITexture *texture = 0;
video::ITexture *hovered_texture = 0;
video::ITexture *pressed_texture = 0;
texture = m_tsrc->getTexture(image_name);
if (!hovered_image_name.empty())
hovered_texture = m_tsrc->getTexture(hovered_image_name);
else
hovered_texture = texture;
if (!pressed_image_name.empty())
pressed_texture = m_tsrc->getTexture(pressed_image_name);
else
@ -733,6 +746,8 @@ void GUIFormSpecMenu::parseButton(parserData* data, const std::string &element,
e->setUseAlphaChannel(style.getBool(StyleSpec::ALPHA, true));
e->setImage(guiScalingImageButton(
Environment->getVideoDriver(), texture, geom.X, geom.Y));
e->setHoveredImage(guiScalingImageButton(
Environment->getVideoDriver(), hovered_texture, geom.X, geom.Y));
e->setPressedImage(guiScalingImageButton(
Environment->getVideoDriver(), pressed_texture, geom.X, geom.Y));
e->setScaleImage(true);
@ -1620,7 +1635,7 @@ void GUIFormSpecMenu::parseImageButton(parserData* data, const std::string &elem
else
pressed_texture = texture;
gui::IGUIButton *e = Environment->addButton(rect, this, spec.fid, spec.flabel.c_str());
GUIButton *e = GUIButton::addButton(Environment, rect, this, spec.fid, spec.flabel.c_str());
if (spec.fname == data->focused_fieldname) {
Environment->setFocus(e);
@ -1818,7 +1833,7 @@ void GUIFormSpecMenu::parseItemImageButton(parserData* data, const std::string &
258 + m_fields.size()
);
gui::IGUIButton *e = Environment->addButton(rect, this, spec.fid, L"");
gui::IGUIButton *e = GUIButton::addButton(Environment, rect, this, spec.fid, L"");
auto style = getStyleForElement("item_image_button", spec.fname, "image_button");
e->setNotClipped(style.getBool(StyleSpec::NOCLIP, false));
@ -2697,7 +2712,7 @@ void GUIFormSpecMenu::regenerateGui(v2u32 screensize)
core::rect<s32>(size.X/2-70, pos.Y,
(size.X/2-70)+140, pos.Y + (m_btn_height*2));
const wchar_t *text = wgettext("Proceed");
Environment->addButton(mydata.rect, this, 257, text);
GUIButton::addButton(Environment, mydata.rect, this, 257, text);
delete[] text;
}