From aea89d3422fc8a2afc661b633581c7f864be6a7a Mon Sep 17 00:00:00 2001 From: Adriaan Wormgoor Date: Fri, 11 Oct 2013 18:40:03 +0200 Subject: [PATCH] - fixed canvasdrawing bug w.r.t. touch-enabled devices - removed some superfluous lines --- js/SettingsWindow.js | 8 ++++---- js/canvasDrawing.js | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/js/SettingsWindow.js b/js/SettingsWindow.js index 6b37859..bbb1086 100644 --- a/js/SettingsWindow.js +++ b/js/SettingsWindow.js @@ -121,15 +121,15 @@ function SettingsWindow() { console.log("f:showSettings()"); this.loadSettings(); // reload settings - this.window.css("display","table"); +// this.window.css("display","table"); $("#contentOverlay").fadeIn(375, function() { - document.body.removeEventListener('touchmove',prevent,false); +// document.body.removeEventListener('touchmove',prevent,false); }); } this.hideSettings = function() { $("#contentOverlay").fadeOut(375, function() { - document.body.addEventListener('touchmove',prevent,false); - self.window.css("display","none"); +// document.body.addEventListener('touchmove',prevent,false); +// self.window.css("display","none"); }); } diff --git a/js/canvasDrawing.js b/js/canvasDrawing.js index 2cabcf2..38274fd 100644 --- a/js/canvasDrawing.js +++ b/js/canvasDrawing.js @@ -62,6 +62,7 @@ function initDoodleDrawing() { canvas.addEventListener('touchstart',onCanvasTouchDown,false); canvas.addEventListener('touchmove',onCanvasTouchMove,false); canvas.addEventListener('touchend',onCanvasTouchEnd,false); + document.body.addEventListener('touchmove',prevent,false); } //*/ @@ -183,7 +184,7 @@ function redrawDoodle() { function adjustBounds(x, y) { var newPointsOutsideOfCurrentBounds = false; - // console.log("f:adjustBounds("+x+","+y+")"); + console.log("f:adjustBounds("+x+","+y+")"); if (doodleBounds[0] == -1) { // if doodleBounds[0] is -1 then it isn't initted yet, so x and y are both the min and max vals @@ -386,10 +387,12 @@ function onCanvasTouchDown(e) { console.log("f:onCanvasTouchDown >> e: " , e); // var x = e.touches[0].pageX - e.touches[0].target.offsetLeft; // var y = e.touches[0].pageY - e.touches[0].target.offsetTop; -// var x = e.touches[0].pageX - drawCanvasTopLeftCoords[0]; -// var y = e.touches[0].pageY - drawCanvasTopLeftCoords[1]; - var x = e.touches[0].layerX; - var y = e.touches[0].layerY; + var x = e.touches[0].pageX - drawCanvasTopLeftCoords[0]; + var y = e.touches[0].pageY - drawCanvasTopLeftCoords[1]; +// var x = e.touches[0].pageX; +// var y = e.touches[0].pageY; +// var x = e.touches[0].layerX; +// var y = e.touches[0].layerY; _points.push([x, y, true]); adjustBounds(x, y); @@ -403,14 +406,17 @@ function onCanvasTouchDown(e) { function onCanvasTouchMove(e) { e.preventDefault(); - console.log("f:onCanvasTouchMove >> e: " , e); // var x = e.touches[0].pageX - e.touches[0].target.offsetLeft; // var y = e.touches[0].pageY - e.touches[0].target.offsetTop; var x = e.touches[0].pageX - drawCanvasTopLeftCoords[0]; var y = e.touches[0].pageY - drawCanvasTopLeftCoords[1]; +// var x = e.touches[0].layerX; +// var y = e.touches[0].layerY; // var x = e.touches[0].layerX; // var y = e.touches[0].layerY; + console.log("f:onCanvasTouchMove >> x,y = "+x+","+y+" , e: " , e); + if (prevPoint.x != -1 || prevPoint.y != -1) { var dist = Math.sqrt(Math.pow((prevPoint.x - x), 2) + Math.pow((prevPoint.y - y), 2)); if (dist > 5) {