Browse Source

DirectX9 render window is now using the common Win32Window

BearishSun 10 years ago
parent
commit
23e86e3779

+ 10 - 0
BansheeCore/Include/Win32/BsWin32Window.h

@@ -114,6 +114,16 @@ namespace BansheeEngine
 		 */
 		Vector2I windowToScreenPos(const Vector2I& windowPos) const;
 
+		/**
+		 * @brief	Returns the window style flags used for creating it.
+		 */
+		DWORD getStyle() const;
+
+		/**
+		 * @brief	Returns the extended window style flags used for creating it.
+		 */
+		DWORD getStyleEx() const;
+
 		/**
 		 * @brief	Called when window is moved or resized externally.
 		 *

+ 36 - 27
BansheeCore/Source/Win32/BsWin32Window.cpp

@@ -11,6 +11,8 @@ namespace BansheeEngine
 		UINT32 width = 0;
 		UINT32 height = 0;
 		bool isExternal = false;
+		DWORD style = 0;
+		DWORD styleEx = 0;
 	};
 
 	Win32Window::Win32Window(const WINDOW_DESC& desc)
@@ -20,14 +22,10 @@ namespace BansheeEngine
 		HMONITOR hMonitor = desc.monitor;
 		if (!desc.external)
 		{
-			DWORD dwStyle = WS_CLIPCHILDREN;
+			m->style = WS_CLIPCHILDREN;
 
 			if (!desc.hidden)
-				dwStyle |= WS_VISIBLE;
-
-			DWORD dwStyleEx = 0;
-			RECT rc;
-			MONITORINFO monitorInfo;
+				m->style |= WS_VISIBLE;
 
 			INT32 left = desc.left;
 			INT32 top = desc.top;
@@ -45,7 +43,8 @@ namespace BansheeEngine
 				hMonitor = MonitorFromPoint(windowAnchorPoint, MONITOR_DEFAULTTOPRIMARY);
 			}
 
-			// Get the target monitor info		
+			// Get the target monitor info
+			MONITORINFO monitorInfo;
 			memset(&monitorInfo, 0, sizeof(MONITORINFO));
 			monitorInfo.cbSize = sizeof(MONITORINFO);
 			GetMonitorInfo(hMonitor, &monitorInfo);
@@ -84,29 +83,29 @@ namespace BansheeEngine
 				if (desc.parent)
 				{
 					if (desc.toolWindow)
-						dwStyleEx = WS_EX_TOOLWINDOW;
+						m->styleEx = WS_EX_TOOLWINDOW;
 					else
-						dwStyle |= WS_CHILD;
+						m->style |= WS_CHILD;
 				}
 
 				if (!desc.parent || desc.toolWindow)
 				{
 					if (desc.border == WindowBorder::None)
-						dwStyle |= WS_POPUP;
+						m->style |= WS_POPUP;
 					else if (desc.border == WindowBorder::Fixed)
-						dwStyle |= WS_OVERLAPPED | WS_BORDER | WS_CAPTION |
-						WS_SYSMENU | WS_MINIMIZEBOX;
+						m->style |= WS_OVERLAPPED | WS_BORDER | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX;
 					else
-						dwStyle |= WS_OVERLAPPEDWINDOW;
+						m->style |= WS_OVERLAPPEDWINDOW;
 				}
 
 				if (!desc.outerDimensions)
 				{
 					// Calculate window dimensions required to get the requested client area
-					SetRect(&rc, 0, 0, width, height);
-					AdjustWindowRect(&rc, dwStyle, false);
-					width = rc.right - rc.left;
-					height = rc.bottom - rc.top;
+					RECT rect;
+					SetRect(&rect, 0, 0, width, height);
+					AdjustWindowRect(&rect, m->style, false);
+					width = rect.right - rect.left;
+					height = rect.bottom - rect.top;
 
 					// Clamp width and height to the desktop dimensions
 					int screenw = GetSystemMetrics(SM_CXSCREEN);
@@ -127,7 +126,7 @@ namespace BansheeEngine
 			}
 			else
 			{
-				dwStyle |= WS_POPUP;
+				m->style |= WS_POPUP;
 				top = 0;
 				left = 0;
 			}
@@ -136,7 +135,7 @@ namespace BansheeEngine
 			if (desc.enableDoubleClick)
 				classStyle |= CS_DBLCLKS;
 
-			HINSTANCE hInst = NULL;
+			HINSTANCE hInst = nullptr;
 
 			// Register the window class
 			WNDCLASS wc = { classStyle, Win32Platform::_win32WndProc, 0, 0, hInst,
@@ -146,7 +145,7 @@ namespace BansheeEngine
 			RegisterClass(&wc);
 
 			// Create main window
-			m->hWnd = CreateWindowEx(dwStyleEx, "Win32Wnd", desc.title.c_str(), dwStyle,
+			m->hWnd = CreateWindowEx(m->styleEx, "Win32Wnd", desc.title.c_str(), m->style,
 				left, top, width, height, desc.parent, nullptr, hInst, desc.creationParams);
 			m->isExternal = false;
 		}
@@ -156,14 +155,14 @@ namespace BansheeEngine
 			m->isExternal = true;
 		}
 
-		RECT rc;
-		GetWindowRect(m->hWnd, &rc);
-		m->top = rc.top;
-		m->left = rc.left;
+		RECT rect;
+		GetWindowRect(m->hWnd, &rect);
+		m->top = rect.top;
+		m->left = rect.left;
 
-		GetClientRect(m->hWnd, &rc);
-		m->width = rc.right;
-		m->height = rc.bottom;
+		GetClientRect(m->hWnd, &rect);
+		m->width = rect.right;
+		m->height = rect.bottom;
 	}
 
 	Win32Window::~Win32Window()
@@ -297,4 +296,14 @@ namespace BansheeEngine
 	{
 		return m->hWnd;
 	}
+
+	DWORD Win32Window::getStyle() const
+	{
+		return m->style;
+	}
+
+	DWORD Win32Window::getStyleEx() const
+	{
+		return m->styleEx;
+	}
 }

+ 4 - 12
BansheeD3D11RenderAPI/Source/BsD3D11RenderWindow.cpp

@@ -85,10 +85,9 @@ namespace BansheeEngine
 		if (opt != mDesc.platformSpecific.end())
 			windowDesc.external = (HWND)parseUnsignedInt(opt->second);
 
-		mIsChild = windowDesc.parent != 0;
+		mIsChild = windowDesc.parent != nullptr;
 		props.mIsFullScreen = mDesc.fullscreen && !mIsChild;
 		props.mColorDepth = 32;
-
 		props.mActive = true;
 
 		if (mDesc.videoMode.isCustom())
@@ -121,12 +120,11 @@ namespace BansheeEngine
 		if (!windowDesc.external)
 		{
 			mShowOnSwap = mDesc.hideUntilSwap;
-			props.mHidden = mDesc.hideUntilSwap;
+			props.mHidden = mDesc.hideUntilSwap || mDesc.hidden;
 		}
 
 		mWindow = bs_new<Win32Window>(windowDesc);
 
-		// TODO - Get window size and populate props
 		props.mWidth = mWindow->getWidth();
 		props.mHeight = mWindow->getHeight();
 		props.mTop = mWindow->getTop();
@@ -220,19 +218,14 @@ namespace BansheeEngine
 		THROW_IF_NOT_CORE_THREAD;
 
 		D3D11RenderWindowProperties& props = mProperties;
+		mWindow->setActive(state);
 
 		if (mSwapChain)
 		{
 			if (state)
-			{
-				ShowWindow(mWindow->getHWnd(), SW_RESTORE);
 				mSwapChain->SetFullscreenState(props.mIsFullScreen, nullptr);
-			}
 			else
-			{
-				ShowWindow(mWindow->getHWnd(), SW_SHOWMINNOACTIVE);
 				mSwapChain->SetFullscreenState(FALSE, nullptr);
-			}
 		}
 
 		RenderWindowCore::setActive(state);
@@ -515,12 +508,11 @@ namespace BansheeEngine
 
 		D3D11RenderWindowProperties& props = mProperties;
 
+		resizeSwapChainBuffers(mWindow->getWidth(), mWindow->getHeight());
 		mWindow->_windowMovedOrResized();
 		props.mTop = mWindow->getTop();
 		props.mLeft = mWindow->getLeft();
 
-		resizeSwapChainBuffers(mWindow->getWidth(), mWindow->getHeight());
-
 		RenderWindowCore::_windowMovedOrResized();
 	}
 

+ 3 - 18
BansheeD3D9RenderAPI/Include/BsD3D9RenderWindow.h

@@ -151,17 +151,6 @@ namespace BansheeEngine
 		 */
 		virtual void initialize() override;
 
-		/**
-		 * @brief	Updates window coordinates and size from actual values provided by Windows.
-		 */
-		void updateWindowRect();
-
-		/**
-		 * @brief	Calculates window size based on provided client area size and currently set window style. 
-		 */	
-		void getAdjustedWindowSize(UINT32 clientWidth, UINT32 clientHeight,
-			DWORD style, UINT32* winWidth, UINT32* winHeight);
-
 		/**
 		 * @copydoc	RenderWindowCore::getProperties
 		 */
@@ -178,22 +167,18 @@ namespace BansheeEngine
 		void syncProperties() override;
 
 	protected:
+		Win32Window* mWindow;
 		HINSTANCE mInstance;
 		D3D9Device* mDevice;
 		bool mDeviceValid;
-		bool mIsExternal;		
 		D3DMULTISAMPLE_TYPE	mMultisampleType;
 		DWORD mMultisampleQuality;
 		UINT mDisplayFrequency;
-		unsigned int mVSyncInterval;		
-		DWORD mStyle;	
-		DWORD mWindowedStyle;
-		DWORD mWindowedStyleEx;
+		unsigned int mVSyncInterval;
 		bool mIsDepthBuffered;
 		bool mIsChild;
-		HWND mHWnd;
 		bool mShowOnSwap;
-
+		
 		D3D9RenderWindowProperties mProperties;
 		D3D9RenderWindowProperties mSyncedProperties;
 	};

+ 80 - 315
BansheeD3D9RenderAPI/Source/BsD3D9RenderWindow.cpp

@@ -10,6 +10,7 @@
 #include "BsD3D9VideoModeInfo.h"
 #include "BsD3D9DeviceManager.h"
 #include "BsRenderWindowManager.h"
+#include "Win32/BsWin32Window.h"
 
 namespace BansheeEngine
 {
@@ -20,8 +21,9 @@ namespace BansheeEngine
 	}
 
 	D3D9RenderWindowCore::D3D9RenderWindowCore(const RENDER_WINDOW_DESC& desc, UINT32 windowId, HINSTANCE instance)
-		: RenderWindowCore(desc, windowId), mInstance(instance), mProperties(desc), mSyncedProperties(desc), mIsDepthBuffered(true), mIsChild(false), mHWnd(0),
-		mStyle(0), mWindowedStyle(0), mWindowedStyleEx(0), mDevice(nullptr), mIsExternal(false), mDisplayFrequency(0), mDeviceValid(false), mShowOnSwap(false)
+		: RenderWindowCore(desc, windowId), mInstance(instance), mProperties(desc), mSyncedProperties(desc), 
+		mIsDepthBuffered(true), mIsChild(false), mWindow(nullptr),mDevice(nullptr), mDisplayFrequency(0), 
+		mDeviceValid(false), mShowOnSwap(false)
 	{ }
 
 	D3D9RenderWindowCore::~D3D9RenderWindowCore()
@@ -32,12 +34,12 @@ namespace BansheeEngine
 			mDevice = nullptr;
 		}
 
-		if (mHWnd && !mIsExternal)
+		if (mWindow != nullptr)
 		{
-			DestroyWindow(mHWnd);
+			bs_delete(mWindow);
+			mWindow = nullptr;
 		}
 
-		mHWnd = 0;
 		mProperties.mActive = false;
 	}
 
@@ -52,197 +54,59 @@ namespace BansheeEngine
 		mMultisampleQuality = 0;
 		mDisplayFrequency = Math::roundToInt(mDesc.videoMode.getRefreshRate());
 
-		HWND parentHWnd = 0;
-		HWND externalHandle = 0;
+		WINDOW_DESC windowDesc;
+		windowDesc.border = mDesc.border;
+		windowDesc.enableDoubleClick = mDesc.enableDoubleClick;
+		windowDesc.fullscreen = mDesc.fullscreen;
+		windowDesc.width = mDesc.videoMode.getWidth();
+		windowDesc.height = mDesc.videoMode.getHeight();
+		windowDesc.hidden = mDesc.hidden || mDesc.hideUntilSwap;
+		windowDesc.left = mDesc.left;
+		windowDesc.top = mDesc.top;
+		windowDesc.outerDimensions = mDesc.outerDimensions;
+		windowDesc.title = mDesc.title;
+		windowDesc.toolWindow = mDesc.toolWindow;
+		windowDesc.creationParams = this;
 
 		NameValuePairList::const_iterator opt;
 		opt = mDesc.platformSpecific.find("parentWindowHandle");
 		if (opt != mDesc.platformSpecific.end())
-			parentHWnd = (HWND)parseUnsignedInt(opt->second);
+			windowDesc.parent = (HWND)parseUnsignedInt(opt->second);
 
 		opt = mDesc.platformSpecific.find("externalWindowHandle");
 		if (opt != mDesc.platformSpecific.end())
-			externalHandle = (HWND)parseUnsignedInt(opt->second);
+			windowDesc.external = (HWND)parseUnsignedInt(opt->second);
 
-		mIsChild = parentHWnd != 0;
-
-		mWindowedStyle = WS_CLIPCHILDREN;
-		mShowOnSwap = mDesc.hideUntilSwap;
-		props.mHidden = mDesc.hideUntilSwap;
-
-		if (!mShowOnSwap)
-			mWindowedStyle |= WS_VISIBLE;
+		mIsChild = windowDesc.parent != nullptr;
+		props.mIsFullScreen = mDesc.fullscreen && !mIsChild;
+		props.mColorDepth = 32;
+		props.mActive = true;
 
-		mWindowedStyleEx = 0;
+		MONITORINFO monitorInfo;
 
-		if (!mDesc.fullscreen || mIsChild)
+		const D3D9VideoModeInfo& videoModeInfo = static_cast<const D3D9VideoModeInfo&>(RenderAPICore::instance().getVideoModeInfo());
+		UINT32 numOutputs = videoModeInfo.getNumOutputs();
+		if (numOutputs > 0)
 		{
-			if (parentHWnd)
-			{
-				if (mDesc.toolWindow)
-					mWindowedStyleEx = WS_EX_TOOLWINDOW;
-				else
-					mWindowedStyle |= WS_CHILD;
-			}
-
-			if (!parentHWnd || mDesc.toolWindow)
-			{
-				if (mDesc.border == WindowBorder::None)
-					mWindowedStyle |= WS_POPUP;
-				else if (mDesc.border == WindowBorder::Fixed)
-					mWindowedStyle |= WS_OVERLAPPED | WS_BORDER | WS_CAPTION |
-					WS_SYSMENU | WS_MINIMIZEBOX;
-				else
-					mWindowedStyle |= WS_OVERLAPPEDWINDOW;
-			}
+			UINT32 actualMonitorIdx = std::min(mDesc.videoMode.getOutputIdx(), numOutputs - 1);
+			const D3D9VideoOutputInfo& outputInfo = static_cast<const D3D9VideoOutputInfo&>(videoModeInfo.getOutputInfo(actualMonitorIdx));
+			windowDesc.monitor = outputInfo.getMonitorHandle();
 		}
 
-		if (!externalHandle)
+		if (!windowDesc.external)
 		{
-			MONITORINFO monitorInfo;
-			RECT rc;
-
-			HMONITOR hMonitor = NULL;
-			const D3D9VideoModeInfo& videoModeInfo = static_cast<const D3D9VideoModeInfo&>(RenderAPICore::instance().getVideoModeInfo());
-			UINT32 numOutputs = videoModeInfo.getNumOutputs();
-			if (numOutputs > 0)
-			{
-				UINT32 actualMonitorIdx = std::min(mDesc.videoMode.getOutputIdx(), numOutputs - 1);
-				const D3D9VideoOutputInfo& outputInfo = static_cast<const D3D9VideoOutputInfo&>(videoModeInfo.getOutputInfo(actualMonitorIdx));
-				hMonitor = outputInfo.getMonitorHandle();
-			}
-
-			// If we didn't specified the adapter index, or if it didn't find it
-			if (hMonitor == NULL)
-			{
-				POINT windowAnchorPoint;
-
-				// Fill in anchor point.
-				windowAnchorPoint.x = mDesc.left;
-				windowAnchorPoint.y = mDesc.top;
-
-				// Get the nearest monitor to this window.
-				hMonitor = MonitorFromPoint(windowAnchorPoint, MONITOR_DEFAULTTOPRIMARY);
-			}
-
-			// Get the target monitor info		
-			memset(&monitorInfo, 0, sizeof(MONITORINFO));
-			monitorInfo.cbSize = sizeof(MONITORINFO);
-			GetMonitorInfo(hMonitor, &monitorInfo);
-
-			unsigned int winWidth, winHeight;
-			winWidth = mDesc.videoMode.getWidth();
-			winHeight = mDesc.videoMode.getHeight();
-
-			UINT32 left = mDesc.left;
-			UINT32 top = mDesc.top;
-
-			// No specified top left -> Center the window in the middle of the monitor
-			if (left == -1 || top == -1)
-			{
-				int screenw = monitorInfo.rcWork.right - monitorInfo.rcWork.left;
-				int screenh = monitorInfo.rcWork.bottom - monitorInfo.rcWork.top;
-
-				// clamp window dimensions to screen size
-				int outerw = (int(winWidth) < screenw) ? int(winWidth) : screenw;
-				int outerh = (int(winHeight) < screenh) ? int(winHeight) : screenh;
-
-				if (left == -1)
-					left = monitorInfo.rcWork.left + (screenw - outerw) / 2;
-				else if (hMonitor != NULL)
-					left += monitorInfo.rcWork.left;
-
-				if (top == -1)
-					top = monitorInfo.rcWork.top + (screenh - outerh) / 2;
-				else if (hMonitor != NULL)
-					top += monitorInfo.rcWork.top;
-			}
-			else if (hMonitor != NULL)
-			{
-				left += monitorInfo.rcWork.left;
-				top += monitorInfo.rcWork.top;
-			}
-
-			props.mWidth = mDesc.videoMode.getWidth();
-			props.mHeight = mDesc.videoMode.getHeight();
-			props.mTop = top;
-			props.mLeft = left;
-
-			DWORD dwStyle = 0;
-			DWORD dwStyleEx = 0;
-			if (mDesc.fullscreen && !mIsChild)
-			{
-				dwStyle = WS_VISIBLE | WS_CLIPCHILDREN | WS_POPUP;
-				props.mTop = monitorInfo.rcMonitor.top;
-				props.mLeft = monitorInfo.rcMonitor.left;
-			}
-			else
-			{
-				dwStyle = mWindowedStyle;
-				dwStyleEx = mWindowedStyleEx;
-
-				getAdjustedWindowSize(mDesc.videoMode.getWidth(), mDesc.videoMode.getHeight(), dwStyle, &winWidth, &winHeight);
-
-				if (!mDesc.outerDimensions)
-				{
-					// Calculate window dimensions required
-					// to get the requested client area
-					SetRect(&rc, 0, 0, props.mWidth, props.mHeight);
-					AdjustWindowRect(&rc, dwStyle, false);
-					props.mWidth = rc.right - rc.left;
-					props.mHeight = rc.bottom - rc.top;
-
-					// Clamp window rect to the nearest display monitor.
-					if (props.mLeft < monitorInfo.rcWork.left)
-						props.mLeft = monitorInfo.rcWork.left;
-
-					if (props.mTop < monitorInfo.rcWork.top)
-						props.mTop = monitorInfo.rcWork.top;
-
-					if (static_cast<int>(winWidth) > monitorInfo.rcWork.right - props.mLeft)
-						winWidth = monitorInfo.rcWork.right - props.mLeft;
-
-					if (static_cast<int>(winHeight) > monitorInfo.rcWork.bottom - props.mTop)
-						winHeight = monitorInfo.rcWork.bottom - props.mTop;
-				}
-			}
-
-			UINT classStyle = 0;
-			if (mDesc.enableDoubleClick)
-				classStyle |= CS_DBLCLKS;
-
-			// Register the window class
-			WNDCLASS wc = { classStyle, Win32Platform::_win32WndProc, 0, 0, hInst,
-				LoadIcon(0, IDI_APPLICATION), LoadCursor(NULL, IDC_ARROW),
-				(HBRUSH)GetStockObject(BLACK_BRUSH), 0, "D3D9Wnd" };
-			RegisterClass(&wc);
-
-			// Create our main window
-			// Pass pointer to self
-			mIsExternal = false;
-			mHWnd = CreateWindowEx(dwStyleEx, "D3D9Wnd", mDesc.title.c_str(), dwStyle,
-				props.mLeft, props.mTop, winWidth, winHeight, parentHWnd, 0, hInst, this);
-			mStyle = dwStyle;
-		}
-		else
-		{
-			mHWnd = externalHandle;
-			mIsExternal = true;
+			mShowOnSwap = mDesc.hideUntilSwap;
+			props.mHidden = mDesc.hideUntilSwap;
 		}
 
-		RECT rc;
-		GetWindowRect(mHWnd, &rc);
-		props.mTop = rc.top;
-		props.mLeft = rc.left;
+		mWindow = bs_new<Win32Window>(windowDesc);
 
-		GetClientRect(mHWnd, &rc);
-		props.mWidth = rc.right;
-		props.mHeight = rc.bottom;
+		props.mWidth = mWindow->getWidth();
+		props.mHeight = mWindow->getHeight();
+		props.mTop = mWindow->getTop();
+		props.mLeft = mWindow->getLeft();
 
 		mIsDepthBuffered = mDesc.depthBuffer;
-		props.mIsFullScreen = mDesc.fullscreen && !mIsChild;
-		props.mColorDepth = 32;
-		props.mActive = true;
 
 		D3D9RenderAPI* rs = static_cast<D3D9RenderAPI*>(RenderAPICore::instancePtr());
 		rs->registerWindow(*this);
@@ -271,7 +135,6 @@ namespace BansheeEngine
 		const D3D9VideoOutputInfo& outputInfo = static_cast<const D3D9VideoOutputInfo&>(videoModeInfo.getOutputInfo(actualMonitorIdx));
 
 		D3D9RenderWindowProperties& props = mProperties;
-		bool oldFullscreen = props.mIsFullScreen;
 
 		props.mWidth = width;
 		props.mHeight = height;
@@ -293,16 +156,7 @@ namespace BansheeEngine
 		mDevice->invalidate(this);
 		mDevice->acquire();
 
-		{
-			ScopedSpinLock lock(mLock);
-			mSyncedProperties.mTop = props.mTop;
-			mSyncedProperties.mLeft = props.mLeft;
-			mSyncedProperties.mWidth = props.mWidth;
-			mSyncedProperties.mHeight = props.mHeight;
-		}
-
-		RenderWindowManager::instance().notifySyncDataDirty(this);
-		RenderWindowManager::instance().notifyMovedOrResized(this);
+		_windowMovedOrResized();
 	}
 
 	void D3D9RenderWindowCore::setFullscreen(const VideoMode& mode)
@@ -322,15 +176,21 @@ namespace BansheeEngine
 			return;
 
 		props.mIsFullScreen = false;
-		mStyle = mWindowedStyle;
 		props.mWidth = width;
 		props.mHeight = height;
 
-		unsigned int winWidth, winHeight;
-		getAdjustedWindowSize(props.mWidth, props.mHeight, mStyle, &winWidth, &winHeight);
+		UINT32 winWidth = 0;
+		UINT32 winHeight = 0;
+
+		RECT rect;
+		SetRect(&rect, 0, 0, winWidth, winHeight);
+
+		AdjustWindowRect(&rect, mWindow->getStyle(), false);
+		winWidth = rect.right - rect.left;
+		winHeight = rect.bottom - rect.top;
 
 		// Deal with centering when switching down to smaller resolution
-		HMONITOR hMonitor = MonitorFromWindow(mHWnd, MONITOR_DEFAULTTONEAREST);
+		HMONITOR hMonitor = MonitorFromWindow(mWindow->getHWnd(), MONITOR_DEFAULTTONEAREST);
 		MONITORINFO monitorInfo;
 		memset(&monitorInfo, 0, sizeof(MONITORINFO));
 		monitorInfo.cbSize = sizeof(MONITORINFO);
@@ -342,39 +202,22 @@ namespace BansheeEngine
 		int left = screenw > int(winWidth) ? ((screenw - int(winWidth)) / 2) : 0;
 		int top = screenh > int(winHeight) ? ((screenh - int(winHeight)) / 2) : 0;
 
-		SetWindowLong(mHWnd, GWL_STYLE, mStyle);
-		SetWindowLong(mHWnd, GWL_EXSTYLE, mWindowedStyleEx);
-		SetWindowPos(mHWnd, HWND_NOTOPMOST, left, top, winWidth, winHeight,
+		SetWindowLong(mWindow->getHWnd(), GWL_STYLE, mWindow->getStyle());
+		SetWindowLong(mWindow->getHWnd(), GWL_EXSTYLE, mWindow->getStyleEx());
+		SetWindowPos(mWindow->getHWnd(), HWND_NOTOPMOST, left, top, winWidth, winHeight,
 			SWP_DRAWFRAME | SWP_FRAMECHANGED | SWP_NOACTIVATE);
 
 		mDevice->invalidate(this);
 		mDevice->acquire();
 
-		{
-			ScopedSpinLock lock(mLock);
-			mSyncedProperties.mTop = props.mTop;
-			mSyncedProperties.mLeft = props.mLeft;
-			mSyncedProperties.mWidth = props.mWidth;
-			mSyncedProperties.mHeight = props.mHeight;
-		}
-
-		RenderWindowManager::instance().notifySyncDataDirty(this);
-		RenderWindowManager::instance().notifyMovedOrResized(this);
+		_windowMovedOrResized();
 	}
 
 	void D3D9RenderWindowCore::setActive(bool state)
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
-		D3D9RenderWindowProperties& props = mProperties;
-
-		if (mHWnd)
-		{
-			if (state)
-				ShowWindow(mHWnd, SW_RESTORE);
-			else
-				ShowWindow(mHWnd, SW_SHOWMINNOACTIVE);
-		}
+		mWindow->setActive(state);
 
 		RenderWindowCore::setActive(state);
 	}
@@ -383,17 +226,8 @@ namespace BansheeEngine
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
-		D3D9RenderWindowProperties& props = mProperties;
-
 		mShowOnSwap = false;
-
-		if (!mIsExternal)
-		{
-			if (hidden)
-				ShowWindow(mHWnd, SW_HIDE);
-			else
-				ShowWindow(mHWnd, SW_SHOWNORMAL);
-		}
+		mWindow->setHidden(hidden);
 
 		RenderWindowCore::setHidden(hidden);
 	}
@@ -402,24 +236,21 @@ namespace BansheeEngine
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
-		if (mHWnd)
-			SendMessage(mHWnd, WM_SYSCOMMAND, SC_MINIMIZE, 0);
+		mWindow->minimize();
 	}
 
 	void D3D9RenderWindowCore::maximize()
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
-		if (mHWnd)
-			SendMessage(mHWnd, WM_SYSCOMMAND, SC_MAXIMIZE, 0);
+		mWindow->maximize();
 	}
 
 	void D3D9RenderWindowCore::restore()
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
-		if (mHWnd)
-			SendMessage(mHWnd, WM_SYSCOMMAND, SC_RESTORE, 0);
+		mWindow->restore();
 	}
 
 	void D3D9RenderWindowCore::move(INT32 top, INT32 left)
@@ -428,12 +259,12 @@ namespace BansheeEngine
 
 		D3D9RenderWindowProperties& props = mProperties;
 
-		if (mHWnd && !props.mIsFullScreen)
+		if (!props.mIsFullScreen)
 		{
-			props.mLeft = left;
-			props.mTop = top;
+			mWindow->move(top, left);
 
-			SetWindowPos(mHWnd, 0, top, left, 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
+			props.mTop = mWindow->getTop();
+			props.mLeft = mWindow->getLeft();
 
 			{
 				ScopedSpinLock lock(mLock);
@@ -451,16 +282,12 @@ namespace BansheeEngine
 
 		D3D9RenderWindowProperties& props = mProperties;
 
-		if (mHWnd && !props.mIsFullScreen)
+		if (!props.mIsFullScreen)
 		{
-			props.mWidth = width;
-			props.mHeight = height;
+			mWindow->resize(width, height);
 
-			unsigned int winWidth, winHeight;
-			getAdjustedWindowSize(width, height, mStyle, &winWidth, &winHeight);
-
-			SetWindowPos(mHWnd, 0, 0, 0, winWidth, winHeight,
-				SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE);
+			props.mWidth = mWindow->getWidth();
+			props.mHeight = mWindow->getHeight();
 
 			{
 				ScopedSpinLock lock(mLock);
@@ -539,12 +366,16 @@ namespace BansheeEngine
 	{
 		THROW_IF_NOT_CORE_THREAD;
 
-		D3D9RenderWindowProperties& props = mProperties;
-
-		if (!mHWnd || IsIconic(mHWnd))
+		if (!mWindow)
 			return;
-	
-		updateWindowRect();
+
+		mWindow->_windowMovedOrResized();
+
+		D3D9RenderWindowProperties& props = mProperties;
+		props.mTop = mWindow->getTop();
+		props.mLeft = mWindow->getLeft();
+		props.mWidth = mWindow->getWidth();
+		props.mHeight = mWindow->getHeight();
 
 		RenderWindowCore::_windowMovedOrResized();
 	}
@@ -552,34 +383,6 @@ namespace BansheeEngine
 	/************************************************************************/
 	/* 						D3D9 IMPLEMENTATION SPECIFIC                    */
 	/************************************************************************/
-
-	void D3D9RenderWindowCore::getAdjustedWindowSize(UINT32 clientWidth, UINT32 clientHeight,
-		DWORD style, UINT32* winWidth, UINT32* winHeight)
-	{
-		D3D9RenderWindowProperties& props = mProperties;
-
-		RECT rc;
-		SetRect(&rc, 0, 0, clientWidth, clientHeight);
-		AdjustWindowRect(&rc, style, false);
-		*winWidth = rc.right - rc.left;
-		*winHeight = rc.bottom - rc.top;
-
-		HMONITOR hMonitor = MonitorFromWindow(mHWnd, MONITOR_DEFAULTTONEAREST);
-
-		MONITORINFO monitorInfo;
-
-		memset(&monitorInfo, 0, sizeof(MONITORINFO));
-		monitorInfo.cbSize = sizeof(MONITORINFO);
-		GetMonitorInfo(hMonitor, &monitorInfo);
-
-		LONG maxW = monitorInfo.rcWork.right  - monitorInfo.rcWork.left;
-		LONG maxH = monitorInfo.rcWork.bottom - monitorInfo.rcWork.top;
-
-		if (*winWidth > (unsigned int)maxW)
-			*winWidth = maxW;
-		if (*winHeight > (unsigned int)maxH)
-			*winHeight = maxH;
-	}
 	
 	void D3D9RenderWindowCore::_buildPresentParameters(D3DPRESENT_PARAMETERS* presentParams) const
 	{	
@@ -595,7 +398,7 @@ namespace BansheeEngine
 		presentParams->SwapEffect = D3DSWAPEFFECT_DISCARD;
 		presentParams->BackBufferCount = 1;
 		presentParams->EnableAutoDepthStencil = mIsDepthBuffered;
-		presentParams->hDeviceWindow = mHWnd;
+		presentParams->hDeviceWindow = mWindow->getHWnd();
 		presentParams->BackBufferWidth = props.mWidth;
 		presentParams->BackBufferHeight = props.mHeight;
 		presentParams->FullScreen_RefreshRateInHz = props.mIsFullScreen ? mDisplayFrequency : 0;
@@ -689,7 +492,7 @@ namespace BansheeEngine
 
 	HWND D3D9RenderWindowCore::_getWindowHandle() const
 	{
-		return mHWnd;
+		return mWindow->getHWnd();
 	}
 
 	IDirect3DDevice9* D3D9RenderWindowCore::_getD3D9Device() const
@@ -718,44 +521,6 @@ namespace BansheeEngine
 		return mIsDepthBuffered;
 	}
 
-	void D3D9RenderWindowCore::updateWindowRect()
-	{
-		RECT rc;
-		BOOL result;
-
-		D3D9RenderWindowProperties& props = mProperties;
-
-		// Update top left parameters
-		result = GetWindowRect(_getWindowHandle(), &rc);
-		if (result == FALSE)
-		{
-			props.mTop = 0;
-			props.mLeft = 0;
-			props.mWidth = 0;
-			props.mHeight = 0;
-
-			return;
-		}
-		
-		props.mTop = rc.top;
-		props.mLeft = rc.left;
-
-		// Width and height represent drawable area only
-		result = GetClientRect(_getWindowHandle(), &rc);
-		if (result == FALSE)
-		{
-			props.mTop = 0;
-			props.mLeft = 0;
-			props.mWidth = 0;
-			props.mHeight = 0;
-
-			return;
-		}
-
-		props.mWidth = rc.right - rc.left;
-		props.mHeight = rc.bottom - rc.top;
-	}
-
 	bool D3D9RenderWindowCore::_validateDevice()
 	{
 		mDeviceValid = mDevice->validate(this);

+ 1 - 1
BansheeEditorExec/BsEditorExec.cpp

@@ -72,7 +72,7 @@ int CALLBACK WinMain(
 
 	__try
 	{
-		EditorApplication::startUp(RenderAPIPlugin::DX11);
+		EditorApplication::startUp(RenderAPIPlugin::DX9);
 		EditorApplication::instance().runMainLoop();
 		EditorApplication::shutDown();
 	}