Commit ff7eee08 authored by cutealien's avatar cutealien

Add IGUIImages::setDrawBounds/getDrawBounds to allow coding stuff like progress bars.


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4734 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 2c7c73c5
--------------------------
Changes in 1.9 (not yet released)
- Add IGUIImages::setDrawBounds/getDrawBounds to allow coding stuff like progress bars.
- Add IGUIImages::setSourceRect/getSourceRect to allow using only parts of an image (can also be used to mirror and scroll them).
- Dev-Cpp project file removed (wasn't really supported for some time already)
- Collada dae-loader now set's the vertex colors (thx @sf17k for report and test-models)
......
......@@ -56,6 +56,19 @@ namespace gui
//! Returns the customized source rectangle of the image to be used.
/** By default an empty rectangle of width and height 0 is returned which means the full image is used. */
virtual core::rect<s32> getSourceRect() const = 0;
//! Restrict drawing-area.
/** This allows for example to use the image as a progress bar.
Base for area is the image, which means:
- The original clippping area when the texture is scaled or there is no texture.
- The source-rect for an unscaled texture (but still restricted afterwards by the clipping area)
Unlike normal clipping this does not affect the gui-children.
\param drawBoundUVs: Coordinates between 0 and 1 where 0 are for left+top and 1 for right+bottom
*/
virtual void setDrawBounds(const core::rect<f32>& drawBoundUVs = core::rect<f32>(0.f, 0.f, 1.f, 1.f)) = 0;
//! Get drawing-area restrictions.
virtual core::rect<f32> getDrawBounds() const = 0;
};
......@@ -63,4 +76,3 @@ namespace gui
} // end namespace irr
#endif
......@@ -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)
UseAlphaChannel(false), ScaleImage(false), DrawBounds(0.f, 0.f, 1.f, 1.f)
{
#ifdef _DEBUG
setDebugName("CGUIImage");
......@@ -88,18 +88,28 @@ void CGUIImage::draw()
{
const video::SColor Colors[] = {Color,Color,Color,Color};
core::rect<s32> clippingRect(AbsoluteClippingRect);
checkBounds(clippingRect);
driver->draw2DImage(Texture, AbsoluteRect, sourceRect,
&AbsoluteClippingRect, Colors, UseAlphaChannel);
&clippingRect, Colors, UseAlphaChannel);
}
else
{
core::rect<s32> clippingRect(AbsoluteRect.UpperLeftCorner, sourceRect.getSize());
checkBounds(clippingRect);
clippingRect.clipAgainst(AbsoluteClippingRect);
driver->draw2DImage(Texture, AbsoluteRect.UpperLeftCorner, sourceRect,
&AbsoluteClippingRect, Color, UseAlphaChannel);
&clippingRect, Color, UseAlphaChannel);
}
}
else
{
skin->draw2DRectangle(this, skin->getColor(EGDC_3D_DARK_SHADOW), AbsoluteRect, &AbsoluteClippingRect);
core::rect<s32> clippingRect(AbsoluteClippingRect);
checkBounds(clippingRect);
skin->draw2DRectangle(this, skin->getColor(EGDC_3D_DARK_SHADOW), AbsoluteRect, &clippingRect);
}
IGUIElement::draw();
......@@ -146,6 +156,25 @@ core::rect<s32> CGUIImage::getSourceRect() const
return SourceRect;
}
//! Restrict target drawing-area.
void CGUIImage::setDrawBounds(const core::rect<f32>& drawBoundUVs)
{
DrawBounds = drawBoundUVs;
DrawBounds.UpperLeftCorner.X = core::clamp(DrawBounds.UpperLeftCorner.X, 0.f, 1.f);
DrawBounds.UpperLeftCorner.Y = core::clamp(DrawBounds.UpperLeftCorner.Y, 0.f, 1.f);
DrawBounds.LowerRightCorner.X = core::clamp(DrawBounds.LowerRightCorner.X, 0.f, 1.f);
DrawBounds.LowerRightCorner.X = core::clamp(DrawBounds.LowerRightCorner.X, 0.f, 1.f);
if ( DrawBounds.UpperLeftCorner.X > DrawBounds.LowerRightCorner.X )
DrawBounds.UpperLeftCorner.X = DrawBounds.LowerRightCorner.X;
if ( DrawBounds.UpperLeftCorner.Y > DrawBounds.LowerRightCorner.Y )
DrawBounds.UpperLeftCorner.Y = DrawBounds.LowerRightCorner.Y;
}
//! Get target drawing-area restrictions.
core::rect<f32> CGUIImage::getDrawBounds() const
{
return DrawBounds;
}
//! Writes attributes of the element.
void CGUIImage::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const
......
......@@ -58,18 +58,37 @@ namespace gui
//! Returns the customized source rectangle of the image to be used.
virtual core::rect<s32> getSourceRect() const _IRR_OVERRIDE_;
//! Restrict drawing-area.
virtual void setDrawBounds(const core::rect<f32>& drawBoundUVs) _IRR_OVERRIDE_;
//! Get drawing-area restrictions.
virtual core::rect<f32> getDrawBounds() const _IRR_OVERRIDE_;
//! Writes attributes of the element.
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const _IRR_OVERRIDE_;
//! Reads attributes of the element
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) _IRR_OVERRIDE_;
protected:
void checkBounds(core::rect<s32>& rect)
{
f32 clipWidth = (f32)rect.getWidth();
f32 clipHeight = (f32)rect.getHeight();
rect.UpperLeftCorner.X += core::round32(DrawBounds.UpperLeftCorner.X*clipWidth);
rect.UpperLeftCorner.Y += core::round32(DrawBounds.UpperLeftCorner.Y*clipHeight);
rect.LowerRightCorner.X -= core::round32((1.f-DrawBounds.LowerRightCorner.X)*clipWidth);
rect.LowerRightCorner.Y -= core::round32((1.f-DrawBounds.LowerRightCorner.Y)*clipHeight);
}
private:
video::ITexture* Texture;
video::SColor Color;
bool UseAlphaChannel;
bool ScaleImage;
core::rect<s32> SourceRect;
core::rect<f32> DrawBounds;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment