Fix fullscreen rendering
This commit is contained in:
parent
160ca7070f
commit
f9232f314b
@ -8,10 +8,10 @@ namespace nf::client {
|
||||
Window::Window(const char* windowTitle)
|
||||
: m_handle(nullptr)
|
||||
, m_wndClassName("NothinFancyWindow")
|
||||
, m_windowedStyle(WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX)
|
||||
, m_fullscreenStyle(WS_POPUP)
|
||||
, m_width()
|
||||
, m_height()
|
||||
, m_styleWindowed(WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX)
|
||||
, m_styleFullscreen(WS_POPUP)
|
||||
, m_currentWidth()
|
||||
, m_currentHeight()
|
||||
{
|
||||
NFLog("Creating window");
|
||||
|
||||
@ -27,9 +27,8 @@ namespace nf::client {
|
||||
return m_handle;
|
||||
}
|
||||
|
||||
void Window::setDisplay(DisplayConfig config) {
|
||||
void Window::setDisplay(DisplayConfig& config) {
|
||||
NFLog("Setting window display");
|
||||
m_width = config.width, m_height = config.height;
|
||||
|
||||
// TODO: Only use "active" monitor when starting windowed
|
||||
POINT cursor = {};
|
||||
@ -44,17 +43,19 @@ namespace nf::client {
|
||||
|
||||
switch (config.mode) {
|
||||
case DisplayMode::Windowed: {
|
||||
SetWindowLongPtr(m_handle, GWL_STYLE, m_windowedStyle);
|
||||
windowX = monitorX + (monitorWidth / 2) - (m_width / 2), windowY = monitorY + (monitorHeight / 2) - (m_height / 2);
|
||||
SetWindowLongPtr(m_handle, GWL_STYLE, m_styleWindowed);
|
||||
m_currentWidth = config.width, m_currentHeight = config.height;
|
||||
windowX = monitorX + (monitorWidth / 2) - (m_currentWidth / 2), windowY = monitorY + (monitorHeight / 2) - (m_currentHeight / 2);
|
||||
SIZE windowSize = getWindowSize();
|
||||
windowWidth = windowSize.cx, windowHeight = windowSize.cy;
|
||||
break;
|
||||
}
|
||||
|
||||
case DisplayMode::Fullscreen: {
|
||||
SetWindowLongPtr(m_handle, GWL_STYLE, m_fullscreenStyle);
|
||||
SetWindowLongPtr(m_handle, GWL_STYLE, m_styleFullscreen);
|
||||
windowX = monitorX, windowY = monitorY;
|
||||
windowWidth = monitorWidth, windowHeight = monitorHeight;
|
||||
config.width = windowWidth, config.height = windowHeight;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -94,7 +95,7 @@ namespace nf::client {
|
||||
|
||||
case WM_DPICHANGED: {
|
||||
// Prevents automatic window resize on DPI change (don't apply to fullscreen)
|
||||
if (GetWindowLongPtr(hWnd, GWL_STYLE) & WS_POPUP)
|
||||
if (GetWindowLongPtr(hWnd, GWL_STYLE) == wnd->m_styleFullscreen)
|
||||
return 0;
|
||||
|
||||
SIZE windowSize = wnd->getWindowSize();
|
||||
@ -112,9 +113,9 @@ namespace nf::client {
|
||||
|
||||
SIZE Window::getWindowSize() {
|
||||
RECT cli = {};
|
||||
cli.right = m_width;
|
||||
cli.bottom = m_height;
|
||||
AdjustWindowRectExForDpi(&cli, m_windowedStyle, FALSE, NULL, GetDpiForWindow(m_handle));
|
||||
cli.right = m_currentWidth;
|
||||
cli.bottom = m_currentHeight;
|
||||
AdjustWindowRectExForDpi(&cli, m_styleWindowed, FALSE, NULL, GetDpiForWindow(m_handle));
|
||||
int width = cli.right - cli.left, height = cli.bottom - cli.top;
|
||||
return { width, height };
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ namespace nf::client {
|
||||
Window(const char* windowTitle);
|
||||
|
||||
HWND getHandle() const;
|
||||
void setDisplay(DisplayConfig config);
|
||||
void setDisplay(DisplayConfig& config);
|
||||
void runLoop();
|
||||
void show(bool show = true);
|
||||
|
||||
@ -24,9 +24,9 @@ namespace nf::client {
|
||||
HWND m_handle;
|
||||
|
||||
const char* m_wndClassName;
|
||||
const DWORD m_windowedStyle;
|
||||
const DWORD m_fullscreenStyle;
|
||||
const DWORD m_styleWindowed;
|
||||
const DWORD m_styleFullscreen;
|
||||
|
||||
unsigned int m_width, m_height;
|
||||
unsigned int m_currentWidth, m_currentHeight;
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user