Mercurial > games > semicongine
changeset 647:6735f6a2de7a
add: working fullscreen for windows (tested)
author | Sam <sam@basx.dev> |
---|---|
date | Wed, 03 May 2023 06:54:37 -0700 |
parents | d52094e438c2 |
children | 4374c13b9b95 |
files | src/semicongine/engine.nim src/semicongine/platform/linux/window.nim src/semicongine/platform/windows/window.nim |
diffstat | 3 files changed, 9 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/semicongine/engine.nim Wed May 03 20:11:16 2023 +0700 +++ b/src/semicongine/engine.nim Wed May 03 06:54:37 2023 -0700 @@ -168,4 +168,4 @@ func windowWasResized*(engine: Engine): auto = engine.input.windowWasResized func showSystemCursor*(engine: Engine) = engine.window.showSystemCursor() func hideSystemCursor*(engine: Engine) = engine.window.hideSystemCursor() -proc fullscreen*(engine: Engine, enable: bool) = engine.window.fullscreen(enable) +proc fullscreen*(engine: var Engine, enable: bool) = engine.window.fullscreen(enable)
--- a/src/semicongine/platform/linux/window.nim Wed May 03 20:11:16 2023 +0700 +++ b/src/semicongine/platform/linux/window.nim Wed May 03 06:54:37 2023 -0700 @@ -78,7 +78,7 @@ checkXlibResult display.XFreePixmap(pixmap) return NativeWindow(display: display, window: window, emptyCursor: empty_cursor) -proc fullscreen*(window: NativeWindow, enable: bool) = +proc fullscreen*(window: var NativeWindow, enable: bool) = var wm_state = window.display.XInternAtom("_NET_WM_STATE", 0) op = (if enable: "_NET_WM_STATE_ADD" else: "_NET_WM_STATE_REMOVE")
--- a/src/semicongine/platform/windows/window.nim Wed May 03 20:11:16 2023 +0700 +++ b/src/semicongine/platform/windows/window.nim Wed May 03 06:54:37 2023 -0700 @@ -70,6 +70,7 @@ lpfnWndProc: WindowHandler, hInstance: result.hInstance, lpszClassName: windowClassName, + hcursor: LoadCursor(HINSTANCE(0), IDC_ARROW), ) if(RegisterClassEx(addr(windowClass)) == 0): @@ -87,20 +88,21 @@ nil ) + result.g_wpPrev.length = UINT(sizeof(WINDOWPLACEMENT)) discard ShowWindow(result.hwnd, SW_SHOW) # inspired by the one and only, Raymond Chen # https://devblogs.microsoft.com/oldnewthing/20100412-00/?p=14353 -proc fullscreen*(window: NativeWindow, enable: bool) = +proc fullscreen*(window: var NativeWindow, enable: bool) = let dwStyle: DWORD = GetWindowLong(window.hwnd, GWL_STYLE) - if (dwStyle and WS_OVERLAPPEDWINDOW): - var mi: MONITORINFO - if GetWindowPlacement(window.hwnd, unsafeAddr window.g_wpPrev) and GetMonitorInfo(MonitorFromWindow(window.hwnd, MONITOR_DEFAULTTOPRIMARY), addr mi): + if enable: + var mi = MONITORINFO(cbSize: DWORD(sizeof(MONITORINFO))) + if GetWindowPlacement(window.hwnd, addr window.g_wpPrev) and GetMonitorInfo(MonitorFromWindow(window.hwnd, MONITOR_DEFAULTTOPRIMARY), addr mi): SetWindowLong(window.hwnd, GWL_STYLE, dwStyle and (not WS_OVERLAPPEDWINDOW)) SetWindowPos(window.hwnd, HWND_TOP, mi.rcMonitor.left, mi.rcMonitor.top, mi.rcMonitor.right - mi.rcMonitor.left, mi.rcMonitor.bottom - mi.rcMonitor.top, SWP_NOOWNERZORDER or SWP_FRAMECHANGED) else: SetWindowLong(window.hwnd, GWL_STYLE, dwStyle or WS_OVERLAPPEDWINDOW) - SetWindowPlacement(window.hwnd, unsafeAddr window.g_wpPrev) + SetWindowPlacement(window.hwnd, addr window.g_wpPrev) SetWindowPos(window.hwnd, HWND(0), 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOZORDER or SWP_NOOWNERZORDER or SWP_FRAMECHANGED) proc hideSystemCursor*(window: NativeWindow) =