Refactored brushes to perform a multi-pass rendering.

This allows effects to change the calculated values.
This commit is contained in:
DarthAffe committed 2016-08-21 18:14:31 +02:00
1 parent ba80ef9848
commit 8d32c73b6d
15 files changed
+159 -97

No files matched your search

+1 -7
View File
@@ -169,8 +169,7 @@ namespace CUE.NET.Devices.Generic
public void Update(bool flushLeds = false)
{
OnUpdating();
DeviceUpdateEffects();
DeviceUpdate();
ICollection<LedUpateRequest> ledsToUpdate = (flushLeds ? Leds : Leds.Where(x => x.Value.IsDirty)).Select(x => new LedUpateRequest(x.Key, x.Value.RequestedColor)).ToList();
@@ -187,11 +186,6 @@ namespace CUE.NET.Devices.Generic
/// Performs device specific updates.
/// </summary>
protected abstract void DeviceUpdate();
/// <summary>
/// Performs device specific updates effect-updates.
/// </summary>
protected abstract void DeviceUpdateEffects();
private void UpdateLeds(ICollection<LedUpateRequest> updateRequests)
{
-5
View File
@@ -76,11 +76,6 @@ namespace CUE.NET.Devices.Headset
//TODO DarthAffe 21.08.2016: Create something fancy for headsets
}
protected override void DeviceUpdateEffects()
{
//TODO DarthAffe 21.08.2016: Create something fancy for headsets
}
#region IEnumerable
/// <summary>
+34 -34
View File
@@ -130,10 +130,16 @@ namespace CUE.NET.Devices.Keyboard
#region Update
/// <summary>
/// Updates all brushes on the keyboard and on groups.
/// Updates all brushes and groups on the keyboard.
/// </summary>
protected override void DeviceUpdate()
{
lock (_keyGroups)
{
foreach (IKeyGroup keyGroup in _keyGroups)
keyGroup.UpdateEffects();
}
if (Brush != null)
ApplyBrush(this.ToList(), Brush);
@@ -144,11 +150,6 @@ namespace CUE.NET.Devices.Keyboard
}
}
protected override void DeviceUpdateEffects()
{
UpdateEffects();
}
// ReSharper disable once MemberCanBeMadeStatic.Local - idc
private void ApplyBrush(ICollection<CorsairKey> keys, IBrush brush)
{
@@ -162,16 +163,20 @@ namespace CUE.NET.Devices.Keyboard
float offsetY = -brushRectangle.Y;
brushRectangle.X = 0;
brushRectangle.Y = 0;
foreach (CorsairKey key in keys)
key.Led.Color = brush.GetColorAtPoint(brushRectangle, key.KeyRectangle.GetCenter(offsetX, offsetY));
brush.PerformRender(brushRectangle, keys.Select(x => new BrushRenderTarget(x.KeyId, x.KeyRectangle.GetCenter(offsetX, offsetY))));
break;
case BrushCalculationMode.Absolute:
foreach (CorsairKey key in keys)
key.Led.Color = brush.GetColorAtPoint(KeyboardRectangle, key.KeyRectangle.GetCenter());
brush.PerformRender(KeyboardRectangle, keys.Select(x => new BrushRenderTarget(x.KeyId, x.KeyRectangle.GetCenter())));
break;
default:
throw new ArgumentException();
}
brush.UpdateEffects();
brush.PerformFinalize();
foreach (KeyValuePair<BrushRenderTarget, Color> renders in brush.RenderedTargets)
_keys[renders.Key.Key].Led.Color = renders.Value;
}
// ReSharper disable once CatchAllClause
catch (Exception ex) { OnException(ex); }
@@ -184,30 +189,6 @@ namespace CUE.NET.Devices.Keyboard
#endregion
public void UpdateEffects()
{
lock (_keyGroups)
{
foreach (IKeyGroup keyGroup in _keyGroups)
{
keyGroup.UpdateEffects();
keyGroup.Brush.UpdateEffects();
}
}
Brush.UpdateEffects();
}
public void AddEffect(IEffect<IKeyGroup> effect)
{
throw new NotSupportedException("Effects can't be applied directly to the keyboard. Add it to the Brush or create a keygroup instead.");
}
public void RemoveEffect(IEffect<IKeyGroup> effect)
{
throw new NotSupportedException("Effects can't be applied directly to the keyboard. Add it to the Brush or create a keygroup instead.");
}
/// <summary>
/// Attaches the given keygroup.
/// </summary>
@@ -259,6 +240,25 @@ namespace CUE.NET.Devices.Keyboard
}
}
#region Effects
public void UpdateEffects()
{
throw new NotSupportedException("Effects can't be applied directly to the keyboard. Add it to the Brush or create a keygroup instead.");
}
public void AddEffect(IEffect<IKeyGroup> effect)
{
throw new NotSupportedException("Effects can't be applied directly to the keyboard. Add it to the Brush or create a keygroup instead.");
}
public void RemoveEffect(IEffect<IKeyGroup> effect)
{
throw new NotSupportedException("Effects can't be applied directly to the keyboard. Add it to the Brush or create a keygroup instead.");
}
#endregion
#region IEnumerable
/// <summary>
-5
View File
@@ -99,11 +99,6 @@ namespace CUE.NET.Devices.Mouse
//TODO DarthAffe 21.08.2016: Create something fancy for mice
}
protected override void DeviceUpdateEffects()
{
//TODO DarthAffe 21.08.2016: Create something fancy for mice
}
#region IEnumerable
/// <summary>