mirror of
https://github.com/m1k1o/neko.git
synced 2024-07-24 14:40:50 +12:00
refactor wheel sensitivity.
This commit is contained in:
parent
b39022c4de
commit
971f43c586
@ -120,7 +120,7 @@
|
|||||||
control: {
|
control: {
|
||||||
scroll: {
|
scroll: {
|
||||||
inverse: true,
|
inverse: true,
|
||||||
sensitivity: 1,
|
sensitivity: 0,
|
||||||
},
|
},
|
||||||
clipboard: null,
|
clipboard: null,
|
||||||
keyboard: {
|
keyboard: {
|
||||||
|
@ -48,6 +48,9 @@
|
|||||||
'zPADwoFouPut3uzO12UyQSoclkotrt9ocAHKZnr8UhAP4bvg/gIs+UMfaaMTZTFOUkHo8/B/AEwAWjl5pV+j1dZ//g4xUMBo8YY/cqlcqhNvffAJxq40dmA5' +
|
'zPADwoFouPut3uzO12UyQSoclkotrt9ocAHKZnr8UhAP4bvg/gIs+UMfaaMTZTFOUkHo8/B/AEwAWjl5pV+j1dZ//g4xUMBo8YY/cqlcqhNvffAJxq40dmA5' +
|
||||||
'bFPoAjrev5EfwZQNfoKbju/u1ri/PvfgKYGMl+K2I7b8U7wA5wpgC/AgAA///Yyif1MZXzRQAAAABJRU5ErkJggg==) 4 4, crosshair'
|
'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({
|
@Component({
|
||||||
name: 'neko-overlay',
|
name: 'neko-overlay',
|
||||||
})
|
})
|
||||||
@ -160,25 +163,81 @@
|
|||||||
Vue.set(this, 'cursorPosition', pos)
|
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) {
|
onWheel(e: WheelEvent) {
|
||||||
if (!this.isControling) {
|
if (!this.isControling) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
let x = e.deltaX
|
this.setMousePos(e)
|
||||||
let y = e.deltaY
|
|
||||||
|
|
||||||
if (this.scroll.inverse) {
|
let dx = e.deltaX
|
||||||
x *= -1
|
let dy = e.deltaY
|
||||||
y *= -1
|
|
||||||
|
if (e.deltaMode !== 0) {
|
||||||
|
dx *= WHEEL_LINE_HEIGHT
|
||||||
|
dy *= WHEEL_LINE_HEIGHT
|
||||||
}
|
}
|
||||||
|
|
||||||
x = Math.min(Math.max(x, -this.scroll.sensitivity), this.scroll.sensitivity)
|
this.wheelX += dx
|
||||||
y = Math.min(Math.max(y, -this.scroll.sensitivity), this.scroll.sensitivity)
|
this.wheelY += dy
|
||||||
|
|
||||||
this.setMousePos(e)
|
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 })
|
this.webrtc.send('wheel', { x, y })
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onMouseMove(e: MouseEvent) {
|
onMouseMove(e: MouseEvent) {
|
||||||
if (!this.isControling) {
|
if (!this.isControling) {
|
||||||
|
Loading…
Reference in New Issue
Block a user