Beispiel #1
0
        /// <summary>
        /// Draws the sprite using the nine cut method
        /// This is mostly useful for gui elements like forms and buttons
        /// </summary>
        /// <param name="sb"></param>
        /// <param name="dest"></param>
        /// <param name="source"></param>
        /// <param name="color"></param>
        /// <param name="destEdge"></param>
        /// <param name="sourceEdge"></param>
        /// <param name="scale"></param>
        /// <param name="origin"></param>
        /// <param name="rotation"></param>
        public void DrawNineCut(SpriteBatch sb, Rectangle dest, Rectangle?source = null, Color?color = null, int?destEdge = null, int?sourceEdge = null, Vector2?scale = null, Vector2?origin = null, float rotation = 0f)
        {
            // setup values
            if (color == null)
            {
                color = Color.White;
            }
            if (scale == null)
            {
                scale = Vector2.One;
            }
            if (origin == null)
            {
                origin = new Vector2(dest.Width / 2, dest.Height / 2);
            }

            switch (spriteType)
            {
            case SpriteType.Atlas:
                if (destEdge == null)
                {
                    destEdge = dest.Width / 3;
                }
                if (sourceEdge == null)
                {
                    sourceEdge = Width / 3;
                }
                Atlas.DrawNineCut(sb, AtlasKey, dest, source, color, destEdge, sourceEdge);
                break;

            case SpriteType.Texture:
                if (destEdge == null)
                {
                    destEdge = 15;
                }
                if (sourceEdge == null)
                {
                    sourceEdge = Texture.Width / 3;
                }
                if (source == null)
                {
                    source = Texture.Bounds;
                }
                DrawTextureNineCut(sb, Texture, color.Value, destEdge.Value, sourceEdge.Value, dest, source.Value);
                break;
            }
        }