From 4333b8145c0bf1892fa2a36806e7bcda526884e8 Mon Sep 17 00:00:00 2001 From: Andre von Houck Date: Sat, 18 Nov 2023 17:16:03 -0800 Subject: [PATCH] Error checking, screen.size, and automated testing. (#116) * More error checking with windows OpenGL * Add function to compute screen size. * Add functions to aid automated testing. --- src/windy/common.nim | 7 +++++++ src/windy/platforms/win32/platform.nim | 15 +++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/windy/common.nim b/src/windy/common.nim index 8c5d5da..e741e40 100644 --- a/src/windy/common.nim +++ b/src/windy/common.nim @@ -210,3 +210,10 @@ proc `[]=`*(headers: var seq[HttpHeader], key, value: string) = header.value = value return headers.add(HttpHeader(key: key, value: value)) + +proc size*(screen: Screen): IVec2 = + ## Returns the size of the screen. + ivec2( + (screen.right - screen.left).int32, + (screen.bottom - screen.top).int32 + ) diff --git a/src/windy/platforms/win32/platform.nim b/src/windy/platforms/win32/platform.nim index 6628c62..d8e178f 100644 --- a/src/windy/platforms/win32/platform.nim +++ b/src/windy/platforms/win32/platform.nim @@ -2354,3 +2354,18 @@ proc pollEvents*() = when defined(windyUseStdHttp): pollHttp() + +proc forceMousePos*(window: Window, mousePos: IVec2) = + ## Forces mouse position to a place. + ## This is used for simulating UI tests. + window.state.mousePos = mousePos + +proc forceButtonPress*(window: Window, button: Button) = + ## Forces button press. + ## This is used for simulating UI tests. + window.handleButtonPress(button) + +proc forceButtonReleased*(window: Window, button: Button) = + ## Forces button release. + ## This is used for simulating UI tests. + window.handleButtonRelease(button)