app: support horizontal scrolling on Windows and Linux

Fixes #181.

Signed-off-by: pierre <pierre.curto@gmail.com>
This commit is contained in:
Pierre Curto
2020-11-26 18:37:00 +01:00
committed by Elias Naur
parent 4f8150cd59
commit 4c3de5f5d2
3 changed files with 19 additions and 3 deletions
+9 -3
View File
@@ -271,7 +271,9 @@ func windowProc(hwnd syscall.Handle, msg uint32, wParam, lParam uintptr) uintptr
Time: windows.GetMessageTime(),
})
case windows.WM_MOUSEWHEEL:
w.scrollEvent(wParam, lParam)
w.scrollEvent(wParam, lParam, false)
case windows.WM_MOUSEHWHEEL:
w.scrollEvent(wParam, lParam, true)
case windows.WM_DESTROY:
windows.PostQuitMessage(0)
case windows.WM_PAINT:
@@ -352,7 +354,7 @@ func coordsFromlParam(lParam uintptr) (int, int) {
return x, y
}
func (w *window) scrollEvent(wParam, lParam uintptr) {
func (w *window) scrollEvent(wParam, lParam uintptr, horizontal bool) {
x, y := coordsFromlParam(lParam)
// The WM_MOUSEWHEEL coordinates are in screen coordinates, in contrast
// to other mouse events.
@@ -360,12 +362,16 @@ func (w *window) scrollEvent(wParam, lParam uintptr) {
windows.ScreenToClient(w.hwnd, &np)
p := f32.Point{X: float32(np.X), Y: float32(np.Y)}
dist := float32(int16(wParam >> 16))
sp := f32.Point{Y: -dist}
if horizontal {
sp.X, sp.Y = sp.Y, sp.X
}
w.w.Event(pointer.Event{
Type: pointer.Scroll,
Source: pointer.Mouse,
Position: p,
Buttons: w.pointerBtns,
Scroll: f32.Point{Y: -dist},
Scroll: sp,
Time: windows.GetMessageTime(),
})
}
+9
View File
@@ -346,6 +346,15 @@ func (h *x11EventHandler) handleEvents() bool {
// scroll down
ev.Type = pointer.Scroll
ev.Scroll.Y = +scrollScale
case 6:
// http://xahlee.info/linux/linux_x11_mouse_button_number.html
// scroll left
ev.Type = pointer.Scroll
ev.Scroll.X = -scrollScale * 2
case 7:
// scroll right
ev.Type = pointer.Scroll
ev.Scroll.X = +scrollScale * 2
default:
continue
}
+1
View File
@@ -142,6 +142,7 @@ const (
WM_MBUTTONUP = 0x0208
WM_MOUSEMOVE = 0x0200
WM_MOUSEWHEEL = 0x020A
WM_MOUSEHWHEEL = 0x020E
WM_PAINT = 0x000F
WM_CLOSE = 0x0010
WM_QUIT = 0x0012