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

        /**
         * @inheritDoc
         * @param x the x coordinate
         * @param y the y coordinate
         * @param singlePoint  single point
         * @return the color Value at given location.
         */
        public override int GetColorAt(int x, int y, bool singlePoint)
        {
            var p = new PointFP(x << SingleFP.DECIMAL_BITS,
                                y << SingleFP.DECIMAL_BITS);

            _nextPt.X = p.X + SingleFP.ONE;
            _nextPt.Y = p.Y;
            if (_finalMatrix != null)
            {
                p.Transform(_finalMatrix);
            }
            var xPos = (p.X >> SingleFP.DECIMAL_BITS) % _width;
            var yPos = (p.Y >> SingleFP.DECIMAL_BITS) % _height;

            if (xPos < 0)
            {
                xPos += _width;
            }
            if (yPos < 0)
            {
                yPos += _height;
            }


            return(_textureBuffer[(xPos + yPos * _width)]);
        }
Exemple #2
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * @inheritDoc
         * @return next color.
         */
        public override int GetNextColor()
        {
            var p = new PointFP(_nextPt);

            _nextPt.X += SingleFP.ONE;
            _nextPt.Y  = p.Y;

            if (_finalMatrix != null)
            {
                p.Transform(_finalMatrix);
            }
            var xPos = (p.X >> SingleFP.DECIMAL_BITS) % _width;
            var yPos = (p.Y >> SingleFP.DECIMAL_BITS) % _height;

            if (xPos < 0)
            {
                xPos += _width;
            }
            if (yPos < 0)
            {
                yPos += _height;
            }

            return(_textureBuffer[xPos + yPos * _width]);
        }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         *
         * @param control
         * @param point
         */
        public virtual void QuadTo(PointFP control, PointFP point)
        {
            // Compute forward difference values for a quadratic
            // curve of type A*(1-t)^2 + 2*B*t*(1-t) + C*t^2

            var f   = new PointFP(_currPoint);
            var tmp = new PointFP((_currPoint.X - control.X * 2 + point.X)
                                  / SUBDIVIDE2, (_currPoint.Y - control.Y * 2 + point.Y)
                                  / SUBDIVIDE2);
            var ddf = new PointFP(tmp.X * 2, tmp.Y * 2);
            var df  = new PointFP(tmp.X + (control.X - _currPoint.X) * 2
                                  / SUBDIVIDE, tmp.Y + (control.Y - _currPoint.Y) * 2 / SUBDIVIDE);

            for (int c = 0; c < SUBDIVIDE - 1; c++)
            {
                f.Add(df);
                df.Add(ddf);
                LineTo(f);
            }

            // We specify the last point manually since
            // we obtain rounding errors during the
            // forward difference computation.
            LineTo(point);
        }
        private void ExtendIfNeeded(int cmdsAddNum, int pntsAddNum)
        {
            if (_cmds == null)
            {
                _cmds = new int[BLOCKSIZE];
            }
            if (_pnts == null)
            {
                _pnts = new PointFP[BLOCKSIZE];
            }

            if (_cmdsSize + cmdsAddNum > _cmds.Length)
            {
                var newdata = new int[_cmds.Length + (cmdsAddNum > BLOCKSIZE
                        ? cmdsAddNum : BLOCKSIZE)];
                if (_cmdsSize > 0)
                {
                    Array.Copy(_cmds, 0, newdata, 0, _cmdsSize);
                }
                _cmds = newdata;
            }
            if (_pntsSize + pntsAddNum > _pnts.Length)
            {
                var newdata = new PointFP[_pnts.Length +
                                          (pntsAddNum > BLOCKSIZE ? pntsAddNum : BLOCKSIZE)];
                if (_pntsSize > 0)
                {
                    Array.Copy(_pnts, 0, newdata, 0, _pntsSize);
                }
                _pnts = newdata;
            }
        }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////
        public virtual void CurveTo(PointFP control1, PointFP control2, PointFP point)
        {
            var tmp1 = new PointFP(_currPoint.X - control1.X * 2 + control2.X,
                                   _currPoint.Y - control1.Y * 2 + control2.Y);
            var tmp2 = new PointFP((control1.X - control2.X) * 3 - _currPoint.X
                                   + point.X, (control1.Y - control2.Y) * 3 - _currPoint.Y + point.Y);

            var f  = new PointFP(_currPoint);
            var df = new PointFP((control1.X - _currPoint.X) * 3 / SUBDIVIDE
                                 + tmp1.X * 3 / SUBDIVIDE2 + tmp2.X / SUBDIVIDE3,
                                 (control1.Y - _currPoint.Y) * 3 / SUBDIVIDE + tmp1.Y * 3
                                 / SUBDIVIDE2 + tmp2.Y / SUBDIVIDE3);
            var ddf = new PointFP(tmp1.X * 6 / SUBDIVIDE2 + tmp2.X * 6
                                  / SUBDIVIDE3, tmp1.Y * 6 / SUBDIVIDE2 + tmp2.Y * 6 / SUBDIVIDE3);
            var dddf = new PointFP(tmp2.X * 6
                                   / SUBDIVIDE3, tmp2.Y * 6 / SUBDIVIDE3);

            for (var c = 0; c < SUBDIVIDE - 1; c++)
            {
                f.Add(df);
                df.Add(ddf);
                ddf.Add(dddf);
                LineTo(f);
            }

            LineTo(point);
        }
Exemple #6
0
 public static Point[] ToPointArray(PointFP[] pnts)
 {
     Point[] result = new Point[pnts.Length];
     for (int i = 0; i < pnts.Length; i++)
     {
         result[i] = ToPoint(pnts[i]);
     }
     return result;
 }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         *
         * @param point
         */
        public virtual void MoveTo(PointFP point)
        {
            if (!_started)
            {
                _startPoint.Reset(point);
                _started = true;
            }
            _currPoint.Reset(point);
        }
Exemple #8
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         *
         * @param point
         */
        public override void MoveTo(PointFP point)
        {
            _transformedPoint = new PointFP(point);
            if (_transformMatrix != null)
            {
                _transformedPoint.Transform(_transformMatrix);
            }
            base.MoveTo(point);
        }
        private static PointFP CalcControlPoint(PointFP p1, PointFP p2,
                                                PointFP p3, int ffFactor)
        {
            var ps = new PointFP(p2.X + MathFP.Mul(p2.X - p1.X, ffFactor),
                                 p2.Y + MathFP.Mul(p2.Y - p1.Y, ffFactor));

            return(new LineFP((new LineFP(p2, ps)).GetCenter(),
                              (new LineFP(p2, p3)).GetCenter()).GetCenter());
        }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * @inheritDoc
         * @param x the x coordinate
         * @param y the y coordinate
         * @param singlePoint
         * @return the color at given position.
         */
        public override int GetColorAt(int x, int y, bool singlePoint)
        {
            var p = new PointFP(x << SingleFP.DECIMAL_BITS,
                                y << SingleFP.DECIMAL_BITS);
            PointFP p1 = null;

            if (!singlePoint)
            {
                p1 = new PointFP(p.X + SingleFP.ONE, p.Y);
            }
            if (_finalMatrix != null)
            {
                p.Transform(_finalMatrix);
                if (!singlePoint)
                {
                    p1.Transform(_finalMatrix);
                }
            }
            //int width = bounds.getWidth();
            //int height = bounds.getHeight();

            var v = p.X + _ffLength / 2;

            _ffCurrpos = (int)(((long)v << RATIO_BITS + SingleFP.DECIMAL_BITS)
                               / _ffLength);
            if (!singlePoint)
            {
                _ffDeltapos = (int)(((long)(p1.X - p.X)
                                     << RATIO_BITS + SingleFP.DECIMAL_BITS) / _ffLength);
            }
            int pos = _ffCurrpos >> SingleFP.DECIMAL_BITS;

            pos -= 512;

            //pos >>= Brush.XY_MAX_BITS - RATIO_BITS;

            switch (FillMode)
            {
            case REFLECT:
                pos = pos % (RATIO_MAX * 2);
                pos = pos < 0 ? pos + RATIO_MAX * 2 : pos;
                pos = (pos < RATIO_MAX) ? pos : RATIO_MAX * 2 - pos;
                break;

            case REPEAT:
                pos = pos % RATIO_MAX;
                pos = pos < 0 ? pos + RATIO_MAX : pos;
                break;

            case NO_CYCLE:
                pos = pos < 0 ? 0 : (pos > RATIO_MAX ? RATIO_MAX : pos);
                break;
            }

            return(_gradientColors[pos]);
        }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * Create a smooth curve from given parameters.
         * @param points
         * @param offset
         * @param numberOfSegments
         * @param ff_factor
         * @param closed
         * @return
         */
        public static GraphicsPathFP CreateSmoothCurves(PointFP[] points,
                                                        int offset, int numberOfSegments, int ffFactor, bool closed)
        {
            var len  = points.Length;
            var path = new GraphicsPathFP();

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

            var pc1S = new PointFP[points.Length];
            var 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], ffFactor);
                pc2S[0] = CalcControlPoint(points[1], points[0],
                                           points[len - 1], ffFactor);
                pc1S[len - 1] = CalcControlPoint(points[len - 2], points[len - 1],
                                                 points[0], ffFactor);
                pc2S[len - 1] = CalcControlPoint(points[0], points[len - 1],
                                                 points[len - 2], ffFactor);
            }
            for (var i = 1; i < len - 1; i++)
            {
                pc1S[i] = CalcControlPoint(points[i - 1], points[i],
                                           points[i + 1], ffFactor);
                pc2S[i] = CalcControlPoint(points[i + 1], points[i],
                                           points[i - 1], ffFactor);
            }

            path.AddMoveTo(points[offset]);
            for (var 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);
        }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * Add curve to.
         * @param control
         * @param point
         */
        public void AddQuadTo(PointFP control, PointFP point)
        {
            if (control.Equals(point))
            {
                AddLineTo(point);
                return;
            }
            ExtendIfNeeded(1, 2);
            _cmds[_cmdsSize++] = CMD_QCURVETO;
            _pnts[_pntsSize++] = new PointFP(control);
            _pnts[_pntsSize++] = new PointFP(point);
        }
 static GraphicsPathFP()
 {
     ONE = SingleFP.ONE;
     ROUNDCAP[0] = new PointFP(25080, 60547);
     ROUNDCAP[1] = new PointFP(46341, 46341);
     ROUNDCAP[2] = new PointFP(60547, 25080);
     ROUNDCAP[3] = new PointFP(ONE, 0);
     ROUNDCAP[4] = new PointFP(60547, -25080);
     ROUNDCAP[5] = new PointFP(46341, -46341);
     ROUNDCAP[6] = new PointFP(25080, -60547);
     SQUARECAP[0] = new PointFP(ONE, ONE);
     SQUARECAP[1] = new PointFP(ONE, -ONE);
 }
 static GraphicsPathFP()
 {
     ONE          = SingleFP.ONE;
     ROUNDCAP[0]  = new PointFP(25080, 60547);
     ROUNDCAP[1]  = new PointFP(46341, 46341);
     ROUNDCAP[2]  = new PointFP(60547, 25080);
     ROUNDCAP[3]  = new PointFP(ONE, 0);
     ROUNDCAP[4]  = new PointFP(60547, -25080);
     ROUNDCAP[5]  = new PointFP(46341, -46341);
     ROUNDCAP[6]  = new PointFP(25080, -60547);
     SQUARECAP[0] = new PointFP(ONE, ONE);
     SQUARECAP[1] = new PointFP(ONE, -ONE);
 }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * Add a path to this path.
         * @param path
         */
        public void AddPath(GraphicsPathFP path)
        {
            if (path._cmdsSize > 0)
            {
                ExtendIfNeeded(path._cmdsSize, path._pntsSize);
                Array.Copy(path._cmds, 0, _cmds, _cmdsSize, path._cmdsSize);
                for (int i = 0; i < path._pntsSize; i++)
                {
                    _pnts[i + _pntsSize] = new PointFP(path._pnts[i]);
                }
                _cmdsSize += path._cmdsSize;
                _pntsSize += path._pntsSize;
            }
        }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * Copy constructor.
         * @param from the one to be copied.
         */
        public GraphicsPathFP(GraphicsPathFP from)
        {
            _cmdsSize = from._cmdsSize;
            _pntsSize = from._pntsSize;
            if (_cmdsSize > 0)
            {
                _cmds = new int[_cmdsSize];
                _pnts = new PointFP[_pntsSize];
                Array.Copy(from._cmds, 0, _cmds, 0, _cmdsSize);
                for (int i = 0; i < _pntsSize; i++)
                {
                    _pnts[i] = new PointFP(from._pnts[i]);
                }
            }
        }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * Constructor.
         * @param from  the path which need to be dashed.
         * @param dashArray the dash array.
         * @param offset  from where the dash starts.
         */
        public GraphicsPathDasherFP(GraphicsPathFP from, int[] dashArray, int offset)
        {
            _fromPath = new GraphicsPathFP(from);
            var arrayLength = dashArray.Length - offset;

            if (arrayLength > 1)
            {
                _pnts      = new PointFP[BLOCKSIZE];
                _cmds      = new int[BLOCKSIZE];
                _dashArray = new int[dashArray.Length - offset];
                Array.Copy(dashArray, offset,
                           _dashArray, 0, dashArray.Length);
                VisitPath(this);
            }
        }
Exemple #18
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 09NOV2008  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         *
         * @param point
         */
        public override void LineTo(PointFP point)
        {
            var pntTemp = new PointFP(point);

            _ffXmin = MathFP.Min(_ffXmin, CurrentPoint().X);
            _ffXmax = MathFP.Max(_ffXmax, point.X);
            _ffYmin = MathFP.Min(_ffYmin, CurrentPoint().Y);
            _ffYmax = MathFP.Max(_ffYmax, point.Y);

            if (_transformMatrix != null)
            {
                pntTemp.Transform(_transformMatrix);
            }

            Scanline(_transformedPoint.X, _transformedPoint.Y, pntTemp.X, pntTemp.Y);
            _transformedPoint = pntTemp;
            base.LineTo(point);
        }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         *
         * @param control1
         * @param control2
         * @param point
         */
        public void AddCurveTo(PointFP control1, PointFP control2, PointFP point)
        {
            if (_pnts[_pntsSize - 1].Equals(control1))
            {
                AddQuadTo(control2, point);
                return;
            }
            if (point.Equals(control2))
            {
                AddQuadTo(control1, point);
                return;
            }
            ExtendIfNeeded(1, 3);
            _cmds[_cmdsSize++] = CMD_CCURVETO;
            _pnts[_pntsSize++] = new PointFP(control1);
            _pnts[_pntsSize++] = new PointFP(control2);
            _pnts[_pntsSize++] = new PointFP(point);
        }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * Create the gradient brush.
         * @param ff_xmin the top left coordinate.
         * @param ff_ymin the top left coordinate.
         * @param ff_xmax the bottom right coordinate.
         * @param ff_ymax the bottom right coordinate.
         * @param ff_angle the angle for this gradient.
         * @param type  the type of the gradient brush.
         */
        public LinearGradientBrushFP(int ffXmin, int ffYmin, int ffXmax, int ffYmax,
                                     int ffAngle)
        {
            _bounds.Reset(ffXmin, ffYmin,
                          ffXmax == ffXmin ? ffXmin + 1 : ffXmax,
                          ffYmax == ffYmin ? ffYmin + 1 : ffYmax);
            _matrix = new MatrixFP();
            _centerPt.Reset(ffXmin + (ffXmax - ffXmin) / 2,
                            ffYmin + (ffYmax - ffYmin) / 2);
            _matrix.Translate(-_centerPt.X, -_centerPt.Y);
            _matrix.Rotate(-ffAngle);
            //matrix.translate((ff_xmin + ff_xmax) / 2,(ff_ymin + ff_ymax) / 2);

            var ffAng = MathFP.Atan(MathFP.Div(_bounds.GetHeight(),
                                               _bounds.GetWidth() == 0 ? 1 : _bounds.GetWidth()));
            var ffLen = PointFP.Distance(_bounds.GetHeight(), _bounds.GetWidth());

            _ffLength = MathFP.Mul(ffLen, MathFP.Max(
                                       MathFP.Abs(MathFP.Cos(ffAngle - ffAng)),
                                       MathFP.Abs(MathFP.Cos(ffAngle + ffAng))));
        }
Exemple #21
0
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 09NOV2008  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * @inheritDoc
         * @param x the x coordinate
         * @param y the y coordinate
         * @param singlePoint
         * @return the color at given position.
         */
        public override int GetColorAt(int x, int y, bool singlePoint)
        {
            var p = new PointFP(x << SingleFP.DECIMAL_BITS,
                                y << SingleFP.DECIMAL_BITS);

            _nextPt.X = p.X + SingleFP.ONE;
            _nextPt.Y = p.Y;
            var newCenterPt = new PointFP(_centerPt);

            if (_finalMatrix != null)
            {
                p.Transform(_finalMatrix);
                //newCenterPt.transform(finalMatrix);
            }
            _ffCurrpos = MathFP.Div(PointFP.Distance(p.X - newCenterPt.X,
                                                     p.Y - newCenterPt.Y), _ffRadius);
            var pos = _ffCurrpos >> SingleFP.DECIMAL_BITS - RATIO_BITS;

            switch (FillMode)
            {
            case REFLECT:
                pos = pos % (RATIO_MAX * 2);
                pos = pos < 0 ? pos + RATIO_MAX * 2 : pos;
                pos = (pos < RATIO_MAX) ? pos : RATIO_MAX * 2 - pos;
                break;

            case REPEAT:
                pos = pos % RATIO_MAX;
                pos = pos < 0 ? pos + RATIO_MAX : pos;
                break;

            case NO_CYCLE:
                pos = pos < 0 ? 0 : (pos > RATIO_MAX ? RATIO_MAX : pos);
                break;
            }

            return(_gradientColors[pos]);
        }
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 13JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * Add curve to.
  * @param control
  * @param point
  */
 public void AddQuadTo(PointFP control, PointFP point)
 {
     if (control.Equals(point))
     {
         AddLineTo(point);
         return;
     }
     ExtendIfNeeded(1, 2);
     _cmds[_cmdsSize++] = CMD_QCURVETO;
     _pnts[_pntsSize++] = new PointFP(control);
     _pnts[_pntsSize++] = new PointFP(point);
 }
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 13JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  *
  * @param point
  */
 public virtual void MoveTo(PointFP point)
 {
     if (!_started)
     {
         _startPoint.Reset(point);
         _started = true;
     }
     _currPoint.Reset(point);
 }
Exemple #24
0
 public static Point ToPoint(PointFP pnt)
 {
     return new Point(SingleFP.ToInt(pnt.X), SingleFP.ToInt(pnt.Y));
 }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                 	          Initial Creation
        ////////////////////////////////////////////////////////////////////////////
        /**
         * @inheritDoc
         * @return next color of the gradient brush.
         */
        public override int GetNextColor()
        {
            var p = new PointFP(_nextPt);
            _nextPt.X = p.X + SingleFP.ONE;
            _nextPt.Y = p.Y;
            var newCenterPt = new PointFP(_centerPt);
            if (_finalMatrix != null)
            {
                p.Transform(_finalMatrix);
                //newCenterPt.transform(finalMatrix);

            }
            _ffCurrpos = MathFP.Div(PointFP.Distance(p.X - newCenterPt.X,
                    p.Y - newCenterPt.Y), _ffRadius);
            var pos = _ffCurrpos >> SingleFP.DECIMAL_BITS - RATIO_BITS;

            switch (FillMode)
            {
                case REFLECT:
                    pos = pos % (RATIO_MAX * 2);
                    pos = pos < 0 ? pos + RATIO_MAX * 2 : pos;
                    pos = (pos < RATIO_MAX) ? pos : RATIO_MAX * 2 - pos;
                    break;
                case REPEAT:
                    pos = pos % RATIO_MAX;
                    pos = pos < 0 ? pos + RATIO_MAX : pos;
                    break;
                case NO_CYCLE:
                    pos = pos < 0 ? 0 : (pos > RATIO_MAX ? RATIO_MAX : pos);
                    break;
            }

            return _gradientColors[pos];
        }
 private void AddMoveTo(PointFP point)
 {
     _cmds[_cmdsSize++] = CMD_MOVETO;
     _pnts[_pntsSize++] = new PointFP(point);
 }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                 	          Initial Creation
        ////////////////////////////////////////////////////////////////////////////
        /**
         * @inheritDoc
         * @param x the x coordinate
         * @param y the y coordinate
         * @param singlePoint  single point
         * @return the color Value at given location.
         */
        public override int GetColorAt(int x, int y, bool singlePoint)
        {
            var p = new PointFP(x << SingleFP.DECIMAL_BITS,
                    y << SingleFP.DECIMAL_BITS);
            _nextPt.X = p.X + SingleFP.ONE;
            _nextPt.Y = p.Y;
            if (_finalMatrix != null)
            {
                p.Transform(_finalMatrix);

            }
            var xPos = (p.X >> SingleFP.DECIMAL_BITS) % _width;
            var yPos = (p.Y >> SingleFP.DECIMAL_BITS) % _height;

            if (xPos < 0) xPos += _width;
            if (yPos < 0) yPos += _height;

            return _textureBuffer[(xPos + yPos * _width)];
        }
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 13JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * Create a polygon path.
  * @param points
  * @return
  */
 public static GraphicsPathFP CreatePolygon(PointFP[] points)
 {
     var path = CreatePolyline(points);
     if (points.Length > 0)
     {
         path.AddClose();
     }
     return path;
 }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                 	          Initial Creation
        ////////////////////////////////////////////////////////////////////////////
        public virtual void CurveTo(PointFP control1, PointFP control2, PointFP point)
        {
            var tmp1 = new PointFP(_currPoint.X - control1.X * 2 + control2.X,
                    _currPoint.Y - control1.Y * 2 + control2.Y);
            var tmp2 = new PointFP((control1.X - control2.X) * 3 - _currPoint.X
                    + point.X, (control1.Y - control2.Y) * 3 - _currPoint.Y + point.Y);

            var f = new PointFP(_currPoint);
            var df = new PointFP((control1.X - _currPoint.X) * 3 / SUBDIVIDE
                    + tmp1.X * 3 / SUBDIVIDE2 + tmp2.X / SUBDIVIDE3,
                    (control1.Y - _currPoint.Y) * 3 / SUBDIVIDE + tmp1.Y * 3
                    / SUBDIVIDE2 + tmp2.Y / SUBDIVIDE3);
            var ddf = new PointFP(tmp1.X * 6 / SUBDIVIDE2 + tmp2.X * 6
                    / SUBDIVIDE3, tmp1.Y * 6 / SUBDIVIDE2 + tmp2.Y * 6 / SUBDIVIDE3);
            var dddf = new PointFP(tmp2.X * 6
                    / SUBDIVIDE3, tmp2.Y * 6 / SUBDIVIDE3);

            for (var c = 0; c < SUBDIVIDE - 1; c++)
            {
                f.Add(df);
                df.Add(ddf);
                ddf.Add(dddf);
                LineTo(f);
            }

            LineTo(point);
        }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                 	          Initial Creation
        ////////////////////////////////////////////////////////////////////////////
        /**
         *
         * @param control
         * @param point
         */
        public virtual void QuadTo(PointFP control, PointFP point)
        {
            // Compute forward difference values for a quadratic
            // curve of type A*(1-t)^2 + 2*B*t*(1-t) + C*t^2

            var f = new PointFP(_currPoint);
            var tmp = new PointFP((_currPoint.X - control.X * 2 + point.X)
                    / SUBDIVIDE2, (_currPoint.Y - control.Y * 2 + point.Y)
                    / SUBDIVIDE2);
            var ddf = new PointFP(tmp.X * 2, tmp.Y * 2);
            var df = new PointFP(tmp.X + (control.X - _currPoint.X) * 2
                    / SUBDIVIDE, tmp.Y + (control.Y - _currPoint.Y) * 2 / SUBDIVIDE);

            for (int c = 0; c < SUBDIVIDE - 1; c++)
            {
                f.Add(df);
                df.Add(ddf);
                LineTo(f);
            }

            // We specify the last point manually since
            // we obtain rounding errors during the
            // forward difference computation.
            LineTo(point);
        }
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 13JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * Copy constructor.
  * @param from the one to be copied.
  */
 public GraphicsPathFP(GraphicsPathFP from)
 {
     _cmdsSize = from._cmdsSize;
     _pntsSize = from._pntsSize;
     if (_cmdsSize > 0)
     {
         _cmds = new int[_cmdsSize];
         _pnts = new PointFP[_pntsSize];
         Array.Copy(from._cmds, 0, _cmds, 0, _cmdsSize);
         for (int i = 0; i < _pntsSize; i++)
         {
             _pnts[i] = new PointFP(from._pnts[i]);
         }
     }
 }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                 	          Initial Creation
        ////////////////////////////////////////////////////////////////////////////
        /**
         * @inheritDoc
         * @return next color.
         */
        public override int GetNextColor()
        {
            var p = new PointFP(_nextPt);

            _nextPt.X += SingleFP.ONE;
            _nextPt.Y = p.Y;

            if (_finalMatrix != null)
            {
                p.Transform(_finalMatrix);

            }
            var xPos = (p.X >> SingleFP.DECIMAL_BITS) % _width;
            var yPos = (p.Y >> SingleFP.DECIMAL_BITS) % _height;

            if (xPos < 0) xPos += _width;
            if (yPos < 0) yPos += _height;

            return _textureBuffer[xPos + yPos * _width];
        }
 private void AddMoveTo(PointFP point)
 {
     _cmds[_cmdsSize++] = CMD_MOVETO;
     _pnts[_pntsSize++] = new PointFP(point);
 }
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 13JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * @inheritDoc
  * @param point
  */
 public override void MoveTo(PointFP point)
 {
     base.MoveTo(point);
     ExtendIfNeeded(1, 1);
     AddMoveTo(point);
 }
 private static PointFP CalcControlPoint(PointFP p1, PointFP p2,
         PointFP p3, int ffFactor)
 {
     var ps = new PointFP(p2.X + MathFP.Mul(p2.X - p1.X, ffFactor),
             p2.Y + MathFP.Mul(p2.Y - p1.Y, ffFactor));
     return new LineFP((new LineFP(p2, ps)).GetCenter(),
             (new LineFP(p2, p3)).GetCenter()).GetCenter();
 }
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- 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
 ////////////////////////////////////////////////////////////////////////////
 /**
  *
  * @param point
  */
 public virtual void LineTo(PointFP point)
 {
     _currPoint.Reset(point);
 }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                 	          Initial Creation
        ////////////////////////////////////////////////////////////////////////////
        /**
         * Create a smooth curve from given parameters.
         * @param points
         * @param offset
         * @param numberOfSegments
         * @param ff_factor
         * @param closed
         * @return
         */
        public static GraphicsPathFP CreateSmoothCurves(PointFP[] points,
                int offset, int numberOfSegments, int ffFactor, bool closed)
        {
            var len = points.Length;
            var path = new GraphicsPathFP();

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

            var pc1S = new PointFP[points.Length];
            var 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], ffFactor);
                pc2S[0] = CalcControlPoint(points[1], points[0],
                        points[len - 1], ffFactor);
                pc1S[len - 1] = CalcControlPoint(points[len - 2], points[len - 1],
                        points[0], ffFactor);
                pc2S[len - 1] = CalcControlPoint(points[0], points[len - 1],
                        points[len - 2], ffFactor);
            }
            for (var i = 1; i < len - 1; i++)
            {
                pc1S[i] = CalcControlPoint(points[i - 1], points[i],
                        points[i + 1], ffFactor);
                pc2S[i] = CalcControlPoint(points[i + 1], points[i],
                        points[i - 1], ffFactor);
            }

            path.AddMoveTo(points[offset]);
            for (var 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;
        }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 11NOV2008  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * @inheritDoc
         * @param point
         */
        public override void LineTo(PointFP point)
        {
            base.LineTo(point);
            ExtendIfNeeded(1, 1);
            AddLineTo(point);
        }
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 13JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  *
  * @param control1
  * @param control2
  * @param point
  */
 public void AddCurveTo(PointFP control1, PointFP control2, PointFP point)
 {
     if (_pnts[_pntsSize - 1].Equals(control1))
     {
         AddQuadTo(control2, point);
         return;
     }
     if (point.Equals(control2))
     {
         AddQuadTo(control1, point);
         return;
     }
     ExtendIfNeeded(1, 3);
     _cmds[_cmdsSize++] = CMD_CCURVETO;
     _pnts[_pntsSize++] = new PointFP(control1);
     _pnts[_pntsSize++] = new PointFP(control2);
     _pnts[_pntsSize++] = new PointFP(point);
 }
 private void AddLineTo(PointFP point)
 {
     _cmds[_cmdsSize++] = CMD_LINETO;
     _pnts[_pntsSize++] = new PointFP(point);
 }
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 13JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * add move to this path.
  * @param point
  */
 public void AddMoveTo(PointFP point)
 {
     ExtendIfNeeded(1, 1);
     _cmds[_cmdsSize++] = CMD_MOVETO;
     _pnts[_pntsSize++] = new PointFP(point);
 }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         * Add line to this path.
         * @param point
         */
        public void AddLineTo(PointFP point)
        {
            ExtendIfNeeded(1, 1);
            _cmds[_cmdsSize++] = CMD_LINETO;
            _pnts[_pntsSize++] = new PointFP(point);
        }
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 13JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  * Add a path to this path.
  * @param path
  */
 public void AddPath(GraphicsPathFP path)
 {
     if (path._cmdsSize > 0)
     {
         ExtendIfNeeded(path._cmdsSize, path._pntsSize);
         Array.Copy(path._cmds, 0, _cmds, _cmdsSize, path._cmdsSize);
         for (int i = 0; i < path._pntsSize; i++)
         {
             _pnts[i + _pntsSize] = new PointFP(path._pnts[i]);
         }
         _cmdsSize += path._cmdsSize;
         _pntsSize += path._pntsSize;
     }
 }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 09NOV2008  James Shen                 	          Initial Creation
        ////////////////////////////////////////////////////////////////////////////
        /**
         *
         * @param point
         */
        public override void LineTo(PointFP point)
        {
            var pntTemp = new PointFP(point);

            _ffXmin = MathFP.Min(_ffXmin, CurrentPoint().X);
            _ffXmax = MathFP.Max(_ffXmax, point.X);
            _ffYmin = MathFP.Min(_ffYmin, CurrentPoint().Y);
            _ffYmax = MathFP.Max(_ffYmax, point.Y);

            if (_transformMatrix != null)
            {
                pntTemp.Transform(_transformMatrix);
            }

            Scanline(_transformedPoint.X, _transformedPoint.Y, pntTemp.X, pntTemp.Y);
            _transformedPoint = pntTemp;
            base.LineTo(point);
        }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                              Initial Creation
        ////////////////////////////////////////////////////////////////////////////

        /**
         *
         * @param point
         */
        public virtual void LineTo(PointFP point)
        {
            _currPoint.Reset(point);
        }
 private void AddLineTo(PointFP point)
 {
     _cmds[_cmdsSize++] = CMD_LINETO;
     _pnts[_pntsSize++] = new PointFP(point);
 }
 ////////////////////////////////////////////////////////////////////////////
 //--------------------------------- REVISIONS ------------------------------
 // Date       Name                 Tracking #         Description
 // ---------  -------------------  -------------      ----------------------
 // 13JUN2009  James Shen                 	          Initial Creation
 ////////////////////////////////////////////////////////////////////////////
 /**
  *
  * @param point
  */
 public override void MoveTo(PointFP point)
 {
     _transformedPoint = new PointFP(point);
     if (_transformMatrix != null)
     {
         _transformedPoint.Transform(_transformMatrix);
     }
     base.MoveTo(point);
 }
        private void ExtendIfNeeded(int cmdsAddNum, int pntsAddNum)
        {
            if (_cmds == null)
            {
                _cmds = new int[BLOCKSIZE];
            }
            if (_pnts == null)
            {
                _pnts = new PointFP[BLOCKSIZE];
            }

            if (_cmdsSize + cmdsAddNum > _cmds.Length)
            {
                var newdata = new int[_cmds.Length + (cmdsAddNum > BLOCKSIZE
                        ? cmdsAddNum : BLOCKSIZE)];
                if (_cmdsSize > 0)
                {
                    Array.Copy(_cmds, 0, newdata, 0, _cmdsSize);
                }
                _cmds = newdata;
            }
            if (_pntsSize + pntsAddNum > _pnts.Length)
            {
                var newdata = new PointFP[_pnts.Length +
                        (pntsAddNum > BLOCKSIZE ? pntsAddNum : BLOCKSIZE)];
                if (_pntsSize > 0)
                {
                    Array.Copy(_pnts, 0, newdata, 0, _pntsSize);
                }
                _pnts = newdata;
            }
        }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- REVISIONS ------------------------------
        // Date       Name                 Tracking #         Description
        // ---------  -------------------  -------------      ----------------------
        // 13JUN2009  James Shen                 	          Initial Creation
        ////////////////////////////////////////////////////////////////////////////
        /**
         * @inheritDoc
         * @param x the x coordinate
         * @param y the y coordinate
         * @param singlePoint
         * @return the color at given position.
         */
        public override int GetColorAt(int x, int y, bool singlePoint)
        {
            var p = new PointFP(x << SingleFP.DECIMAL_BITS,
                    y << SingleFP.DECIMAL_BITS);
            PointFP p1 = null;
            if (!singlePoint)
            {
                p1 = new PointFP(p.X + SingleFP.ONE, p.Y);
            }
            if (_finalMatrix != null)
            {
                p.Transform(_finalMatrix);
                if (!singlePoint)
                {
                    p1.Transform(_finalMatrix);
                }
            }
            //int width = bounds.getWidth();
            //int height = bounds.getHeight();

            var v = p.X + _ffLength / 2;
            _ffCurrpos = (int)(((long)v << RATIO_BITS + SingleFP.DECIMAL_BITS)
                    / _ffLength);
            if (!singlePoint)
            {
                _ffDeltapos = (int)(((long)(p1.X - p.X)
                        << RATIO_BITS + SingleFP.DECIMAL_BITS) / _ffLength);
            }
            int pos = _ffCurrpos >> SingleFP.DECIMAL_BITS;
            pos -= 512;

            //pos >>= Brush.XY_MAX_BITS - RATIO_BITS;

            switch (FillMode)
            {
                case REFLECT:
                    pos = pos % (RATIO_MAX * 2);
                    pos = pos < 0 ? pos + RATIO_MAX * 2 : pos;
                    pos = (pos < RATIO_MAX) ? pos : RATIO_MAX * 2 - pos;
                    break;
                case REPEAT:
                    pos = pos % RATIO_MAX;
                    pos = pos < 0 ? pos + RATIO_MAX : pos;
                    break;
                case NO_CYCLE:
                    pos = pos < 0 ? 0 : (pos > RATIO_MAX ? RATIO_MAX : pos);
                    break;
            }

            return _gradientColors[pos];
        }