// developed by jinni of moonfun studio // email: jinnilove@126.com var start; var height; var daimeter; var ratio; var fillColor,strokeColor; function init() { daimeter = theTool.daimeter; ratio = theTool.ratio; fillColor = theTool.fillColor; strokeColor = theTool.strokeColor; } function configureTool() { theTool = fl.tools.activeTool; theTool.setToolName("Cylinder"); theTool.setIcon("Cylinder.png"); theTool.setMenuString("Cylinder"); theTool.setToolTip("Cylinder"); theTool.setOptionsFile( "Cylinder.xml" ); init(); } function notifySettingsChanged() { theTool = fl.tools.activeTool; init(); } function activate() { theTool = fl.tools.activeTool; } function deactivate() { } function mouseDown() { var pointX = fl.tools.penLoc.x; var pointY = fl.tools.penLoc.y; start={x:pointX,y:pointY}; fl.drawingLayer.beginDraw(); } function mouseMove() { if(fl.tools.mouseIsDown){ height = fl.tools.penLoc.y - start.y; fl.drawingLayer.beginFrame(); fl.drawingLayer.moveTo(start.x,start.y); fl.drawingLayer.lineTo(start.x-daimeter,start.y); fl.drawingLayer.lineTo(start.x-daimeter,start.y+height); fl.drawingLayer.lineTo(start.x,start.y+height); fl.drawingLayer.lineTo(start.x,start.y); fl.drawingLayer.endFrame(); } } function mouseUp() { var doc; doc=fl.getDocumentDOM(); fl.drawingLayer.endDraw(); if(height>=10) { var oval_top = {left:(start.x-daimeter), top:start.y, right:start.x, bottom:(start.y+(daimeter/ratio))}; var oval_bottom = {left:(start.x-daimeter), top:(start.y+height), right:start.x, bottom:(start.y+(daimeter/ratio)+height)}; var rect_eraser = {left:(start.x-daimeter), top:(start.y+height), right:start.x, bottom:(start.y+height+(daimeter/ratio/2))}; var rect_fill = {left:(start.x-daimeter), top:(start.y+(daimeter/ratio/2)), right:start.x, bottom:(start.y+height+(daimeter/ratio/2))}; var rect_total = {left:(start.x-daimeter-1), top:(start.y-1), right:(start.x+1), bottom:(start.y+(daimeter/ratio)+height+1)}; doc.addNewOval(oval_bottom); doc.setSelectionRect(rect_eraser); doc.deleteSelection(); doc.addNewRectangle(rect_fill,0,0,1); doc.addNewOval(oval_top); doc.addNewLine({x:start.x,y:(start.y+(daimeter/ratio/2))},{x:start.x,y:(start.y+height+(daimeter/ratio/2))}); doc.addNewLine({x:(start.x-daimeter-0.5),y:(start.y+(daimeter/ratio/2))},{x:(start.x-daimeter-0.5),y:(start.y+height+(daimeter/ratio/2))}); doc.setSelectionRect(rect_total); doc.setFillColor(fillColor); doc.setStrokeColor(strokeColor); } }