From 69a2099c04527404f2d0942f2088b3d22dd75b5a Mon Sep 17 00:00:00 2001 From: Hugues Ross Date: Sat, 12 Oct 2019 12:44:23 -0400 Subject: 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) --- src/gui/guiFormSpecMenu.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src/gui/guiFormSpecMenu.cpp') diff --git a/src/gui/guiFormSpecMenu.cpp b/src/gui/guiFormSpecMenu.cpp index aee7da869..ea6072cab 100644 --- a/src/gui/guiFormSpecMenu.cpp +++ b/src/gui/guiFormSpecMenu.cpp @@ -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(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; } -- cgit v1.2.3