2011-02-21 08:31:26 -05:00
|
|
|
<!DOCTYPE html>
|
2011-02-08 19:10:55 -05:00
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
|
|
|
<title>Example</title>
|
2011-03-03 11:56:31 -05:00
|
|
|
<script type="text/javascript" src="../../lib/bootstrap.js"></script>
|
2011-02-12 10:20:10 -05:00
|
|
|
<script type="text/javascript" src="../../src/Paper.js"></script>
|
2011-02-16 16:35:17 -05:00
|
|
|
<script type="text/javascript" src="../../src/tool/ToolEvent.js"></script>
|
|
|
|
<script type="text/javascript" src="../../src/tool/ToolHandler.js"></script>
|
|
|
|
<script type="text/javascript" src="../../src/tool/Tool.js"></script>
|
2011-02-12 11:59:39 -05:00
|
|
|
<script type="text/javascript" src="../../src/basic/Point.js"></script>
|
|
|
|
<script type="text/javascript" src="../../src/basic/Rectangle.js"></script>
|
|
|
|
<script type="text/javascript" src="../../src/basic/Size.js"></script>
|
2011-02-16 16:35:17 -05:00
|
|
|
<script type="text/javascript" src="../../src/basic/Matrix.js"></script>
|
2011-03-02 11:18:32 -05:00
|
|
|
<script type="text/javascript" src="../../src/document/DocumentView.js"></script>
|
2011-03-03 12:23:27 -05:00
|
|
|
<script type="text/javascript" src="../../src/document/Document.js"></script>
|
2011-02-20 17:28:38 -05:00
|
|
|
<script type="text/javascript" src="../../src/document/Symbol.js"></script>
|
2011-02-16 16:35:17 -05:00
|
|
|
<script type="text/javascript" src="../../src/item/Item.js"></script>
|
2011-02-20 17:28:38 -05:00
|
|
|
<script type="text/javascript" src="../../src/item/PlacedSymbol.js"></script>
|
2011-02-16 16:35:17 -05:00
|
|
|
<script type="text/javascript" src="../../src/item/Group.js"></script>
|
|
|
|
<script type="text/javascript" src="../../src/item/Layer.js"></script>
|
2011-03-02 20:25:45 -05:00
|
|
|
<script type="text/javascript" src="../../src/item/Raster.js"></script>
|
2011-02-16 16:35:17 -05:00
|
|
|
<script type="text/javascript" src="../../src/item/PathStyle.js"></script>
|
2011-02-12 11:59:39 -05:00
|
|
|
<script type="text/javascript" src="../../src/path/Segment.js"></script>
|
|
|
|
<script type="text/javascript" src="../../src/path/PathItem.js"></script>
|
|
|
|
<script type="text/javascript" src="../../src/path/Path.js"></script>
|
2011-03-02 20:25:45 -05:00
|
|
|
<script type="text/javascript" src="../../src/path/CompoundPath.js"></script>
|
2011-02-17 09:56:07 -05:00
|
|
|
<script type="text/javascript" src="../../src/path/Path.Constructors.js"></script>
|
2011-02-19 11:56:15 -05:00
|
|
|
<script type="text/javascript" src="../../src/color/Color.js"></script>
|
|
|
|
<script type="text/javascript" src="../../src/color/RGBColor.js"></script>
|
|
|
|
<script type="text/javascript" src="../../src/color/GrayColor.js"></script>
|
2011-02-20 17:28:38 -05:00
|
|
|
<script type="text/javascript" src="../../src/color/GradientColor.js"></script>
|
|
|
|
<script type="text/javascript" src="../../src/color/Gradient.js"></script>
|
|
|
|
<script type="text/javascript" src="../../src/color/GradientStop.js"></script>
|
2011-02-08 19:10:55 -05:00
|
|
|
<script>
|
|
|
|
window.onload = function() {
|
|
|
|
var canvas = document.getElementById('canvas');
|
2011-03-03 12:23:27 -05:00
|
|
|
var doc = new Document(canvas);
|
2011-02-08 19:10:55 -05:00
|
|
|
|
|
|
|
var path;
|
|
|
|
var minSize = 5;
|
|
|
|
|
|
|
|
var tool = new Tool({
|
|
|
|
onMouseDrag: function(event) {
|
|
|
|
// If the user dragged more then minSize:
|
2011-02-11 08:58:53 -05:00
|
|
|
if (event.delta.length > minSize) {
|
2011-02-08 19:10:55 -05:00
|
|
|
// If there is no path, make one:
|
|
|
|
if (!path) {
|
|
|
|
path = new Path();
|
|
|
|
path.fillColor = 'black';
|
|
|
|
path.add(event.lastPoint);
|
|
|
|
}
|
|
|
|
|
2011-02-11 08:58:53 -05:00
|
|
|
var step = event.delta.divide(2);
|
|
|
|
step.angle = step.angle + 90;
|
2011-02-08 19:10:55 -05:00
|
|
|
|
|
|
|
// The top point: the middle point + the step rotated by 90 degrees:
|
|
|
|
// -----*
|
|
|
|
// |
|
|
|
|
// ------
|
2011-02-11 08:58:53 -05:00
|
|
|
var top = event.middlePoint.add(step);
|
2011-02-08 19:10:55 -05:00
|
|
|
|
|
|
|
// The bottom point: the middle point - the step rotated by 90 degrees:
|
|
|
|
// ------
|
|
|
|
// |
|
|
|
|
// -----*
|
2011-02-11 08:58:53 -05:00
|
|
|
var bottom = event.middlePoint.subtract(step);
|
2011-02-08 19:10:55 -05:00
|
|
|
|
|
|
|
path.add(top);
|
|
|
|
path.insert(0, bottom);
|
|
|
|
path.smooth();
|
|
|
|
} else {
|
|
|
|
// If the user dragged too slowly:
|
|
|
|
|
|
|
|
// If there is currently a path, close it
|
|
|
|
if (path) {
|
2011-02-11 08:58:53 -05:00
|
|
|
path.add(event.point);
|
2011-02-08 19:10:55 -05:00
|
|
|
path.closed = true;
|
|
|
|
path.smooth();
|
|
|
|
|
|
|
|
// Set path to null (nothing) so the path check above
|
|
|
|
// will force a new path next time the user drags fast enough:
|
|
|
|
path = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
onMouseUp: function(event) {
|
|
|
|
if (path) {
|
2011-02-11 08:58:53 -05:00
|
|
|
path.add(event.point);
|
2011-02-08 19:10:55 -05:00
|
|
|
path.closed = true;
|
|
|
|
path.smooth();
|
|
|
|
|
|
|
|
// Set path to null (nothing) so the path check above
|
|
|
|
// will force a new path next time the user drags fast enough:
|
|
|
|
path = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2011-02-11 08:58:53 -05:00
|
|
|
tool.maxDistance = 20;
|
2011-02-08 19:10:55 -05:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
</head>
|
|
|
|
<body>
|
|
|
|
<canvas id='canvas' width=1024 height=768></canvas>
|
|
|
|
</body>
|