Beispiel #1
0
        public Tuple <SpriteKey, SpriteInstanceData> Resolve(Sprite sprite)
        {
            var      assetType = AssetTypeLookup[sprite.IdType];
            var      id        = sprite.NumericId;
            ITexture texture   = Resolve <IAssetManager>().LoadTexture(assetType, id);

            if (texture == null)
            {
                return(Tuple.Create(new SpriteKey(_defaultTexture, (int)DrawLayer.Diagnostic, sprite.Flags),
                                    SpriteInstanceData.Centred(sprite.Position,
                                                               new Vector2(_defaultTexture.Width, _defaultTexture.Height),
                                                               Vector2.Zero, Vector2.One, 0, 0)));
            }

            texture.GetSubImageDetails(sprite.SubObject, out var size, out var texOffset, out var texSize, out var layer);

            var key      = new SpriteKey(texture, sprite.RenderOrder, sprite.Flags);
            var instance = SpriteInstanceData.CopyFlags(
                sprite.Position,
                sprite.Size ?? size, texOffset, texSize, layer,
                sprite.Flags | (texture.Format == PixelFormat.R8_UNorm ? SpriteFlags.UsePalette : 0)
                );

            return(Tuple.Create(key, instance));
        }
Beispiel #2
0
        void Rebuild(int width, int height, int order)
        {
            var window = Resolve <IWindowManager>();

            {
                var normSize  = window.UiToNormRelative(new Vector2(width, height));
                var pixelSize = window.NormToPixelRelative(normSize);

                if ((pixelSize - _lastPixelSize).LengthSquared() < float.Epsilon && _sprite.RenderOrder == order)
                {
                    return;
                }
                _lastPixelSize = pixelSize;
            }

            var totalSize = GetSize();
            var extents   = new Rectangle(0, 0, (int)totalSize.X, (int)totalSize.Y);

            var instances = new List <SpriteInstanceData>();

            for (int j = extents.Y; j < extents.Height; j++)
            {
                for (int i = extents.X; i < extents.Width; i++)
                {
                    int         n     = instances.Count;
                    SpriteFlags flags = SpriteFlags.NoTransform | SpriteFlags.NoDepthTest;
                    if ((n & 1) != 0)
                    {
                        flags |= SpriteFlags.BlueTint;
                    }
                    if ((n & 2) != 0)
                    {
                        flags |= SpriteFlags.GreenTint;
                    }
                    if ((n & 4) != 0)
                    {
                        flags |= SpriteFlags.RedTint;
                    }
                    if ((n & 8) != 0)
                    {
                        flags |= SpriteFlags.Highlight;
                    }

                    var position = new Vector3(window.UiToNorm(new Vector2(i, j)), 0);
                    var size     = 2 * Vector2.One / window.Size;
                    instances.Add(SpriteInstanceData.Centred(position, size, Vector2.Zero, Vector2.One, 0, flags));
                }
            }

            _sprite = new MultiSprite(new SpriteKey(_pixel, order, instances[0].Flags))
            {
                Instances = instances.ToArray()
            };
        }