From dd0777141501a462253bcb4bfc698cd77912a49b Mon Sep 17 00:00:00 2001 From: Antoine Vandecreme Date: Wed, 22 Apr 2015 18:30:49 -0400 Subject: [PATCH] Fix drawer.clear --- src/drawer.js | 14 +++++++++++--- src/tiledimage.js | 6 +++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/drawer.js b/src/drawer.js index 2d39c373..939a8cf0 100644 --- a/src/drawer.js +++ b/src/drawer.js @@ -240,7 +240,7 @@ $.Drawer.prototype = /** @lends OpenSeadragon.Drawer.prototype */{ /** * Clears the Drawer so it's ready to draw another frame. */ - clear: function( useSketch ) { + clear: function() { this.canvas.innerHTML = ""; if ( this.useCanvas ) { var viewportSize = this._calculateCanvasSize(); @@ -253,11 +253,19 @@ $.Drawer.prototype = /** @lends OpenSeadragon.Drawer.prototype */{ this.sketchCanvas.height = this.canvas.height; } } - this._getContext( useSketch ).clearRect( - 0, 0, viewportSize.x, viewportSize.y ); + this._clear(); } }, + _clear: function ( useSketch ) { + if ( !this.useCanvas ) { + return; + } + var context = this._getContext( useSketch ); + var canvas = context.canvas; + context.clearRect( 0, 0, canvas.width, canvas.height ); + }, + /** * Translates from OpenSeadragon viewer rectangle to drawer rectangle. * @param {OpenSeadragon.Rect} rectangle - The rectangle in viewport coordinate system. diff --git a/src/tiledimage.js b/src/tiledimage.js index 80515434..faa49cc9 100644 --- a/src/tiledimage.js +++ b/src/tiledimage.js @@ -497,12 +497,10 @@ $.extend($.TiledImage.prototype, $.EventSource.prototype, /** @lends OpenSeadrag /** * @param {Number} opacity Opacity the tiled image should be drawn at. - * @returns {OpenSeadragon.TiledImage} Chainable */ setOpacity: function(opacity) { this.opacity = opacity; this._needsDraw = true; - return this; }, // private @@ -1178,6 +1176,9 @@ function drawTiles( tiledImage, lastDrawn ) { return; } var useSketch = tiledImage.opacity < 1; + if ( useSketch ) { + tiledImage._drawer._clear( true ); + } var usedClip = false; if ( tiledImage._clip ) { @@ -1234,7 +1235,6 @@ function drawTiles( tiledImage, lastDrawn ) { if ( useSketch ) { tiledImage._drawer.blendSketch( tiledImage.opacity ); - tiledImage._drawer.clear( true ); } drawDebugInfo( tiledImage, lastDrawn ); }