diff -abBdpuNPr --exclude='*.svn' irrlicht-svn-ss/trunk/include/IGUIImage.h Irrlicht_starsonata/include/IGUIImage.h --- irrlicht-svn-ss/trunk/include/IGUIImage.h 2007-07-26 02:11:22.000000000 +0200 +++ Irrlicht_starsonata/include/IGUIImage.h 2008-05-24 04:00:26.000000000 +0200 @@ -46,6 +46,18 @@ namespace gui //! Returns true if the image is using the alpha channel, false if not virtual bool isAlphaChannelUsed() const = 0; + //! sets the image source rectangle in the texture + virtual void setSourceRect(core::rect sourceRect) = 0; + + // starsonata, micha + //! Reduce the area used for clipping the image + //! All values are relative in percent to total width (for left and right) and height (for top and bottom) + //! Example: To create a typical progressbar which slightly increases you will decrease the right clipping from 100 to 0. + virtual void shrinkClippingArea(f32 left=0.f, f32 top=0.f, f32 right=0.f, f32 bottom=0.f) = 0; + + // starsonata, micha + //! rotate image + virtual void setRotationDegrees(f32 angle) = 0; }; diff -abBdpuNPr --exclude='*.svn' irrlicht-svn-ss/trunk/source/Irrlicht/CGUIImage.cpp Irrlicht_starsonata/source/Irrlicht/CGUIImage.cpp --- irrlicht-svn-ss/trunk/source/Irrlicht/CGUIImage.cpp 2007-07-26 02:11:08.000000000 +0200 +++ Irrlicht_starsonata/source/Irrlicht/CGUIImage.cpp 2008-05-24 04:54:22.000000000 +0200 @@ -18,6 +18,9 @@ namespace gui CGUIImage::CGUIImage(IGUIEnvironment* environment, IGUIElement* parent, s32 id, core::rect rectangle) : IGUIImage(environment, parent, id, rectangle), Color(255,255,255,255), Texture(0), UseAlphaChannel(false), ScaleImage(false) + , ShrinkClippingLeft(0.f), ShrinkClippingTop(0.f) + , ShrinkClippingRight(0.f), ShrinkClippingBottom(0.f) + , RotationAngle(0.f) { #ifdef _DEBUG setDebugName("CGUIImage"); @@ -38,6 +41,9 @@ CGUIImage::~CGUIImage() //! sets an image void CGUIImage::setImage(video::ITexture* image) { + if ( Texture == image ) + return; + if (Texture) Texture->drop(); @@ -68,6 +74,34 @@ void CGUIImage::draw() if (Texture) { + core::rect rectSource; + if ( SourceRect.getWidth() ) + rectSource = SourceRect; + else + rectSource = core::rect(core::position2d(0,0), Texture->getOriginalSize()); + + // reduce the clipping area + core::rect rectClipping(AbsoluteClippingRect); + f32 clipWidth = (f32)AbsoluteClippingRect.getWidth(); + f32 clipHeight = (f32)AbsoluteClippingRect.getHeight(); + if ( ShrinkClippingLeft > 0.f ) + { + rectClipping.UpperLeftCorner.X -= s32(0.01f*ShrinkClippingLeft*clipWidth); + } + if ( ShrinkClippingTop > 0.f ) + { + rectClipping.UpperLeftCorner.Y -= s32(0.01f*ShrinkClippingTop*clipHeight); + } + if ( ShrinkClippingRight > 0.f ) + { + rectClipping.LowerRightCorner.X -= s32(0.01f*ShrinkClippingRight*clipWidth); + } + if ( ShrinkClippingBottom > 0.f ) + { + rectClipping.LowerRightCorner.Y -= s32(0.01f*ShrinkClippingBottom*clipHeight); + } + rectClipping.repair(); + if (ScaleImage) { video::SColor Colors[4]; @@ -76,15 +110,14 @@ void CGUIImage::draw() Colors[2] = Color; Colors[3] = Color; - driver->draw2DImage(Texture, AbsoluteRect, - core::rect(core::position2d(0,0), Texture->getOriginalSize()), - &AbsoluteClippingRect, Colors, UseAlphaChannel); + driver->draw2DImage(Texture, AbsoluteRect, rectSource, + &rectClipping, Colors, UseAlphaChannel, RotationAngle); } else { driver->draw2DImage(Texture, AbsoluteRect.UpperLeftCorner, - core::rect(core::position2d(0,0), Texture->getOriginalSize()), - &AbsoluteClippingRect, Color, UseAlphaChannel); + rectSource, + &rectClipping, Color, UseAlphaChannel, RotationAngle); } } else @@ -146,8 +179,24 @@ void CGUIImage::deserializeAttributes(io setScaleImage(in->getAttributeAsBool("ScaleImage")); } +//! sets the image source rectangle in the texture +void CGUIImage::setSourceRect(core::rect sourceRect) +{ + SourceRect = sourceRect; +} +void CGUIImage::shrinkClippingArea(f32 left, f32 top, f32 right, f32 bottom) +{ + ShrinkClippingLeft = left; + ShrinkClippingTop = top; + ShrinkClippingRight = right; + ShrinkClippingBottom = bottom; +} +void CGUIImage::setRotationDegrees(f32 angleInDegree) +{ + RotationAngle = angleInDegree; +} } // end namespace gui } // end namespace irr diff -abBdpuNPr --exclude='*.svn' irrlicht-svn-ss/trunk/source/Irrlicht/CGUIImage.h Irrlicht_starsonata/source/Irrlicht/CGUIImage.h --- irrlicht-svn-ss/trunk/source/Irrlicht/CGUIImage.h 2007-07-26 02:11:08.000000000 +0200 +++ Irrlicht_starsonata/source/Irrlicht/CGUIImage.h 2008-05-24 04:01:02.000000000 +0200 @@ -49,13 +49,30 @@ namespace gui //! Reads attributes of the element virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options); + //! sets the image source rectangle in the texture + virtual void setSourceRect(core::rect sourceRect); + + // starsonata, micha + //! Reduce the area used for clipping the image + //! All values are relative in percent to total width (for left and right) and height (for top and bottom) + //! Example: To create a typical progressbar which slightly increases you will decrease the right clipping from 100 to 0. + virtual void shrinkClippingArea(f32 left, f32 top, f32 right, f32 bottom); + + // starsonata, micha + //! rotate image + virtual void setRotationDegrees(f32 angleInDegree); private: + core::rect SourceRect; video::SColor Color; video::ITexture* Texture; bool UseAlphaChannel; bool ScaleImage; - + f32 ShrinkClippingLeft; + f32 ShrinkClippingTop; + f32 ShrinkClippingRight; + f32 ShrinkClippingBottom; + f32 RotationAngle; };