Kaynağa Gözat

Added functionality for adding toolbar items in GUIMenuBar (untested)

BearishSun 10 yıl önce
ebeveyn
işleme
e80f411c86

+ 6 - 0
BansheeEditor/Include/BsBuiltinEditorResources.h

@@ -327,6 +327,12 @@ namespace BansheeEngine
 		static const WString MenuBarLineNormalTex;
 		static const WString MenuBarLineNormalTex;
 		static const WString MenuBarLineActiveTex;
 		static const WString MenuBarLineActiveTex;
 
 
+		static const WString ToolBarBtnNormalTex;
+		static const WString ToolBarBtnHoverTex;
+		static const WString ToolBarBtnActiveTex;
+
+		static const WString ToolBarSeparatorTex;
+
 		static const WString DockSliderNormalTex;
 		static const WString DockSliderNormalTex;
 
 
 		static const WString TreeViewExpandButtonOffNormal;
 		static const WString TreeViewExpandButtonOffNormal;

+ 57 - 5
BansheeEditor/Include/BsGUIMenuBar.h

@@ -6,9 +6,10 @@
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
 	/**
 	/**
-	 * @brief	A menu bar GUI element that contains a horizontal list of elements
-	 *			that can each be expanded into a hierarchical sub-menus. Contents
-	 *			of the menu bar are customizable once created.
+	 * @brief	A menu bar GUI element that contains a horizontal list of elements that can each be expanded into a 
+	 * 			hierarchical sub-menus, as well as a list of tool bar buttons.
+	 * 			
+	 *			Contents of the menu and tool bar are customizable.
 	 *
 	 *
 	 *			The menu bar also displays the minimize, maximize and close buttons for the window.
 	 *			The menu bar also displays the minimize, maximize and close buttons for the window.
 	 */
 	 */
@@ -25,6 +26,18 @@ namespace BansheeEngine
 			GUIFixedSpace* space;
 			GUIFixedSpace* space;
 		};
 		};
 
 
+		/**
+		 * @brief	Contains data about a single tool bar element.
+		 */
+		struct GUIToolBarData
+		{
+			String name;
+			INT32 priority;
+			GUIButton* button;
+			GUITexture* separator;
+			GUIFixedSpace* space;
+		};
+
 	public:
 	public:
 		/**
 		/**
 		 * @brief	Returns the style type for the menu bar background.
 		 * @brief	Returns the style type for the menu bar background.
@@ -46,6 +59,16 @@ namespace BansheeEngine
 		 */
 		 */
 		static const String& getMenuItemButtonStyleType();
 		static const String& getMenuItemButtonStyleType();
 
 
+		/**
+		 * @brief	Returns the style type for tool bar buttons.
+		 */
+		static const String& getToolBarButtonStyleType();
+
+		/**
+		 * @brief	Returns the style type for the tool bar button separator.
+		 */
+		static const String& getToolBarSeparatorStyleType();
+
 		/**
 		/**
 		 * @brief	Constructs a new menu bar.
 		 * @brief	Constructs a new menu bar.
 		 *
 		 *
@@ -79,13 +102,13 @@ namespace BansheeEngine
 		const GUIMenuItem* addMenuItem(const WString& path, std::function<void()> callback, INT32 priority = 0, const ShortcutKey& shortcut = ShortcutKey::NONE);
 		const GUIMenuItem* addMenuItem(const WString& path, std::function<void()> callback, INT32 priority = 0, const ShortcutKey& shortcut = ShortcutKey::NONE);
 
 
 		/**
 		/**
-		 * @brief	Adds a separator element at the specified path. The separator is added as a child of the path.
+		 * @brief	Adds a menu item separator element at the specified path. The separator is added as a child of the path.
 		 *
 		 *
 		 * @param	path		Parent path of the sub-menu to add the separator.
 		 * @param	path		Parent path of the sub-menu to add the separator.
 		 * @param	priority	Determines where is the separator positioned compared to other elements in the same sub-menu.
 		 * @param	priority	Determines where is the separator positioned compared to other elements in the same sub-menu.
 		 *						Higher priority elements get placed higher up in the sub-menu.
 		 *						Higher priority elements get placed higher up in the sub-menu.
 		 */
 		 */
-		const GUIMenuItem* addSeparator(const WString& path, INT32 priority = 0);
+		const GUIMenuItem* addMenuItemSeparator(const WString& path, INT32 priority = 0);
 
 
 		/**
 		/**
 		 * @brief	Returns an existing menu item at the specified path, or null if one cannot be found.
 		 * @brief	Returns an existing menu item at the specified path, or null if one cannot be found.
@@ -96,6 +119,33 @@ namespace BansheeEngine
 		 * @brief	Removes a menu item from the specified path. If this path points to a sub-menu entire sub-menu will be removed.
 		 * @brief	Removes a menu item from the specified path. If this path points to a sub-menu entire sub-menu will be removed.
 		 */
 		 */
 		void removeMenuItem(const WString& path);
 		void removeMenuItem(const WString& path);
+
+		/**
+		 * @brief	Adds a new button to the tool bar.
+		 *
+		 * @param	name		Unique name of the button that you may use for identifiying it.
+		 * @param	content 	Content to display on the button.
+		 * @param	callback	Callback to trigger when the button is pressed.
+		 * @param	priority	Determines where is the button positioned compared to other elements on the tool bar.
+		 * 						Higher priority elements get placed before lower priority ones.
+		 */
+		void addToolBarButton(const String& name, const GUIContent& content, std::function<void()> callback, INT32 priority = 0);
+
+		/**
+		 * @brief	Adds a new separator element to the tool bar.
+		 *
+		 * @param	name		Unique name of the separator that you may use for identifiying it.
+		 * @param	priority	Determines where is the separator positioned compared to other elements on the tool bar.
+		 * 						Higher priority elements get placed before lower priority ones.
+		 */
+		void addToolBarSeparator(const String& name, INT32 priority = 0);
+
+		/**
+		 * @brief	Removes an element from the tool bar.
+		 *
+		 * @param	name	Unique name of the element to remove.
+		 */
+		void removeToolBarButton(const String& name);
 	private:
 	private:
 		/**
 		/**
 		 * @brief	Finds a top level sub-menu with the specified name.
 		 * @brief	Finds a top level sub-menu with the specified name.
@@ -199,6 +249,7 @@ namespace BansheeEngine
 		GUIPanel* mMainPanel;
 		GUIPanel* mMainPanel;
 		GUIPanel* mBgPanel;
 		GUIPanel* mBgPanel;
 		GUILayout* mMenuItemLayout;
 		GUILayout* mMenuItemLayout;
+		GUILayout* mToolBarLayout;
 		GUITexture* mBgTexture;
 		GUITexture* mBgTexture;
 		GUITexture* mLogoTexture;
 		GUITexture* mLogoTexture;
 		GUITexture* mSplitterLine;
 		GUITexture* mSplitterLine;
@@ -210,6 +261,7 @@ namespace BansheeEngine
 
 
 		Vector<GUIMenuBarData> mChildMenus;
 		Vector<GUIMenuBarData> mChildMenus;
 		UnorderedMap<WString, ShortcutKey> mEntryShortcuts;
 		UnorderedMap<WString, ShortcutKey> mEntryShortcuts;
+		Vector<GUIToolBarData> mToolbarElements;
 
 
 		GUIButton* mSubMenuButton;
 		GUIButton* mSubMenuButton;
 		bool mSubMenuOpen;
 		bool mSubMenuOpen;

+ 31 - 1
BansheeEditor/Source/BsBuiltinEditorResources.cpp

@@ -219,6 +219,12 @@ namespace BansheeEngine
 	const WString BuiltinEditorResources::MenuBarLineNormalTex = L"MenuBarLineNormal.png";
 	const WString BuiltinEditorResources::MenuBarLineNormalTex = L"MenuBarLineNormal.png";
 	const WString BuiltinEditorResources::MenuBarLineActiveTex = L"MenuBarLineActive.png";
 	const WString BuiltinEditorResources::MenuBarLineActiveTex = L"MenuBarLineActive.png";
 
 
+	const WString BuiltinEditorResources::ToolBarBtnNormalTex = L"ToolBarButtonNormal.png";
+	const WString BuiltinEditorResources::ToolBarBtnHoverTex = L"ToolBarButtonNormal.png";
+	const WString BuiltinEditorResources::ToolBarBtnActiveTex = L"ToolBarButtonNormal.png";
+
+	const WString BuiltinEditorResources::ToolBarSeparatorTex = L"ToolBarSeparator.png";
+
 	const WString BuiltinEditorResources::DockSliderNormalTex = L"DockSliderNormal.png";
 	const WString BuiltinEditorResources::DockSliderNormalTex = L"DockSliderNormal.png";
 
 
 	const WString BuiltinEditorResources::TreeViewExpandButtonOffNormal = L"TreeViewExpandButtonOffNormal.psd";
 	const WString BuiltinEditorResources::TreeViewExpandButtonOffNormal = L"TreeViewExpandButtonOffNormal.psd";
@@ -970,7 +976,7 @@ namespace BansheeEngine
 		// MenuBar separator line
 		// MenuBar separator line
 		GUIElementStyle menuBarLineStyle;
 		GUIElementStyle menuBarLineStyle;
 		menuBarLineStyle.normal.texture = getGUITexture(MenuBarLineNormalTex);
 		menuBarLineStyle.normal.texture = getGUITexture(MenuBarLineNormalTex);
-		menuBarLineStyle.normalOn.texture = getGUITexture(MenuBarBtnActiveTex);
+		menuBarLineStyle.normalOn.texture = getGUITexture(MenuBarLineActiveTex);
 		menuBarLineStyle.fixedHeight = true;
 		menuBarLineStyle.fixedHeight = true;
 		menuBarLineStyle.height = 1;
 		menuBarLineStyle.height = 1;
 
 
@@ -1015,6 +1021,30 @@ namespace BansheeEngine
 
 
 		skin->setStyle(GUIMenuBar::getMenuItemButtonStyleType(), menuBarBtnStyle);
 		skin->setStyle(GUIMenuBar::getMenuItemButtonStyleType(), menuBarBtnStyle);
 
 
+		// ToolBar separator
+		GUIElementStyle toolBarSeparator;
+		toolBarSeparator.normal.texture = getGUITexture(ToolBarSeparatorTex);
+		toolBarSeparator.fixedWidth = true;
+		toolBarSeparator.width = 3;
+		toolBarSeparator.height = 30;
+
+		skin->setStyle(GUIMenuBar::getToolBarSeparatorStyleType(), toolBarSeparator);
+
+		// ToolBar button
+		GUIElementStyle toolBarBtnStyle;
+		toolBarBtnStyle.normal.texture = getGUITexture(ToolBarBtnNormalTex);
+		toolBarBtnStyle.hover.texture = getGUITexture(ToolBarBtnHoverTex);
+		toolBarBtnStyle.active.texture = getGUITexture(ToolBarBtnActiveTex);
+		toolBarBtnStyle.normal.textColor = TextNormalColor;
+		toolBarBtnStyle.hover.textColor = TextNormalColor;
+		toolBarBtnStyle.active.textColor = TextActiveColor;
+		toolBarBtnStyle.fixedHeight = true;
+		toolBarBtnStyle.fixedWidth = true;
+		toolBarBtnStyle.height = 30;
+		toolBarBtnStyle.width = 30;
+
+		skin->setStyle(GUIMenuBar::getToolBarButtonStyleType(), toolBarBtnStyle);
+
 		/************************************************************************/
 		/************************************************************************/
 		/* 								DOCK SLIDER	                     		*/
 		/* 								DOCK SLIDER	                     		*/
 		/************************************************************************/
 		/************************************************************************/

+ 112 - 2
BansheeEditor/Source/BsGUIMenuBar.cpp

@@ -45,6 +45,18 @@ namespace BansheeEngine
 		return type;
 		return type;
 	}
 	}
 
 
+	const String& GUIMenuBar::getToolBarButtonStyleType()
+	{
+		static const String type = "ToolBarBtn";
+		return type;
+	}
+
+	const String& GUIMenuBar::getToolBarSeparatorStyleType()
+	{
+		static const String type = "ToolBarSeparator";
+		return type;
+	}
+
 	GUIMenuBar::GUIMenuBar(CGUIWidget* parent, RenderWindow* parentWindow)
 	GUIMenuBar::GUIMenuBar(CGUIWidget* parent, RenderWindow* parentWindow)
 		:mParentWidget(parent), mParentWindow(parentWindow), mMainPanel(nullptr), mMenuItemLayout(nullptr),
 		:mParentWidget(parent), mParentWindow(parentWindow), mMainPanel(nullptr), mMenuItemLayout(nullptr),
 		mBgTexture(nullptr), mLogoTexture(nullptr), mSubMenuOpen(false), mSubMenuButton(nullptr), mBgPanel(nullptr)
 		mBgTexture(nullptr), mLogoTexture(nullptr), mSubMenuOpen(false), mSubMenuButton(nullptr), mBgPanel(nullptr)
@@ -84,7 +96,7 @@ namespace BansheeEngine
 		GUILayout* mainLayoutVert = mainLayout->addNewElement<GUILayoutY>();
 		GUILayout* mainLayoutVert = mainLayout->addNewElement<GUILayoutY>();
 		mMenuItemLayout = mainLayoutVert->addNewElement<GUILayoutX>();
 		mMenuItemLayout = mainLayoutVert->addNewElement<GUILayoutX>();
 		mainLayoutVert->addElement(mSplitterLine);
 		mainLayoutVert->addElement(mSplitterLine);
-		mainLayoutVert->addNewElement<GUIFlexibleSpace>(); // Note: Insert layout for toolbar buttons here
+		mToolBarLayout = mainLayoutVert->addNewElement<GUILayoutX>();
 		
 		
 		mMenuItemLayout->addNewElement<GUIFlexibleSpace>();
 		mMenuItemLayout->addNewElement<GUIFlexibleSpace>();
 		mMenuItemLayout->addNewElement<GUIFixedSpace>(3);
 		mMenuItemLayout->addNewElement<GUIFixedSpace>(3);
@@ -95,6 +107,8 @@ namespace BansheeEngine
 		mMenuItemLayout->addElement(mCloseBtn);
 		mMenuItemLayout->addElement(mCloseBtn);
 		mMenuItemLayout->addNewElement<GUIFixedSpace>(3);
 		mMenuItemLayout->addNewElement<GUIFixedSpace>(3);
 
 
+		mToolBarLayout->addNewElement<GUIFlexibleSpace>();
+
 		mMinBtn->onClick.connect(std::bind(&GUIMenuBar::onMinimizeClicked, this));
 		mMinBtn->onClick.connect(std::bind(&GUIMenuBar::onMinimizeClicked, this));
 		mMaxBtn->onClick.connect(std::bind(&GUIMenuBar::onMaximizeClicked, this));
 		mMaxBtn->onClick.connect(std::bind(&GUIMenuBar::onMaximizeClicked, this));
 		mCloseBtn->onClick.connect(std::bind(&GUIMenuBar::onCloseClicked, this));
 		mCloseBtn->onClick.connect(std::bind(&GUIMenuBar::onCloseClicked, this));
@@ -161,7 +175,7 @@ namespace BansheeEngine
 		return subMenu->menu->addMenuItem(strippedPath, callback, priority, shortcut);
 		return subMenu->menu->addMenuItem(strippedPath, callback, priority, shortcut);
 	}
 	}
 
 
-	const GUIMenuItem* GUIMenuBar::addSeparator(const WString& path, INT32 priority)
+	const GUIMenuItem* GUIMenuBar::addMenuItemSeparator(const WString& path, INT32 priority)
 	{
 	{
 		WString strippedPath = path;
 		WString strippedPath = path;
 		WString rootName;
 		WString rootName;
@@ -276,6 +290,102 @@ namespace BansheeEngine
 		return nullptr;
 		return nullptr;
 	}
 	}
 
 
+	void GUIMenuBar::addToolBarButton(const String& name, const GUIContent& content, 
+		std::function<void()> callback, INT32 priority)
+	{
+		removeToolBarButton(name);
+
+		UINT32 numElements = (UINT32)mToolbarElements.size();
+		UINT32 idx = 0;
+		for (idx = 0; idx < numElements; idx++)
+		{
+			GUIToolBarData& element = mToolbarElements[idx];
+
+			if (element.priority < priority)
+				break;
+		}
+
+		if (idx < numElements)
+		{
+			mToolbarElements.push_back(GUIToolBarData());
+			idx = numElements;
+		}
+		else
+		{
+			mToolbarElements.insert(mToolbarElements.begin() + idx, GUIToolBarData());
+		}
+
+		GUIToolBarData& newData = mToolbarElements[idx];
+		newData.name = name;
+		newData.priority = priority;
+		newData.button = GUIButton::create(content, getToolBarButtonStyleType());
+		newData.space = GUIFixedSpace::create(5);
+		newData.separator = nullptr;
+
+		mToolBarLayout->insertElement(idx * 2, newData.button);
+		mToolBarLayout->insertElement(idx * 2 + 1, newData.space);
+
+		newData.button->onClick.connect(callback);
+	}
+
+	void GUIMenuBar::addToolBarSeparator(const String& name, INT32 priority)
+	{
+		removeToolBarButton(name);
+
+		UINT32 numElements = (UINT32)mToolbarElements.size();
+		UINT32 idx = 0;
+		for (idx = 0; idx < numElements; idx++)
+		{
+			GUIToolBarData& element = mToolbarElements[idx];
+
+			if (element.priority < priority)
+				break;
+		}
+
+		if (idx < numElements)
+		{
+			mToolbarElements.push_back(GUIToolBarData());
+			idx = numElements;
+		}
+		else
+		{
+			mToolbarElements.insert(mToolbarElements.begin() + idx, GUIToolBarData());
+		}
+
+		GUIToolBarData& newData = mToolbarElements[idx];
+		newData.name = name;
+		newData.priority = priority;
+		newData.space = GUIFixedSpace::create(5);
+		newData.separator = GUITexture::create(getToolBarSeparatorStyleType());
+		newData.button = nullptr;
+
+		mToolBarLayout->insertElement(idx * 2, newData.separator);
+		mToolBarLayout->insertElement(idx * 2 + 1, newData.space);
+	}
+
+	void GUIMenuBar::removeToolBarButton(const String& name)
+	{
+		for (UINT32 i = 0; i < (UINT32)mToolbarElements.size(); i++)
+		{
+			GUIToolBarData& element = mToolbarElements[i];
+
+			if (element.name == name)
+			{
+				if (element.button != nullptr)
+					GUIElement::destroy(element.button);
+
+				if (element.separator != nullptr)
+					GUIElement::destroy(element.separator);
+
+				if (element.space != nullptr)
+					GUIFixedSpace::destroy(element.space);
+
+				mToolbarElements.erase(mToolbarElements.begin() + i);
+				return;
+			}
+		}
+	}
+
 	void GUIMenuBar::registerShortcut(const WString& path, const ShortcutKey& shortcut, std::function<void()> callback)
 	void GUIMenuBar::registerShortcut(const WString& path, const ShortcutKey& shortcut, std::function<void()> callback)
 	{
 	{
 		ShortcutManager::instance().addShortcut(shortcut, callback);
 		ShortcutManager::instance().addShortcut(shortcut, callback);

+ 1 - 1
BansheeEditor/Source/BsMainEditorWindow.cpp

@@ -29,7 +29,7 @@ namespace BansheeEngine
 
 
 		updateAreas();
 		updateAreas();
 
 
-		mMenuBar->addSeparator(L"File", 0);
+		mMenuBar->addMenuItemSeparator(L"File", 0);
 		mMenuBar->addMenuItem(L"File/Exit", nullptr, 0);
 		mMenuBar->addMenuItem(L"File/Exit", nullptr, 0);
 
 
 		TestSuitePtr testSuite = TestSuite::create<EditorTestSuite>();
 		TestSuitePtr testSuite = TestSuite::create<EditorTestSuite>();

+ 1 - 1
SBansheeEditor/Source/BsMenuItemManager.cpp

@@ -85,7 +85,7 @@ namespace BansheeEngine
 								separatorPath.erase(path.size() - lastElem.size() - 1, lastElem.size() + 1);
 								separatorPath.erase(path.size() - lastElem.size() - 1, lastElem.size() + 1);
 							}
 							}
 
 
-							mainWindow->getMenuBar().addSeparator(separatorPath, priority);
+							mainWindow->getMenuBar().addMenuItemSeparator(separatorPath, priority);
 						}
 						}
 
 
 						mainWindow->getMenuBar().addMenuItem(path, callback, priority, shortcutKey);
 						mainWindow->getMenuBar().addMenuItem(path, callback, priority, shortcutKey);

+ 1 - 0
TODO.txt

@@ -53,6 +53,7 @@ Code quality improvements:
 Polish
 Polish
 
 
 Ribek use:
 Ribek use:
+ - Clicking on a menu bar item hides the text (likely a depth issue) 
  - Hook up color picker to guicolor field
  - Hook up color picker to guicolor field
  - UseCustomInspector isn't implemented
  - UseCustomInspector isn't implemented
  - Camera, Renderable, Material, Texture inspector
  - Camera, Renderable, Material, Texture inspector