Exemple #1
0
        /// <summary>
        /// Sets the currently active skin, and flags a redraw.
        /// </summary>
        /// <remarks>
        /// Does nothing if no skin has been set for the specified index, or
        /// clears current skin if -1.
        /// </remarks>
        /// <param name="index">Skin index.</param>
        private void SetActiveSkin(int index)
        {
            // Minimize redraws
            if (index != this.currentSkin)
            {
                ComponentSkin skin = null;

                if (index != -1)
                {
                    skin = GetSkin(index);
                }

                if (skin != null || index == -1)
                {
                    this.currentSkin = index;
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Draws all skins associated with control, after clipping them to the
        /// parent control area.
        /// </summary>
        /// <param name="spriteBatch">SpriteBatch to draw with.</param>
        /// <param name="parentScissor">The scissor region of the parent control.</param>
        protected override void DrawControl(SpriteBatch spriteBatch, Rectangle scissor)
        {
            ComponentSkin skin = GetSkin(this.currentSkin);

            if (skin != null)
            {
                Texture2D texture;

                // Should the default GUI skin be used?
                if (skin.UseCustomSkin)
                {
                    texture = skin.Skin;
                }
                else
                {
                    texture = GUIManager.SkinTexture;
                }

                Rectangle source;
                Rectangle destination;

                foreach (GUIRect rect in skin.Rects)
                {
                    source = rect.Source;

                    // Convert to absolute position
                    destination    = rect.Destination;
                    destination.X += AbsolutePosition.X;
                    destination.Y += AbsolutePosition.Y;

                    if (GUIManager.PerformClipping(ref scissor, ref source, ref destination))
                    {
                        // Actually draw!
                        spriteBatch.Draw(
                            texture,
                            destination,
                            source,
                            Color.White
                            );
                    }
                }
            }
        }