Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/expose api default mouse primary #622

Merged
merged 4 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions common/reviews/api/tools.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -2893,6 +2893,10 @@ interface IToolGroup {
(): undefined | string;
};
// (undocumented)
getDefaultMousePrimary: {
(): MouseBindings;
};
// (undocumented)
getToolConfiguration: {
(toolName: string, configurationPath: string): any;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -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
);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand All @@ -55,7 +56,7 @@ export default function getActiveToolForTouchEvent(
(binding) =>
(binding.numTouchPoints === numTouchPoints ||
(numTouchPoints === 1 &&
binding.mouseButton === MouseBindings.Primary)) &&
binding.mouseButton === defaultMousePrimary)) &&
binding.modifierKey === modifierKey
);

Expand Down
17 changes: 14 additions & 3 deletions packages/tools/src/store/ToolGroupManager/ToolGroup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 '.'.
Expand Down Expand Up @@ -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
);
}
Expand Down
5 changes: 4 additions & 1 deletion packages/tools/src/types/IToolGroup.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { Types } from '@cornerstonejs/core';
import { SetToolBindingsType, ToolOptionsType } from './ISetToolModeOptions';

import { MouseBindings } from '../enums';
/**
* ToolGroup interface
*/
Expand Down Expand Up @@ -69,4 +69,7 @@ export default interface IToolGroup {
getToolConfiguration: {
(toolName: string, configurationPath: string): any;
};
getDefaultMousePrimary: {
(): MouseBindings;
};
}