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); }
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(); }
public static void DrawBackground(string baseName, Rectangle rect, bool disabled, bool pressed, bool hover, bool highlighted) { var variant = highlighted ? "-highlighted" : ""; var state = disabled ? "-disabled" : pressed ? "-pressed" : hover ? "-hover" : ""; WidgetUtils.DrawPanel(baseName + variant + state, rect); }
public override void Draw() { var state = IsSelected() ? BaseName + "-selected" : Ui.MouseOverWidget == this ? BaseName + "-hover" : null; if (state != null) { WidgetUtils.DrawPanel(state, RenderBounds); } }
public static void DrawBackground(string baseName, Rectangle rect, bool disabled, bool pressed, bool hover, bool highlighted) { if (string.IsNullOrEmpty(baseName)) { return; } var variantName = highlighted ? baseName + "-highlighted" : baseName; var imageName = WidgetUtils.GetStatefulImageName(variantName, disabled, pressed, hover); WidgetUtils.DrawPanel(imageName, rect); }
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(); } }
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(); }
public override void Draw() { var rb = RenderBounds; var percentage = GetPercentage(); WidgetUtils.DrawPanel("progressbar-bg", rb); var barRect = wasIndeterminate ? 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); } }
public override void Draw() { var disabled = IsDisabled(); var highlighted = IsHighlighted(); var font = Game.Renderer.Fonts[Font]; var color = GetColor(); var colordisabled = GetColorDisabled(); var bgDark = GetContrastColorDark(); var bgLight = GetContrastColorLight(); 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 topOffset = font.TopOffset; var position = new float2(rect.Left + rect.Height * 1.5f, RenderOrigin.Y + (Bounds.Height - textSize.Y - topOffset) / 2); if (Contrast) { font.DrawTextWithContrast(text, position, disabled ? colordisabled : color, bgDark, bgLight, 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); } }
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 valid = IsValid(); 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 var isTextOverflowing = textSize.X > Bounds.Width - LeftMargin - RightMargin; if (isTextOverflowing) { Game.Renderer.EnableScissor(new Rectangle(pos.X + LeftMargin, pos.Y, Bounds.Width - LeftMargin - RightMargin, Bounds.Bottom)); } var color = disabled ? TextColorDisabled : !valid ? TextColorInvalid : TextColor; font.DrawText(apparentText, textPos, color); if (isTextOverflowing) { Game.Renderer.DisableScissor(); } }
public override void Draw() { var rb = RenderBounds; var percentage = GetPercentage(); WidgetUtils.DrawPanel(Background, rb); var minBarWidth = (int)(ChromeProvider.GetImage(Bar, "border-l").Size.X + ChromeProvider.GetImage(Bar, "border-r").Size.X); var maxBarWidth = rb.Width - BarMargin.Width * 2; var barWidth = wasIndeterminate ? maxBarWidth / 4 : percentage * maxBarWidth / 100; barWidth = Math.Max(barWidth, minBarWidth); var barOffset = wasIndeterminate ? (int)(0.75 * offset * maxBarWidth) : 0; var barRect = new Rectangle(rb.X + BarMargin.Width + barOffset, rb.Y + BarMargin.Height, barWidth, rb.Height - 2 * BarMargin.Height); WidgetUtils.DrawPanel(Bar, barRect); }
public override void Draw() { // PERF: Only check for ourself or our direct children var isHover = Ui.MouseOverWidget == this; if (!IgnoreChildMouseOver && !isHover) { isHover = Children.Contains(Ui.MouseOverWidget); } var state = IsSelected() ? BaseName + "-selected" : isHover ? BaseName + "-hover" : null; if (state != null) { WidgetUtils.DrawPanel(state, RenderBounds); } }
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(); }
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(); }
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(); } }
public override void Draw() { WidgetUtils.DrawPanel(Background, RenderBounds); }