Commit d2d60889 authored by cutealien's avatar cutealien

Add IGUIImages::setSourceRect/getSourceRect to allow using only parts of an...

Add IGUIImages::setSourceRect/getSourceRect to allow using only parts of an image (can also be used to mirror and scroll them).
Thx @Nalin and @StarSonata who both proposed patches for this in the past.


git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4730 dfc29bdd-3216-0410-991c-e03cc46cb475
parent 8e6db671
-------------------------- --------------------------
Changes in 1.9 (not yet released) Changes in 1.9 (not yet released)
- 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) - Collada dae-loader now set's the vertex colors (thx @sf17k for report and test-models)
- IAttributes interface changed. Parameters are now passed by const-ref instead of per value. - IAttributes interface changed. Parameters are now passed by const-ref instead of per value.
- Fix c::b project obj folder names. Some static builds had used the shared folders (thx @ gerdb for reporting) - Fix c::b project obj folder names. Some static builds had used the shared folders (thx @ gerdb for reporting)
......
...@@ -48,6 +48,14 @@ namespace gui ...@@ -48,6 +48,14 @@ namespace gui
//! Returns true if the image is using the alpha channel, false if not //! Returns true if the image is using the alpha channel, false if not
virtual bool isAlphaChannelUsed() const = 0; virtual bool isAlphaChannelUsed() const = 0;
//! Sets the source rectangle of the image. By default the full image is used.
/** \param sourceRect coordinates inside the image or an area with size 0 for using the full image (default). */
virtual void setSourceRect(const core::rect<s32>& sourceRect) = 0;
//! 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;
}; };
......
...@@ -78,18 +78,22 @@ void CGUIImage::draw() ...@@ -78,18 +78,22 @@ void CGUIImage::draw()
if (Texture) if (Texture)
{ {
core::rect<s32> sourceRect(SourceRect);
if (sourceRect.getWidth() == 0 || sourceRect.getHeight() == 0)
{
sourceRect = core::rect<s32>(core::position2d<s32>(0,0), core::dimension2di(Texture->getOriginalSize()));
}
if (ScaleImage) if (ScaleImage)
{ {
const video::SColor Colors[] = {Color,Color,Color,Color}; const video::SColor Colors[] = {Color,Color,Color,Color};
driver->draw2DImage(Texture, AbsoluteRect, driver->draw2DImage(Texture, AbsoluteRect, sourceRect,
core::rect<s32>(core::position2d<s32>(0,0), core::dimension2di(Texture->getOriginalSize())),
&AbsoluteClippingRect, Colors, UseAlphaChannel); &AbsoluteClippingRect, Colors, UseAlphaChannel);
} }
else else
{ {
driver->draw2DImage(Texture, AbsoluteRect.UpperLeftCorner, driver->draw2DImage(Texture, AbsoluteRect.UpperLeftCorner, sourceRect,
core::rect<s32>(core::position2d<s32>(0,0), core::dimension2di(Texture->getOriginalSize())),
&AbsoluteClippingRect, Color, UseAlphaChannel); &AbsoluteClippingRect, Color, UseAlphaChannel);
} }
} }
...@@ -130,6 +134,18 @@ bool CGUIImage::isAlphaChannelUsed() const ...@@ -130,6 +134,18 @@ bool CGUIImage::isAlphaChannelUsed() const
return UseAlphaChannel; return UseAlphaChannel;
} }
//! Sets the source rectangle of the image. By default the full image is used.
void CGUIImage::setSourceRect(const core::rect<s32>& sourceRect)
{
SourceRect = sourceRect;
}
//! Returns the customized source rectangle of the image to be used.
core::rect<s32> CGUIImage::getSourceRect() const
{
return SourceRect;
}
//! Writes attributes of the element. //! Writes attributes of the element.
void CGUIImage::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const void CGUIImage::serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options=0) const
...@@ -140,7 +156,7 @@ void CGUIImage::serializeAttributes(io::IAttributes* out, io::SAttributeReadWrit ...@@ -140,7 +156,7 @@ void CGUIImage::serializeAttributes(io::IAttributes* out, io::SAttributeReadWrit
out->addBool ("UseAlphaChannel", UseAlphaChannel); out->addBool ("UseAlphaChannel", UseAlphaChannel);
out->addColor ("Color", Color); out->addColor ("Color", Color);
out->addBool ("ScaleImage", ScaleImage); out->addBool ("ScaleImage", ScaleImage);
out->addRect ("SourceRect", SourceRect);
} }
...@@ -149,10 +165,11 @@ void CGUIImage::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWri ...@@ -149,10 +165,11 @@ void CGUIImage::deserializeAttributes(io::IAttributes* in, io::SAttributeReadWri
{ {
IGUIImage::deserializeAttributes(in,options); IGUIImage::deserializeAttributes(in,options);
setImage(in->getAttributeAsTexture("Texture")); setImage(in->getAttributeAsTexture("Texture", Texture));
setUseAlphaChannel(in->getAttributeAsBool("UseAlphaChannel")); setUseAlphaChannel(in->getAttributeAsBool("UseAlphaChannel", UseAlphaChannel));
setColor(in->getAttributeAsColor("Color")); setColor(in->getAttributeAsColor("Color", Color));
setScaleImage(in->getAttributeAsBool("ScaleImage")); setScaleImage(in->getAttributeAsBool("ScaleImage", UseAlphaChannel));
setSourceRect(in->getAttributeAsRect("SourceRect", SourceRect));
} }
......
...@@ -52,6 +52,12 @@ namespace gui ...@@ -52,6 +52,12 @@ namespace gui
//! Returns true if the image is using the alpha channel, false if not //! Returns true if the image is using the alpha channel, false if not
virtual bool isAlphaChannelUsed() const _IRR_OVERRIDE_; virtual bool isAlphaChannelUsed() const _IRR_OVERRIDE_;
//! Sets the source rectangle of the image. By default the full image is used.
virtual void setSourceRect(const core::rect<s32>& sourceRect) _IRR_OVERRIDE_;
//! Returns the customized source rectangle of the image to be used.
virtual core::rect<s32> getSourceRect() const _IRR_OVERRIDE_;
//! Writes attributes of the element. //! Writes attributes of the element.
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const _IRR_OVERRIDE_; virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const _IRR_OVERRIDE_;
...@@ -63,7 +69,7 @@ namespace gui ...@@ -63,7 +69,7 @@ namespace gui
video::SColor Color; video::SColor Color;
bool UseAlphaChannel; bool UseAlphaChannel;
bool ScaleImage; bool ScaleImage;
core::rect<s32> SourceRect;
}; };
......
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