mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
Rename Event -> DomEvent and Element -> DomElement, to be more specific and not clash with other classes, e.g. a future base class for ToolEvent and KeyEvent.
This commit is contained in:
parent
0e37f86156
commit
926fffee4a
12 changed files with 32 additions and 33 deletions
|
@ -44,7 +44,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reposition the paths whenever the window is resized:
|
// Reposition the paths whenever the window is resized:
|
||||||
Event.add(window, {
|
DomEvent.add(window, {
|
||||||
resize: function(event) {
|
resize: function(event) {
|
||||||
document.activeLayer.position = document.bounds.center;
|
document.activeLayer.position = document.bounds.center;
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
// http://processing.org/learning/topics/flocking.html
|
// http://processing.org/learning/topics/flocking.html
|
||||||
|
|
||||||
// Reposition the heart path whenever the window is resized:
|
// Reposition the heart path whenever the window is resized:
|
||||||
Event.add(window, {
|
DomEvent.add(window, {
|
||||||
resize: function(event) {
|
resize: function(event) {
|
||||||
size = document.size;
|
size = document.size;
|
||||||
heartPath.position = document.bounds.center;
|
heartPath.position = document.bounds.center;
|
||||||
|
|
|
@ -64,7 +64,7 @@
|
||||||
gradientColor.hilite = mouseDown ? point : point + vector;
|
gradientColor.hilite = mouseDown ? point : point + vector;
|
||||||
}
|
}
|
||||||
|
|
||||||
Event.add(window, {
|
DomEvent.add(window, {
|
||||||
resize: function(event) {
|
resize: function(event) {
|
||||||
point = new Point(document.size) / 2;
|
point = new Point(document.size) / 2;
|
||||||
path.bounds = document.bounds;
|
path.bounds = document.bounds;
|
||||||
|
|
|
@ -59,7 +59,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reposition the path whenever the window is resized:
|
// Reposition the path whenever the window is resized:
|
||||||
Event.add(window, {
|
DomEvent.add(window, {
|
||||||
resize: function(event) {
|
resize: function(event) {
|
||||||
initializePath();
|
initializePath();
|
||||||
onFrame();
|
onFrame();
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Element = new function() {
|
var DomElement = new function() {
|
||||||
function cumulate(el, name, parent) {
|
function cumulate(el, name, parent) {
|
||||||
var left = name + 'Left',
|
var left = name + 'Left',
|
||||||
top = name + 'Top',
|
top = name + 'Top',
|
||||||
|
@ -41,8 +41,8 @@ var Element = new function() {
|
||||||
},
|
},
|
||||||
|
|
||||||
getBounds: function(el, scroll) {
|
getBounds: function(el, scroll) {
|
||||||
return new Rectangle(Element.getOffset(el, scroll),
|
return new Rectangle(DomElement.getOffset(el, scroll),
|
||||||
Element.getSize(el));
|
DomElement.getSize(el));
|
||||||
},
|
},
|
||||||
|
|
||||||
getWindowSize: function() {
|
getWindowSize: function() {
|
||||||
|
@ -58,8 +58,8 @@ var Element = new function() {
|
||||||
isVisible: function(el) {
|
isVisible: function(el) {
|
||||||
// See if the scrolled bounds intersect with the windows rectangle
|
// See if the scrolled bounds intersect with the windows rectangle
|
||||||
// which always starts at 0, 0
|
// which always starts at 0, 0
|
||||||
return new Rectangle([0, 0], Element.getWindowSize())
|
return new Rectangle([0, 0], DomElement.getWindowSize())
|
||||||
.intersects(Element.getBounds(el, true));
|
.intersects(DomElement.getBounds(el, true));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
|
@ -14,7 +14,7 @@
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
var Event = {
|
var DomEvent = {
|
||||||
add: function(el, events) {
|
add: function(el, events) {
|
||||||
for (var type in events) {
|
for (var type in events) {
|
||||||
var func = events[type];
|
var func = events[type];
|
||||||
|
@ -60,12 +60,12 @@ var Event = {
|
||||||
|
|
||||||
getOffset: function(event) {
|
getOffset: function(event) {
|
||||||
// Remove target offsets from page coordinates
|
// Remove target offsets from page coordinates
|
||||||
return Event.getPoint(event).subtract(
|
return DomEvent.getPoint(event).subtract(
|
||||||
Element.getOffset(Event.getElement(event), true));
|
DomElement.getOffset(DomEvent.getElement(event), true));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Event.requestAnimationFrame = new function() {
|
DomEvent.requestAnimationFrame = new function() {
|
||||||
var part = 'equestAnimationFrame',
|
var part = 'equestAnimationFrame',
|
||||||
request = window['r' + part] || window['webkitR' + part]
|
request = window['r' + part] || window['webkitR' + part]
|
||||||
|| window['mozR' + part] || window['oR' + part]
|
|| window['mozR' + part] || window['oR' + part]
|
||||||
|
@ -100,7 +100,7 @@ Event.requestAnimationFrame = new function() {
|
||||||
var entry = callbacks[i],
|
var entry = callbacks[i],
|
||||||
func = entry[0],
|
func = entry[0],
|
||||||
element = entry[1];
|
element = entry[1];
|
||||||
if (!element || Element.isVisible(element)) {
|
if (!element || DomElement.isVisible(element)) {
|
||||||
// Handle callback and remove it from callbacks list.
|
// Handle callback and remove it from callbacks list.
|
||||||
callbacks.splice(i, 1);
|
callbacks.splice(i, 1);
|
||||||
func(+new Date);
|
func(+new Date);
|
||||||
|
@ -110,7 +110,7 @@ Event.requestAnimationFrame = new function() {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!paper.debug) {
|
if (!paper.debug) {
|
||||||
Event.add(window, {
|
DomEvent.add(window, {
|
||||||
focus: function() {
|
focus: function() {
|
||||||
focused = true;
|
focused = true;
|
||||||
// Switch to falst checkCallback calls while window is focused.
|
// Switch to falst checkCallback calls while window is focused.
|
|
@ -30,15 +30,15 @@ var Document = this.Document = Base.extend({
|
||||||
// margin: 0;
|
// margin: 0;
|
||||||
// overflow: hidden;
|
// overflow: hidden;
|
||||||
// }
|
// }
|
||||||
this._size = Element.getWindowSize()
|
this._size = DomElement.getWindowSize()
|
||||||
.subtract(Element.getOffset(this.canvas));
|
.subtract(DomElement.getOffset(this.canvas));
|
||||||
this.canvas.width = this._size.width;
|
this.canvas.width = this._size.width;
|
||||||
this.canvas.height = this._size.height;
|
this.canvas.height = this._size.height;
|
||||||
var that = this;
|
var that = this;
|
||||||
Event.add(window, {
|
DomEvent.add(window, {
|
||||||
resize: function(event) {
|
resize: function(event) {
|
||||||
that.setSize(Element.getWindowSize()
|
that.setSize(DomElement.getWindowSize()
|
||||||
.subtract(Element.getOffset(that.canvas)));
|
.subtract(DomElement.getOffset(that.canvas)));
|
||||||
that.redraw();
|
that.redraw();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -72,7 +72,7 @@ var Document = this.Document = Base.extend({
|
||||||
// Align top-left to the canvas
|
// Align top-left to the canvas
|
||||||
var element = this.stats.domElement,
|
var element = this.stats.domElement,
|
||||||
style = element.style,
|
style = element.style,
|
||||||
offset = Element.getOffset(this.canvas);
|
offset = DomElement.getOffset(this.canvas);
|
||||||
style.position = 'absolute';
|
style.position = 'absolute';
|
||||||
style.left = offset.x + 'px';
|
style.left = offset.x + 'px';
|
||||||
style.top = offset.y + 'px';
|
style.top = offset.y + 'px';
|
||||||
|
|
|
@ -66,8 +66,8 @@ var sources = [
|
||||||
'src/tool/ToolHandler.js',
|
'src/tool/ToolHandler.js',
|
||||||
'src/tool/Tool.js',
|
'src/tool/Tool.js',
|
||||||
|
|
||||||
'src/browser/Element.js',
|
'src/browser/DomElement.js',
|
||||||
'src/browser/Event.js',
|
'src/browser/DomEvent.js',
|
||||||
|
|
||||||
'src/util/CanvasProvider.js',
|
'src/util/CanvasProvider.js',
|
||||||
'src/util/Numerical.js',
|
'src/util/Numerical.js',
|
||||||
|
|
|
@ -163,8 +163,8 @@ Base.inject({
|
||||||
//#include "tool/Tool.js"
|
//#include "tool/Tool.js"
|
||||||
|
|
||||||
//#ifdef BROWSER
|
//#ifdef BROWSER
|
||||||
//#include "browser/Element.js"
|
//#include "browser/DomElement.js"
|
||||||
//#include "browser/Event.js"
|
//#include "browser/DomEvent.js"
|
||||||
//#endif // BROWSER
|
//#endif // BROWSER
|
||||||
|
|
||||||
//#include "util/CanvasProvider.js"
|
//#include "util/CanvasProvider.js"
|
||||||
|
|
|
@ -16,9 +16,8 @@
|
||||||
|
|
||||||
var Tool = this.Tool = ToolHandler.extend(new function() {
|
var Tool = this.Tool = ToolHandler.extend(new function() {
|
||||||
function viewToArtwork(event, document) {
|
function viewToArtwork(event, document) {
|
||||||
var point = Event.getOffset(event);
|
|
||||||
// TODO: always the active view?
|
// TODO: always the active view?
|
||||||
return document.activeView.viewToArtwork(point);
|
return document.activeView.viewToArtwork(DomEvent.getOffset(event));
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -91,9 +90,9 @@ var Tool = this.Tool = ToolHandler.extend(new function() {
|
||||||
|
|
||||||
// Remove old events first.
|
// Remove old events first.
|
||||||
if (this._document)
|
if (this._document)
|
||||||
Event.remove(this._document.canvas, this.events);
|
DomEvent.remove(this._document.canvas, this.events);
|
||||||
this._document = doc;
|
this._document = doc;
|
||||||
Event.add(doc.canvas, this.events);
|
DomEvent.add(doc.canvas, this.events);
|
||||||
},
|
},
|
||||||
|
|
||||||
getDocument: function() {
|
getDocument: function() {
|
||||||
|
|
|
@ -35,9 +35,9 @@ var ToolEvent = this.ToolEvent = Base.extend({
|
||||||
beans: true,
|
beans: true,
|
||||||
|
|
||||||
initialize: function(tool, type, event) {
|
initialize: function(tool, type, event) {
|
||||||
this.event = event;
|
|
||||||
this.tool = tool;
|
this.tool = tool;
|
||||||
this.type = type;
|
this.type = type;
|
||||||
|
this.event = event;
|
||||||
},
|
},
|
||||||
|
|
||||||
toString: function() {
|
toString: function() {
|
||||||
|
|
|
@ -152,12 +152,12 @@ var PaperScript = this.PaperScript = new function() {
|
||||||
if (onFrame) {
|
if (onFrame) {
|
||||||
function frame() {
|
function frame() {
|
||||||
// Request next frame already
|
// Request next frame already
|
||||||
Event.requestAnimationFrame(frame, doc && doc.canvas);
|
DomEvent.requestAnimationFrame(frame, doc && doc.canvas);
|
||||||
onFrame();
|
onFrame();
|
||||||
// Automatically redraw document each frame.
|
// Automatically redraw document each frame.
|
||||||
doc && doc.redraw();
|
doc && doc.redraw();
|
||||||
}
|
}
|
||||||
Event.requestAnimationFrame(frame, doc && doc.canvas);
|
DomEvent.requestAnimationFrame(frame, doc && doc.canvas);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
}
|
}
|
||||||
|
@ -209,7 +209,7 @@ var PaperScript = this.PaperScript = new function() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Event.add(window, { load: load });
|
DomEvent.add(window, { load: load });
|
||||||
|
|
||||||
return {
|
return {
|
||||||
compile: compile,
|
compile: compile,
|
||||||
|
|
Loading…
Reference in a new issue