Example #1
0
        public NinePatchDrawable(NinePatchSubtexture subtexture)
        {
            _subtexture = subtexture;
            minWidth    = _subtexture.ninePatchRects[MIDDLE_LEFT].Width + _subtexture.ninePatchRects[MIDDLE_CENTER].Width
                          + _subtexture.ninePatchRects[MIDDLE_RIGHT].Width;
            minHeight = _subtexture.ninePatchRects[TOP_CENTER].Height + _subtexture.ninePatchRects[MIDDLE_CENTER].Height
                        + _subtexture.ninePatchRects[BOTTOM_CENTER]
                        .Height;

            // by default, if padding isn't given, we will pad the content by the nine patch margins
            if (_subtexture.hasPadding)
            {
                leftWidth    = _subtexture.padLeft;
                rightWidth   = _subtexture.padRight;
                topHeight    = _subtexture.padTop;
                bottomHeight = _subtexture.padBottom;
            }
            else
            {
                leftWidth    = _subtexture.left;
                rightWidth   = _subtexture.right;
                topHeight    = _subtexture.top;
                bottomHeight = _subtexture.bottom;
            }
        }
Example #2
0
        public NinePatchDrawable(NinePatchSubtexture subtexture)
        {
            _subtexture = subtexture;
            MinWidth    = _subtexture.NinePatchRects[MIDDLE_LEFT].Width + _subtexture.NinePatchRects[MIDDLE_CENTER].Width +
                          _subtexture.NinePatchRects[MIDDLE_RIGHT].Width;
            MinHeight = _subtexture.NinePatchRects[TOP_CENTER].Height +
                        _subtexture.NinePatchRects[MIDDLE_CENTER].Height +
                        _subtexture.NinePatchRects[BOTTOM_CENTER].Height;

            // by default, if padding isn't given, we will pad the content by the nine patch margins
            if (_subtexture.HasPadding)
            {
                LeftWidth    = _subtexture.PadLeft;
                RightWidth   = _subtexture.PadRight;
                TopHeight    = _subtexture.PadTop;
                BottomHeight = _subtexture.PadBottom;
            }
            else
            {
                LeftWidth    = _subtexture.Left;
                RightWidth   = _subtexture.Right;
                TopHeight    = _subtexture.Top;
                BottomHeight = _subtexture.Bottom;
            }
        }
Example #3
0
        public NinePatchDrawable(NinePatchSubtexture subtexture)
        {
            _subtexture = subtexture;
            minWidth    = _subtexture.ninePatchRects[MIDDLE_LEFT].Width + _subtexture.ninePatchRects[MIDDLE_CENTER].Width + _subtexture.ninePatchRects[MIDDLE_RIGHT].Width;
            minHeight   = _subtexture.ninePatchRects[TOP_CENTER].Height + _subtexture.ninePatchRects[MIDDLE_CENTER].Height + _subtexture.ninePatchRects[BOTTOM_CENTER].Height;

            // by default, we will pad the content by the nine patch margins
            leftWidth    = _subtexture.left;
            rightWidth   = _subtexture.right;
            topHeight    = _subtexture.top;
            bottomHeight = _subtexture.bottom;
        }
        protected override LibGdxAtlas Read(ContentReader reader, LibGdxAtlas existingInstance)
        {
            var atlasContainer = new LibGdxAtlas();
            var numPages       = reader.ReadInt32();

            for (var p = 0; p < numPages; p++)
            {
                var assetName = reader.getRelativeAssetPath(reader.ReadString());
                var texture   = reader.ContentManager.Load <Texture2D>(assetName);

                var regionCount = reader.ReadInt32();
                var subtextures = new Subtexture[regionCount];
                var regionNames = new string[regionCount];

                for (var i = 0; i < regionCount; i++)
                {
                    var rect = new Rectangle();
                    var name = reader.ReadString();
                    rect.X      = reader.ReadInt32();
                    rect.Y      = reader.ReadInt32();
                    rect.Width  = reader.ReadInt32();
                    rect.Height = reader.ReadInt32();

                    var hasSplits = reader.ReadBoolean();
                    if (hasSplits)
                    {
                        subtextures[i] = new NinePatchSubtexture(texture, rect, reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32());
                    }
                    else
                    {
                        subtextures[i] = new Subtexture(texture, rect);
                    }

                    var hasPads = reader.ReadBoolean();
                    if (hasPads)
                    {
                        ((NinePatchSubtexture)subtextures[i]).hasPadding = true;
                        ((NinePatchSubtexture)subtextures[i]).padLeft    = reader.ReadInt32();
                        ((NinePatchSubtexture)subtextures[i]).padRight   = reader.ReadInt32();
                        ((NinePatchSubtexture)subtextures[i]).padTop     = reader.ReadInt32();
                        ((NinePatchSubtexture)subtextures[i]).padBottom  = reader.ReadInt32();
                    }

                    regionNames[i] = name;
                }

                var atlas = new TextureAtlas(regionNames, subtextures);
                atlasContainer.atlases.Add(atlas);
            }

            return(atlasContainer);
        }
Example #5
0
        protected override TextureAtlas Read(ContentReader input, TextureAtlas existingInstance)
        {
            if (existingInstance != null)
            {
                // read the texture
                var texture = input.ReadObject <Texture2D>();

                foreach (var subtexture in existingInstance.Subtextures)
                {
                    subtexture.Texture2D = texture;
                }

                // discard the rest of the SpriteSheet data as we are only reloading GPU resources for now
                input.ReadObject <List <Rectangle> >();
                input.ReadObject <string[]>();
                input.ReadObject <Dictionary <string, Point> >();
                input.ReadObject <Dictionary <string, int[]> >();
                input.ReadInt32();

                return(existingInstance);
            }
            else
            {
                // create a fresh TextureAtlas instance
                var texture                = input.ReadObject <Texture2D>();
                var spriteRectangles       = input.ReadObject <List <Rectangle> >();
                var spriteNames            = input.ReadObject <string[]>();
                var spriteAnimationDetails = input.ReadObject <Dictionary <string, Point> >();
                var splits       = input.ReadObject <Dictionary <string, int[]> >();
                var animationFPS = input.ReadInt32();

                // create subtextures
                var subtextures = new Subtexture[spriteNames.Length];
                for (var i = 0; i < spriteNames.Length; i++)
                {
                    // check to see if this is a nine patch
                    if (splits.ContainsKey(spriteNames[i]))
                    {
                        var split = splits[spriteNames[i]];
                        subtextures[i] = new NinePatchSubtexture(texture, spriteRectangles[i], split[0], split[1],
                                                                 split[2], split[3]);
                    }
                    else
                    {
                        subtextures[i] = new Subtexture(texture, spriteRectangles[i]);
                    }
                }

                return(new TextureAtlas(spriteNames, subtextures, spriteAnimationDetails, animationFPS));
            }
        }
Example #6
0
        protected override LibGdxAtlas Read(ContentReader reader, LibGdxAtlas existingInstance)
        {
            var atlasContainer = new LibGdxAtlas();
            var numPages       = reader.ReadInt32();

            for (var p = 0; p < numPages; p++)
            {
                var assetName = reader.GetRelativeAssetPath(reader.ReadString());
                var texture   = reader.ContentManager.Load <Texture2D>(assetName);

                var regionCount = reader.ReadInt32();
                var subtextures = new Subtexture[regionCount];
                var regionNames = new string[regionCount];

                for (var i = 0; i < regionCount; i++)
                {
                    var rect = new Rectangle();
                    var name = reader.ReadString();
                    rect.X      = reader.ReadInt32();
                    rect.Y      = reader.ReadInt32();
                    rect.Width  = reader.ReadInt32();
                    rect.Height = reader.ReadInt32();

                    var hasSplits = reader.ReadBoolean();
                    if (hasSplits)
                    {
                        subtextures[i] = new NinePatchSubtexture(texture, rect, reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32());
                    }
                    else
                    {
                        subtextures[i] = new Subtexture(texture, rect);
                    }

                    var hasPads = reader.ReadBoolean();
                    if (hasPads)
                    {
                        ((NinePatchSubtexture)subtextures[i]).HasPadding = true;
                        ((NinePatchSubtexture)subtextures[i]).PadLeft    = reader.ReadInt32();
                        ((NinePatchSubtexture)subtextures[i]).PadRight   = reader.ReadInt32();
                        ((NinePatchSubtexture)subtextures[i]).PadTop     = reader.ReadInt32();
                        ((NinePatchSubtexture)subtextures[i]).PadBottom  = reader.ReadInt32();
                    }

                    var index = reader.ReadInt32();

                    // animation
                    if (index != -1)
                    {
                        List <Subtexture> frames;
                        if (!atlasContainer.Animations.TryGetValue(name, out frames))
                        {
                            frames = new List <Subtexture>();
                            atlasContainer.Animations[name] = frames;
                        }

                        frames.Insert(index, subtextures[i]);
                    }

                    regionNames[i] = name;
                }

                var atlas = new TextureAtlas(regionNames, subtextures);
                atlasContainer.Atlases.Add(atlas);
            }

            return(atlasContainer);
        }
Example #7
0
 public NineSliceSprite(NinePatchSubtexture subtexture) : base(subtexture)
 {
     this.subtexture = subtexture;
 }