Exemplo n.º 1
0
 /// <summary>
 ///     Gets the width of the MenuList
 /// </summary>
 /// <returns>The <see cref="int" /></returns>
 public override int Width()
 {
     return(TechUtilities.CalcWidthItem(this.Component) + this.Component.MaxStringWidth + (2 * TextSpacing)
            + this.dropDownButtonWidth);
 }
Exemplo n.º 2
0
        /// <summary>
        ///     Draw a <see cref="MenuList" />
        /// </summary>
        public override void Draw()
        {
            var dropdownMenuWidth = this.dropDownButtonWidth + (2 * TextSpacing) + this.Component.MaxStringWidth;
            var position          = this.Component.Position;
            var rectangleName     = TechUtilities.GetContainerRectangle(this.Component)
                                    .GetCenteredText(null, MenuSettings.Font, this.Component.DisplayName, CenteredFlags.VerticalCenter);

            MenuSettings.Font.DrawText(
                MenuManager.Instance.Sprite,
                this.Component.DisplayName,
                (int)(position.X + MenuSettings.ContainerTextOffset),
                (int)rectangleName.Y,
                MenuSettings.TextColor);

            MenuSettings.Font.DrawText(
                MenuManager.Instance.Sprite,
                "\u23EC",
                (int)(position.X + this.Component.MenuWidth - this.dropDownButtonWidth + ArrowSpacing),
                (int)rectangleName.Y,
                MenuSettings.TextColor);

            MenuSettings.Font.DrawText(
                MenuManager.Instance.Sprite,
                this.Component.SelectedValueAsObject.ToString(),
                (int)position.X + this.Component.MenuWidth - this.dropDownButtonWidth - TextSpacing
                - this.Component.MaxStringWidth,
                (int)rectangleName.Y,
                MenuSettings.TextColor);

            if (this.Component.Active)
            {
                var valueStrings       = this.Component.ValuesAsStrings;
                var dropdownMenuHeight = valueStrings.Length * MenuSettings.ContainerHeight;
                MenuManager.Instance.DrawDelayed(
                    delegate
                {
                    var color = MenuSettings.RootContainerColor;

                    Utils.DrawBoxRounded(position.X + Component.MenuWidth - dropdownMenuWidth, position.Y + MenuSettings.ContainerHeight,
                                         dropdownMenuWidth, dropdownMenuHeight, 4, true,
                                         MenuSettings.RootContainerColor, new ColorBGRA(55, 76, 95, 255));

                    var x =
                        (int)
                        (position.X + Component.MenuWidth - dropDownButtonWidth - TextSpacing
                         - Component.MaxStringWidth);
                    var y = (int)rectangleName.Y;
                    for (var i = 0; i < valueStrings.Length; i++)
                    {
                        if (i == Component.HoveringIndex)
                        {
                            Line.Width = MenuSettings.ContainerHeight;
                            Line.Begin();
                            Line.Draw(
                                new[]
                            {
                                new Vector2(
                                    position.X + Component.MenuWidth - dropdownMenuWidth,
                                    position.Y + ((i + 1) * MenuSettings.ContainerHeight)
                                    + MenuSettings.ContainerHeight / 2f),
                                new Vector2(
                                    position.X + Component.MenuWidth,
                                    position.Y + ((i + 1) * MenuSettings.ContainerHeight)
                                    + MenuSettings.ContainerHeight / 2f)
                            },
                                MenuSettings.HoverColor);
                            Line.End();
                        }

                        if (i != 0)
                        {
                            Line.Width = 1f;
                            Line.Begin();
                            Line.Draw(
                                new[]
                            {
                                new Vector2(
                                    position.X + Component.MenuWidth - dropdownMenuWidth + 10,
                                    position.Y + (MenuSettings.ContainerHeight * (i + 1))),
                                new Vector2(
                                    position.X + Component.MenuWidth - 10,
                                    position.Y + (MenuSettings.ContainerHeight * (i + 1)))
                            },
                                MenuSettings.ContainerSeparatorColor);
                            Line.End();
                        }

                        y += MenuSettings.ContainerHeight;
                        MenuSettings.Font.DrawText(
                            MenuManager.Instance.Sprite,
                            valueStrings[i],
                            x,
                            y,
                            MenuSettings.TextColor);
                        if (Component.Index == i)
                        {
                            var checkmarkWidth = MenuSettings.Font.MeasureText(null, "\u2713", 0).Width;
                            MenuSettings.Font.DrawText(
                                MenuManager.Instance.Sprite,
                                "\u2713",
                                (int)(position.X + Component.MenuWidth - checkmarkWidth - TextSpacing),
                                y,
                                new ColorBGRA(1, 165, 226, 255));
                        }
                    }
                });
            }
        }