コード例 #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();
        }
コード例 #2
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);
                }
            }
        }