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

        /**
         *
         * @param ff_sx
         * @param ff_sy
         * @param ff_ex
         * @param ff_ey
         */
        private void Scanline(int ffSx, int ffSy, int ffEx, int ffEy)
        {
            var sx   = ffSx >> (SingleFP.DECIMAL_BITS - RENDERER_FRAC_X);
            var ex   = ffEx >> (SingleFP.DECIMAL_BITS - RENDERER_FRAC_X);
            var sy   = (ffSy * RENDERER_FRAC_Y) >> SingleFP.DECIMAL_BITS;
            var ey   = (ffEy * RENDERER_FRAC_Y) >> SingleFP.DECIMAL_BITS;
            var xmin = MathFP.Min(sx, ex);
            var xmax = MathFP.Max(sx, ex);
            var ymin = MathFP.Min(sy, ey);
            var ymax = MathFP.Max(sy, ey);
            var incx = ffSx < ffEx && ffSy < ffEy || ffSx >= ffEx &&
                       ffSy >= ffEy ? 1 : -1;
            var x    = incx == 1 ? xmin : xmax;
            var dire = ffSy < ffEy ? 1 : 0;

            if (((ymin < 0) && (ymax < 0)) || ((ymin >= (_height * RENDERER_FRAC_Y)) &&
                                               (ymax >= (_height * RENDERER_FRAC_Y))))
            {
                return;
            }

            var n = MathFP.Abs(xmax - xmin);
            var d = MathFP.Abs(ymax - ymin);
            var i = d;

            ymax = MathFP.Min(ymax, _height * RENDERER_FRAC_Y);

            for (var y = ymin; y < ymax; y++)
            {
                if (y >= 0)
                {
                    if (_scanIndex >= Scanbuf.Length)
                    {
                        var bufSize = _scanIndex / BUFFERSIZE;
                        if ((_scanIndex + 1) % BUFFERSIZE != 0)
                        {
                            bufSize += 1;
                        }
                        ScanbufTmp = new int[bufSize * BUFFERSIZE];
                        Array.Copy(Scanbuf, 0, ScanbufTmp, 0, _scanIndex);
                        Scanbuf = new int[bufSize * BUFFERSIZE];
                        Array.Copy(ScanbufTmp, 0, Scanbuf, 0, _scanIndex);
                    }
                    Scanbuf[_scanIndex++] = ((y / RENDERER_FRAC_Y)
                                             << (RENDERER_REAL_X + RENDERER_FRAC_X + 1))
                                            | (MathFP.Max(0, MathFP.Min((_width *
                                                                         RENDERER_FRAC_X_FACTOR) - 1, x)) << 1) | dire;
                }
                i += n;
                if (i > d)
                {
                    var idivd = (i - 1) / d;
                    x += incx * idivd;
                    i -= d * idivd;
                }
            }
        }
        ////////////////////////////////////////////////////////////////////////////
        //--------------------------------- 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);
        }
Beispiel #3
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);
        }
Beispiel #4
0
        private void DrawBuffer()
        {
            var curd  = 0;
            var cure  = 0;
            var cura  = 0;
            var cula  = 0;
            var cury  = 0;
            var curx  = 0;
            var count = _scanIndex;

            for (int c = 0; c <= count; c++)
            {
                var curs = c == count ? 0 : Scanbuf[c];

                var newy = ((curs >> (RENDERER_REAL_X + RENDERER_FRAC_X + 1))
                            & RENDERER_REAL_Y_MASK);
                var newx = ((curs >> (RENDERER_FRAC_X + 1)) & RENDERER_REAL_X_MASK);
                if ((newx != curx) || (newy != cury))
                {
                    var alp = (256 * cure) / (RENDERER_FRAC_Y)+
                              (256 * cula) / (RENDERER_FRAC_Y
                                              * (RENDERER_FRAC_X_FACTOR - 1)) +
                              (256 * cura) / (RENDERER_FRAC_Y
                                              * (RENDERER_FRAC_X_FACTOR - 1));
                    if (alp != 0)
                    {
                        if (_drawMode == MODE_XOR)
                        {
                            alp = (alp & 0x100) != 0
                                    ? (0xFF - (alp & 0xFF)) : (alp & 0xFF);
                        }
                        else
                        {
                            alp = MathFP.Min(255, MathFP.Abs(alp));
                        }
                        if (alp != 0)
                        {
                            MergePixels(curx, cury, 1, alp);
                        }
                    }
                    cure = curd;

                    if (newy == cury)
                    {
                        if (curd != 0)
                        {
                            alp = (256 * curd) / RENDERER_FRAC_Y;
                            if (alp != 0)
                            {
                                if (_drawMode == MODE_XOR)
                                {
                                    alp = (alp & 0x100) != 0
                                            ? (0xFF - (alp & 0xFF)) : (alp & 0xFF);
                                }
                                else
                                {
                                    alp = MathFP.Min(255, MathFP.Abs(alp));
                                }
                                if (alp != 0)
                                {
                                    MergePixels(curx + 1, cury, newx - curx - 1, alp);
                                }
                            }
                        }
                    }
                    else
                    {
                        cury = newy;
                        curd = cure = 0;
                    }

                    curx = newx;
                    cura = cula = 0;
                }

                if ((curs & 1) != 0)
                {
                    curd++;
                    cula += ((~(curs >> 1)) & RENDERER_FRAC_X_MASK);
                }
                else
                {
                    curd--;
                    cura -= ((~(curs >> 1)) & RENDERER_FRAC_X_MASK);
                }
            }
        }