1
0
mirror of https://github.com/Pomax/BezierInfo-2.git synced 2025-09-02 12:54:23 +02:00

touch handling

This commit is contained in:
Pomax
2020-08-08 11:26:43 -07:00
parent 03216d1488
commit 1b40e3fcd9

View File

@@ -6,7 +6,7 @@
*/
class BaseAPI {
static get privateMethods() {
return [`constructor`, `addListeners`, `getMouseCoords`]
return [`constructor`, `addListeners`, `getCursorCoords`]
.concat(this.superCallers)
.concat(this.eventHandlers);
}
@@ -89,9 +89,15 @@ class BaseAPI {
/**
*
*/
getMouseCoords(evt) {
this.cursor.x = evt.offsetX;
this.cursor.y = evt.offsetY;
getCursorCoords(evt) {
if (e.targetTouches) {
const rect = e.target.getBoundingClientRect();
this.cursor.x = e.targetTouches[0].pageX - rect.left;
this.cursor.y = e.targetTouches[0].pageY - rect.top;
} else {
this.cursor.x = evt.offsetX;
this.cursor.y = evt.offsetY;
}
}
/**
@@ -101,7 +107,7 @@ class BaseAPI {
stop(evt);
this.cursor.button = evt.button;
this.cursor.down = true;
this.getMouseCoords(evt);
this.getCursorCoords(evt);
}
/**
@@ -111,7 +117,7 @@ class BaseAPI {
stop(evt);
this.cursor.button = undefined;
this.cursor.move = true;
this.getMouseCoords(evt);
this.getCursorCoords(evt);
}
/**
@@ -122,7 +128,7 @@ class BaseAPI {
this.cursor.button = evt.button;
this.cursor.down = false;
this.cursor.move = false;
this.getMouseCoords(evt);
this.getCursorCoords(evt);
}
/**