mirror of
https://github.com/DarthAffe/CUE.NET.git
synced 2025-12-13 00:58:31 +00:00
Fixed update mechanism
This commit is contained in:
parent
603c4f72fe
commit
dbdc1c22e8
@ -56,6 +56,7 @@
|
|||||||
<Compile Include="Devices\Generic\EventArgs\LedsUpdatingEventArgs.cs" />
|
<Compile Include="Devices\Generic\EventArgs\LedsUpdatingEventArgs.cs" />
|
||||||
<Compile Include="Devices\Generic\EventArgs\UpdatedEventArgs.cs" />
|
<Compile Include="Devices\Generic\EventArgs\UpdatedEventArgs.cs" />
|
||||||
<Compile Include="Devices\Generic\EventArgs\UpdatingEventArgs.cs" />
|
<Compile Include="Devices\Generic\EventArgs\UpdatingEventArgs.cs" />
|
||||||
|
<Compile Include="Devices\Generic\LedUpateRequest.cs" />
|
||||||
<Compile Include="Devices\Keyboard\Enums\BrushCalculationMode.cs" />
|
<Compile Include="Devices\Keyboard\Enums\BrushCalculationMode.cs" />
|
||||||
<Compile Include="Gradients\AbstractGradient.cs" />
|
<Compile Include="Gradients\AbstractGradient.cs" />
|
||||||
<Compile Include="Gradients\GradientStop.cs" />
|
<Compile Include="Gradients\GradientStop.cs" />
|
||||||
|
|||||||
@ -186,7 +186,7 @@ namespace CUE.NET.Devices.Generic
|
|||||||
DeviceUpdate();
|
DeviceUpdate();
|
||||||
UpdateEffects();
|
UpdateEffects();
|
||||||
|
|
||||||
IList<KeyValuePair<int, CorsairLed>> ledsToUpdate = (flushLeds ? Leds : Leds.Where(x => x.Value.IsDirty)).ToList();
|
ICollection<LedUpateRequest> ledsToUpdate = (flushLeds ? Leds : Leds.Where(x => x.Value.IsDirty)).Select(x => new LedUpateRequest(x.Key, x.Value.RequestedColor)).ToList();
|
||||||
|
|
||||||
foreach (CorsairLed led in Leds.Values)
|
foreach (CorsairLed led in Leds.Values)
|
||||||
led.Update();
|
led.Update();
|
||||||
@ -244,35 +244,35 @@ namespace CUE.NET.Devices.Generic
|
|||||||
/// <param name="effect">The effect to apply.</param>
|
/// <param name="effect">The effect to apply.</param>
|
||||||
protected abstract void ApplyEffect(IEffect effect);
|
protected abstract void ApplyEffect(IEffect effect);
|
||||||
|
|
||||||
private void UpdateLeds(ICollection<KeyValuePair<int, CorsairLed>> ledsToUpdate)
|
private void UpdateLeds(ICollection<LedUpateRequest> updateRequests)
|
||||||
{
|
{
|
||||||
ledsToUpdate = ledsToUpdate.Where(x => x.Value.Color != Color.Transparent).ToList();
|
updateRequests = updateRequests.Where(x => x.Color != Color.Transparent).ToList();
|
||||||
|
|
||||||
OnLedsUpdating(ledsToUpdate);
|
OnLedsUpdating(updateRequests);
|
||||||
|
|
||||||
if (ledsToUpdate.Any()) // CUE seems to crash if 'CorsairSetLedsColors' is called with a zero length array
|
if (updateRequests.Any()) // CUE seems to crash if 'CorsairSetLedsColors' is called with a zero length array
|
||||||
{
|
{
|
||||||
int structSize = Marshal.SizeOf(typeof(_CorsairLedColor));
|
int structSize = Marshal.SizeOf(typeof(_CorsairLedColor));
|
||||||
IntPtr ptr = Marshal.AllocHGlobal(structSize * ledsToUpdate.Count);
|
IntPtr ptr = Marshal.AllocHGlobal(structSize * updateRequests.Count);
|
||||||
IntPtr addPtr = new IntPtr(ptr.ToInt64());
|
IntPtr addPtr = new IntPtr(ptr.ToInt64());
|
||||||
foreach (KeyValuePair<int, CorsairLed> led in ledsToUpdate)
|
foreach (LedUpateRequest ledUpdateRequest in updateRequests)
|
||||||
{
|
{
|
||||||
_CorsairLedColor color = new _CorsairLedColor
|
_CorsairLedColor color = new _CorsairLedColor
|
||||||
{
|
{
|
||||||
ledId = led.Key,
|
ledId = ledUpdateRequest.LedId,
|
||||||
r = led.Value.Color.R,
|
r = ledUpdateRequest.Color.R,
|
||||||
g = led.Value.Color.G,
|
g = ledUpdateRequest.Color.G,
|
||||||
b = led.Value.Color.B
|
b = ledUpdateRequest.Color.B
|
||||||
};
|
};
|
||||||
|
|
||||||
Marshal.StructureToPtr(color, addPtr, false);
|
Marshal.StructureToPtr(color, addPtr, false);
|
||||||
addPtr = new IntPtr(addPtr.ToInt64() + structSize);
|
addPtr = new IntPtr(addPtr.ToInt64() + structSize);
|
||||||
}
|
}
|
||||||
_CUESDK.CorsairSetLedsColors(ledsToUpdate.Count, ptr);
|
_CUESDK.CorsairSetLedsColors(updateRequests.Count, ptr);
|
||||||
Marshal.FreeHGlobal(ptr);
|
Marshal.FreeHGlobal(ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
OnLedsUpdated(ledsToUpdate);
|
OnLedsUpdated(updateRequests);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -382,7 +382,7 @@ namespace CUE.NET.Devices.Generic
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handles the needed event-calls before the leds are updated.
|
/// Handles the needed event-calls before the leds are updated.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual void OnLedsUpdating(ICollection<KeyValuePair<int, CorsairLed>> updatingLeds)
|
protected virtual void OnLedsUpdating(ICollection<LedUpateRequest> updatingLeds)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@ -397,7 +397,7 @@ namespace CUE.NET.Devices.Generic
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handles the needed event-calls after the leds are updated.
|
/// Handles the needed event-calls after the leds are updated.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected virtual void OnLedsUpdated(IEnumerable<KeyValuePair<int, CorsairLed>> updatedLeds)
|
protected virtual void OnLedsUpdated(IEnumerable<LedUpateRequest> updatedLeds)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
// ReSharper disable MemberCanBePrivate.Global
|
// ReSharper disable MemberCanBePrivate.Global
|
||||||
|
// ReSharper disable UnusedAutoPropertyAccessor.Global
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
@ -8,15 +9,15 @@ namespace CUE.NET.Devices.Generic.EventArgs
|
|||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
public IEnumerable<KeyValuePair<int, CorsairLed>> UpdatedLeds { get; private set; }
|
public IEnumerable<LedUpateRequest> UpdatedLeds { get; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
|
|
||||||
public LedsUpdatedEventArgs(IEnumerable<KeyValuePair<int, CorsairLed>> updatedLeds)
|
public LedsUpdatedEventArgs(IEnumerable<LedUpateRequest> updatedLeds)
|
||||||
{
|
{
|
||||||
this.UpdatedLeds = new List<KeyValuePair<int, CorsairLed>>(updatedLeds); // Copy this - we don't want anyone to change the original led list.
|
this.UpdatedLeds = updatedLeds;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
// ReSharper disable MemberCanBePrivate.Global
|
// ReSharper disable MemberCanBePrivate.Global
|
||||||
|
// ReSharper disable UnusedAutoPropertyAccessor.Global
|
||||||
|
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
@ -8,15 +9,15 @@ namespace CUE.NET.Devices.Generic.EventArgs
|
|||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
public ICollection<KeyValuePair<int, CorsairLed>> UpdatingLeds { get; private set; }
|
public ICollection<LedUpateRequest> UpdatingLeds { get; }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
|
|
||||||
public LedsUpdatingEventArgs(ICollection<KeyValuePair<int, CorsairLed>> updatingLeds)
|
public LedsUpdatingEventArgs(ICollection<LedUpateRequest> updatingLeds)
|
||||||
{
|
{
|
||||||
this.UpdatingLeds = updatingLeds; // No copy here - before the update changing this is ok.
|
this.UpdatingLeds = updatingLeds;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
28
Devices/Generic/LedUpateRequest.cs
Normal file
28
Devices/Generic/LedUpateRequest.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// ReSharper disable MemberCanBePrivate.Global
|
||||||
|
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
|
||||||
|
|
||||||
|
using System.Drawing;
|
||||||
|
|
||||||
|
namespace CUE.NET.Devices.Generic
|
||||||
|
{
|
||||||
|
public class LedUpateRequest
|
||||||
|
{
|
||||||
|
#region Properties & Fields
|
||||||
|
|
||||||
|
public int LedId { get; }
|
||||||
|
|
||||||
|
public Color Color { get; set; }
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region Constructors
|
||||||
|
|
||||||
|
public LedUpateRequest(int ledId, Color color)
|
||||||
|
{
|
||||||
|
this.LedId = ledId;
|
||||||
|
this.Color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -183,7 +183,7 @@ namespace CUE.NET.Devices.Keyboard
|
|||||||
brushRectangle.X = 0;
|
brushRectangle.X = 0;
|
||||||
brushRectangle.Y = 0;
|
brushRectangle.Y = 0;
|
||||||
foreach (CorsairKey key in keys)
|
foreach (CorsairKey key in keys)
|
||||||
key.Led.Color = brush.GetColorAtPoint(KeyboardRectangle, key.KeyRectangle.GetCenter(offsetX, offsetY));
|
key.Led.Color = brush.GetColorAtPoint(brushRectangle, key.KeyRectangle.GetCenter(offsetX, offsetY));
|
||||||
break;
|
break;
|
||||||
case BrushCalculationMode.Absolute:
|
case BrushCalculationMode.Absolute:
|
||||||
foreach (CorsairKey key in keys)
|
foreach (CorsairKey key in keys)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user