示例#1
0
        public override bool OnMouseMove(Point mouseCurPos, Point mousePrevPos, BaseViewport viewport)
        {
            if (viewport.ViewportType != BaseViewport.ViewportTypes.PERSPECTIVE)
            {
                controller.SetCursor(Cursors.Cross);

                if (viewport.IsButtonHeld(BaseViewport.ViewportButtons.LEFT))
                {
                    Vector3 mouseDownPosition    = new Vector3(mouseDownPos.X, mouseDownPos.Y, 0);
                    Vector3 currentMousePosition = new Vector3(mouseCurPos.X, mouseCurPos.Y, 0);

                    Vector3 currentMouseWorld        = viewport.ViewportToWorld(currentMousePosition);
                    Vector3 snappedCurrentMouseWorld = GeneralUtility.SnapToGrid(currentMouseWorld, viewport.GridSize);
                    mouseHasMoved = (currentMousePosition - mouseDownPosition).Length > GeneralUtility.Epsilon;

                    switch (currentAction)
                    {
                    case VertexToolActionType.SelectMultiple:
                        coverBlanket.Reset();
                        coverBlanket.Grow(mouseDownPosition);
                        coverBlanket.Grow(currentMousePosition);
                        break;

                    case VertexToolActionType.SelectDrag:
                        Vector3 delta = snappedCurrentMouseWorld - dragStartPosition;
                        if (delta != Vector3.Zero)
                        {
                            TranslateVertices(delta);
                        }
                        dragStartPosition = snappedCurrentMouseWorld;
                        break;
                    }
                }
            }
            else
            {
                controller.SetCursor(Cursors.Default);
            }

            return(false);
        }
        public override bool OnMouseMove(Point mouseCurPos, Point mousePrevPos, BaseViewport viewport)
        {
            if (viewport.ViewportType != BaseViewport.ViewportTypes.PERSPECTIVE)
            {
                UpdateCursor(mouseCurPos, viewport);

                if (viewport.IsButtonHeld(BaseViewport.ViewportButtons.LEFT))
                {
                    // set standard values
                    Vector3 mouseDownPosition    = new Vector3(mouseDownPos.X, mouseDownPos.Y, 0);
                    Vector3 prevMousePosition    = new Vector3(mousePrevPos.X, mousePrevPos.Y, 0);
                    Vector3 currentMousePosition = new Vector3(mouseCurPos.X, mouseCurPos.Y, 0);
                    Matrix4 fromGridSpaceMatrix  = viewport.Camera.GetViewMatrix().ClearTranslation();

                    // we only give the rubberband volume if the mouse has moved in creation mode
                    bool mouseHasMoved = (currentMousePosition - mouseDownPosition).Length > GeneralUtility.Epsilon;
                    if (currentAction == SolidToolActionType.Create && mouseHasMoved)
                    {
                        mouseDownPosition.Z    = -viewport.GridSize * 4;
                        currentMousePosition.Z = viewport.GridSize * 4;
                    }

                    // convert to world
                    mouseDownPosition    = viewport.ViewportToWorld(mouseDownPosition);
                    prevMousePosition    = viewport.ViewportToWorld(prevMousePosition);
                    currentMousePosition = viewport.ViewportToWorld(currentMousePosition);

                    // snap
                    Vector3 snappedDownMousePosition    = GeneralUtility.SnapToGrid(mouseDownPosition, viewport.GridSize);
                    Vector3 snappedPrevMousePosition    = GeneralUtility.SnapToGrid(prevMousePosition, viewport.GridSize);
                    Vector3 snappedCurrentMousePosition = GeneralUtility.SnapToGrid(currentMousePosition, viewport.GridSize);

                    RubberBand rubberband = controller.RubberBand;

                    switch (currentAction)
                    {
                    case SolidToolActionType.Create:
                        rubberband.Bounds.Reset();
                        rubberband.Bounds.Grow(snappedDownMousePosition);
                        rubberband.Bounds.Grow(snappedCurrentMousePosition);
                        break;

                    case SolidToolActionType.Drag:
                    {
                        Vector3 delta = snappedCurrentMousePosition - snappedPrevMousePosition;
                        if (delta != Vector3.Zero)
                        {
                            TranslateOperation translate = new TranslateOperation(delta)
                            {
                                GridSize  = viewport.GridSize,
                                Transform = fromGridSpaceMatrix
                            };
                            rubberband.PerformOperation(translate);
                            rubberband.ShowGrabhandles = false;
                        }
                    }
                    break;

                    case SolidToolActionType.Transform:
                    {
                        SolidGrabHandles    handles   = rubberband.Handles;
                        IMapObjectOperation operation = null;

                        Vector3 delta = currentMousePosition - prevMousePosition;
                        if (delta != Vector3.Zero)
                        {
                            rubberband.ShowGrabhandles = false;
                        }

                        switch (handles.Mode)
                        {
                        case SolidGrabHandles.HandleMode.Resize:
                            operation = new ResizeTransformation(fromGridSpaceMatrix, snappedPrevMousePosition,
                                                                 snappedCurrentMousePosition,
                                                                 handles.LastHitStatus, viewport.GridSize);
                            break;

                        case SolidGrabHandles.HandleMode.Rotate:
                            operation = new RotateTransformation(fromGridSpaceMatrix, mouseDownPosition,
                                                                 currentMousePosition, Matrix4.Identity);
                            break;

                        case SolidGrabHandles.HandleMode.Skew:
                            operation = new SkewTransformation(fromGridSpaceMatrix, snappedDownMousePosition,
                                                               snappedCurrentMousePosition, Matrix4.Identity,
                                                               handles.LastHitStatus);
                            break;
                        }

                        if (operation != null)
                        {
                            controller.RubberBand.PerformOperation(operation);
                        }
                    }

                    break;
                    }
                }
            }
            else
            {
                controller.SetCursor(Cursors.Default);
            }

            return(true);
        }