Add IGUIImage::setDrawBackground to allow disabling background drawing even when no texture is set.

I considered also adding more flags to allow background drawing when a texture is set, but couldn't 
really find a good use-case for that, so keeping it simple (also that case could be done 
otherwise with a second element and disabling background drawing for top-element completely).


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@5563 dfc29bdd-3216-0410-991c-e03cc46cb475
master
cutealien 2017-11-03 22:34:46 +00:00
parent 99f957efe9
commit a03af926e9
4 changed files with 27 additions and 3 deletions

View File

@ -1,5 +1,6 @@
--------------------------
Changes in 1.9 (not yet released)
- Add IGUIImage::setDrawBackground to allow disabling background drawing even when no texture is set.
- Add gui event EGET_ELEMENT_REMOVED.
- Fix: IGUIContextMenu now raises sub-menu when they would otherwise be displayed below bottom-border of root gui element.
- Prevent initializing/quitting SDL several times when using more than one Irrlicht device.

View File

@ -15,7 +15,6 @@ namespace video
}
namespace gui
{
//! GUI element displaying an image.
class IGUIImage : public IGUIElement
{
@ -71,6 +70,14 @@ namespace gui
//! Get drawing-area restrictions.
virtual core::rect<f32> getDrawBounds() const = 0;
//! Sets whether to draw a background color (EGDC_3D_DARK_SHADOW) when no texture is set
/** By default it's enabled */
virtual void setDrawBackground(bool draw) = 0;
//! Checks if a background is drawn when no texture is set
/** \return true if background drawing is enabled, false otherwise */
virtual bool isDrawBackgroundEnabled() const = 0;
};

View File

@ -18,7 +18,7 @@ namespace gui
//! constructor
CGUIImage::CGUIImage(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect<s32> rectangle)
: IGUIImage(environment, parent, id, rectangle), Texture(0), Color(255,255,255,255),
UseAlphaChannel(false), ScaleImage(false), DrawBounds(0.f, 0.f, 1.f, 1.f)
UseAlphaChannel(false), ScaleImage(false), DrawBounds(0.f, 0.f, 1.f, 1.f), DrawBackground(true)
{
#ifdef _DEBUG
setDebugName("CGUIImage");
@ -104,7 +104,7 @@ void CGUIImage::draw()
&clippingRect, Color, UseAlphaChannel);
}
}
else
else if ( DrawBackground )
{
core::rect<s32> clippingRect(AbsoluteClippingRect);
checkBounds(clippingRect);
@ -188,6 +188,7 @@ void CGUIImage::serializeAttributes(io::IAttributes* out, io::SAttributeReadWrit
out->addFloat ("DrawBoundsY1", DrawBounds.UpperLeftCorner.Y);
out->addFloat ("DrawBoundsX2", DrawBounds.LowerRightCorner.X);
out->addFloat ("DrawBoundsY2", DrawBounds.LowerRightCorner.Y);
out->addBool ("DrawBackground", DrawBackground);
}
@ -207,6 +208,8 @@ void CGUIImage::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWri
DrawBounds.LowerRightCorner.X = in->getAttributeAsFloat("DrawBoundsX2", DrawBounds.LowerRightCorner.X);
DrawBounds.LowerRightCorner.Y = in->getAttributeAsFloat("DrawBoundsY2", DrawBounds.LowerRightCorner.Y);
setDrawBounds(DrawBounds);
setDrawBackground(in->getAttributeAsBool("DrawBackground", DrawBackground));
}

View File

@ -64,6 +64,18 @@ namespace gui
//! Get drawing-area restrictions.
virtual core::rect<f32> getDrawBounds() const _IRR_OVERRIDE_;
//! Sets whether to draw a background color (EGDC_3D_DARK_SHADOW) when no texture is set
virtual void setDrawBackground(bool draw) _IRR_OVERRIDE_
{
DrawBackground = draw;
}
//! Checks if a background is drawn when no texture is set
virtual bool isDrawBackgroundEnabled() const _IRR_OVERRIDE_
{
return DrawBackground;
}
//! Writes attributes of the element.
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const _IRR_OVERRIDE_;
@ -89,6 +101,7 @@ namespace gui
bool ScaleImage;
core::rect<s32> SourceRect;
core::rect<f32> DrawBounds;
bool DrawBackground;
};