path-tool.js revision bd8602ea6a0a0749b673d9ee28d1ae8d5808175b
var myline,
///////////////////// pencil //////////////////////
var jsStr = '',
shiftIsDown = false,
altIsDown = false,
curveInProgress = false,
prevToMethod = 'moveTo', // this is part of a patch for the problem that multiple moveTo commands = lineTo See drag:end
myX,
myY,
cp1X,
cp1Y,
cp2X,
cp2Y,
}),
});
});
if(curveInProgress){
}
});
if((isNewObj)&&(!shiftIsDown)){
myline.moveTo(myX,myY); //fixes issue of graphics needs a moveTo to start a new object or it won't draw.
isNewObj = false;
}
});
});
var newObjStr = "",
if(shiftIsDown){
toMethod = 'moveTo';
if(prevToMethod === 'moveTo'){ // this is part of a patch for the problem that multiple moveTo commands = lineTo
Y.log('double moveto issue') ;
}
prevToMethod = 'moveTo';
}else if(altIsDown){
curveInProgress = true;
prevToMethod = '';
return; // Do not write code in box. Do not update prevX prevY
}else{
toMethod = 'lineTo';
prevToMethod = '';
}
if(toMethod === 'moveTo'){
// this is part of a patch for the problem that multiple moveTo commands = lineTo See drag:end
} else{
}
});
// inserts code into text area
var insertCode = function(methodStr){
}
var finalizeCurve = function(){
// draw myline where mycurve was
var methodStr;
// try to clear mycurve, FIXME
toMethod = 'curveTo';
methodStr = '.' + toMethod + '(' + cp1X + ',' + cp1Y + ',' + cp2X + ',' + cp2Y + ',' + myX + ',' + myY + ');\r\n' + objName + '.end(); // lastEndMarker';
curveInProgress = false;
}
Y.on('keydown', function(e){
if(e.shiftKey){
shiftIsDown = true; // This will be a myLine.moveTo
//Y.one('.pencil-img-container').addClass('pencil-img-container-moving'); // doesn't work in IE6
}else if(e.altKey){
altIsDown = true; // triggers a curve line
}
},document);
Y.on('keyup', function(e){
shiftIsDown = false; // This will be a myLine.lineTo
altIsDown = false; // Will this cause bug if multiple keys are down?
//Y.one('.pencil-img-container').removeClass('pencil-img-container-moving'); // doesn't work in IE6
},document);
// when user changes the object name in the input box "Graphic Object Name"
Y.on('change', function(){
if(prevToMethod === 'moveTo'){ // this is part of a patch for the problem that multiple moveTo commands = lineTo
Y.log('double moveto issue on new obj creation') ;
jsStr = jsStr.substring(0, jsStr.lastIndexOf('.moveTo(')) + '.end();\r\n\r\n'; // remove the last moveTo because a new object is being created
}
jsStr += makeStrForNewObject();
}
},inpObjName);
var makeStrForNewObject = function(){
var newLine = '\r\n',
' = mygraphic.addShape({' + newLine +
' type: "path",' + newLine +
' stroke: {' + newLine +
' weight: 2,' + newLine +
' color: "#00dd00"' + newLine +
' },' + newLine +
' fill: {' + newLine +
' type: "linear",' + newLine +
' stops: [' + newLine +
' {color: "#cc0000", opacity: 1, offset: 0},' + newLine +
' {color: "#00cc00", opacity: 0.3, offset: 0.8}' + newLine +
' ]' + newLine +
' }' + newLine +
'});' + newLine +
'';
return newObjStr;
}
// init code gen box
jsStr += makeStrForNewObject();
////////////////////////////////////// end pencil code /////////////////////
function loadGraphics(e)
{
// line object reused for all lines
type: "path",
stroke: {
weight: 1,
color: "#ff0000",
opacity: 1
}
});
// curve object reused for all curve
type: "path",
stroke: {
weight: 1,
color: "#f00",
//dashstyle: [3,3]
}
});
}
loadGraphics();
});