0
0
mirror of https://github.com/Doodle3D/doodle3d-client.git synced 2024-06-28 21:51:22 +02:00

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.

This commit is contained in:
Adriaan Wormgoor 2013-10-29 22:08:08 +01:00
parent 176f8f4ae1
commit e7ef6eccc4
3 changed files with 41 additions and 25 deletions

View File

@ -64,7 +64,8 @@ function initButtonBehavior() {
e.preventDefault(); e.preventDefault();
clearInterval(btnOopsInterval); clearInterval(btnOopsInterval);
redrawDoodle(true); redrawDoodle(true);
redrawPreview(); renderToImageDataPreview();
// redrawPreview();
} }
btnOops.on('touchstart', function(e) { startOops(e); }); btnOops.on('touchstart', function(e) { startOops(e); });
btnOops.on('touchend', function(e) { stopOops(e); }); btnOops.on('touchend', function(e) { stopOops(e); });
@ -74,17 +75,19 @@ function initButtonBehavior() {
function startMoveUp(e) { function startMoveUp(e) {
e.preventDefault(); e.preventDefault();
// console.log("btnMoveUp mouse down"); // console.log("btnMoveUp mouse down");
previewUp(true); if (_points.length > 1) {
clearInterval(btnMoveUpInterval);
btnMoveUpInterval = setInterval( function() {
previewUp(true); previewUp(true);
}, 1000/30); clearInterval(btnMoveUpInterval);
btnMoveUpInterval = setInterval( function() {
previewUp(true);
}, 1000/30);
}
} }
function stopMoveUp(e) { function stopMoveUp(e) {
e.preventDefault(); e.preventDefault();
console.log("btnMoveUp mouse up"); // console.log("btnMoveUp mouse up");
clearInterval(btnMoveUpInterval); clearInterval(btnMoveUpInterval);
previewUp(); if (_points.length > 1) previewUp();
} }
btnMoveUp.mousedown(function(e) { startMoveUp(e) }); btnMoveUp.mousedown(function(e) { startMoveUp(e) });
btnMoveUp.mouseup(function(e) { stopMoveUp(e) }); btnMoveUp.mouseup(function(e) { stopMoveUp(e) });
@ -94,17 +97,19 @@ function initButtonBehavior() {
function startMoveDown(e) { function startMoveDown(e) {
e.preventDefault(); e.preventDefault();
// console.log("btnMoveDown mouse down"); // console.log("btnMoveDown mouse down");
previewDown(true); if (_points.length > 1) {
clearInterval(btnMoveDownInterval);
btnMoveDownInterval = setInterval( function() {
previewDown(true); previewDown(true);
}, 1000/30); clearInterval(btnMoveDownInterval);
btnMoveDownInterval = setInterval( function() {
previewDown(true);
}, 1000/30);
}
} }
function stopMoveDown(e) { function stopMoveDown(e) {
e.preventDefault(); e.preventDefault();
console.log("btnMoveDown mouse up"); // console.log("btnMoveDown mouse up");
clearInterval(btnMoveDownInterval); clearInterval(btnMoveDownInterval);
previewDown(); if (_points.length > 1) previewDown();
} }
btnMoveDown.mousedown(function(e) { startMoveDown(e) }); btnMoveDown.mousedown(function(e) { startMoveDown(e) });
btnMoveDown.mouseup(function(e) { stopMoveDown(e) }); btnMoveDown.mouseup(function(e) { stopMoveDown(e) });
@ -114,17 +119,19 @@ function initButtonBehavior() {
function startTwistLeft(e) { function startTwistLeft(e) {
e.preventDefault(); e.preventDefault();
// console.log("btnTwistLeft mouse down"); // console.log("btnTwistLeft mouse down");
previewTwistLeft(true); if (_points.length > 1) {
clearInterval(btnTwistLeftInterval);
btnTwistLeftInterval = setInterval( function() {
previewTwistLeft(true); previewTwistLeft(true);
}, 1000/30); clearInterval(btnTwistLeftInterval);
btnTwistLeftInterval = setInterval( function() {
previewTwistLeft(true);
}, 1000/30);
}
} }
function stopTwistLeft(e) { function stopTwistLeft(e) {
e.preventDefault(); e.preventDefault();
// console.log("btnTwistLeft mouse up"); // console.log("btnTwistLeft mouse up");
clearInterval(btnTwistLeftInterval); clearInterval(btnTwistLeftInterval);
previewTwistLeft(); if (_points.length > 1) previewTwistLeft();
} }
btnTwistLeft.mousedown(function(e) { startTwistLeft(e) }); btnTwistLeft.mousedown(function(e) { startTwistLeft(e) });
btnTwistLeft.mouseup(function(e) { stopTwistLeft(e) }); btnTwistLeft.mouseup(function(e) { stopTwistLeft(e) });
@ -134,17 +141,19 @@ function initButtonBehavior() {
function startTwistRight(e) { function startTwistRight(e) {
e.preventDefault(); e.preventDefault();
// console.log("btnTwistRight mouse down"); // console.log("btnTwistRight mouse down");
previewTwistRight(true); if (_points.length > 1) {
clearInterval(btnTwistRightInterval);
btnTwistRightInterval = setInterval( function() {
previewTwistRight(true); previewTwistRight(true);
}, 1000/30); clearInterval(btnTwistRightInterval);
btnTwistRightInterval = setInterval( function() {
previewTwistRight(true);
}, 1000/30);
}
} }
function stopTwistRight(e) { function stopTwistRight(e) {
e.preventDefault(); e.preventDefault();
// console.log("btnTwistRight mouse up"); // console.log("btnTwistRight mouse up");
clearInterval(btnTwistRightInterval); clearInterval(btnTwistRightInterval);
previewTwistRight(); if (_points.length > 1) previewTwistRight();
} }
btnTwistRight.mousedown(function(e) { startTwistRight(e) }); btnTwistRight.mousedown(function(e) { startTwistRight(e) });
btnTwistRight.mouseup(function(e) { stopTwistRight(e) }); btnTwistRight.mouseup(function(e) { stopTwistRight(e) });
@ -267,6 +276,9 @@ function resetPreview() {
previewCtx.clearRect(0,0,canvas.width, canvas.height); previewCtx.clearRect(0,0,canvas.width, canvas.height);
previewCtx.restore(); 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 // reset height and rotation to default values
numLayers = previewDefaults.numLayers; // current number of preview layers numLayers = previewDefaults.numLayers; // current number of preview layers
rStep = previewDefaults.rotation; // Math.PI/180; //Math.PI/40; // rStep = previewDefaults.rotation; // Math.PI/180; //Math.PI/40; //

View File

@ -22,7 +22,6 @@ function doOnResize() {
redrawDoodle(); redrawDoodle();
redrawPreview(); redrawPreview();
} }
function initLayouting() { function initLayouting() {

View File

@ -33,8 +33,13 @@ function initPreviewRendering() {
previewCtx_tmp = preview_tmp.getContext('2d'); previewCtx_tmp = preview_tmp.getContext('2d');
// doodleImageCapture = new Image();
calcPreviewCanvasProperties(); calcPreviewCanvasProperties();
redrawPreview(); redrawPreview();
// needed to
// doodleImageCapture = new Image();
} }
function calcPreviewCanvasProperties() { 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) // 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) { function redrawRenderedPreview(redrawLess) {
if (redrawLess == undefined) redrawLess = false; if (redrawLess == undefined) redrawLess = false;
console.log("f:redrawRenderedPreview()"); // console.log("f:redrawRenderedPreview()");
previewCtx.clearRect(0, 0, preview.width, preview.height); previewCtx.clearRect(0, 0, preview.width, preview.height);
previewCtx.lineWidth = strokeWidth; previewCtx.lineWidth = strokeWidth;