Split function updateMoveAndScroll
This commit is contained in:
parent
ab09e7c674
commit
51dbecaa63
1 changed files with 28 additions and 27 deletions
|
|
@ -153,21 +153,31 @@ function onDraggingTimeout() {
|
||||||
ws.send("b" + POINTER_BUTTON_LEFT + ";0");
|
ws.send("b" + POINTER_BUTTON_LEFT + ";0");
|
||||||
}
|
}
|
||||||
|
|
||||||
function updateMoveAndScroll() {
|
function updateMove(x, y) {
|
||||||
var moveX = Math.trunc(moveXSum);
|
moveXSum += x;
|
||||||
var moveY = Math.trunc(moveYSum);
|
moveYSum += y;
|
||||||
if (Math.abs(moveX) >= 1 || Math.abs(moveY) >= 1) {
|
var xInt = Math.trunc(moveXSum);
|
||||||
moveXSum -= moveX;
|
var yInt = Math.trunc(moveYSum);
|
||||||
moveYSum -= moveY;
|
if (xInt != 0 || yInt != 0) {
|
||||||
ws.send("m" + moveX + ";" + moveY);
|
moveXSum -= xInt;
|
||||||
|
moveYSum -= yInt;
|
||||||
|
ws.send("m" + xInt + ";" + yInt);
|
||||||
}
|
}
|
||||||
var scrollX = Math.trunc(scrollXSum);
|
}
|
||||||
var scrollY = Math.trunc(scrollYSum);
|
|
||||||
if (Math.abs(scrollX) >= 1 || Math.abs(scrollY) >= 1) {
|
function updateScroll(x, y, scrollFinish) {
|
||||||
scrollXSum -= scrollX;
|
scrollXSum += x;
|
||||||
scrollYSum -= scrollY;
|
scrollYSum += y;
|
||||||
scrolling = true;
|
var xInt = Math.trunc(scrollXSum);
|
||||||
ws.send("s" + scrollX + ";" + scrollY);
|
var yInt = Math.trunc(scrollYSum);
|
||||||
|
if (xInt != 0 || yInt != 0) {
|
||||||
|
scrollXSum -= xInt;
|
||||||
|
scrollYSum -= yInt;
|
||||||
|
ws.send((scrollFinish ? "S" : "s") + xInt + ";" + yInt);
|
||||||
|
scrolling = !scrollFinish;
|
||||||
|
} else if (scrollFinish && scrolling) {
|
||||||
|
ws.send("S");
|
||||||
|
scrolling = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -202,10 +212,7 @@ function handleStart(evt) {
|
||||||
draggingTimeout = null;
|
draggingTimeout = null;
|
||||||
dragging = true;
|
dragging = true;
|
||||||
}
|
}
|
||||||
if (scrolling) {
|
updateScroll(0, 0, true);
|
||||||
ws.send("S");
|
|
||||||
scrolling = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -219,10 +226,7 @@ function handleEnd(evt) {
|
||||||
ongoingTouches.splice(idx, 1);
|
ongoingTouches.splice(idx, 1);
|
||||||
touchReleasedCount += 1;
|
touchReleasedCount += 1;
|
||||||
touchLastEnd = evt.timeStamp;
|
touchLastEnd = evt.timeStamp;
|
||||||
if (scrolling) {
|
updateScroll(0, 0, true);
|
||||||
ws.send("S");
|
|
||||||
scrolling = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if (touchReleasedCount > TOUCH_MOVE_THRESHOLD.length) {
|
if (touchReleasedCount > TOUCH_MOVE_THRESHOLD.length) {
|
||||||
touchMoved = true;
|
touchMoved = true;
|
||||||
|
|
@ -281,13 +285,10 @@ function handleMove(evt) {
|
||||||
}
|
}
|
||||||
if (touchMoved && evt.timeStamp - touchLastEnd >= TOUCH_TIMEOUT) {
|
if (touchMoved && evt.timeStamp - touchLastEnd >= TOUCH_TIMEOUT) {
|
||||||
if (ongoingTouches.length == 1 || dragging) {
|
if (ongoingTouches.length == 1 || dragging) {
|
||||||
moveXSum += sumX;
|
updateMove(sumX, sumY);
|
||||||
moveYSum += sumY;
|
|
||||||
} else if (ongoingTouches.length == 2) {
|
} else if (ongoingTouches.length == 2) {
|
||||||
scrollXSum -= sumX;
|
updateScroll(-sumX, -sumY, false);
|
||||||
scrollYSum -= sumY;
|
|
||||||
}
|
}
|
||||||
updateMoveAndScroll();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue