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