Normalize scrollpanel
This commit is contained in:
@@ -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);
|
||||
@@ -90,8 +98,10 @@ 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);
|
||||
|
||||
@@ -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<CncScrollPanelWidget>("CHAT_DISPLAY");
|
||||
chatPanel = lobby.GetWidget<ScrollPanelWidget>("CHAT_DISPLAY");
|
||||
chatTemplate = chatPanel.GetWidget("CHAT_TEMPLATE");
|
||||
|
||||
lobby.GetWidget<ButtonWidget>("MUSIC_BUTTON").OnClick = () =>
|
||||
|
||||
@@ -50,78 +50,6 @@ 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<bool> IsDisabled = () => false;
|
||||
@@ -163,45 +91,13 @@ namespace OpenRA.Mods.Cnc.Widgets
|
||||
|
||||
public class CncDropDownButtonWidget : DropDownButtonWidget
|
||||
{
|
||||
public Func<bool> 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<T>(Widget w, IEnumerable<T> ts, Func<T, int, LabelWidget> 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";
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -327,7 +327,7 @@ Container@SETTINGS_PANEL:
|
||||
# Height:25
|
||||
# Align:Right
|
||||
# Text:Key
|
||||
# CncScrollPanel@KEYBINDINGS:
|
||||
# ScrollPanel@KEYBINDINGS:
|
||||
# Id:KEYBINDINGS
|
||||
# X:375
|
||||
# Y:85
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user