Exemple #1
0
        /// <summary>
        /// Generates and adds an item with the specified text into the drop-down.
        /// </summary>
        /// <param name="text">The text of the item.</param>
        public void AddItem(string text)
        {
            XNADropDownItem item = new XNADropDownItem();

            item.Text = text;

            Items.Add(item);
        }
Exemple #2
0
        /// <summary>
        /// Generates and adds an item with the specified text
        /// and text color into the drop-down control.
        /// </summary>
        /// <param name="text">The text of the item.</param>
        /// <param name="color">The color of the item's text.</param>
        public void AddItem(string text, Color color)
        {
            XNADropDownItem item = new XNADropDownItem();

            item.Text      = text;
            item.TextColor = color;

            Items.Add(item);
        }
Exemple #3
0
        /// <summary>
        /// Generates and adds an item with the specified text and texture
        /// into the drop-down.
        /// </summary>
        /// <param name="text">The text of the item.</param>
        /// <param name="texture">The item's texture.</param>
        public void AddItem(string text, Texture2D texture)
        {
            XNADropDownItem item = new XNADropDownItem();

            item.Text    = text;
            item.Texture = texture;

            Items.Add(item);
        }
Exemple #4
0
        /// <summary>
        /// Draws a single drop-down item.
        /// This can be overridden in derived classes to customize the drawing code.
        /// </summary>
        /// <param name="index">The index of the item to be drawn.</param>
        /// <param name="y">The Y coordinate of the item's top border.</param>
        protected virtual void DrawItem(int index, int y)
        {
            XNADropDownItem item = Items[index];

            if (hoveredIndex == index)
            {
                FillRectangle(new Rectangle(1, y, Width - 2, ItemHeight), FocusColor);
            }
            else
            {
                FillRectangle(new Rectangle(1, y, Width - 2, ItemHeight), BackColor);
            }

            int textX = 2;

            if (item.Texture != null)
            {
                DrawTexture(item.Texture, new Rectangle(1, y + 1, item.Texture.Width, item.Texture.Height), Color.White);
                textX += item.Texture.Width + 1;
            }

            Color textColor;

            if (item.Selectable)
            {
                textColor = GetItemTextColor(item);
            }
            else
            {
                textColor = DisabledItemColor;
            }

            if (item.Text != null)
            {
                DrawStringWithShadow(item.Text, FontIndex, new Vector2(textX, y + 1), textColor);
            }
        }
Exemple #5
0
        /// <summary>
        /// Draws the drop-down.
        /// </summary>
        public override void Draw(GameTime gameTime)
        {
            Rectangle dropDownRect;

            if (DropDownState == DropDownState.CLOSED)
            {
                dropDownRect = new Rectangle(0, 0, Width, Height);
            }
            else if (DropDownState == DropDownState.OPENED_DOWN)
            {
                dropDownRect = new Rectangle(0, 0, Width, DropDownTexture.Height);
            }
            else
            {
                dropDownRect = new Rectangle(0, Height - DropDownTexture.Height, Width, DropDownTexture.Height);
            }

            FillRectangle(new Rectangle(dropDownRect.X + 1, dropDownRect.Y + 1,
                                        dropDownRect.Width - 2, dropDownRect.Height - 2), BackColor);
            DrawRectangle(dropDownRect, BorderColor);

            if (SelectedIndex > -1 && SelectedIndex < Items.Count)
            {
                XNADropDownItem item = Items[SelectedIndex];

                int textX = 3;
                if (item.Texture != null)
                {
                    DrawTexture(item.Texture,
                                new Rectangle(1, dropDownRect.Y + 2,
                                              item.Texture.Width, item.Texture.Height), Color.White);
                    textX += item.Texture.Width + 1;
                }

                if (item.Text != null)
                {
                    DrawStringWithShadow(item.Text, FontIndex,
                                         new Vector2(textX, dropDownRect.Y + 2), GetItemTextColor(item));
                }
            }

            if (AllowDropDown)
            {
                Rectangle ddRectangle = new Rectangle(Width - DropDownTexture.Width,
                                                      dropDownRect.Y, DropDownTexture.Width, DropDownTexture.Height);

                if (DropDownState != DropDownState.CLOSED)
                {
                    DrawTexture(DropDownOpenTexture,
                                ddRectangle, RemapColor);

                    Rectangle listRectangle;

                    if (DropDownState == DropDownState.OPENED_DOWN)
                    {
                        listRectangle = new Rectangle(0, DropDownTexture.Height, Width, Height + 1 - DropDownTexture.Height);
                    }
                    else
                    {
                        listRectangle = new Rectangle(0, 0, Width, Height - DropDownTexture.Height);
                    }

                    DrawRectangle(listRectangle, BorderColor);

                    for (int i = 0; i < Items.Count; i++)
                    {
                        int y = listRectangle.Y + 1 + i * ItemHeight;
                        DrawItem(i, y);
                    }
                }
                else
                {
                    DrawTexture(DropDownTexture, ddRectangle, RemapColor);
                }
            }

            base.Draw(gameTime);
        }
Exemple #6
0
 /// <summary>
 /// Gets the text color of a drop-down item.
 /// </summary>
 /// <param name="item">The item.</param>
 protected Color GetItemTextColor(XNADropDownItem item) =>
 item.TextColor ?? TextColor;
Exemple #7
0
 /// <summary>
 /// Adds an item into the drop-down.
 /// </summary>
 /// <param name="item">The item.</param>
 public void AddItem(XNADropDownItem item)
 {
     Items.Add(item);
 }