diff --git a/source/Irrlicht/CGUIContextMenu.cpp b/source/Irrlicht/CGUIContextMenu.cpp index f35295d4..417330a2 100644 --- a/source/Irrlicht/CGUIContextMenu.cpp +++ b/source/Irrlicht/CGUIContextMenu.cpp @@ -673,19 +673,22 @@ void CGUIContextMenu::recalculateSize() if ( root ) { core::rect rectRoot( root->getAbsolutePosition() ); + core::rect absRect( getAbsolutePosition() ); - // if it would be drawn beyond the right border, then add it to the left side - if ( getAbsolutePosition().UpperLeftCorner.X+subRect.LowerRightCorner.X > rectRoot.LowerRightCorner.X ) + // if it would be drawn beyond the right border, then add it to the left side - if there is more space + irr::s32 beyondRight = absRect.UpperLeftCorner.X+subRect.LowerRightCorner.X-rectRoot.LowerRightCorner.X; + irr::s32 beyondLeft = -(absRect.UpperLeftCorner.X - w - rectRoot.UpperLeftCorner.X); + if ( beyondRight > 0 && beyondRight > beyondLeft ) { subRect.UpperLeftCorner.X = -w; subRect.LowerRightCorner.X = 0; } // if it would be drawn below bottom border, move it up, but not further than to top. - irr::s32 belowBottom = getAbsolutePosition().UpperLeftCorner.Y+subRect.LowerRightCorner.Y - rectRoot.LowerRightCorner.Y; + irr::s32 belowBottom = absRect.UpperLeftCorner.Y+subRect.LowerRightCorner.Y - rectRoot.LowerRightCorner.Y; if ( belowBottom > 0 ) { - irr::s32 belowTop = getAbsolutePosition().UpperLeftCorner.Y+subRect.UpperLeftCorner.Y; + irr::s32 belowTop = absRect.UpperLeftCorner.Y+subRect.UpperLeftCorner.Y; irr::s32 moveUp = belowBottom < belowTop ? belowBottom : belowTop; subRect.UpperLeftCorner.Y -= moveUp; subRect.LowerRightCorner.Y -= moveUp;