From 92705e55cece978883a052eb7115c54af6daaca4 Mon Sep 17 00:00:00 2001 From: Raphael Date: Sat, 11 Jun 2022 17:56:32 +0200 Subject: [PATCH] improve --- src/js/classes/Point.js | 8 ++++++++ src/js/whiteboard.js | 14 +++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/js/classes/Point.js b/src/js/classes/Point.js index 4c8fd81..36e2e7c 100644 --- a/src/js/classes/Point.js +++ b/src/js/classes/Point.js @@ -38,6 +38,14 @@ class Point { return this.#x === 0 && this.#y === 0; } + set x(newX) { + this.#x = newX; + } + + set y(newY) { + this.#y = newY; + } + /** * Get a Point object from an event * @param {event} e diff --git a/src/js/whiteboard.js b/src/js/whiteboard.js index 2024b8f..870fa48 100644 --- a/src/js/whiteboard.js +++ b/src/js/whiteboard.js @@ -244,7 +244,12 @@ const whiteboard = { _this.ctx.globalCompositeOperation = _this.oldGCO; let currentPos = Point.fromEvent(e); - + if (_this.tool !== "hand") { + console.log(currentPos.x, currentPos.y, _this.viewCoords.x, _this.viewCoords.y); + currentPos.x += _this.viewCoords.x; + currentPos.y += _this.viewCoords.y; + console.log(currentPos.x, currentPos.y); + } if (currentPos.isZeroZero) { _this.sendFunction({ t: "cursor", @@ -285,6 +290,7 @@ const whiteboard = { _this.drawBuffer = []; _this.textContainer.empty(); _this.loadData(dbCp); // draw old content in + console.log(_this.viewCoords.x, _this.viewCoords.y); } else if (_this.tool === "pen") { _this.pushPointSmoothPen(currentPos.x, currentPos.y); @@ -493,6 +499,12 @@ const whiteboard = { } let currentPos = Point.fromEvent(e); + if (_this.tool !== "hand") { + console.log(currentPos.x, currentPos.y, _this.viewCoords.x, _this.viewCoords.y); + currentPos.x -= _this.viewCoords.x; + currentPos.y -= _this.viewCoords.y; + console.log(currentPos.x, currentPos.y); + } window.requestAnimationFrame(function () { // update position