我有一个简单的应用程序,将绘制一条直线,矩形和多边形。
我正在使用纸张.js但不知道如何控制流量。
仅当单击线条(按钮)时才应绘制线条。目前,默认情况下,该线绘制在画布上。
<!-- templates/index.html -->
<html>
<head>
<title>Annotation Tool</title>
<!-- CSS Files -->
<link rel="stylesheet" href="/static/node_modules/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="/static/css/style.css">
<!-- Javascript files -->
<script src="/static/node_modules/jquery/dist/jquery.min.js" charset="utf-8"></script>
<script src="/static/node_modules/bootstrap/dist/js/bootstrap.min.js" charset="utf-8"></script>
<script src="/static/js/scripts.js" charset="utf-8"></script>
<!-- Paper files -->
<script src="/static/node_modules/paper/dist/paper-full.min.js" charset="utf-8"></script>
<script type="text/paperscript" src="/static/js/paperscript.js" charset="utf-8" canvas="myCanvas"></script>
</head>
<body>
<script>
</script>
<div class="container">
<div class="row row-bordered">
<div class="btn-toolbar">
<button type="button" class="btn btn-primary" id="draw-line">Line</button>
<button type="button" class="btn btn-primary" id="draw-rect">Rectangle</button>
<button type="button" class="btn btn-primary" id="draw-poly">Polygon</button>
</div>
</div>
<canvas id="myCanvas"></canvas>
<!--<div class="row">-->
<!--<img src="/static/images/lena.png" alt="Italian Trulli">-->
<!--</div>-->
</div>
</body>
</html>
tool.minDistance = 10;
var path;
function onMouseDown(event) {
// Create a new path and give it a stroke color:
path = new Path();
path.strokeColor = '#00000';
// Add a segment to the path where
// you clicked:
path.add(event.point);
}
function onMouseDrag(event) {
// Every drag event, add a segment
// to the path at the position of the mouse:
path.add(event.point);
}
function internalClicked() {
alert('clicked!');
}
globals.onMouseDown = onMouseDown
globals.onMouseDrag = onMouseDrag
globals.internalClicked = internalClicked
// 脚本.js
var globals = {}
$(document).ready(function(){
$('#draw-line').click(function(){
// how can I pass this function to paper script, so that before drawing the line I can check if the draw-line is clicked.
// or how can I override the mouseclickevents of paperjs in javascript.
})
})