Browse Source

Viewport properly resized with its render target

Marko Pintera 12 years ago
parent
commit
8bc3903ee2

+ 4 - 4
BansheeEngine/Include/BsGUIWidget.h

@@ -22,7 +22,7 @@ namespace BansheeEngine
 		 * @param	ownerWindow   	Window that contains the widget. This will be the source of all input
 		 * @param	ownerWindow   	Window that contains the widget. This will be the source of all input
 		 * 							for the widget. "target" and "ownerWindow" may be the same object.
 		 * 							for the widget. "target" and "ownerWindow" may be the same object.
 		 */
 		 */
-		virtual void initialize(CM::Viewport* target, const CM::RenderWindow* ownerWindow);
+		virtual void initialize(CM::Viewport* target, CM::RenderWindow* ownerWindow);
 
 
 		void setSkin(const GUISkin* skin);
 		void setSkin(const GUISkin* skin);
 		const GUISkin* getSkin() const;
 		const GUISkin* getSkin() const;
@@ -41,7 +41,7 @@ namespace BansheeEngine
 		 */
 		 */
 		bool isDirty(bool cleanIfDirty);
 		bool isDirty(bool cleanIfDirty);
 
 
-		const CM::RenderWindow* getOwnerWindow() const { return mOwnerWindow; }
+		CM::RenderWindow* getOwnerWindow() const { return mOwnerWindow; }
 		CM::Viewport* getTarget() const { return mTarget; }
 		CM::Viewport* getTarget() const { return mTarget; }
 		const CM::vector<GUIElement*>::type& getElements() const { return mElements; }
 		const CM::vector<GUIElement*>::type& getElements() const { return mElements; }
 
 
@@ -67,12 +67,12 @@ namespace BansheeEngine
 	private:
 	private:
 		void updateBounds() const;
 		void updateBounds() const;
 
 
-		virtual void ownerWindowResized(CM::RenderWindow* window);
+		virtual void ownerWindowResized(CM::RenderTarget* window);
 		virtual void ownerWindowFocusChanged(CM::RenderWindow* window);
 		virtual void ownerWindowFocusChanged(CM::RenderWindow* window);
 
 
 		virtual void update();
 		virtual void update();
 
 
-		const CM::RenderWindow* mOwnerWindow;
+		CM::RenderWindow* mOwnerWindow;
 		CM::Viewport* mTarget;
 		CM::Viewport* mTarget;
 		CM::vector<GUIElement*>::type mElements;
 		CM::vector<GUIElement*>::type mElements;
 		CM::vector<GUIArea*>::type mAreas;
 		CM::vector<GUIArea*>::type mAreas;

+ 4 - 4
BansheeEngine/Source/BsGUIWidget.cpp

@@ -51,7 +51,7 @@ namespace BansheeEngine
 		mWinFocusConn.disconnect();
 		mWinFocusConn.disconnect();
 	}
 	}
 
 
-	void GUIWidget::initialize(Viewport* target, const RenderWindow* ownerWindow)
+	void GUIWidget::initialize(Viewport* target, RenderWindow* ownerWindow)
 	{
 	{
 		assert(target != nullptr);
 		assert(target != nullptr);
 		assert(ownerWindow != nullptr);
 		assert(ownerWindow != nullptr);
@@ -64,8 +64,8 @@ namespace BansheeEngine
 
 
 		GUIManager::instance().registerWidget(this);
 		GUIManager::instance().registerWidget(this);
 
 
-		mWinResizeConn = mOwnerWindow->onWindowMovedOrResized.connect(boost::bind(&GUIWidget::ownerWindowResized, this, _1));
-		mWinFocusConn = mOwnerWindow->onWindowFocusChanged.connect(boost::bind(&GUIWidget::ownerWindowFocusChanged, this, _1));
+		mWinResizeConn = mOwnerWindow->onMovedOrResized.connect(boost::bind(&GUIWidget::ownerWindowResized, this, _1));
+		mWinFocusConn = mOwnerWindow->onFocusChanged.connect(boost::bind(&GUIWidget::ownerWindowFocusChanged, this, _1));
 	}
 	}
 
 
 	void GUIWidget::update()
 	void GUIWidget::update()
@@ -241,7 +241,7 @@ namespace BansheeEngine
 		}
 		}
 	}
 	}
 
 
-	void GUIWidget::ownerWindowResized(RenderWindow* window)
+	void GUIWidget::ownerWindowResized(RenderTarget* window)
 	{
 	{
 		for(auto& area : mAreas)
 		for(auto& area : mAreas)
 		{
 		{

+ 8 - 0
BansheeEngine/Source/BsGUIWindowFrame.cpp

@@ -7,6 +7,7 @@
 #include "BsGUIMouseEvent.h"
 #include "BsGUIMouseEvent.h"
 #include "CmCursor.h"
 #include "CmCursor.h"
 #include "CmTexture.h"
 #include "CmTexture.h"
+#include "CmRenderWindow.h"
 
 
 using namespace CamelotFramework;
 using namespace CamelotFramework;
 
 
@@ -258,6 +259,13 @@ namespace BansheeEngine
 
 
 				return true;
 				return true;
 			}
 			}
+
+			Int2 dragAmount = ev.getDragAmount();
+			if(dragAmount.x != 0 || dragAmount.y != 0)
+			{
+				RenderWindow* window = _getParentWidget().getOwnerWindow();
+				window->resize(window->getWidth() + dragAmount.x, window->getHeight() + dragAmount.y);
+			}
 		}
 		}
 
 
 		if(ev.getType() == GUIMouseEventType::MouseOut)
 		if(ev.getType() == GUIMouseEventType::MouseOut)

+ 1 - 1
CamelotClient/BsGUITabbedTitleBar.cpp

@@ -56,7 +56,7 @@ namespace BansheeEditor
 		mDragDropElements.erase(mDragDropElements.begin() + idx);
 		mDragDropElements.erase(mDragDropElements.begin() + idx);
 	}
 	}
 
 
-	void TabbedTitleBar::initialize(CM::Viewport* target, const CM::RenderWindow* ownerWindow)
+	void TabbedTitleBar::initialize(CM::Viewport* target, CM::RenderWindow* ownerWindow)
 	{
 	{
 		GUIWidget::initialize(target, ownerWindow);
 		GUIWidget::initialize(target, ownerWindow);
 
 

+ 1 - 1
CamelotClient/BsGUITabbedTitleBar.h

@@ -12,7 +12,7 @@ namespace BansheeEditor
 		TabbedTitleBar(const CM::HSceneObject& parent);
 		TabbedTitleBar(const CM::HSceneObject& parent);
 		virtual ~TabbedTitleBar();
 		virtual ~TabbedTitleBar();
 
 
-		virtual void initialize(CM::Viewport* target, const CM::RenderWindow* ownerWindow);
+		virtual void initialize(CM::Viewport* target, CM::RenderWindow* ownerWindow);
 
 
 		void addTab(const CM::String& name);
 		void addTab(const CM::String& name);
 		void insertTab(CM::UINT32 idx, const CM::String& name);
 		void insertTab(CM::UINT32 idx, const CM::String& name);

+ 1 - 1
CamelotClient/BsGUIWindowFrameWidget.cpp

@@ -24,7 +24,7 @@ namespace BansheeEditor
 
 
 	}
 	}
 
 
-	void WindowFrameWidget::initialize(CM::Viewport* target, const CM::RenderWindow* ownerWindow)
+	void WindowFrameWidget::initialize(CM::Viewport* target, CM::RenderWindow* ownerWindow)
 	{
 	{
 		GUIWidget::initialize(target, ownerWindow);
 		GUIWidget::initialize(target, ownerWindow);
 
 

+ 1 - 1
CamelotClient/BsGUIWindowFrameWidget.h

@@ -12,7 +12,7 @@ namespace BansheeEditor
 		WindowFrameWidget(const CM::HSceneObject& parent);
 		WindowFrameWidget(const CM::HSceneObject& parent);
 		virtual ~WindowFrameWidget();
 		virtual ~WindowFrameWidget();
 
 
-		virtual void initialize(CM::Viewport* target, const CM::RenderWindow* ownerWindow);
+		virtual void initialize(CM::Viewport* target, CM::RenderWindow* ownerWindow);
 
 
 	protected:
 	protected:
 		BS::GUIArea* mWindowFrameArea;
 		BS::GUIArea* mWindowFrameArea;

+ 2 - 0
CamelotClient/CmEditorWindow.cpp

@@ -91,6 +91,8 @@ namespace BansheeEditor
 		//titleBarBackgroundArea->getLayout().addSpace(1);
 		//titleBarBackgroundArea->getLayout().addSpace(1);
 		//titleBarBackgroundArea->getLayout().addElement(GUITexture::create(*mGUI, GUIImageScaleMode::RepeatToFit, GUILayoutOptions::expandableXY(), mGUI->getGUISkin()->getStyle("TitleBarBg")));
 		//titleBarBackgroundArea->getLayout().addElement(GUITexture::create(*mGUI, GUIImageScaleMode::RepeatToFit, GUILayoutOptions::expandableXY(), mGUI->getGUISkin()->getStyle("TitleBarBg")));
 		//titleBarBackgroundArea->getLayout().addSpace(1);
 		//titleBarBackgroundArea->getLayout().addSpace(1);
+		
+		mRenderWindow->resize(300, 250);
 	}
 	}
 
 
 	EditorWindow::~EditorWindow()
 	EditorWindow::~EditorWindow()

+ 2 - 0
CamelotCore/Include/CmRenderTarget.h

@@ -34,6 +34,7 @@ THE SOFTWARE.
 #include "CmPixelUtil.h"
 #include "CmPixelUtil.h"
 #include "CmViewport.h"
 #include "CmViewport.h"
 #include "CmCoreObject.h"
 #include "CmCoreObject.h"
+#include "boost/signal.hpp"
 
 
 /* Define the number of priority groups for the render system's render targets. */
 /* Define the number of priority groups for the render system's render targets. */
 #ifndef CM_NUM_RENDERTARGET_GROUPS
 #ifndef CM_NUM_RENDERTARGET_GROUPS
@@ -174,6 +175,7 @@ namespace CamelotFramework
 		 */
 		 */
 		void setVSync(bool vsync)  { mVSync = vsync; }
 		void setVSync(bool vsync)  { mVSync = vsync; }
 
 
+		mutable boost::signal<void(RenderTarget*)> onMovedOrResized;
     protected:
     protected:
 		RenderTarget();
 		RenderTarget();
 
 

+ 1 - 3
CamelotCore/Include/CmRenderWindow.h

@@ -29,7 +29,6 @@ THE SOFTWARE
 #include "CmPrerequisites.h"
 #include "CmPrerequisites.h"
 
 
 #include "CmRenderTarget.h"
 #include "CmRenderTarget.h"
-#include "boost/signal.hpp"
 
 
 namespace CamelotFramework
 namespace CamelotFramework
 {
 {
@@ -179,8 +178,7 @@ namespace CamelotFramework
 		void setHasFocus(bool focus);
 		void setHasFocus(bool focus);
 		bool hasFocus() const { return mHasFocus; }
 		bool hasFocus() const { return mHasFocus; }
 
 
-		mutable boost::signal<void(RenderWindow*)> onWindowMovedOrResized;
-		mutable boost::signal<void(RenderWindow*)> onWindowFocusChanged;
+		mutable boost::signal<void(RenderWindow*)> onFocusChanged;
 
 
 		virtual void destroy();
 		virtual void destroy();
 
 

+ 5 - 0
CamelotCore/Include/CmViewport.h

@@ -32,6 +32,7 @@ THE SOFTWARE.
 #include "CmCommonEnums.h"
 #include "CmCommonEnums.h"
 #include "CmColor.h"
 #include "CmColor.h"
 #include "CmRect.h"
 #include "CmRect.h"
+#include <boost/signals/connection.hpp>
 
 
 namespace CamelotFramework {
 namespace CamelotFramework {
 	/** \addtogroup Core
 	/** \addtogroup Core
@@ -160,6 +161,8 @@ namespace CamelotFramework {
         // Actual dimensions, based on target dimensions
         // Actual dimensions, based on target dimensions
 		Rect mDimensions;
 		Rect mDimensions;
 
 
+		boost::signals::connection mTargetConn;
+
         /// ZOrder
         /// ZOrder
         int mZOrder;
         int mZOrder;
 
 
@@ -171,6 +174,8 @@ namespace CamelotFramework {
                 Internal use by engine only.
                 Internal use by engine only.
         */
         */
         void updateDimensions(void);
         void updateDimensions(void);
+
+		void targetResized(RenderTarget* target);
     };
     };
 	/** @} */
 	/** @} */
 	/** @} */
 	/** @} */

+ 4 - 4
CamelotCore/Source/CmRenderWindow.cpp

@@ -73,16 +73,16 @@ namespace CamelotFramework
 
 
 	void RenderWindow::windowMovedOrResized()
 	void RenderWindow::windowMovedOrResized()
 	{
 	{
-		if(!onWindowMovedOrResized.empty())
-			onWindowMovedOrResized(this);
+		if(!onMovedOrResized.empty())
+			onMovedOrResized(this);
 	}
 	}
 
 
 	void RenderWindow::setHasFocus(bool focus)
 	void RenderWindow::setHasFocus(bool focus)
 	{ 
 	{ 
 		mHasFocus = focus; 
 		mHasFocus = focus; 
 
 
-		if(!onWindowFocusChanged.empty())
-			onWindowFocusChanged(this);
+		if(!onFocusChanged.empty())
+			onFocusChanged(this);
 	}
 	}
 
 
 	void RenderWindow::destroy()
 	void RenderWindow::destroy()

+ 11 - 1
CamelotCore/Source/CmViewport.cpp

@@ -56,15 +56,25 @@ namespace CamelotFramework
         // Actual dimensions will update later
         // Actual dimensions will update later
         , mZOrder(ZOrder)
         , mZOrder(ZOrder)
     {
     {
+		if(target != nullptr)
+		{
+			mTargetConn = target->onMovedOrResized.connect(boost::bind(&Viewport::targetResized, this, _1));
+		}
+
         // Calculate actual dimensions
         // Calculate actual dimensions
         updateDimensions();
         updateDimensions();
     }
     }
 
 
     Viewport::~Viewport()
     Viewport::~Viewport()
     {
     {
-
+		mTargetConn.disconnect();
     }
     }
 
 
+	void Viewport::targetResized(RenderTarget* target)
+	{
+		updateDimensions();
+	}
+
     void Viewport::updateDimensions(void)
     void Viewport::updateDimensions(void)
     {
     {
 		if(mTarget != nullptr)
 		if(mTarget != nullptr)

+ 2 - 2
CamelotD3D11RenderSystem/Source/CmD3D11RenderWindow.cpp

@@ -301,7 +301,7 @@ namespace CamelotFramework
 		if (mHWnd && !mIsFullScreen)
 		if (mHWnd && !mIsFullScreen)
 		{
 		{
 			SetWindowPos(mHWnd, 0, top, left, 0, 0,
 			SetWindowPos(mHWnd, 0, top, left, 0, 0,
-				SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
+				SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_ASYNCWINDOWPOS);
 		}
 		}
 	}
 	}
 
 
@@ -314,7 +314,7 @@ namespace CamelotFramework
 			width = rc.right - rc.left;
 			width = rc.right - rc.left;
 			height = rc.bottom - rc.top;
 			height = rc.bottom - rc.top;
 			SetWindowPos(mHWnd, 0, 0, 0, width, height,
 			SetWindowPos(mHWnd, 0, 0, 0, width, height,
-				SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
+				SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_ASYNCWINDOWPOS);
 		}
 		}
 	}
 	}