Skip to content

Instantly share code, notes, and snippets.

@nsdevaraj
Created December 21, 2011 15:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nsdevaraj/1506440 to your computer and use it in GitHub Desktop.
Save nsdevaraj/1506440 to your computer and use it in GitHub Desktop.
draw SVG Shape
private function drawShape(shape:String, mouseType:String):void
{
trace("Start X : "+drawStartX+" ::: "+drawStartY+" :: "+drawStopX+" :: "+drawStopY)
if(mouseType == MouseEvent.MOUSE_DOWN)
{
drawStartX = this.mouseX;
drawStartY = this.mouseY;
drawStart = true;
svgData = "";
shapeNoOfPoint = 0;
trace(convertToRGB(this.fillColor) +" ::fillColor:: "+this.fillColor)
svgData='<'+shape+' fill="#'+convertToRGB(this.fillColor)+'" style="stroke:#'+convertToRGB(this.strokeColor)+';stroke-width:2;fill-opacity:0.5" '
if(shape == HIGHLIGHT || shape == BRUSH)
{
(shape == BRUSH)?this.drawingCanvas.graphics.lineStyle(2,strokeColor,1):this.drawingCanvas.graphics.lineStyle(5,fillColor,0.5);
this.drawingCanvas.graphics.moveTo(drawStartX, drawStartY);
var ifHL:String = ((shape == HIGHLIGHT)?"stroke-opacity:0.5":"")
svgData='<path style="stroke:#'+convertToRGB(this.fillColor)+';stroke-width:5;'+ifHL+'" fill="none" d="M'+drawStartX+' '+drawStartY;
}
}
if(mouseType == MouseEvent.MOUSE_MOVE)
{
drawStopX = this.mouseX;
drawStopY = this.mouseY;
if(shape == HIGHLIGHT || shape == BRUSH)
{
var pos:Number = (shape == HIGHLIGHT)?3:0
this.drawingCanvas.graphics.lineTo(drawStopX-pos , drawStopY-pos);
svgData += ' L'+(drawStopX-pos)+' '+(drawStopY-pos);
shapeNoOfPoint++;
}
else{
this.drawingCanvas.graphics.clear();
this.drawingCanvas.graphics.lineStyle(2,strokeColor,1);
this.drawingCanvas.graphics.beginFill(fillColor, 0.5);
}
if(shape == RECTANGLE)
{
this.drawingCanvas.graphics.drawRect(drawStartX, drawStartY, drawStopX-drawStartX, drawStopY-drawStartY);
}
if(shape == OVAL)
{
this.drawingCanvas.graphics.drawEllipse( drawStartX, drawStartY, drawStopX-drawStartX, drawStopY-drawStartY);
}
if(shape == LINE)
{
this.drawingCanvas.graphics.moveTo(drawStartX , drawStartY);
this.drawingCanvas.graphics.lineTo(drawStopX , drawStopY);
}
}
if(mouseType == MouseEvent.MOUSE_UP)
{
if(drawStart){
drawStopX = this.mouseX;
drawStopY = this.mouseY;
}
var xVal:Number = (drawStartX<drawStopX)?drawStartX:drawStopX;
var yVal:Number = (drawStartY<drawStopY)?drawStartY:drawStopY;
var widthVal:Number = Math.abs(drawStartX-drawStopX);
var heightVal:Number = Math.abs(drawStartY-drawStopY);
var xPos:Number = 0;
var yPos:Number = 0;
if(shape == LINE)
{
svgData += 'x1="'+drawStartX+'" y1="'+drawStartY+'" x2="'+drawStopX+'" y2="'+drawStopY+'"/>';
xPos = drawStartX;
yPos = drawStartY;
}
if(shape == RECTANGLE)
{
svgData+= 'x="'+xVal+'" y="'+yVal+'" width="'+widthVal+'" height="'+heightVal+'"/>';
xPos = xVal;
yPos = yVal;
}
if(shape == OVAL)
{
svgData+= 'cx="'+(xVal+(widthVal/2))+'" cy="'+(yVal+(heightVal/2))+'" rx="'+widthVal/2+'" ry="'+heightVal/2+'"/>';
xPos = xVal;
yPos = yVal+heightVal/2;
}
if(shape == HIGHLIGHT || shape == BRUSH)
{
svgData+= '"/>';
xPos = drawStartX;
yPos = drawStartY;
}
if(Math.abs(drawStartX-drawStopX) > minimumNoteWidth || Math.abs(drawStartY-drawStopY) > minimumNoteHeight || shapeNoOfPoint>7)
{
model.pdfDetailVO.notesModificationHistoryAC.addItem({name:model.person.personFirstname +"( "+ (GetVOUtil.getProfileObject(model.person.defaultProfile).profileLabel.substr(0,3)) +" )",title:shape.substr(0,1).toUpperCase()+shape.substr(1),desc:"", status: "New Comment"});
isLastCommentIsNew = true;
var commentEvent:CommentEvent;
commentEvent = new CommentEvent(CommentEvent.ADD_COMMENT, null, svgData+SinglePageCanvas.SHAPE_FIRST_NOTE_SPLITTER, shape.substr(0,1).toUpperCase()+shape.substr(1) ,xPos.toString(),yPos.toString(),"0","0","0","2", "4", false, ModelLocator.getInstance().person.personId, (Math.random()*200+50), (Math.random()*200+50), false, GetVOUtil.getProfileObject(model.person.defaultProfile).profileLabel);
//commentEvent = new CommentEvent(CommentEvent.ADD_COMMENT, null, svgData, shape.substr(0,1).toUpperCase()+shape.substr(1) ,"0","0","0","0","0","2", "4", false, ModelLocator.getInstance().person.personId, 0, 0, false, GetVOUtil.getProfileObject(model.person.defaultProfile).profileLabel);
commentEvent.dispatch();
}
else{
this.drawingCanvas.graphics.clear();
}
drawStart = false;
shapeNoOfPoint = 0;
drawStartX = drawStartY = drawStopX = drawStopY = 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment