コード例 #1
0
 public DecoratorContext(System.Drawing.Point ShapePosition = new System.Drawing.Point(), string CaptionPosition = "",
                         CanvasShape shape = null, string captionText = "Enter your text here...")
 {
     this.CaptionPosition = CaptionPosition;
     this.shape           = shape;
     this.CaptionPosition = positions[CommandInvoker.Rnd.Next(0, 4)];
     this.captionText     = captionText;
 }
コード例 #2
0
ファイル: CommandMove.cs プロジェクト: dannypas00/DrawingApp
 public CommandMove(CanvasShape shape, Point initialPos, MainWindow mainWindow)
 {
     this.mainWindow = mainWindow;
     this.shape      = shape;
     oldPos.X        = (int)MathF.Round((float)Canvas.GetLeft(shape.GetShape()));
     oldPos.Y        = (int)MathF.Round((float)Canvas.GetTop(shape.GetShape()));
     offset.X        = initialPos.X - Canvas.GetLeft(shape.GetShape());
     offset.Y        = initialPos.Y - Canvas.GetTop(shape.GetShape());
 }
コード例 #3
0
        public RenderCanvas(CanvasShape canvasShape)
        {
            _canvasShape = canvasShape;
            _canvasShape.InvalidateShape = () => this.InvalidateVisual();

            _drawingContextRenderer = new DrawingContextRenderer();

            //Background = Brushes.Transparent;
            Width  = _canvasShape.Width;
            Height = _canvasShape.Height;
        }
コード例 #4
0
        public void DrawBackground(DrawingContext dc, CanvasShape canvasShape)
        {
            if (canvasShape.Background == null)
            {
                return;
            }

            var brush = new SolidColorBrush(ToColor(canvasShape.Background));

            var rectangle = new Rect(0, 0, canvasShape.Width, canvasShape.Height);

            dc.DrawRectangle(brush, null, rectangle);
        }
コード例 #5
0
 public void DrawCanvasShape(DrawingContext dc, CanvasShape canvasShape)
 {
     foreach (var shape in canvasShape.Children)
     {
         if (shape is LineShape lineShape)
         {
             DrawLine(dc, lineShape);
         }
         else if (shape is RectangleShape rectangleShape)
         {
             DrawRectangle(dc, rectangleShape);
         }
         else if (shape is PolygonShape polygonShape)
         {
             DrawPolygon(dc, polygonShape);
         }
     }
 }
コード例 #6
0
        public void VisitCanvasShape(CanvasShape e)
        {
            string postLine;
            string type   = e.GetName().Split(' ')[1];;
            string indent = "";
            double x      = Canvas.GetLeft(e.GetShape());
            double y      = Canvas.GetTop(e.GetShape());
            double h      = e.GetShape().Width;
            double w      = e.GetShape().Height;

            postLine = " " + x + " " + y + " " + h + " " + w;
            for (int i = 0; i < e.GetDepth(); i++)
            {
                indent += "    ";
            }

            string line = indent + type + postLine;

            buffer.Add(line);
        }
コード例 #7
0
ファイル: CommandDraw.cs プロジェクト: dannypas00/DrawingApp
        private void Select(object sender, MouseButtonEventArgs e)
        {
            if (!(sender is Shape) || invoker.MainWindow.CurrentAction != "select")
            {
                return;
            }
            CanvasShape parent = invoker.Map[shape];

            if (invoker.MainWindow.Selected != null)
            {
                invoker.MainWindow.Selected.Unselect();
                invoker.MainWindow.Selected = null;
            }
            if (invoker.MainWindow.Selected == parent)
            {
                return;
            }
            invoker.MainWindow.Selected = parent;
            invoker.StartMove(parent, e.GetPosition(invoker.MainWindow.canvas));
            parent.Select();
        }
コード例 #8
0
        private void ShapeButton_Click(object sender, RoutedEventArgs e)
        {
            Button s = (Button)sender;

            CurrentAction = s.Name;
            if (CurrentAction == "rectangle")
            {
                strategy = new RectangleStrategy();
            }
            else if (CurrentAction == "ellipse")
            {
                strategy = new EllipseStrategy();
            }
            Trace.WriteLine("Name: " + CurrentAction);
            if (Selected == null)
            {
                return;
            }
            Selected.Unselect();
            Selected = null;
        }
コード例 #9
0
        private void ObserveInput(CanvasShape canvasShape, IControl target)
        {
            canvasShape.Downs = Observable.FromEventPattern <PointerPressedEventArgs>(
                target,
                "PointerPressed").Select(e =>
            {
                var p = e.EventArgs.GetPosition(target);
                return(new Point2(
                           canvasShape.EnableSnap ? canvasShape.Snap(p.X, canvasShape.SnapX) : p.X,
                           canvasShape.EnableSnap ? canvasShape.Snap(p.Y, canvasShape.SnapY) : p.Y));
            });

            canvasShape.Ups = Observable.FromEventPattern <PointerReleasedEventArgs>(
                target,
                "PointerReleased").Select(e =>
            {
                var p = e.EventArgs.GetPosition(target);
                return(new Point2(
                           canvasShape.EnableSnap ? canvasShape.Snap(p.X, canvasShape.SnapX) : p.X,
                           canvasShape.EnableSnap ? canvasShape.Snap(p.Y, canvasShape.SnapY) : p.Y));
            });

            canvasShape.Moves = Observable.FromEventPattern <PointerEventArgs>(
                target,
                "PointerMoved").Select(e =>
            {
                var p = e.EventArgs.GetPosition(target);
                return(new Point2(
                           canvasShape.EnableSnap ? canvasShape.Snap(p.X, canvasShape.SnapX) : p.X,
                           canvasShape.EnableSnap ? canvasShape.Snap(p.Y, canvasShape.SnapY) : p.Y));
            });

            bool captured = false;

            canvasShape.IsCaptured = () => captured;

            canvasShape.Capture = () => captured = true;

            canvasShape.ReleaseCapture = () => captured = false;
        }
コード例 #10
0
        private void ObserveInput(CanvasShape canvasShape, UIElement target)
        {
            canvasShape.Downs = Observable.FromEventPattern <MouseButtonEventArgs>(
                target,
                "PreviewMouseLeftButtonDown").Select(e =>
            {
                var p = e.EventArgs.GetPosition(target);
                return(new Point2(
                           canvasShape.EnableSnap ? canvasShape.Snap(p.X, canvasShape.SnapX) : p.X,
                           canvasShape.EnableSnap ? canvasShape.Snap(p.Y, canvasShape.SnapY) : p.Y));
            });

            canvasShape.Ups = Observable.FromEventPattern <MouseButtonEventArgs>(
                target,
                "PreviewMouseLeftButtonUp").Select(e =>
            {
                var p = e.EventArgs.GetPosition(target);
                return(new Point2(
                           canvasShape.EnableSnap ? canvasShape.Snap(p.X, canvasShape.SnapX) : p.X,
                           canvasShape.EnableSnap ? canvasShape.Snap(p.Y, canvasShape.SnapY) : p.Y));
            });

            canvasShape.Moves = Observable.FromEventPattern <MouseEventArgs>(
                target,
                "PreviewMouseMove").Select(e =>
            {
                var p = e.EventArgs.GetPosition(target);
                return(new Point2(
                           canvasShape.EnableSnap ? canvasShape.Snap(p.X, canvasShape.SnapX) : p.X,
                           canvasShape.EnableSnap ? canvasShape.Snap(p.Y, canvasShape.SnapY) : p.Y));
            });

            canvasShape.IsCaptured = () => Mouse.Captured == target;

            canvasShape.Capture = () => target.CaptureMouse();

            canvasShape.ReleaseCapture = () => target.ReleaseMouseCapture();
        }
コード例 #11
0
 public void DrawCustom(CanvasShape shape, Vector2 position, Vector2 size, Color c, float rotation = 0)
 {
     AddObject(new MySprite(SpriteType.TEXTURE, shape.Value, position, size, c, null, TextAlignment.CENTER, rotation));
 }
コード例 #12
0
 public void VisitCanvasShape(CanvasShape e)
 {
     throw new NotImplementedException();
 }
コード例 #13
0
        //This region handles the two movement commands

        /// <summary>
        /// Starts the movement process,
        /// it is intended to run once when the mouse button is pressed,
        /// and to be finished with the Move function.
        /// </summary>
        /// <param name="shape">The shape to move</param>
        /// <param name="initialPos">The initial position of the mouse moving the shape</param>
        public void StartMove(CanvasShape shape, Point initialPos)
        {
            ICommand cmd = new CommandMove(shape, initialPos, MainWindow);

            actionsDone.Push(cmd);
        }
コード例 #14
0
 public CommandResize(CanvasShape shape, MouseWheelEventArgs currMouseWheelEventArgs)
 {
     this.shape = shape;
     wheelDelta = -currMouseWheelEventArgs.Delta;
 }