From 9976f36b18b8d227e3240feb24000dda0916ee44 Mon Sep 17 00:00:00 2001 From: Hugues Ross Date: Sat, 29 Aug 2020 11:41:19 -0400 Subject: Make bgcolor tint button background images (#9818) --- src/gui/guiButton.cpp | 21 ++++++++++++++------- src/gui/guiButton.h | 1 + 2 files changed, 15 insertions(+), 7 deletions(-) (limited to 'src/gui') diff --git a/src/gui/guiButton.cpp b/src/gui/guiButton.cpp index e0d6337cd..b98e5de82 100644 --- a/src/gui/guiButton.cpp +++ b/src/gui/guiButton.cpp @@ -313,11 +313,12 @@ void GUIButton::draw() // PATCH video::ITexture* texture = ButtonImages[(u32)imageState].Texture; + video::SColor image_colors[] = { BgColor, BgColor, BgColor, BgColor }; if (BgMiddle.getArea() == 0) { driver->draw2DImage(texture, ScaleImage? AbsoluteRect : core::rect(pos, sourceRect.getSize()), sourceRect, &AbsoluteClippingRect, - 0, UseAlphaChannel); + image_colors, UseAlphaChannel); } else { core::rect middle = BgMiddle; // `-x` is interpreted as `w - x` @@ -327,7 +328,7 @@ void GUIButton::draw() middle.LowerRightCorner.Y += texture->getOriginalSize().Height; draw2DImage9Slice(driver, texture, ScaleImage ? AbsoluteRect : core::rect(pos, sourceRect.getSize()), - middle, &AbsoluteClippingRect); + middle, &AbsoluteClippingRect, image_colors); } // END PATCH } @@ -722,6 +723,8 @@ GUIButton* GUIButton::addButton(IGUIEnvironment *environment, void GUIButton::setColor(video::SColor color) { + BgColor = color; + float d = 0.65f; for (size_t i = 0; i < 4; i++) { video::SColor base = Environment->getSkin()->getColor((gui::EGUI_DEFAULT_COLOR)i); @@ -750,22 +753,26 @@ void GUIButton::setFromStyle(const StyleSpec& style) bool pressed = (style.getState() & StyleSpec::STATE_PRESSED) != 0; if (style.isNotDefault(StyleSpec::BGCOLOR)) { - setColor(style.getColor(StyleSpec::BGCOLOR)); // If we have a propagated hover/press color, we need to automatically // lighten/darken it if (!Styles[style.getState()].isNotDefault(StyleSpec::BGCOLOR)) { - for (size_t i = 0; i < 4; i++) { if (pressed) { - Colors[i] = multiplyColorValue(Colors[i], COLOR_PRESSED_MOD); + BgColor = multiplyColorValue(BgColor, COLOR_PRESSED_MOD); + + for (size_t i = 0; i < 4; i++) + Colors[i] = multiplyColorValue(Colors[i], COLOR_PRESSED_MOD); } else if (hovered) { - Colors[i] = multiplyColorValue(Colors[i], COLOR_HOVERED_MOD); + BgColor = multiplyColorValue(BgColor, COLOR_HOVERED_MOD); + + for (size_t i = 0; i < 4; i++) + Colors[i] = multiplyColorValue(Colors[i], COLOR_HOVERED_MOD); } - } } } else { + BgColor = video::SColor(255, 255, 255, 255); for (size_t i = 0; i < 4; i++) { video::SColor base = Environment->getSkin()->getColor((gui::EGUI_DEFAULT_COLOR)i); diff --git a/src/gui/guiButton.h b/src/gui/guiButton.h index 95fa1a2a1..4e1b04aac 100644 --- a/src/gui/guiButton.h +++ b/src/gui/guiButton.h @@ -338,5 +338,6 @@ private: core::rect BgMiddle; core::rect Padding; core::vector2d ContentOffset; + video::SColor BgColor; // END PATCH }; -- cgit v1.2.3