mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-22 07:19:57 -05:00
Merge remote branch 'origin/master'
This commit is contained in:
commit
4bba0a5201
4 changed files with 30 additions and 17 deletions
|
@ -141,11 +141,31 @@ var PaperScope = this.PaperScope = Base.extend(/** @scope _global_ */{
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Installs the paper scope into any other given scope. Can be used for
|
* Sets up the scope for a standard project, by creating an empty
|
||||||
|
* {@link Project} object for us, along with a {@link View} for the passed
|
||||||
|
* canvas, both linked to this scope.
|
||||||
|
*/
|
||||||
|
setup: function(canvas) {
|
||||||
|
// We need to set the global paper reference to this scope,
|
||||||
|
// since that will be used in the Project constructor to set
|
||||||
|
// internal references.
|
||||||
|
paper = this;
|
||||||
|
new Project();
|
||||||
|
if (canvas) {
|
||||||
|
// Activate the newly created view straight away
|
||||||
|
new View(canvas).activate();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Injects the paper scope into any other given scope. Can be used for
|
||||||
* examle to inject the currently active PaperScope into the window's global
|
* examle to inject the currently active PaperScope into the window's global
|
||||||
* scope, to emulate PaperScript-style globally accessible Paper classes:
|
* scope, to emulate PaperScript-style globally accessible Paper classes and
|
||||||
|
* objects:
|
||||||
*
|
*
|
||||||
|
* @example
|
||||||
* paper.install(window);
|
* paper.install(window);
|
||||||
|
*
|
||||||
* @ignore
|
* @ignore
|
||||||
*/
|
*/
|
||||||
install: function(scope) {
|
install: function(scope) {
|
||||||
|
|
|
@ -138,12 +138,7 @@ var PaperScript = this.PaperScript = new function() {
|
||||||
// so the active project is defined.
|
// so the active project is defined.
|
||||||
var canvas = PaperScript.getAttribute(code, 'canvas');
|
var canvas = PaperScript.getAttribute(code, 'canvas');
|
||||||
if (canvas = canvas && document.getElementById(canvas)) {
|
if (canvas = canvas && document.getElementById(canvas)) {
|
||||||
// Create an empty Project for this scope, and a view for the
|
scope.setup(canvas);
|
||||||
// canvas, both using the right paper scope
|
|
||||||
paper = scope;
|
|
||||||
new Project();
|
|
||||||
// Activate the newly created view straight away
|
|
||||||
new View(canvas).activate();
|
|
||||||
}
|
}
|
||||||
if (code.src) {
|
if (code.src) {
|
||||||
// If we're loading from a source, request that first and then
|
// If we're loading from a source, request that first and then
|
||||||
|
@ -155,15 +150,15 @@ var PaperScript = this.PaperScript = new function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//#endif // BROWSER
|
//#endif // BROWSER
|
||||||
|
// Set currently active scope.
|
||||||
|
paper = scope;
|
||||||
var view = scope.view,
|
var view = scope.view,
|
||||||
// TODO: Add support for multiple tools
|
// TODO: Add support for multiple tools
|
||||||
tool = scope.tool = /on(?:Key|Mouse)(?:Up|Down|Move|Drag)/.test(code)
|
tool = scope.tool = /on(?:Key|Mouse)(?:Up|Down|Move|Drag)/.test(code)
|
||||||
&& new Tool(null, scope),
|
&& new Tool(),
|
||||||
res;
|
res;
|
||||||
// Define variables for potential handlers, so eval() calls below to
|
// Define variables for potential handlers, so eval() calls below to
|
||||||
// fetch their values do not require try-catch around them.
|
// fetch their values do not require try-catch around them.
|
||||||
// Set currently active scope.
|
|
||||||
paper = scope;
|
|
||||||
// Use with(){} in order to make the scope the current 'global' scope
|
// Use with(){} in order to make the scope the current 'global' scope
|
||||||
// instead of window.
|
// instead of window.
|
||||||
with (scope) {
|
with (scope) {
|
||||||
|
|
|
@ -48,11 +48,9 @@
|
||||||
*/
|
*/
|
||||||
var Tool = this.Tool = Base.extend(/** @lends Tool# */{
|
var Tool = this.Tool = Base.extend(/** @lends Tool# */{
|
||||||
// DOCS: rewrite Tool constructor explanation
|
// DOCS: rewrite Tool constructor explanation
|
||||||
/**
|
initialize: function() {
|
||||||
* Initializes the tool's settings, so a new tool can be assigned to it
|
// Store reference to the currently active global paper scope:
|
||||||
*/
|
this._scope = paper;
|
||||||
initialize: function(handlers, scope) {
|
|
||||||
this._scope = scope;
|
|
||||||
this._firstMove = true;
|
this._firstMove = true;
|
||||||
this._count = 0;
|
this._count = 0;
|
||||||
this._downCount = 0;
|
this._downCount = 0;
|
||||||
|
|
|
@ -183,7 +183,7 @@ var ToolEvent = this.ToolEvent = Event.extend(/** @lends ToolEvent# */{
|
||||||
if (result) {
|
if (result) {
|
||||||
var item = result.item,
|
var item = result.item,
|
||||||
// Find group parent
|
// Find group parent
|
||||||
parent = item.getParent();
|
parent = item._parent;
|
||||||
while ((parent instanceof Group && !(parent instanceof Layer))
|
while ((parent instanceof Group && !(parent instanceof Layer))
|
||||||
|| parent instanceof CompoundPath) {
|
|| parent instanceof CompoundPath) {
|
||||||
item = parent;
|
item = parent;
|
||||||
|
|
Loading…
Reference in a new issue