From e55af78b31fe74614533a925ca6c76afbb55b62c Mon Sep 17 00:00:00 2001 From: cutealien Date: Tue, 25 Apr 2023 13:14:52 +0000 Subject: [PATCH] No longer move context sub-menu to left if there's even less space there Probably still moving too often to the left - should find some better solution. But at least some improvement. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6471 dfc29bdd-3216-0410-991c-e03cc46cb475 --- source/Irrlicht/CGUIContextMenu.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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;