mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Rename Paper to paper, implement it as an object literal and add paper.populate() and paper.install() methods that do the bootstraping.
This commit is contained in:
parent
6923e168ab
commit
d088dc629e
10 changed files with 42 additions and 32 deletions
|
@ -58,7 +58,7 @@
|
|||
}
|
||||
});
|
||||
|
||||
var children = Paper.document.activeLayer.children;
|
||||
var children = paper.document.activeLayer.children;
|
||||
var count = 0;
|
||||
function draw() {
|
||||
count++;
|
||||
|
|
10
src/Paper.js
10
src/Paper.js
|
@ -1,10 +0,0 @@
|
|||
var Paper = Base.extend({
|
||||
statics: {
|
||||
documents: [],
|
||||
activateDocument: function(doc) {
|
||||
var index = this.documents.indexOf(doc);
|
||||
if (index != -1)
|
||||
this.document = this.documents[index];
|
||||
}
|
||||
}
|
||||
});
|
14
src/build.js
14
src/build.js
|
@ -1,6 +1,6 @@
|
|||
(function(scope) {
|
||||
|
||||
#include "Paper.js"
|
||||
#include "paper.js"
|
||||
|
||||
#include "basic/Point.js"
|
||||
#include "basic/Size.js"
|
||||
|
@ -36,15 +36,7 @@
|
|||
#include "tool/ToolHandler.js"
|
||||
#include "tool/Tool.js"
|
||||
|
||||
// Now inject all these local prototypes into the paper scope.
|
||||
Base.each(['Point', 'Size', 'Rectangle', 'Matrix', 'DocumentView', 'Doc',
|
||||
'Symbol', 'Item', 'Group', 'Layer', 'Raster', 'PlacedSymbol', 'PathStyle',
|
||||
'Segment', 'Curve', 'PathItem', 'Path', 'CompoundPath', 'Color', 'RGBColor',
|
||||
'GrayColor', 'GradientColor', 'Gradient', 'GradientStop', 'ToolEvent',
|
||||
'ToolHandler', 'Tool'],
|
||||
function(name) {
|
||||
scope[name] = eval(name);
|
||||
}
|
||||
);
|
||||
paper.populate();
|
||||
paper.install(scope);
|
||||
|
||||
})(this);
|
||||
|
|
|
@ -13,7 +13,7 @@ var Doc = Base.extend({
|
|||
}
|
||||
this.bounds = new Rectangle(new Point(0, 0), this.size);
|
||||
this.ctx = this.canvas.getContext('2d');
|
||||
Paper.documents.push(this);
|
||||
paper.documents.push(this);
|
||||
this.activate();
|
||||
this.layers = [];
|
||||
this.activeLayer = new Layer();
|
||||
|
@ -32,7 +32,12 @@ var Doc = Base.extend({
|
|||
},
|
||||
|
||||
activate: function() {
|
||||
Paper.activateDocument(this);
|
||||
var index = paper.documents.indexOf(this);
|
||||
if (index != -1) {
|
||||
paper.document = this;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
draw: function() {
|
||||
|
|
|
@ -2,7 +2,7 @@ var Symbol = Base.extend({
|
|||
beans: true,
|
||||
|
||||
initialize: function(item) {
|
||||
this.document = Paper.document;
|
||||
this.document = paper.document;
|
||||
this.document.symbols.push(this);
|
||||
this.definition = item;
|
||||
},
|
||||
|
|
|
@ -2,7 +2,7 @@ var Item = Base.extend({
|
|||
beans: true,
|
||||
|
||||
initialize: function() {
|
||||
Paper.document.activeLayer.appendTop(this);
|
||||
paper.document.activeLayer.appendTop(this);
|
||||
this.style = this.document.currentStyle;
|
||||
},
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@ var Layer = Group.extend({
|
|||
|
||||
initialize: function() {
|
||||
this.children = [];
|
||||
this.document = Paper.document;
|
||||
this.document = paper.document;
|
||||
this.document.layers.push(this);
|
||||
this.activate();
|
||||
},
|
||||
|
|
23
src/paper.js
Normal file
23
src/paper.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
var paper = {
|
||||
document: null,
|
||||
documents: [],
|
||||
|
||||
populate: function() {
|
||||
// Inject all prototypes from the paper scope into the paper object.
|
||||
Base.each(['Point', 'Size', 'Rectangle', 'Matrix', 'DocumentView',
|
||||
'Doc', 'Symbol', 'Item', 'Group', 'Layer', 'Raster', 'PlacedSymbol',
|
||||
'PathStyle', 'Segment', 'Curve', 'PathItem', 'Path', 'CompoundPath',
|
||||
'Color', 'RGBColor', 'GrayColor', 'GradientColor', 'Gradient',
|
||||
'GradientStop', 'ToolEvent', 'ToolHandler', 'Tool'],
|
||||
function(name) {
|
||||
paper[name] = eval(name);
|
||||
}
|
||||
);
|
||||
},
|
||||
|
||||
install: function(scope) {
|
||||
for (var i in paper) {
|
||||
scope[i] = paper[i];
|
||||
}
|
||||
}
|
||||
};
|
|
@ -10,14 +10,14 @@ var Tool = ToolHandler.extend(new function() {
|
|||
|
||||
initialize: function(handlers, doc) {
|
||||
this.base(handlers);
|
||||
if (Paper.document)
|
||||
this.document = Paper.document;
|
||||
if (paper.document)
|
||||
this.document = paper.document;
|
||||
},
|
||||
|
||||
setDocument: function(doc) {
|
||||
if (this._document)
|
||||
$(this._document.canvas).removeEvents();
|
||||
this._document = doc || Paper.document;
|
||||
this._document = doc || paper.document;
|
||||
var that = this, curPoint;
|
||||
var dragging = false;
|
||||
var events = {
|
||||
|
|
|
@ -112,9 +112,9 @@ test('isGroupedWith', function() {
|
|||
equals(secondGroup.isDescendant(path), false);
|
||||
equals(secondGroup.isDescendant(secondGroup), false);
|
||||
equals(path.isGroupedWith(secondGroup), false);
|
||||
Paper.document.activeLayer.appendTop(path);
|
||||
paper.document.activeLayer.appendTop(path);
|
||||
equals(path.isGroupedWith(secondPath), false);
|
||||
Paper.document.activeLayer.appendTop(secondPath);
|
||||
paper.document.activeLayer.appendTop(secondPath);
|
||||
equals(path.isGroupedWith(secondPath), false);
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue