Esempio n. 1
0
 public void MouseMove(Vector p)
 {
     CurrentPos = p;
     if (CreatingVertex)
     {
         AdjustForGrid(CurrentPos);
         _currentPolygon.Vertices[_currentPolygon.Count - 1] = p;
         if (_currentPolygon.Count > 2)
         {
             _currentPolygon.UpdateDecomposition(false);
         }
         UpdateHelp();
     }
     else if (!CreatingRectangle)
     {
         ResetHighlight();
         int nearestVertex = GetNearestVertexIndex(p);
         if (nearestVertex >= -1)
         {
             _nearestSegmentIndex = NearestPolygon.GetNearestSegmentIndex(p);
             ChangeCursorToHand();
         }
         else
         {
             ChangeToDefaultCursorIfHand();
             _nearestSegmentIndex = -1;
         }
     }
 }
Esempio n. 2
0
        public void MouseDown(MouseEventArgs mouseData)
        {
            switch (mouseData.Button)
            {
            case MouseButtons.Left:
                int nearestIndex = GetNearestVertexIndex(CurrentPos);
                AdjustForGrid(CurrentPos);
                if (CreatingRectangle)
                {
                    CreatingRectangle = false;
                    var rect = Polygon.Rectangle(_rectangleStart, CurrentPos);
                    Lev.Polygons.Add(rect);
                    rect.UpdateDecomposition();
                    LevEditor.Modified = true;
                    return;
                }

                if (!CreatingVertex)
                {
                    if (Keyboard.IsKeyDown(Key.LeftShift))
                    {
                        CreatingRectangle = true;
                        _rectangleStart   = CurrentPos;
                    }
                    else
                    {
                        CreatingVertex = true;
                        if (nearestIndex >= -1)
                        {
                            _nearestSegmentIndex = NearestPolygon.GetNearestSegmentIndex(CurrentPos);
                            _currentPolygon      = NearestPolygon;
                            _currentPolygon.SetBeginPoint(_nearestSegmentIndex + 1);
                            _currentPolygon.Add(CurrentPos);
                            ChangeToDefaultCursorIfHand();
                        }
                        else
                        {
                            _currentPolygon = new Polygon(CurrentPos, CurrentPos);
                        }
                    }
                }
                else
                {
                    _currentPolygon.Add(CurrentPos);
                    if (_currentPolygon.Count == 3)
                    {
                        Lev.Polygons.Add(_currentPolygon);
                        _currentPolygon.UpdateDecomposition(false);
                    }
                }

                break;

            case MouseButtons.Right:
                FinishVertexCreation();
                break;
            }
        }
Esempio n. 3
0
        public void MouseDown(MouseEventArgs mouseData)
        {
            Vector p = CurrentPos;

            _anythingMoved = false;
            int nearestVertexIndex  = GetNearestVertexIndex(p);
            int nearestObjectIndex  = GetNearestObjectIndex(p);
            int nearestPictureIndex = GetNearestPictureIndex(p);

            switch (mouseData.Button)
            {
            case MouseButtons.Left:
                if (nearestVertexIndex >= -1 && Keyboard.IsKeyDown(Key.LeftAlt))
                {
                    if (!Keyboard.IsKeyDown(Key.LeftCtrl))
                    {
                        MarkAllAs(VectorMark.None);
                    }

                    NearestPolygon.MarkVectorsAs(VectorMark.Selected);
                    var inearest = NearestPolygon.ToIPolygon();
                    foreach (var polygon in Lev.Polygons.Where(polygon => polygon.ToIPolygon().Within(inearest)))
                    {
                        polygon.MarkVectorsAs(VectorMark.Selected);
                    }

                    foreach (var obj in Lev.Objects)
                    {
                        if (NearestPolygon.AreaHasPoint(obj.Position))
                        {
                            obj.Position.Mark = VectorMark.Selected;
                        }
                    }

                    foreach (var pic in Lev.Pictures)
                    {
                        if (NearestPolygon.AreaHasPoint(pic.Position))
                        {
                            pic.Position.Mark = VectorMark.Selected;
                        }
                    }

                    EndSelectionHandling();
                }
                else if (nearestVertexIndex >= 0)
                {
                    HandleMark(NearestPolygon[nearestVertexIndex]);
                    if (Keyboard.IsKeyDown(Key.LeftShift))
                    {
                        _lockCenter        = NearestPolygon[nearestVertexIndex];
                        _lockPrev          = NearestPolygon[nearestVertexIndex - 1];
                        _lockNext          = NearestPolygon[nearestVertexIndex + 1];
                        _lockingLines      = true;
                        _moveStartPosition = _lockCenter;
                    }
                }
                else if (nearestVertexIndex == -1)
                {
                    int nearestSegmentIndex = NearestPolygon.GetNearestSegmentIndex(p);
                    AdjustForGrid(p);
                    if (Keyboard.IsKeyDown(Key.LeftShift))
                    {
                        MarkAllAs(VectorMark.None);
                        p.Mark = VectorMark.Selected;
                        NearestPolygon.Insert(nearestSegmentIndex + 1, p);
                        LevEditor.Modified = true;
                    }
                    else
                    {
                        if (
                            !(NearestPolygon[nearestSegmentIndex].Mark == VectorMark.Selected &&
                              NearestPolygon[nearestSegmentIndex + 1].Mark == VectorMark.Selected))
                        {
                            if (!Keyboard.IsKeyDown(Key.LeftCtrl))
                            {
                                MarkAllAs(VectorMark.None);
                                NearestPolygon.MarkVectorsAs(VectorMark.Selected);
                            }
                        }

                        if (Keyboard.IsKeyDown(Key.LeftCtrl))
                        {
                            NearestPolygon.MarkVectorsAs(
                                NearestPolygon.Vertices.TrueForAll(v => v.Mark == VectorMark.Selected)
                                        ? VectorMark.None
                                        : VectorMark.Selected);
                        }
                    }

                    EndSelectionHandling();
                }
                else if (nearestObjectIndex >= 0)
                {
                    HandleMark(Lev.Objects[nearestObjectIndex].Position);
                }
                else if (nearestPictureIndex >= 0)
                {
                    HandleMark(Lev.Pictures[nearestPictureIndex].Position);
                }
                else
                {
                    if (!Keyboard.IsKeyDown(Key.LeftCtrl))
                    {
                        MarkAllAs(VectorMark.None);
                        LevEditor.PreserveSelection();
                    }

                    if (Keyboard.IsKeyDown(Key.LeftShift))
                    {
                        FreeSelecting  = true;
                        _selectionPoly = new Polygon();
                        _selectionPoly.Add(CurrentPos);
                        _mouseTrip         = 0;
                        _lastMousePosition = CurrentPos;
                    }
                    else
                    {
                        _selectionStartPoint = p;
                        RectSelecting        = true;
                    }
                }

                LevEditor.UpdateSelectionInfo();
                break;

            case MouseButtons.Right:
                break;

            case MouseButtons.Middle:
                break;
            }
        }