mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-03-13 16:33:28 -04:00
Add support for onResize handler.
This commit is contained in:
parent
3bd4db802c
commit
535e5fc5fc
2 changed files with 16 additions and 1 deletions
|
@ -141,7 +141,8 @@ var PaperScript = this.PaperScript = new function() {
|
|||
// Define variables for potential handlers, so eval() calls below to
|
||||
// fetch their values do not require try-catch around them.
|
||||
var onEditOptions, onSelect, onDeselect, onReselect, onMouseDown,
|
||||
onMouseUp, onMouseDrag, onMouseMove, onKeyDown, onKeyUp, onFrame;
|
||||
onMouseUp, onMouseDrag, onMouseMove, onKeyDown, onKeyUp,
|
||||
onFrame, onResize;
|
||||
var res = eval(compile(code));
|
||||
if (tool) {
|
||||
Base.each(['onEditOptions', 'onSelect', 'onDeselect',
|
||||
|
@ -153,6 +154,7 @@ var PaperScript = this.PaperScript = new function() {
|
|||
);
|
||||
}
|
||||
if (view) {
|
||||
view.onResize = onResize;
|
||||
if (onFrame) {
|
||||
view.setOnFrame(onFrame);
|
||||
} else {
|
||||
|
|
|
@ -86,9 +86,17 @@ var DocumentView = this.DocumentView = Base.extend({
|
|||
},
|
||||
|
||||
setSize: function(size) {
|
||||
var old = this._size;
|
||||
this._size = Size.read(arguments);
|
||||
this._canvas.width = this._size.width;
|
||||
this._canvas.height = this._size.height;
|
||||
// Call onResize handler on any size change
|
||||
if (this.onResize) {
|
||||
this.onResize({
|
||||
size: this._size,
|
||||
delta: this._size.subtract(old)
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
getBounds: function() {
|
||||
|
@ -165,6 +173,11 @@ var DocumentView = this.DocumentView = Base.extend({
|
|||
return this._getInverse()._transformPoint(Point.read(arguments));
|
||||
},
|
||||
|
||||
/**
|
||||
* Handler to be called whenever a view gets resized.
|
||||
*/
|
||||
onResize: null,
|
||||
|
||||
setOnFrame: function(onFrame) {
|
||||
this._onFrame = onFrame;
|
||||
var that = this,
|
||||
|
|
Loading…
Reference in a new issue