Browse Source

Merge branch 'carlosmarti-master'

BearishSun 9 years ago
parent
commit
d88d96625c

+ 5 - 1
Source/BansheeEditor/Include/BsEditorWidget.h

@@ -56,6 +56,9 @@ namespace BansheeEngine
 		/**	Checks if the widget has focus (usually means user clicked on it last). */
 		bool hasFocus() const { return mHasFocus; }
 
+		/** Makes the widget active in its container. This means the widgets tab is active and the widget is visible. */
+		void setActive();
+
 		/** 
 		 * Checks is the widget the currently active widget in its container. This means the widget's tab is active or
 		 * the widget is the only one in its container. 
@@ -105,7 +108,7 @@ namespace BansheeEngine
 		 * Changes the parent container of the widget (for example when re-docking or moving a widget to another window). 
 		 * Parent can be null (for example when widget is in the process of dragging and not visible).
 		 */
-		void _changeParent(EditorWidgetContainer* parent);
+		void _changeParent(EditorWidgetContainer* parent, UINT32 indx);
 
 		/**	Sets or removes focus for this widget. */
 		void _setHasFocus(bool focus);
@@ -148,6 +151,7 @@ namespace BansheeEngine
 		INT32 mX, mY;
 		UINT32 mWidth, mHeight;
 		UINT32 mDefaultWidth, mDefaultHeight;
+		UINT32 mIndex = 0;
 		GUIPanel* mContent;
 		bool mHasFocus;
 		bool mIsActive;

+ 8 - 8
Source/BansheeEditor/Include/BsEditorWidgetContainer.h

@@ -47,6 +47,14 @@ namespace BansheeEngine
 		 */
 		void setPosition(INT32 x, INT32 y);
 
+		/**
+		* Changes the currently active widget to the one at the specified index. Making the widget active means it will be
+		* visible in the container.
+		*
+		* @param[in]	idx		Unique widget index (not sequential).
+		*/
+		void setActiveWidget(UINT32 idx);
+
 		/**	Returns the number of widgets currently docked in this container. */
 		UINT32 getNumWidgets() const { return (UINT32)mWidgets.size(); }
 
@@ -102,14 +110,6 @@ namespace BansheeEngine
 		/**	Removes a widget without triggering a widget closed event. */
 		void removeInternal(EditorWidgetBase& widget);
 
-		/**
-		 * Changes the currently active widget to the one at the specified index. Making the widget active means it will be
-		 * visible in the container.
-		 *
-		 * @param[in]	idx		Unique widget index (not sequential).
-		 */
-		void setActiveWidget(UINT32 idx);
-
 		/**
 		 * Triggered when a user clicks on a tab in the tabbed title bar.
 		 *

+ 11 - 1
Source/BansheeEditor/Source/BsEditorWidget.cpp

@@ -54,6 +54,15 @@ namespace BansheeEngine
 		_setHasFocus(focus);
 	}
 
+	void EditorWidgetBase::setActive()
+	{
+		EditorWidgetContainer* parentContainer = _getParent();
+		if (parentContainer == nullptr)
+			return;
+
+		parentContainer->setActiveWidget(mIndex);
+	}
+
 	void EditorWidgetBase::close()
 	{
 		EditorWidgetManager::instance().close(this);
@@ -152,7 +161,7 @@ namespace BansheeEngine
 	}
 
 	// Note: Must not be virtual as parent container uses it in constructor
-	void EditorWidgetBase::_changeParent(EditorWidgetContainer* parent)
+	void EditorWidgetBase::_changeParent(EditorWidgetContainer* parent, UINT32 indx)
 	{
 		if(mParent != parent) 
 		{
@@ -170,6 +179,7 @@ namespace BansheeEngine
 			}
 
 			mParent = parent;
+			mIndex = indx;
 
 			doOnParentChanged();
 

+ 3 - 3
Source/BansheeEditor/Source/BsEditorWidgetContainer.cpp

@@ -90,7 +90,7 @@ namespace BansheeEngine
 
 		mWidgets.erase((UINT32)tabIdx);
 		mTitleBar->removeTab((UINT32)tabIdx);
-		widget._changeParent(nullptr);
+		widget._changeParent(nullptr, 0);
 
 		if(tabIdx == mActiveWidget)
 		{
@@ -111,7 +111,7 @@ namespace BansheeEngine
 
 		UINT32 tabIdx = mTitleBar->insertTab(idx, widget.getDisplayName());
 		mWidgets[tabIdx] = &widget;
-		widget._changeParent(this);
+		widget._changeParent(this, tabIdx);
 
 		if(mActiveWidget == -1)
 			setActiveWidget(mTitleBar->getTabIdx(mTitleBar->getNumTabs() - 1));
@@ -152,7 +152,7 @@ namespace BansheeEngine
 		if (mActiveWidget >= 0)
 		{
 			auto iterFind = mWidgets.find(mActiveWidget);
-
+			
 			if (iterFind != mWidgets.end())
 				return iterFind->second;
 		}

+ 2 - 2
Source/ExampleProject/Source/Main.cpp

@@ -142,7 +142,7 @@ namespace BansheeEngine
 		HMesh exampleModel;
 		HTexture exampleTexture;
 		HShader exampleShader;
-
+		
 		loadAssets(exampleModel, exampleTexture, exampleShader);
 		HMaterial exampleMaterial = createMaterial(exampleTexture, exampleShader);
 
@@ -241,7 +241,7 @@ namespace BansheeEngine
 
 		// Create new scene object at (0, 0, 0)
 		HSceneObject dragonSO = SceneObject::create("Dragon");
-
+		
 		// Attach the Renderable component and hook up the mesh we imported earlier,
 		// and the material we created in the previous section.
 		HRenderable renderable = dragonSO->addComponent<CRenderable>();

+ 8 - 1
Source/MBansheeEditor/Window/EditorWindow.cs

@@ -77,7 +77,11 @@ namespace BansheeEditor
         /// Checks if the window's tab is currently active. If the window is floating or not sharing space with any other
         /// windows (just a single tab), it is always considered active.
         /// </summary>
-        public bool Active { get { return Internal_IsActive(mCachedPtr); } }
+        public bool Active
+        {
+            set { Internal_SetActive(mCachedPtr, value); }
+            get { return Internal_IsActive(mCachedPtr); }
+        }
 
         /// <summary>
         /// GUI panel that you may use for adding GUI elements to the window.
@@ -185,6 +189,9 @@ namespace BansheeEditor
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_SetFocus(IntPtr nativeInstance, bool focus);
 
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern bool Internal_SetActive(IntPtr nativeInstance, bool active);
+
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern bool Internal_IsActive(IntPtr nativeInstance);
 

+ 14 - 0
Source/MBansheeEditor/Windows/GameWindow.cs

@@ -45,6 +45,20 @@ namespace BansheeEditor
         [ToolbarItem("Play", ToolbarIcon.Play, "Play", 1800, true)]
         private static void Play()
         {
+            GameWindow gameWindow = GetWindow<GameWindow>();
+            SceneWindow sceneWindow = GetWindow<SceneWindow>();
+
+            if (!EditorApplication.IsPlaying)
+            {
+                gameWindow.Active = true;
+                gameWindow.HasFocus = true;
+            }
+            else
+            {
+                sceneWindow.Active = true;
+                sceneWindow.HasFocus = true;
+            }
+
             if (EditorApplication.IsPaused)
                 EditorApplication.IsPaused = false;
             else

+ 1 - 0
Source/SBansheeEditor/Include/BsScriptEditorWindow.h

@@ -115,6 +115,7 @@ namespace BansheeEngine
 
 		static bool internal_hasFocus(ScriptEditorWindow* thisPtr);
 		static void internal_setFocus(ScriptEditorWindow* thisPtr, bool focus);
+		static void internal_setActive(ScriptEditorWindow* thisPtr, bool active);
 		static bool internal_isActive(ScriptEditorWindow* thisPtr);
 		static bool internal_isPointerHovering(ScriptEditorWindow* thisPtr);
 		static void internal_screenToWindowPos(ScriptEditorWindow* thisPtr, Vector2I* screenPos, Vector2I* windowPos);

+ 10 - 0
Source/SBansheeEditor/Source/BsScriptEditorWindow.cpp

@@ -60,6 +60,7 @@ namespace BansheeEngine
 		metaData.scriptClass->addInternalCall("Internal_GetBounds", &ScriptEditorWindow::internal_getBounds);
 		metaData.scriptClass->addInternalCall("Internal_SetFocus", &ScriptEditorWindow::internal_setFocus);
 		metaData.scriptClass->addInternalCall("Internal_HasFocus", &ScriptEditorWindow::internal_hasFocus);
+		metaData.scriptClass->addInternalCall("Internal_SetActive", &ScriptEditorWindow::internal_setActive);
 		metaData.scriptClass->addInternalCall("Internal_IsActive", &ScriptEditorWindow::internal_isActive);
 		metaData.scriptClass->addInternalCall("Internal_IsPointerHovering", &ScriptEditorWindow::internal_isPointerHovering);
 		metaData.scriptClass->addInternalCall("Internal_ScreenToWindowPos", &ScriptEditorWindow::internal_screenToWindowPos);
@@ -201,6 +202,15 @@ namespace BansheeEngine
 			return false;
 	}
 
+	void ScriptEditorWindow::internal_setActive(ScriptEditorWindow* thisPtr, bool active)
+	{
+		if (!thisPtr->isDestroyed())
+		{
+			if (active)
+				thisPtr->getEditorWidget()->setActive(); 
+		}
+	}
+
 	bool ScriptEditorWindow::internal_isActive(ScriptEditorWindow* thisPtr)
 	{
 		if (!thisPtr->isDestroyed())