Exemplo n.º 1
0
        /// <summary>
        ///     The drawing event.
        /// </summary>
        /// <param name="args">
        ///     The event args.
        /// </param>
        internal void OnDraw(EventArgs args)
        {
            if (!this.Visible)
            {
                return;
            }

            var childs = this.Children.ToArray();
            var items  = this.Items.ToArray();

            Drawing.Direct3DDevice.SetRenderState(RenderState.AlphaBlendEnable, true);
            MenuDrawHelper.DrawBox(
                this.Position,
                this.Width,
                this.Height,
                (childs.Length > 0 && childs[0].Visible || items.Length > 0 && items[0].Visible)
                    ? MenuSettings.ActiveBackgroundColor
                    : MenuSettings.BackgroundColor,
                1,
                System.Drawing.Color.Black);

            var style = this.Style;

            style &= ~FontStyle.Strikeout;
            style &= ~FontStyle.Underline;

            var font = MenuDrawHelper.GetFont(style);

            font.DrawText(
                null,
                MultiLanguages._(this.DisplayName),
                new Rectangle((int)this.Position.X + 5, (int)this.Position.Y, this.Width, this.Height),
                FontDrawFlags.VerticalCenter,
                this.Color);
            font.DrawText(
                null,
                ">",
                new Rectangle((int)this.Position.X - 5, (int)this.Position.Y, this.Width, this.Height),
                FontDrawFlags.Right | FontDrawFlags.VerticalCenter,
                this.Color);

            var textWidth = font.MeasureText(null, MultiLanguages._(this.DisplayName));

            if ((this.Style & FontStyle.Strikeout) != 0)
            {
                Drawing.DrawLine(
                    this.Position.X + 5,
                    this.Position.Y + (MenuSettings.MenuItemHeight / 2f),
                    this.Position.X + 5 + textWidth.Width,
                    this.Position.Y + (MenuSettings.MenuItemHeight / 2f),
                    1f,
                    System.Drawing.Color.FromArgb(this.Color.A, this.Color.R, this.Color.G, this.Color.B));
            }

            if ((this.Style & FontStyle.Underline) != 0)
            {
                Drawing.DrawLine(
                    this.Position.X + 5,
                    this.Position.Y + (MenuSettings.MenuItemHeight / 1.5f),
                    this.Position.X + 5 + textWidth.Width,
                    this.Position.Y + (MenuSettings.MenuItemHeight / 1.5f),
                    1f,
                    System.Drawing.Color.FromArgb(this.Color.A, this.Color.R, this.Color.G, this.Color.B));
            }

            //Draw the menu submenus
            foreach (var child in childs.ToArray().Where(child => child.Visible))
            {
                child.OnDraw(args);
            }

            //Draw the items
            for (var i = items.Length - 1; i >= 0; i--)
            {
                var item = items[i];
                if (item.Visible)
                {
                    item.OnDraw();
                }
            }
        }
Exemplo n.º 2
0
        /// <summary>
        ///     On draw event.
        /// </summary>
        internal void OnDraw()
        {
            var s = MultiLanguages._(this.DisplayName);

            MenuDrawHelper.DrawBox(
                this.Position,
                this.Width,
                this.Height,
                MenuSettings.BackgroundColor,
                1,
                System.Drawing.Color.Black);

            if (this.DrawingTooltip)
            {
                MenuDrawHelper.DrawToolTipText(
                    new Vector2(this.Position.X + this.Width, this.Position.Y),
                    this,
                    this.TooltipColor);
            }

            var style = this.FontStyle;

            style &= ~FontStyle.Strikeout;
            style &= ~FontStyle.Underline;

            var font = MenuDrawHelper.GetFont(style);

            switch (this.ValueType)
            {
            case MenuValueType.Boolean:
                MenuDrawHelper.DrawOnOff(
                    this.GetValue <bool>(),
                    new Vector2(this.Position.X + this.Width - this.Height, this.Position.Y),
                    this);
                break;

            case MenuValueType.Slider:
                MenuDrawHelper.DrawSlider(this.Position, this);
                break;

            case MenuValueType.KeyBind:
                var val = this.GetValue <KeyBind>();

                if (this.Interacting)
                {
                    s = MultiLanguages._("Press new key(s)");
                }

                if (val.Key != 0)
                {
                    var x = !string.IsNullOrEmpty(this.Tooltip)
                                    ? (int)this.Position.X + this.Width - this.Height
                            - font.MeasureText("[" + Utils.KeyToText(val.Key) + "]").Width - 35
                                    : (int)this.Position.X + this.Width - this.Height
                            - font.MeasureText("[" + Utils.KeyToText(val.Key) + "]").Width - 10;

                    font.DrawText(
                        null,
                        "[" + Utils.KeyToText(val.Key) + "]",
                        new Rectangle(x, (int)this.Position.Y, this.Width, this.Height),
                        FontDrawFlags.VerticalCenter,
                        new ColorBGRA(1, 169, 234, 255));
                }

                if (val.SecondaryKey != 0)
                {
                    var x_secondary = !string.IsNullOrEmpty(this.Tooltip)
                                              ? (int)this.Position.X + this.Width - this.Height
                                      - font.MeasureText("[" + Utils.KeyToText(val.Key) + "]").Width
                                      - font.MeasureText("[" + Utils.KeyToText(val.Key) + "]").Width / 4
                                      - font.MeasureText("[" + Utils.KeyToText(val.SecondaryKey) + "]").Width
                                      - 35
                                              : (int)this.Position.X + this.Width - this.Height
                                      - font.MeasureText("[" + Utils.KeyToText(val.Key) + "]").Width
                                      - font.MeasureText("[" + Utils.KeyToText(val.Key) + "]").Width / 4
                                      - font.MeasureText("[" + Utils.KeyToText(val.SecondaryKey) + "]").Width
                                      - 10;

                    font.DrawText(
                        null,
                        "[" + Utils.KeyToText(val.SecondaryKey) + "]",
                        new Rectangle(x_secondary, (int)this.Position.Y, this.Width, this.Height),
                        FontDrawFlags.VerticalCenter,
                        new ColorBGRA(1, 169, 234, 255));
                }

                MenuDrawHelper.DrawOnOff(
                    val.Active,
                    new Vector2(this.Position.X + this.Width - this.Height, this.Position.Y),
                    this);

                break;

            case MenuValueType.Integer:
                var intVal = this.GetValue <int>();
                MenuDrawHelper.Font.DrawText(
                    null,
                    intVal.ToString(),
                    new Rectangle((int)this.Position.X + 5, (int)this.Position.Y, this.Width, this.Height),
                    FontDrawFlags.VerticalCenter | FontDrawFlags.Right,
                    new ColorBGRA(255, 255, 255, 255));
                break;

            case MenuValueType.Color:
                var colorVal = this.GetValue <System.Drawing.Color>();
                MenuDrawHelper.DrawBox(
                    this.Position + new Vector2(this.Width - this.Height, 0),
                    this.Height,
                    this.Height,
                    colorVal,
                    1,
                    System.Drawing.Color.Black);
                break;

            case MenuValueType.Circle:
                var circleVal = this.GetValue <Circle>();
                MenuDrawHelper.DrawBox(
                    this.Position + new Vector2(this.Width - this.Height * 2, 0),
                    this.Height,
                    this.Height,
                    circleVal.Color,
                    1,
                    System.Drawing.Color.Black);
                MenuDrawHelper.DrawOnOff(
                    circleVal.Active,
                    new Vector2(this.Position.X + this.Width - this.Height, this.Position.Y),
                    this);
                break;

            case MenuValueType.StringList:
                var slVal = this.GetValue <StringList>();

                var t = slVal.SList[slVal.SelectedIndex];

                MenuDrawHelper.DrawArrow(
                    "<<",
                    this.Position + new Vector2(this.Width - this.Height * 2, 0),
                    this,
                    System.Drawing.Color.Black);
                MenuDrawHelper.DrawArrow(
                    ">>",
                    this.Position + new Vector2(this.Width - this.Height, 0),
                    this,
                    System.Drawing.Color.Black);

                MenuDrawHelper.Font.DrawText(
                    null,
                    MultiLanguages._(t),
                    new Rectangle(
                        (int)this.Position.X - 5 - 2 * this.Height,
                        (int)this.Position.Y,
                        this.Width,
                        this.Height),
                    FontDrawFlags.VerticalCenter | FontDrawFlags.Right,
                    new ColorBGRA(255, 255, 255, 255));
                break;
            }

            if (!string.IsNullOrEmpty(this.Tooltip))
            {
                MenuDrawHelper.DrawToolTipButton(new Vector2(this.Position.X + this.Width, this.Position.Y), this);
            }

            font.DrawText(
                null,
                s,
                new Rectangle((int)this.Position.X + 5, (int)this.Position.Y, this.Width, this.Height),
                FontDrawFlags.VerticalCenter,
                this.FontColor);

            var textWidth = font.MeasureText(null, MultiLanguages._(this.DisplayName));

            if ((this.FontStyle & FontStyle.Strikeout) != 0)
            {
                Drawing.DrawLine(
                    this.Position.X + 5,
                    this.Position.Y + (MenuSettings.MenuItemHeight / 2f),
                    this.Position.X + 5 + textWidth.Width,
                    this.Position.Y + (MenuSettings.MenuItemHeight / 2f),
                    1f,
                    System.Drawing.Color.FromArgb(
                        this.FontColor.A,
                        this.FontColor.R,
                        this.FontColor.G,
                        this.FontColor.B));
            }

            if ((this.FontStyle & FontStyle.Underline) != 0)
            {
                Drawing.DrawLine(
                    this.Position.X + 5,
                    this.Position.Y + (MenuSettings.MenuItemHeight / 1.5f),
                    this.Position.X + 5 + textWidth.Width,
                    this.Position.Y + (MenuSettings.MenuItemHeight / 1.5f),
                    1f,
                    System.Drawing.Color.FromArgb(
                        this.FontColor.A,
                        this.FontColor.R,
                        this.FontColor.G,
                        this.FontColor.B));
            }
        }