修复高DPI下修改窗口大小异常BUG
This commit is contained in:
parent
58af967968
commit
649eaa6ee6
|
|
@ -54,36 +54,28 @@ void e2d::Game::start()
|
|||
Window::getInstance()->poll();
|
||||
|
||||
// ¿ªÊ¼ÓÎÏ·
|
||||
Duration interval;
|
||||
int wait = 0;
|
||||
|
||||
Duration interval;
|
||||
|
||||
_quit = false;
|
||||
_last = _now = Time::now();
|
||||
|
||||
while (!_quit)
|
||||
{
|
||||
_now = Time::now();
|
||||
interval = _now - _last;
|
||||
|
||||
if (_config.isVSyncEnabled())
|
||||
if (_config.isVSyncEnabled() || _frameInterval < interval)
|
||||
{
|
||||
_last += _frameInterval;
|
||||
__update();
|
||||
}
|
||||
else
|
||||
{
|
||||
interval = _now - _last;
|
||||
|
||||
if (_frameInterval < interval)
|
||||
wait = (_frameInterval - interval).milliseconds() - 1;
|
||||
if (wait > 1)
|
||||
{
|
||||
_last = _now;
|
||||
__update();
|
||||
}
|
||||
else
|
||||
{
|
||||
wait = (_frameInterval - interval).milliseconds() - 1;
|
||||
if (wait > 1)
|
||||
{
|
||||
std::this_thread::sleep_for(milliseconds(wait));
|
||||
}
|
||||
std::this_thread::sleep_for(milliseconds(wait));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -139,6 +131,7 @@ void e2d::Game::setConfig(const Config& config)
|
|||
if (_config.isVSyncEnabled() != config.isVSyncEnabled())
|
||||
{
|
||||
Renderer::getInstance()->discardDeviceResources();
|
||||
_last = _now;
|
||||
}
|
||||
|
||||
_config = config;
|
||||
|
|
|
|||
|
|
@ -219,6 +219,11 @@ void e2d::Window::setSize(int width, int height)
|
|||
this->_size = Size(width, height);
|
||||
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;
|
||||
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)
|
||||
{
|
||||
UINT ret = ::GetDpiForWindow(hWnd);
|
||||
_instance->_size = Size(width * 96.0 / ret, height * 96.0 / ret);
|
||||
UINT dpi = ::GetDpiForWindow(hWnd);
|
||||
_instance->_size = Size(width * 96.0 / dpi, height * 96.0 / dpi);
|
||||
}
|
||||
|
||||
// 如果程序接收到一个 WM_SIZE 消息,这个方法将调整渲染
|
||||
|
|
|
|||
Loading…
Reference in New Issue