////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * Create the line path from given coordinates.
         * @param ff_x1
         * @param ff_y1
         * @param ff_x2
         * @param ff_y2
         * @return
         */
        public static GraphicsPathFP CreateLine(int ffX1, int ffY1,
                                                int ffX2, int ffY2)
        {
            var path = new GraphicsPathFP();

            path.AddMoveTo(new PointFP(ffX1, ffY1));
            path.AddLineTo(new PointFP(ffX2, ffY2));
            return(path);
        }
        private void DashLine(GraphicsPathFP path, LineFP line)
        {
            if (_nextDistance < 0)
            {
                _nextDistance = _dashArray[_dashIndex];
                _dashIndex    = (_dashIndex + 1) % _dashArray.Length;
            }
            var distance = _nextDistance;

            var pt = line.GetPointAtDistance(distance);

            while (pt != null)
            {
                if (_isEmpty)
                {
                    path.AddMoveTo(pt);
                }
                else
                {
                    path.AddLineTo(pt);
                }

                _isEmpty       = !_isEmpty;
                _nextDistance += _dashArray[_dashIndex];
                distance       = _nextDistance;
                pt             = line.GetPointAtDistance(distance);
                _dashIndex     = (_dashIndex + 1) % _dashArray.Length;
            }
            if (_isEmpty)
            {
                path.AddMoveTo(line.Pt2);
            }
            else
            {
                path.AddLineTo(line.Pt2);
            }
            _nextDistance = _nextDistance - line.GetLength();
        }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * create a polyline path.
         * @param points
         * @return
         */
        public static GraphicsPathFP CreatePolyline(PointFP[] points)
        {
            var path = new GraphicsPathFP();

            if (points.Length > 0)
            {
                path.AddMoveTo(points[0]);
                for (var i = 1; i < points.Length; i++)
                {
                    path.AddLineTo(points[i]);
                }
            }
            return(path);
        }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 09NOV2008  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * Create an round rectangle path from given parameter.
         * @param ff_xmin
         * @param ff_ymin
         * @param ff_xmax
         * @param ff_ymax
         * @param ff_rx
         * @param ff_ry
         * @return
         */
        public static GraphicsPathFP CreateRoundRect(int ffXmin, int ffYmin,
                                                     int ffXmax, int ffYmax, int ffRx, int ffRy)
        {
            const int ffPi = MathFP.PI;
            var       path = new GraphicsPathFP();

            path.AddMoveTo(new PointFP(ffXmin + ffRx, ffYmin));
            path.AddLineTo(new PointFP(ffXmax - ffRx, ffYmin));
            var ffRmax = MathFP.Min(ffXmax - ffXmin, ffYmax - ffYmin) / 2;

            if (ffRx > ffRmax)
            {
                ffRx = ffRmax;
            }
            if (ffRy > ffRmax)
            {
                ffRy = ffRmax;
            }
            if (ffRx != 0 && ffRy != 0)
            {
                path.AddPath(CreateArc(ffXmax - ffRx * 2,
                                       ffYmin, ffXmax, ffYmin + ffRy * 2,
                                       (-ffPi) / 2, 0, false, false));
            }
            path.AddLineTo(new PointFP(ffXmax, ffYmin + ffRy));
            path.AddLineTo(new PointFP(ffXmax, ffYmax - ffRy));
            if (ffRx != 0 && ffRy != 0)
            {
                path.AddPath(CreateArc(ffXmax - ffRx * 2,
                                       ffYmax - ffRy * 2, ffXmax, ffYmax, 0,
                                       ffPi / 2, false, false));
            }
            path.AddLineTo(new PointFP(ffXmax - ffRx, ffYmax));
            path.AddLineTo(new PointFP(ffXmin + ffRx, ffYmax));
            if (ffRx != 0 && ffRy != 0)
            {
                path.AddPath(CreateArc(ffXmin, ffYmax - ffRy * 2,
                                       ffXmin + ffRx * 2, ffYmax,
                                       ffPi / 2, ffPi, false, false));
            }
            path.AddLineTo(new PointFP(ffXmin, ffYmax - ffRy));
            path.AddLineTo(new PointFP(ffXmin, ffYmin + ffRy));
            if (ffRx != 0 && ffRy != 0)
            {
                path.AddPath(CreateArc(ffXmin, ffYmin,
                                       ffXmin + ffRx * 2, ffYmin + ffRy * 2, -ffPi,
                                       (-ffPi) / 2, false, false));
            }
            path.AddClose();
            return(path);
        }
        private void DashLine(GraphicsPathFP path, LineFP line)
        {
            if (_nextDistance < 0)
            {
                _nextDistance = _dashArray[_dashIndex];
                _dashIndex = (_dashIndex + 1) % _dashArray.Length;
            }
            var distance = _nextDistance;

            var pt = line.GetPointAtDistance(distance);
            while (pt != null)
            {
                if (_isEmpty)
                {
                    path.AddMoveTo(pt);
                }
                else
                {
                    path.AddLineTo(pt);
                }

                _isEmpty = !_isEmpty;
                _nextDistance += _dashArray[_dashIndex];
                distance = _nextDistance;
                pt = line.GetPointAtDistance(distance);
                _dashIndex = (_dashIndex + 1) % _dashArray.Length;
            }
            if (_isEmpty)
            {
                path.AddMoveTo(line.Pt2);
            }
            else
            {
                path.AddLineTo(line.Pt2);
            }
            _nextDistance = _nextDistance - line.GetLength();
        }
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 09NOV2008  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * Create an round rectangle path from given parameter.
  * @param ff_xmin
  * @param ff_ymin
  * @param ff_xmax
  * @param ff_ymax
  * @param ff_rx
  * @param ff_ry
  * @return
  */
 public static GraphicsPathFP CreateRoundRect(int ffXmin, int ffYmin,
         int ffXmax, int ffYmax, int ffRx, int ffRy)
 {
     const int ffPi = MathFP.PI;
     var path = new GraphicsPathFP();
     path.AddMoveTo(new PointFP(ffXmin + ffRx, ffYmin));
     path.AddLineTo(new PointFP(ffXmax - ffRx, ffYmin));
     var ffRmax = MathFP.Min(ffXmax - ffXmin, ffYmax - ffYmin) / 2;
     if (ffRx > ffRmax)
     {
         ffRx = ffRmax;
     }
     if (ffRy > ffRmax)
     {
         ffRy = ffRmax;
     }
     if (ffRx != 0 && ffRy != 0)
     {
         path.AddPath(CreateArc(ffXmax - ffRx * 2,
                 ffYmin, ffXmax, ffYmin + ffRy * 2,
                 (-ffPi) / 2, 0, false, false));
     }
     path.AddLineTo(new PointFP(ffXmax, ffYmin + ffRy));
     path.AddLineTo(new PointFP(ffXmax, ffYmax - ffRy));
     if (ffRx != 0 && ffRy != 0)
     {
         path.AddPath(CreateArc(ffXmax - ffRx * 2,
                 ffYmax - ffRy * 2, ffXmax, ffYmax, 0,
                 ffPi / 2, false, false));
     }
     path.AddLineTo(new PointFP(ffXmax - ffRx, ffYmax));
     path.AddLineTo(new PointFP(ffXmin + ffRx, ffYmax));
     if (ffRx != 0 && ffRy != 0)
     {
         path.AddPath(CreateArc(ffXmin, ffYmax - ffRy * 2,
                 ffXmin + ffRx * 2, ffYmax,
                 ffPi / 2, ffPi, false, false));
     }
     path.AddLineTo(new PointFP(ffXmin, ffYmax - ffRy));
     path.AddLineTo(new PointFP(ffXmin, ffYmin + ffRy));
     if (ffRx != 0 && ffRy != 0)
     {
         path.AddPath(CreateArc(ffXmin, ffYmin,
                 ffXmin + ffRx * 2, ffYmin + ffRy * 2, -ffPi,
                 (-ffPi) / 2, false, false));
     }
     path.AddClose();
     return path;
 }
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 13JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * create a polyline path.
  * @param points
  * @return
  */
 public static GraphicsPathFP CreatePolyline(PointFP[] points)
 {
     var path = new GraphicsPathFP();
     if (points.Length > 0)
     {
         path.AddMoveTo(points[0]);
         for (var i = 1; i < points.Length; i++)
         {
             path.AddLineTo(points[i]);
         }
     }
     return path;
 }
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 13JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * Create the line path from given coordinates.
  * @param ff_x1
  * @param ff_y1
  * @param ff_x2
  * @param ff_y2
  * @return
  */
 public static GraphicsPathFP CreateLine(int ffX1, int ffY1,
         int ffX2, int ffY2)
 {
     var path = new GraphicsPathFP();
     path.AddMoveTo(new PointFP(ffX1, ffY1));
     path.AddLineTo(new PointFP(ffX2, ffY2));
     return path;
 }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                 	          Initial Creation
        ////////////////////////////////////////////////////////////////////////////
        /**
         * Create arc path.
         * @param ff_xmin
         * @param ff_ymin
         * @param ff_xmax
         * @param ff_ymax
         * @param ff_startangle
         * @param ff_sweepangle
         * @param closed
         * @param standalone
         * @return
         */
        public static GraphicsPathFP CreateArc(int ffXmin, int ffYmin,
                int ffXmax, int ffYmax, int ffStartangle,
                int ffSweepangle, bool closed, bool standalone)
        {
            if (ffSweepangle < 0)
            {
                ffStartangle += ffSweepangle;
                ffSweepangle = -ffSweepangle;
            }
            var segments = MathFP.Round(MathFP.Div(4 * MathFP.Abs(ffSweepangle),
                    MathFP.PI)) >> SingleFP.DECIMAL_BITS;
            if (segments == 0)
            {
                segments = 1;
            }
            var path = new GraphicsPathFP();
            var ffDarg = ffSweepangle / segments;
            var ffArg = ffStartangle;
            var ffLastcos = MathFP.Cos(ffStartangle);
            var ffLastsin = MathFP.Sin(ffStartangle);
            var ffXc = (ffXmin + ffXmax) / 2;
            var ffYc = (ffYmin + ffYmax) / 2;
            var ffRx = (ffXmax - ffXmin) / 2;
            var ffRy = (ffYmax - ffYmin) / 2;
            var ffRxbeta = MathFP.Mul(17381, ffRx);
            var ffRybeta = MathFP.Mul(17381, ffRy);

            if (closed)
            {
                path.AddMoveTo(new PointFP(ffXc, ffYc));
            }

            for (var i = 1; i <= segments; i++)
            {
                ffArg = i == segments ? ffStartangle + ffSweepangle
                        : ffArg + ffDarg;
                var ffCurrcos = MathFP.Cos(ffArg);
                var ffCurrsin = MathFP.Sin(ffArg);
                var ffX1 = ffXc + MathFP.Mul(ffRx, ffLastcos);
                var ffY1 = ffYc + MathFP.Mul(ffRy, ffLastsin);
                var ffX2 = ffXc + MathFP.Mul(ffRx, ffCurrcos);
                var ffY2 = ffYc + MathFP.Mul(ffRy, ffCurrsin);
                if (i == 1)
                {
                    if (closed)
                    {
                        path.AddLineTo(new PointFP(ffX1, ffY1));
                    }
                    else if (standalone)
                    {
                        path.AddMoveTo(new PointFP(ffX1, ffY1));
                    }
                }

                path.AddCurveTo(
                        new PointFP(ffX1 - MathFP.Mul(ffRxbeta, ffLastsin),
                        ffY1 + MathFP.Mul(ffRybeta, ffLastcos)),
                        new PointFP(ffX2 + MathFP.Mul(ffRxbeta, ffCurrsin),
                        ffY2 - MathFP.Mul(ffRybeta, ffCurrcos)),
                        new PointFP(ffX2, ffY2));
                ffLastcos = ffCurrcos;
                ffLastsin = ffCurrsin;
            }
            if (closed)
            {
                path.AddClose();
            }
            return path;
        }
示例#10
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * Create arc path.
         * @param ff_xmin
         * @param ff_ymin
         * @param ff_xmax
         * @param ff_ymax
         * @param ff_startangle
         * @param ff_sweepangle
         * @param closed
         * @param standalone
         * @return
         */
        public static GraphicsPathFP CreateArc(int ffXmin, int ffYmin,
                                               int ffXmax, int ffYmax, int ffStartangle,
                                               int ffSweepangle, bool closed, bool standalone)
        {
            if (ffSweepangle < 0)
            {
                ffStartangle += ffSweepangle;
                ffSweepangle  = -ffSweepangle;
            }
            var segments = MathFP.Round(MathFP.Div(4 * MathFP.Abs(ffSweepangle),
                                                   MathFP.PI)) >> SingleFP.DECIMAL_BITS;

            if (segments == 0)
            {
                segments = 1;
            }
            var path      = new GraphicsPathFP();
            var ffDarg    = ffSweepangle / segments;
            var ffArg     = ffStartangle;
            var ffLastcos = MathFP.Cos(ffStartangle);
            var ffLastsin = MathFP.Sin(ffStartangle);
            var ffXc      = (ffXmin + ffXmax) / 2;
            var ffYc      = (ffYmin + ffYmax) / 2;
            var ffRx      = (ffXmax - ffXmin) / 2;
            var ffRy      = (ffYmax - ffYmin) / 2;
            var ffRxbeta  = MathFP.Mul(17381, ffRx);
            var ffRybeta  = MathFP.Mul(17381, ffRy);

            if (closed)
            {
                path.AddMoveTo(new PointFP(ffXc, ffYc));
            }

            for (var i = 1; i <= segments; i++)
            {
                ffArg = i == segments ? ffStartangle + ffSweepangle
                        : ffArg + ffDarg;
                var ffCurrcos = MathFP.Cos(ffArg);
                var ffCurrsin = MathFP.Sin(ffArg);
                var ffX1      = ffXc + MathFP.Mul(ffRx, ffLastcos);
                var ffY1      = ffYc + MathFP.Mul(ffRy, ffLastsin);
                var ffX2      = ffXc + MathFP.Mul(ffRx, ffCurrcos);
                var ffY2      = ffYc + MathFP.Mul(ffRy, ffCurrsin);
                if (i == 1)
                {
                    if (closed)
                    {
                        path.AddLineTo(new PointFP(ffX1, ffY1));
                    }
                    else if (standalone)
                    {
                        path.AddMoveTo(new PointFP(ffX1, ffY1));
                    }
                }

                path.AddCurveTo(
                    new PointFP(ffX1 - MathFP.Mul(ffRxbeta, ffLastsin),
                                ffY1 + MathFP.Mul(ffRybeta, ffLastcos)),
                    new PointFP(ffX2 + MathFP.Mul(ffRxbeta, ffCurrsin),
                                ffY2 - MathFP.Mul(ffRybeta, ffCurrcos)),
                    new PointFP(ffX2, ffY2));
                ffLastcos = ffCurrcos;
                ffLastsin = ffCurrsin;
            }
            if (closed)
            {
                path.AddClose();
            }
            return(path);
        }