mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2024-12-28 17:02:24 -05:00
PaperScript: Improve tool detection code.
And implement Multiple Tools example.
This commit is contained in:
parent
eceb133686
commit
e0a0cd58d5
2 changed files with 48 additions and 2 deletions
44
examples/Tools/MultipleTools.html
Normal file
44
examples/Tools/MultipleTools.html
Normal file
|
@ -0,0 +1,44 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>Mulitple Tools</title>
|
||||
<link rel="stylesheet" href="../css/style.css">
|
||||
<script type="text/javascript" src="../../dist/paper-full.js"></script>
|
||||
<script type="text/paperscript" canvas="canvas">
|
||||
// Create two drawing tools.
|
||||
// tool1 will draw straight lines, tool2 will draw clouds.
|
||||
|
||||
// Both share the mouseDown event:
|
||||
var path;
|
||||
function onMouseDown(event) {
|
||||
path = new Path();
|
||||
path.strokeColor = 'black';
|
||||
path.add(event.point);
|
||||
}
|
||||
|
||||
window.app = {
|
||||
tool1: new Tool({
|
||||
onMouseDown: onMouseDown,
|
||||
onMouseDrag: function(event) {
|
||||
path.add(event.point);
|
||||
}
|
||||
}),
|
||||
|
||||
tool2: new Tool({
|
||||
minDistance: 20,
|
||||
onMouseDown: onMouseDown,
|
||||
onMouseDrag: function(event) {
|
||||
// Use the arcTo command to draw cloudy lines
|
||||
path.arcTo(event.point);
|
||||
}
|
||||
})
|
||||
};
|
||||
</script>
|
||||
</head>
|
||||
<body>
|
||||
<a href="#" onclick="app.tool1.activate(); return false;">Lines</a>
|
||||
<a href="#" onclick="app.tool2.activate(); return false;">Clouds</a>
|
||||
<canvas id="canvas" resize></canvas>
|
||||
</body>
|
||||
</html>
|
|
@ -387,9 +387,11 @@ Base.exports.PaperScript = (function() {
|
|||
paper = scope;
|
||||
var view = scope.getView(),
|
||||
// Only create a tool if the tool object is accessed or something
|
||||
// resembling a global tool handler is contained in the code.
|
||||
// resembling a global tool handler is contained in the code, but
|
||||
// no tool objects are actually created.
|
||||
tool = /\btool\.\w+|\s+on(?:Key|Mouse)(?:Up|Down|Move|Drag)\b/
|
||||
.test(code) ? new Tool() : null,
|
||||
.test(code) && !/\bnew\s+Tool\b/.test(code)
|
||||
? new Tool() : null,
|
||||
toolHandlers = tool ? tool._events : [],
|
||||
// Compile a list of all handlers that can be defined globally
|
||||
// inside the PaperScript. These are passed on to the function as
|
||||
|
|
Loading…
Reference in a new issue