From 630060143cd63b714d65d8a97621d00fadc5a65b Mon Sep 17 00:00:00 2001 From: Leone25 <39310565+Leone25@users.noreply.github.com> Date: Wed, 5 Jun 2024 10:00:59 +0200 Subject: [PATCH] forgot touch support --- templates/sugo.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/templates/sugo.php b/templates/sugo.php index c8370db..2dd904a 100644 --- a/templates/sugo.php +++ b/templates/sugo.php @@ -99,21 +99,33 @@ e.preventDefault(); this.mouseDown = true; const ctx = this.$refs.signature.getContext('2d'); + let x = e.touches[0].clientX - this.$refs.signature.getBoundingClientRect().left; + let y = e.touches[0].clientY - this.$refs.signature.getBoundingClientRect().top; ctx.beginPath(); - ctx.moveTo(e.touches[0].clientX - this.$refs.signature.getBoundingClientRect().left, e.touches[0].clientY - this.$refs.signature.getBoundingClientRect().top); + ctx.arc(x, y, 1.5, 0, 2 * Math.PI); + ctx.fill(); + ctx.beginPath(); + ctx.moveTo(x, y); }, handleTouchMove(e) { e.preventDefault(); if (!this.mouseDown) return; const ctx = this.$refs.signature.getContext('2d'); + let x = e.touches[0].clientX - this.$refs.signature.getBoundingClientRect().left; + let y = e.touches[0].clientY - this.$refs.signature.getBoundingClientRect().top; ctx.lineWidth = 3; - ctx.lineTo(e.touches[0].clientX - this.$refs.signature.getBoundingClientRect().left, e.touches[0].clientY - this.$refs.signature.getBoundingClientRect().top); + ctx.lineTo(x, y); ctx.stroke(); }, handleTouchEnd(e) { e.preventDefault(); this.mouseDown = false; const ctx = this.$refs.signature.getContext('2d'); + let x = e.touches[0].clientX - this.$refs.signature.getBoundingClientRect().left; + let y = e.touches[0].clientY - this.$refs.signature.getBoundingClientRect().top; + ctx.beginPath(); + ctx.arc(x, y, 1.5, 0, 2 * Math.PI); + ctx.fill(); }, clear() { const ctx = this.$refs.signature.getContext('2d');