diff semiconginev2/rendering/platform/windows.nim @ 1256:bfb75c934f4e

add: window focus handling, improve window api a bit
author sam <sam@basx.dev>
date Sun, 28 Jul 2024 17:33:41 +0700
parents b0f4c8ccd49a
children
line wrap: on
line diff
--- a/semiconginev2/rendering/platform/windows.nim	Sun Jul 28 00:17:34 2024 +0700
+++ b/semiconginev2/rendering/platform/windows.nim	Sun Jul 28 17:33:41 2024 +0700
@@ -96,6 +96,10 @@
       currentEvents.add(Event(eventType: MinimizedWindow))
     elif wParam == SIZE_RESTORED:
       currentEvents.add(Event(eventType: RestoredWindow))
+  of WM_SETFOCUS:
+    currentEvents.add(Event(eventType: GotFocus))
+  of WM_KILLFOCUS:
+    currentEvents.add(Event(eventType: LostFocus))
   of WM_SETCURSOR:
     if LOWORD(lParam) == HTCLIENT:
       SetCursor(currentCursor)
@@ -148,7 +152,7 @@
 
 # inspired by the one and only, Raymond Chen
 # https://devblogs.microsoft.com/oldnewthing/20100412-00/?p=14353
-proc Fullscreen*(window: var NativeWindow, enable: bool) =
+proc SetFullscreen*(window: var NativeWindow, enable: bool) =
   let dwStyle: DWORD = GetWindowLong(window.hwnd, GWL_STYLE)
   if enable:
     var mi = MONITORINFO(cbSize: DWORD(sizeof(MONITORINFO)))
@@ -160,13 +164,13 @@
     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) =
-  currentCursor = invisibleCursor
-  SetCursor(currentCursor)
-
-proc ShowSystemCursor*(window: NativeWindow) =
-  currentCursor = defaultCursor
-  SetCursor(currentCursor)
+proc ShowSystemCursor*(window: NativeWindow, value: bool) =
+  if value == true:
+    currentCursor = defaultCursor
+    SetCursor(currentCursor)
+  else:
+    currentCursor = invisibleCursor
+    SetCursor(currentCursor)
 
 proc Destroy*(window: NativeWindow) =
   discard