Exemple #1
0
        private List <GraphicsPath> GetPath(List <Vex.IShapeData> shapes, bool isFilled)
        {
            List <GraphicsPath> result = new List <GraphicsPath>();

            if (shapes.Count == 0)
            {
                return(result);
            }
            DDW.Vex.Point endPoint = shapes[0].EndPoint;
            GraphicsPath  gp       = new GraphicsPath();

            gp.FillMode = FillMode.Alternate;
            result.Add(gp);

            for (int i = 0; i < shapes.Count; i++)
            {
                Vex.IShapeData sd = shapes[i];

                if (sd.StartPoint != endPoint)
                {
                    if (isFilled)
                    {
                        gp.CloseFigure();
                    }
                    else
                    {
                        gp          = new GraphicsPath();
                        gp.FillMode = FillMode.Alternate;
                        result.Add(gp);
                    }
                }
                switch (sd.SegmentType)
                {
                case Vex.SegmentType.Line:
                    Vex.Line l = (Vex.Line)sd;
                    gp.AddLine(l.Anchor0.X, l.Anchor0.Y, l.Anchor1.X, l.Anchor1.Y);
                    break;

                case Vex.SegmentType.CubicBezier:
                    Vex.CubicBezier cb = (Vex.CubicBezier)sd;
                    gp.AddBezier(
                        cb.Anchor0.X, cb.Anchor0.Y,
                        cb.Control0.X, cb.Control0.Y,
                        cb.Control1.X, cb.Control1.Y,
                        cb.Anchor1.X, cb.Anchor1.Y);
                    break;

                case Vex.SegmentType.QuadraticBezier:
                    Vex.QuadBezier  qb  = (Vex.QuadBezier)sd;
                    Vex.CubicBezier qtc = qb.GetCubicBezier();
                    gp.AddBezier(
                        qtc.Anchor0.X, qtc.Anchor0.Y,
                        qtc.Control0.X, qtc.Control0.Y,
                        qtc.Control1.X, qtc.Control1.Y,
                        qtc.Anchor1.X, qtc.Anchor1.Y);
                    break;
                }
                endPoint = sd.EndPoint;
            }
            if (isFilled)
            {
                gp.CloseFigure();
            }
            return(result);
        }