Esempio n. 1
0
        public byte[] getPixels()
        {
            var numOfPixels   = getWidth() * getHeight();
            var bytesPerPixel = getBytesPerPixel(_format);

            var bytes = new byte[numOfPixels * bytesPerPixel];

            for (int currentPixel = 0; currentPixel < numOfPixels; currentPixel++)
            {
                var convertedPixel = MonoGameColor.convertTo(_format, getPixel(currentPixel));
                switch (bytesPerPixel)
                {
                case 4:
                    bytes[(bytesPerPixel * currentPixel) + bytesPerPixel - 4] = (byte)(convertedPixel >> 24 & 0xff);
                    goto case 3;     //because c# doesn't support switch fallthrough

                case 3:
                    bytes[(bytesPerPixel * currentPixel) + bytesPerPixel - 3] = (byte)(convertedPixel >> 16 & 0xff);
                    goto case 2;     //because c# doesn't support switch fallthrough

                case 2:
                    bytes[(bytesPerPixel * currentPixel) + bytesPerPixel - 2] = (byte)(convertedPixel >> 8 & 0xff);
                    goto case 1;     //because c# doesn't support switch fallthrough

                case 1:
                    bytes[(bytesPerPixel * currentPixel) + bytesPerPixel - 1] = (byte)(convertedPixel & 0xff);
                    break;

                default:
                    return(null);
                }
            }

            return(bytes);
        }
Esempio n. 2
0
 public void setColor(float r, float g, float b, float a)
 {
     _currentColor = (MonoGameColor)_currentColor.copy();
     _currentColor.setR(r);
     _currentColor.setG(g);
     _currentColor.setB(b);
     _currentColor.setA(a);
 }
Esempio n. 3
0
 public void setColor(Color tint)
 {
     _currentColor = (MonoGameColor)_currentColor.copy();
     _currentColor.setR(tint.rf());
     _currentColor.setG(tint.gf());
     _currentColor.setB(tint.bf());
     _currentColor.setA(tint.af());
 }
Esempio n. 4
0
 public MonoGamePixmap(int width, int height, PixmapFormat format)
 {
     _width    = width;
     _height   = height;
     _pixmap   = new UInt32[width, height];
     _setColor = new MonoGameColor(0, 0, 0, 255);
     _blending = PixmapBlending.NONE;
     _filter   = PixmapFilter.NEAREST_NEIGHBOUR;
     _format   = format;
 }
Esempio n. 5
0
        public void drawPixmap(Pixmap pixmap, int srcX, int srcY, int srcWidth, int srcHeight, int dstX, int dstY, int dstWidth, int dstHeight)
        {
            if (srcWidth == dstWidth && srcHeight == dstHeight)
            {
                for (var x = 0; x < srcWidth; x++)
                {
                    for (var y = 0; y < srcHeight; y++)
                    {
                        drawPixel(dstX + x, dstY + y, (uint)pixmap.getPixel(srcX + x, srcY + y));
                    }
                }
            }
            else if (_filter == PixmapFilter.NEAREST_NEIGHBOUR)
            {
                var xRatio = (float)srcWidth / dstWidth;
                var yRatio = (float)srcHeight / dstHeight;
                for (var x = dstX; x < dstX + dstWidth; x++)
                {
                    for (var y = dstY; y < dstY + dstWidth; y++)
                    {
                        var srcPixX = (int)Math.Round((x - dstX + srcX) * xRatio, MidpointRounding.AwayFromZero);
                        var srcPixY = (int)Math.Round((y - dstY + srcY) * yRatio, MidpointRounding.AwayFromZero);
                        drawPixel(x, y, (uint)pixmap.getPixel(srcPixX, srcPixY));
                    }
                }
            }
            else
            {
                for (int x = 0; x < dstWidth; ++x)
                {
                    for (int y = 0; y < dstWidth; ++y)
                    {
                        float gx  = ((float)x) / dstWidth * (srcWidth - 1);
                        float gy  = ((float)y) / dstWidth * (srcWidth - 1);
                        int   gxi = (int)gx;
                        int   gyi = (int)gy;

                        var c00 = (uint)pixmap.getPixel(gxi, gyi);
                        var c10 = (uint)pixmap.getPixel(gxi + 1, gyi);
                        var c01 = (uint)pixmap.getPixel(gxi, gyi + 1);
                        var c11 = (uint)pixmap.getPixel(gxi + 1, gyi + 1);

                        UInt32 red   = (byte)blerp(MonoGameColor.getRAsByte(c00), MonoGameColor.getRAsByte(c10), MonoGameColor.getRAsByte(c01), MonoGameColor.getRAsByte(c11), gx - gxi, gy - gyi);
                        UInt32 green = (byte)blerp(MonoGameColor.getGAsByte(c00), MonoGameColor.getGAsByte(c10), MonoGameColor.getGAsByte(c01), MonoGameColor.getGAsByte(c11), gx - gxi, gy - gyi);
                        UInt32 blue  = (byte)blerp(MonoGameColor.getBAsByte(c00), MonoGameColor.getBAsByte(c10), MonoGameColor.getBAsByte(c01), MonoGameColor.getBAsByte(c11), gx - gxi, gy - gyi);
                        UInt32 alpha = (byte)blerp(MonoGameColor.getAAsByte(c00), MonoGameColor.getAAsByte(c10), MonoGameColor.getAAsByte(c01), MonoGameColor.getAAsByte(c11), gx - gxi, gy - gyi);
                        var    color = ((red << 24) & 0xff000000) |
                                       ((green << 16) & 0xff0000) |
                                       ((blue << 8) & 0xff00) |
                                       alpha;
                        drawPixel(dstX + x, dstY + y, color);
                    }
                }
            }
        }
 public MonoGameShapeRenderer(GraphicsDevice graphicsDevice, MonoGameColor color, SpriteBatch spriteBatch)
 {
     _graphicsDevice = graphicsDevice;
     setColor(color);
     _spriteBatch = spriteBatch;
     if (_sharedTexture == null)
     {
         _sharedTexture = new Texture2D(_graphicsDevice, 1, 1, false, SurfaceFormat.Color);
         _sharedTexture.SetData(new[] { 0xffffffff });
     }
 }
Esempio n. 7
0
 public MonoGameShapeRenderer(GraphicsDevice graphicsDevice, MonoGameColor color, SpriteBatch spriteBatch, Vector2 rotationCenter, Vector2 translation, Vector2 scale, Color tint)
 {
     _graphicsDevice = graphicsDevice;
     setColor(color);
     _spriteBatch    = spriteBatch;
     _rotationCenter = rotationCenter;
     _translation    = translation;
     _scale          = scale;
     _tint           = tint;
     if (_sharedTexture == null)
     {
         _sharedTexture = newTexture2D(1, 1);
         _sharedTexture.SetData(new[] { 0xffffffff });
     }
 }
        public Pixmap toPixmap()
        {
            var pixmap = new MonoGamePixmap(_regionWidth, _regionHeight);

            var texture2d            = ((MonoGameTexture)_texture).texture2D;
            var rawTextureRegionData = new Color[_regionWidth * _regionHeight];

            Rectangle boundingRect = new Rectangle(getRegionX(), getRegionY(), _regionWidth, _regionHeight);

            bool flipX = isFlipX();
            bool flipY = isFlipY();

            if (flipX)
            {
                boundingRect.X -= _regionWidth;
            }

            if (flipY)
            {
                boundingRect.Y -= _regionHeight;
            }

            texture2d.GetData(0, boundingRect, rawTextureRegionData, 0, _regionWidth * _regionHeight);
            for (var x = 0; x < _regionWidth; x++)
            {
                for (var y = 0; y < _regionHeight; y++)
                {
                    var actualX = x;
                    var actualY = y;
                    if (flipX)
                    {
                        actualX = _regionWidth - x;
                    }

                    if (flipY)
                    {
                        actualY = _regionHeight - y;
                    }
                    pixmap.drawPixel(actualX, actualY, MonoGameColor.toRGBA8888(rawTextureRegionData[x + y * _regionWidth]));
                }
            }

            return(pixmap);
        }
Esempio n. 9
0
        public UInt32[] toRawPixelsARGB()
        {
            if (_format != PixmapFormat.RGBA8888)
            {
                throw new NotSupportedException();
            }

            var rawPixels = new UInt32[getWidth() * getHeight()];

            for (var x = 0; x < getWidth(); x++)
            {
                for (var y = 0; y < getHeight(); y++)
                {
                    rawPixels[y * getWidth() + x] = MonoGameColor.rgbaToArgb(_pixmap[x, y]);
                }
            }

            return(rawPixels);
        }
Esempio n. 10
0
        public void drawPixel(int x, int y, UInt32 color, bool blend = true)
        {
            var colorAlpha = MonoGameColor.getAAsByte(color);

            if (x < getWidth() && y < getHeight() && x >= 0 && y >= 0 && colorAlpha > 0)
            {
                if (colorAlpha == 255 || !blend)
                {
                    _pixmap[x, y] = color;
                }
                else
                {
                    var newR = (byte)(MonoGameColor.getRAsByte(color) * colorAlpha + MonoGameColor.getAAsByte((uint)getPixel(x, y)) * (255 - colorAlpha));
                    var newG = (byte)(MonoGameColor.getRAsByte(color) * colorAlpha + MonoGameColor.getAAsByte((uint)getPixel(x, y)) * (255 - colorAlpha));
                    var newB = (byte)(MonoGameColor.getRAsByte(color) * colorAlpha + MonoGameColor.getAAsByte((uint)getPixel(x, y)) * (255 - colorAlpha));
                    _pixmap[x, y] = MonoGameColor.toRGBA8888(newR, newG, newB, colorAlpha);
                }
            }
        }
Esempio n. 11
0
 public void setColor(Color color)
 {
     _setColor = (MonoGameColor)color;
 }
Esempio n. 12
0
 public void setColor(MonoGameColor color)
 {
     _color = color.toMonoGameColor();
 }
 public void setColor(MonoGameColor color)
 {
     _color = color._color;
 }