Skip to content

Commit

Permalink
Add option for Background based on Delta
Browse files Browse the repository at this point in the history
  • Loading branch information
wooferzfg committed Aug 15, 2015
1 parent 8b237a9 commit fbacda1
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 39 deletions.
1 change: 1 addition & 0 deletions LiveSplit.Timer.csproj
Expand Up @@ -52,6 +52,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="UI\Components\DeltasGradientType.cs" />
<Compile Include="UI\Components\Timer.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UI\Components\TimerFactory.cs" />
Expand Down
7 changes: 7 additions & 0 deletions UI/Components/DeltasGradientType.cs
@@ -0,0 +1,7 @@
namespace LiveSplit.UI
{
public enum DeltasGradientType
{
Plain, Vertical, Horizontal, PlainWithDeltaColor, VerticalWithDeltaColor, HorizontalWithDeltaColor
}
}
85 changes: 58 additions & 27 deletions UI/Components/Timer.cs
Expand Up @@ -21,6 +21,8 @@ public class Timer : IComponent
protected Font TimerFont { get; set; }
protected float PreviousDecimalsSize { get; set; }

public Color TimerColor = Color.Transparent;

protected String CurrentFormat { get; set; }
protected TimeAccuracy CurrentAccuracy { get; set; }
protected TimeFormat CurrentTimeFormat { get; set; }
Expand Down Expand Up @@ -94,25 +96,54 @@ public Timer()
Settings = new TimerSettings();
UpdateTimeFormat();
Cache = new GraphicsCache();
TimerColor = Color.Transparent;
}

private void DrawGeneral(Graphics g, LiveSplitState state, float width, float height)
public static void DrawBackground(Graphics g, Color timerColor, Color settingsColor1, Color settingsColor2,
float width, float height, DeltasGradientType gradientType)
{
if (Settings.BackgroundColor.ToArgb() != Color.Transparent.ToArgb()
|| Settings.BackgroundGradient != GradientType.Plain
&& Settings.BackgroundColor2.ToArgb() != Color.Transparent.ToArgb())
var background1 = settingsColor1;
var background2 = settingsColor2;
if (gradientType == DeltasGradientType.PlainWithDeltaColor
|| gradientType == DeltasGradientType.HorizontalWithDeltaColor
|| gradientType == DeltasGradientType.VerticalWithDeltaColor)
{
double h, s, v;
timerColor.ToHSV(out h, out s, out v);
var newColor = ColorExtensions.FromHSV(h, s * 0.5, v * 0.25);

if (gradientType == DeltasGradientType.PlainWithDeltaColor)
{
background1 = Color.FromArgb(timerColor.A * 7 / 12, newColor);
}
else
{
background1 = Color.FromArgb(timerColor.A / 6, newColor);
background2 = Color.FromArgb(timerColor.A, newColor);
}
}
if (background1.ToArgb() != Color.Transparent.ToArgb()
|| gradientType != DeltasGradientType.Plain
&& background2.ToArgb() != Color.Transparent.ToArgb())
{
var gradientBrush = new LinearGradientBrush(
new PointF(0, 0),
Settings.BackgroundGradient == GradientType.Horizontal
gradientType == DeltasGradientType.Horizontal
|| gradientType == DeltasGradientType.HorizontalWithDeltaColor
? new PointF(width, 0)
: new PointF(0, height),
Settings.BackgroundColor,
Settings.BackgroundGradient == GradientType.Plain
? Settings.BackgroundColor
: Settings.BackgroundColor2);
background1,
gradientType == DeltasGradientType.Plain
|| gradientType == DeltasGradientType.PlainWithDeltaColor
? background1
: background2);
g.FillRectangle(gradientBrush, 0, 0, width, height);
}
}

private void DrawGeneral(Graphics g, LiveSplitState state, float width, float height)
{
DrawBackground(g, TimerColor, Settings.BackgroundColor, Settings.BackgroundColor2, width, height, Settings.BackgroundGradient);

if (state.LayoutSettings.TimerFont != TimerFont || Settings.DecimalsSize != PreviousDecimalsSize)
{
Expand Down Expand Up @@ -318,45 +349,45 @@ public void Update(IInvalidator invalidator, LiveSplitState state, float width,
BigTextLabel.Text = "";
}

if (Settings.OverrideSplitColors)
if (state.CurrentPhase == TimerPhase.NotRunning || state.CurrentTime[timingMethod] < TimeSpan.Zero)
{
BigTextLabel.ForeColor = Settings.TimerColor;
SmallTextLabel.ForeColor = Settings.TimerColor;
}
else if (state.CurrentPhase == TimerPhase.NotRunning || state.CurrentTime[timingMethod] < TimeSpan.Zero)
{
BigTextLabel.ForeColor = state.LayoutSettings.NotRunningColor;
SmallTextLabel.ForeColor = state.LayoutSettings.NotRunningColor;
TimerColor = state.LayoutSettings.NotRunningColor;
}
else if (state.CurrentPhase == TimerPhase.Paused)
{
BigTextLabel.ForeColor = SmallTextLabel.ForeColor = state.LayoutSettings.PausedColor;
TimerColor = state.LayoutSettings.PausedColor;
}
else if (state.CurrentPhase == TimerPhase.Ended)
{
if (state.Run.Last().Comparisons[state.CurrentComparison][timingMethod] == null || state.CurrentTime[timingMethod] < state.Run.Last().Comparisons[state.CurrentComparison][timingMethod])
{
BigTextLabel.ForeColor = state.LayoutSettings.PersonalBestColor;
SmallTextLabel.ForeColor = state.LayoutSettings.PersonalBestColor;
TimerColor = state.LayoutSettings.PersonalBestColor;
}
else
{
BigTextLabel.ForeColor = state.LayoutSettings.BehindLosingTimeColor;
SmallTextLabel.ForeColor = state.LayoutSettings.BehindLosingTimeColor;
TimerColor = state.LayoutSettings.BehindLosingTimeColor;
}
}
else if (state.CurrentPhase == TimerPhase.Running)
{
Color timerColor;
if (state.CurrentSplit.Comparisons[state.CurrentComparison][timingMethod] != null)
{
timerColor = LiveSplitStateHelper.GetSplitColor(state, state.CurrentTime[timingMethod] - state.CurrentSplit.Comparisons[state.CurrentComparison][timingMethod],
TimerColor = LiveSplitStateHelper.GetSplitColor(state, state.CurrentTime[timingMethod] - state.CurrentSplit.Comparisons[state.CurrentComparison][timingMethod],
state.CurrentSplitIndex, true, false, state.CurrentComparison, timingMethod).Value;
}
else
timerColor = state.LayoutSettings.AheadGainingTimeColor;
BigTextLabel.ForeColor = timerColor;
SmallTextLabel.ForeColor = timerColor;
TimerColor = state.LayoutSettings.AheadGainingTimeColor;
}

if (Settings.OverrideSplitColors)
{
BigTextLabel.ForeColor = Settings.TimerColor;
SmallTextLabel.ForeColor = Settings.TimerColor;
}
else
{
BigTextLabel.ForeColor = TimerColor;
SmallTextLabel.ForeColor = TimerColor;
}

Cache["TimerText"] = BigTextLabel.Text + SmallTextLabel.Text;
Expand Down
15 changes: 9 additions & 6 deletions UI/Components/TimerSettings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 28 additions & 6 deletions UI/Components/TimerSettings.cs
Expand Up @@ -28,11 +28,11 @@ public partial class TimerSettings : UserControl

public Color BackgroundColor { get; set; }
public Color BackgroundColor2 { get; set; }
public GradientType BackgroundGradient { get; set; }
public DeltasGradientType BackgroundGradient { get; set; }
public String GradientString
{
get { return BackgroundGradient.ToString(); }
set { BackgroundGradient = (GradientType)Enum.Parse(typeof(GradientType), value); }
get { return GetBackgroundTypeString(BackgroundGradient); }
set { BackgroundGradient = (DeltasGradientType)Enum.Parse(typeof(DeltasGradientType), value.Replace(" ", "")); }
}

public TimerSettings()
Expand All @@ -47,7 +47,7 @@ public TimerSettings()
ShowGradient = true;
BackgroundColor = Color.Transparent;
BackgroundColor2 = Color.Transparent;
BackgroundGradient = GradientType.Plain;
BackgroundGradient = DeltasGradientType.Plain;
CenterTimer = false;
TimingMethod = "Current Timing Method";
DecimalsSize = 35f;
Expand Down Expand Up @@ -81,12 +81,34 @@ void chkOverrideTimerColors_CheckedChanged(object sender, EventArgs e)

void cmbGradientType_SelectedIndexChanged(object sender, EventArgs e)
{
btnColor1.Visible = cmbGradientType.SelectedItem.ToString() != "Plain";
var selectedText = cmbGradientType.SelectedItem.ToString();
btnColor1.Visible = selectedText != "Plain" && !selectedText.Contains("Delta");
btnColor2.Visible = !selectedText.Contains("Delta");
btnColor2.DataBindings.Clear();
btnColor2.DataBindings.Add("BackColor", this, btnColor1.Visible ? "BackgroundColor2" : "BackgroundColor", false, DataSourceUpdateMode.OnPropertyChanged);
GradientString = cmbGradientType.SelectedItem.ToString();
}

public static string GetBackgroundTypeString(DeltasGradientType type)
{
switch (type)
{
case DeltasGradientType.Horizontal:
return "Horizontal Gradient";
case DeltasGradientType.HorizontalWithDeltaColor:
return "Horizontal With Delta Color";
case DeltasGradientType.PlainWithDeltaColor:
return "Plain With Delta Color";
case DeltasGradientType.Vertical:
return "Vertical";
case DeltasGradientType.VerticalWithDeltaColor:
return "Vertical With Delta Color";
case DeltasGradientType.Plain:
default:
return "Plain";
}
}

void TimerSettings_Load(object sender, EventArgs e)
{
chkOverrideTimerColors_CheckedChanged(null, null);
Expand Down Expand Up @@ -121,7 +143,7 @@ public void SetSettings(XmlNode node)
DecimalsSize = SettingsHelper.ParseFloat(element["DecimalsSize"], 35f);
BackgroundColor = SettingsHelper.ParseColor(element["BackgroundColor"], Color.Transparent);
BackgroundColor2 = SettingsHelper.ParseColor(element["BackgroundColor2"], Color.Transparent);
GradientString = SettingsHelper.ParseString(element["BackgroundGradient"], GradientType.Plain.ToString());
GradientString = SettingsHelper.ParseString(element["BackgroundGradient"], DeltasGradientType.Plain.ToString());
CenterTimer = SettingsHelper.ParseBool(element["CenterTimer"], false);
TimingMethod = SettingsHelper.ParseString(element["TimingMethod"], "Current Timing Method");

Expand Down

0 comments on commit fbacda1

Please sign in to comment.