Skip to content
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
28 changes: 28 additions & 0 deletions src/components/tools/paint/PaintWidget2D.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
watchEffect,
inject,
} from 'vue';
import { useMagicKeys } from '@vueuse/core';
import vtkPlaneManipulator from '@kitware/vtk.js/Widgets/Manipulators/PlaneManipulator';
import { getLPSAxisFromDir } from '@/src/utils/lps';
import { useImage } from '@/src/composables/useCurrentImage';
Expand All @@ -22,6 +23,7 @@ import { useSliceInfo } from '@/src/composables/useSliceInfo';
import { VtkViewContext } from '@/src/components/vtk/context';
import { Maybe } from '@/src/types';
import { PaintMode } from '@/src/core/tools/paint';
import { actionToKey } from '@/src/composables/useKeyboardShortcuts';

export default defineComponent({
name: 'PaintWidget2D',
Expand Down Expand Up @@ -155,6 +157,32 @@ export default defineComponent({
widget.setEnabled(paintStore.activeMode !== PaintMode.Process);
});

// Brush size scroll wheel control with customizable modifier key
const keys = useMagicKeys();
const enableBrushSizeAdjustment = computed(
() => keys[actionToKey.value.brushSize].value
);

const handleWheelEvent = (event: WheelEvent) => {
if (!enableBrushSizeAdjustment.value) return;
event.preventDefault();
const delta = event.deltaY < 0 ? 1 : -1;
const newSize = Math.max(1, Math.min(50, paintStore.brushSize + delta));
paintStore.setBrushSize(newSize);
};

onMounted(() => {
view.renderWindowView
.getContainer()
?.addEventListener('wheel', handleWheelEvent, { passive: false });
});

onUnmounted(() => {
view.renderWindowView
.getContainer()
?.removeEventListener('wheel', handleWheelEvent);
});

return () => null;
},
});
Expand Down
1 change: 1 addition & 0 deletions src/composables/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ export const ACTION_TO_FUNC = {
zoom: setTool(Tools.Zoom),
ruler: setTool(Tools.Ruler),
paint: setTool(Tools.Paint),
brushSize: NOOP, // act as modifier key rather than immediate effect, so no-op
rectangle: setTool(Tools.Rectangle),
crosshairs: setTool(Tools.Crosshairs),
temporaryCrosshairs: NOOP, // behavior implemented elsewhere
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ export const ACTION_TO_KEY = {
zoom: 'z',
ruler: 'm',
paint: 'p',
brushSize: 'ctrl',
rectangle: 'r',
crosshairs: 'c',
temporaryCrosshairs: 'shift-c',
Expand Down
3 changes: 3 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ export const ACTIONS = {
paint: {
readable: 'Activate Paint tool',
},
brushSize: {
readable: 'Change brush size by holding key and scrolling',
},
rectangle: {
readable: 'Activate Rectangle tool',
},
Expand Down
Loading