Example #1
0
        public Texture2DArray(int width, int height, params ResourceLocator[] textureLocators)
            : base(TextureTarget.Texture2DArray, width, height, GetNextPowerOfTwo(textureLocators.Length))
        {
            _names = textureLocators;
            _textures = new BitmapTexture2D[textureLocators.Length];

            for (int i = 0; i < textureLocators.Length; ++i) {
                _textures[i] = new BitmapTexture2D(Archive.Get<Bitmap>(_names[i]));
            }

            int tileLength = width * height;

            _data = new uint[tileLength * Depth];

            for (int i = 0; i < _textures.Length; ++i) {
                Bitmap tile = _textures[i].Bitmap;

                int xScale = tile.Width / width;
                int yScale = tile.Height / height;

                for (int x = 0; x < width; ++x) {
                    for (int y = 0; y < height; ++y) {
                        int tx = x * xScale;
                        int ty = y * yScale;

                        Color clr = tile.GetPixel(tx, ty);

                        _data[i * tileLength + x + y * width]
                            = (UInt32) (clr.R << 24 | clr.G << 16 | clr.B << 08 | clr.A << 00);
                    }
                }
            }
        }
Example #2
0
        protected virtual void UpdateImage()
        {
            using (var ctx = Graphics.FromImage(BitmapTexture2D.Blank.Bitmap)) {
                var size = ctx.MeasureString(Value, Font);
                SubrectWidth = (float) Math.Ceiling(size.Width);
                SubrectHeight = (float) Math.Ceiling(size.Height);
            }

            if (Texture.Bitmap.Width < SubrectWidth || Texture.Bitmap.Height < SubrectHeight) {
                if (Texture != BitmapTexture2D.Blank) Texture.Dispose();

                int newWidth = Math.Max((int) SubrectWidth, Texture.Bitmap.Width);
                int newHeight = Math.Max((int) SubrectHeight, Texture.Bitmap.Height);

                Texture = new BitmapTexture2D(MathHelper.NextPowerOfTwo(newWidth), MathHelper.NextPowerOfTwo(newHeight));
            }

            using (var ctx = Graphics.FromImage(Texture.Bitmap)) {
                ctx.SmoothingMode = SmoothingMode.HighQuality;
                ctx.Clear(Color.Transparent);

                var path = new GraphicsPath();

                path.AddString(Value, Font.FontFamily, (int) Font.Style,
                    ctx.DpiY * Font.Size / 72f, PointF.Empty, StringFormat.GenericDefault);

                ctx.FillPath(_brush, path);
            }

            Texture.Invalidate();
        }
Example #3
0
        /// <summary>
        /// Static constructor for BitmapTexture2D. Creates the default texture.
        /// </summary>
        static BitmapTexture2D()
        {
            Bitmap blankBmp = new Bitmap(1, 1);

            blankBmp.SetPixel(0, 0, Color.White);
            Blank = new BitmapTexture2D(blankBmp);
        }
Example #4
0
        public AnimatedSprite(BitmapTexture2D texture, int frameWidth, int frameHeight, double frameRate, float scale = 1.0f)
            : base(texture, scale)
        {
            _frameWidth = frameWidth;
            _frameHeight = frameHeight;

            FrameRate = frameRate;

            _startTime = 0;
            _stopTime = 0;

            SubrectSize = new Vector2(frameWidth, frameHeight);

            FindFrameLocations();

            StartFrame = 0;
            FrameCount = _frameLocations.Length;

            _lastFrame = -1;
        }
Example #5
0
 /// <summary>
 /// Static constructor for BitmapTexture2D. Creates the default texture.
 /// </summary>
 static BitmapTexture2D()
 {
     Bitmap blankBmp = new Bitmap(1, 1);
     blankBmp.SetPixel(0, 0, Color.White);
     Blank = new BitmapTexture2D(blankBmp);
 }
Example #6
0
        public PixelFont(params String[] charMapLocator)
        {
            Texture = new BitmapTexture2D(Archive.Get<Bitmap>(charMapLocator));

            CharSize = new Vector2(Texture.Width / 16, Texture.Height / 16);
        }
Example #7
0
        public Sprite(BitmapTexture2D texture, float scale = 1.0f)
        {
            Texture = texture;

            Position = new Vector2();
            SubrectOffset = new Vector2(0, 0);
            SubrectSize = new Vector2(Texture.Width, Texture.Height);
            FlipHorizontal = false;
            FlipVertical = false;
            Rotation = 0;
            UseCentreAsOrigin = false;
            Colour = new Color4(1.0f, 1.0f, 1.0f, 1.0f);

            Scale = new Vector2(scale, scale);
        }
Example #8
0
        public Sprite(float width, float height, Color4 colour)
        {
            Texture = BitmapTexture2D.Blank;

            Position = new Vector2();
            Scale = new Vector2(width, height);
            SubrectOffset = new Vector2(0, 0);
            SubrectSize = new Vector2(Texture.Width, Texture.Height);
            FlipHorizontal = false;
            FlipVertical = false;
            Rotation = 0;
            UseCentreAsOrigin = false;
            Colour = colour;
        }
Example #9
0
 public FrameSprite(BitmapTexture2D texture, float scale = 1.0f)
     : base(texture, scale)
 {
     _frameTopLeft = new Vector2();
     _frameBottomRight = new Vector2();
 }