Ejemplo n.º 1
0
        private void UpdateVM(IDbSpriteAtlasFromImage entry)
        {
            SourceImage = dataProvider.GetModel <Bitmap>(entry.DataRef);

            Items.UpdateAfter(() =>
            {
                Items.Clear();

                for (int i = 0; i < entry.Sprites.Count; i++)
                {
                    var spriteDef = entry.Sprites[i];

                    var spriteBuilder = SpriteBuilder.NewSprite();
                    spriteBuilder.SetIndex(i);
                    spriteBuilder.SetSize(spriteDef.Width, spriteDef.Height);
                    var cutout = new Rectangle(spriteDef.X, spriteDef.Y, spriteDef.Width, spriteDef.Height);
                    var bytes  = BitmapHelper.ToBytes(SourceImage, cutout);
                    spriteBuilder.SetData(bytes);

                    var sprite = spriteBuilder.Build();

                    var spriteVM = SpriteFromImageVM.Create(sprite, cutout);
                    Items.Add(spriteVM);
                }
            });

            CurrentSpriteIndex = 0;
        }
Ejemplo n.º 2
0
        public static SpriteFromImageVM Create(SpriteModel spriteModel, Rectangle sourceRectangle)
        {
            var vm = new SpriteFromImageVM();

            vm.FromModel(spriteModel);
            vm.SourceRectangle = sourceRectangle;
            return(vm);
        }
Ejemplo n.º 3
0
        public void AddSprite()
        {
            var newSprite = new SpriteFromImageVM();

            newSprite.Id = Items.Count;
            newSprite.SourceRectangle = new Rectangle(0, 0, 8, 8);
            var bytes = BitmapHelper.ToBytes(SourceImage, newSprite.SourceRectangle);

            newSprite.UpdateBitmap(8, 8, bytes);
            BitmapHelper.SetPaletteColors(newSprite.Image, SourceImage.Palette.Entries);

            Items.Add(newSprite);
            CurrentSpriteIndex = Items.Count - 1;
        }