mirror of
https://github.com/DarthAffe/CUE.NET.git
synced 2025-12-12 16:58:29 +00:00
Added methods to use the new GetColor method
This commit is contained in:
parent
6840813529
commit
c4ac6f0e40
@ -236,6 +236,15 @@ namespace CUE.NET
|
|||||||
IsInitialized = true;
|
IsInitialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Resets the colors of all devices back to the last saved color-data. (If there wasn't a manual save, that's the data from the time the SDK was initialized.)
|
||||||
|
/// </summary>
|
||||||
|
public static void Reset()
|
||||||
|
{
|
||||||
|
foreach (ICueDevice device in InitializedDevices)
|
||||||
|
device.RestoreColors();
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Reinitialize the CUE-SDK and temporarily hand back full control to CUE.
|
/// Reinitialize the CUE-SDK and temporarily hand back full control to CUE.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -29,6 +29,8 @@ namespace CUE.NET.Devices.Generic
|
|||||||
|
|
||||||
private static DateTime _lastUpdate = DateTime.Now;
|
private static DateTime _lastUpdate = DateTime.Now;
|
||||||
|
|
||||||
|
private Dictionary<CorsairLedId, CorsairColor> _colorDataSave;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets generic information provided by CUE for the device.
|
/// Gets generic information provided by CUE for the device.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -56,6 +58,7 @@ namespace CUE.NET.Devices.Generic
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the background brush of the keyboard.
|
/// Gets or sets the background brush of the keyboard.
|
||||||
|
/// If this is null the last saved color-data is used as background.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IBrush Brush { get; set; }
|
public IBrush Brush { get; set; }
|
||||||
|
|
||||||
@ -153,6 +156,7 @@ namespace CUE.NET.Devices.Generic
|
|||||||
public virtual void Initialize()
|
public virtual void Initialize()
|
||||||
{
|
{
|
||||||
DeviceRectangle = RectangleHelper.CreateRectangleFromRectangles((this).Select(x => x.LedRectangle));
|
DeviceRectangle = RectangleHelper.CreateRectangleFromRectangles((this).Select(x => x.LedRectangle));
|
||||||
|
SaveColors();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -187,19 +191,26 @@ namespace CUE.NET.Devices.Generic
|
|||||||
/// Performs an update for all dirty keys, or all keys if flushLeds is set to true.
|
/// Performs an update for all dirty keys, or all keys if flushLeds is set to true.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="flushLeds">Specifies whether all keys (including clean ones) should be updated.</param>
|
/// <param name="flushLeds">Specifies whether all keys (including clean ones) should be updated.</param>
|
||||||
public void Update(bool flushLeds = false)
|
/// <param name="noRender">Only updates the hardware-leds skippin effects and the render-pass. Only use this if you know what that means!</param>
|
||||||
|
public void Update(bool flushLeds = false, bool noRender = false)
|
||||||
{
|
{
|
||||||
OnUpdating();
|
OnUpdating();
|
||||||
|
|
||||||
// Update effects
|
if (!noRender)
|
||||||
foreach (ILedGroup ledGroup in LedGroups)
|
{
|
||||||
ledGroup.UpdateEffects();
|
// Update effects
|
||||||
|
foreach (ILedGroup ledGroup in LedGroups)
|
||||||
|
ledGroup.UpdateEffects();
|
||||||
|
|
||||||
// Render brushes
|
// Render brushes
|
||||||
Render(this);
|
if (Brush != null)
|
||||||
foreach (ILedGroup ledGroup in LedGroups.OrderBy(x => x.ZIndex))
|
Render(this);
|
||||||
Render(ledGroup);
|
else
|
||||||
|
ApplyColorData(_colorDataSave);
|
||||||
|
|
||||||
|
foreach (ILedGroup ledGroup in LedGroups.OrderBy(x => x.ZIndex))
|
||||||
|
Render(ledGroup);
|
||||||
|
}
|
||||||
// Device-specific updates
|
// Device-specific updates
|
||||||
DeviceUpdate();
|
DeviceUpdate();
|
||||||
|
|
||||||
@ -293,6 +304,63 @@ namespace CUE.NET.Devices.Generic
|
|||||||
OnLedsUpdated(updateRequests);
|
OnLedsUpdated(updateRequests);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void SyncColors()
|
||||||
|
{
|
||||||
|
Dictionary<CorsairLedId, CorsairColor> colorData = GetColors();
|
||||||
|
ApplyColorData(colorData);
|
||||||
|
Update(true, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void SaveColors()
|
||||||
|
{
|
||||||
|
_colorDataSave = GetColors();
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void RestoreColors()
|
||||||
|
{
|
||||||
|
ApplyColorData(_colorDataSave);
|
||||||
|
Update(true, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ApplyColorData(Dictionary<CorsairLedId, CorsairColor> colorData)
|
||||||
|
{
|
||||||
|
if (colorData == null) return;
|
||||||
|
|
||||||
|
foreach (KeyValuePair<CorsairLedId, CorsairColor> corsairColor in _colorDataSave)
|
||||||
|
LedMapping[corsairColor.Key].Color = corsairColor.Value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Dictionary<CorsairLedId, CorsairColor> GetColors()
|
||||||
|
{
|
||||||
|
int structSize = Marshal.SizeOf(typeof(_CorsairLedColor));
|
||||||
|
IntPtr ptr = Marshal.AllocHGlobal(structSize * LedMapping.Count);
|
||||||
|
IntPtr addPtr = new IntPtr(ptr.ToInt64());
|
||||||
|
foreach (KeyValuePair<CorsairLedId, CorsairLed> led in LedMapping)
|
||||||
|
{
|
||||||
|
_CorsairLedColor color = new _CorsairLedColor { ledId = (int)led.Value.Id };
|
||||||
|
Marshal.StructureToPtr(color, addPtr, false);
|
||||||
|
addPtr = new IntPtr(addPtr.ToInt64() + structSize);
|
||||||
|
}
|
||||||
|
_CUESDK.CorsairGetLedsColors(LedMapping.Count, ptr);
|
||||||
|
|
||||||
|
IntPtr readPtr = ptr;
|
||||||
|
Dictionary<CorsairLedId, CorsairColor> colorData = new Dictionary<CorsairLedId, CorsairColor>();
|
||||||
|
for (int i = 0; i < LedMapping.Count; i++)
|
||||||
|
{
|
||||||
|
_CorsairLedColor ledColor = (_CorsairLedColor)Marshal.PtrToStructure(readPtr, typeof(_CorsairLedColor));
|
||||||
|
colorData.Add((CorsairLedId)ledColor.ledId, new CorsairColor((byte)ledColor.r, (byte)ledColor.g, (byte)ledColor.b));
|
||||||
|
|
||||||
|
readPtr = new IntPtr(readPtr.ToInt64() + structSize);
|
||||||
|
}
|
||||||
|
|
||||||
|
Marshal.FreeHGlobal(ptr);
|
||||||
|
|
||||||
|
return colorData;
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region LedGroup
|
#region LedGroup
|
||||||
|
|||||||
@ -140,10 +140,26 @@ namespace CUE.NET.Devices
|
|||||||
void Initialize();
|
void Initialize();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Perform an update for all dirty keys, or all keys if flushLeds is set to true.
|
/// Performs an update for all dirty keys, or all keys if flushLeds is set to true.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="flushLeds">Specifies whether all keys (including clean ones) should be updated.</param>
|
/// <param name="flushLeds">Specifies whether all keys (including clean ones) should be updated.</param>
|
||||||
void Update(bool flushLeds = false);
|
/// <param name="noRender">Only updates the hardware-leds skippin effects and the render-pass. Only use this if you know what that means!</param>
|
||||||
|
void Update(bool flushLeds = false, bool noRender = false);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads the currently active colors from the device and sync them with the internal state.
|
||||||
|
/// </summary>
|
||||||
|
void SyncColors();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Saves the currently active colors from the device.
|
||||||
|
/// </summary>
|
||||||
|
void SaveColors();
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Restores the last saved colors.
|
||||||
|
/// </summary>
|
||||||
|
void RestoreColors();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Attaches the given ledgroup.
|
/// Attaches the given ledgroup.
|
||||||
|
|||||||
@ -39,7 +39,7 @@ namespace SimpleDevTest
|
|||||||
CueSDK.Initialize();
|
CueSDK.Initialize();
|
||||||
Console.WriteLine("Initialized with " + CueSDK.LoadedArchitecture + "-SDK");
|
Console.WriteLine("Initialized with " + CueSDK.LoadedArchitecture + "-SDK");
|
||||||
|
|
||||||
CueSDK.KeyboardSDK.Brush = (SolidColorBrush)Color.Black;
|
//CueSDK.KeyboardSDK.Brush = (SolidColorBrush)Color.Black;
|
||||||
//CueSDK.KeyboardSDK[CorsairLedId.Z].Color = Color.Red;
|
//CueSDK.KeyboardSDK[CorsairLedId.Z].Color = Color.Red;
|
||||||
//CueSDK.KeyboardSDK[CorsairLedId.Z].IsLocked = true;
|
//CueSDK.KeyboardSDK[CorsairLedId.Z].IsLocked = true;
|
||||||
|
|
||||||
@ -51,12 +51,15 @@ namespace SimpleDevTest
|
|||||||
//CueSDK.KeyboardSDK.Brush = new LinearGradientBrush(new LinearGradient(true, new GradientStop(0, Color.Blue), new GradientStop(0.5f, Color.Red)));
|
//CueSDK.KeyboardSDK.Brush = new LinearGradientBrush(new LinearGradient(true, new GradientStop(0, Color.Blue), new GradientStop(0.5f, Color.Red)));
|
||||||
left.Brush = new ConicalGradientBrush(new PointF(0.6f, 0.7f), new RainbowGradient(360, 0));
|
left.Brush = new ConicalGradientBrush(new PointF(0.6f, 0.7f), new RainbowGradient(360, 0));
|
||||||
left.Brush.AddEffect(new MoveGradientEffect());
|
left.Brush.AddEffect(new MoveGradientEffect());
|
||||||
|
left.Brush.AddEffect(new FlashEffect { Attack = 2, Sustain = 1f, Release = 2, Interval = 1f });
|
||||||
|
|
||||||
mid.Brush = new ConicalGradientBrush(new PointF(0.5f, 0.3f), new RainbowGradient());
|
mid.Brush = new ConicalGradientBrush(new PointF(0.5f, 0.3f), new RainbowGradient());
|
||||||
mid.Brush.AddEffect(new MoveGradientEffect());
|
mid.Brush.AddEffect(new MoveGradientEffect());
|
||||||
|
mid.Brush.AddEffect(new FlashEffect { Attack = 2, Sustain = 1f, Release = 2, Interval = 1f });
|
||||||
|
|
||||||
right.Brush = new ConicalGradientBrush(new PointF(0.4f, 0.7f), new RainbowGradient(360, 0));
|
right.Brush = new ConicalGradientBrush(new PointF(0.4f, 0.7f), new RainbowGradient(360, 0));
|
||||||
right.Brush.AddEffect(new MoveGradientEffect());
|
right.Brush.AddEffect(new MoveGradientEffect());
|
||||||
|
right.Brush.AddEffect(new FlashEffect { Attack = 2, Sustain = 1f, Release = 2, Interval = 1f });
|
||||||
|
|
||||||
//float halfKeyboardWidth = CueSDK.KeyboardSDK.DeviceRectangle.Width / 2f;
|
//float halfKeyboardWidth = CueSDK.KeyboardSDK.DeviceRectangle.Width / 2f;
|
||||||
//ILedGroup left = new RectangleLedGroup(CueSDK.KeyboardSDK, new RectangleF(CueSDK.KeyboardSDK.DeviceRectangle.X, CueSDK.KeyboardSDK.DeviceRectangle.Y, halfKeyboardWidth, CueSDK.KeyboardSDK.DeviceRectangle.Height));
|
//ILedGroup left = new RectangleLedGroup(CueSDK.KeyboardSDK, new RectangleF(CueSDK.KeyboardSDK.DeviceRectangle.X, CueSDK.KeyboardSDK.DeviceRectangle.Y, halfKeyboardWidth, CueSDK.KeyboardSDK.DeviceRectangle.Height));
|
||||||
|
|||||||
@ -53,6 +53,7 @@ namespace CUE.NET.Native
|
|||||||
_dllHandle = LoadLibrary(dllPath);
|
_dllHandle = LoadLibrary(dllPath);
|
||||||
|
|
||||||
_corsairSetLedsColorsPointer = (CorsairSetLedsColorsPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairSetLedsColors"), typeof(CorsairSetLedsColorsPointer));
|
_corsairSetLedsColorsPointer = (CorsairSetLedsColorsPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairSetLedsColors"), typeof(CorsairSetLedsColorsPointer));
|
||||||
|
_corsairGetLedsColorsPointer = (CorsairGetLedsColorsPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetLedsColors"), typeof(CorsairGetLedsColorsPointer));
|
||||||
_corsairGetDeviceCountPointer = (CorsairGetDeviceCountPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetDeviceCount"), typeof(CorsairGetDeviceCountPointer));
|
_corsairGetDeviceCountPointer = (CorsairGetDeviceCountPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetDeviceCount"), typeof(CorsairGetDeviceCountPointer));
|
||||||
_corsairGetDeviceInfoPointer = (CorsairGetDeviceInfoPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetDeviceInfo"), typeof(CorsairGetDeviceInfoPointer));
|
_corsairGetDeviceInfoPointer = (CorsairGetDeviceInfoPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetDeviceInfo"), typeof(CorsairGetDeviceInfoPointer));
|
||||||
_corsairGetLedPositionsPointer = (CorsairGetLedPositionsPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetLedPositions"), typeof(CorsairGetLedPositionsPointer));
|
_corsairGetLedPositionsPointer = (CorsairGetLedPositionsPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetLedPositions"), typeof(CorsairGetLedPositionsPointer));
|
||||||
@ -89,6 +90,7 @@ namespace CUE.NET.Native
|
|||||||
#region Pointers
|
#region Pointers
|
||||||
|
|
||||||
private static CorsairSetLedsColorsPointer _corsairSetLedsColorsPointer;
|
private static CorsairSetLedsColorsPointer _corsairSetLedsColorsPointer;
|
||||||
|
private static CorsairGetLedsColorsPointer _corsairGetLedsColorsPointer;
|
||||||
private static CorsairGetDeviceCountPointer _corsairGetDeviceCountPointer;
|
private static CorsairGetDeviceCountPointer _corsairGetDeviceCountPointer;
|
||||||
private static CorsairGetDeviceInfoPointer _corsairGetDeviceInfoPointer;
|
private static CorsairGetDeviceInfoPointer _corsairGetDeviceInfoPointer;
|
||||||
private static CorsairGetLedPositionsPointer _corsairGetLedPositionsPointer;
|
private static CorsairGetLedPositionsPointer _corsairGetLedPositionsPointer;
|
||||||
@ -106,6 +108,9 @@ namespace CUE.NET.Native
|
|||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||||
private delegate bool CorsairSetLedsColorsPointer(int size, IntPtr ledsColors);
|
private delegate bool CorsairSetLedsColorsPointer(int size, IntPtr ledsColors);
|
||||||
|
|
||||||
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||||
|
private delegate bool CorsairGetLedsColorsPointer(int size, IntPtr ledsColors);
|
||||||
|
|
||||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||||
private delegate int CorsairGetDeviceCountPointer();
|
private delegate int CorsairGetDeviceCountPointer();
|
||||||
|
|
||||||
@ -145,6 +150,14 @@ namespace CUE.NET.Native
|
|||||||
return _corsairSetLedsColorsPointer(size, ledsColors);
|
return _corsairSetLedsColorsPointer(size, ledsColors);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// CUE-SDK: get current color for the list of requested LEDs.
|
||||||
|
/// </summary>
|
||||||
|
internal static bool CorsairGetLedsColors(int size, IntPtr ledsColors)
|
||||||
|
{
|
||||||
|
return _corsairGetLedsColorsPointer(size, ledsColors);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// CUE-SDK: returns number of connected Corsair devices that support lighting control.
|
/// CUE-SDK: returns number of connected Corsair devices that support lighting control.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user