changeset 1152:2ce0c75f5715

fix: windows cursor not visible on border 1
author sam <sam@basx.dev>
date Sat, 15 Jun 2024 15:20:02 +0700
parents 911e43f0ee50
children 9bdab0729b99
files semicongine/platform/windows/window.nim
diffstat 1 files changed, 12 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/semicongine/platform/windows/window.nim	Sat Jun 15 15:13:31 2024 +0700
+++ b/semicongine/platform/windows/window.nim	Sat Jun 15 15:20:02 2024 +0700
@@ -22,9 +22,12 @@
   if value == 0:
     raise newException(Exception, "Win32 error: " & astToStr(call) & " returned " & $value)
 
-let andCursorMask = [0xff]
-let xorCursorMask = [0x00]
-let invisibleCursor = CreateCursor(HINSTANCE(0), 0, 0, 1, 1, pointer(addr andCursorMask), pointer(addr xorCursorMask))
+let
+  andCursorMask = [0xff]
+  xorCursorMask = [0x00]
+  invisibleCursor = CreateCursor(HINSTANCE(0), 0, 0, 1, 1, pointer(addr andCursorMask), pointer(addr xorCursorMask))
+  defaultCursor = LoadCursor(HINSTANCE(0), IDC_ARROW)
+var currentCursor = defaultCursor
 
 proc MapLeftRightKeys(key: INT, lparam: LPARAM): INT =
   case key
@@ -65,7 +68,7 @@
     currentEvents.add(Event(eventType: events.MouseWheel, amount: float32(GET_WHEEL_DELTA_WPARAM(wParam)) / WHEEL_DELTA))
   of WM_SETCURSOR:
     if LOWORD(lParam) == HTCLIENT:
-      SetCursor(invisibleCursor)
+      SetCursor(currentCursor)
       return 1
     else:
       return DefWindowProc(hwnd, uMsg, wParam, lParam)
@@ -89,8 +92,7 @@
       lpfnWndProc: WindowHandler,
       hInstance: result.hInstance,
       lpszClassName: windowClassName,
-      # hcursor: LoadCursor(HINSTANCE(0), IDC_ARROW),
-      hcursor: invisibleCursor,
+       hcursor: currentCursor,
     )
 
   if(RegisterClassEx(addr(windowClass)) == 0):
@@ -129,12 +131,12 @@
     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) =
-  discard
-  # discard ShowCursor(false)
+  currentCursor = invisibleCursor
+  SetCursor(currentCursor)
 
 proc ShowSystemCursor*(window: NativeWindow) =
-  discard
-  # discard ShowCursor(true)
+  currentCursor = defaultCursor
+  SetCursor(currentCursor)
 
 proc Destroy*(window: NativeWindow) =
   discard