DrawBackground() public method

public DrawBackground ( Rectangle rect, bool disabled, bool pressed, bool hover, bool highlighted ) : void
rect System.Drawing.Rectangle
disabled bool
pressed bool
hover bool
highlighted bool
return void
        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);
        }
Ejemplo n.º 2
0
        public override void Draw()
        {
            var tabs = Groups[queueGroup].Tabs.Where(t => t.Queue.BuildableItems().Any());

            if (!tabs.Any())
            {
                return;
            }

            var rb = RenderBounds;

            leftButtonRect  = new Rectangle(rb.X, rb.Y, ArrowWidth, rb.Height);
            rightButtonRect = new Rectangle(rb.Right - ArrowWidth, rb.Y, ArrowWidth, rb.Height);

            var leftDisabled  = listOffset >= 0;
            var leftHover     = Ui.MouseOverWidget == this && leftButtonRect.Contains(Viewport.LastMousePos);
            var rightDisabled = listOffset <= Bounds.Width - rightButtonRect.Width - leftButtonRect.Width - contentWidth;
            var rightHover    = Ui.MouseOverWidget == this && rightButtonRect.Contains(Viewport.LastMousePos);

            WidgetUtils.DrawPanel(Background, rb);
            ButtonWidget.DrawBackground(Button, leftButtonRect, leftDisabled, leftPressed, leftHover, false);
            ButtonWidget.DrawBackground(Button, rightButtonRect, rightDisabled, rightPressed, rightHover, false);

            var leftArrowImageName = WidgetUtils.GetStatefulImageName(DecorationScrollLeft, leftDisabled, leftPressed, leftHover);
            var leftArrowImage     = ChromeProvider.GetImage(Decorations, leftArrowImageName) ?? ChromeProvider.GetImage(Decorations, DecorationScrollLeft);

            WidgetUtils.DrawRGBA(leftArrowImage,
                                 new float2(leftButtonRect.Left + 2, leftButtonRect.Top + 2));

            var rightArrowImageName = WidgetUtils.GetStatefulImageName(DecorationScrollRight, rightDisabled, rightPressed, rightHover);
            var rightArrowImage     = ChromeProvider.GetImage(Decorations, rightArrowImageName) ?? ChromeProvider.GetImage(Decorations, DecorationScrollRight);

            WidgetUtils.DrawRGBA(rightArrowImage,
                                 new float2(rightButtonRect.Left + 2, rightButtonRect.Top + 2));

            // Draw tab buttons
            Game.Renderer.EnableScissor(new Rectangle(leftButtonRect.Right, rb.Y + 1, rightButtonRect.Left - leftButtonRect.Right - 1, rb.Height));
            var origin = new int2(leftButtonRect.Right - 1 + (int)listOffset, leftButtonRect.Y);
            var font   = Game.Renderer.Fonts["TinyBold"];

            contentWidth = 0;

            foreach (var tab in tabs)
            {
                var rect        = new Rectangle(origin.X + contentWidth, origin.Y, TabWidth, rb.Height);
                var hover       = !leftHover && !rightHover && Ui.MouseOverWidget == this && rect.Contains(Viewport.LastMousePos);
                var highlighted = tab.Queue == CurrentQueue;
                ButtonWidget.DrawBackground(Button, rect, false, false, hover, highlighted);
                contentWidth += TabWidth - 1;

                var textSize = font.Measure(tab.Name);
                var position = new int2(rect.X + (rect.Width - textSize.X) / 2, rect.Y + (rect.Height - textSize.Y) / 2);
                font.DrawTextWithContrast(tab.Name, position, tab.Queue.AllQueued().Any(i => i.Done) ? Color.Gold : Color.White, Color.Black, 1);
            }

            Game.Renderer.DisableScissor();
        }
Ejemplo n.º 3
0
        public override void Draw()
        {
            if (!Groups[queueGroup].Tabs.Any(t => t.Queue.BuildableItems().Any()))
            {
                return;
            }

            var rb = RenderBounds;

            leftButtonRect  = new Rectangle(rb.X, rb.Y, ArrowWidth, rb.Height);
            rightButtonRect = new Rectangle(rb.Right - ArrowWidth, rb.Y, ArrowWidth, rb.Height);

            var leftDisabled  = listOffset >= 0;
            var leftHover     = Ui.MouseOverWidget == this && leftButtonRect.Contains(Viewport.LastMousePos);
            var rightDisabled = listOffset <= Bounds.Width - rightButtonRect.Width - leftButtonRect.Width - contentWidth;
            var rightHover    = Ui.MouseOverWidget == this && rightButtonRect.Contains(Viewport.LastMousePos);

            WidgetUtils.DrawPanel("panel-black", rb);
            ButtonWidget.DrawBackground("button", leftButtonRect, leftDisabled, leftPressed, leftHover, false);
            ButtonWidget.DrawBackground("button", rightButtonRect, rightDisabled, rightPressed, rightHover, false);

            WidgetUtils.DrawRGBA(ChromeProvider.GetImage("scrollbar", leftPressed || leftDisabled ? "left_pressed" : "left_arrow"),
                                 new float2(leftButtonRect.Left + 2, leftButtonRect.Top + 2));
            WidgetUtils.DrawRGBA(ChromeProvider.GetImage("scrollbar", rightPressed || rightDisabled ? "right_pressed" : "right_arrow"),
                                 new float2(rightButtonRect.Left + 2, rightButtonRect.Top + 2));

            // Draw tab buttons
            Game.Renderer.EnableScissor(new Rectangle(leftButtonRect.Right, rb.Y + 1, rightButtonRect.Left - leftButtonRect.Right - 1, rb.Height));
            var origin = new int2(leftButtonRect.Right - 1 + (int)listOffset, leftButtonRect.Y);
            var font   = Game.Renderer.Fonts["TinyBold"];

            contentWidth = 0;

            foreach (var tab in Groups[queueGroup].Tabs.Where(t => t.Queue.BuildableItems().Any()))
            {
                var rect     = new Rectangle(origin.X + contentWidth, origin.Y, TabWidth, rb.Height);
                var hover    = !leftHover && !rightHover && Ui.MouseOverWidget == this && rect.Contains(Viewport.LastMousePos);
                var baseName = tab.Queue == CurrentQueue ? "button-highlighted" : "button";
                ButtonWidget.DrawBackground(baseName, rect, false, false, hover, false);
                contentWidth += TabWidth - 1;

                var textSize = font.Measure(tab.Name);
                var position = new int2(rect.X + (rect.Width - textSize.X) / 2, rect.Y + (rect.Height - textSize.Y) / 2);
                font.DrawTextWithContrast(tab.Name, position, tab.Queue.CurrentDone ? Color.Gold : Color.White, Color.Black, 1);
            }

            Game.Renderer.DisableScissor();
        }
Ejemplo n.º 4
0
        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 * currentListOffset / (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);

            upDisabled = thumbHeight == 0 || currentListOffset >= 0;

            var downHover = Ui.MouseOverWidget == this && downButtonRect.Contains(Viewport.LastMousePos);

            downDisabled = thumbHeight == 0 || currentListOffset <= Bounds.Height - ContentHeight;

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

            WidgetUtils.DrawPanel(Background, backgroundRect);
            WidgetUtils.DrawPanel(Background, scrollbarRect);
            ButtonWidget.DrawBackground(Button, upButtonRect, upDisabled, upPressed, upHover, false);
            ButtonWidget.DrawBackground(Button, downButtonRect, downDisabled, downPressed, downHover, false);

            if (thumbHeight > 0)
            {
                ButtonWidget.DrawBackground(Button, 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));

            var drawBounds = backgroundRect.InflateBy(-BorderWidth, -BorderWidth, -BorderWidth, -BorderWidth);

            Game.Renderer.EnableScissor(drawBounds);

            drawBounds.Offset((-ChildOrigin).ToPoint());
            foreach (var child in Children)
            {
                if (child.Bounds.IntersectsWith(drawBounds))
                {
                    child.DrawOuter();
                }
            }

            Game.Renderer.DisableScissor();
        }
Ejemplo n.º 5
0
        public override void DrawOuter()
        {
            if (!IsVisible())
            {
                return;
            }

            UpdateSmoothScrolling();

            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 * currentListOffset / (ContentHeight - rb.Height)));

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

            switch (ScrollBar)
            {
            case ScrollBar.Left:
                backgroundRect = new Rectangle(rb.X + ScrollbarWidth, rb.Y, rb.Width + 1, rb.Height);
                upButtonRect   = new Rectangle(rb.X, rb.Y, ScrollbarWidth, ScrollbarWidth);
                downButtonRect = new Rectangle(rb.X, rb.Bottom - ScrollbarWidth, ScrollbarWidth, ScrollbarWidth);
                scrollbarRect  = new Rectangle(rb.X, rb.Y + ScrollbarWidth - 1, ScrollbarWidth, scrollbarHeight + 2);
                thumbRect      = new Rectangle(rb.X, thumbOrigin, ScrollbarWidth, thumbHeight);
                break;

            case ScrollBar.Right:
                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);
                break;

            case ScrollBar.Hidden:
                backgroundRect = new Rectangle(rb.X, rb.Y, rb.Width + 1, rb.Height);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            WidgetUtils.DrawPanel(Background, backgroundRect);

            if (ScrollBar != ScrollBar.Hidden)
            {
                var upHover = Ui.MouseOverWidget == this && upButtonRect.Contains(Viewport.LastMousePos);
                upDisabled = thumbHeight == 0 || currentListOffset >= 0;

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

                var thumbHover = Ui.MouseOverWidget == this && thumbRect.Contains(Viewport.LastMousePos);
                WidgetUtils.DrawPanel(ScrollBarBackground, scrollbarRect);
                ButtonWidget.DrawBackground(Button, upButtonRect, upDisabled, upPressed, upHover, false);
                ButtonWidget.DrawBackground(Button, downButtonRect, downDisabled, downPressed, downHover, false);

                if (thumbHeight > 0)
                {
                    ButtonWidget.DrawBackground(Button, 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));
            }

            var drawBounds = backgroundRect.InflateBy(-BorderWidth, -BorderWidth, -BorderWidth, -BorderWidth);

            Game.Renderer.EnableScissor(drawBounds);

            // ChildOrigin enumerates the widget tree, so only evaluate it once
            var co = ChildOrigin;

            drawBounds.X -= co.X;
            drawBounds.Y -= co.Y;

            foreach (var child in Children)
            {
                if (child.Bounds.IntersectsWith(drawBounds))
                {
                    child.DrawOuter();
                }
            }

            Game.Renderer.DisableScissor();
        }