Merge remote-tracking branch 'origin/rectangle-when-empty' into rectangle-when-empty

This commit is contained in:
Philip Giuliani 2015-04-13 19:15:10 +02:00
commit 3097abdbc2
4 changed files with 82 additions and 30 deletions

View File

@ -232,6 +232,23 @@ $.Drawer.prototype = /** @lends OpenSeadragon.Drawer.prototype */{
} }
}, },
/**
* Translates from OpenSeadragon viewer rectangle to drawer rectangle.
* @param {OpenSeadragon.Rect} rectangle - The rectangle in viewport coordinate system.
* @return {OpenSeadragon.Rect} Rectangle in drawer coordinate system.
*/
viewportToDrawerRectangle: function(rectangle) {
var topLeft = this.viewport.pixelFromPoint(rectangle.getTopLeft(), true);
var size = this.viewport.deltaPixelsFromPoints(rectangle.getSize(), true);
return new $.Rect(
topLeft.x * $.pixelDensityRatio,
topLeft.y * $.pixelDensityRatio,
size.x * $.pixelDensityRatio,
size.y * $.pixelDensityRatio
);
},
/** /**
* Draws the given tile. * Draws the given tile.
* @param {OpenSeadragon.Tile} tile - The tile to draw. * @param {OpenSeadragon.Tile} tile - The tile to draw.
@ -287,6 +304,24 @@ $.Drawer.prototype = /** @lends OpenSeadragon.Drawer.prototype */{
this.context.clip(); this.context.clip();
}, },
// private
drawPlaceholder: function(rect, fillStyle) {
if (!this.useCanvas) {
return;
}
this.saveContext();
if ( typeof fillStyle === "function" ) {
this.context.fillStyle = fillStyle(this.context);
}
else {
this.context.fillStyle = fillStyle;
}
this.context.fillRect(rect.x, rect.y, rect.width, rect.height);
this.restoreContext();
},
// private // private
drawDebugInfo: function( tile, count, i ){ drawDebugInfo: function( tile, count, i ){
if ( this.useCanvas ) { if ( this.useCanvas ) {

View File

@ -206,6 +206,11 @@
* @property {Number} [opacity=1] * @property {Number} [opacity=1]
* Opacity of the drawer (1=opaque, 0=transparent) * Opacity of the drawer (1=opaque, 0=transparent)
* *
* @property {String|CanvasGradient|CanvasPattern|Function} [placeholderFillStyle=null]
* Draws a colored rectangle behind the tile if it is not loaded yet.
* You can pass a CSS color value like "#FF8800".
* When passing a function the canvas context is available as argument which is useful when you draw a gradient or pattern.
*
* @property {Number} [degrees=0] * @property {Number} [degrees=0]
* Initial rotation. * Initial rotation.
* *
@ -262,7 +267,7 @@
* Possible subproperties (Numbers, in screen coordinates): left, top, right, bottom. * Possible subproperties (Numbers, in screen coordinates): left, top, right, bottom.
* *
* @property {Number} [imageLoaderLimit=0] * @property {Number} [imageLoaderLimit=0]
* The maximum number of image requests to make concurrently. By default * The maximum number of image requests to make concurrently. By default
* it is set to 0 allowing the browser to make the maximum number of * it is set to 0 allowing the browser to make the maximum number of
* image requests in parallel as allowed by the browsers policy. * image requests in parallel as allowed by the browsers policy.
* *
@ -1013,10 +1018,11 @@ window.OpenSeadragon = window.OpenSeadragon || function( options ){
navigatorRotate: true, navigatorRotate: true,
// INITIAL ROTATION // INITIAL ROTATION
degrees: 0, degrees: 0,
// APPEARANCE // APPEARANCE
opacity: 1, opacity: 1,
placeholderFillStyle: null,
//REFERENCE STRIP SETTINGS //REFERENCE STRIP SETTINGS
showReferenceStrip: false, showReferenceStrip: false,

View File

@ -65,6 +65,7 @@
* @param {Boolean} [options.alwaysBlend] - See {@link OpenSeadragon.Options}. * @param {Boolean} [options.alwaysBlend] - See {@link OpenSeadragon.Options}.
* @param {Number} [options.minPixelRatio] - See {@link OpenSeadragon.Options}. * @param {Number} [options.minPixelRatio] - See {@link OpenSeadragon.Options}.
* @param {Boolean} [options.debugMode] - See {@link OpenSeadragon.Options}. * @param {Boolean} [options.debugMode] - See {@link OpenSeadragon.Options}.
* @param {String|CanvasGradient|CanvasPattern|Function} [options.placeholderFillStyle] - See {@link OpenSeadragon.Options}.
* @param {String|Boolean} [options.crossOriginPolicy] - See {@link OpenSeadragon.Options}. * @param {String|Boolean} [options.crossOriginPolicy] - See {@link OpenSeadragon.Options}.
*/ */
$.TiledImage = function( options ) { $.TiledImage = function( options ) {
@ -126,21 +127,22 @@ $.TiledImage = function( options ) {
coverage: {}, // A '3d' dictionary [level][x][y] --> Boolean. coverage: {}, // A '3d' dictionary [level][x][y] --> Boolean.
lastDrawn: [], // An unordered list of Tiles drawn last frame. lastDrawn: [], // An unordered list of Tiles drawn last frame.
lastResetTime: 0, // Last time for which the tiledImage was reset. lastResetTime: 0, // Last time for which the tiledImage was reset.
_midDraw: false, // Is the tiledImage currently updating the viewport? _midDraw: false, // Is the tiledImage currently updating the viewport?
_needsDraw: true, // Does the tiledImage need to update the viewport again? _needsDraw: true, // Does the tiledImage need to update the viewport again?
//configurable settings //configurable settings
springStiffness: $.DEFAULT_SETTINGS.springStiffness, springStiffness: $.DEFAULT_SETTINGS.springStiffness,
animationTime: $.DEFAULT_SETTINGS.animationTime, animationTime: $.DEFAULT_SETTINGS.animationTime,
minZoomImageRatio: $.DEFAULT_SETTINGS.minZoomImageRatio, minZoomImageRatio: $.DEFAULT_SETTINGS.minZoomImageRatio,
wrapHorizontal: $.DEFAULT_SETTINGS.wrapHorizontal, wrapHorizontal: $.DEFAULT_SETTINGS.wrapHorizontal,
wrapVertical: $.DEFAULT_SETTINGS.wrapVertical, wrapVertical: $.DEFAULT_SETTINGS.wrapVertical,
immediateRender: $.DEFAULT_SETTINGS.immediateRender, immediateRender: $.DEFAULT_SETTINGS.immediateRender,
blendTime: $.DEFAULT_SETTINGS.blendTime, blendTime: $.DEFAULT_SETTINGS.blendTime,
alwaysBlend: $.DEFAULT_SETTINGS.alwaysBlend, alwaysBlend: $.DEFAULT_SETTINGS.alwaysBlend,
minPixelRatio: $.DEFAULT_SETTINGS.minPixelRatio, minPixelRatio: $.DEFAULT_SETTINGS.minPixelRatio,
debugMode: $.DEFAULT_SETTINGS.debugMode, debugMode: $.DEFAULT_SETTINGS.debugMode,
crossOriginPolicy: $.DEFAULT_SETTINGS.crossOriginPolicy crossOriginPolicy: $.DEFAULT_SETTINGS.crossOriginPolicy,
placeholderFillStyle: $.DEFAULT_SETTINGS.placeholderFillStyle
}, options ); }, options );
@ -1148,38 +1150,41 @@ function compareTiles( previousBest, tile ) {
return previousBest; return previousBest;
} }
function drawTiles( tiledImage, lastDrawn ){ function drawTiles( tiledImage, lastDrawn ) {
var i, var i,
tile, tile,
tileKey, tileKey,
viewer, viewer,
viewport, viewport,
position, position,
tileSource; tileSource,
contextSaved = false;
var usedClip = false; var usedClip = false;
if (tiledImage._clip) { if ( tiledImage._clip ) {
tiledImage._drawer.saveContext(); tiledImage._drawer.saveContext();
var box = tiledImage.imageToViewportRectangle(tiledImage._clip, true); var box = tiledImage.imageToViewportRectangle(tiledImage._clip, true);
var topLeft = tiledImage.viewport.pixelFromPoint(box.getTopLeft(), true); var clipRect = tiledImage._drawer.viewportToDrawerRectangle(box);
var size = tiledImage.viewport.deltaPixelsFromPoints(box.getSize(), true); tiledImage._drawer.setClip(clipRect);
box = new OpenSeadragon.Rect(topLeft.x * $.pixelDensityRatio,
topLeft.y * $.pixelDensityRatio,
size.x * $.pixelDensityRatio,
size.y * $.pixelDensityRatio);
tiledImage._drawer.setClip(box);
usedClip = true; usedClip = true;
} }
if ( tiledImage.placeholderFillStyle && lastDrawn.length === 0 ) {
var placeholderRect = tiledImage._drawer.viewportToDrawerRectangle(tiledImage.getBounds(true));
tiledImage._drawer.drawPlaceholder(placeholderRect, tiledImage.placeholderFillStyle);
}
for ( i = lastDrawn.length - 1; i >= 0; i-- ) { for ( i = lastDrawn.length - 1; i >= 0; i-- ) {
tile = lastDrawn[ i ]; tile = lastDrawn[ i ];
tiledImage._drawer.drawTile( tile, tiledImage._drawingHandler ); tiledImage._drawer.drawTile( tile, tiledImage._drawingHandler );
tile.beingDrawn = true; tile.beingDrawn = true;
if( tiledImage.debugMode ){ if( tiledImage.debugMode ) {
try{ try {
tiledImage._drawer.drawDebugInfo( tile, lastDrawn.length, i ); tiledImage._drawer.drawDebugInfo( tile, lastDrawn.length, i );
}catch(e){ } catch(e) {
$.console.error(e); $.console.error(e);
} }
} }
@ -1203,7 +1208,7 @@ function drawTiles( tiledImage, lastDrawn ){
} }
} }
if (usedClip) { if ( usedClip ) {
tiledImage._drawer.restoreContext(); tiledImage._drawer.restoreContext();
} }
} }

View File

@ -1206,6 +1206,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
* and "source" properties. * and "source" properties.
* @param {Boolean} [options.collectionImmediately=false] If collectionMode is on, * @param {Boolean} [options.collectionImmediately=false] If collectionMode is on,
* specifies whether to snap to the new arrangement immediately or to animate to it. * specifies whether to snap to the new arrangement immediately or to animate to it.
* @param {String|CanvasGradient|CanvasPattern|Function} [options.placeholderFillStyle] - See {@link OpenSeadragon.Options}.
* @fires OpenSeadragon.World.event:add-item * @fires OpenSeadragon.World.event:add-item
* @fires OpenSeadragon.Viewer.event:add-item-failed * @fires OpenSeadragon.Viewer.event:add-item-failed
*/ */
@ -1217,6 +1218,10 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
this._hideMessage(); this._hideMessage();
if (options.placeholderFillStyle === undefined) {
options.placeholderFillStyle = this.placeholderFillStyle;
}
var myQueueItem = { var myQueueItem = {
options: options options: options
}; };
@ -1284,6 +1289,7 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
width: queueItem.options.width, width: queueItem.options.width,
height: queueItem.options.height, height: queueItem.options.height,
clip: queueItem.options.clip, clip: queueItem.options.clip,
placeholderFillStyle: queueItem.options.placeholderFillStyle,
springStiffness: _this.springStiffness, springStiffness: _this.springStiffness,
animationTime: _this.animationTime, animationTime: _this.animationTime,
minZoomImageRatio: _this.minZoomImageRatio, minZoomImageRatio: _this.minZoomImageRatio,