From e09cd16042154b75adc8de9ed8528f143c5282ee Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Mon, 16 May 2011 23:13:06 +1200 Subject: [PATCH] Normalize scrollpanel --- OpenRA.Game/Widgets/ScrollPanelWidget.cs | 37 +++++--- OpenRA.Mods.Cnc/Widgets/CncLobbyLogic.cs | 4 +- OpenRA.Mods.Cnc/Widgets/CncMenuButton.cs | 108 +---------------------- mods/cnc/chrome.yaml | 12 +++ mods/cnc/chrome/lobby.yaml | 4 +- mods/cnc/chrome/mapchooser.yaml | 2 +- mods/cnc/chrome/modchooser.yaml | 2 +- mods/cnc/chrome/music.yaml | 2 +- mods/cnc/chrome/preferences.yaml | 2 +- mods/cnc/chrome/replaybrowser.yaml | 2 +- mods/cnc/chrome/serverbrowser.yaml | 2 +- mods/ra/chrome.yaml | 12 +++ 12 files changed, 62 insertions(+), 127 deletions(-) diff --git a/OpenRA.Game/Widgets/ScrollPanelWidget.cs b/OpenRA.Game/Widgets/ScrollPanelWidget.cs index 2ab681536d..ca8424bcec 100644 --- a/OpenRA.Game/Widgets/ScrollPanelWidget.cs +++ b/OpenRA.Game/Widgets/ScrollPanelWidget.cs @@ -16,11 +16,11 @@ namespace OpenRA.Widgets { public class ScrollPanelWidget : Widget { - public string Background = "dialog3"; public int ScrollbarWidth = 24; public float ScrollVelocity = 4f; public int ItemSpacing = 2; - + public int ButtonDepth = ChromeMetrics.GetInt("ButtonDepth"); + public string Background = "scrollpanel-bg"; public int ContentHeight = 0; protected float ListOffset = 0; protected bool UpPressed = false; @@ -71,16 +71,24 @@ namespace OpenRA.Widgets if (thumbHeight == ScrollbarHeight) thumbHeight = 0; - backgroundRect = new Rectangle(rb.X, rb.Y, rb.Width - ScrollbarWidth, rb.Height); + 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, ScrollbarWidth, ScrollbarHeight); + scrollbarRect = new Rectangle(rb.Right - ScrollbarWidth, rb.Y + ScrollbarWidth - 1, ScrollbarWidth, ScrollbarHeight + 2); thumbRect = new Rectangle(rb.Right - ScrollbarWidth, thumbOrigin, ScrollbarWidth, thumbHeight); - string upButtonBg = UpPressed || thumbHeight == 0 ? "dialog3" : "dialog2"; - string downButtonBg = DownPressed || thumbHeight == 0 ? "dialog3" : "dialog2"; - string scrollbarBg = "dialog3"; - string thumbBg = "dialog2"; + + 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); @@ -89,9 +97,11 @@ namespace OpenRA.Widgets if (thumbHeight > 0) WidgetUtils.DrawPanel(thumbBg, thumbRect); - - var upOffset = UpPressed || thumbHeight == 0 ? 4 : 3; - var downOffset = DownPressed || thumbHeight == 0 ? 4 : 3; + + var upOffset = !UpPressed || thumbHeight == 0 || ListOffset >= 0 ? 4 : 4 + ButtonDepth; + var downOffset = !DownPressed || thumbHeight == 0 || ListOffset <= Bounds.Height - ContentHeight + ? 4 : 4 + ButtonDepth; + WidgetUtils.DrawRGBA(ChromeProvider.GetImage("scrollbar", "up_arrow"), new float2(upButtonRect.Left + upOffset, upButtonRect.Top + upOffset)); WidgetUtils.DrawRGBA(ChromeProvider.GetImage("scrollbar", "down_arrow"), @@ -118,6 +128,11 @@ namespace OpenRA.Widgets ListOffset = Math.Min(0,Math.Max(Bounds.Height - ContentHeight, ListOffset)); } + public void ScrollToBottom() + { + ListOffset = Math.Min(0,Bounds.Height - ContentHeight); + } + public override void Tick () { if (UpPressed) Scroll(1); diff --git a/OpenRA.Mods.Cnc/Widgets/CncLobbyLogic.cs b/OpenRA.Mods.Cnc/Widgets/CncLobbyLogic.cs index 448ecf607e..f0a06307f5 100755 --- a/OpenRA.Mods.Cnc/Widgets/CncLobbyLogic.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncLobbyLogic.cs @@ -23,7 +23,7 @@ namespace OpenRA.Mods.Cnc.Widgets public class CncLobbyLogic : IWidgetDelegate { Widget LocalPlayerTemplate, RemotePlayerTemplate, EmptySlotTemplate, EmptySlotTemplateHost; - CncScrollPanelWidget chatPanel; + ScrollPanelWidget chatPanel; Widget chatTemplate; ScrollPanelWidget Players; @@ -251,7 +251,7 @@ namespace OpenRA.Mods.Cnc.Widgets return true; }; - chatPanel = lobby.GetWidget("CHAT_DISPLAY"); + chatPanel = lobby.GetWidget("CHAT_DISPLAY"); chatTemplate = chatPanel.GetWidget("CHAT_TEMPLATE"); lobby.GetWidget("MUSIC_BUTTON").OnClick = () => diff --git a/OpenRA.Mods.Cnc/Widgets/CncMenuButton.cs b/OpenRA.Mods.Cnc/Widgets/CncMenuButton.cs index 10e09bde21..14ce32272e 100644 --- a/OpenRA.Mods.Cnc/Widgets/CncMenuButton.cs +++ b/OpenRA.Mods.Cnc/Widgets/CncMenuButton.cs @@ -49,79 +49,7 @@ namespace OpenRA.Mods.Cnc.Widgets public override Widget Clone() { return new CncCheckboxWidget(this); } } - - public class CncScrollPanelWidget : ScrollPanelWidget - { - public CncScrollPanelWidget() - : base() - { - Background = "panel-gray"; - } - protected CncScrollPanelWidget(CncScrollPanelWidget widget) - : base(widget) { } - - public override void Draw() - { - if (!IsVisible()) - return; - - var rb = RenderBounds; - - var ScrollbarHeight = rb.Height - 2 * ScrollbarWidth; - - var thumbHeight = ContentHeight == 0 ? 0 : (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); - - 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 = "panel-gray"; - string thumbBg = (Focused && thumbRect.Contains(Viewport.LastMousePos)) ? "button-pressed" : - thumbRect.Contains(Viewport.LastMousePos) ? "button-hover" : "button"; - - WidgetUtils.DrawPanel(scrollbarBg, scrollbarRect); - WidgetUtils.DrawPanel(Background, backgroundRect); - WidgetUtils.DrawPanel(upButtonBg, upButtonRect); - WidgetUtils.DrawPanel(downButtonBg, downButtonRect); - - if (thumbHeight > 0) - WidgetUtils.DrawPanel(thumbBg, thumbRect); - - WidgetUtils.DrawRGBA(ChromeProvider.GetImage("scrollbar", "up_arrow"), - new float2(upButtonRect.Left + 4, upButtonRect.Top + 4)); - WidgetUtils.DrawRGBA(ChromeProvider.GetImage("scrollbar", "down_arrow"), - new float2(downButtonRect.Left + 4, downButtonRect.Top + 4)); - - Game.Renderer.EnableScissor(backgroundRect.X + 1, backgroundRect.Y + 1, backgroundRect.Width - 2, backgroundRect.Height - 2); - - foreach (var child in Children) - child.Draw(); - - Game.Renderer.DisableScissor(); - } - - public void ScrollToBottom() - { - ListOffset = Math.Min(0,Bounds.Height - ContentHeight); - } - - public override Widget Clone() { return new CncScrollPanelWidget(this); } - } - public class CncSliderWidget : SliderWidget { public Func IsDisabled = () => false; @@ -163,45 +91,13 @@ namespace OpenRA.Mods.Cnc.Widgets public class CncDropDownButtonWidget : DropDownButtonWidget { - public Func IsDisabled = () => false; - public string Font = "Bold"; - public CncDropDownButtonWidget() : base() { } - protected CncDropDownButtonWidget(CncDropDownButtonWidget other) : base(other) - { - Font = other.Font; - } - + protected CncDropDownButtonWidget(CncDropDownButtonWidget other) : base(other) { } public override Widget Clone() { return new CncDropDownButtonWidget(this); } - public override void DrawInner() - { - var rb = RenderBounds; - var state = IsDisabled() ? "button-disabled" : - Depressed ? "button-pressed" : - rb.Contains(Viewport.LastMousePos) ? "button-hover" : - "button"; - - WidgetUtils.DrawPanel(state, rb); - - var font = Game.Renderer.Fonts[Font]; - var text = GetText(); - font.DrawText(text, - new int2(rb.X + UsableWidth / 2, rb.Y + Bounds.Height / 2) - - new int2(font.Measure(text).X / 2, - font.Measure(text).Y / 2), IsDisabled() ? Color.Gray : Color.White); - - var image = ChromeProvider.GetImage("scrollbar", "down_arrow"); - WidgetUtils.DrawRGBA( image, new float2(rb.Right - rb.Height + 4, - rb.Top + (rb.Height - image.bounds.Height) / 2)); - - WidgetUtils.FillRectWithColor(new Rectangle(rb.Right - rb.Height, rb.Top + 3, 1, rb.Height - 6), - Color.White); - } - public static new void ShowDropDown(Widget w, IEnumerable ts, Func ft) { - var dropDown = new CncScrollPanelWidget(); + var dropDown = new ScrollPanelWidget(); dropDown.Bounds = new Rectangle(w.RenderOrigin.X, w.RenderOrigin.Y + w.Bounds.Height, w.Bounds.Width, 100); dropDown.ItemSpacing = 1; dropDown.Background = "panel-black"; diff --git a/mods/cnc/chrome.yaml b/mods/cnc/chrome.yaml index 21aa860a90..a115467b7c 100644 --- a/mods/cnc/chrome.yaml +++ b/mods/cnc/chrome.yaml @@ -121,6 +121,18 @@ progressbar-thumb: chrome.png corner-br: 62,190,2,2 +# A copy of panel-gray +scrollpanel-bg: chrome.png + background: 66,66,60,60 + border-r: 126,66,2,60 + border-l: 64,66,2,60 + border-b: 66,126,60,2 + border-t: 66,64,60,2 + corner-tl: 64,64,2,2 + corner-tr: 126,64,2,2 + corner-bl: 64,126,2,2 + corner-br: 126,126,2,2 + # A copy of button-hover scrollitem-hover: chrome.png background: 2,130,60,60 diff --git a/mods/cnc/chrome/lobby.yaml b/mods/cnc/chrome/lobby.yaml index 6886a12613..a7400d5ac9 100644 --- a/mods/cnc/chrome/lobby.yaml +++ b/mods/cnc/chrome/lobby.yaml @@ -45,7 +45,7 @@ Container@SERVER_LOBBY: Width:130 Height:20 Text: Allow Cheats - CncScrollPanel@PLAYERS: + ScrollPanel@PLAYERS: Id:PLAYERS X:15 Y:30 @@ -306,7 +306,7 @@ Container@SERVER_LOBBY: Text:Ready Align:Left Font:Bold - CncScrollPanel@CHAT_DISPLAY: + ScrollPanel@CHAT_DISPLAY: Id:CHAT_DISPLAY X:15 Y:285 diff --git a/mods/cnc/chrome/mapchooser.yaml b/mods/cnc/chrome/mapchooser.yaml index d33c06986d..9215b98e33 100644 --- a/mods/cnc/chrome/mapchooser.yaml +++ b/mods/cnc/chrome/mapchooser.yaml @@ -31,7 +31,7 @@ Container@MAPCHOOSER_PANEL: Y:1 Width:192 Height:192 - CncScrollPanel@MAP_LIST: + ScrollPanel@MAP_LIST: Id:MAP_LIST X:15 Y:30 diff --git a/mods/cnc/chrome/modchooser.yaml b/mods/cnc/chrome/modchooser.yaml index bdeac5b4c3..7e23bb4e43 100644 --- a/mods/cnc/chrome/modchooser.yaml +++ b/mods/cnc/chrome/modchooser.yaml @@ -18,7 +18,7 @@ Container@MODS_PANEL: Height:500 Background:panel-black Children: - CncScrollPanel@MOD_LIST: + ScrollPanel@MOD_LIST: Id:MOD_LIST X:15 Y:30 diff --git a/mods/cnc/chrome/music.yaml b/mods/cnc/chrome/music.yaml index 5481776e60..b08b0ad24a 100644 --- a/mods/cnc/chrome/music.yaml +++ b/mods/cnc/chrome/music.yaml @@ -18,7 +18,7 @@ Container@MUSIC_PANEL: Height:400 Background:panel-black Children: - CncScrollPanel@MUSIC_LIST: + ScrollPanel@MUSIC_LIST: Id:MUSIC_LIST X:15 Y:30 diff --git a/mods/cnc/chrome/preferences.yaml b/mods/cnc/chrome/preferences.yaml index 300f316978..ba5b6045b8 100644 --- a/mods/cnc/chrome/preferences.yaml +++ b/mods/cnc/chrome/preferences.yaml @@ -327,7 +327,7 @@ Container@SETTINGS_PANEL: # Height:25 # Align:Right # Text:Key -# CncScrollPanel@KEYBINDINGS: +# ScrollPanel@KEYBINDINGS: # Id:KEYBINDINGS # X:375 # Y:85 diff --git a/mods/cnc/chrome/replaybrowser.yaml b/mods/cnc/chrome/replaybrowser.yaml index 62f2d0f4b9..5e8f3b84fd 100644 --- a/mods/cnc/chrome/replaybrowser.yaml +++ b/mods/cnc/chrome/replaybrowser.yaml @@ -18,7 +18,7 @@ Container@REPLAYBROWSER_PANEL: Height:300 Background:panel-black Children: - CncScrollPanel@REPLAY_LIST: + ScrollPanel@REPLAY_LIST: Id:REPLAY_LIST X:15 Y:15 diff --git a/mods/cnc/chrome/serverbrowser.yaml b/mods/cnc/chrome/serverbrowser.yaml index a15faad75e..1d8aabcbbc 100644 --- a/mods/cnc/chrome/serverbrowser.yaml +++ b/mods/cnc/chrome/serverbrowser.yaml @@ -18,7 +18,7 @@ Container@SERVERBROWSER_PANEL: Height:500 Background:panel-black Children: - CncScrollPanel@SERVER_LIST: + ScrollPanel@SERVER_LIST: Id:SERVER_LIST X:15 Y:30 diff --git a/mods/ra/chrome.yaml b/mods/ra/chrome.yaml index 4163d03b78..0b177630f8 100644 --- a/mods/ra/chrome.yaml +++ b/mods/ra/chrome.yaml @@ -333,3 +333,15 @@ textfield-focused: dialog.png corner-tr: 722,0,1,1 corner-bl: 640,82,1,1 corner-br: 722,82,1,1 + +# A copy of dialog3 +scrollpanel-bg: dialog.png + background: 641,1,126,126 + border-r: 767,1,1,126 + border-l: 640,1,1,126 + border-b: 641,127,126,1 + border-t: 641,0,126,1 + corner-tl: 640,0,1,1 + corner-tr: 722,0,1,1 + corner-bl: 640,82,1,1 + corner-br: 722,82,1,1