예제 #1
0
        /// <summary>
        /// Returns a registered sprite drawable. If no sprite drawable is found but a Sprite exists with the name, a
        /// sprite drawable is created from the Sprite and stored in the skin
        /// </summary>
        /// <returns>The sprite drawable.</returns>
        /// <param name="name">Name.</param>
        public SpriteDrawable GetSpriteDrawable(string name)
        {
            var spriteDrawable = Get <SpriteDrawable>(name);

            if (spriteDrawable != null)
            {
                return(spriteDrawable);
            }

            var sprite = Get <Sprite>(name);

            if (sprite != null)
            {
                spriteDrawable = new SpriteDrawable(sprite);
                Add(name, spriteDrawable);
            }

            return(spriteDrawable);
        }
예제 #2
0
        /// <summary>
        /// Returns a registered drawable. If no drawable is found but a Sprite/NinePatchSprite exists with the name, then the
        /// appropriate drawable is created and stored in the skin. If name is a color a PrimitiveDrawable will be created and stored.
        /// </summary>
        /// <returns>The drawable.</returns>
        /// <param name="name">Name.</param>
        public IDrawable GetDrawable(string name)
        {
            var drawable = Get <IDrawable>(name);

            if (drawable != null)
            {
                return(drawable);
            }

            // Check for explicit registration of ninepatch, sprite or tiled drawable
            drawable = Get <SpriteDrawable>(name);
            if (drawable != null)
            {
                return(drawable);
            }

            drawable = Get <NinePatchDrawable>(name);
            if (drawable != null)
            {
                return(drawable);
            }

            drawable = Get <TiledDrawable>(name);
            if (drawable != null)
            {
                return(drawable);
            }

            drawable = Get <PrimitiveDrawable>(name);
            if (drawable != null)
            {
                return(drawable);
            }

            // still nothing. check for a NinePatchSprite or a Sprite and create a new drawable if we find one
            var ninePatchSprite = Get <NinePatchSprite>(name);

            if (ninePatchSprite != null)
            {
                drawable = new NinePatchDrawable(ninePatchSprite);
                Add(name, drawable as NinePatchDrawable);
                return(drawable);
            }

            var sprite = Get <Sprite>(name);

            if (sprite != null)
            {
                drawable = new SpriteDrawable(sprite);
                Add(name, drawable as SpriteDrawable);
                return(drawable);
            }

            // finally, we will check if name is a Color and create a PrimitiveDrawable if it is
            if (Has <Color>(name))
            {
                var color = Get <Color>(name);
                drawable = new PrimitiveDrawable(color);
                Add(name, drawable as PrimitiveDrawable);
                return(drawable);
            }

            return(null);
        }