Browse Source

Added a way to open menu bar menu in GUIManager

Marko Pintera 12 years ago
parent
commit
9d8c22a9cc

+ 3 - 2
BansheeEngine/Include/BsGUIManager.h

@@ -48,9 +48,11 @@ namespace BansheeEngine
 		void update();
 		void update();
 		void render(CM::ViewportPtr& target, CM::RenderQueue& renderQueue) const;
 		void render(CM::ViewportPtr& target, CM::RenderQueue& renderQueue) const;
 
 
-		void openDropDownListBox(GUIListBox* parentList, const CM::Vector<CM::WString>::type& elements, 
+		void openDropDownListBox(const GUIListBox* parentList, const CM::Vector<CM::WString>::type& elements, 
 			std::function<void(CM::UINT32)> selectedCallback, const GUISkin& skin);
 			std::function<void(CM::UINT32)> selectedCallback, const GUISkin& skin);
 
 
+		void openMenuBarMenu(GUIButton* parentButton, const GUIMenu* menu);
+
 		void queueForDestroy(GUIElement* element);
 		void queueForDestroy(GUIElement* element);
 
 
 		void setCaretColor(const CM::Color& color) { mCaretColor = color; updateCaretTexture(); }
 		void setCaretColor(const CM::Color& color) { mCaretColor = color; updateCaretTexture(); }
@@ -144,7 +146,6 @@ namespace BansheeEngine
 		bool handleMouseOver(GUIWidget* widget, GUIElement* element, const CM::Int2& screenMousePos, float wheelScrollAmount = 0.0f);
 		bool handleMouseOver(GUIWidget* widget, GUIElement* element, const CM::Int2& screenMousePos, float wheelScrollAmount = 0.0f);
 
 
 		void openContextMenu(const GUIContextMenu* menu, const CM::Int2& position, GUIWidget& widget);
 		void openContextMenu(const GUIContextMenu* menu, const CM::Int2& position, GUIWidget& widget);
-		void closeContextMenu();
 
 
 		void closeDropDownListBox(CM::INT32 selectedIdx);
 		void closeDropDownListBox(CM::INT32 selectedIdx);
 		void closeDropDownBox();
 		void closeDropDownBox();

+ 2 - 0
BansheeEngine/Include/BsGUIMenuBar.h

@@ -41,5 +41,7 @@ namespace BansheeEngine
 		 * @return	False if first element doesn't exist, true otherwise.
 		 * @return	False if first element doesn't exist, true otherwise.
 		 */
 		 */
 		bool stripPath(CM::WString& path, CM::WString& pathRoot) const;
 		bool stripPath(CM::WString& path, CM::WString& pathRoot) const;
+
+		void openSubMenu(const CM::WString& name);
 	};
 	};
 }
 }

+ 19 - 6
BansheeEngine/Source/BsGUIManager.cpp

@@ -21,6 +21,7 @@
 #include "BsGUIInputCaret.h"
 #include "BsGUIInputCaret.h"
 #include "BsGUIInputSelection.h"
 #include "BsGUIInputSelection.h"
 #include "BsGUIListBox.h"
 #include "BsGUIListBox.h"
+#include "BsGUIButton.h"
 #include "BsGUIDropDownBox.h"
 #include "BsGUIDropDownBox.h"
 #include "BsGUIContextMenu.h"
 #include "BsGUIContextMenu.h"
 #include "BsDragAndDropManager.h"
 #include "BsDragAndDropManager.h"
@@ -503,7 +504,7 @@ namespace BansheeEngine
 		}
 		}
 	}
 	}
 
 
-	void GUIManager::openDropDownListBox(GUIListBox* parentList, const CM::Vector<WString>::type& elements, 
+	void GUIManager::openDropDownListBox(const GUIListBox* parentList, const CM::Vector<WString>::type& elements, 
 		std::function<void(CM::UINT32)> selectedCallback, const GUISkin& skin)
 		std::function<void(CM::UINT32)> selectedCallback, const GUISkin& skin)
 	{
 	{
 		if(mDropDownBoxOpenScheduled || mDropDownBoxActive)
 		if(mDropDownBoxOpenScheduled || mDropDownBoxActive)
@@ -544,25 +545,37 @@ namespace BansheeEngine
 		mDropDownBoxActive = false;
 		mDropDownBoxActive = false;
 	}
 	}
 
 
-	void GUIManager::openContextMenu(const GUIContextMenu* menu, const Int2& position, GUIWidget& widget)
+	void GUIManager::openMenuBarMenu(GUIButton* parentButton, const GUIMenu* menu)
 	{
 	{
 		if(mDropDownBoxOpenScheduled || mDropDownBoxActive)
 		if(mDropDownBoxOpenScheduled || mDropDownBoxActive)
-			closeContextMenu();
+			closeDropDownBox();
 
 
 		mDropDownSO = SceneObject::create("DropDownBox");
 		mDropDownSO = SceneObject::create("DropDownBox");
 		mDropDownBox = mDropDownSO->addComponent<GUIDropDownBox>();
 		mDropDownBox = mDropDownSO->addComponent<GUIDropDownBox>();
 
 
 		Vector<GUIDropDownData>::type dropDownData = menu->getDropDownData();
 		Vector<GUIDropDownData>::type dropDownData = menu->getDropDownData();
+		GUIWidget& widget = parentButton->_getParentWidget();
 
 
 		mDropDownBox->initialize(widget.getTarget(), widget.getOwnerWindow(), 
 		mDropDownBox->initialize(widget.getTarget(), widget.getOwnerWindow(), 
-			GUIDropDownAreaPlacement::aroundPosition(position), dropDownData, widget.getSkin(), GUIDropDownType::ContextMenu);
+			GUIDropDownAreaPlacement::aroundBoundsVert(parentButton->getBounds()), dropDownData, widget.getSkin(), GUIDropDownType::MenuBar);
 
 
 		mDropDownBoxOpenScheduled = true;
 		mDropDownBoxOpenScheduled = true;
 	}
 	}
 
 
-	void GUIManager::closeContextMenu()
+	void GUIManager::openContextMenu(const GUIContextMenu* menu, const Int2& position, GUIWidget& widget)
 	{
 	{
-		closeDropDownBox();
+		if(mDropDownBoxOpenScheduled || mDropDownBoxActive)
+			closeDropDownBox();
+
+		mDropDownSO = SceneObject::create("DropDownBox");
+		mDropDownBox = mDropDownSO->addComponent<GUIDropDownBox>();
+
+		Vector<GUIDropDownData>::type dropDownData = menu->getDropDownData();
+
+		mDropDownBox->initialize(widget.getTarget(), widget.getOwnerWindow(), 
+			GUIDropDownAreaPlacement::aroundPosition(position), dropDownData, widget.getSkin(), GUIDropDownType::ContextMenu);
+
+		mDropDownBoxOpenScheduled = true;
 	}
 	}
 
 
 	void GUIManager::updateCaretTexture()
 	void GUIManager::updateCaretTexture()

+ 1 - 1
BansheeEngine/Source/BsGUIMenu.cpp

@@ -168,7 +168,7 @@ namespace BansheeEngine
 				}
 				}
 				else
 				else
 				{
 				{
-					dropDownData.push_back(GUIDropDownData::subMenu(menuItem->getName(), getDropDownData(*menuItem)));
+					dropDownData.push_back(GUIDropDownData::subMenu(menuItem->getName(), getDropDownDataInternal(*menuItem)));
 				}
 				}
 			}
 			}
 		}
 		}

+ 11 - 0
BansheeEngine/Source/BsGUIMenuBar.cpp

@@ -4,6 +4,7 @@
 #include "BsGUIButton.h"
 #include "BsGUIButton.h"
 #include "BsGUILayout.h"
 #include "BsGUILayout.h"
 #include "BsGUIMenu.h"
 #include "BsGUIMenu.h"
+#include "BsGUIManager.h"
 
 
 using namespace CamelotFramework;
 using namespace CamelotFramework;
 
 
@@ -86,6 +87,7 @@ namespace BansheeEngine
 			newSubMenu.menu = cm_new<GUIMenu>();
 			newSubMenu.menu = cm_new<GUIMenu>();
 
 
 			GUIButton* newButton = GUIButton::create(*mParentWidget, rootName);
 			GUIButton* newButton = GUIButton::create(*mParentWidget, rootName);
+			newButton->onClick.connect(boost::bind(&GUIMenuBar::openSubMenu, this, rootName));
 			mMainArea->getLayout().addElement(newButton);
 			mMainArea->getLayout().addElement(newButton);
 
 
 			newSubMenu.button = newButton;
 			newSubMenu.button = newButton;
@@ -155,4 +157,13 @@ namespace BansheeEngine
 
 
 		return true;
 		return true;
 	}
 	}
+
+	void GUIMenuBar::openSubMenu(const CM::WString& name)
+	{
+		const GUIMenuBarData* subMenu = getSubMenu(name);
+		if(subMenu == nullptr)
+			return;
+
+		GUIManager::instance().openMenuBarMenu(subMenu->button, subMenu->menu);
+	}
 }
 }