2011-05-16 08:33:15 -04:00
|
|
|
/*
|
|
|
|
* Paper.js
|
|
|
|
*
|
|
|
|
* This file is part of Paper.js, a JavaScript Vector Graphics Library,
|
|
|
|
* based on Scriptographer.org and designed to be largely API compatible.
|
|
|
|
* http://paperjs.org/
|
|
|
|
* http://scriptographer.org/
|
|
|
|
*
|
|
|
|
* Distributed under the MIT license. See LICENSE file for details.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
|
|
|
|
* http://lehni.org/ & http://jonathanpuckey.com/
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
var Symbol = this.Symbol = Base.extend({
|
2011-05-23 12:28:48 -04:00
|
|
|
/** @lends Symbol# */
|
|
|
|
|
2011-05-16 08:33:15 -04:00
|
|
|
beans: true,
|
|
|
|
|
2011-05-23 12:28:48 -04:00
|
|
|
/**
|
|
|
|
* Creates a Symbol item.
|
|
|
|
*
|
|
|
|
* Sample code:
|
|
|
|
* @example
|
|
|
|
* var circlePath = new Path.Circle(new Point(100, 100), 50);
|
|
|
|
* circlePath.fillColor = 'red';
|
|
|
|
*
|
|
|
|
* var circleSymbol = new Symbol(circlePath);
|
|
|
|
* circleSymbol.name = 'Circle';
|
|
|
|
*
|
|
|
|
* // The original item is still contained in the document:
|
|
|
|
* circlePath.remove();
|
|
|
|
*
|
|
|
|
* // The symbol can now also be accessed
|
|
|
|
* // through project.symbols:
|
|
|
|
* console.log(project.symbols['Circle']);
|
|
|
|
*
|
|
|
|
* // To place instances of the symbol in the document:
|
|
|
|
* var placedCircle = new PlacedSymbol(circleSymbol);
|
|
|
|
* placedCircle.position = new Point(150, 150);
|
|
|
|
*
|
|
|
|
* @param {Item} item the source item which is copied as the definition of
|
|
|
|
* the symbol
|
|
|
|
*
|
|
|
|
* @name Symbol
|
|
|
|
* @constructor
|
|
|
|
*
|
|
|
|
* @class Symbols allow you to place multiple instances of an item in your
|
|
|
|
* project. This can save memory, since all instances of a symbol
|
|
|
|
* simply refer to the original item and it can speed up moving
|
|
|
|
* around complex objects, since internal properties such as segment
|
|
|
|
* lists and gradient positions don't need to be updated with every
|
|
|
|
* transformation.
|
|
|
|
*/
|
2011-05-16 08:33:15 -04:00
|
|
|
initialize: function(item) {
|
|
|
|
this.project = paper.project;
|
|
|
|
this.project.symbols.push(this);
|
|
|
|
this.setDefinition(item);
|
|
|
|
},
|
|
|
|
|
2011-05-20 03:55:44 -04:00
|
|
|
// TODO: remove()
|
|
|
|
|
2011-05-23 12:28:48 -04:00
|
|
|
/**
|
|
|
|
* The symbol definition.
|
|
|
|
*
|
|
|
|
* @type Item
|
|
|
|
* @bean
|
|
|
|
*/
|
2011-05-16 08:33:15 -04:00
|
|
|
getDefinition: function() {
|
|
|
|
return this._definition;
|
|
|
|
},
|
|
|
|
|
|
|
|
setDefinition: function(item) {
|
|
|
|
this._definition = item;
|
2011-05-21 15:33:43 -04:00
|
|
|
// Deselect the item, as PlacedSymbol has its own selection.
|
|
|
|
item.setSelected(false);
|
2011-05-16 08:33:15 -04:00
|
|
|
item._removeFromParent();
|
2011-05-20 03:55:44 -04:00
|
|
|
// Move position to 0, 0. TODO: Why?
|
2011-05-16 08:33:15 -04:00
|
|
|
item.setPosition(new Point());
|
2011-05-23 12:28:48 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a copy of the symbol.
|
|
|
|
*
|
|
|
|
* @return {Symbol}
|
|
|
|
*/
|
|
|
|
clone: function() {
|
|
|
|
return new Symbol(this._definition.clone());
|
2011-05-16 08:33:15 -04:00
|
|
|
}
|
|
|
|
});
|