Skip to content

Commit 39ec739

Browse files
author
HarshKhandeparkar
committed
feat<RealDrawBoard>: method to calculate
touch coords
1 parent ae3813e commit 39ec739

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

src/renderers/RealDrawBoard/_coords.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,24 @@ export function _getMouseCoords(
1212

1313
return [x, y]; // In graph coordinates
1414
}
15+
16+
export function _getTouchCoords(
17+
this: RealDrawBoard,
18+
e: TouchEvent
19+
): [number, number][] {
20+
let allCoords: [number, number][] = [];
21+
22+
for (let i = 0; i < e.touches.length; i++) {
23+
const touch = e.touches.item(i);
24+
25+
let x = touch.clientX - this.canvas.getBoundingClientRect().left;
26+
let y = this.dimensions[1] - (touch.clientY - this.canvas.getBoundingClientRect().top);
27+
28+
x = x / this.xScaleFactor - (this.dimensions[0] * (this.yOffset / 100)) / this.xScaleFactor;
29+
y = y / this.yScaleFactor - (this.dimensions[1] * (this.xOffset / 100)) / this.yScaleFactor;
30+
31+
allCoords.push([x, y]);
32+
}
33+
34+
return allCoords;
35+
}

0 commit comments

Comments
 (0)