Exemplo n.º 1
0
        /// <summary>
        /// Update skin sizes.
        /// </summary>
        protected override void RefreshSkins()
        {
            // Get the current list of skins
            Dictionary <int, ComponentSkin> skins = Skins;

            foreach (KeyValuePair <int, ComponentSkin> skin in skins)
            {
                GUIRect rect = new GUIRect();
                rect.Source = GetSkinLocation(skin.Key);

                if (this.scale)
                {
                    rect.Destination = new Rectangle(0, 0, Width, Height);
                }
                else
                {
                    rect.Destination = new Rectangle(0, 0, rect.Source.Width, rect.Source.Height);
                }

                skin.Value.Rects.Clear();
                skin.Value.Rects.Add(rect);
            }

            Redraw();
        }
Exemplo n.º 2
0
        /// <summary>
        /// Constructs a box drawn with four corner sprites, and five other
        /// sprites stretched to allow resizing. Note that there must a 1 pixel
        /// gap between edges and the middle sprite on the source texture.
        /// </summary>
        /// <param name="source">Location on source texture.</param>
        /// <param name="dimensions">Size of bar to construct.</param>
        /// <param name="edgeSize">The box corner size.</param>
        /// <param name="isVertical">Orientation of the bar.</param>
        /// <returns>List of skin locations of new bar.</returns>
        protected static List <GUIRect> CreateBox(Rectangle source, Rectangle dimensions, int cornerSize)
        {
            List <GUIRect> result = new List <GUIRect>();

            GUIRect[] sprites = new GUIRect[9];

            // Top Left
            sprites[0]             = new GUIRect();
            sprites[0].Source      = new Rectangle(source.X, source.Y, cornerSize, cornerSize);
            sprites[0].Destination = new Rectangle(dimensions.X, dimensions.Y, cornerSize, cornerSize);

            // Bottom Left
            sprites[1]             = new GUIRect();
            sprites[1].Source      = new Rectangle(source.X, source.Bottom - cornerSize, cornerSize, cornerSize);
            sprites[1].Destination = new Rectangle(dimensions.X, dimensions.Bottom - cornerSize, cornerSize, cornerSize);

            // Bottom Right
            sprites[2]             = new GUIRect();
            sprites[2].Source      = new Rectangle(source.Right - cornerSize, source.Bottom - cornerSize, cornerSize, cornerSize);
            sprites[2].Destination = new Rectangle(dimensions.Right - cornerSize, dimensions.Bottom - cornerSize, cornerSize, cornerSize);

            // Top Right
            sprites[3]             = new GUIRect();
            sprites[3].Source      = new Rectangle(source.Right - cornerSize, source.Y, cornerSize, cornerSize);
            sprites[3].Destination = new Rectangle(dimensions.Right - cornerSize, dimensions.Y, cornerSize, cornerSize);

            // Top
            sprites[4]             = new GUIRect();
            sprites[4].Source      = new Rectangle(source.X + cornerSize, source.Y, source.Width - (2 * cornerSize), cornerSize);
            sprites[4].Destination = new Rectangle(dimensions.X + cornerSize, dimensions.Y, dimensions.Width - (2 * cornerSize), cornerSize);

            // Bottom
            sprites[5]             = new GUIRect();
            sprites[5].Source      = new Rectangle(source.X + cornerSize, source.Bottom - cornerSize, source.Width - (2 * cornerSize), cornerSize);
            sprites[5].Destination = new Rectangle(dimensions.X + cornerSize, dimensions.Bottom - cornerSize, dimensions.Width - (2 * cornerSize), cornerSize);

            // Left
            sprites[6]             = new GUIRect();
            sprites[6].Source      = new Rectangle(source.X, source.Y + cornerSize, cornerSize, source.Height - (2 * cornerSize));
            sprites[6].Destination = new Rectangle(dimensions.X, dimensions.Y + cornerSize, cornerSize, dimensions.Height - (2 * cornerSize));

            // Right
            sprites[7]             = new GUIRect();
            sprites[7].Source      = new Rectangle(source.Right - cornerSize, source.Y + cornerSize, cornerSize, source.Height - (2 * cornerSize));
            sprites[7].Destination = new Rectangle(dimensions.Right - cornerSize, dimensions.Y + cornerSize, cornerSize, dimensions.Height - (2 * cornerSize));

            // Middle
            sprites[8]             = new GUIRect();
            sprites[8].Source      = new Rectangle(source.X + cornerSize, source.Y + cornerSize, source.Width - (2 * cornerSize), source.Height - (2 * cornerSize));
            sprites[8].Destination = new Rectangle(dimensions.X + cornerSize, dimensions.Y + cornerSize, dimensions.Width - (2 * cornerSize), dimensions.Height - (2 * cornerSize));

            // Copy over the results
            for (int i = 0; i < 9; i++)
            {
                result.Add(sprites[i]);
            }

            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Constructs a bar skin by creating edges and stretching the middle.
        /// </summary>
        /// <param name="source">Location on source texture.</param>
        /// <param name="dimensions">Size of bar to construct.</param>
        /// <param name="edgeSize">The bar edge size.</param>
        /// <param name="isVertical">Orientation of the bar.</param>
        /// <returns>List of skin locations of new bar.</returns>
        protected static List <GUIRect> CreateBar(
            Rectangle source,
            Rectangle dimensions,
            int edgeSize,
            bool isVertical
            )
        {
            List <GUIRect> result = new List <GUIRect>();

            GUIRect[] sprites = new GUIRect[3];

            if (isVertical)
            {
                // Top
                sprites[0]             = new GUIRect();
                sprites[0].Source      = new Rectangle(source.X, source.Y, source.Width, edgeSize);
                sprites[0].Destination = new Rectangle(dimensions.X, dimensions.Y, dimensions.Width, edgeSize);

                // Middle
                sprites[1]             = new GUIRect();
                sprites[1].Source      = new Rectangle(source.X, source.Y + edgeSize, source.Width, source.Height - (2 * edgeSize));
                sprites[1].Destination = new Rectangle(dimensions.X, dimensions.Y + edgeSize, dimensions.Width, dimensions.Height - (2 * edgeSize));

                // Bottom
                sprites[2]             = new GUIRect();
                sprites[2].Source      = new Rectangle(source.X, source.Bottom - edgeSize, source.Width, edgeSize);
                sprites[2].Destination = new Rectangle(dimensions.X, dimensions.Y + dimensions.Height - edgeSize, dimensions.Width, edgeSize);
            }
            else
            {
                // Left
                sprites[0]             = new GUIRect();
                sprites[0].Source      = new Rectangle(source.X, source.Y, edgeSize, source.Height);
                sprites[0].Destination = new Rectangle(dimensions.X, dimensions.Y, edgeSize, dimensions.Height);

                // Middle
                sprites[1]             = new GUIRect();
                sprites[1].Source      = new Rectangle(source.X + edgeSize, source.Y, source.Width - (2 * edgeSize), source.Height);
                sprites[1].Destination = new Rectangle(dimensions.X + edgeSize, dimensions.Y, dimensions.Width - (2 * edgeSize), dimensions.Height);

                // Right
                sprites[2]             = new GUIRect();
                sprites[2].Source      = new Rectangle(source.Right - edgeSize, source.Y, edgeSize, source.Height);
                sprites[2].Destination = new Rectangle(dimensions.Right - edgeSize, dimensions.Y, edgeSize, dimensions.Height);
            }

            // Copy over the results
            for (int i = 0; i < 3; i++)
            {
                result.Add(sprites[i]);
            }

            return(result);
        }