修复高DPI下修改窗口大小异常BUG
This commit is contained in:
		
							parent
							
								
									58af967968
								
							
						
					
					
						commit
						649eaa6ee6
					
				|  | @ -54,8 +54,8 @@ void e2d::Game::start() | ||||||
| 	Window::getInstance()->poll(); | 	Window::getInstance()->poll(); | ||||||
| 
 | 
 | ||||||
| 	// ¿ªÊ¼ÓÎÏ·
 | 	// ¿ªÊ¼ÓÎÏ·
 | ||||||
| 	Duration interval; |  | ||||||
| 	int wait = 0; | 	int wait = 0; | ||||||
|  | 	Duration interval; | ||||||
| 
 | 
 | ||||||
| 	_quit = false; | 	_quit = false; | ||||||
| 	_last = _now = Time::now(); | 	_last = _now = Time::now(); | ||||||
|  | @ -63,18 +63,11 @@ void e2d::Game::start() | ||||||
| 	while (!_quit) | 	while (!_quit) | ||||||
| 	{ | 	{ | ||||||
| 		_now = Time::now(); | 		_now = Time::now(); | ||||||
| 
 |  | ||||||
| 		if (_config.isVSyncEnabled()) |  | ||||||
| 		{ |  | ||||||
| 			__update(); |  | ||||||
| 		} |  | ||||||
| 		else |  | ||||||
| 		{ |  | ||||||
| 		interval = _now - _last; | 		interval = _now - _last; | ||||||
| 
 | 
 | ||||||
| 			if (_frameInterval < interval) | 		if (_config.isVSyncEnabled() || _frameInterval < interval) | ||||||
| 		{ | 		{ | ||||||
| 				_last = _now; | 			_last += _frameInterval; | ||||||
| 			__update(); | 			__update(); | ||||||
| 		} | 		} | ||||||
| 		else | 		else | ||||||
|  | @ -86,7 +79,6 @@ void e2d::Game::start() | ||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	} |  | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| void e2d::Game::__update() | void e2d::Game::__update() | ||||||
|  | @ -139,6 +131,7 @@ void e2d::Game::setConfig(const Config& config) | ||||||
| 	if (_config.isVSyncEnabled() != config.isVSyncEnabled()) | 	if (_config.isVSyncEnabled() != config.isVSyncEnabled()) | ||||||
| 	{ | 	{ | ||||||
| 		Renderer::getInstance()->discardDeviceResources(); | 		Renderer::getInstance()->discardDeviceResources(); | ||||||
|  | 		_last = _now; | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	_config = config; | 	_config = config; | ||||||
|  |  | ||||||
|  | @ -219,6 +219,11 @@ void e2d::Window::setSize(int width, int height) | ||||||
| 	this->_size = Size(width, height); | 	this->_size = Size(width, height); | ||||||
| 	if (_hWnd) | 	if (_hWnd) | ||||||
| 	{ | 	{ | ||||||
|  | 		float dpiScaleX = 0.f, dpiScaleY = 0.f; | ||||||
|  | 		Renderer::getFactory()->GetDesktopDpi(&dpiScaleX, &dpiScaleY); | ||||||
|  | 
 | ||||||
|  | 		width = static_cast<int>(ceil(width * dpiScaleX / 96.f)); | ||||||
|  | 		height = static_cast<int>(ceil(height * dpiScaleY / 96.f)); | ||||||
| 		// 计算窗口大小
 | 		// 计算窗口大小
 | ||||||
| 		DWORD dwStyle = WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX &~WS_THICKFRAME; | 		DWORD dwStyle = WS_OVERLAPPEDWINDOW & ~WS_MAXIMIZEBOX &~WS_THICKFRAME; | ||||||
| 		RECT wr = { 0, 0, static_cast<LONG>(width), static_cast<LONG>(height) }; | 		RECT wr = { 0, 0, static_cast<LONG>(width), static_cast<LONG>(height) }; | ||||||
|  | @ -426,8 +431,8 @@ LRESULT e2d::Window::WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPar | ||||||
| 
 | 
 | ||||||
| 		if (wParam == SIZE_RESTORED) | 		if (wParam == SIZE_RESTORED) | ||||||
| 		{ | 		{ | ||||||
| 			UINT ret = ::GetDpiForWindow(hWnd); | 			UINT dpi = ::GetDpiForWindow(hWnd); | ||||||
| 			_instance->_size = Size(width * 96.0 / ret, height * 96.0 / ret); | 			_instance->_size = Size(width * 96.0 / dpi, height * 96.0 / dpi); | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		// 如果程序接收到一个 WM_SIZE 消息,这个方法将调整渲染
 | 		// 如果程序接收到一个 WM_SIZE 消息,这个方法将调整渲染
 | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue