var line = (function() { // dashed line var tool = {}; var states = ["primeiro_ponto", "segundo_ponto"]; var state = undefined; var points = [0, 0, 0, 0]; function drawLine() { if (state == undefined) { state = states[0]; app.setStatus("Selecione o primeiro ponto no canvas"); } else if (state == states[0]) { var pos = app.pos(); points[0] = pos.x; points[1] = pos.y; state = states[1]; app.setStatus("Selecione o segundo ponto no canvas"); } else if (state == states[1]) { var pos = app.pos(); points[2] = pos.x; points[3] = pos.y; var p = points.slice(); var ln = new Konva.Line({ points: p, stroke: "grey", strokeWidth: 2, lineJoin: "round", draggable: true, strokeScaleEnabled: false }); var layer = app.currentLayer(); layer.add(ln); app.stage.add(layer); app.stage.draw(); state = undefined; app.clearSelectedTool(); app.setStatus(""); } } function bootstrap() { app.tools.push(tool); } function onClick() { app.setSelectedTool(tool); state = states[0]; app.setStatus("Selecione o primeiro ponto no canvas"); } tool = { id: "reta", title: "Reta", icon: "line", click: onClick, draw: drawLine, points: points }; bootstrap(); return { drawLine: drawLine, onClick: onClick }; })();