diff --git a/common/reviews/api/tools.api.md b/common/reviews/api/tools.api.md index cde8be5d5..c6043e86d 100644 --- a/common/reviews/api/tools.api.md +++ b/common/reviews/api/tools.api.md @@ -2893,6 +2893,10 @@ interface IToolGroup { (): undefined | string; }; // (undocumented) + getDefaultMousePrimary: { + (): MouseBindings; + }; + // (undocumented) getToolConfiguration: { (toolName: string, configurationPath: string): any; }; diff --git a/packages/tools/src/eventDispatchers/shared/getActiveToolForKeyboardEvent.ts b/packages/tools/src/eventDispatchers/shared/getActiveToolForKeyboardEvent.ts index 80d024bb2..1a0f47713 100644 --- a/packages/tools/src/eventDispatchers/shared/getActiveToolForKeyboardEvent.ts +++ b/packages/tools/src/eventDispatchers/shared/getActiveToolForKeyboardEvent.ts @@ -36,6 +36,7 @@ export default function getActiveToolForKeyboardEvent( } const toolGroupToolNames = Object.keys(toolGroup.toolOptions); + const defaultMousePrimary = toolGroup.getDefaultMousePrimary(); for (let j = 0; j < toolGroupToolNames.length; j++) { const toolName = toolGroupToolNames[j]; @@ -47,7 +48,7 @@ export default function getActiveToolForKeyboardEvent( toolOptions.bindings.length && toolOptions.bindings.some( (binding) => - binding.mouseButton === (mouseButton ?? MouseBindings.Primary) && + binding.mouseButton === (mouseButton ?? defaultMousePrimary) && binding.modifierKey === modifierKey ); diff --git a/packages/tools/src/eventDispatchers/shared/getActiveToolForMouseEvent.ts b/packages/tools/src/eventDispatchers/shared/getActiveToolForMouseEvent.ts index 34ee4c63d..89a63c8df 100644 --- a/packages/tools/src/eventDispatchers/shared/getActiveToolForMouseEvent.ts +++ b/packages/tools/src/eventDispatchers/shared/getActiveToolForMouseEvent.ts @@ -38,6 +38,7 @@ export default function getActiveToolForMouseEvent( } const toolGroupToolNames = Object.keys(toolGroup.toolOptions); + const defaultMousePrimary = toolGroup.getDefaultMousePrimary(); for (let j = 0; j < toolGroupToolNames.length; j++) { const toolName = toolGroupToolNames[j]; @@ -50,7 +51,7 @@ export default function getActiveToolForMouseEvent( toolOptions.bindings.some((binding) => { return ( binding.mouseButton === - (mouseEvent ? mouseEvent.buttons : MouseBindings.Primary) && + (mouseEvent ? mouseEvent.buttons : defaultMousePrimary) && binding.modifierKey === modifierKey ); }); diff --git a/packages/tools/src/eventDispatchers/shared/getActiveToolForTouchEvent.ts b/packages/tools/src/eventDispatchers/shared/getActiveToolForTouchEvent.ts index 99b67e095..35d2fbe32 100644 --- a/packages/tools/src/eventDispatchers/shared/getActiveToolForTouchEvent.ts +++ b/packages/tools/src/eventDispatchers/shared/getActiveToolForTouchEvent.ts @@ -38,6 +38,7 @@ export default function getActiveToolForTouchEvent( // If any keyboard modifier key is also pressed const modifierKey = getMouseModifier(touchEvent) || keyEventListener.getModifierKey(); + const defaultMousePrimary = toolGroup.getDefaultMousePrimary(); for (let j = 0; j < toolGroupToolNames.length; j++) { const toolName = toolGroupToolNames[j]; @@ -55,7 +56,7 @@ export default function getActiveToolForTouchEvent( (binding) => (binding.numTouchPoints === numTouchPoints || (numTouchPoints === 1 && - binding.mouseButton === MouseBindings.Primary)) && + binding.mouseButton === defaultMousePrimary)) && binding.modifierKey === modifierKey ); diff --git a/packages/tools/src/store/ToolGroupManager/ToolGroup.ts b/packages/tools/src/store/ToolGroupManager/ToolGroup.ts index 4c6fa125f..aa93fc613 100644 --- a/packages/tools/src/store/ToolGroupManager/ToolGroup.ts +++ b/packages/tools/src/store/ToolGroupManager/ToolGroup.ts @@ -406,12 +406,13 @@ export default class ToolGroup implements IToolGroup { } ); + const defaultMousePrimary = this.getDefaultMousePrimary(); + // Remove the primary button bindings without modifiers, if they exist toolOptions.bindings = toolOptions.bindings.filter( (binding) => - binding.mouseButton !== MouseBindings.Primary || binding.modifierKey + binding.mouseButton !== defaultMousePrimary || binding.modifierKey ); - // If there are other bindings, set the tool to be active let mode = Passive; if (toolOptions.bindings.length !== 0) { @@ -620,6 +621,14 @@ export default class ToolGroup implements IToolGroup { return true; } + /** + * Returns the default mouse primary button. + * + */ + public getDefaultMousePrimary(): MouseBindings { + return MouseBindings.Primary; + } + /** * Get the configuration of tool. It returns only the config for the given path (in case exists). * ConfigurationPath is the the path of the property to get separated by '.'. @@ -650,9 +659,11 @@ export default class ToolGroup implements IToolGroup { * @returns A boolean value. */ private _hasMousePrimaryButtonBinding(toolOptions) { + const defaultMousePrimary = this.getDefaultMousePrimary(); + return toolOptions?.bindings?.some( (binding) => - binding.mouseButton === MouseBindings.Primary && + binding.mouseButton === defaultMousePrimary && binding.modifierKey === undefined ); } diff --git a/packages/tools/src/types/IToolGroup.ts b/packages/tools/src/types/IToolGroup.ts index bde30470e..430b2225d 100644 --- a/packages/tools/src/types/IToolGroup.ts +++ b/packages/tools/src/types/IToolGroup.ts @@ -1,6 +1,6 @@ import type { Types } from '@cornerstonejs/core'; import { SetToolBindingsType, ToolOptionsType } from './ISetToolModeOptions'; - +import { MouseBindings } from '../enums'; /** * ToolGroup interface */ @@ -69,4 +69,7 @@ export default interface IToolGroup { getToolConfiguration: { (toolName: string, configurationPath: string): any; }; + getDefaultMousePrimary: { + (): MouseBindings; + }; }