소스 검색

Added ability to toggle toolbar items on or off

BearishSun 10 년 전
부모
커밋
a13e94a825

+ 8 - 0
BansheeEditor/Include/BsGUIMenuBar.h

@@ -137,6 +137,14 @@ namespace BansheeEngine
 		 */
 		void addToolBarButton(const String& name, const GUIContent& content, std::function<void()> callback, INT32 priority = 0);
 
+		/**
+		 * @brief	Toggles an existing toolbar button into an on or off state which changes the visuals of the button.
+		 *
+		 * @param	name	Name of the existing button to toggle.
+		 * @param	on		True to toggle on, false to toggle off (default).
+		 */
+		void toggleToolbarButton(const String& name, bool on);
+
 		/**
 		 * @brief	Adds a new separator element to the tool bar.
 		 *

+ 6 - 0
BansheeEditor/Source/BsBuiltinEditorResources.cpp

@@ -1137,9 +1137,15 @@ namespace BansheeEngine
 		toolBarBtnStyle.normal.texture = getGUITexture(ToolBarBtnNormalTex);
 		toolBarBtnStyle.hover.texture = getGUITexture(ToolBarBtnHoverTex);
 		toolBarBtnStyle.active.texture = getGUITexture(ToolBarBtnActiveTex);
+		toolBarBtnStyle.normalOn.texture = getGUITexture(ToolBarBtnActiveTex);
+		toolBarBtnStyle.hoverOn.texture = getGUITexture(ToolBarBtnActiveTex);
+		toolBarBtnStyle.activeOn.texture = getGUITexture(ToolBarBtnActiveTex);
 		toolBarBtnStyle.normal.textColor = TextNormalColor;
 		toolBarBtnStyle.hover.textColor = TextNormalColor;
 		toolBarBtnStyle.active.textColor = TextActiveColor;
+		toolBarBtnStyle.normalOn.textColor = TextNormalColor;
+		toolBarBtnStyle.hoverOn.textColor = TextNormalColor;
+		toolBarBtnStyle.activeOn.textColor = TextActiveColor;
 		toolBarBtnStyle.fixedHeight = true;
 		toolBarBtnStyle.fixedWidth = true;
 		toolBarBtnStyle.height = 32;

+ 14 - 0
BansheeEditor/Source/BsGUIMenuBar.cpp

@@ -399,6 +399,20 @@ namespace BansheeEngine
 		}
 	}
 
+	void GUIMenuBar::toggleToolbarButton(const String& name, bool on)
+	{
+		for (UINT32 i = 0; i < (UINT32)mToolbarElements.size(); i++)
+		{
+			GUIToolBarData& element = mToolbarElements[i];
+
+			if (element.name == name)
+			{
+				if (element.button != nullptr)
+					element.button->_setOn(on);
+			}
+		}
+	}
+
 	void GUIMenuBar::registerShortcut(const WString& path, const ShortcutKey& shortcut, std::function<void()> callback)
 	{
 		ShortcutManager::instance().addShortcut(shortcut, callback);

+ 13 - 0
MBansheeEditor/EditorApplication.cs

@@ -427,6 +427,16 @@ namespace BansheeEditor
             Internal_Quit();
         }
 
+        /// <summary>
+        /// Toggles an existing toolbar button into an on or off state which changes the visuals of the button.
+        /// </summary>
+        /// <param name="name">Name of the existing button to toggle</param>
+        /// <param name="on">True to toggle on, false to toggle off (default)</param>
+        public static void ToggleToolbarItem(string name, bool on)
+        {
+            Internal_ToggleToolbarItem(name, on);
+        }
+
         /// <summary>
         /// Opens a file or a folder in the default external application.
         /// </summary>
@@ -723,5 +733,8 @@ namespace BansheeEditor
 
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_Quit();
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_ToggleToolbarItem(string name, bool on);
     }
 }

+ 1 - 0
SBansheeEditor/Include/BsScriptEditorApplication.h

@@ -68,6 +68,7 @@ namespace BansheeEngine
 		static void internal_OpenExternally(MonoString* path);
 		static void internal_RunUnitTests();
 		static void internal_Quit();
+		static void internal_ToggleToolbarItem(MonoString* name, bool on);
 
 		typedef void(__stdcall *OnProjectLoadedThunkDef)(MonoException**);
 		typedef void(__stdcall *OnStatusBarClickedThunkDef) (MonoException**);

+ 10 - 10
SBansheeEditor/Source/BsScriptEditorApplication.cpp

@@ -7,7 +7,6 @@
 #include "BsProjectLibrary.h"
 #include "BsProjectResourceMeta.h"
 #include "BsPrefab.h"
-#include "BsPrefabUtility.h"
 #include "BsSceneManager.h"
 #include "BsEditorWindowManager.h"
 #include "BsMainEditorWindow.h"
@@ -15,15 +14,7 @@
 #include "BsScriptEditorTestSuite.h"
 #include "BsTestOutput.h"
 #include "BsScriptManager.h"
-#include "BsPlatform.h"
-#include "BsResources.h"
-#include "BsScriptEditorWindow.h"
-#include "BsEditorWindowBase.h"
-#include "BsProfilerOverlay.h"
-#include "BsCGUIWidget.h"
-#include "BsSceneObject.h"
-#include "BsCCamera.h"
-#include <BsScriptInput.h>
+#include "BsGUIMenuBar.h"
 
 namespace BansheeEngine
 {
@@ -65,6 +56,7 @@ namespace BansheeEngine
 		metaData.scriptClass->addInternalCall("Internal_OpenExternally", &ScriptEditorApplication::internal_OpenExternally);
 		metaData.scriptClass->addInternalCall("Internal_RunUnitTests", &ScriptEditorApplication::internal_RunUnitTests);
 		metaData.scriptClass->addInternalCall("Internal_Quit", &ScriptEditorApplication::internal_Quit);
+		metaData.scriptClass->addInternalCall("Internal_ToggleToolbarItem", &ScriptEditorApplication::internal_ToggleToolbarItem);
 
 		onProjectLoadedThunk = (OnProjectLoadedThunkDef)metaData.scriptClass->getMethod("Internal_OnProjectLoaded")->getThunk();
 		onStatusBarClickedThunk = (OnStatusBarClickedThunkDef)metaData.scriptClass->getMethod("Internal_OnStatusBarClicked")->getThunk();
@@ -281,4 +273,12 @@ namespace BansheeEngine
 	{
 		gApplication().stopMainLoop();
 	}
+
+	void ScriptEditorApplication::internal_ToggleToolbarItem(MonoString* name, bool on)
+	{
+		String nativeName = MonoUtil::monoToString(name);
+
+		MainEditorWindow* editorWindow = EditorWindowManager::instance().getMainWindow();
+		editorWindow->getMenuBar().toggleToolbarButton(nativeName, on);
+	}
 }