From 2dd8a65e632dab7aaf0da4710a341de83551a8c2 Mon Sep 17 00:00:00 2001 From: Jonathan Lake Date: Tue, 21 Aug 2018 17:39:46 -0400 Subject: [PATCH] Adds option to set rotation increment for nav buttons and keyboard; Issue 1518 --- src/openseadragon.js | 4 ++++ src/viewer.js | 27 ++++++++++----------------- 2 files changed, 14 insertions(+), 17 deletions(-) diff --git a/src/openseadragon.js b/src/openseadragon.js index 77616346..74851e94 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -271,6 +271,9 @@ * events between different devices, causing the faster devices to slow down enough to make the zoom control * more manageable. * + * @property {Number} [rotationIncrement=90] + * The number of degrees to rotate right or left when the rotate buttons or keyboard shortcuts are activated. + * * @property {Number} [pixelsPerWheelLine=40] * For pixel-resolution scrolling devices, the number of pixels equal to one scroll line. * @@ -1137,6 +1140,7 @@ function OpenSeadragon( options ){ autoResize: true, preserveImageSizeOnResize: false, // requires autoResize=true minScrollDeltaTime: 50, + rotationIncrement: 90, //DEFAULT CONTROL SETTINGS showSequenceControl: true, //SEQUENCE diff --git a/src/viewer.js b/src/viewer.js index b91cfd7b..2adf8bb1 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -2640,19 +2640,19 @@ function onCanvasKeyPress( event ) { this.viewport.applyConstraints(); } return false; - case 114: //r - 90 degrees clockwise rotation + case 114: //r - clockwise rotation if(this.viewport.flipped){ - this.viewport.setRotation(this.viewport.degrees - 90); + this.viewport.setRotation($.positiveModulo(this.viewport.degrees - this.rotationIncrement, 360)); } else{ - this.viewport.setRotation(this.viewport.degrees + 90); + this.viewport.setRotation($.positiveModulo(this.viewport.degrees + this.rotationIncrement, 360)); } this.viewport.applyConstraints(); return false; - case 82: //R - 90 degrees counterclockwise rotation + case 82: //R - counterclockwise rotation if(this.viewport.flipped){ - this.viewport.setRotation(this.viewport.degrees + 90); + this.viewport.setRotation($.positiveModulo(this.viewport.degrees + this.rotationIncrement, 360)); } else{ - this.viewport.setRotation(this.viewport.degrees - 90); + this.viewport.setRotation($.positiveModulo(this.viewport.degrees - this.rotationIncrement, 360)); } this.viewport.applyConstraints(); return false; @@ -3490,38 +3490,31 @@ function onFullScreen() { } } -/** - * Note: The current rotation feature is limited to 90 degree turns. - */ function onRotateLeft() { if ( this.viewport ) { var currRotation = this.viewport.getRotation(); if ( this.viewport.flipped ){ - currRotation = $.positiveModulo(currRotation + 90, 360); + currRotation = $.positiveModulo(currRotation + this.rotationIncrement, 360); } else { - currRotation = $.positiveModulo(currRotation - 90, 360); + currRotation = $.positiveModulo(currRotation - this.rotationIncrement, 360); } this.viewport.setRotation(currRotation); } } -/** - * Note: The current rotation feature is limited to 90 degree turns. - */ function onRotateRight() { if ( this.viewport ) { var currRotation = this.viewport.getRotation(); if ( this.viewport.flipped ){ - currRotation = $.positiveModulo(currRotation - 90, 360); + currRotation = $.positiveModulo(currRotation - this.rotationIncrement, 360); } else { - currRotation = $.positiveModulo(currRotation + 90, 360); + currRotation = $.positiveModulo(currRotation + this.rotationIncrement, 360); } this.viewport.setRotation(currRotation); } } - /** * Note: When pressed flip control button */