Skip to content

Commit 32a1bb4

Browse files
committed
feat(ResliceCursorWidget): ability to select mouse cursor styles
Expose api to set mouse cursor styles from outside. User can also disable mouse cursor styles by setting all styles as 'default'.
1 parent 18bf515 commit 32a1bb4

File tree

2 files changed

+38
-14
lines changed

2 files changed

+38
-14
lines changed

Sources/Widgets/Widgets3D/ResliceCursorWidget/behavior.js

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,18 @@ export default function widgetBehavior(publicAPI, model) {
2424
let isScrolling = false;
2525
let previousPosition;
2626

27-
macro.setGet(publicAPI, model, ['keepOrthogonality']);
27+
macro.setGet(publicAPI, model, [
28+
'keepOrthogonality',
29+
{ type: 'object', name: 'cursorStyles' },
30+
]);
31+
32+
// Set default value for cursorStyles
33+
publicAPI.setCursorStyles({
34+
[InteractionMethodsName.TranslateCenter]: 'move',
35+
[InteractionMethodsName.RotateLine]: 'alias',
36+
[InteractionMethodsName.TranslateAxis]: 'pointer',
37+
default: 'default',
38+
});
2839

2940
publicAPI.setEnableTranslation = (enable) => {
3041
model.representations[0].setPickable(enable); // line handle
@@ -115,19 +126,24 @@ export default function widgetBehavior(publicAPI, model) {
115126
};
116127

117128
publicAPI.updateCursor = () => {
118-
switch (publicAPI.getActiveInteraction()) {
119-
case InteractionMethodsName.TranslateCenter:
120-
model._apiSpecificRenderWindow.setCursor('move');
121-
break;
122-
case InteractionMethodsName.RotateLine:
123-
model._apiSpecificRenderWindow.setCursor('alias');
124-
break;
125-
case InteractionMethodsName.TranslateAxis:
126-
model._apiSpecificRenderWindow.setCursor('pointer');
127-
break;
128-
default:
129-
model._apiSpecificRenderWindow.setCursor('default');
130-
break;
129+
const cursorStyles = publicAPI.getCursorStyles();
130+
if (cursorStyles) {
131+
switch (publicAPI.getActiveInteraction()) {
132+
case InteractionMethodsName.TranslateCenter:
133+
model._apiSpecificRenderWindow.setCursor(
134+
cursorStyles.translateCenter
135+
);
136+
break;
137+
case InteractionMethodsName.RotateLine:
138+
model._apiSpecificRenderWindow.setCursor(cursorStyles.rotateLine);
139+
break;
140+
case InteractionMethodsName.TranslateAxis:
141+
model._apiSpecificRenderWindow.setCursor(cursorStyles.translateAxis);
142+
break;
143+
default:
144+
model._apiSpecificRenderWindow.setCursor(cursorStyles.default);
145+
break;
146+
}
131147
}
132148
};
133149

Sources/Widgets/Widgets3D/ResliceCursorWidget/example/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,13 @@ widgetState
5252
.forEach((handle) => handle.setScale1(20));
5353
const showDebugActors = true;
5454

55+
const appCursorStyles = {
56+
translateCenter: 'move',
57+
rotateLine: 'alias',
58+
translateAxis: 'pointer',
59+
default: 'default',
60+
};
61+
5562
// ----------------------------------------------------------------------------
5663
// Define html structure
5764
// ----------------------------------------------------------------------------
@@ -148,6 +155,7 @@ for (let i = 0; i < 4; i++) {
148155
obj.widgetInstance = obj.widgetManager.addWidget(widget, xyzToViewType[i]);
149156
obj.widgetInstance.setScaleInPixels(true);
150157
obj.widgetInstance.setKeepOrthogonality(checkboxOrthogonality.checked);
158+
obj.widgetInstance.setCursorStyles(appCursorStyles);
151159
obj.widgetManager.enablePicking();
152160
// Use to update all renderers buffer when actors are moved
153161
obj.widgetManager.setCaptureOn(CaptureOn.MOUSE_MOVE);

0 commit comments

Comments
 (0)