mirror of
https://github.com/minetest/minetest.git
synced 2024-12-23 22:52:25 +01:00
Remove the dependency on FGIMG/BGIMG from the hovered/pressed variants
- Make guiButtonImage support null images properly
This commit is contained in:
parent
bd4b8d40b3
commit
e42faae8d9
@ -778,18 +778,25 @@ void GUIButton::setFromStyle(const StyleSpec& style, ISimpleTextureSource *tsrc)
|
||||
setDrawBorder(style.getBool(StyleSpec::BORDER, DrawBorder));
|
||||
setUseAlphaChannel(style.getBool(StyleSpec::ALPHA, true));
|
||||
|
||||
const core::position2di buttonCenter(AbsoluteRect.getCenter());
|
||||
core::position2d<s32> geom(buttonCenter);
|
||||
if (style.isNotDefault(StyleSpec::BGIMG)) {
|
||||
video::ITexture *texture = style.getTexture(StyleSpec::BGIMG, tsrc);
|
||||
video::ITexture *hovered_texture = style.getTexture(StyleSpec::BGIMG_HOVERED, tsrc, texture);
|
||||
video::ITexture *pressed_texture = style.getTexture(StyleSpec::BGIMG_PRESSED, tsrc, texture);
|
||||
|
||||
const core::position2di buttonCenter(AbsoluteRect.getCenter());
|
||||
core::position2d<s32> geom(buttonCenter);
|
||||
|
||||
setImage(guiScalingImageButton(
|
||||
Environment->getVideoDriver(), texture, geom.X, geom.Y));
|
||||
setScaleImage(true);
|
||||
}
|
||||
if (style.isNotDefault(StyleSpec::BGIMG_HOVERED)) {
|
||||
video::ITexture *hovered_texture = style.getTexture(StyleSpec::BGIMG_HOVERED, tsrc);
|
||||
|
||||
setHoveredImage(guiScalingImageButton(
|
||||
Environment->getVideoDriver(), hovered_texture, geom.X, geom.Y));
|
||||
setScaleImage(true);
|
||||
}
|
||||
if (style.isNotDefault(StyleSpec::BGIMG_PRESSED)) {
|
||||
video::ITexture *pressed_texture = style.getTexture(StyleSpec::BGIMG_PRESSED, tsrc);
|
||||
|
||||
setPressedImage(guiScalingImageButton(
|
||||
Environment->getVideoDriver(), pressed_texture, geom.X, geom.Y));
|
||||
setScaleImage(true);
|
||||
|
@ -46,7 +46,11 @@ bool GUIButtonImage::OnEvent(const SEvent& event)
|
||||
EGUI_BUTTON_IMAGE_STATE imageState = getImageState(isPressed(), m_foreground_images);
|
||||
video::ITexture *texture = m_foreground_images[(u32)imageState].Texture;
|
||||
if (texture != nullptr)
|
||||
{
|
||||
m_image->setImage(texture);
|
||||
}
|
||||
|
||||
m_image->setVisible(texture != nullptr);
|
||||
|
||||
return result;
|
||||
}
|
||||
@ -110,16 +114,23 @@ void GUIButtonImage::setFromStyle(const StyleSpec &style, ISimpleTextureSource *
|
||||
|
||||
video::IVideoDriver *driver = Environment->getVideoDriver();
|
||||
|
||||
const core::position2di buttonCenter(AbsoluteRect.getCenter());
|
||||
core::position2d<s32> geom(buttonCenter);
|
||||
if (style.isNotDefault(StyleSpec::FGIMG)) {
|
||||
video::ITexture *texture = style.getTexture(StyleSpec::FGIMG, tsrc);
|
||||
video::ITexture *hovered_texture = style.getTexture(StyleSpec::FGIMG_HOVERED, tsrc, texture);
|
||||
video::ITexture *pressed_texture = style.getTexture(StyleSpec::FGIMG_PRESSED, tsrc, texture);
|
||||
|
||||
const core::position2di buttonCenter(AbsoluteRect.getCenter());
|
||||
core::position2d<s32> geom(buttonCenter);
|
||||
|
||||
setForegroundImage(guiScalingImageButton(driver, texture, geom.X, geom.Y));
|
||||
setScaleImage(true);
|
||||
}
|
||||
if (style.isNotDefault(StyleSpec::FGIMG_HOVERED)) {
|
||||
video::ITexture *hovered_texture = style.getTexture(StyleSpec::FGIMG_HOVERED, tsrc);
|
||||
|
||||
setHoveredForegroundImage(guiScalingImageButton(driver, hovered_texture, geom.X, geom.Y));
|
||||
setScaleImage(true);
|
||||
}
|
||||
if (style.isNotDefault(StyleSpec::FGIMG_PRESSED)) {
|
||||
video::ITexture *pressed_texture = style.getTexture(StyleSpec::FGIMG_PRESSED, tsrc);
|
||||
|
||||
setPressedForegroundImage(guiScalingImageButton(driver, pressed_texture, geom.X, geom.Y));
|
||||
setScaleImage(true);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user