From d6ea0dfdf23b791fa75e066c457ab1a9f3bc2f8e Mon Sep 17 00:00:00 2001 From: Geoff Harper Date: Mon, 12 Dec 2022 11:44:32 -0500 Subject: [PATCH] Allow the flipping of the primary mouse button --- src/mousetracker.js | 34 +++++++++++++++++++++++++--------- src/openseadragon.js | 5 +++++ src/viewer.js | 20 +++++++++++--------- test/modules/events.js | 1 + 4 files changed, 42 insertions(+), 18 deletions(-) diff --git a/src/mousetracker.js b/src/mousetracker.js index 5854d923..1f1f9919 100644 --- a/src/mousetracker.js +++ b/src/mousetracker.js @@ -69,6 +69,9 @@ * @param {Number} options.dblClickDistThreshold * The maximum distance allowed between two pointer click events * to be treated as a click gesture. + * @param {Boolean} options.flipPrimaryMouseButton + * Configure which mouse button should control panning. If enabled, button 2 will be used + * for panning instead of 0. * @param {Number} [options.stopDelay=50] * The number of milliseconds without pointer move before the stop * event is fired. @@ -129,9 +132,10 @@ if ( !$.isPlainObject( options ) ) { options = { - element: args[ 0 ], - clickTimeThreshold: args[ 1 ], - clickDistThreshold: args[ 2 ] + element: args[ 0 ], + clickTimeThreshold: args[ 1 ], + clickDistThreshold: args[ 2 ], + flipPrimaryMouseButton: args[ 3 ] }; } @@ -170,6 +174,14 @@ * @memberof OpenSeadragon.MouseTracker# */ this.dblClickDistThreshold = options.dblClickDistThreshold || $.DEFAULT_SETTINGS.dblClickDistThreshold; + /** + * Configure which mouse button should control panning. If enabled, button 2 will be used + * for panning instead of 0. + * @member {Boolean} flipPrimaryMouseButton + * @memberof OpenSeadragon.MouseTracker# + */ + this.flipPrimaryMouseButton = options.flipPrimaryMouseButton || $.DEFAULT_SETTINGS.flipPrimaryMouseButton; + /*eslint-disable no-multi-spaces*/ this.userData = options.userData || null; this.stopDelay = options.stopDelay || 50; @@ -3216,16 +3228,18 @@ pointsList = tracker.getActivePointersListByType( gPoint.type ), updateGPoint; + var primarySecondaryButtons = tracker.flipPrimaryMouseButton ? [2, 0] : [0, 2]; + if ( typeof eventInfo.originalEvent.buttons !== 'undefined' ) { pointsList.buttons = eventInfo.originalEvent.buttons; } else { - if ( buttonChanged === 0 ) { + if ( buttonChanged === primarySecondaryButtons[0] ) { // Primary pointsList.buttons |= 1; } else if ( buttonChanged === 1 ) { // Aux pointsList.buttons |= 4; - } else if ( buttonChanged === 2 ) { + } else if ( buttonChanged === primarySecondaryButtons[1] ) { // Secondary pointsList.buttons |= 2; } else if ( buttonChanged === 3 ) { @@ -3241,7 +3255,7 @@ } // Only capture and track primary button, pen, and touch contacts - if ( buttonChanged !== 0 ) { + if ( buttonChanged !== primarySecondaryButtons[0] ) { eventInfo.shouldCapture = false; eventInfo.shouldReleaseCapture = false; @@ -3360,16 +3374,18 @@ wasCaptured = false, quick; + var primarySecondaryButtons = tracker.flipPrimaryMouseButton ? [2, 0] : [0, 2]; + if ( typeof eventInfo.originalEvent.buttons !== 'undefined' ) { pointsList.buttons = eventInfo.originalEvent.buttons; } else { - if ( buttonChanged === 0 ) { + if ( buttonChanged === primarySecondaryButtons[0] ) { // Primary pointsList.buttons ^= ~1; } else if ( buttonChanged === 1 ) { // Aux pointsList.buttons ^= ~4; - } else if ( buttonChanged === 2 ) { + } else if ( buttonChanged === primarySecondaryButtons[1] ) { // Secondary pointsList.buttons ^= ~2; } else if ( buttonChanged === 3 ) { @@ -3387,7 +3403,7 @@ eventInfo.shouldCapture = false; // Only capture and track primary button, pen, and touch contacts - if ( buttonChanged !== 0 ) { + if ( buttonChanged !== primarySecondaryButtons[0] ) { eventInfo.shouldReleaseCapture = false; // Aux Release diff --git a/src/openseadragon.js b/src/openseadragon.js index 45e4c8e7..a032aa04 100644 --- a/src/openseadragon.js +++ b/src/openseadragon.js @@ -328,6 +328,10 @@ * The maximum distance allowed between two pointer click events * to be treated as a double-click gesture. * + * @property {Boolean} [flipPrimaryMouseButton=false] + * Configure which mouse button should control panning. If enabled, + * button 2 will be used for panning instead of 0. + * * @property {Number} [springStiffness=6.5] * * @property {Number} [animationTime=1.2] @@ -1209,6 +1213,7 @@ function OpenSeadragon( options ){ clickDistThreshold: 5, dblClickTimeThreshold: 300, dblClickDistThreshold: 20, + flipPrimaryMouseButton: false, springStiffness: 6.5, animationTime: 1.2, gestureSettingsMouse: { diff --git a/src/viewer.js b/src/viewer.js index 748137fe..18bd1191 100644 --- a/src/viewer.js +++ b/src/viewer.js @@ -291,6 +291,7 @@ $.Viewer = function( options ) { clickDistThreshold: this.clickDistThreshold, dblClickTimeThreshold: this.dblClickTimeThreshold, dblClickDistThreshold: this.dblClickDistThreshold, + flipPrimaryMouseButton: this.flipPrimaryMouseButton, contextMenuHandler: $.delegate( this, onCanvasContextMenu ), keyDownHandler: $.delegate( this, onCanvasKeyDown ), keyHandler: $.delegate( this, onCanvasKeyPress ), @@ -309,15 +310,16 @@ $.Viewer = function( options ) { }); this.outerTracker = new $.MouseTracker({ - userData: 'Viewer.outerTracker', - element: this.container, - startDisabled: !this.mouseNavEnabled, - clickTimeThreshold: this.clickTimeThreshold, - clickDistThreshold: this.clickDistThreshold, - dblClickTimeThreshold: this.dblClickTimeThreshold, - dblClickDistThreshold: this.dblClickDistThreshold, - enterHandler: $.delegate( this, onContainerEnter ), - leaveHandler: $.delegate( this, onContainerLeave ) + userData: 'Viewer.outerTracker', + element: this.container, + startDisabled: !this.mouseNavEnabled, + clickTimeThreshold: this.clickTimeThreshold, + clickDistThreshold: this.clickDistThreshold, + dblClickTimeThreshold: this.dblClickTimeThreshold, + dblClickDistThreshold: this.dblClickDistThreshold, + flipPrimaryMouseButton: this.flipPrimaryMouseButton, + enterHandler: $.delegate( this, onContainerEnter ), + leaveHandler: $.delegate( this, onContainerLeave ) }); if( this.toolbar ){ diff --git a/test/modules/events.js b/test/modules/events.js index 010b08b9..97f0483e 100644 --- a/test/modules/events.js +++ b/test/modules/events.js @@ -1027,6 +1027,7 @@ clickDistThreshold: OpenSeadragon.DEFAULT_SETTINGS.clickDistThreshold, dblClickTimeThreshold: OpenSeadragon.DEFAULT_SETTINGS.dblClickTimeThreshold, dblClickDistThreshold: OpenSeadragon.DEFAULT_SETTINGS.dblClickDistThreshold, + flipPrimaryMouseButton: OpenSeadragon.DEFAULT_SETTINGS.flipPrimaryMouseButton, focusHandler: onMouseTrackerFocus, blurHandler: onMouseTrackerBlur, enterHandler: onMouseTrackerEnter,