Пример #1
0
 private void SetElement(UIElement element, Point startPoint, Point endPoint)
 {
     if (element is DoodleCube)
     {
         DoodleCube cube = (DoodleCube)element;
         cube.SetPoints(startPoint, endPoint);
     }
     else if (element is DoodleCone)
     {
         DoodleCone cone = (DoodleCone)element;
         cone.SetPoints(startPoint, endPoint);
     }
     else if (element is DoodleCylinder)
     {
         DoodleCylinder cylinder = (DoodleCylinder)element;
         cylinder.SetPoints(startPoint, endPoint);
     }
 }
Пример #2
0
        private void drawWithMovePoint(Point point)
        {
            DoodleModel model = (DoodleModel)doodleModels[doodleModels.Count - 1];

            model.points.Add(new DoodlePoint(getLogicPoint(point)));

            switch (model.drawType)
            {
            case DoodleEnumType.eraser:
            {
                if (doodleCanvas is InkCanvas)
                {
                    double eraserWidth = getEraserWidth();
                    eraserPointList.Add(point);
                    if (eraserPointList.Count > 5)
                    {
                        eraserPointList.RemoveAt(0);
                    }
                    doodleCanvas.Strokes.Erase(eraserPointList, new RectangleStylusShape(eraserWidth, eraserWidth));
                }
            }
            break;

            case DoodleEnumType.draw:
            {
                if (doodleCanvas is InkCanvas)
                {
                    List <Point> pointList = new List <Point>();
                    pointList.Add(point);

                    Stroke s = stroke;
                    s.StylusPoints.Add(new StylusPointCollection(pointList));
                }
                else if (doodleCanvas is Canvas)
                {
                    Path path = (Path)element;
                    doodleCanvas.Children.Remove(path);
                    PathFigure pathFigure = new PathFigure();
                    pathFigure.StartPoint = getLocalPoint(model.points[0].GetPoint);

                    List <Point> controls = new List <Point>();
                    for (int i = 0; i < model.points.Count; i++)
                    {
                        controls.AddRange(BezierControlPoints(model.points, i));
                    }
                    for (int i = 1; i < model.points.Count; i++)
                    {
                        BezierSegment bs = new BezierSegment(controls[i * 2 - 1], controls[i * 2], getLocalPoint(model.points[i].GetPoint), true);
                        bs.IsSmoothJoin = true;
                        pathFigure.Segments.Add(bs);
                    }
                    PathFigureCollection pathFigureCollection = new PathFigureCollection();
                    pathFigureCollection.Add(pathFigure);
                    PathGeometry pathGeometry = new PathGeometry(pathFigureCollection);
                    path.Data = pathGeometry;
                    doodleCanvas.Children.Add(path);
                }
            }
            break;

            case DoodleEnumType.rect:
            {
                Point     startPoint = getLocalPoint(model.startPoint.GetPoint);
                Rectangle rect       = (Rectangle)element;
                rect.Margin = new Thickness(getSmallX(startPoint, point), getSmallY(startPoint, point), 0, 0);
                rect.Width  = Math.Abs(startPoint.X - point.X);
                rect.Height = Math.Abs(startPoint.Y - point.Y);
            }
            break;

            case DoodleEnumType.line:
            {
                Point startPoint = getLocalPoint(model.startPoint.GetPoint);
                Line  line       = (Line)element;
                line.X1 = startPoint.X;
                line.Y1 = startPoint.Y;
                line.X2 = point.X;
                line.Y2 = point.Y;
            }
            break;

            case DoodleEnumType.circle:
            {
                Point   startPoint = getLocalPoint(model.startPoint.GetPoint);
                Ellipse circle     = (Ellipse)element;
                circle.Margin = new Thickness(getSmallX(startPoint, point), getSmallY(startPoint, point), 0, 0);
                circle.Width  = Math.Abs(startPoint.X - point.X);
                circle.Height = Math.Abs(startPoint.Y - point.Y);
            }
            break;

            case DoodleEnumType.arrow:
            {
                Point startPoint = getLocalPoint(model.startPoint.GetPoint);
                Arrow arrow      = (Arrow)element;
                arrow.X1 = startPoint.X;
                arrow.Y1 = startPoint.Y;
                arrow.X2 = point.X;
                arrow.Y2 = point.Y;
            }
            break;

            case DoodleEnumType.cube:
            {
                Point      startPoint = getLocalPoint(model.startPoint.GetPoint);
                DoodleCube cone       = (DoodleCube)element;
                cone.SetPoints(startPoint, point);
            }
            break;

            case DoodleEnumType.cylinder:
            {
                Point          startPoint = getLocalPoint(model.startPoint.GetPoint);
                DoodleCylinder cone       = (DoodleCylinder)element;
                cone.SetPoints(startPoint, point);
            }
            break;

            case DoodleEnumType.cone:
            {
                Point      startPoint = getLocalPoint(model.startPoint.GetPoint);
                DoodleCone cone       = (DoodleCone)element;
                cone.SetPoints(startPoint, point);
            }
            break;

            default:
                break;
            }
        }