Exemplo n.º 1
0
 private void SetSelectDragAction(Vector3 startPosition, BaseViewport viewport)
 {
     if (viewport.ViewportType != BaseViewport.ViewportTypes.PERSPECTIVE)
     {
         currentAction = VertexToolActionType.SelectDrag;
         Matrix4 toViewportMatrix = viewport.Camera.GetWorldMatrix().ClearTranslation();
         dragStartPosition = startPosition * (toViewportMatrix.Row0.Xyz + toViewportMatrix.Row1.Xyz);
     }
 }
Exemplo n.º 2
0
 public override void Initialize(IEditorController controller)
 {
     this.controller = controller;
     controller.CurrentSolidManipulationMode = SolidManipulationMode.Vertex;
     currentAction = VertexToolActionType.None;
     mouseHasMoved = false;
     newHandlesHit = new Dictionary <Solid, List <int> >();
     coverBlanket  = new AABB();
     coverBlanket.Grow(Vector3.Zero);
     controller.SetCursor(Cursors.Default);
 }
Exemplo n.º 3
0
        public override bool OnMouseUp(Point mouseCurPos, MouseButtons button, BaseViewport viewport)
        {
            if (viewport.ViewportType != BaseViewport.ViewportTypes.PERSPECTIVE &&
                button == MouseButtons.Left)
            {
                // ON MOUSE UP
                // -- action == selectDrag && NOT control pressed && if we did not move the mouse
                // -- and selected new vertices we select them (adding them to existing selection)
                switch (currentAction)
                {
                case VertexToolActionType.SelectMultiple:
                    if (mouseHasMoved)
                    {
                        SelectHandlesWithBlanket(viewport, coverBlanket);
                    }
                    else
                    {
                        ClearAllSelectedVertices();
                    }
                    break;

                case VertexToolActionType.SelectDrag:
                    bool isControlPressed = modifierKey == Keys.Control;
                    bool anySelected      = newHandlesHit.All((pair) => pair.Value.Any((index) => pair.Key.SelectedVertices.Contains(index)));

                    if (!isControlPressed && !mouseHasMoved && anySelected)
                    {
                        foreach (KeyValuePair <Solid, List <int> > pair in newHandlesHit)
                        {
                            pair.Value.ForEach((index) =>
                            {
                                if (!pair.Key.SelectedVertices.Contains(index))
                                {
                                    pair.Key.SelectedVertices.Add(index);
                                }
                            });
                        }
                    }

                    break;
                }

                coverBlanket.Reset();
                coverBlanket.Grow(Vector3.Zero);

                mouseHasMoved = false;
                currentAction = VertexToolActionType.None;
            }

            return(false);
        }
Exemplo n.º 4
0
        public override bool OnMouseDown(Point mouseCurPos, MouseButtons button, BaseViewport viewport)
        {
            if (button == MouseButtons.Left)
            {
                currentActionViewport = viewport.ViewportType;
                MapObjectGroup selectedMapObjectGroup = controller.Selection;

                bool isControlPressed = modifierKey == Keys.Control;
                newHandlesHit = GetHandlesHitWithMouse(viewport, mouseCurPos);

                // Check if we hit a vertex handle
                if (newHandlesHit.Count > 0)
                {
                    Action dragStartPositionAction = () =>
                    {
                        // any vertex will do
                        var   first       = newHandlesHit.First();
                        Solid solid       = first.Key;
                        int   firstVertex = first.Value[0];

                        SetSelectDragAction(solid.VertexPositions[firstVertex], viewport);
                    };

                    Action isAnySelected = () =>
                    {
                        // if still any selected left, setSelectDrag
                        bool selected = newHandlesHit.All((pair) => pair.Value.Any((index) => pair.Key.SelectedVertices.Contains(index)));
                        if (selected)
                        {
                            dragStartPositionAction();
                        }
                    };

                    bool anySelected = newHandlesHit.All((pair) => pair.Value.Any((index) => pair.Key.SelectedVertices.Contains(index)));
                    if (isControlPressed)
                    {
                        foreach (KeyValuePair <Solid, List <int> > pair in newHandlesHit)
                        {
                            pair.Value.ForEach((index) =>
                            {
                                if (pair.Key.SelectedVertices.Contains(index))
                                {
                                    pair.Key.SelectedVertices.Remove(index);
                                }
                                else
                                {
                                    pair.Key.SelectedVertices.Add(index);
                                }
                            });
                        }

                        isAnySelected();
                    }
                    else if (anySelected)
                    {
                        dragStartPositionAction();
                    }
                    else
                    {
                        ClearAllSelectedVertices();
                        foreach (KeyValuePair <Solid, List <int> > pair in newHandlesHit)
                        {
                            pair.Value.ForEach((index) =>
                            {
                                if (!pair.Key.SelectedVertices.Contains(index))
                                {
                                    pair.Key.SelectedVertices.Add(index);
                                }
                            });
                        }

                        isAnySelected();
                    }
                }
                else // if no handles hit, check if we hit a solid
                {
                    MapObject rootMapObject = controller.GetMapObjectIfHit(mouseCurPos.X, mouseCurPos.Y, viewport);
                    if (rootMapObject == null)
                    {
                        if (viewport.ViewportType == BaseViewport.ViewportTypes.PERSPECTIVE)
                        {
                            ClearAllSelectedVertices();
                        }
                        else // no map object hit for orthographic set action to SelectMultiple
                        {
                            currentAction = VertexToolActionType.SelectMultiple;
                        }
                    }
                    else
                    {
                        if (isControlPressed)
                        {
                            if (!rootMapObject.Selected)
                            {
                                rootMapObject.Selected = true;
                                selectedMapObjectGroup.Add(rootMapObject);
                            }
                            else
                            {
                                DoSolidAction(rootMapObject, (solid) =>
                                {
                                    solid.SelectedVertices.Clear();
                                });
                                rootMapObject.Selected = false;
                                selectedMapObjectGroup.Remove(rootMapObject);
                            }
                        }
                        else if (!rootMapObject.Selected)
                        {
                            ClearAllSelectedVertices();
                            selectedMapObjectGroup.Clear();
                            rootMapObject.Selected = true;
                            selectedMapObjectGroup.Add(rootMapObject);
                        }
                        else
                        {
                            // solid we hit was already selected so we set action to SelectMultiples
                            currentAction = VertexToolActionType.SelectMultiple;
                        }
                    }
                }

                mouseDownPos = mouseCurPos;
            }

            return(true);
        }