//----------------------------------------------------------------------------- void D3D9RenderWindow::_beginUpdate() { // External windows should update per frame // since it dosen't get the window resize/move messages. if (mIsExternal) { updateWindowRect(); } if (mWidth == 0 || mHeight == 0) { mDeviceValid = false; return; } D3D9RenderSystem::getDeviceManager()->setActiveRenderTargetDevice(mDevice); // Check that device can be used for rendering operations. mDeviceValid = mDevice->validate(this); if (mDeviceValid) { // Finish window / fullscreen mode switch. if (_getSwitchingFullscreen()) { _finishSwitchingFullscreen(); // have to re-validate since this may have altered dimensions mDeviceValid = mDevice->validate(this); } } RenderWindow::_beginUpdate(); }
void D3D9RenderWindow::windowMovedOrResized() { if (!mHWnd || IsIconic(mHWnd)) return; updateWindowRect(); }
void D3D9RenderWindow::resize(unsigned int width, unsigned int height) { if (!mIsExternal) { if (mHWnd && !mIsFullScreen) { unsigned int winWidth, winHeight; adjustWindow(width, height, &winWidth, &winHeight); SetWindowPos(mHWnd, 0, 0, 0, winWidth, winHeight, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE); } } else updateWindowRect(); }
void D3D9RenderWindow::_finishSwitchingFullscreen() { if(mIsFullScreen) { // Need to reset the region on the window sometimes, when the // windowed mode was constrained by desktop HRGN hRgn = CreateRectRgn(0,0,mWidth, mHeight); SetWindowRgn(mHWnd, hRgn, FALSE); } else { // When switching back to windowed mode, need to reset window size // after device has been restored // We may have had a resize event which polluted our desired sizes if (mWidth != mDesiredWidth || mHeight != mDesiredHeight) { mWidth = mDesiredWidth; mHeight = mDesiredHeight; } unsigned int winWidth, winHeight; adjustWindow(mWidth, mHeight, &winWidth, &winHeight); // deal with centering when switching down to smaller resolution HMONITOR hMonitor = MonitorFromWindow(mHWnd, MONITOR_DEFAULTTONEAREST); MONITORINFO monitorInfo; memset(&monitorInfo, 0, sizeof(MONITORINFO)); monitorInfo.cbSize = sizeof(MONITORINFO); GetMonitorInfo(hMonitor, &monitorInfo); LONG screenw = monitorInfo.rcWork.right - monitorInfo.rcWork.left; LONG screenh = monitorInfo.rcWork.bottom - monitorInfo.rcWork.top; // When switching from a low fullscreen res to windowed mode in a high // res desktop need to release this low res constraint on the window // region otherwise we will not be able to make the window larger // than the low fullscreen res we were just at SetWindowRgn(mHWnd, NULL, TRUE); int left = screenw > winWidth ? ((screenw - winWidth) / 2) : 0; int top = screenh > winHeight ? ((screenh - winHeight) / 2) : 0; SetWindowPos(mHWnd, HWND_NOTOPMOST, left, top, winWidth, winHeight, SWP_DRAWFRAME | SWP_FRAMECHANGED | SWP_NOACTIVATE); updateWindowRect(); } mSwitchingFullscreen = false; }
void D3D9RenderWindow::setFullscreen(bool fullScreen, unsigned int width, unsigned int height) { if (fullScreen != mIsFullScreen || width != mWidth || height != mHeight) { if (fullScreen != mIsFullScreen) mSwitchingFullscreen = true; bool oldFullscreen = mIsFullScreen; mIsFullScreen = fullScreen; mWidth = mDesiredWidth = width; mHeight = mDesiredHeight = height; if (fullScreen) { // Get the nearest monitor to this window. HMONITOR hMonitor = MonitorFromWindow(mHWnd, MONITOR_DEFAULTTONEAREST); // Get monitor info MONITORINFO monitorInfo; memset(&monitorInfo, 0, sizeof(MONITORINFO)); monitorInfo.cbSize = sizeof(MONITORINFO); GetMonitorInfo(hMonitor, &monitorInfo); mTop = monitorInfo.rcMonitor.top; mLeft = monitorInfo.rcMonitor.left; // need different ordering here if (oldFullscreen) { // was previously fullscreen, just changing the resolution SetWindowPos(mHWnd, HWND_TOPMOST, mLeft, mTop, width, height, SWP_NOACTIVATE); } else { SetWindowPos(mHWnd, HWND_TOPMOST, mLeft, mTop, width, height, SWP_NOACTIVATE); //MoveWindow(mHWnd, mLeft, mTop, mWidth, mHeight, FALSE); SetWindowLong(mHWnd, GWL_STYLE, getWindowStyle(mIsFullScreen)); SetWindowPos(mHWnd, 0, 0,0, 0,0, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER | SWP_FRAMECHANGED); } } else { // Calculate window dimensions required // to get the requested client area unsigned int winWidth, winHeight; winWidth = mWidth; winHeight = mHeight; adjustWindow(mWidth, mHeight, &winWidth, &winHeight); SetWindowLong(mHWnd, GWL_STYLE, getWindowStyle(mIsFullScreen)); SetWindowPos(mHWnd, HWND_NOTOPMOST, 0, 0, winWidth, winHeight, SWP_DRAWFRAME | SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOACTIVATE); // Note that we also set the position in the restoreLostDevice method // via _finishSwitchingFullScreen // Update the current rect. updateWindowRect(); } // Have to release & trigger device reset // NB don't use windowMovedOrResized since Win32 doesn't know // about the size change yet mDevice->invalidate(this); // Notify viewports of resize ViewportList::iterator it = mViewportList.begin(); while( it != mViewportList.end() ) (*it++).second->_updateDimensions(); } }