From 1747118ed47a854ec2a21041bb69fb951380f949 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 16 May 2011 13:03:02 +0100 Subject: [PATCH] Have onResize() call onFrame() if it's defined. --- src/document/DocumentView.js | 33 +++++++++++++++++++++++---------- 1 file changed, 23 insertions(+), 10 deletions(-) diff --git a/src/document/DocumentView.js b/src/document/DocumentView.js index da3911c3..d28c558e 100644 --- a/src/document/DocumentView.js +++ b/src/document/DocumentView.js @@ -45,8 +45,16 @@ var DocumentView = this.DocumentView = Base.extend({ // 0, 0), as otherwise the offset would be wrong. if (!DomElement.getSize(canvas).equals([0, 0])) offset = DomElement.getOffset(canvas); + // Set the size now, which internally calls onResize that.setViewSize( DomElement.getWindowSize().subtract(offset)); + // If there's a _onFrameCallback, call it staight away, + // but without requesting another animation frame. + if (this._onFrameCallback) { + this._onFrameCallback(0, true); + } else { + this.draw(); + } } }); } else { @@ -108,7 +116,6 @@ var DocumentView = this.DocumentView = Base.extend({ } // Force recalculation this._bounds = null; - this.draw(); }, getViewSize: function() { @@ -221,21 +228,27 @@ var DocumentView = this.DocumentView = Base.extend({ setOnFrame: function(onFrame) { this._onFrame = onFrame; + if (!onFrame) { + delete this._onFrameCallback; + return; + } var that = this, - running = false, + requested = false, before, time = 0, count = 0; - function frame() { - if (!that._onFrame) { - running = false; + this._onFrameCallback = function(param, dontRequest) { + requested = false; + if (!that._onFrame) return; - } // Set the global paper object to the current scope paper = that._scope; // Request next frame already - DomEvent.requestAnimationFrame(frame, that._canvas); - running = true; + requested = true; + if (!dontRequest) { + DomEvent.requestAnimationFrame(that._onFrameCallback, + that._canvas); + } var now = Date.now() / 1000, delta = before ? now - before : 0; that._onFrame({ @@ -249,8 +262,8 @@ var DocumentView = this.DocumentView = Base.extend({ }; // Call the onFrame handler straight away, initializing the sequence // of onFrame calls. - if (!running) - frame(); + if (!requested) + this._onFrameCallback(); }, _createEvents: function() {