diff -abBdpuNPr --exclude='*.svn' irrlicht-svn-ss/trunk/include/IGUIElement.h Irrlicht_starsonata/include/IGUIElement.h --- irrlicht-svn-ss/trunk/include/IGUIElement.h 2007-07-26 02:11:22.000000000 +0200 +++ Irrlicht_starsonata/include/IGUIElement.h 2008-07-25 16:36:24.000000000 +0200 @@ -446,6 +443,83 @@ public: setRelativePosition(DesiredRect + absoluteMovement); } + // starsonata, micha + //! Try to move the element as good as possible inside the given absolute coordinates. + //! When it does not fit inside try to align it as good as possible + virtual void moveInside(const core::rect& absRect, EGUI_ALIGNMENT align_=EGUIA_CENTER) + { + core::rect desired(AbsoluteRect); + if (! desired.constrainTo(absRect) ) + { + switch ( align_ ) + { + case EGUIA_UPPERLEFT: + { + core::position2d out; + if ( desired.UpperLeftCorner.X < absRect.UpperLeftCorner.X ) + { + out.X = desired.UpperLeftCorner.X - absRect.UpperLeftCorner.X; + } + if ( desired.UpperLeftCorner.Y < absRect.UpperLeftCorner.Y ) + { + out.Y = desired.UpperLeftCorner.Y - absRect.UpperLeftCorner.Y; + } + desired -= out; + } + break; + case EGUIA_LOWERRIGHT: + { + core::position2d out; + if ( desired.LowerRightCorner.X > absRect.LowerRightCorner.X ) + { + out.X = desired.LowerRightCorner.X - absRect.LowerRightCorner.X; + } + if ( desired.LowerRightCorner.Y > absRect.LowerRightCorner.Y ) + { + out.Y = desired.LowerRightCorner.Y - absRect.LowerRightCorner.Y; + } + desired -= out; + } + break; + case EGUIA_CENTER: + { + core::position2d toMove; + core::position2d centerDesired( desired.getCenter() ); + core::position2d centerAbs( absRect.getCenter() ); + + if ( desired.getWidth() > absRect.getWidth() ) + toMove.X = centerAbs.X - centerDesired.X; + else if ( desired.UpperLeftCorner.X < absRect.UpperLeftCorner.X ) + toMove.X = absRect.UpperLeftCorner.X - desired.UpperLeftCorner.X; + else if ( desired.LowerRightCorner.X > absRect.LowerRightCorner.X ) + toMove.X = absRect.LowerRightCorner.X - desired.LowerRightCorner.X; + + if ( desired.getHeight() > absRect.getHeight() ) + toMove.Y = centerAbs.Y - centerDesired.Y; + else if ( desired.UpperLeftCorner.Y < absRect.UpperLeftCorner.Y ) + toMove.Y = absRect.UpperLeftCorner.Y - desired.UpperLeftCorner.Y; + else if ( desired.LowerRightCorner.Y > absRect.LowerRightCorner.Y ) + toMove.Y = absRect.LowerRightCorner.Y - desired.LowerRightCorner.Y; + + desired += toMove; + } + break; + case EGUIA_SCALE: + { + f32 scaleX = desired.getWidth() ? (f32)absRect.getWidth() / (f32)desired.getWidth() : 0; + f32 scaleY = desired.getHeight() ? (f32)absRect.getHeight() / (f32)desired.getHeight() : 0; + f32 smallerScale = scaleX > scaleY ? scaleX : scaleY; + desired.LowerRightCorner.X = desired.UpperLeftCorner.X + (s32)(desired.getWidth() * smallerScale); + desired.LowerRightCorner.Y = desired.UpperLeftCorner.Y + (s32)(desired.getHeight() * smallerScale); + moveInside(absRect, EGUIA_CENTER); + return; + } + break; + } + } + + move( desired.UpperLeftCorner-AbsoluteRect.UpperLeftCorner ); + } //! Returns true if element is visible. virtual bool isVisible()