Esempio n. 1
0
        public override void OnMouseDown(object sender, MouseEventArgs e)
        {
            // Only run during initial press
            if (ClickData.Action != ShapeClickAction.None)
            {
                return;
            }

            using (GraphicsPath path = new GraphicsPath(FillMode.Alternate))
            {
                var location = e.Location;
                ClickData.Origin = Grid.SnapToGrid(e.Location);
                var shape = Canvas.Instance.layer.GetShapeByPoint(path, location);

                switch (e.Button)
                {
                case MouseButtons.Right:
                    SharedActions.RemoveShape(shape);
                    break;

                case MouseButtons.Middle:
                    if (shape != null && shape.Type == ShapeType.Triangle)
                    {
                        SharedActions.TriangleIncrementAngle(shape);
                    }
                    break;

                case MouseButtons.Left:
                    bool createShape = true;
                    if (!KeyboardController.IsShiftDown && shape != null)
                    {
                        var action = shape.GetShapeActionByPoint(path, location);
                        if (action != ShapeClickAction.None)
                        {
                            ClickData.Set(action, shape);
                            createShape = false;
                            OnMouseMove(sender, e);
                        }
                        else
                        {
                            throw new InvalidOperationException(
                                      "Shape was found under Point, but action wasn't - This shouldn't happen."
                                      );
                        }
                    }
                    if (createShape)
                    {
                        var newSize     = new Size(20, 20);
                        var sizeSnapped = Grid.SnapToGrid(newSize, Grid.SnapSizeToGrid);
                        GenerateShape(sizeSnapped);
                    }
                    break;
                }
            }

            Canvas.Instance.Invalidate();
        }
Esempio n. 2
0
 public override void OnProcessKeys(KeyEventArgs e, bool isDown)
 {
     switch (e.KeyCode)
     {
     case Keys.Delete:
         if (!isDown && !ClickData.IsShapesEmpty() && Canvas.Instance.Focused)
         {
             foreach (Shape s in ClickData.Shapes)
             {
                 SharedActions.RemoveShape(s);
             }
         }
         break;
     }
 }
Esempio n. 3
0
 public override void OnProcessKeys(KeyEventArgs e, bool isDown)
 {
     if (action == SelectorAction.EndSelectionRectangle || action == SelectorAction.EndMoveSelectedShapes)
     {
         switch (e.KeyCode)
         {
         case Keys.Delete:
             foreach (var s in ClickData.Shapes)
             {
                 SharedActions.RemoveShape(s);
             }
             break;
         }
     }
 }
Esempio n. 4
0
        public override void OnMouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button != MouseButtons.Right)
            {
                return;
            }

            using (GraphicsPath path = new GraphicsPath(FillMode.Alternate))
            {
                var location = e.Location;
                ClickData.Origin = Grid.SnapToGrid(e.Location);
                var shape = Canvas.Instance.layer.GetShapeByPoint(path, location);

                SharedActions.RemoveShape(shape);
            }
            Canvas.Instance.Invalidate();
        }
Esempio n. 5
0
        public override void OnMouseDoubleClick(object sender, MouseEventArgs e)
        {
            using (GraphicsPath path = new GraphicsPath(FillMode.Alternate))
            {
                var location = e.Location;
                ClickData.Origin = Grid.SnapToGrid(e.Location);

                // Todo: Copy over the moving mechanics a little better.
                var shape = Canvas.Instance.layer.GetShapeByPoint(path, location);
                if (shape == null)
                {
                    return;
                }

                if (shape.Type == ShapeType.Triangle)
                {
                    SharedActions.TriangleIncrementAngle(shape);
                }
            }
        }