diff --git a/src/pages/detect.vue b/src/pages/detect.vue index bdbd080..e14130e 100644 --- a/src/pages/detect.vue +++ b/src/pages/detect.vue @@ -9,13 +9,26 @@ +
Capture
- + 0) { this.canvasZoom *= 1.05 this.canvasOffset.x = (((1.05 ** -1) - 1)*event.clientX + this.canvasOffset.x)*1.05 @@ -635,7 +648,6 @@ this.canvasOffset.x = ((.05)*event.clientX + this.canvasOffset.x)/1.05 this.canvasOffset.y = ((.05)*event.clientY + this.canvasOffset.y)/1.05 } - console.log(this.canvasOffset) this.selectChip("redraw") } } diff --git a/src/pages/touch-mixin.js b/src/pages/touch-mixin.js new file mode 100644 index 0000000..1a6dcfb --- /dev/null +++ b/src/pages/touch-mixin.js @@ -0,0 +1,49 @@ +export default { + data () { + return { + touchPrevious: {} + } + }, + methods: { + startTouch(event) { + if (event.touches.length == 1) { + this.touchPrevious = {x: event.touches[0].clientX, y: event.touches[0].clientY} + } + if (event.touches.length == 2) { + this.touchPrevious = {distance: this.touchDistance(event.touches)} + } + }, + endTouch(event) { + if (event.touches.length == 1) { + this.touchPrevious = {x: event.touches[0].clientX, y: event.touches[0].clientY} + } else { + this.debugInfo = null + } + }, + moveTouch(event) { + switch (event.touches.length) { + case 1: + this.canvasOffset.x += event.touches[0].clientX - this.touchPrevious.x + this.canvasOffset.y += event.touches[0].clientY - this.touchPrevious.y + this.touchPrevious = {x: event.touches[0].clientX, y: event.touches[0].clientY} + break; + case 2: + let newDistance = this.touchDistance(event.touches) + let midX = (event.touches.item(0).clientX + event.touches.item(1).clientX) / 2 + let midY = (event.touches.item(0).clientY + event.touches.item(1).clientY) / 2 + let scale = newDistance / this.touchPrevious.distance + this.canvasZoom *= scale + this.canvasOffset.x = (((scale ** -1) - 1) * midX + this.canvasOffset.x) * scale + this.canvasOffset.y = (((scale ** -1) - 1) * midY + this.canvasOffset.y) * scale + this.touchPrevious = {distance: newDistance} + break; + } + this.selectChip("redraw") + }, + touchDistance(touches) { + let touch1 = touches.item(0) + let touch2 = touches.item(1) + return Math.sqrt((touch1.clientX - touch2.clientX) ** 2 + (touch1.clientY - touch2.clientY) ** 2) + } + } +} \ No newline at end of file