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