Explorar el Código

Drop down box now properly closes when I click outside of it

Marko Pintera hace 12 años
padre
commit
32c5614a30
Se han modificado 2 ficheros con 18 adiciones y 6 borrados
  1. 1 0
      BansheeEngine/Include/BsGUIManager.h
  2. 17 6
      BansheeEngine/Source/BsGUIManager.cpp

+ 1 - 0
BansheeEngine/Include/BsGUIManager.h

@@ -103,6 +103,7 @@ namespace BansheeEngine
 		CM::Color mTextSelectionColor;
 		CM::Color mTextSelectionColor;
 
 
 		// Drop down box
 		// Drop down box
+		bool mDropDownBoxOpenScheduled;
 		bool mDropDownBoxActive;
 		bool mDropDownBoxActive;
 		CM::HSceneObject mDropDownSO;
 		CM::HSceneObject mDropDownSO;
 		CM::GameObjectHandle<GUIDropDownBox> mDropDownBox;
 		CM::GameObjectHandle<GUIDropDownBox> mDropDownBox;

+ 17 - 6
BansheeEngine/Source/BsGUIManager.cpp

@@ -53,7 +53,7 @@ namespace BansheeEngine
 		:mMouseOverElement(nullptr), mMouseOverWidget(nullptr), mSeparateMeshesByWidget(true), mActiveElement(nullptr), 
 		:mMouseOverElement(nullptr), mMouseOverWidget(nullptr), mSeparateMeshesByWidget(true), mActiveElement(nullptr), 
 		mActiveWidget(nullptr), mActiveMouseButton(GUIMouseButton::Left), mKeyboardFocusElement(nullptr), mKeyboardFocusWidget(nullptr),
 		mActiveWidget(nullptr), mActiveMouseButton(GUIMouseButton::Left), mKeyboardFocusElement(nullptr), mKeyboardFocusWidget(nullptr),
 		mCaretTexture(nullptr), mCaretBlinkInterval(0.5f), mCaretLastBlinkTime(0.0f), mCaretColor(1.0f, 0.6588f, 0.0f), mIsCaretOn(false),
 		mCaretTexture(nullptr), mCaretBlinkInterval(0.5f), mCaretLastBlinkTime(0.0f), mCaretColor(1.0f, 0.6588f, 0.0f), mIsCaretOn(false),
-		mTextSelectionColor(1.0f, 0.6588f, 0.0f), mInputCaret(nullptr), mInputSelection(nullptr), mDropDownBoxActive(false)
+		mTextSelectionColor(1.0f, 0.6588f, 0.0f), mInputCaret(nullptr), mInputSelection(nullptr), mDropDownBoxActive(false), mDropDownBoxOpenScheduled(false)
 	{
 	{
 		mOnButtonDownConn = gInput().onButtonDown.connect(boost::bind(&GUIManager::onButtonDown, this, _1));
 		mOnButtonDownConn = gInput().onButtonDown.connect(boost::bind(&GUIManager::onButtonDown, this, _1));
 		mOnButtonUpConn = gInput().onButtonUp.connect(boost::bind(&GUIManager::onButtonUp, this, _1));
 		mOnButtonUpConn = gInput().onButtonUp.connect(boost::bind(&GUIManager::onButtonUp, this, _1));
@@ -164,6 +164,14 @@ namespace BansheeEngine
 	{
 	{
 		DragAndDropManager::instance().update();
 		DragAndDropManager::instance().update();
 
 
+		// We only activate the drop down box the next frame so it isn't
+		// accidentally destroyed the same frame it was created
+		if(mDropDownBoxOpenScheduled)
+		{
+			mDropDownBoxActive = true;
+			mDropDownBoxOpenScheduled = false;
+		}
+
 		// Update layouts
 		// Update layouts
 		for(auto& widgetInfo : mWidgets)
 		for(auto& widgetInfo : mWidgets)
 		{
 		{
@@ -497,6 +505,9 @@ namespace BansheeEngine
 	void GUIManager::openDropDownBox(GUIDropDownList* parentList, const CM::Vector<WString>::type& elements, 
 	void GUIManager::openDropDownBox(GUIDropDownList* parentList, const CM::Vector<WString>::type& elements, 
 		std::function<void(CM::UINT32)> selectedCallback)
 		std::function<void(CM::UINT32)> selectedCallback)
 	{
 	{
+		if(mDropDownBoxOpenScheduled || mDropDownBoxActive)
+			closeDropDownBox(-1);
+
 		mDropDownSO = SceneObject::create("DropDownBox");
 		mDropDownSO = SceneObject::create("DropDownBox");
 		mDropDownBox = mDropDownSO->addComponent<GUIDropDownBox>();
 		mDropDownBox = mDropDownSO->addComponent<GUIDropDownBox>();
 
 
@@ -504,7 +515,7 @@ namespace BansheeEngine
 		mDropDownBox->initialize(widget.getTarget(), widget.getOwnerWindow(), parentList, elements, 
 		mDropDownBox->initialize(widget.getTarget(), widget.getOwnerWindow(), parentList, elements, 
 			boost::bind(&GUIManager::closeDropDownBox, this, _1));
 			boost::bind(&GUIManager::closeDropDownBox, this, _1));
 
 
-		mDropDownBoxActive = true;
+		mDropDownBoxOpenScheduled = true;
 		mDropDownSelectionMade = selectedCallback;
 		mDropDownSelectionMade = selectedCallback;
 	}
 	}
 
 
@@ -623,10 +634,10 @@ namespace BansheeEngine
 			// Close drop down box if user clicks outside the drop down box
 			// Close drop down box if user clicks outside the drop down box
 			if(mDropDownBoxActive)
 			if(mDropDownBoxActive)
 			{
 			{
-				//if(mMouseOverElement == nullptr || (&mMouseOverElement->_getParentWidget() != mDropDownBox.get()))
-				//{
-				//	closeDropDownBox(-1);
-				//}
+				if(mMouseOverElement == nullptr || (&mMouseOverElement->_getParentWidget() != mDropDownBox.get()))
+				{
+					closeDropDownBox(-1);
+				}
 			}
 			}
 		}
 		}
 	}
 	}