From 971f43c586161c4dde69a831030b5f792962f770 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Tue, 4 May 2021 21:48:57 +0000 Subject: [PATCH] refactor wheel sensitivity. --- src/component/main.vue | 2 +- src/component/overlay.vue | 77 ++++++++++++++++++++++++++++++++++----- 2 files changed, 69 insertions(+), 10 deletions(-) diff --git a/src/component/main.vue b/src/component/main.vue index b8964763..e0f2e12a 100644 --- a/src/component/main.vue +++ b/src/component/main.vue @@ -120,7 +120,7 @@ control: { scroll: { inverse: true, - sensitivity: 1, + sensitivity: 0, }, clipboard: null, keyboard: { diff --git a/src/component/overlay.vue b/src/component/overlay.vue index 787f6fc9..2dc582d7 100644 --- a/src/component/overlay.vue +++ b/src/component/overlay.vue @@ -48,6 +48,9 @@ 'zPADwoFouPut3uzO12UyQSoclkotrt9ocAHKZnr8UhAP4bvg/gIs+UMfaaMTZTFOUkHo8/B/AEwAWjl5pV+j1dZ//g4xUMBo8YY/cqlcqhNvffAJxq40dmA5' + 'bFPoAjrev5EfwZQNfoKbju/u1ri/PvfgKYGMl+K2I7b8U7wA5wpgC/AgAA///Yyif1MZXzRQAAAABJRU5ErkJggg==) 4 4, crosshair' + const WHEEL_STEP = 50 // Delta threshold for a mouse wheel step + const WHEEL_LINE_HEIGHT = 19 + @Component({ name: 'neko-overlay', }) @@ -160,24 +163,80 @@ Vue.set(this, 'cursorPosition', pos) } + private wheelX = 0 + private wheelY = 0 + + // negative sensitivity can be acheived using increased step value + get wheelStep() { + let x = 20 * (window.devicePixelRatio || 1) + + if (this.scroll.sensitivity < 0) { + x *= Math.abs(this.scroll.sensitivity) + 1 + } + + return x + } + + // sensitivity can only be positive + get wheelSensitivity() { + let x = 1 + + if (this.scroll.sensitivity > 0) { + x = Math.abs(this.scroll.sensitivity) + 1 + } + + if (this.scroll.inverse) { + x *= -1 + } + + return x + } + onWheel(e: WheelEvent) { if (!this.isControling) { return } - let x = e.deltaX - let y = e.deltaY + this.setMousePos(e) - if (this.scroll.inverse) { - x *= -1 - y *= -1 + let dx = e.deltaX + let dy = e.deltaY + + if (e.deltaMode !== 0) { + dx *= WHEEL_LINE_HEIGHT + dy *= WHEEL_LINE_HEIGHT } - x = Math.min(Math.max(x, -this.scroll.sensitivity), this.scroll.sensitivity) - y = Math.min(Math.max(y, -this.scroll.sensitivity), this.scroll.sensitivity) + this.wheelX += dx + this.wheelY += dy - this.setMousePos(e) - this.webrtc.send('wheel', { x, y }) + console.log(typeof dx, dx, typeof dy, dy, this.wheelX, this.wheelY) + + let x = 0 + if (Math.abs(this.wheelX) >= this.wheelStep) { + if (this.wheelX < 0) { + x = this.wheelSensitivity * -1 + } else if (this.wheelX > 0) { + x = this.wheelSensitivity + } + + this.wheelX = 0 + } + + let y = 0 + if (Math.abs(this.wheelY) >= this.wheelStep) { + if (this.wheelY < 0) { + y = this.wheelSensitivity * -1 + } else if (this.wheelY > 0) { + y = this.wheelSensitivity + } + + this.wheelY = 0 + } + + if (x != 0 || y != 0) { + this.webrtc.send('wheel', { x, y }) + } } onMouseMove(e: MouseEvent) {