Exemplo n.º 1
0
        private void  AddLineCap(PointFP p1, PointFP p2, int lineCap)
        {
            if (lineCap == PenFP.LINECAP_BUTT || p1.Equals(p2))
            {
                return;
            }
            int dx  = p2.X - p1.X;
            int dy  = p2.Y - p1.Y;
            int len = PointFP.Distance(dx, dy);

            PointFP[] cap = lineCap == PenFP.LINECAP_ROUND?GraphicsPathFP.roundCap:GraphicsPathFP.squareCap;

            dx = MathFP.Mul(ff_rad, MathFP.Div(dx, len));
            dy = MathFP.Mul(ff_rad, MathFP.Div(dy, len));

            MatrixFP m = new MatrixFP(dx, dx, dy, -dy, p2.X, p2.Y);

            outline.AddMoveTo(new PointFP(0, GraphicsPathFP.One).Transform(m));
            for (int i = 0; i < cap.Length; i++)
            {
                outline.AddLineTo(new PointFP(cap[i]).Transform(m));
            }
            outline.AddLineTo(new PointFP(0, -GraphicsPathFP.One).Transform(m));
            outline.AddClose();
        }
Exemplo n.º 2
0
        public static GraphicsPathFP CreateOval(int ff_xmin, int ff_ymin, int ff_xmax, int ff_ymax)
        {
            GraphicsPathFP path = GraphicsPathFP.CreateArc(ff_xmin, ff_ymin, ff_xmax, ff_ymax, 0, MathFP.PI * 2, false);

            path.AddClose();
            return(path);
        }
Exemplo n.º 3
0
        public void  FillOval(int ff_xmin, int ff_ymin, int ff_xmax, int ff_ymax)
        {
            GraphicsPathFP path = GraphicsPathFP.CreateOval(ff_xmin, ff_ymin, ff_xmax, ff_ymax);

            path.AddClose();
            FillPath(path);
        }
Exemplo n.º 4
0
        public static GraphicsPathFP CreatePolygon(PointFP[] points)
        {
            GraphicsPathFP path = CreatePolyline(points);

            if (points.Length > 0)
            {
                path.AddClose();
            }
            return(path);
        }
Exemplo n.º 5
0
        public static GraphicsPathFP CreateSmoothCurves(PointFP[] points, int offset, int numberOfSegments, int ff_factor, bool closed)
        {
            int            len  = points.Length;
            GraphicsPathFP path = new GraphicsPathFP();

            if (numberOfSegments < 1 ||
                numberOfSegments > points.Length - 1 ||
                offset < 0 ||
                offset + numberOfSegments > len - 1)
            {
                return(path);
            }

            PointFP[] PC1s = new PointFP[points.Length];
            PointFP[] PC2s = new PointFP[points.Length];
            if (!closed)
            {
                PC1s[0]       = points[0];
                PC2s[len - 1] = points[len - 1];
            }
            else
            {
                PC1s[0]       = CalcControlPoint(points[len - 1], points[0], points[1], ff_factor);
                PC2s[0]       = CalcControlPoint(points[1], points[0], points[len - 1], ff_factor);
                PC1s[len - 1] = CalcControlPoint(points[len - 2], points[len - 1], points[0], ff_factor);
                PC2s[len - 1] = CalcControlPoint(points[0], points[len - 1], points[len - 2], ff_factor);
            }
            for (int i = 1; i < len - 1; i++)
            {
                PC1s[i] = CalcControlPoint(points[i - 1], points[i], points[i + 1], ff_factor);
                PC2s[i] = CalcControlPoint(points[i + 1], points[i], points[i - 1], ff_factor);
            }

            path.AddMoveTo(points[offset]);
            for (int i = 0; i < numberOfSegments; i++)
            {
                path.AddCurveTo(PC1s[offset + i], PC2s[offset + i + 1], points[offset + i + 1]);
            }
            if (closed)
            {
                path.AddCurveTo(PC1s[len - 1], PC2s[0], points[0]);
                path.AddClose();
            }
            return(path);
        }
Exemplo n.º 6
0
        public static GraphicsPathFP CreateRoundRect(int ff_xmin, int ff_ymin, int ff_xmax, int ff_ymax, int ff_rx, int ff_ry)
        {
            int            ff_rmax;
            int            FF_PI = MathFP.PI;
            GraphicsPathFP path  = new GraphicsPathFP();

            path.AddMoveTo(new PointFP(ff_xmin + ff_rx, ff_ymin));
            path.AddLineTo(new PointFP(ff_xmax - ff_rx, ff_ymin));
            ff_rmax = MathFP.Min(ff_xmax - ff_xmin, ff_ymax - ff_ymin) / 2;
            if (ff_rx > ff_rmax)
            {
                ff_rx = ff_rmax;
            }
            if (ff_ry > ff_rmax)
            {
                ff_ry = ff_rmax;
            }
            if (ff_rx != 0 && ff_ry != 0)
            {
                path.AddPath(GraphicsPathFP.CreateArc(ff_xmax - ff_rx * 2, ff_ymin, ff_xmax, ff_ymin + ff_ry * 2, (-FF_PI) / 2, 0, false, false));
            }
            path.AddLineTo(new PointFP(ff_xmax, ff_ymin + ff_ry));
            path.AddLineTo(new PointFP(ff_xmax, ff_ymax - ff_ry));
            if (ff_rx != 0 && ff_ry != 0)
            {
                path.AddPath(GraphicsPathFP.CreateArc(ff_xmax - ff_rx * 2, ff_ymax - ff_ry * 2, ff_xmax, ff_ymax, 0, FF_PI / 2, false, false));
            }
            path.AddLineTo(new PointFP(ff_xmax - ff_rx, ff_ymax));
            path.AddLineTo(new PointFP(ff_xmin + ff_rx, ff_ymax));
            if (ff_rx != 0 && ff_ry != 0)
            {
                path.AddPath(GraphicsPathFP.CreateArc(ff_xmin, ff_ymax - ff_ry * 2, ff_xmin + ff_rx * 2, ff_ymax, FF_PI / 2, FF_PI, false, false));
            }
            path.AddLineTo(new PointFP(ff_xmin, ff_ymax - ff_ry));
            path.AddLineTo(new PointFP(ff_xmin, ff_ymin + ff_ry));
            if (ff_rx != 0 && ff_ry != 0)
            {
                path.AddPath(GraphicsPathFP.CreateArc(ff_xmin, ff_ymin, ff_xmin + ff_rx * 2, ff_ymin + ff_ry * 2, -FF_PI, (-FF_PI) / 2, false, false));
            }
            path.AddClose();
            return(path);
        }
Exemplo n.º 7
0
        public static GraphicsPathFP  CreateArc(int ff_xmin, int ff_ymin, int ff_xmax, int ff_ymax, int ff_startangle, int ff_sweepangle, bool closed, bool standalone)
        {
            if (ff_sweepangle < 0)
            {
                ff_startangle += ff_sweepangle;
                ff_sweepangle  = -ff_sweepangle;
            }
            int segments = MathFP.Round(MathFP.Div(4 * MathFP.Abs(ff_sweepangle), MathFP.PI)) >> SingleFP.DecimalBits;

            if (segments == 0)
            {
                segments = 1;
            }
            GraphicsPathFP path = new GraphicsPathFP();
            int            ff_darg = ff_sweepangle / segments;
            int            ff_arg = ff_startangle;
            int            ff_lastcos = MathFP.Cos(ff_startangle);
            int            ff_lastsin = MathFP.Sin(ff_startangle);
            int            ff_xc = (ff_xmin + ff_xmax) / 2;
            int            ff_yc = (ff_ymin + ff_ymax) / 2;
            int            ff_rx = (ff_xmax - ff_xmin) / 2;
            int            ff_ry = (ff_ymax - ff_ymin) / 2;
            int            ff_RXBETA = MathFP.Mul(17381, ff_rx);
            int            ff_RYBETA = MathFP.Mul(17381, ff_ry);
            int            ff_currcos, ff_currsin, ff_x1, ff_y1, ff_x2, ff_y2;

            if (closed)
            {
                path.AddMoveTo(new PointFP(ff_xc, ff_yc));
            }

            for (int i = 1; i <= segments; i++)
            {
                ff_arg     = i == segments?ff_startangle + ff_sweepangle:ff_arg + ff_darg;
                ff_currcos = MathFP.Cos(ff_arg);
                ff_currsin = MathFP.Sin(ff_arg);
                ff_x1      = ff_xc + MathFP.Mul(ff_rx, ff_lastcos);
                ff_y1      = ff_yc + MathFP.Mul(ff_ry, ff_lastsin);
                ff_x2      = ff_xc + MathFP.Mul(ff_rx, ff_currcos);
                ff_y2      = ff_yc + MathFP.Mul(ff_ry, ff_currsin);
                if (i == 1)
                {
                    if (closed)
                    {
                        path.AddLineTo(new PointFP(ff_x1, ff_y1));
                    }
                    else
                    if (standalone)
                    {
                        path.AddMoveTo(new PointFP(ff_x1, ff_y1));
                    }
                }

                path.AddCurveTo(
                    new PointFP(ff_x1 - MathFP.Mul(ff_RXBETA, ff_lastsin), ff_y1 + MathFP.Mul(ff_RYBETA, ff_lastcos)),
                    new PointFP(ff_x2 + MathFP.Mul(ff_RXBETA, ff_currsin), ff_y2 - MathFP.Mul(ff_RYBETA, ff_currcos)),
                    new PointFP(ff_x2, ff_y2));
                ff_lastcos = ff_currcos;
                ff_lastsin = ff_currsin;
            }
            if (closed)
            {
                path.AddClose();
            }
            return(path);
        }