Add support for onResize handler.

This commit is contained in:
Jürg Lehni 2011-05-15 23:46:34 +01:00
parent 3bd4db802c
commit 535e5fc5fc
2 changed files with 16 additions and 1 deletions

View file

@ -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 {

View file

@ -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,