From 65bfb091e19fe922463496c0466a91c3c3fccad3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 20 Jun 2011 22:51:05 +0100 Subject: [PATCH 1/3] Filter out invisible elements in DomElement.isVisible() check. --- src/browser/DomElement.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/browser/DomElement.js b/src/browser/DomElement.js index b1d2cec8..975c5598 100644 --- a/src/browser/DomElement.js +++ b/src/browser/DomElement.js @@ -70,8 +70,9 @@ var DomElement = new function() { isVisible: function(el) { // See if the scrolled bounds intersect with the windows rectangle // which always starts at 0, 0 - return new Rectangle([0, 0], DomElement.getWindowSize()) - .intersects(DomElement.getBounds(el, false, true)); + return !DomElement.isInvisible(el) + && new Rectangle([0, 0], DomElement.getWindowSize()) + .intersects(DomElement.getBounds(el, false, true)); } }; }; From 0fecbe50bcb22b7e07c8c054fc8ee50acc68f4a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 20 Jun 2011 22:51:39 +0100 Subject: [PATCH 2/3] Define View#isVisible() and use it to only handle key events if the focused view is not hidden. --- src/ui/Key.js | 2 +- src/ui/View.js | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/ui/Key.js b/src/ui/Key.js index 858ca537..33d85cf6 100644 --- a/src/ui/Key.js +++ b/src/ui/Key.js @@ -70,7 +70,7 @@ var Key = this.Key = new function() { key = keys[keyCode] || character.toLowerCase(), handler = down ? 'onKeyDown' : 'onKeyUp', view = View.focused, - scope = view && view._scope, + scope = view && view.isVisible() && view._scope, tool = scope && scope.tool; keyMap[key] = down; if (tool && tool[handler]) { diff --git a/src/ui/View.js b/src/ui/View.js index 35a391f5..0e13b915 100644 --- a/src/ui/View.js +++ b/src/ui/View.js @@ -193,6 +193,17 @@ var View = this.View = Base.extend({ this._zoom = zoom; }, + /** + * Checks whether the view is currently visible within the current browser + * viewport. + * + * @return {Boolean} Whether the view is visible. + */ + isVisible: function() { + // TODO: Take bounds into account if it's not the full canvas? + return DomElement.isVisible(this._canvas); + }, + /** * @param {Point} point */ From 909bb6310f51f02f6a7534c20c3392b305d86fdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Mon, 20 Jun 2011 22:54:45 +0100 Subject: [PATCH 3/3] Shorten RadialRainbows. --- examples/Animated/RadialRainbows.html | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/examples/Animated/RadialRainbows.html b/examples/Animated/RadialRainbows.html index 3de1a46f..00247d80 100644 --- a/examples/Animated/RadialRainbows.html +++ b/examples/Animated/RadialRainbows.html @@ -39,14 +39,10 @@ mouseDown = false; } - function onFrame() { - iterate(); - } - var grow = false; var vector = new Point(150, 0); - function iterate() { + function onFrame() { for (var i = 0, l = gradient.stops.length; i < l; i++) gradient.stops[i].color.hue -= 20; if (grow && vector.length > 300) {