Esempio n. 1
0
        public virtual void FillRectangle(int x1, int y1, int x2, int y2, Color color)
        {
            int _x1 = x1;
            int _y1 = y1;
            int _x2 = x2;
            int _y2 = y2;

            if (_x1 > _x2)
            {
                _x1 = x2;
                _x2 = x1;
            }
            if (_y1 > _y2)
            {
                _y1 = y2;
                _y2 = y1;
            }

            pixelBuffer.SetSubBuffer(color, _x1, _y1, _x2 - _x1, _y2 - _y1);
        }
Esempio n. 2
0
        private unsafe PixelBuffer GetSubBufferOutside(int x, int y, int width, int height)
        {
            PixelBuffer retBuff = new PixelBuffer(width, height);

            int sx = x;
            int sy = y;
            int sw = width;
            int sh = height;

            if (x < 0)
            {
                sx  = 0;
                sw += x;
            }
            else if ((x + width) > _width)
            {
                sw = _width - x;
            }

            if (y < 0)
            {
                sy  = 0;
                sh += y;
            }
            else if ((y + height) > _height)
            {
                sh = _height - y;
            }

            if (sw <= 0 || sh <= 0)
            {
                return(new PixelBuffer(width, height));
            }

            int defaultColor = 0;

            fixed(int *src = _buffer)
            {
                int index = this.GetPixelBytesIndex(sx, sy, _width);

                defaultColor = this.GetPixelColorByIndex(src, index);
            }

            fixed(int *dest = retBuff.InternalBuffer)
            {
                retBuff.SetBufferColor(dest, defaultColor);
            }

            using (PixelBuffer subBuff = this.GetSubBuffer(sx, sy, sw, sh))
            {
                int fx = 0;
                int fy = 0;
                if (x < 0)
                {
                    fx = -x;
                }
                if (y < 0)
                {
                    fy = -y;
                }

                retBuff.SetSubBuffer(subBuff, fx, fy);
            }

            return(retBuff);
        }