Allow the flipping of the primary mouse button

This commit is contained in:
Geoff Harper 2022-12-12 11:44:32 -05:00
parent dd2f132577
commit d6ea0dfdf2
4 changed files with 42 additions and 18 deletions

View File

@ -69,6 +69,9 @@
* @param {Number} options.dblClickDistThreshold * @param {Number} options.dblClickDistThreshold
* The maximum distance allowed between two pointer click events * The maximum distance allowed between two pointer click events
* to be treated as a click gesture. * 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] * @param {Number} [options.stopDelay=50]
* The number of milliseconds without pointer move before the stop * The number of milliseconds without pointer move before the stop
* event is fired. * event is fired.
@ -131,7 +134,8 @@
options = { options = {
element: args[ 0 ], element: args[ 0 ],
clickTimeThreshold: args[ 1 ], clickTimeThreshold: args[ 1 ],
clickDistThreshold: args[ 2 ] clickDistThreshold: args[ 2 ],
flipPrimaryMouseButton: args[ 3 ]
}; };
} }
@ -170,6 +174,14 @@
* @memberof OpenSeadragon.MouseTracker# * @memberof OpenSeadragon.MouseTracker#
*/ */
this.dblClickDistThreshold = options.dblClickDistThreshold || $.DEFAULT_SETTINGS.dblClickDistThreshold; 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*/ /*eslint-disable no-multi-spaces*/
this.userData = options.userData || null; this.userData = options.userData || null;
this.stopDelay = options.stopDelay || 50; this.stopDelay = options.stopDelay || 50;
@ -3216,16 +3228,18 @@
pointsList = tracker.getActivePointersListByType( gPoint.type ), pointsList = tracker.getActivePointersListByType( gPoint.type ),
updateGPoint; updateGPoint;
var primarySecondaryButtons = tracker.flipPrimaryMouseButton ? [2, 0] : [0, 2];
if ( typeof eventInfo.originalEvent.buttons !== 'undefined' ) { if ( typeof eventInfo.originalEvent.buttons !== 'undefined' ) {
pointsList.buttons = eventInfo.originalEvent.buttons; pointsList.buttons = eventInfo.originalEvent.buttons;
} else { } else {
if ( buttonChanged === 0 ) { if ( buttonChanged === primarySecondaryButtons[0] ) {
// Primary // Primary
pointsList.buttons |= 1; pointsList.buttons |= 1;
} else if ( buttonChanged === 1 ) { } else if ( buttonChanged === 1 ) {
// Aux // Aux
pointsList.buttons |= 4; pointsList.buttons |= 4;
} else if ( buttonChanged === 2 ) { } else if ( buttonChanged === primarySecondaryButtons[1] ) {
// Secondary // Secondary
pointsList.buttons |= 2; pointsList.buttons |= 2;
} else if ( buttonChanged === 3 ) { } else if ( buttonChanged === 3 ) {
@ -3241,7 +3255,7 @@
} }
// Only capture and track primary button, pen, and touch contacts // Only capture and track primary button, pen, and touch contacts
if ( buttonChanged !== 0 ) { if ( buttonChanged !== primarySecondaryButtons[0] ) {
eventInfo.shouldCapture = false; eventInfo.shouldCapture = false;
eventInfo.shouldReleaseCapture = false; eventInfo.shouldReleaseCapture = false;
@ -3360,16 +3374,18 @@
wasCaptured = false, wasCaptured = false,
quick; quick;
var primarySecondaryButtons = tracker.flipPrimaryMouseButton ? [2, 0] : [0, 2];
if ( typeof eventInfo.originalEvent.buttons !== 'undefined' ) { if ( typeof eventInfo.originalEvent.buttons !== 'undefined' ) {
pointsList.buttons = eventInfo.originalEvent.buttons; pointsList.buttons = eventInfo.originalEvent.buttons;
} else { } else {
if ( buttonChanged === 0 ) { if ( buttonChanged === primarySecondaryButtons[0] ) {
// Primary // Primary
pointsList.buttons ^= ~1; pointsList.buttons ^= ~1;
} else if ( buttonChanged === 1 ) { } else if ( buttonChanged === 1 ) {
// Aux // Aux
pointsList.buttons ^= ~4; pointsList.buttons ^= ~4;
} else if ( buttonChanged === 2 ) { } else if ( buttonChanged === primarySecondaryButtons[1] ) {
// Secondary // Secondary
pointsList.buttons ^= ~2; pointsList.buttons ^= ~2;
} else if ( buttonChanged === 3 ) { } else if ( buttonChanged === 3 ) {
@ -3387,7 +3403,7 @@
eventInfo.shouldCapture = false; eventInfo.shouldCapture = false;
// Only capture and track primary button, pen, and touch contacts // Only capture and track primary button, pen, and touch contacts
if ( buttonChanged !== 0 ) { if ( buttonChanged !== primarySecondaryButtons[0] ) {
eventInfo.shouldReleaseCapture = false; eventInfo.shouldReleaseCapture = false;
// Aux Release // Aux Release

View File

@ -328,6 +328,10 @@
* The maximum distance allowed between two pointer click events * The maximum distance allowed between two pointer click events
* to be treated as a double-click gesture. * 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} [springStiffness=6.5]
* *
* @property {Number} [animationTime=1.2] * @property {Number} [animationTime=1.2]
@ -1209,6 +1213,7 @@ function OpenSeadragon( options ){
clickDistThreshold: 5, clickDistThreshold: 5,
dblClickTimeThreshold: 300, dblClickTimeThreshold: 300,
dblClickDistThreshold: 20, dblClickDistThreshold: 20,
flipPrimaryMouseButton: false,
springStiffness: 6.5, springStiffness: 6.5,
animationTime: 1.2, animationTime: 1.2,
gestureSettingsMouse: { gestureSettingsMouse: {

View File

@ -291,6 +291,7 @@ $.Viewer = function( options ) {
clickDistThreshold: this.clickDistThreshold, clickDistThreshold: this.clickDistThreshold,
dblClickTimeThreshold: this.dblClickTimeThreshold, dblClickTimeThreshold: this.dblClickTimeThreshold,
dblClickDistThreshold: this.dblClickDistThreshold, dblClickDistThreshold: this.dblClickDistThreshold,
flipPrimaryMouseButton: this.flipPrimaryMouseButton,
contextMenuHandler: $.delegate( this, onCanvasContextMenu ), contextMenuHandler: $.delegate( this, onCanvasContextMenu ),
keyDownHandler: $.delegate( this, onCanvasKeyDown ), keyDownHandler: $.delegate( this, onCanvasKeyDown ),
keyHandler: $.delegate( this, onCanvasKeyPress ), keyHandler: $.delegate( this, onCanvasKeyPress ),
@ -316,6 +317,7 @@ $.Viewer = function( options ) {
clickDistThreshold: this.clickDistThreshold, clickDistThreshold: this.clickDistThreshold,
dblClickTimeThreshold: this.dblClickTimeThreshold, dblClickTimeThreshold: this.dblClickTimeThreshold,
dblClickDistThreshold: this.dblClickDistThreshold, dblClickDistThreshold: this.dblClickDistThreshold,
flipPrimaryMouseButton: this.flipPrimaryMouseButton,
enterHandler: $.delegate( this, onContainerEnter ), enterHandler: $.delegate( this, onContainerEnter ),
leaveHandler: $.delegate( this, onContainerLeave ) leaveHandler: $.delegate( this, onContainerLeave )
}); });

View File

@ -1027,6 +1027,7 @@
clickDistThreshold: OpenSeadragon.DEFAULT_SETTINGS.clickDistThreshold, clickDistThreshold: OpenSeadragon.DEFAULT_SETTINGS.clickDistThreshold,
dblClickTimeThreshold: OpenSeadragon.DEFAULT_SETTINGS.dblClickTimeThreshold, dblClickTimeThreshold: OpenSeadragon.DEFAULT_SETTINGS.dblClickTimeThreshold,
dblClickDistThreshold: OpenSeadragon.DEFAULT_SETTINGS.dblClickDistThreshold, dblClickDistThreshold: OpenSeadragon.DEFAULT_SETTINGS.dblClickDistThreshold,
flipPrimaryMouseButton: OpenSeadragon.DEFAULT_SETTINGS.flipPrimaryMouseButton,
focusHandler: onMouseTrackerFocus, focusHandler: onMouseTrackerFocus,
blurHandler: onMouseTrackerBlur, blurHandler: onMouseTrackerBlur,
enterHandler: onMouseTrackerEnter, enterHandler: onMouseTrackerEnter,