mirror of
https://github.com/openseadragon/openseadragon.git
synced 2024-11-25 14:46:10 +03:00
Introduced animation state and testing it to determine rendering when at rest
This commit is contained in:
parent
bfc0c4608e
commit
458a16ce1f
@ -1424,9 +1424,25 @@ function OpenSeadragon( options ){
|
|||||||
* @property {Number} ALWAYS Apply subpixel rounding for transparency during animation and when animation is over.
|
* @property {Number} ALWAYS Apply subpixel rounding for transparency during animation and when animation is over.
|
||||||
*/
|
*/
|
||||||
SUBPIXEL_ROUNDING_OCCURRENCES: {
|
SUBPIXEL_ROUNDING_OCCURRENCES: {
|
||||||
NEVER: 0,
|
NEVER: 0,
|
||||||
ONLY_AT_REST: 1,
|
ONLY_AT_REST: 1,
|
||||||
ALWAYS: 2
|
ALWAYS: 2
|
||||||
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An enumeration of animation states.
|
||||||
|
* @static
|
||||||
|
* @type {Object}
|
||||||
|
* @property {Number} AT_REST Indicates there are no more animations running and the image is at rest.
|
||||||
|
* @property {Number} ANIMATION_STARTED Indicates the image is in motion and it just started.
|
||||||
|
* @property {Number} ANIMATING Indicates the image was in motion and is still in motion.
|
||||||
|
* @property {Number} ANIMATION_FINISHED Indicates the image was in motion and is not in motion anymore.
|
||||||
|
*/
|
||||||
|
ANIMATION_STATES: {
|
||||||
|
AT_REST: 0,
|
||||||
|
ANIMATION_STARTED: 1,
|
||||||
|
ANIMATING: 2,
|
||||||
|
ANIMATION_FINISHED: 3
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -2210,8 +2210,10 @@ function drawTiles( tiledImage, lastDrawn ) {
|
|||||||
if (isSubPixelRoundingRuleAlways(subPixelRoundingRule)) {
|
if (isSubPixelRoundingRuleAlways(subPixelRoundingRule)) {
|
||||||
shouldRoundPositionAndSize = true;
|
shouldRoundPositionAndSize = true;
|
||||||
} else if (isSubPixelRoundingRuleOnlyAtRest(subPixelRoundingRule)) {
|
} else if (isSubPixelRoundingRuleOnlyAtRest(subPixelRoundingRule)) {
|
||||||
var isAnimating = tiledImage.viewer && tiledImage.viewer.isAnimating();
|
shouldRoundPositionAndSize = tiledImage.viewer && (
|
||||||
shouldRoundPositionAndSize = !isAnimating;
|
tiledImage.viewer.getAnimationState() === $.ANIMATION_STATES.ANIMATION_FINISHED ||
|
||||||
|
tiledImage.viewer.getAnimationState() === $.ANIMATION_STATES.AT_REST // Testing AT_REST here is for the very first render after loading.
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = lastDrawn.length - 1; i >= 0; i--) {
|
for (var i = lastDrawn.length - 1; i >= 0; i--) {
|
||||||
|
@ -203,6 +203,7 @@ $.Viewer = function( options ) {
|
|||||||
fsBoundsDelta: new $.Point( 1, 1 ),
|
fsBoundsDelta: new $.Point( 1, 1 ),
|
||||||
prevContainerSize: null,
|
prevContainerSize: null,
|
||||||
animating: false,
|
animating: false,
|
||||||
|
animationState: $.ANIMATION_STATES.AT_REST,
|
||||||
forceRedraw: false,
|
forceRedraw: false,
|
||||||
mouseInside: false,
|
mouseInside: false,
|
||||||
group: null,
|
group: null,
|
||||||
@ -713,6 +714,8 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
|
|||||||
}
|
}
|
||||||
|
|
||||||
THIS[ this.hash ].animating = false;
|
THIS[ this.hash ].animating = false;
|
||||||
|
THIS[ this.hash ].animationState = $.ANIMATION_STATES.AT_REST;
|
||||||
|
|
||||||
this.world.removeAll();
|
this.world.removeAll();
|
||||||
this.imageLoader.clear();
|
this.imageLoader.clear();
|
||||||
|
|
||||||
@ -2353,6 +2356,10 @@ $.extend( $.Viewer.prototype, $.EventSource.prototype, $.ControlDock.prototype,
|
|||||||
isAnimating: function () {
|
isAnimating: function () {
|
||||||
return THIS[ this.hash ].animating;
|
return THIS[ this.hash ].animating;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
getAnimationState: function () {
|
||||||
|
return THIS[ this.hash ].animationState;
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@ -3502,6 +3509,8 @@ function updateOnce( viewer ) {
|
|||||||
var currentAnimating = THIS[ viewer.hash ].animating;
|
var currentAnimating = THIS[ viewer.hash ].animating;
|
||||||
|
|
||||||
if ( !currentAnimating && animated ) {
|
if ( !currentAnimating && animated ) {
|
||||||
|
THIS[ viewer.hash ].animationState = $.ANIMATION_STATES.ANIMATION_STARTED;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Raised when any spring animation starts (zoom, pan, etc.).
|
* Raised when any spring animation starts (zoom, pan, etc.).
|
||||||
*
|
*
|
||||||
@ -3515,7 +3524,18 @@ function updateOnce( viewer ) {
|
|||||||
abortControlsAutoHide( viewer );
|
abortControlsAutoHide( viewer );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( animated || THIS[ viewer.hash ].forceRedraw || viewer.world.needsDraw() ) {
|
var lastAnimation = false;
|
||||||
|
|
||||||
|
if (currentAnimating) {
|
||||||
|
if (animated) {
|
||||||
|
THIS[ viewer.hash ].animationState = $.ANIMATION_STATES.ANIMATING;
|
||||||
|
} else {
|
||||||
|
THIS[ viewer.hash ].animationState = $.ANIMATION_STATES.ANIMATION_FINISHED;
|
||||||
|
lastAnimation = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( animated || lastAnimation || THIS[ viewer.hash ].forceRedraw || viewer.world.needsDraw() ) {
|
||||||
drawWorld( viewer );
|
drawWorld( viewer );
|
||||||
viewer._drawOverlays();
|
viewer._drawOverlays();
|
||||||
if( viewer.navigator ){
|
if( viewer.navigator ){
|
||||||
@ -3540,6 +3560,8 @@ function updateOnce( viewer ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ( currentAnimating && !animated ) {
|
if ( currentAnimating && !animated ) {
|
||||||
|
THIS[ viewer.hash ].animationState = $.ANIMATION_STATES.AT_REST;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Raised when any spring animation ends (zoom, pan, etc.).
|
* Raised when any spring animation ends (zoom, pan, etc.).
|
||||||
*
|
*
|
||||||
@ -3558,13 +3580,6 @@ function updateOnce( viewer ) {
|
|||||||
|
|
||||||
THIS[ viewer.hash ].animating = animated;
|
THIS[ viewer.hash ].animating = animated;
|
||||||
|
|
||||||
// Intentionally use currentAnimating as the value at the current frame,
|
|
||||||
// regardless of THIS[ viewer.hash ].animating being updated.
|
|
||||||
if (currentAnimating && !animated) {
|
|
||||||
// Ensure a draw occurs once animation is over.
|
|
||||||
drawWorld( viewer );
|
|
||||||
}
|
|
||||||
|
|
||||||
//viewer.profiler.endUpdate();
|
//viewer.profiler.endUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user