public TextureSlice Remove(TextureSlice area)
 {
     return(TextureSlice.FromTwoPoints(
                area.TopLeft - (this.Left, this.Top),
                area.BottomRight + (this.Right, this.Bottom)
                ));
 }
Example #2
0
        public Matrix4x4 ScaleMatrix(TextureSlice container, TextureSlice fitting)
        {
            var screenSize = container.Size;

            var scaleX = fitting.Size.X / (float)screenSize.X;
            var scaleY = fitting.Size.Y / (float)screenSize.Y;
            var scale  = Math.Max(scaleY, scaleX);

            var width  = (int)(fitting.Size.X / scale);
            var height = (int)(fitting.Size.Y / scale);

            var matrix = Matrix4x4.CreateScale(
                1 / scale,
                1 / scale,
                1
                );

            matrix *= Matrix4x4.CreateTranslation(
                (screenSize.X - width) / 2,
                (screenSize.Y - height) / 2,
                0
                );

            return(matrix);
        }
Example #3
0
 private void recalcCurrentFrame()
 {
     this.currentFrame = new TextureSlice(
         this.currentSprite.X * indivudualSize.X,
         this.currentSprite.Y * indivudualSize.Y,
         this.indivudualSize.X,
         this.indivudualSize.Y
         );
 }
Example #4
0
 public static IntRect ToSFML(this TextureSlice self)
 {
     return(new IntRect(
                self.TopLeft.X,
                self.TopLeft.Y,
                self.Width,
                self.Height
                ));
 }
Example #5
0
 public void Draw(IDrawable texture,
                  TextureSlice destinationRectangle,
                  Color color,
                  float deltaTime,
                  Vector2?origin = null,
                  float rotation = 0,
                  TextureSlice?sourceRectangle = null)
 {
     // TODO
 }
Example #6
0
        public GameAction Create(string resName, Resource res)
        {
            var data  = res.GetLayer <ActionLayer>();
            var image = TextureSlice.FromBitmap(res.GetLayer <ImageLayer>().Data);

            return(new GameAction(
                       data.Name,
                       resName,
                       data.Parent,
                       data.Name,
                       new Picture(image, null),
                       data.Verbs));
        }
        /// <summary>
        /// Positions a textureslice inside another textureslice
        /// </summary>
        /// <param name="availableArea">The area where we can position our texture slice</param>
        /// <param name="toPosition">The texture slice to position</param>
        /// <returns>The positioned texture slice</returns>
        public TextureSlice Apply(TextureSlice availableArea, TextureSlice toPosition)
        {
            // origin - position
            var topLeft = availableArea.TopLeft + availableArea.Size * (Vector2)this
                          - new Vector2(toPosition.Width * this.X, toPosition.Height * this.Y)
                          - (availableArea.TopLeft - toPosition.TopLeft);

            return(new TextureSlice(
                       (Point)topLeft,
                       toPosition.Width,
                       toPosition.Height
                       ));
        }
Example #8
0
 private void RequestMinimap(MapGrid grid)
 {
     try
     {
         var bytes = provider.Get(grid.MinimapName);
         // texture needs to be loaded on the main thread
         App.QueueOnMainThread(() =>
         {
             var tex   = TextureSlice.FromBitmap(bytes);
             var image = new Picture(tex, null);
             cache[grid.MinimapName] = image;
         });
     }
     catch (Exception ex)
     {
         Log.Error(ex, "Couldn't get minimap at " + grid.Coord);
     }
 }
Example #9
0
        static AimWidget()
        {
            var res = App.Resources.Load("ui/aim");

            foreach (var imageData in res.GetLayers <ImageLayer>())
            {
                if (imageData.Id == 0)
                {
                    bg       = new Picture(TextureSlice.FromBitmap(imageData.Data), null);
                    bgOffset = imageData.Offset;
                }
                if (imageData.Id == 1)
                {
                    fg       = new Picture(TextureSlice.FromBitmap(imageData.Data), null);
                    fgOffset = imageData.Offset;
                }
            }
        }
Example #10
0
        public TextureSlice Scale(TextureSlice container, TextureSlice fitting)
        {
            var screenSize = container.Size;

            var scaleX = fitting.Size.X / (float)screenSize.X;
            var scaleY = fitting.Size.Y / (float)screenSize.Y;
            var scale  = Math.Max(scaleY, scaleX);

            var width  = (int)(fitting.Size.X / scale);
            var height = (int)(fitting.Size.Y / scale);

            return(new TextureSlice(
                       (screenSize.X - width) / 2,
                       (screenSize.Y - height) / 2,
                       width,
                       height
                       ));
        }
Example #11
0
        private void Pack(ImageLayer[] images, Point2D center)
        {
            var bitmaps  = new Bitmap[images.Length];
            var regions  = new RectF[images.Length];
            var hitmasks = new BitArray[images.Length];

            try
            {
                var packer = new NaiveHorizontalPacker();
                // calculate pack
                for (int i = 0; i < images.Length; i++)
                {
                    using (var ms = new MemoryStream(images[i].Data))
                    {
                        BitArray hitmask;
                        bitmaps[i]  = ProcessImage(new Bitmap(ms), out hitmask);
                        regions[i]  = packer.Add(bitmaps[i].Size);
                        hitmasks[i] = hitmask;
                    }
                }
                tex = new Texture(packer.PackWidth, packer.PackHeight);
                // add sprite parts to the texture
                for (int i = 0; i < images.Length; i++)
                {
                    var slice = new TextureSlice(tex, regions[i]);
                    slice.Update(bitmaps[i]);
                    var img = images[i];
                    var off = img.Offset.Sub(center);
                    var pic = new Picture(slice, hitmasks[i]);
                    parts.Add(new SpritePart(img.Id, pic, off, img.Z, img.SubZ));
                }
            }
            finally
            {
                foreach (var bitmap in bitmaps.Where(x => x != null))
                {
                    bitmap.Dispose();
                }
            }
        }
Example #12
0
        public Drawable Create(string resName, Resource res)
        {
            var imageData = res.GetLayer <ImageLayer>();

            if (imageData == null)
            {
                return(null);
            }

            using (var ms = new MemoryStream(imageData.Data))
                using (var bitmap = new Bitmap(ms))
                {
                    // load texture
                    var tex = TextureSlice.FromBitmap(bitmap);
                    // check whether image is a ninepatch
                    var ninepatch = res.GetLayer <NinepatchLayer>();
                    if (ninepatch != null)
                    {
                        return(new NinePatch(tex, ninepatch.Left, ninepatch.Right,
                                             ninepatch.Top, ninepatch.Bottom));
                    }
                    return(new Picture(tex, GenerateHitmask(bitmap)));
                }
        }