greatly improve scrolling functionality
This commit is contained in:
parent
23eddd1206
commit
8192cf901a
2 changed files with 17 additions and 11 deletions
9
capybara
9
capybara
|
@ -29,6 +29,11 @@ class MessageParser():
|
|||
decoded_arguments[argument_name] = int(message_arguments[i])
|
||||
except ValueError:
|
||||
return None, "Error parsing int argument for message (is it really an int?)"
|
||||
elif argument_type == "float":
|
||||
try:
|
||||
decoded_arguments[argument_name] = float(message_arguments[i])
|
||||
except ValueError:
|
||||
return None, "Error parsing float argument for message (is it really a float?)"
|
||||
elif argument_type == "str":
|
||||
decoded_arguments[argument_name] = message_arguments[i]
|
||||
else:
|
||||
|
@ -53,8 +58,8 @@ class InputController():
|
|||
})
|
||||
# Mouse relative scroll
|
||||
self.parser.add_handler("s", {
|
||||
"x": "int",
|
||||
"y": "int"
|
||||
"x": "float",
|
||||
"y": "float"
|
||||
})
|
||||
# Mouse button down
|
||||
self.parser.add_handler("d", {
|
||||
|
|
|
@ -104,8 +104,6 @@
|
|||
this.currentMoveY = 0;
|
||||
this.lastMoveX = 0;
|
||||
this.lastMoveY = 0;
|
||||
this.scrollXSum = 0;
|
||||
this.scrollYSum = 0;
|
||||
this.shouldResetLastMove = false;
|
||||
this.isInHoldingMode = false;
|
||||
this.ongoingTouches = {};
|
||||
|
@ -156,8 +154,9 @@
|
|||
element.addEventListener("touchstart", this.onTouchStart.bind(this));
|
||||
}
|
||||
|
||||
onTouchMove({ preventDefault, touches }) {
|
||||
preventDefault();
|
||||
onTouchMove(event) {
|
||||
const touches = event.touches;
|
||||
event.preventDefault();
|
||||
for (let i = 0; i < touches.length; i++) {
|
||||
this.ongoingTouches[touches[i].identifier].hasMoved = true;
|
||||
}
|
||||
|
@ -180,14 +179,15 @@
|
|||
this.lastMoveY = this.currentMoveY;
|
||||
// if two touches moved at the same time, assume scrolling intent
|
||||
if (touches.length === 2) {
|
||||
this._sendRelativeMouseScroll(deltaX, deltaY);
|
||||
this._sendRelativeMouseScroll(deltaX * 0.1, deltaY * 0.5);
|
||||
} else {
|
||||
this._sendRelativeMouseMovement(deltaX, deltaY);
|
||||
}
|
||||
}
|
||||
|
||||
onTouchEnd({ preventDefault, changedTouches }) {
|
||||
preventDefault();
|
||||
onTouchEnd(event) {
|
||||
const changedTouches = event.changedTouches;
|
||||
event.preventDefault();
|
||||
this.shouldResetLastMove = true;
|
||||
if (changedTouches.length === 1) {
|
||||
// This is a single tap - left click
|
||||
|
@ -207,8 +207,9 @@
|
|||
}
|
||||
}
|
||||
|
||||
onTouchStart({ preventDefault, changedTouches }) {
|
||||
preventDefault();
|
||||
onTouchStart(event) {
|
||||
const changedTouches = event.changedTouches;
|
||||
event.preventDefault();
|
||||
|
||||
// Clear the hold mode time out if another touch begins
|
||||
if (this.holdModeTimeout)
|
||||
|
|
Loading…
Reference in a new issue