Esempio n. 1
0
        public override void Draw()
        {
            base.Draw();
            var stateOffset = Depressed ? new int2(VisualHeight, VisualHeight) : new int2(0, 0);

            var image         = ChromeProvider.GetImage("scrollbar", IsDisabled() ? "down_pressed" : "down_arrow");
            var rb            = RenderBounds;
            var color         = GetColor();
            var colorDisabled = GetColorDisabled();

            WidgetUtils.DrawRGBA(image, stateOffset + new float2(rb.Right - rb.Height + 4, rb.Top + (rb.Height - image.Bounds.Height) / 2));

            WidgetUtils.FillRectWithColor(new Rectangle(stateOffset.X + rb.Right - rb.Height,
                                                        stateOffset.Y + rb.Top + 3, 1, rb.Height - 6),
                                          IsDisabled() ? colorDisabled : color);
        }
 public override void Draw()
 {
     WidgetUtils.FillRectWithColor(RenderBounds, GetColor());
 }
        public override void Draw()
        {
            var apparentText = GetApparentText();
            var font         = Game.Renderer.Fonts[Font];
            var pos          = RenderOrigin;

            var textSize       = font.Measure(apparentText);
            var cursorPosition = font.Measure(apparentText.Substring(0, CursorPosition));

            var disabled = IsDisabled();
            var state    = disabled ? "textfield-disabled" :
                           HasKeyboardFocus ? "textfield-focused" :
                           Ui.MouseOverWidget == this || Children.Any(c => c == Ui.MouseOverWidget) ? "textfield-hover" :
                           "textfield";

            WidgetUtils.DrawPanel(state,
                                  new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height));

            // Inset text by the margin and center vertically
            var verticalMargin = (Bounds.Height - textSize.Y) / 2 - VisualHeight;
            var textPos        = pos + new int2(LeftMargin, verticalMargin);

            // Right align when editing and scissor when the text overflows
            if (textSize.X > Bounds.Width - LeftMargin - RightMargin)
            {
                if (HasKeyboardFocus)
                {
                    textPos += new int2(Bounds.Width - LeftMargin - RightMargin - textSize.X, 0);
                }

                Game.Renderer.EnableScissor(new Rectangle(pos.X + LeftMargin, pos.Y,
                                                          Bounds.Width - LeftMargin - RightMargin, Bounds.Bottom));
            }

            // Draw the highlight around the selected area
            if (selectionStartIndex != -1)
            {
                var visualSelectionStartIndex = selectionStartIndex < selectionEndIndex ? selectionStartIndex : selectionEndIndex;
                var visualSelectionEndIndex   = selectionStartIndex < selectionEndIndex ? selectionEndIndex : selectionStartIndex;
                var highlightStartX           = font.Measure(apparentText.Substring(0, visualSelectionStartIndex)).X;
                var highlightEndX             = font.Measure(apparentText.Substring(0, visualSelectionEndIndex)).X;

                WidgetUtils.FillRectWithColor(
                    new Rectangle(textPos.X + highlightStartX, textPos.Y, highlightEndX - highlightStartX, Bounds.Height - (verticalMargin * 2)), TextColorHighlight);
            }

            var color =
                disabled ? TextColorDisabled
                                : IsValid() ? TextColor
                                : TextColorInvalid;

            font.DrawText(apparentText, textPos, color);

            if (showCursor && HasKeyboardFocus)
            {
                font.DrawText("|", new float2(textPos.X + cursorPosition.X - 2, textPos.Y), TextColor);
            }

            if (textSize.X > Bounds.Width - LeftMargin - RightMargin)
            {
                Game.Renderer.DisableScissor();
            }
        }
Esempio n. 4
0
 public override void Draw()
 {
     WidgetUtils.FillRectWithColor(RenderBounds, GetTopLeftColor(), GetTopRightColor(), GetBottomRightColor(), GetBottomLeftColor());
 }