Răsfoiți Sursa

Context menu now receives proper mouse coordinates
Fixed an issue with upwards opening drop down box where y offset wasn't correct

Marko Pintera 12 ani în urmă
părinte
comite
ab0ac7047c

+ 1 - 0
BansheeEngine/Include/BsGUIDropDownBox.h

@@ -116,6 +116,7 @@ namespace BansheeEngine
 			CM::INT32 x, y;
 			CM::UINT32 width, height;
 			CM::Rect mAvailableBounds;
+			bool mOpenedUpward;
 
 			CM::Vector<GUITexture*>::type mCachedSeparators;
 			CM::Vector<GUIButton*>::type mCachedEntryBtns;

+ 19 - 6
BansheeEngine/Source/BsGUIDropDownBox.cpp

@@ -117,7 +117,7 @@ namespace BansheeEngine
 		const Rect& availableBounds, const CM::Vector<GUIDropDownData>::type& elements, GUIDropDownType type)
 		:mOwner(owner), mPage(0), mBackgroundFrame(nullptr), mBackgroundArea(nullptr), mContentArea(nullptr), 
 		mContentLayout(nullptr), mScrollUpBtn(nullptr), mScrollDownBtn(nullptr), x(0), y(0), width(0), height(0), 
-		mType(type), mSubMenu(nullptr), mElements(elements)
+		mType(type), mSubMenu(nullptr), mElements(elements), mOpenedUpward(false)
 	{
 		mAvailableBounds = availableBounds;
 
@@ -184,6 +184,7 @@ namespace BansheeEngine
 		{
 			y = potentialBottomStart;
 			height = availableDownwardHeight;
+			mOpenedUpward = false;
 		}
 		else
 		{
@@ -191,20 +192,27 @@ namespace BansheeEngine
 			{
 				y = potentialBottomStart;
 				height = availableDownwardHeight;
+				mOpenedUpward = false;
 			}
 			else
 			{
-				y = potentialTopStart - std::min(maxNeededHeight, availableUpwardHeight);
+				y = potentialTopStart;
 				height = availableUpwardHeight;
+				mOpenedUpward = true;
 			}
 		}
 
+		INT32 actualY = y;
+			
+		if(mOpenedUpward)	
+			actualY -= (INT32)std::min(maxNeededHeight, availableUpwardHeight);
+
 		// Content area
-		mContentArea = GUIArea::create(*mOwner, x, y, width, height);
+		mContentArea = GUIArea::create(*mOwner, x, actualY, width, height);
 		mContentLayout = &mContentArea->getLayout().addLayoutY();
 
 		// Background frame
-		mBackgroundArea = GUIArea::create(*mOwner, x, y, width, height);
+		mBackgroundArea = GUIArea::create(*mOwner, x, actualY, width, height);
 		mBackgroundArea->setDepth(102);
 
 		mBackgroundFrame = GUITexture::create(*mOwner, GUIImageScaleMode::StretchToFit, mOwner->mBackgroundStyle);
@@ -403,13 +411,18 @@ namespace BansheeEngine
 		}
 		
 		// Resize and reposition areas
+		INT32 actualY = y;
+
+		if(mOpenedUpward)	
+			actualY -= (INT32)usedHeight;
+
 		mBackgroundArea->setSize(width, usedHeight);
-		mBackgroundArea->setPosition(x, y);
+		mBackgroundArea->setPosition(x, actualY);
 
 		UINT32 contentWidth = (UINT32)std::max(0, (INT32)width - (INT32)mOwner->mBackgroundStyle->margins.left - (INT32)mOwner->mBackgroundStyle->margins.right);
 		UINT32 contentHeight = (UINT32)std::max(0, (INT32)usedHeight - (INT32)mOwner->mBackgroundStyle->margins.top - (INT32)mOwner->mBackgroundStyle->margins.bottom);
 		mContentArea->setSize(contentWidth, contentHeight);
-		mContentArea->setPosition(x + mOwner->mBackgroundStyle->margins.left, y + mOwner->mBackgroundStyle->margins.top);
+		mContentArea->setPosition(x + mOwner->mBackgroundStyle->margins.left, actualY + mOwner->mBackgroundStyle->margins.top);
 	}
 
 	UINT32 GUIDropDownBox::DropDownSubMenu::getElementHeight(CM::UINT32 idx) const

+ 4 - 1
BansheeEngine/Source/BsGUIManager.cpp

@@ -617,7 +617,10 @@ namespace BansheeEngine
 
 				if(menu != nullptr)
 				{
-					menu->open(gInput().getMousePosition(), *mMouseOverWidget);
+					const RenderWindow* window = mMouseOverWidget->getOwnerWindow();
+					Int2 windowPos = window->screenToWindowPos(gInput().getMousePosition());
+
+					menu->open(windowPos, *mMouseOverWidget);
 					event.markAsUsed();
 				}
 			}

+ 1 - 1
DropDown.txt

@@ -1,9 +1,9 @@
 GUI ignores image in GUIContent for most elements.
 
 Context menu appears at the wrong coordinates
-Menus lack proper frame
 
 Test scrollUp/scrollDown
+ - Scroll up/down button arrows seem to be missing
 
 Design improvements:
 Attempt to get rid of selective input click callback in GUIManager. It's too specific.