diff --git a/OpenRA.Game/Widgets/ButtonWidget.cs b/OpenRA.Game/Widgets/ButtonWidget.cs index c1071e31fe..673a5948d8 100644 --- a/OpenRA.Game/Widgets/ButtonWidget.cs +++ b/OpenRA.Game/Widgets/ButtonWidget.cs @@ -99,15 +99,10 @@ namespace OpenRA.Widgets Font = "Bold"; var font = Game.Renderer.Fonts[Font]; - var state = IsDisabled() ? "button-disabled" : - Depressed ? "button-pressed" : - rb.Contains(Viewport.LastMousePos) ? "button-hover" : - "button"; - - WidgetUtils.DrawPanel(state, rb); var text = GetText(); var stateOffset = (Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0); + DrawBackground(rb, IsDisabled(), Depressed, rb.Contains(Viewport.LastMousePos)); font.DrawText(text, new int2(rb.X + UsableWidth / 2, rb.Y + Bounds.Height / 2) - new int2(font.Measure(text).X / 2, @@ -116,6 +111,16 @@ namespace OpenRA.Widgets public override Widget Clone() { return new ButtonWidget(this); } public virtual int UsableWidth { get { return Bounds.Width; } } + + public static void DrawBackground(Rectangle rect, bool disabled, bool pressed, bool hover) + { + var state = disabled ? "button-disabled" : + pressed ? "button-pressed" : + hover ? "button-hover" : + "button"; + + WidgetUtils.DrawPanel(state, rect); + } } public class DropDownButtonWidget : ButtonWidget diff --git a/OpenRA.Game/Widgets/ScrollPanelWidget.cs b/OpenRA.Game/Widgets/ScrollPanelWidget.cs index ca8424bcec..02ffffe864 100644 --- a/OpenRA.Game/Widgets/ScrollPanelWidget.cs +++ b/OpenRA.Game/Widgets/ScrollPanelWidget.cs @@ -77,26 +77,16 @@ namespace OpenRA.Widgets scrollbarRect = new Rectangle(rb.Right - ScrollbarWidth, rb.Y + ScrollbarWidth - 1, ScrollbarWidth, ScrollbarHeight + 2); thumbRect = new Rectangle(rb.Right - ScrollbarWidth, thumbOrigin, ScrollbarWidth, thumbHeight); - - string upButtonBg = (thumbHeight == 0 || ListOffset >= 0) ? "button-disabled" : - UpPressed ? "button-pressed" : - upButtonRect.Contains(Viewport.LastMousePos) ? "button-hover" : "button"; - - string downButtonBg = (thumbHeight == 0 || ListOffset <= Bounds.Height - ContentHeight) ? "button-disabled" : - DownPressed ? "button-pressed" : - downButtonRect.Contains(Viewport.LastMousePos) ? "button-hover" : "button"; - - string scrollbarBg = "scrollpanel-bg"; - string thumbBg = (Focused && thumbRect.Contains(Viewport.LastMousePos)) ? "button-pressed" : - thumbRect.Contains(Viewport.LastMousePos) ? "button-hover" : "button"; - WidgetUtils.DrawPanel(Background, backgroundRect); - WidgetUtils.DrawPanel(upButtonBg, upButtonRect); - WidgetUtils.DrawPanel(downButtonBg, downButtonRect); - WidgetUtils.DrawPanel(scrollbarBg, scrollbarRect); + WidgetUtils.DrawPanel("scrollpanel-bg", scrollbarRect); + ButtonWidget.DrawBackground(upButtonRect, (thumbHeight == 0 || ListOffset >= 0), + UpPressed, upButtonRect.Contains(Viewport.LastMousePos)); + ButtonWidget.DrawBackground(downButtonRect, (thumbHeight == 0 || ListOffset <= Bounds.Height - ContentHeight), + DownPressed, downButtonRect.Contains(Viewport.LastMousePos)); if (thumbHeight > 0) - WidgetUtils.DrawPanel(thumbBg, thumbRect); + ButtonWidget.DrawBackground(thumbRect, false, (Focused && thumbRect.Contains(Viewport.LastMousePos)), + thumbRect.Contains(Viewport.LastMousePos)); var upOffset = !UpPressed || thumbHeight == 0 || ListOffset >= 0 ? 4 : 4 + ButtonDepth; var downOffset = !DownPressed || thumbHeight == 0 || ListOffset <= Bounds.Height - ContentHeight diff --git a/OpenRA.Game/Widgets/SliderWidget.cs b/OpenRA.Game/Widgets/SliderWidget.cs index d682a3d84a..78644adaf1 100755 --- a/OpenRA.Game/Widgets/SliderWidget.cs +++ b/OpenRA.Game/Widgets/SliderWidget.cs @@ -197,12 +197,7 @@ namespace OpenRA.Widgets WidgetUtils.DrawPanel("slider-track", trackRect); // Thumb - var state = IsDisabled() ? "button-disabled" : - isMoving ? "button-pressed" : - tr.Contains(Viewport.LastMousePos) ? "button-hover" : - "button"; - - WidgetUtils.DrawPanel(state, tr); + ButtonWidget.DrawBackground(tr, IsDisabled(), isMoving, tr.Contains(Viewport.LastMousePos)); } } } diff --git a/OpenRA.Mods.Cnc/Widgets/CncMenuButton.cs b/OpenRA.Mods.Cnc/Widgets/CncMenuButton.cs index 624a28ac8b..f7b9c21e40 100644 --- a/OpenRA.Mods.Cnc/Widgets/CncMenuButton.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncMenuButton.cs @@ -28,14 +28,10 @@ namespace OpenRA.Mods.Cnc.Widgets public override void DrawInner() { - var state = IsDisabled() ? "button-disabled" : - Depressed ? "button-pressed" : - RenderBounds.Contains(Viewport.LastMousePos) ? "button-hover" : - "button"; - var font = Game.Renderer.Fonts[Font]; var rect = RenderBounds; - WidgetUtils.DrawPanel(state, new Rectangle(rect.Location, new Size(Bounds.Height, Bounds.Height))); + ButtonWidget.DrawBackground(new Rectangle(rect.Location, new Size(Bounds.Height, Bounds.Height)), + IsDisabled(), Depressed, RenderBounds.Contains(Viewport.LastMousePos)); var textSize = font.Measure(Text); font.DrawText(Text,