From 2b314091eb8f0aabdcca752a17dc33ffebb5328b Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sat, 10 Sep 2016 18:30:22 +0200 Subject: [PATCH] Code cleanup --- Brushes/AbstractBrush.cs | 5 +++++ Brushes/ImageBrush.cs | 8 ++------ Brushes/LinearGradientBrush.cs | 7 +------ Brushes/ProfileBrush.cs | 7 +------ Brushes/RadialGradientBrush.cs | 5 ----- Brushes/RandomColorBrush.cs | 7 +------ Brushes/SolidColorBrush.cs | 7 +------ Effects/AbstractBrushEffect.cs | 2 +- Effects/AbstractEffectTarget.cs | 24 ++++++++++++------------ Effects/AbstractLedGroupEffect.cs | 2 +- 10 files changed, 25 insertions(+), 49 deletions(-) diff --git a/Brushes/AbstractBrush.cs b/Brushes/AbstractBrush.cs index 366b08e..0851b10 100644 --- a/Brushes/AbstractBrush.cs +++ b/Brushes/AbstractBrush.cs @@ -43,6 +43,11 @@ namespace CUE.NET.Brushes /// public Dictionary RenderedTargets { get; } = new Dictionary(); + /// + /// Gets the strongly-typed target used for the effect. + /// + protected override IBrush EffectTarget => this; + #endregion #region Constructors diff --git a/Brushes/ImageBrush.cs b/Brushes/ImageBrush.cs index d1fb66a..332c648 100644 --- a/Brushes/ImageBrush.cs +++ b/Brushes/ImageBrush.cs @@ -3,6 +3,7 @@ // ReSharper disable UnusedMember.Global using System; +using System.Collections.Generic; using System.Drawing; namespace CUE.NET.Brushes @@ -40,11 +41,6 @@ namespace CUE.NET.Brushes #region Properties & Fields - /// - /// Gets the strongly-typed target used for the effect. - /// - protected override IBrush EffectTarget => this; - /// /// Gets or sets the image drawn by the brush. If null it will default to full transparent. /// @@ -63,7 +59,7 @@ namespace CUE.NET.Brushes #endregion #region Methods - + /// /// Gets the color at an specific point assuming the brush is drawn into the given rectangle. /// diff --git a/Brushes/LinearGradientBrush.cs b/Brushes/LinearGradientBrush.cs index 76435a5..95ae138 100644 --- a/Brushes/LinearGradientBrush.cs +++ b/Brushes/LinearGradientBrush.cs @@ -17,12 +17,7 @@ namespace CUE.NET.Brushes public class LinearGradientBrush : AbstractBrush { #region Properties & Fields - - /// - /// Gets the strongly-typed target used for the effect. - /// - protected override IBrush EffectTarget => this; - + /// /// Gets or sets the start point (as percentage in the range [0..1]) of the gradient drawn by the brush. (default: 0f, 0.5f) /// diff --git a/Brushes/ProfileBrush.cs b/Brushes/ProfileBrush.cs index a33af89..0a9049f 100644 --- a/Brushes/ProfileBrush.cs +++ b/Brushes/ProfileBrush.cs @@ -11,12 +11,7 @@ namespace CUE.NET.Brushes public class ProfileBrush : AbstractBrush { #region Properties & Fields - - /// - /// Gets the strongly-typed target used for the effect. - /// - protected override IBrush EffectTarget => this; - + private Dictionary _colors; #endregion diff --git a/Brushes/RadialGradientBrush.cs b/Brushes/RadialGradientBrush.cs index 846e4fc..c4212bc 100644 --- a/Brushes/RadialGradientBrush.cs +++ b/Brushes/RadialGradientBrush.cs @@ -16,11 +16,6 @@ namespace CUE.NET.Brushes { #region Properties & Fields - /// - /// Gets the strongly-typed target used for the effect. - /// - protected override IBrush EffectTarget => this; - /// /// Gets or sets the center point (as percentage in the range [0..1]) around which the brush should be drawn. /// diff --git a/Brushes/RandomColorBrush.cs b/Brushes/RandomColorBrush.cs index 5cdff3d..8143f13 100644 --- a/Brushes/RandomColorBrush.cs +++ b/Brushes/RandomColorBrush.cs @@ -14,12 +14,7 @@ namespace CUE.NET.Brushes public class RandomColorBrush : AbstractBrush { #region Properties & Fields - - /// - /// Gets the strongly-typed target used for the effect. - /// - protected override IBrush EffectTarget => this; - + private Random _random = new Random(); #endregion diff --git a/Brushes/SolidColorBrush.cs b/Brushes/SolidColorBrush.cs index 680d414..0d4ec68 100644 --- a/Brushes/SolidColorBrush.cs +++ b/Brushes/SolidColorBrush.cs @@ -11,12 +11,7 @@ namespace CUE.NET.Brushes public class SolidColorBrush : AbstractBrush { #region Properties & Fields - - /// - /// Gets the strongly-typed target used for the effect. - /// - protected override IBrush EffectTarget => this; - + /// /// Gets or sets the color drawn by the brush. /// diff --git a/Effects/AbstractBrushEffect.cs b/Effects/AbstractBrushEffect.cs index 3290c34..6cf43e7 100644 --- a/Effects/AbstractBrushEffect.cs +++ b/Effects/AbstractBrushEffect.cs @@ -19,7 +19,7 @@ namespace CUE.NET.Effects /// /// Gets the this effect is targeting. /// - protected IBrush Brush { get; private set; } + protected IBrush Brush { get; set; } #endregion diff --git a/Effects/AbstractEffectTarget.cs b/Effects/AbstractEffectTarget.cs index d075000..0718d05 100644 --- a/Effects/AbstractEffectTarget.cs +++ b/Effects/AbstractEffectTarget.cs @@ -15,12 +15,12 @@ namespace CUE.NET.Effects { #region Properties & Fields - private IList _effectTimes = new List(); + protected IList EffectTimes = new List(); /// /// Gets all attached to this target. /// - protected IList> Effects => _effectTimes.Select(x => x.Effect).Cast>().ToList(); + protected IList> Effects => EffectTimes.Select(x => x.Effect).Cast>().ToList(); /// /// Gets the strongly-typed target used for the effect. @@ -34,13 +34,13 @@ namespace CUE.NET.Effects /// /// Updates all effects added to this target. /// - public void UpdateEffects() + public virtual void UpdateEffects() { lock (Effects) { - for (int i = _effectTimes.Count - 1; i >= 0; i--) + for (int i = EffectTimes.Count - 1; i >= 0; i--) { - EffectTimeContainer effectTime = _effectTimes[i]; + EffectTimeContainer effectTime = EffectTimes[i]; long currentTicks = DateTime.Now.Ticks; float deltaTime; @@ -57,7 +57,7 @@ namespace CUE.NET.Effects if (effectTime.Effect.IsDone) - _effectTimes.RemoveAt(i); + EffectTimes.RemoveAt(i); } } } @@ -66,25 +66,25 @@ namespace CUE.NET.Effects /// Adds an affect. /// /// The effect to add. - public void AddEffect(IEffect effect) + public virtual void AddEffect(IEffect effect) { - if (_effectTimes.Any(x => x.Effect == effect)) return; + if (EffectTimes.Any(x => x.Effect == effect)) return; effect.OnAttach(EffectTarget); - _effectTimes.Add(new EffectTimeContainer(effect, -1)); + EffectTimes.Add(new EffectTimeContainer(effect, -1)); } /// /// Removes an effect /// /// The effect to remove. - public void RemoveEffect(IEffect effect) + public virtual void RemoveEffect(IEffect effect) { - EffectTimeContainer effectTimeToRemove = _effectTimes.FirstOrDefault(x => x.Effect == effect); + EffectTimeContainer effectTimeToRemove = EffectTimes.FirstOrDefault(x => x.Effect == effect); if (effectTimeToRemove == null) return; effect.OnDetach(EffectTarget); - _effectTimes.Remove(effectTimeToRemove); + EffectTimes.Remove(effectTimeToRemove); } #endregion diff --git a/Effects/AbstractLedGroupEffect.cs b/Effects/AbstractLedGroupEffect.cs index 188f93e..35e51d0 100644 --- a/Effects/AbstractLedGroupEffect.cs +++ b/Effects/AbstractLedGroupEffect.cs @@ -21,7 +21,7 @@ namespace CUE.NET.Effects /// /// Gets the this effect is targeting. /// - protected ILedGroup LedGroup { get; private set; } + protected ILedGroup LedGroup { get; set; } #endregion