Merge pull request #4156 from reaperrr/widgets04

Improved Widget text customizability rev.2
This commit is contained in:
Paul Chote
2013-11-27 00:47:00 -08:00
15 changed files with 137 additions and 31 deletions

View File

@@ -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,20 @@ 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);
var position = new int2(rb.X + (UsableWidth - s.X) / 2, rb.Y + (Bounds.Height - s.Y) / 2);
DrawBackground(rb, disabled, Depressed, Ui.MouseOverWidget == this, highlighted);
font.DrawText(text, new int2(rb.X + (UsableWidth - s.X)/ 2, rb.Y + (Bounds.Height - s.Y) / 2) + stateOffset,
disabled ? Color.Gray : Color.White);
if (Contrast)
font.DrawTextWithContrast(text, position + stateOffset,
disabled ? colordisabled : color, contrast, 2);
else
font.DrawText(text, position + stateOffset,
disabled ? colordisabled : color);
}
public override Widget Clone() { return new ButtonWidget(this); }

View File

@@ -43,7 +43,11 @@ 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 textSize = font.Measure(Text);
var check = new Rectangle(rect.Location, new Size(Bounds.Height, Bounds.Height));
var state = disabled ? "checkbox-disabled" :
Depressed && HasPressedState ? "checkbox-pressed" :
@@ -51,11 +55,14 @@ namespace OpenRA.Widgets
"checkbox";
WidgetUtils.DrawPanel(state, check);
var position = new float2(rect.Left + rect.Height * 1.5f, RenderOrigin.Y - BaseLine + (Bounds.Height - textSize.Y)/2);
var textSize = font.Measure(Text);
font.DrawText(Text,
new float2(rect.Left + rect.Height * 1.5f, RenderOrigin.Y - BaseLine + (Bounds.Height - textSize.Y)/2),
disabled ? Color.Gray : Color.White);
if (Contrast)
font.DrawTextWithContrast(Text, position,
disabled ? colordisabled : color, contrast, 2);
else
font.DrawText(Text, position,
disabled ? colordisabled : color);
if (IsChecked() || (Depressed && HasPressedState && !disabled))
{

View File

@@ -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); }

View File

@@ -25,9 +25,9 @@ namespace OpenRA.Widgets
public Action OnLoseFocus = () => { };
public Func<bool> IsDisabled = () => false;
public Color TextColor = Color.White;
public Color DisabledColor = Color.Gray;
public string Font = "Regular";
public string Font = ChromeMetrics.Get<string>("HotkeyFont");
public Color TextColor = ChromeMetrics.Get<Color>("HotkeyColor");
public Color TextColorDisabled = ChromeMetrics.Get<Color>("HotkeyColorDisabled");
public HotkeyEntryWidget() {}
protected HotkeyEntryWidget(HotkeyEntryWidget widget)
@@ -35,7 +35,7 @@ namespace OpenRA.Widgets
{
Font = widget.Font;
TextColor = widget.TextColor;
DisabledColor = widget.DisabledColor;
TextColorDisabled = widget.TextColorDisabled;
VisualHeight = widget.VisualHeight;
}
@@ -126,7 +126,7 @@ namespace OpenRA.Widgets
Bounds.Width - LeftMargin - RightMargin, Bounds.Bottom));
}
var color = disabled ? DisabledColor : TextColor;
var color = disabled ? TextColorDisabled : TextColor;
font.DrawText(apparentText, textPos, color);
if (textSize.X > Bounds.Width - LeftMargin - RightMargin)

View File

@@ -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,
@@ -23,10 +23,10 @@ namespace OpenRA.Widgets
[Translate] public string Text = null;
public TextAlign Align = TextAlign.Left;
public TextVAlign VAlign = TextVAlign.Middle;
public string Font = "Regular";
public Color Color = Color.White;
public bool Contrast = false;
public Color ContrastColor = Color.Black;
public string Font = ChromeMetrics.Get<string>("TextFont");
public Color TextColor = ChromeMetrics.Get<Color>("TextColor");
public bool Contrast = ChromeMetrics.Get<bool>("TextContrast");
public Color ContrastColor = ChromeMetrics.Get<Color>("TextContrastColor");
public bool WordWrap = false;
public Func<string> GetText;
public Func<Color> GetColor;
@@ -35,7 +35,7 @@ namespace OpenRA.Widgets
public LabelWidget()
{
GetText = () => Text;
GetColor = () => Color;
GetColor = () => TextColor;
GetContrastColor = () => ContrastColor;
}
@@ -45,7 +45,7 @@ namespace OpenRA.Widgets
Text = other.Text;
Align = other.Align;
Font = other.Font;
Color = other.Color;
TextColor = other.TextColor;
Contrast = other.Contrast;
ContrastColor = other.ContrastColor;
WordWrap = other.WordWrap;

View File

@@ -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,
@@ -34,9 +34,9 @@ namespace OpenRA.Widgets
public int CursorPosition { get; set; }
public Func<bool> IsDisabled = () => false;
public Color TextColor = Color.White;
public Color DisabledColor = Color.Gray;
public string Font = "Regular";
public string Font = ChromeMetrics.Get<string>("TextfieldFont");
public Color TextColor = ChromeMetrics.Get<Color>("TextfieldColor");
public Color TextColorDisabled = ChromeMetrics.Get<Color>("TextfieldColorDisabled");
public TextFieldWidget() {}
protected TextFieldWidget(TextFieldWidget widget)
@@ -46,7 +46,7 @@ namespace OpenRA.Widgets
MaxLength = widget.MaxLength;
Font = widget.Font;
TextColor = widget.TextColor;
DisabledColor = widget.DisabledColor;
TextColorDisabled = widget.TextColorDisabled;
VisualHeight = widget.VisualHeight;
}
@@ -215,11 +215,11 @@ namespace OpenRA.Widgets
Bounds.Width - LeftMargin - RightMargin, Bounds.Bottom));
}
var color = disabled ? DisabledColor : TextColor;
var color = disabled ? TextColorDisabled : TextColor;
font.DrawText(apparentText, textPos, color);
if (showCursor && HasKeyboardFocus)
font.DrawText("|", new float2(textPos.X + cursorPosition.X - 2, textPos.Y), Color.White);
font.DrawText("|", new float2(textPos.X + cursorPosition.X - 2, textPos.Y), TextColor);
if (textSize.X > Bounds.Width - LeftMargin - RightMargin)
Game.Renderer.DisableScissor();

View File

@@ -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,
@@ -8,20 +8,28 @@
*/
#endregion
using System;
using System.Drawing;
using OpenRA.FileFormats;
using OpenRA.Graphics;
namespace OpenRA.Widgets
{
public class TimerWidget : Widget
public class TimerWidget : LabelWidget
{
public override void Draw()
{
var font = Game.Renderer.Fonts["Title"];
var font = Game.Renderer.Fonts[Font];
var rb = RenderBounds;
var color = GetColor();
var contrast = GetContrastColor();
var s = WidgetUtils.FormatTime(Game.LocalTick) + (Game.orderManager.world.Paused?" (paused)":"");
var pos = new float2(rb.Left - font.Measure(s).X / 2, rb.Top);
font.DrawTextWithContrast(s, pos, Color.White, Color.Black, 1);
if (Contrast)
font.DrawTextWithContrast(s, pos, color, contrast, 1);
else
font.DrawText(s, pos, color);
}
}
}