2011-03-07 00:50:44 +00: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.
|
2011-03-08 01:41:50 +00:00
|
|
|
* http://paperjs.org/
|
2011-03-07 00:50:44 +00:00
|
|
|
* http://scriptographer.org/
|
|
|
|
*
|
2011-03-08 01:41:50 +00:00
|
|
|
* Distributed under the MIT license. See LICENSE file for details.
|
|
|
|
*
|
2011-03-07 00:50:44 +00:00
|
|
|
* Copyright (c) 2011, Juerg Lehni & Jonathan Puckey
|
|
|
|
* http://lehni.org/ & http://jonathanpuckey.com/
|
|
|
|
*
|
2011-03-08 01:41:50 +00:00
|
|
|
* All rights reserved.
|
2011-03-07 00:50:44 +00:00
|
|
|
*/
|
|
|
|
|
2011-03-04 13:34:31 +00:00
|
|
|
var Layer = this.Layer = Group.extend({
|
2011-02-16 00:18:58 +00:00
|
|
|
beans: true,
|
|
|
|
|
2011-02-11 18:37:36 +01:00
|
|
|
initialize: function() {
|
2011-05-17 13:14:23 +01:00
|
|
|
// TODO: Isn't there a way to call this.base() here and then move the
|
|
|
|
// layer into layers instead?
|
2011-05-14 18:07:10 +01:00
|
|
|
this._children = [];
|
2011-05-15 19:12:27 +02:00
|
|
|
this._namedChildren = {};
|
2011-05-16 13:33:15 +01:00
|
|
|
this._project = paper.project;
|
|
|
|
// Push it onto project.layers and set index:
|
|
|
|
this._index = this._project.layers.push(this) - 1;
|
2011-02-12 16:20:10 +01:00
|
|
|
this.activate();
|
|
|
|
},
|
2011-02-16 00:18:58 +00:00
|
|
|
|
2011-02-16 18:55:12 +01:00
|
|
|
/**
|
2011-05-16 13:33:15 +01:00
|
|
|
* Removes the layer from its project's layers list
|
2011-02-16 18:55:12 +01:00
|
|
|
* or its parent's children list.
|
|
|
|
*/
|
2011-05-07 14:50:48 +01:00
|
|
|
_removeFromParent: function() {
|
2011-05-14 17:56:14 +01:00
|
|
|
return this._parent ? this.base()
|
2011-05-16 13:33:15 +01:00
|
|
|
: !!Base.splice(this._project.layers, null, this._index, 1).length;
|
2011-02-16 18:55:12 +01:00
|
|
|
},
|
2011-03-03 22:45:17 +00:00
|
|
|
|
2011-02-16 18:55:12 +01:00
|
|
|
getNextSibling: function() {
|
2011-05-14 17:56:14 +01:00
|
|
|
return this._parent ? this.base()
|
2011-05-16 13:33:15 +01:00
|
|
|
: this._project.layers[this._index + 1] || null;
|
2011-02-16 18:55:12 +01:00
|
|
|
},
|
2011-03-03 22:45:17 +00:00
|
|
|
|
2011-02-16 18:55:12 +01:00
|
|
|
getPreviousSibling: function() {
|
2011-05-14 17:56:14 +01:00
|
|
|
return this._parent ? this.base()
|
2011-05-16 13:33:15 +01:00
|
|
|
: this._project.layers[this._index - 1] || null;
|
2011-02-16 18:55:12 +01:00
|
|
|
},
|
2011-02-16 00:18:58 +00:00
|
|
|
|
2011-02-12 16:20:10 +01:00
|
|
|
activate: function() {
|
2011-05-16 13:33:15 +01:00
|
|
|
this._project.activeLayer = this;
|
2011-02-11 18:37:36 +01:00
|
|
|
}
|
2011-03-05 01:53:32 +00:00
|
|
|
}, new function () {
|
|
|
|
function move(above) {
|
|
|
|
return function(item) {
|
2011-05-16 13:33:15 +01:00
|
|
|
// if the item is a layer and contained within Project#layers
|
2011-05-14 17:56:14 +01:00
|
|
|
if (item instanceof Layer && !item._parent
|
2011-05-07 17:27:19 +01:00
|
|
|
&& this._removeFromParent()) {
|
2011-05-16 13:33:15 +01:00
|
|
|
Base.splice(item._project.layers, [this],
|
2011-05-07 17:27:19 +01:00
|
|
|
item._index + (above ? 1 : -1), 0);
|
2011-05-16 13:33:15 +01:00
|
|
|
this._setProject(item._project);
|
2011-03-05 01:53:32 +00:00
|
|
|
return true;
|
|
|
|
}
|
2011-05-07 17:27:19 +01:00
|
|
|
return this.base(item);
|
2011-05-02 12:23:42 +02:00
|
|
|
};
|
2011-03-05 01:53:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
moveAbove: move(true),
|
|
|
|
|
|
|
|
moveBelow: move(false)
|
|
|
|
};
|
2011-02-13 16:26:24 +00:00
|
|
|
});
|