From 7357614d9ac48b436727929d14e65d136577d481 Mon Sep 17 00:00:00 2001 From: jdescottes Date: Sun, 30 Mar 2014 23:28:18 +0200 Subject: [PATCH] Fix : Window resize is erasing the canvas Issue was coming from the cached frame renderer. During the window resize, we update the displaySize of the frame renderer, regardless of the fact that the dimensions changed or not. The setDisplaySize triggers a destruction of the canvas. But the CachedFrameRenderer will render the frame only if it detects a change. In this case, setDisplaySize has been overrided in CachedFrameRenderer to skip any processing if the dimensions didn't change. This behavior could be actually done in the FrameRenderer itself, but since this is crucial to the CachedFrameRenderer behavior, I prefer to keep it in this class. Alternatively, could implement a way to discard caches of CachedFrameRenderers from the outside. --- src/css/tools.css | 2 +- src/js/controller/DrawingController.js | 1 + src/js/rendering/frame/CachedFrameRenderer.js | 14 ++++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/css/tools.css b/src/css/tools.css index 975ae22..3b0dbcf 100644 --- a/src/css/tools.css +++ b/src/css/tools.css @@ -167,7 +167,7 @@ .tool-color-picker:nth-child(2) { z-index : 90; - margin-top: 20px; + margin-top: 25px; margin-left:-20px; } diff --git a/src/js/controller/DrawingController.js b/src/js/controller/DrawingController.js index 413f0c2..d3c9818 100644 --- a/src/js/controller/DrawingController.js +++ b/src/js/controller/DrawingController.js @@ -60,6 +60,7 @@ $.subscribe(Events.USER_SETTINGS_CHANGED, $.proxy(this.onUserSettingsChange_, this)); $.subscribe(Events.FRAME_SIZE_CHANGED, $.proxy(this.onFrameSizeChanged_, this)); + // this.afterWindowResize_.bind(this); window.setTimeout(this.afterWindowResize_.bind(this), 100); }; diff --git a/src/js/rendering/frame/CachedFrameRenderer.js b/src/js/rendering/frame/CachedFrameRenderer.js index e2306dd..79e6d5f 100644 --- a/src/js/rendering/frame/CachedFrameRenderer.js +++ b/src/js/rendering/frame/CachedFrameRenderer.js @@ -14,6 +14,20 @@ pskl.utils.inherit(pskl.rendering.frame.CachedFrameRenderer, pskl.rendering.frame.FrameRenderer); + /** + * Only call display size if provided values are different from current values. + * FrameRenderer:setDisplaySize destroys the underlying canvas + * If the canvas is destroyed, a rendering is mandatory. + * (Alternatively we could find a way to force the rendering of the CachedFrameRenderer from the outside) + * @param {Number} width + * @param {Number} height + */ + ns.CachedFrameRenderer.prototype.setDisplaySize = function (width, height) { + if (this.displayWidth !== width || this.displayHeight !== height) { + pskl.rendering.frame.FrameRenderer.prototype.setDisplaySize.call(this, width, height); + } + }; + ns.CachedFrameRenderer.prototype.render = function (frame) { var offset = this.getOffset(); var size = this.getDisplaySize();