Mercurial > games > semicongine
comparison 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 |
comparison
equal
deleted
inserted
replaced
1255:2b5ca798f6d6 | 1256:bfb75c934f4e |
---|---|
94 of WM_SIZE: | 94 of WM_SIZE: |
95 if wParam == SIZE_MINIMIZED: | 95 if wParam == SIZE_MINIMIZED: |
96 currentEvents.add(Event(eventType: MinimizedWindow)) | 96 currentEvents.add(Event(eventType: MinimizedWindow)) |
97 elif wParam == SIZE_RESTORED: | 97 elif wParam == SIZE_RESTORED: |
98 currentEvents.add(Event(eventType: RestoredWindow)) | 98 currentEvents.add(Event(eventType: RestoredWindow)) |
99 of WM_SETFOCUS: | |
100 currentEvents.add(Event(eventType: GotFocus)) | |
101 of WM_KILLFOCUS: | |
102 currentEvents.add(Event(eventType: LostFocus)) | |
99 of WM_SETCURSOR: | 103 of WM_SETCURSOR: |
100 if LOWORD(lParam) == HTCLIENT: | 104 if LOWORD(lParam) == HTCLIENT: |
101 SetCursor(currentCursor) | 105 SetCursor(currentCursor) |
102 return 1 | 106 return 1 |
103 else: | 107 else: |
146 proc SetTitle*(window: NativeWindow, title: string) = | 150 proc SetTitle*(window: NativeWindow, title: string) = |
147 window.hwnd.SetWindowText(T(title)) | 151 window.hwnd.SetWindowText(T(title)) |
148 | 152 |
149 # inspired by the one and only, Raymond Chen | 153 # inspired by the one and only, Raymond Chen |
150 # https://devblogs.microsoft.com/oldnewthing/20100412-00/?p=14353 | 154 # https://devblogs.microsoft.com/oldnewthing/20100412-00/?p=14353 |
151 proc Fullscreen*(window: var NativeWindow, enable: bool) = | 155 proc SetFullscreen*(window: var NativeWindow, enable: bool) = |
152 let dwStyle: DWORD = GetWindowLong(window.hwnd, GWL_STYLE) | 156 let dwStyle: DWORD = GetWindowLong(window.hwnd, GWL_STYLE) |
153 if enable: | 157 if enable: |
154 var mi = MONITORINFO(cbSize: DWORD(sizeof(MONITORINFO))) | 158 var mi = MONITORINFO(cbSize: DWORD(sizeof(MONITORINFO))) |
155 if GetWindowPlacement(window.hwnd, addr window.g_wpPrev) and GetMonitorInfo(MonitorFromWindow(window.hwnd, MONITOR_DEFAULTTOPRIMARY), addr mi): | 159 if GetWindowPlacement(window.hwnd, addr window.g_wpPrev) and GetMonitorInfo(MonitorFromWindow(window.hwnd, MONITOR_DEFAULTTOPRIMARY), addr mi): |
156 SetWindowLong(window.hwnd, GWL_STYLE, dwStyle and (not WS_OVERLAPPEDWINDOW)) | 160 SetWindowLong(window.hwnd, GWL_STYLE, dwStyle and (not WS_OVERLAPPEDWINDOW)) |
158 else: | 162 else: |
159 SetWindowLong(window.hwnd, GWL_STYLE, dwStyle or WS_OVERLAPPEDWINDOW) | 163 SetWindowLong(window.hwnd, GWL_STYLE, dwStyle or WS_OVERLAPPEDWINDOW) |
160 SetWindowPlacement(window.hwnd, addr window.g_wpPrev) | 164 SetWindowPlacement(window.hwnd, addr window.g_wpPrev) |
161 SetWindowPos(window.hwnd, HWND(0), 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOZORDER or SWP_NOOWNERZORDER or SWP_FRAMECHANGED) | 165 SetWindowPos(window.hwnd, HWND(0), 0, 0, 0, 0, SWP_NOMOVE or SWP_NOSIZE or SWP_NOZORDER or SWP_NOOWNERZORDER or SWP_FRAMECHANGED) |
162 | 166 |
163 proc HideSystemCursor*(window: NativeWindow) = | 167 proc ShowSystemCursor*(window: NativeWindow, value: bool) = |
164 currentCursor = invisibleCursor | 168 if value == true: |
165 SetCursor(currentCursor) | 169 currentCursor = defaultCursor |
166 | 170 SetCursor(currentCursor) |
167 proc ShowSystemCursor*(window: NativeWindow) = | 171 else: |
168 currentCursor = defaultCursor | 172 currentCursor = invisibleCursor |
169 SetCursor(currentCursor) | 173 SetCursor(currentCursor) |
170 | 174 |
171 proc Destroy*(window: NativeWindow) = | 175 proc Destroy*(window: NativeWindow) = |
172 discard | 176 discard |
173 | 177 |
174 proc Size*(window: NativeWindow): (int, int) = | 178 proc Size*(window: NativeWindow): (int, int) = |