Skip to content

Commit 6de3948

Browse files
committed
feat(RenderWindowInteractor): add deviceType
deviceType will allow listeners to determine the type of device that triggered a particular event.
1 parent 31997ae commit 6de3948

File tree

1 file changed

+24
-4
lines changed
  • Sources/Rendering/Core/RenderWindowInteractor

1 file changed

+24
-4
lines changed

Sources/Rendering/Core/RenderWindowInteractor/index.js

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,10 @@ function vtkRenderWindowInteractor(publicAPI, model) {
204204
return keys;
205205
}
206206

207+
function getDeviceTypeFor(event) {
208+
return event.pointerType || '';
209+
}
210+
207211
publicAPI.bindEvents = (container) => {
208212
model.container = container;
209213
container.addEventListener('contextmenu', preventDefault);
@@ -286,18 +290,24 @@ function vtkRenderWindowInteractor(publicAPI, model) {
286290
const callData = {
287291
...getModifierKeysFor(event),
288292
position: getScreenEventPositionFor(event),
293+
deviceType: getDeviceTypeFor(event),
289294
};
290295
publicAPI.pointerEnterEvent(callData);
291-
publicAPI.mouseEnterEvent(callData);
296+
if (callData.deviceType === 'mouse') {
297+
publicAPI.mouseEnterEvent(callData);
298+
}
292299
};
293300

294301
publicAPI.handlePointerLeave = (event) => {
295302
const callData = {
296303
...getModifierKeysFor(event),
297304
position: getScreenEventPositionFor(event),
305+
deviceType: getDeviceTypeFor(event),
298306
};
299307
publicAPI.pointerLeaveEvent(callData);
300-
publicAPI.mouseLeaveEvent(callData);
308+
if (callData.deviceType === 'mouse') {
309+
publicAPI.mouseLeaveEvent(callData);
310+
}
301311
};
302312

303313
publicAPI.handlePointerDown = (event) => {
@@ -392,6 +402,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {
392402
const callData = {
393403
...getModifierKeysFor(event),
394404
position: getScreenEventPositionFor(event),
405+
deviceType: getDeviceTypeFor(event),
395406
};
396407
switch (event.button) {
397408
case 0:
@@ -591,6 +602,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {
591602
const callData = {
592603
...getModifierKeysFor(event),
593604
position: getScreenEventPositionFor(event),
605+
deviceType: getDeviceTypeFor(event),
594606
};
595607

596608
if (model.moveTimeoutID === 0) {
@@ -660,6 +672,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {
660672
...normalizeWheel(event),
661673
...getModifierKeysFor(event),
662674
position: getScreenEventPositionFor(event),
675+
deviceType: getDeviceTypeFor(event),
663676
};
664677

665678
if (model.wheelTimeoutID === 0) {
@@ -681,6 +694,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {
681694
const callData = {
682695
...getModifierKeysFor(event),
683696
position: getScreenEventPositionFor(event),
697+
deviceType: getDeviceTypeFor(event),
684698
};
685699
switch (event.button) {
686700
case 0:
@@ -708,6 +722,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {
708722
const callData = {
709723
...getModifierKeysFor(EMPTY_MOUSE_EVENT),
710724
position: pointers[0].position,
725+
deviceType: getDeviceTypeFor(event),
711726
};
712727
publicAPI.leftButtonReleaseEvent(callData);
713728
}
@@ -717,12 +732,13 @@ function vtkRenderWindowInteractor(publicAPI, model) {
717732
const callData = {
718733
...getModifierKeysFor(EMPTY_MOUSE_EVENT),
719734
position: getScreenEventPositionFor(event),
735+
deviceType: getDeviceTypeFor(event),
720736
};
721737
publicAPI.leftButtonPressEvent(callData);
722738
}
723739
};
724740

725-
publicAPI.handleTouchMove = () => {
741+
publicAPI.handleTouchMove = (event) => {
726742
const pointers = [...pointerCache.values()];
727743
if (model.recognizeGestures && pointers.length > 1) {
728744
const positions = pointerCacheToPositions(pointerCache);
@@ -731,12 +747,13 @@ function vtkRenderWindowInteractor(publicAPI, model) {
731747
const callData = {
732748
...getModifierKeysFor(EMPTY_MOUSE_EVENT),
733749
position: pointers[0].position,
750+
deviceType: getDeviceTypeFor(event),
734751
};
735752
publicAPI.mouseMoveEvent(callData);
736753
}
737754
};
738755

739-
publicAPI.handleTouchEnd = () => {
756+
publicAPI.handleTouchEnd = (event) => {
740757
const pointers = [...pointerCache.values()];
741758

742759
if (model.recognizeGestures) {
@@ -745,6 +762,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {
745762
const callData = {
746763
...getModifierKeysFor(EMPTY_MOUSE_EVENT),
747764
position: pointers[0].position,
765+
deviceType: getDeviceTypeFor(event),
748766
};
749767
publicAPI.leftButtonReleaseEvent(callData);
750768
} else if (pointers.length === 1) {
@@ -754,6 +772,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {
754772
const callData = {
755773
...getModifierKeysFor(EMPTY_MOUSE_EVENT),
756774
position: pointers[0].position,
775+
deviceType: getDeviceTypeFor(event),
757776
};
758777
publicAPI.leftButtonPressEvent(callData);
759778
} else {
@@ -765,6 +784,7 @@ function vtkRenderWindowInteractor(publicAPI, model) {
765784
const callData = {
766785
...getModifierKeysFor(EMPTY_MOUSE_EVENT),
767786
position: pointers[0].position,
787+
deviceType: getDeviceTypeFor(event),
768788
};
769789
publicAPI.leftButtonReleaseEvent(callData);
770790
}

0 commit comments

Comments
 (0)