From e7ef6eccc492d07f3df4cb5dea396ca87ea5e818 Mon Sep 17 00:00:00 2001 From: Adriaan Wormgoor Date: Tue, 29 Oct 2013 22:08:08 +0100 Subject: [PATCH] fixed bug which happened if you pressed the move up/down or twist left/right buttons after loading Doodle3D (before drawing anything). Somewhat related: after pressing 'new', the move up/down and twist left/right buttons would show the previous (cached) doodle. Cleared that as well. --- js_src/buttonbehaviors.js | 58 +++++++++++++++++++++++--------------- js_src/init_layout.js | 1 - js_src/previewRendering.js | 7 ++++- 3 files changed, 41 insertions(+), 25 deletions(-) diff --git a/js_src/buttonbehaviors.js b/js_src/buttonbehaviors.js index eec0c37..590b273 100644 --- a/js_src/buttonbehaviors.js +++ b/js_src/buttonbehaviors.js @@ -64,7 +64,8 @@ function initButtonBehavior() { e.preventDefault(); clearInterval(btnOopsInterval); redrawDoodle(true); - redrawPreview(); + renderToImageDataPreview(); +// redrawPreview(); } btnOops.on('touchstart', function(e) { startOops(e); }); btnOops.on('touchend', function(e) { stopOops(e); }); @@ -74,17 +75,19 @@ function initButtonBehavior() { function startMoveUp(e) { e.preventDefault(); // console.log("btnMoveUp mouse down"); - previewUp(true); - clearInterval(btnMoveUpInterval); - btnMoveUpInterval = setInterval( function() { + if (_points.length > 1) { previewUp(true); - }, 1000/30); + clearInterval(btnMoveUpInterval); + btnMoveUpInterval = setInterval( function() { + previewUp(true); + }, 1000/30); + } } function stopMoveUp(e) { e.preventDefault(); - console.log("btnMoveUp mouse up"); +// console.log("btnMoveUp mouse up"); clearInterval(btnMoveUpInterval); - previewUp(); + if (_points.length > 1) previewUp(); } btnMoveUp.mousedown(function(e) { startMoveUp(e) }); btnMoveUp.mouseup(function(e) { stopMoveUp(e) }); @@ -94,17 +97,19 @@ function initButtonBehavior() { function startMoveDown(e) { e.preventDefault(); // console.log("btnMoveDown mouse down"); - previewDown(true); - clearInterval(btnMoveDownInterval); - btnMoveDownInterval = setInterval( function() { + if (_points.length > 1) { previewDown(true); - }, 1000/30); + clearInterval(btnMoveDownInterval); + btnMoveDownInterval = setInterval( function() { + previewDown(true); + }, 1000/30); + } } function stopMoveDown(e) { e.preventDefault(); - console.log("btnMoveDown mouse up"); +// console.log("btnMoveDown mouse up"); clearInterval(btnMoveDownInterval); - previewDown(); + if (_points.length > 1) previewDown(); } btnMoveDown.mousedown(function(e) { startMoveDown(e) }); btnMoveDown.mouseup(function(e) { stopMoveDown(e) }); @@ -114,17 +119,19 @@ function initButtonBehavior() { function startTwistLeft(e) { e.preventDefault(); // console.log("btnTwistLeft mouse down"); - previewTwistLeft(true); - clearInterval(btnTwistLeftInterval); - btnTwistLeftInterval = setInterval( function() { + if (_points.length > 1) { previewTwistLeft(true); - }, 1000/30); + clearInterval(btnTwistLeftInterval); + btnTwistLeftInterval = setInterval( function() { + previewTwistLeft(true); + }, 1000/30); + } } function stopTwistLeft(e) { e.preventDefault(); // console.log("btnTwistLeft mouse up"); clearInterval(btnTwistLeftInterval); - previewTwistLeft(); + if (_points.length > 1) previewTwistLeft(); } btnTwistLeft.mousedown(function(e) { startTwistLeft(e) }); btnTwistLeft.mouseup(function(e) { stopTwistLeft(e) }); @@ -134,17 +141,19 @@ function initButtonBehavior() { function startTwistRight(e) { e.preventDefault(); // console.log("btnTwistRight mouse down"); - previewTwistRight(true); - clearInterval(btnTwistRightInterval); - btnTwistRightInterval = setInterval( function() { + if (_points.length > 1) { previewTwistRight(true); - }, 1000/30); + clearInterval(btnTwistRightInterval); + btnTwistRightInterval = setInterval( function() { + previewTwistRight(true); + }, 1000/30); + } } function stopTwistRight(e) { e.preventDefault(); // console.log("btnTwistRight mouse up"); clearInterval(btnTwistRightInterval); - previewTwistRight(); + if (_points.length > 1) previewTwistRight(); } btnTwistRight.mousedown(function(e) { startTwistRight(e) }); btnTwistRight.mouseup(function(e) { stopTwistRight(e) }); @@ -267,6 +276,9 @@ function resetPreview() { previewCtx.clearRect(0,0,canvas.width, canvas.height); previewCtx.restore(); + // also make new Image, otherwise the previously cached preview can be redrawn with move up/down or twist left/right + doodleImageCapture = new Image(); + // reset height and rotation to default values numLayers = previewDefaults.numLayers; // current number of preview layers rStep = previewDefaults.rotation; // Math.PI/180; //Math.PI/40; // diff --git a/js_src/init_layout.js b/js_src/init_layout.js index 907aa30..34be0e0 100644 --- a/js_src/init_layout.js +++ b/js_src/init_layout.js @@ -22,7 +22,6 @@ function doOnResize() { redrawDoodle(); redrawPreview(); - } function initLayouting() { diff --git a/js_src/previewRendering.js b/js_src/previewRendering.js index 32a7383..6c3c825 100644 --- a/js_src/previewRendering.js +++ b/js_src/previewRendering.js @@ -33,8 +33,13 @@ function initPreviewRendering() { previewCtx_tmp = preview_tmp.getContext('2d'); +// doodleImageCapture = new Image(); + calcPreviewCanvasProperties(); redrawPreview(); + + // needed to +// doodleImageCapture = new Image(); } function calcPreviewCanvasProperties() { @@ -226,7 +231,7 @@ function renderToImageDataPreview() { // it is assumed that the preview has been rendered to an Image object, which will be used to draw the preview with (much better performance) function redrawRenderedPreview(redrawLess) { if (redrawLess == undefined) redrawLess = false; - console.log("f:redrawRenderedPreview()"); +// console.log("f:redrawRenderedPreview()"); previewCtx.clearRect(0, 0, preview.width, preview.height); previewCtx.lineWidth = strokeWidth;