mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Implement serialization of selection.
This commit is contained in:
parent
3958d35f28
commit
9976033655
4 changed files with 54 additions and 2 deletions
42
examples/JSON/Selection.html
Normal file
42
examples/JSON/Selection.html
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Symbols</title>
|
||||||
|
<link rel="stylesheet" href="../css/style.css">
|
||||||
|
<script type="text/javascript" src="../../dist/paper.js"></script>
|
||||||
|
<script type="text/paperscript" canvas="canvas1">
|
||||||
|
var path = new Path.Ellipse({
|
||||||
|
from: [10, 10],
|
||||||
|
to: [200, 100],
|
||||||
|
fillColor: 'red'
|
||||||
|
});
|
||||||
|
path.firstSegment.handleOut.selected = true;
|
||||||
|
|
||||||
|
var circle = new Path.Circle({
|
||||||
|
center: [50, 150],
|
||||||
|
radius: 25,
|
||||||
|
fillColor: 'blue'
|
||||||
|
});
|
||||||
|
circle.selected = true;
|
||||||
|
|
||||||
|
var rectangle = new Path.Rectangle({
|
||||||
|
from: [25, 200],
|
||||||
|
to: [100, 225],
|
||||||
|
fillColor: 'green'
|
||||||
|
});
|
||||||
|
|
||||||
|
var group = new Group(circle, rectangle);
|
||||||
|
|
||||||
|
window._json = project.exportJSON();
|
||||||
|
console.log(window._json);
|
||||||
|
</script>
|
||||||
|
<script type="text/paperscript" canvas="canvas2">
|
||||||
|
project.importJSON(window._json);
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<canvas id="canvas1" width="500" height="500"></canvas>
|
||||||
|
<canvas id="canvas2" width="500" height="500"></canvas>
|
||||||
|
</body>
|
||||||
|
</html>
|
|
@ -234,8 +234,7 @@ var Point = Base.extend(/** @lends Point# */{
|
||||||
var f = options.formatter;
|
var f = options.formatter;
|
||||||
// For speed reasons, we directly call formatter.number() here, instead
|
// For speed reasons, we directly call formatter.number() here, instead
|
||||||
// of converting array through Base.serialize() which makes a copy.
|
// of converting array through Base.serialize() which makes a copy.
|
||||||
return [f.number(this.x),
|
return [f.number(this.x), f.number(this.y)];
|
||||||
f.number(this.y)];
|
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -57,6 +57,7 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
||||||
blendMode: 'normal',
|
blendMode: 'normal',
|
||||||
opacity: 1,
|
opacity: 1,
|
||||||
guide: false,
|
guide: false,
|
||||||
|
selected: false,
|
||||||
clipMask: false,
|
clipMask: false,
|
||||||
data: {}
|
data: {}
|
||||||
},
|
},
|
||||||
|
|
|
@ -24,6 +24,7 @@ var SegmentPoint = Point.extend({
|
||||||
x = y = 0;
|
x = y = 0;
|
||||||
} else if ((x = point[0]) !== undefined) { // Array-like
|
} else if ((x = point[0]) !== undefined) { // Array-like
|
||||||
y = point[1];
|
y = point[1];
|
||||||
|
selected = point[2]; // See #_serialize()
|
||||||
} else {
|
} else {
|
||||||
// If not Point-like already, read Point from arguments
|
// If not Point-like already, read Point from arguments
|
||||||
if ((x = point.x) === undefined) {
|
if ((x = point.x) === undefined) {
|
||||||
|
@ -47,6 +48,15 @@ var SegmentPoint = Point.extend({
|
||||||
return this;
|
return this;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
_serialize: function(options) {
|
||||||
|
var f = options.formatter,
|
||||||
|
values = [f.number(this._x), f.number(this._y)];
|
||||||
|
// Included the selected state of the segment point
|
||||||
|
if (this.isSelected())
|
||||||
|
values.push(true);
|
||||||
|
return values;
|
||||||
|
},
|
||||||
|
|
||||||
getX: function() {
|
getX: function() {
|
||||||
return this._x;
|
return this._x;
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue