Search in sources :

Example 1 with SelectionBoxModel

use of au.gov.asd.tac.constellation.graph.interaction.visual.renderables.SelectionBoxModel in project constellation by constellation-app.

the class DefaultInteractionEventHandler method mouseDragged.

/**
 * Mouse pressed.
 * <p>
 * Note: if you right-click on an element, move the mouse to another part of
 * the element (ignoring the pop-up menu), and right-press, you don't get a
 * mousePressed event.
 *
 * @param event Mouse event.
 */
@Override
public void mouseDragged(final MouseEvent event) {
    queue.add(wg -> {
        // If a mouse pressed event was never registered (can happen when left clicking off a context menu) we ignore this event.
        // HACK_DPI - Multiply point by DPI scale factor
        Point point = event.getPoint();
        scaleMousePointByDPIFactor(point);
        if (eventState.isMousePressed()) {
            if (wg != null) {
                final Camera camera = new Camera(VisualGraphUtilities.getCamera(wg));
                final Point from;
                final Point to;
                boolean cameraChange = false;
                switch(eventState.getCurrentAction()) {
                    case ROTATING:
                        from = eventState.getFirstValidPoint(EventState.DRAG_POINT, EventState.REFERENCE_POINT);
                        to = point;
                        final boolean zAxisRotation = !VisualGraphUtilities.isDisplayModeIn3D(wg) || (event.isControlDown() && event.isShiftDown());
                        if (zAxisRotation) {
                            CameraUtilities.spin(camera, visualInteraction.convertTranslationToSpin(from, to));
                        } else {
                            CameraUtilities.rotate(camera, event.isShiftDown() ? 0 : (from.y - to.y) / 2.0F, event.isControlDown() ? 0 : (from.x - to.x) / 2.0F);
                        }
                        cameraChange = true;
                        break;
                    case PANNING:
                        from = eventState.getFirstValidPoint(EventState.DRAG_POINT, EventState.REFERENCE_POINT);
                        to = point;
                        final Vector3f panReferencePoint = eventState.hasClosestNode() ? eventState.getClosestNode() : CameraUtilities.getFocusVector(camera);
                        final Vector3f translation = visualInteraction.convertTranslationToPan(from, to, panReferencePoint);
                        CameraUtilities.pan(camera, translation.getX(), translation.getY());
                        cameraChange = true;
                        break;
                    case DRAG_NODES:
                        from = eventState.getFirstValidPoint(EventState.DRAG_POINT, EventState.REFERENCE_POINT);
                        to = point;
                        performDrag(wg, camera, from, to);
                        break;
                    case SELECTING:
                        updateSelectionBoxModel(new SelectionBoxModel(eventState.getPoint(EventState.PRESSED_POINT), point));
                        break;
                    case FREEFORM_SELECTING:
                        freeformModel.addPoint(point);
                        updateSelectionFreeformModel(freeformModel);
                        break;
                    default:
                        break;
                }
                updateCameraAndNewLine(wg, point, cameraChange ? camera : VisualGraphUtilities.getCamera(wg), cameraChange);
            }
            eventState.storePoint(point, EventState.DRAG_POINT);
        } else if (wg != null) {
            // In this case, a button is held down but its pressed event was not registered for whatever reason.
            updateHitTestAndNewLine(wg, point);
        } else {
        // Do nothing
        }
        return 0;
    });
}
Also used : Vector3f(au.gov.asd.tac.constellation.utilities.graphics.Vector3f) SelectionBoxModel(au.gov.asd.tac.constellation.graph.interaction.visual.renderables.SelectionBoxModel) Point(java.awt.Point) Camera(au.gov.asd.tac.constellation.utilities.camera.Camera)

Aggregations

SelectionBoxModel (au.gov.asd.tac.constellation.graph.interaction.visual.renderables.SelectionBoxModel)1 Camera (au.gov.asd.tac.constellation.utilities.camera.Camera)1 Vector3f (au.gov.asd.tac.constellation.utilities.graphics.Vector3f)1 Point (java.awt.Point)1