Skip to content

Commit

Permalink
feat(polygon): hover on when cursor over line or handle
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulHax committed Sep 14, 2023
1 parent d15b65a commit eb2ddbc
Showing 1 changed file with 2 additions and 34 deletions.
36 changes: 2 additions & 34 deletions src/vtk/PolygonWidget/behavior.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { distance2BetweenPoints } from '@kitware/vtk.js/Common/Core/Math';
import vtkBoundingBox from '@kitware/vtk.js/Common/DataModel/BoundingBox';
import macro from '@kitware/vtk.js/macros';
import { Bounds, Vector3 } from '@kitware/vtk.js/types';
import { Vector3 } from '@kitware/vtk.js/types';
import vtkRenderer from '@kitware/vtk.js/Rendering/Core/Renderer';

import { WidgetAction } from '../ToolWidgetUtils/utils';
Expand Down Expand Up @@ -224,37 +223,6 @@ export default function widgetBehavior(publicAPI: any, model: any) {
// Mouse move: Drag selected handle / Handle follow the mouse
// --------------------------------------------------------------------------

const checkInScreenBounds = (event: vtkMouseEvent) => {
const b = publicAPI.getBounds();
if (!vtkBoundingBox.isValid(b)) return false;

const corners = [] as Array<Vector3>;
vtkBoundingBox.getCorners(b, corners);

const screenBounds = [...vtkBoundingBox.INIT_BOUNDS] as Bounds;
corners.forEach((corner) => {
const pos = model._apiSpecificRenderWindow.worldToDisplay(
...corner,
event.pokedRenderer
) as Vector3;
vtkBoundingBox.addPoint(screenBounds, ...pos);
});

const pointerScreenPos = [
event.position.x,
event.position.y,
event.position.z,
] as Vector3;

screenBounds[4] = -1;
screenBounds[5] = 1;
const isInside = vtkBoundingBox.containsPoint(
screenBounds,
...pointerScreenPos
);
return isInside;
};

publicAPI.handleMouseMove = (event: vtkMouseEvent) => {
if (
model.pickable &&
Expand All @@ -278,7 +246,7 @@ export default function widgetBehavior(publicAPI: any, model: any) {

publicAPI.invokeHoverEvent({
...event,
hovering: checkInScreenBounds(event),
hovering: !!model.activeState,
});

return macro.VOID;
Expand Down

0 comments on commit eb2ddbc

Please sign in to comment.