示例#1
0
 public override void Start(object sender)
 {
     if (sender is Ellipse)
     {
         Ellipse     pointShape = (Ellipse)sender;
         HandlePoint point      = CanvasHolder.GetHandlePointByShape(pointShape);
         if (point is AnchorPoint)
         {
             CanvasHolder.SelectHandlePoint(point);
             moveAnchor = true;
             ProgressTimer.Start();
         }
     }
     else if (sender is Shape)
     {
         Shape       shape         = (Shape)sender;
         ShapeHolder shapeHolder   = CanvasHolder.GetShapeHolderByShape(shape);
         AnchorPoint anchorPoint   = shapeHolder.AnchorPoint;
         Point       mousePosition = Mouse.GetPosition(CanvasHolder.Canvas);
         if (anchorPoint == null)
         {
             anchorPoint             = new AnchorPoint(mousePosition, shapeHolder);
             shapeHolder.AnchorPoint = anchorPoint;
             CanvasHolder.SelectHandlePoint(anchorPoint);
             moveAnchor = true;
             ProgressTimer.Start();
         }
         else
         {
             position   = mousePosition;
             moveAnchor = false;
             ProgressTimer.Start();
         }
     }
 }
        public override void Start(object sender)
        {
            if (sender is Shape)
            {
                Shape  shape  = sender as Shape;
                Canvas canvas = CanvasHolder.Canvas;
                position    = Mouse.GetPosition(canvas);
                shapeHolder = CanvasHolder.GetShapeHolderByShape(shape);
                CanvasHolder.ActiveShapeHolder = shapeHolder;

                ProgressTimer.Start();
            }
        }
        private void Save_OnClick(object sender, RoutedEventArgs e)
        {
            SaveFileDialog dialog = new SaveFileDialog();

            if (dialog.ShowDialog() == true)
            {
                ShapeHolder  shapeHolder = CanvasHolder.ActiveShapeHolder;
                string       path        = dialog.FileName;
                StreamWriter outputFile  = new StreamWriter(path);
                outputFile.WriteLine(shapeHolder.ToString());
                outputFile.Close();
            }
        }
示例#4
0
        public override void Start(object sender)
        {
            if (sender is Canvas)
            {
                Canvas canvas        = (Canvas)sender;
                Point  mousePosition = Mouse.GetPosition(canvas);

                ShapeHolder newShapeHolder = ShapeHolderFactory.CreateShapeHolder(CanvasHolder);
                HandlePoint newHandlePoint = new HandlePoint(mousePosition, newShapeHolder);
                newShapeHolder.CreateByPoint(newHandlePoint);
                CanvasHolder.SelectHandlePoint(newHandlePoint);

                ProgressTimer.Start();
            }
        }
        private void Load_OnClick(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            if (dialog.ShowDialog() == true)
            {
                ShapeHolder shapeHolder = ShapeHolderFactory.CreateShapeHolder(CanvasHolder);
                CanvasHolder.ActiveShapeHolder = shapeHolder;
                string       path      = dialog.FileName;
                StreamReader inputFile = new StreamReader(path);
                string       input     = inputFile.ReadLine();
                shapeHolder.FromString(input);
                inputFile.Close();
            }
        }
示例#6
0
        protected override void Progress()
        {
            HandlePoint activeHandlePoint = CanvasHolder.ActiveHandlePoint;
            Point       mousePosition     = Mouse.GetPosition(CanvasHolder.Canvas);

            if (moveAnchor)
            {
                activeHandlePoint.Move(mousePosition);
            }
            else
            {
                double      angle       = getAngle(activeHandlePoint.Position, position, mousePosition);
                ShapeHolder shapeHolder = activeHandlePoint.ShapeHolder;
                shapeHolder.Rotate(angle);
                position = mousePosition;
            }
        }
示例#7
0
        protected override void Progress()
        {
            HandlePoint activeHandlePoint = CanvasHolder.ActiveHandlePoint;
            Point       mousePosition     = Mouse.GetPosition(CanvasHolder.Canvas);

            if (moveAnchor)
            {
                activeHandlePoint.Move(mousePosition);
            }
            else
            {
                double      distance    = getDistance(activeHandlePoint.Position, mousePosition);
                double      ratio       = distance / oldDistance;
                ShapeHolder shapeHolder = activeHandlePoint.ShapeHolder;
                shapeHolder.Scale(ratio);
                position    = mousePosition;
                oldDistance = distance;
            }
        }
示例#8
0
        private void Draw_OnClick(object sender, RoutedEventArgs e)
        {
            Point position1 = new Point();
            Point position2 = new Point();

            position1.X = Convert.ToDouble(tbPositionX1.Text);
            position1.Y = Convert.ToDouble(tbPositionY1.Text);
            position2.X = Convert.ToDouble(tbPositionX2.Text);
            position2.Y = Convert.ToDouble(tbPositionY2.Text);

            ShapeHolder newShapeHolder = ShapeHolderFactory.CreateShapeHolder(CanvasHolder);
            HandlePoint newHandlePoint = new HandlePoint(position1, newShapeHolder);

            newShapeHolder.CreateByPoint(newHandlePoint);
            CanvasHolder.SelectHandlePoint(newHandlePoint);

            newHandlePoint.Move(position2);
            newHandlePoint.ModifyShape();
        }
        public HandlePoint(Point position, ShapeHolder shapeHolder)
        {
            ShapeHolder = shapeHolder;
            pointShape  = new Ellipse();

            pointShape.Stroke = Brushes.Black;
            pointShape.Fill   = Brushes.Black;
            pointShape.Width  = HANDLE_POINT_SIZE;
            pointShape.Height = HANDLE_POINT_SIZE;

            pointShape.MouseDown += shapeHolder.CanvasHolder.MouseDownEventHandler;
            pointShape.MouseUp   += shapeHolder.CanvasHolder.MouseUpEventHandler;

            ShapeHolder.CanvasHolder.Canvas.Children.Add(pointShape);
            ShapeHolder.CanvasHolder.AddHandlePoint(this);
            Canvas.SetZIndex(pointShape, 1);

            Move(position);
        }
示例#10
0
        public override void Start(object sender)
        {
            if (sender is Canvas)
            {
                Canvas      canvas        = (Canvas)sender;
                Point       mousePosition = Mouse.GetPosition(canvas);
                ShapeHolder shapeHolder   = CanvasHolder.ActiveShapeHolder;

                if (shapeHolder == null)
                {
                    shapeHolder = ShapeHolderFactory.CreateShapeHolder(CanvasHolder);
                    CanvasHolder.ActiveShapeHolder = shapeHolder;
                }
                HandlePoint newHandlePoint = new HandlePoint(mousePosition, shapeHolder);
                shapeHolder.CreateByPoint(newHandlePoint);

                if (shapeHolder.HandlePoints.Count > 2)
                {
                    shapeHolder.ModifyByPoint(newHandlePoint);
                }
            }
        }
        private void AddPoint_OnClick(object sender, RoutedEventArgs e)
        {
            Point position = new Point();

            position.X = Convert.ToDouble(tbPositionX.Text);
            position.Y = Convert.ToDouble(tbPositionY.Text);

            ShapeHolder shapeHolder = CanvasHolder.ActiveShapeHolder;

            if (shapeHolder == null)
            {
                shapeHolder = ShapeHolderFactory.CreateShapeHolder(CanvasHolder);
                CanvasHolder.ActiveShapeHolder = shapeHolder;
            }
            HandlePoint newHandlePoint = new HandlePoint(position, shapeHolder);

            shapeHolder.CreateByPoint(newHandlePoint);

            if (shapeHolder.HandlePoints.Count > 2)
            {
                shapeHolder.ModifyByPoint(newHandlePoint);
            }
        }
 public AnchorPoint(Point position, ShapeHolder shapeHolder) : base(position, shapeHolder)
 {
     pointShape.Stroke = Brushes.Gray;
     pointShape.Fill   = Brushes.Gray;
 }
 public virtual void TranslateShape()
 {
     ShapeHolder.TranslateByPoint(this);
 }
 public virtual void ModifyShape()
 {
     ShapeHolder.ModifyByPoint(this);
 }
 public void AddShapeHolder(ShapeHolder shapeHolder)
 {
     ShapeHolders.Add(shapeHolder);
 }