From 76b921b2c6a095244bafd34d203fbf47d45dfcc2 Mon Sep 17 00:00:00 2001 From: cutealien Date: Sun, 15 Nov 2009 09:07:09 +0000 Subject: [PATCH] Draw sub-menues to the left side fi they would be outside main-window otherwise. git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@2866 dfc29bdd-3216-0410-991c-e03cc46cb475 --- source/Irrlicht/CGUIContextMenu.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/source/Irrlicht/CGUIContextMenu.cpp b/source/Irrlicht/CGUIContextMenu.cpp index 37812452..935fff4d 100644 --- a/source/Irrlicht/CGUIContextMenu.cpp +++ b/source/Irrlicht/CGUIContextMenu.cpp @@ -651,9 +651,21 @@ void CGUIContextMenu::recalculateSize() const s32 w = Items[i].SubMenu->getAbsolutePosition().getWidth(); const s32 h = Items[i].SubMenu->getAbsolutePosition().getHeight(); - Items[i].SubMenu->setRelativePosition( - core::rect(width-5, Items[i].PosY, - width+w-5, Items[i].PosY+h)); + core::rect subRect(width-5, Items[i].PosY, width+w-5, Items[i].PosY+h); + + // if it would be drawn beyond the right border, then add it to the left side + gui::IGUIElement * root = Environment->getRootGUIElement(); + if ( root ) + { + core::rect rectRoot( root->getAbsolutePosition() ); + if ( getAbsolutePosition().UpperLeftCorner.X+subRect.LowerRightCorner.X > rectRoot.LowerRightCorner.X ) + { + subRect.UpperLeftCorner.X = -w; + subRect.LowerRightCorner.X = 0; + } + } + + Items[i].SubMenu->setRelativePosition(subRect); } } }