pathutility.js revision 38688a22f899a470ad6fb8c7d60c503cff7035ff
var myline,
///////////////////// pencil //////////////////////
var jsStr = '',
ctrlIsDown = false,
altIsDown = false,
curveInProgress = false,
myX,
myY,
cp1X,
cp1Y,
cp2X,
cp2Y,
}),
});
});
if(curveInProgress){
}
});
if((isNewObj)&&(!ctrlIsDown)){
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(ctrlIsDown){
toMethod = 'moveTo';
}else if(altIsDown){
//mycurve.set("stroke", {color: "#0f0"});
curveInProgress = true;
return; // Do not write code in box. Do not update prevX prevY
}else{
toMethod = 'lineTo';
}
});
// inserts code into text area
var insertCode = function(methodStr){
code.remove(); // If the user types into the textarea, the contents would not update anymore, So removed then created a new one
code = Y.Node.create('<textarea class="code" rows="8" cols="5">copy generated code from here</textarea>');
}
var finalizeCurve = function(){
// draw myline where mycurve was
var methodStr;
// try to clear mycurve, but no luck 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){
ctrlIsDown = true; // This will be a myLine.moveTo
}else if(e.altKey){
altIsDown = true; // triggers a curve line
}
},document);
Y.on('keyup', function(e){
ctrlIsDown = false; // This will be a myLine.lineTo
altIsDown = false; // Will this cause bug if multiple keys are down?
},document);
// when user changes the object name in the input box "Graphic Object Name"
Y.on('change', function(){
jsStr += makeStrForNewObject();
//jsStr += objName + '.end(); // lastEndMarker\r\n';
}
},inpObjName);
var makeStrForNewObject = function(){
' = mygraphic.addShape({\r\n'+
' type: "path",\r\n'+
' stroke: {\r\n'+
' weight: 2,\r\n'+
' color: "#00dd00"\r\n'+
' },\r\n'+
' fill: {\r\n'+
' type: "linear",\r\n'+
' stops: [\r\n'+
' {color: "#cc0000", opacity: 1, offset: 0},\r\n'+
' {color: "#00cc00", opacity: 0.3, offset: 0.8}\r\n'+
' ]\r\n'+
' }\r\n'+
'});\r\n'+
objName + '.end(); // lastEndMarker\r\n'+
'';
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();
});