From 2a13d2e766795df4e5cb3a2612a0db611389e5c1 Mon Sep 17 00:00:00 2001 From: Ryan Oldenburg Date: Sat, 23 Oct 2021 22:03:45 -0500 Subject: [PATCH 1/3] fix typos --- src/windy/common.nim | 4 ++-- src/windy/platforms/win32/platform.nim | 2 +- src/windy/platforms/win32/utils.nim | 4 ++-- src/windy/platforms/win32/windefs.nim | 2 ++ 4 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/windy/common.nim b/src/windy/common.nim index dfcf125..b5df294 100644 --- a/src/windy/common.nim +++ b/src/windy/common.nim @@ -61,7 +61,7 @@ type KeyBackslash KeyCapsLock KeySemicolon - KeyApostraphe + KeyApostrophe KeyEnter KeyLeftShift KeyComma @@ -116,7 +116,7 @@ type NumpadDecimal NumpadEnter NumpadAdd - NumbadSubtract + NumpadSubtract NumpadMultiply NumpadDivide NumpadEqual diff --git a/src/windy/platforms/win32/platform.nim b/src/windy/platforms/win32/platform.nim index 196248b..932c3c2 100644 --- a/src/windy/platforms/win32/platform.nim +++ b/src/windy/platforms/win32/platform.nim @@ -101,7 +101,7 @@ proc registerWindowClass(windowClassName: string, wndProc: WNDPROC) = var wc: WNDCLASSEXW wc.cbSize = sizeof(WNDCLASSEXW).UINT - wc.style = CS_HREDRAW or CS_VREDRAW or CS_DBLCLKS + wc.style = CS_HREDRAW or CS_VREDRAW wc.lpfnWndProc = wndProc wc.hInstance = GetModuleHandleW(nil) wc.hCursor = LoadCursorW(0, IDC_ARROW) diff --git a/src/windy/platforms/win32/utils.nim b/src/windy/platforms/win32/utils.nim index 3a7c656..6bd7338 100644 --- a/src/windy/platforms/win32/utils.nim +++ b/src/windy/platforms/win32/utils.nim @@ -78,7 +78,7 @@ const scancodeToButton* = block: s[0x02b] = KeyBackslash s[0x03a] = KeyCapsLock s[0x027] = KeySemicolon - s[0x028] = KeyApostraphe + s[0x028] = KeyApostrophe s[0x01c] = KeyEnter s[0x02a] = KeyLeftShift s[0x033] = KeyComma @@ -133,7 +133,7 @@ const scancodeToButton* = block: s[0x053] = NumpadDecimal s[0x11c] = NumpadEnter s[0x04e] = NumpadAdd - s[0x04a] = NumbadSubtract + s[0x04a] = NumpadSubtract s[0x037] = NumpadMultiply s[0x135] = NumpadDivide s[0x059] = NumpadEqual diff --git a/src/windy/platforms/win32/windefs.nim b/src/windy/platforms/win32/windefs.nim index 5b7c7ab..0ad2139 100644 --- a/src/windy/platforms/win32/windefs.nim +++ b/src/windy/platforms/win32/windefs.nim @@ -555,6 +555,8 @@ proc SendMessageW*( lParam: LPARAM ): LRESULT {.importc, stdcall, dynlib: "User32".} +proc GetDoubleClickTime*(): UINT {.importc, stdcall, dynlib: "User32".} + proc ChoosePixelFormat*( hdc: HDC, ppfd: ptr PIXELFORMATDESCRIPTOR From 94688fc7dc2b352eb6c38058563f4969f3ac00fd Mon Sep 17 00:00:00 2001 From: Ryan Oldenburg Date: Sat, 23 Oct 2021 23:28:39 -0500 Subject: [PATCH 2/3] double click --- src/windy/common.nim | 1 + src/windy/platforms/win32/platform.nim | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/windy/common.nim b/src/windy/common.nim index b5df294..4ea9213 100644 --- a/src/windy/common.nim +++ b/src/windy/common.nim @@ -15,6 +15,7 @@ type MouseLeft MouseRight MouseMiddle + DoubleClick Key0 Key1 Key2 diff --git a/src/windy/platforms/win32/platform.nim b/src/windy/platforms/win32/platform.nim index 932c3c2..d62f82d 100644 --- a/src/windy/platforms/win32/platform.nim +++ b/src/windy/platforms/win32/platform.nim @@ -1,4 +1,4 @@ -import ../../common, ../../internal, unicode, utils, vmath, windefs +import ../../common, ../../internal, times, unicode, utils, vmath, windefs const windowClassName = "WINDY0" @@ -80,6 +80,8 @@ var onQuitRequest*: Callback initialized: bool + doubleClickInterval: float64 + prevClickTime: float64 windows: seq[Window] proc indexForHandle(windows: seq[Window], hWnd: HWND): int = @@ -325,7 +327,19 @@ proc handleButtonPress(window: Window, button: Button) = if window.onButtonPress != nil: window.onButtonPress(button) + if button == MouseLeft: + let + clickTime = cpuTime() + intervalSinceLastClick = clickTime - prevClickTime + if intervalSinceLastClick <= doubleClickInterval: + window.handleButtonPress(DoubleClick) + prevClickTime = clickTime + proc handleButtonRelease(window: Window, button: Button) = + if button == MouseLeft: + if DoubleClick in window.buttonDown: + window.handleButtonRelease(DoubleClick) + window.buttonDown.excl button window.buttonReleased.incl button if window.onButtonRelease != nil: @@ -472,6 +486,7 @@ proc init*() = discard SetProcessDpiAwarenessContext(DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE_V2) loadOpenGL() registerWindowClass(windowClassName, wndProc) + doubleClickInterval = GetDoubleClickTime().float64 / 1000 initialized = true proc pollEvents*() = From 2ee96e4a2e138cc4b2c4df26aba1cf7ed909a159 Mon Sep 17 00:00:00 2001 From: Ryan Oldenburg Date: Sat, 23 Oct 2021 23:47:06 -0500 Subject: [PATCH 3/3] double, triple, quadruple click --- src/windy/common.nim | 2 ++ src/windy/platforms/win32/platform.nim | 26 +++++++++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/windy/common.nim b/src/windy/common.nim index 4ea9213..5bedd6c 100644 --- a/src/windy/common.nim +++ b/src/windy/common.nim @@ -16,6 +16,8 @@ type MouseRight MouseMiddle DoubleClick + TripleClick + QuadrupleClick Key0 Key1 Key2 diff --git a/src/windy/platforms/win32/platform.nim b/src/windy/platforms/win32/platform.nim index d62f82d..e4b7ffc 100644 --- a/src/windy/platforms/win32/platform.nim +++ b/src/windy/platforms/win32/platform.nim @@ -81,7 +81,7 @@ var initialized: bool doubleClickInterval: float64 - prevClickTime: float64 + prevClickTimes: array[3, float64] windows: seq[Window] proc indexForHandle(windows: seq[Window], hWnd: HWND): int = @@ -329,14 +329,30 @@ proc handleButtonPress(window: Window, button: Button) = if button == MouseLeft: let - clickTime = cpuTime() - intervalSinceLastClick = clickTime - prevClickTime - if intervalSinceLastClick <= doubleClickInterval: + clickTime = epochTime() + clickIntervals = [ + clickTime - prevClickTimes[0], + clickTime - prevClickTimes[1], + clickTime - prevClickTimes[2] + ] + + if clickIntervals[0] <= doubleClickInterval: window.handleButtonPress(DoubleClick) - prevClickTime = clickTime + if clickIntervals[1] <= 2 * doubleClickInterval: + window.handleButtonPress(TripleClick) + if clickIntervals[2] <= 3 * doubleClickInterval: + window.handleButtonPress(QuadrupleClick) + + prevClickTimes[2] = prevClickTimes[1] + prevClickTimes[1] = prevClickTimes[0] + prevClickTimes[0] = clickTime proc handleButtonRelease(window: Window, button: Button) = if button == MouseLeft: + if QuadrupleClick in window.buttonDown: + window.handleButtonRelease(QuadrupleClick) + if TripleClick in window.buttonDown: + window.handleButtonRelease(TripleClick) if DoubleClick in window.buttonDown: window.handleButtonRelease(DoubleClick)