public override void DrawOuter()
        {
            if (!IsVisible())
            {
                return;
            }

            var rb = RenderBounds;

            var ScrollbarHeight = rb.Height - 2 * ScrollbarWidth;

            var thumbHeight = ContentHeight == 0 ? 0 : Math.Max(MinimumThumbSize, (int)(ScrollbarHeight * Math.Min(rb.Height * 1f / ContentHeight, 1f)));
            var thumbOrigin = rb.Y + ScrollbarWidth + (int)((ScrollbarHeight - thumbHeight) * (-1f * ListOffset / (ContentHeight - rb.Height)));

            if (thumbHeight == ScrollbarHeight)
            {
                thumbHeight = 0;
            }

            backgroundRect = new Rectangle(rb.X, rb.Y, rb.Width - ScrollbarWidth + 1, rb.Height);
            upButtonRect   = new Rectangle(rb.Right - ScrollbarWidth, rb.Y, ScrollbarWidth, ScrollbarWidth);
            downButtonRect = new Rectangle(rb.Right - ScrollbarWidth, rb.Bottom - ScrollbarWidth, ScrollbarWidth, ScrollbarWidth);
            scrollbarRect  = new Rectangle(rb.Right - ScrollbarWidth, rb.Y + ScrollbarWidth - 1, ScrollbarWidth, ScrollbarHeight + 2);
            thumbRect      = new Rectangle(rb.Right - ScrollbarWidth, thumbOrigin, ScrollbarWidth, thumbHeight);

            var upHover    = Ui.MouseOverWidget == this && upButtonRect.Contains(Viewport.LastMousePos);
            var upDisabled = thumbHeight == 0 || ListOffset >= 0;

            var downHover    = Ui.MouseOverWidget == this && downButtonRect.Contains(Viewport.LastMousePos);
            var downDisabled = thumbHeight == 0 || ListOffset <= Bounds.Height - ContentHeight;

            var thumbHover = Ui.MouseOverWidget == this && thumbRect.Contains(Viewport.LastMousePos);

            WidgetUtils.DrawPanel(Background, backgroundRect);
            WidgetUtils.DrawPanel("scrollpanel-bg", scrollbarRect);
            ButtonWidget.DrawBackground("button", upButtonRect, upDisabled, UpPressed, upHover, false);
            ButtonWidget.DrawBackground("button", downButtonRect, downDisabled, DownPressed, downHover, false);

            if (thumbHeight > 0)
            {
                ButtonWidget.DrawBackground("scrollthumb", thumbRect, false, HasMouseFocus && thumbHover, thumbHover, false);
            }

            var upOffset   = !UpPressed || upDisabled ? 4 : 4 + ButtonDepth;
            var downOffset = !DownPressed || downDisabled ? 4 : 4 + ButtonDepth;

            WidgetUtils.DrawRGBA(ChromeProvider.GetImage("scrollbar", UpPressed || upDisabled ? "up_pressed" : "up_arrow"),
                                 new float2(upButtonRect.Left + upOffset, upButtonRect.Top + upOffset));
            WidgetUtils.DrawRGBA(ChromeProvider.GetImage("scrollbar", DownPressed || downDisabled ? "down_pressed" : "down_arrow"),
                                 new float2(downButtonRect.Left + downOffset, downButtonRect.Top + downOffset));

            Game.Renderer.EnableScissor(backgroundRect.InflateBy(-1, -1, -1, -1));

            foreach (var child in Children)
            {
                child.DrawOuter();
            }

            Game.Renderer.DisableScissor();
        }
Exemple #2
0
        public override void Draw()
        {
            if (!IsVisible())
            {
                return;
            }

            var tr          = ThumbRect;
            var rb          = RenderBounds;
            var trackWidth  = rb.Width;
            var trackOrigin = rb.X;
            var trackRect   = new Rectangle(trackOrigin - 1, rb.Y + (rb.Height - TrackHeight) / 2, trackWidth + 2, TrackHeight);

            // Tickmarks (hacked until we have real art)
            for (int i = 0; i < Ticks; i++)
            {
                var tickRect = new Rectangle(trackOrigin - 1 + (int)(i * trackWidth * 1f / (Ticks - 1)),
                                             rb.Y + rb.Height / 2, 2, rb.Height / 2);
                WidgetUtils.DrawPanel("slider-tick", tickRect);
            }

            // Track
            WidgetUtils.DrawPanel("slider-track", trackRect);

            // Thumb
            var thumbHover = Widget.MouseOverWidget == this && tr.Contains(Viewport.LastMousePos);

            ButtonWidget.DrawBackground("scrollthumb", tr, IsDisabled(), isMoving, thumbHover);
        }
Exemple #3
0
        public override void Draw()
        {
            var pos         = RenderOrigin;
            var chatLogArea = new Rectangle(pos.X, pos.Y, Bounds.Width, Bounds.Height);
            var chatpos     = new int2(chatLogArea.X + 10, chatLogArea.Bottom - 6);

            if (DrawBackground)
            {
                WidgetUtils.DrawPanel("dialog3", chatLogArea);
            }

            var font = Game.Renderer.Fonts["Regular"];

            Game.Renderer.EnableScissor(chatLogArea.Left, chatLogArea.Top, chatLogArea.Width, chatLogArea.Height);

            foreach (var line in recentLines.AsEnumerable().Reverse())
            {
                chatpos.Y -= 20;
                var inset = 0;

                if (!string.IsNullOrEmpty(line.Owner))
                {
                    var owner = line.Owner + ":";
                    inset = font.Measure(owner).X + 10;

                    font.DrawTextWithContrast(owner, chatpos,
                                              line.Color, Color.Black, UseContrast ? 1 : 0);
                }

                font.DrawTextWithContrast(line.Text, chatpos + new int2(inset, 0),
                                          Color.White, Color.Black, UseContrast ? 1 : 0);
            }

            Game.Renderer.DisableScissor();
        }
Exemple #4
0
        public override void Draw()
        {
            var disabled = IsDisabled();
            var font     = Game.Renderer.Fonts[Font];
            var rect     = RenderBounds;
            var check    = new Rectangle(rect.Location, new Size(Bounds.Height, Bounds.Height));
            var state    = disabled ? "checkbox-disabled" :
                           Depressed && HasPressedState ? "checkbox-pressed" :
                           Widget.MouseOverWidget == this ? "checkbox-hover" :
                           "checkbox";

            WidgetUtils.DrawPanel(state, check);

            var textSize = font.Measure(Text);

            font.DrawText(Text,
                          new float2(rect.Left + rect.Height * 1.5f, RenderOrigin.Y - BaseLine + (Bounds.Height - textSize.Y) / 2), Color.White);

            if (IsChecked() || (Depressed && HasPressedState && !disabled))
            {
                var checkType = GetCheckType();
                if (HasPressedState && (Depressed || disabled))
                {
                    checkType += "-disabled";
                }

                var offset = new float2(rect.Left + CheckOffset, rect.Top + CheckOffset);
                WidgetUtils.DrawRGBA(ChromeProvider.GetImage("checkbox-bits", checkType), offset);
            }
        }
Exemple #5
0
        public override void Draw()
        {
            if (!IsVisible())
            {
                return;
            }

            Value = GetValue();

            var tr          = ThumbRect;
            var rb          = RenderBounds;
            var trackWidth  = rb.Width - rb.Height;
            var trackOrigin = rb.X + rb.Height / 2;
            var trackRect   = new Rectangle(trackOrigin - 1, rb.Y + (rb.Height - TrackHeight) / 2, trackWidth + 2, TrackHeight);

            // Tickmarks
            var tick = ChromeProvider.GetImage("slider", "tick");

            for (var i = 0; i < Ticks; i++)
            {
                var tickPos = new float2(
                    trackOrigin + (i * (trackRect.Width - (int)tick.size.X) / (Ticks - 1)) - tick.size.X / 2,
                    trackRect.Bottom);

                WidgetUtils.DrawRGBA(tick, tickPos);
            }

            // Track
            WidgetUtils.DrawPanel(Track, trackRect);

            // Thumb
            var thumbHover = Ui.MouseOverWidget == this && tr.Contains(Viewport.LastMousePos);

            ButtonWidget.DrawBackground(Thumb, tr, IsDisabled(), isMoving, thumbHover, false);
        }
Exemple #6
0
        public static void DrawBackground(string baseName, Rectangle rect, bool disabled, bool pressed, bool hover)
        {
            var state = disabled ? "-disabled" :
                        pressed ? "-pressed" :
                        hover ? "-hover" :
                        "";

            WidgetUtils.DrawPanel(baseName + state, rect);
        }
Exemple #7
0
        public override void Draw()
        {
            var state = IsSelected() ? BaseName + "-selected" :
                        Ui.MouseOverWidget == this ? BaseName + "-hover" :
                        null;

            if (state != null)
            {
                WidgetUtils.DrawPanel(state, RenderBounds);
            }
        }
Exemple #8
0
        public override void Draw()
        {
            var state = IsSelected() ? "scrollitem-selected" :
                        Widget.MouseOverWidget == this ? "scrollitem-hover" :
                        null;

            if (state != null)
            {
                WidgetUtils.DrawPanel(state, RenderBounds);
            }
        }
        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 ? "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 textPos = pos + new int2(LeftMargin, (Bounds.Height - textSize.Y) / 2 - VisualHeight);

            // 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));
            }

            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();
            }
        }
Exemple #10
0
        public override void Draw()
        {
            var rb = RenderBounds;

            WidgetUtils.DrawPanel("progressbar-bg", rb);

            Rectangle barRect = Indeterminate ?
                                new Rectangle(rb.X + 2 + (int)(0.75 * offset * (rb.Width - 4)), rb.Y + 2, (rb.Width - 4) / 4, rb.Height - 4) :
                                new Rectangle(rb.X + 2, rb.Y + 2, Percentage * (rb.Width - 4) / 100, rb.Height - 4);

            if (barRect.Width > 0)
            {
                WidgetUtils.DrawPanel("progressbar-thumb", barRect);
            }
        }
Exemple #11
0
        public override void Draw()
        {
            var disabled      = IsDisabled();
            var highlighted   = IsHighlighted();
            var font          = Game.Renderer.Fonts[Font];
            var color         = GetColor();
            var colordisabled = GetColorDisabled();
            var contrast      = GetContrastColor();
            var rect          = RenderBounds;
            var text          = GetText();
            var textSize      = font.Measure(text);
            var check         = new Rectangle(rect.Location, new Size(Bounds.Height, Bounds.Height));
            var state         = disabled ? "checkbox-disabled" :
                                highlighted ? "checkbox-highlighted" :
                                Depressed && HasPressedState ? "checkbox-pressed" :
                                Ui.MouseOverWidget == this ? "checkbox-hover" :
                                "checkbox";

            WidgetUtils.DrawPanel(state, check);
            var position = new float2(rect.Left + rect.Height * 1.5f, RenderOrigin.Y - BaseLine + (Bounds.Height - textSize.Y) / 2);

            if (Contrast)
            {
                font.DrawTextWithContrast(text, position,
                                          disabled ? colordisabled : color, contrast, 2);
            }
            else
            {
                font.DrawText(text, position,
                              disabled ? colordisabled : color);
            }

            if (IsChecked() || (Depressed && HasPressedState && !disabled))
            {
                var checkType = GetCheckType();
                if (HasPressedState && (Depressed || disabled))
                {
                    checkType += "-disabled";
                }

                var offset = new float2(rect.Left + CheckOffset, rect.Top + CheckOffset);
                WidgetUtils.DrawRGBA(ChromeProvider.GetImage("checkbox-bits", checkType), offset);
            }
        }
Exemple #12
0
        public override void Draw()
        {
            var apparentText = Key.DisplayString();

            var font = Game.Renderer.Fonts[Font];
            var pos  = RenderOrigin;

            var textSize = font.Measure(apparentText);

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

            WidgetUtils.DrawPanel(state, RenderBounds);

            // Blink the current entry to indicate focus
            if (HasKeyboardFocus && !showEntry)
            {
                return;
            }

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

            // Scissor when the text overflows
            if (textSize.X > Bounds.Width - LeftMargin - RightMargin)
            {
                Game.Renderer.EnableScissor(new Rectangle(pos.X + LeftMargin, pos.Y,
                                                          Bounds.Width - LeftMargin - RightMargin, Bounds.Bottom));
            }

            var color = disabled ? TextColorDisabled : TextColor;

            font.DrawText(apparentText, textPos, color);

            if (textSize.X > Bounds.Width - LeftMargin - RightMargin)
            {
                Game.Renderer.DisableScissor();
            }
        }
Exemple #13
0
 public override void Draw()
 {
     WidgetUtils.DrawPanel(Background, RenderBounds);
 }