Merge branch 'develop' of github.com:Doodle3D/doodle3d-client into develop

This commit is contained in:
Wouter R 2014-01-17 18:04:40 +01:00
commit 92a28f54b8
6 changed files with 33 additions and 154 deletions

View File

@ -124,7 +124,7 @@ function rotateShape(radians) {
function updateView() {
setSketchModified(true);
redrawDoodle();
redrawDoodle(true);
adjustPreviewTransformation();
renderToImageDataPreview();

View File

@ -45,7 +45,7 @@ var isModified = false;
*
* * * * * * * * * */
function initDoodleDrawing() {
console.log("f:initDoodleDrawing()");
//console.log("f:initDoodleDrawing()");
$canvas = $("#mycanvas");
canvas = $canvas[0];
@ -79,7 +79,7 @@ function initDoodleDrawing() {
// drawCanvas = $(".drawareacontainer");
drawCanvas = $("#mycanvasContainer"); // $("#drawAreaContainer")
console.log("drawCanvasTopLeftCoords: " + drawCanvasTopLeftCoords);
//console.log("drawCanvasTopLeftCoords: " + drawCanvasTopLeftCoords);
// drawCanvasTopLeftCoords[0] = drawCanvas.css("left").match(/[0-9]/g).join("");
// drawCanvasTopLeftCoords[1] = drawCanvas.css("top").match(/[0-9]/g).join("");
drawCanvasTopLeftCoords[0] = drawCanvas.offset().left;
@ -87,8 +87,8 @@ function initDoodleDrawing() {
// drawCanvasTopLeftCoords[0] = drawCanvas[0].offsetParent.offsetLeft;
// drawCanvasTopLeftCoords[1] = drawCanvas[0].offsetParent.offsetTop;
console.log("f:initDoodleDrawing() >> canvasWidth: " + canvasWidth);
console.log("f:initDoodleDrawing() >> canvasHeight: " + canvasHeight);
//console.log("f:initDoodleDrawing() >> canvasWidth: " + canvasWidth);
//console.log("f:initDoodleDrawing() >> canvasHeight: " + canvasHeight);
}
@ -98,6 +98,7 @@ function initDoodleDrawing() {
*
* * * * * * * * * */
function draw(_x, _y, _width) {
//console.log("canvasDrawing:draw");
// console.log("f:draw() >> _width: " + _width);
if (prevX == 0 && prevY ==0) {
@ -154,7 +155,7 @@ function draw(_x, _y, _width) {
*
* * * * * * * * * */
function clearDoodle() {
console.log("f:clearDoodle");
//console.log("f:clearDoodle");
updatePrevNextButtonStateOnClear();
@ -179,6 +180,7 @@ function clearDoodle() {
}
function redrawDoodle(recalcBoundsAndTransforms) {
//console.log("canvasDrawing:redrawDoodle");
if (recalcBoundsAndTransforms == undefined) recalcBoundsAndTransforms = false;
// console.log("f:redrawDoodle() >> recalcBoundsAndTransforms = " + recalcBoundsAndTransforms);
@ -205,8 +207,9 @@ function redrawDoodle(recalcBoundsAndTransforms) {
}
}
}
// checks if x,y is outside doodleBounds, if so update
function adjustBounds(x, y) {
//console.log("canvasDrawing:adjustBounds");
var newPointsOutsideOfCurrentBounds = false;
// console.log("f:adjustBounds("+x+","+y+")");
@ -242,7 +245,7 @@ function redrawDoodle(recalcBoundsAndTransforms) {
// does what exactly?
function adjustPreviewTransformation() {
// console.log("f:adjustPreviewTransformation()");
//console.log("canvasDrawing:adjustPreviewTransformation");
doodleTransform[0] = doodleBounds[0];
doodleTransform[1] = doodleBounds[1];
@ -272,6 +275,7 @@ function adjustPreviewTransformation() {
*
* * * * * * * * * */
function onCanvasMouseDown(e) {
//console.log("canvasDrawing:onCanvasMouseDown");
setSketchModified(true);
// console.log("f:onCanvasMouseDown()");
@ -301,7 +305,7 @@ function onCanvasMouseDown(e) {
var prevPoint = {x:-1, y:-1};
function onCanvasMouseMove(e) {
//console.log("canvasDrawing:onCanvasMouseMove");
// console.log("f:onCanvasMouseMove()");
if (!dragging) return;
@ -363,11 +367,11 @@ function onCanvasMouseUp(e) {
// console.log("f:onCanvasMouseUp()");
// console.log("onmouseup");
dragging = false;
console.log("doodleBounds: " + doodleBounds);
console.log("doodleTransform: " + doodleTransform);
//console.log("doodleBounds: " + doodleBounds);
//console.log("doodleTransform: " + doodleTransform);
// ctx.stroke();
console.log("_points.length :" + _points.length);
//console.log("_points.length :" + _points.length);
// console.log(_points);
// DEBUG
@ -383,7 +387,7 @@ function onCanvasTouchDown(e) {
setSketchModified(true);
e.preventDefault();
console.log("f:onCanvasTouchDown >> e: " , 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];
@ -404,6 +408,7 @@ function onCanvasTouchDown(e) {
}
function onCanvasTouchMove(e) {
//console.log("canvasDrawing:onCanvasTouchMove");
setSketchModified(true);
e.preventDefault();
@ -469,12 +474,12 @@ function onCanvasTouchMove(e) {
}
function onCanvasTouchEnd(e) {
console.log("f:onCanvasTouchEnd()");
console.log("doodleBounds: " + doodleBounds);
console.log("doodleTransform: " + doodleTransform);
//console.log("f:onCanvasTouchEnd()");
//console.log("doodleBounds: " + doodleBounds);
//console.log("doodleTransform: " + doodleTransform);
// ctx.stroke();
console.log("_points.length :" + _points.length);
//console.log("_points.length :" + _points.length);
// redrawPreview();
renderToImageDataPreview();

View File

@ -26,7 +26,7 @@ var prevRedrawTime = new Date().getTime();
var redrawInterval = 1000 / 30; // ms
function initPreviewRendering() {
console.log("f:initPreviewRendering()");
//console.log("f:initPreviewRendering()");
$preview = $("#preview");
preview = $preview[0];
@ -89,6 +89,7 @@ var highlight = true; //highlight bottom, middle and top layers
var linesRaw = "";
var debug_redrawSimplification = 6;
function redrawPreview(redrawLess) {
//console.log("PreviewRendering:redrawPreview");
if (redrawLess == undefined) redrawLess = false;
if (_points.length < 2) {
@ -168,6 +169,7 @@ function redrawPreview(redrawLess) {
}
function renderToImageDataPreview() {
//console.log("PreviewRendering:renderToImageDataPreview");
if (_points.length < 2) return;
//*
@ -236,9 +238,10 @@ function renderToImageDataPreview() {
previewCtx.globalAlpha = globalAlpha;
}
// called by the move up/down or twist left/right buttons
// called by the move up/down, twist left/right or new buttons
// 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) {
//console.log("PreviewRendering:redrawRenderedPreview");
if (redrawLess == undefined) redrawLess = false;
// console.log("f:redrawRenderedPreview()");
@ -248,7 +251,10 @@ function redrawRenderedPreview(redrawLess) {
var y = 0;
var r = 0;
// check if there is preview image data that we can use for the layers
if(!doodleImageCapture.src || doodleImageCapture.src == "") return;
for(var i = 0; i < numLayers; i++) {
var verticalScaleFactor = scaleFunction(i / maxNumLayers);
@ -271,7 +277,7 @@ function redrawRenderedPreview(redrawLess) {
previewCtx.scale(verticalScaleFactor, scaleY * verticalScaleFactor);
previewCtx.rotate(r);
previewCtx.translate(-layerCX,-layerCY);
previewCtx.drawImage(doodleImageCapture, 0, 0);
y -= yStep;
@ -297,6 +303,7 @@ function centeredAndScaledDoodlePoint(p) {
var updatePrevX = -1;
var updatePrevY = -1;
function updatePreview(_x, _y, redrawLess) {
//console.log("PreviewRendering:updatePreview");
if (redrawLess == undefined) redrawLess = false;
redrawLess = false;

View File

@ -1,42 +0,0 @@
/*
* This file is part of the Doodle3D project (http://doodle3d.com).
*
* Copyright (c) 2013, Doodle3D
* This software is licensed under the terms of the GNU GPL v2 or later.
* See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
*/
var keyboardShortcutsEnabled = true;
function initKeyboard() {
$(document).keypress(function(event) {
if (!keyboardShortcutsEnabled) return;
var ch = String.fromCharCode(event.which);
switch (ch) {
case 'c': clearDoodle(); break;
case 'n': clearDoodle(); break;
case 'p': print(); break;
case 'u': oopsUndo(); break;
case 'e': settingsWindow.downloadGcode(); break;
case 'q': stopPrint(); break;
case ',': openSettingsWindow(); break;
case 'C': drawCircle(250,180,80,64); break; //x,y,r,res
case 'T': drawCircle(250,180,80,3); break; //triangle
case 'X': drawCircle(250,180,80,6); break; //hexagon
case 'h': previewUp(true); break;
case 'H': previewDown(true); break;
case 's': saveSketch(); break;
case 'L': nextDoodle(); break;
case 'l': prevDoodle(); break;
case '[': previewTwistLeft(); break;
case ']': previewTwistRight(); break;
case '\'': resetTwist(); break;
default: console.log("Key: '" + ch + "' (" + event.which + ")");
}
})
}

View File

@ -1,42 +0,0 @@
/*
* This file is part of the Doodle3D project (http://doodle3d.com).
*
* Copyright (c) 2013, Doodle3D
* This software is licensed under the terms of the GNU GPL v2 or later.
* See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
*/
function drawCircle(x0,y0,r,res) {
if (res==undefined) res = 50; //circle resolution
beginShape();
var step=Math.PI * 2.0 / res;
for (var a=0; a<=Math.PI*2; a+=step) {
var x = Math.sin(a) * r + x0;
var y = Math.cos(a) * r + y0;
if (a==0) shapeMoveTo(x,y);
else shapeLineTo(x,y);
}
endShape();
}
function beginShape(x,y) {
setSketchModified(true);
}
function shapeMoveTo(x,y) {
_points.push([x, y, true]);
adjustBounds(x, y)
adjustPreviewTransformation();
draw(x, y, .5);
}
function shapeLineTo(x,y) {
_points.push([x, y, false]);
adjustBounds(x, y)
adjustPreviewTransformation();
draw(x, y);
}
function endShape() {
renderToImageDataPreview();
}

View File

@ -1,49 +0,0 @@
/*
* This file is part of the Doodle3D project (http://doodle3d.com).
*
* Copyright (c) 2013, Doodle3D
* This software is licensed under the terms of the GNU GPL v2 or later.
* See file LICENSE.txt or visit http://www.gnu.org/licenses/gpl.html for full license details.
*/
var VERTICALSHAPE;
var verticalShapes = {
"NONE": 'none',
"DIVERGING": 'diverging',
"CONVERGING": 'converging',
"SINUS": 'sinus'
};
function initVerticalShapes() {
// TODO give these vertical shapes a better spot
VERTICALSHAPE = verticalShapes.NONE;
$(".verticalShapes, .straight").on('mouseup touchend', function(e) {
e.preventDefault();
console.log("diverging");
VERTICALSHAPE = verticalShapes.NONE;
redrawRenderedPreview();
})
$(".verticalShapes, .diverging").on('mouseup touchend', function(e) {
e.preventDefault();
console.log("diverging");
VERTICALSHAPE = verticalShapes.DIVERGING;
redrawRenderedPreview();
})
$(".verticalShapes, .converging").on('mouseup touchend', function(e) {
e.preventDefault();
console.log("converging");
VERTICALSHAPE = verticalShapes.CONVERGING;
redrawRenderedPreview();
})
$(".verticalShapes, .sinus").on('mouseup touchend', function(e) {
e.preventDefault();
console.log("sinus");
VERTICALSHAPE = verticalShapes.SINUS;
redrawRenderedPreview();
})
}
function resetVerticalShapes() {
VERTICALSHAPE = verticalShapes.NONE;
}