From be0d71d19d5b42fa01452b3e7f88d3a83c9b8a5d Mon Sep 17 00:00:00 2001 From: Ross Date: Fri, 30 May 2025 18:06:22 +0100 Subject: [PATCH] . --- dicom-viewer/src/App.tsx | 141 ++++++++++++++++++++++++++++++++++----- 1 file changed, 126 insertions(+), 15 deletions(-) diff --git a/dicom-viewer/src/App.tsx b/dicom-viewer/src/App.tsx index 84034ad..b9d6660 100644 --- a/dicom-viewer/src/App.tsx +++ b/dicom-viewer/src/App.tsx @@ -62,7 +62,19 @@ const MOUSE_BUTTONS = [ { label: "Middle", value: "Auxiliary" }, { label: "Right", value: "Secondary" }, ] - +const ALL_MOUSE_BINDINGS = [ + { label: "Left", value: "Primary", mask: 1 }, + { label: "Middle", value: "Auxiliary", mask: 4 }, + { label: "Right", value: "Secondary", mask: 2 }, + { label: "Left + Right", value: "Primary_and_Secondary", mask: 3 }, + { label: "Left + Middle", value: "Primary_and_Auxiliary", mask: 5 }, + { label: "Right + Middle", value: "Secondary_and_Auxiliary", mask: 6 }, + { label: "Left + Right + Middle", value: "Primary_and_Secondary_and_Auxiliary", mask: 7 }, + { label: "Fourth Button", value: "Fourth_Button", mask: 8 }, + { label: "Fifth Button", value: "Fifth_Button", mask: 16 }, + { label: "Mouse Wheel", value: "Wheel", mask: 524288 }, + { label: "Mouse Wheel + Left", value: "Wheel_Primary", mask: 524289 }, +]; // App definintion @@ -129,6 +141,8 @@ function App() { const [crossHairsEnabled, setCrossHairsEnabled] = useState(false); const [referenceLinesEnabled, setReferenceLinesEnabled] = useState(true); + const [showAdvancedMouseBindings, setShowAdvancedMouseBindings] = useState(false); + const sortViewportImageIdsBySliceLocation = () => { setViewportImageIds(prev => { const next = prev.map((imageIds, idx) => { @@ -256,6 +270,9 @@ function App() { Auxiliary: PanTool.toolName, Secondary: WindowLevelTool.toolName, Primary_and_Secondary: ZoomTool.toolName, // 1 (left) + 2 (right) = 3 + Fourth_Button: PlanarRotateTool.toolName, // 16 + Wheel: StackScrollTool.toolName, // 524288 + }) const [ctrlMouseToolBindings, setCtrlMouseToolBindings] = useState({ Primary: LengthTool.toolName, @@ -395,12 +412,31 @@ function App() { // Normal bindings Object.entries(mouseToolBindings).forEach(([btn, tool]) => { if (!toolBindings[tool]) toolBindings[tool] = []; - toolBindings[tool].push({ mouseButton: MouseBindings[btn] }); + // Find the mask for this binding + const binding = ALL_MOUSE_BINDINGS.find(b => b.value === btn); + if (binding) { + toolBindings[tool].push({ mouseButton: binding.mask }); + } else if (MouseBindings[btn]) { + // Fallback for legacy bindings + toolBindings[tool].push({ mouseButton: MouseBindings[btn] }); + } }); - // Ctrl bindings + // Ctrl bindings (now supports advanced mouse bindings) Object.entries(ctrlMouseToolBindings).forEach(([btn, tool]) => { + if (!tool) return; if (!toolBindings[tool]) toolBindings[tool] = []; - toolBindings[tool].push({ mouseButton: MouseBindings[btn], modifierKey: KeyboardBindings.Ctrl }); + const binding = ALL_MOUSE_BINDINGS.find(b => b.value === btn); + if (binding) { + toolBindings[tool].push({ + mouseButton: binding.mask, + modifierKey: KeyboardBindings.Ctrl, + }); + } else if (MouseBindings[btn]) { + toolBindings[tool].push({ + mouseButton: MouseBindings[btn], + modifierKey: KeyboardBindings.Ctrl, + }); + } }); // Apply all bindings for each tool in a single call @@ -408,14 +444,14 @@ function App() { toolGroup.setToolActive(tool, { bindings }); }); - // Always re-apply the mouse wheel binding for StackScrollTool - toolGroup.setToolActive(StackScrollTool.toolName, { - bindings: [ - { - mouseButton: MouseBindings.Wheel, // Wheel Mouse - }, - ], - }); + //// Always re-apply the mouse wheel binding for StackScrollTool + //toolGroup.setToolActive(StackScrollTool.toolName, { + // bindings: [ + // { + // mouseButton: MouseBindings.Wheel, // Wheel Mouse + // }, + // ], + //}); } }); @@ -636,7 +672,7 @@ function App() { typeof viewport.setImageIdIndex === "function" ) { //viewport.setImageIdIndex(prevScrollIndices.current[i]); - csUtilities.jumpToSlice(viewport.element, {imageIndex: prevScrollIndices.current[i]} ) + csUtilities.jumpToSlice(viewport.element, { imageIndex: prevScrollIndices.current[i] }) } @@ -1218,7 +1254,7 @@ function App() { ) { //viewport.setImageIdIndex(idx); - csUtilities.jumpToSlice(viewport.element, {imageIndex: idx} ) + csUtilities.jumpToSlice(viewport.element, { imageIndex: idx }) //viewport.render(); updateOverlay(i, viewport); @@ -1698,12 +1734,58 @@ function App() { ))} + + {/* Expandable advanced mouse bindings */} +
+ + {showAdvancedMouseBindings && ( +
+ {ALL_MOUSE_BINDINGS.slice(3).map((btn) => ( +
+ + +
+ ))} +
+ )} +
+ {/* Ctrl + Mouse Button Tool Bindings */}
Ctrl + Mouse Button Tool Bindings
{MOUSE_BUTTONS.map((btn) => (
))} + + {/* Expandable advanced ctrl+mouse bindings */} + {showAdvancedMouseBindings && ( +
+ {ALL_MOUSE_BINDINGS.slice(3).map((btn) => ( +
+ + +
+ ))} +
+ )}