Makes ButtonWidget and Widgets based on it more customizable, sets defaults in metrics.yaml.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||
* Copyright 2007-2013 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
@@ -27,9 +27,16 @@ namespace OpenRA.Widgets
|
||||
public bool Depressed = false;
|
||||
public int VisualHeight = ChromeMetrics.Get<int>("ButtonDepth");
|
||||
public string Font = ChromeMetrics.Get<string>("ButtonFont");
|
||||
public Color TextColor = ChromeMetrics.Get<Color>("ButtonTextColor");
|
||||
public Color TextColorDisabled = ChromeMetrics.Get<Color>("ButtonTextColorDisabled");
|
||||
public bool Contrast = ChromeMetrics.Get<bool>("ButtonTextContrast");
|
||||
public Color ContrastColor = ChromeMetrics.Get<Color>("ButtonTextContrastColor");
|
||||
public bool Disabled = false;
|
||||
public bool Highlighted = false;
|
||||
public Func<string> GetText;
|
||||
public Func<Color> GetColor;
|
||||
public Func<Color> GetColorDisabled;
|
||||
public Func<Color> GetContrastColor;
|
||||
public Func<bool> IsDisabled;
|
||||
public Func<bool> IsHighlighted;
|
||||
public Action<MouseInput> OnMouseDown = _ => {};
|
||||
@@ -48,6 +55,9 @@ namespace OpenRA.Widgets
|
||||
public ButtonWidget()
|
||||
{
|
||||
GetText = () => { return Text; };
|
||||
GetColor = () => TextColor;
|
||||
GetColorDisabled = () => TextColorDisabled;
|
||||
GetContrastColor = () => ContrastColor;
|
||||
OnMouseUp = _ => OnClick();
|
||||
OnKeyPress = _ => OnClick();
|
||||
IsDisabled = () => Disabled;
|
||||
@@ -61,9 +71,16 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
Text = other.Text;
|
||||
Font = other.Font;
|
||||
TextColor = other.TextColor;
|
||||
TextColorDisabled = other.TextColorDisabled;
|
||||
Contrast = other.Contrast;
|
||||
ContrastColor = other.ContrastColor;
|
||||
Depressed = other.Depressed;
|
||||
VisualHeight = other.VisualHeight;
|
||||
GetText = other.GetText;
|
||||
GetColor = other.GetColor;
|
||||
GetColorDisabled = other.GetColorDisabled;
|
||||
GetContrastColor = other.GetContrastColor;
|
||||
OnMouseDown = other.OnMouseDown;
|
||||
Disabled = other.Disabled;
|
||||
IsDisabled = other.IsDisabled;
|
||||
@@ -172,12 +189,19 @@ namespace OpenRA.Widgets
|
||||
|
||||
var font = Game.Renderer.Fonts[Font];
|
||||
var text = GetText();
|
||||
var color = GetColor();
|
||||
var colordisabled = GetColorDisabled();
|
||||
var contrast = GetContrastColor();
|
||||
var s = font.Measure(text);
|
||||
var stateOffset = (Depressed) ? new int2(VisualHeight, VisualHeight) : new int2(0, 0);
|
||||
|
||||
DrawBackground(rb, disabled, Depressed, Ui.MouseOverWidget == this, highlighted);
|
||||
if (Contrast)
|
||||
font.DrawTextWithContrast(text, new int2(rb.X + (UsableWidth - s.X) / 2, rb.Y + (Bounds.Height - s.Y) / 2) + stateOffset,
|
||||
disabled ? colordisabled : color, contrast, 2);
|
||||
else
|
||||
font.DrawText(text, new int2(rb.X + (UsableWidth - s.X)/ 2, rb.Y + (Bounds.Height - s.Y) / 2) + stateOffset,
|
||||
disabled ? Color.Gray : Color.White);
|
||||
disabled ? colordisabled : color);
|
||||
}
|
||||
|
||||
public override Widget Clone() { return new ButtonWidget(this); }
|
||||
|
||||
@@ -43,6 +43,9 @@ namespace OpenRA.Widgets
|
||||
{
|
||||
var disabled = IsDisabled();
|
||||
var font = Game.Renderer.Fonts[Font];
|
||||
var color = GetColor();
|
||||
var colordisabled = GetColorDisabled();
|
||||
var contrast = GetContrastColor();
|
||||
var rect = RenderBounds;
|
||||
var check = new Rectangle(rect.Location, new Size(Bounds.Height, Bounds.Height));
|
||||
var state = disabled ? "checkbox-disabled" :
|
||||
@@ -53,9 +56,15 @@ namespace OpenRA.Widgets
|
||||
WidgetUtils.DrawPanel(state, check);
|
||||
|
||||
var textSize = font.Measure(Text);
|
||||
|
||||
if (Contrast)
|
||||
font.DrawTextWithContrast(Text,
|
||||
new float2(rect.Left + rect.Height * 1.5f, RenderOrigin.Y - BaseLine + (Bounds.Height - textSize.Y)/2),
|
||||
disabled ? colordisabled : color, contrast, 2);
|
||||
else
|
||||
font.DrawText(Text,
|
||||
new float2(rect.Left + rect.Height * 1.5f, RenderOrigin.Y - BaseLine + (Bounds.Height - textSize.Y)/2),
|
||||
disabled ? Color.Gray : Color.White);
|
||||
disabled ? colordisabled : color);
|
||||
|
||||
if (IsChecked() || (Depressed && HasPressedState && !disabled))
|
||||
{
|
||||
|
||||
@@ -31,6 +31,8 @@ namespace OpenRA.Widgets
|
||||
|
||||
var image = ChromeProvider.GetImage("scrollbar", IsDisabled() ? "down_pressed" : "down_arrow");
|
||||
var rb = RenderBounds;
|
||||
var color = GetColor();
|
||||
var colordisabled = GetColorDisabled();
|
||||
|
||||
WidgetUtils.DrawRGBA( image,
|
||||
stateOffset + new float2( rb.Right - rb.Height + 4,
|
||||
@@ -38,7 +40,7 @@ namespace OpenRA.Widgets
|
||||
|
||||
WidgetUtils.FillRectWithColor(new Rectangle(stateOffset.X + rb.Right - rb.Height,
|
||||
stateOffset.Y + rb.Top + 3, 1, rb.Height - 6),
|
||||
Color.White);
|
||||
IsDisabled() ? colordisabled : color);
|
||||
}
|
||||
|
||||
public override Widget Clone() { return new DropDownButtonWidget(this); }
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
Metrics:
|
||||
ButtonDepth: 0
|
||||
ButtonFont: Bold
|
||||
ButtonTextColor: 255,255,255
|
||||
ButtonTextColorDisabled: 128,128,128
|
||||
ButtonTextContrast: false
|
||||
ButtonTextContrastColor: 0,0,0
|
||||
CheckboxPressedState: true
|
||||
TextFont: Regular
|
||||
TextColor: 255,255,255
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
Metrics:
|
||||
ButtonDepth: 1
|
||||
ButtonFont: Regular
|
||||
ButtonTextColor: 255,255,255
|
||||
ButtonTextColorDisabled: 128,128,128
|
||||
ButtonTextContrast: false
|
||||
ButtonTextContrastColor: 0,0,0
|
||||
CheckboxPressedState: false
|
||||
TextFont: Regular
|
||||
TextColor: 255,255,255
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
Metrics:
|
||||
ButtonDepth: 1
|
||||
ButtonFont: Regular
|
||||
ButtonTextColor: 255,255,255
|
||||
ButtonTextColorDisabled: 128,128,128
|
||||
ButtonTextContrast: true
|
||||
ButtonTextContrastColor: 0,0,0
|
||||
CheckboxPressedState: false
|
||||
TextFont: Regular
|
||||
TextColor: 255,255,255
|
||||
|
||||
@@ -3,6 +3,10 @@
|
||||
Metrics:
|
||||
ButtonDepth: 1
|
||||
ButtonFont: Regular
|
||||
ButtonTextColor: 255,255,255
|
||||
ButtonTextColorDisabled: 128,128,128
|
||||
ButtonTextContrast: false
|
||||
ButtonTextContrastColor: 0,0,0
|
||||
CheckboxPressedState: false
|
||||
TextFont: Regular
|
||||
TextColor: 255,255,255
|
||||
|
||||
Reference in New Issue
Block a user