1
0
mirror of https://github.com/DarthAffe/CUE.NET.git synced 2025-12-12 16:58:29 +00:00

Removed CorsairKey since it wasn't of any use anyway

This commit is contained in:
Darth Affe 2016-09-10 17:34:32 +02:00
parent 5a018d0743
commit 223c0e8886
8 changed files with 19 additions and 153 deletions

View File

@ -1,7 +1,7 @@
using System.Collections.Generic;
using System.Drawing;
using CUE.NET.Devices.Keyboard.Enums;
using CUE.NET.Devices.Keyboard.Keys;
using CUE.NET.Devices.Generic;
using CUE.NET.Devices.Generic.Enums;
namespace CUE.NET.Brushes
{
@ -17,7 +17,7 @@ namespace CUE.NET.Brushes
/// </summary>
protected override IBrush EffectTarget => this;
private Dictionary<CorsairKeyboardKeyId, Color> _keyLights;
private Dictionary<CorsairLedId, Color> _colors;
#endregion
@ -27,9 +27,9 @@ namespace CUE.NET.Brushes
/// Initializes a new instance of the <see cref="ProfileBrush"/> class.
/// </summary>
/// <param name="keyLights">The light settings of the CUE profile.</param>
internal ProfileBrush(Dictionary<CorsairKeyboardKeyId, Color> keyLights)
internal ProfileBrush(Dictionary<CorsairLedId, Color> keyLights)
{
this._keyLights = keyLights;
this._colors = keyLights;
}
#endregion
@ -44,11 +44,11 @@ namespace CUE.NET.Brushes
/// <returns>The color at the specified point.</returns>
protected override Color GetColorAtPoint(RectangleF rectangle, BrushRenderTarget renderTarget)
{
CorsairKey key = CueSDK.KeyboardSDK[(CorsairKeyboardKeyId)renderTarget.LedId];
if (key == null) return Color.Transparent;
CorsairLed led = CueSDK.KeyboardSDK[renderTarget.LedId];
if (led == null) return Color.Transparent;
Color color;
return !_keyLights.TryGetValue(key.KeyId, out color) ? Color.Transparent : color;
return !_colors.TryGetValue(led.Id, out color) ? Color.Transparent : color;
}
#endregion

View File

@ -98,7 +98,6 @@
<Compile Include="Devices\Headset\CorsairHeadset.cs" />
<Compile Include="Devices\Headset\CorsairHeadsetDeviceInfo.cs" />
<Compile Include="Devices\IDeviceInfo.cs" />
<Compile Include="Devices\Keyboard\Keys\CorsairKey.cs" />
<Compile Include="Devices\Keyboard\CorsairKeyboard.cs" />
<Compile Include="Devices\Mouse\CorsairMouseDeviceInfo.cs" />
<Compile Include="Devices\Mouse\CorsairMouse.cs" />

View File

@ -14,7 +14,10 @@ namespace CUE.NET.Devices.Generic
public class CorsairLed
{
#region Properties & Fields
/// <summary>
/// Gets the key-ID of the Led.
/// </summary>
public CorsairLedId Id { get; set; }
/// <summary>

View File

@ -13,7 +13,6 @@ using System.Runtime.InteropServices;
using CUE.NET.Brushes;
using CUE.NET.Devices.Generic;
using CUE.NET.Devices.Keyboard.Enums;
using CUE.NET.Devices.Keyboard.Keys;
using CUE.NET.Effects;
using CUE.NET.Groups;
using CUE.NET.Helper;
@ -24,67 +23,10 @@ namespace CUE.NET.Devices.Keyboard
/// <summary>
/// Represents the SDK for a corsair keyboard.
/// </summary>
public class CorsairKeyboard : AbstractCueDevice, IEnumerable<CorsairKey>
public class CorsairKeyboard : AbstractCueDevice
{
#region Properties & Fields
#region Indexer
/// <summary>
/// Gets the <see cref="CorsairKey" /> with the specified ID.
/// </summary>
/// <param name="keyId">The ID of the key to get.</param>
/// <returns>The key with the specified ID or null if no key is found.</returns>
public CorsairKey this[CorsairKeyboardKeyId keyId]
{
get
{
CorsairKey key;
return _keys.TryGetValue(keyId, out key) ? key : null;
}
}
/// <summary>
/// Gets the <see cref="CorsairKey" /> representing the given character by calling the SDK-method 'CorsairGetLedIdForKeyName'.<br />
/// Note that this currently only works for letters.
/// </summary>
/// <param name="key">The character of the key.</param>
/// <returns>The key representing the given character or null if no key is found.</returns>
public CorsairKey this[char key]
{
get
{
CorsairKeyboardKeyId keyId = _CUESDK.CorsairGetLedIdForKeyName(key);
CorsairKey cKey;
return _keys.TryGetValue(keyId, out cKey) ? cKey : null;
}
}
/// <summary>
/// Gets the <see cref="CorsairKey" /> at the given physical location.
/// </summary>
/// <param name="location">The point to get the key from.</param>
/// <returns>The key at the given point or null if no key is found.</returns>
public new CorsairKey this[PointF location] => _keys.Values.FirstOrDefault(x => x.Led.LedRectangle.Contains(location));
/// <summary>
/// Gets a list of <see cref="CorsairKey" /> inside the given rectangle.
/// </summary>
/// <param name="referenceRect">The rectangle to check.</param>
/// <param name="minOverlayPercentage">The minimal percentage overlay a key must have with the <see cref="Rectangle" /> to be taken into the list.</param>
/// <returns></returns>
public new IEnumerable<CorsairKey> this[RectangleF referenceRect, float minOverlayPercentage = 0.5f] => _keys.Values
.Where(x => RectangleHelper.CalculateIntersectPercentage(x.Led.LedRectangle, referenceRect) >= minOverlayPercentage);
#endregion
private Dictionary<CorsairKeyboardKeyId, CorsairKey> _keys = new Dictionary<CorsairKeyboardKeyId, CorsairKey>();
/// <summary>
/// Gets a read-only collection containing the keys of the keyboard.
/// </summary>
public IEnumerable<CorsairKey> Keys => new ReadOnlyCollection<CorsairKey>(_keys.Values.ToList());
/// <summary>
/// Gets specific information provided by CUE for the keyboard.
/// </summary>
@ -116,35 +58,11 @@ namespace CUE.NET.Devices.Keyboard
for (int i = 0; i < nativeLedPositions.numberOfLed; i++)
{
_CorsairLedPosition ledPosition = (_CorsairLedPosition)Marshal.PtrToStructure(ptr, typeof(_CorsairLedPosition));
CorsairLed led = InitializeLed(ledPosition.ledId, new RectangleF((float)ledPosition.left, (float)ledPosition.top, (float)ledPosition.width, (float)ledPosition.height));
_keys.Add((CorsairKeyboardKeyId)ledPosition.ledId, new CorsairKey((CorsairKeyboardKeyId)ledPosition.ledId, led));
InitializeLed(ledPosition.ledId, new RectangleF((float)ledPosition.left, (float)ledPosition.top, (float)ledPosition.width, (float)ledPosition.height));
ptr = new IntPtr(ptr.ToInt64() + structSize);
}
}
#region IEnumerable
/// <summary>
/// Returns an enumerator that iterates over all keys of the keyboard.
/// </summary>
/// <returns>An enumerator for all keys of the keyboard.</returns>
public new IEnumerator<CorsairKey> GetEnumerator()
{
return _keys.Values.GetEnumerator();
}
/// <summary>
/// Returns an enumerator that iterates over all keys of the keyboard.
/// </summary>
/// <returns>An enumerator for all keys of the keyboard.</returns>
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
#endregion
#endregion
}
}

View File

@ -1,52 +0,0 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
using CUE.NET.Devices.Generic;
using CUE.NET.Devices.Keyboard.Enums;
namespace CUE.NET.Devices.Keyboard.Keys
{
/// <summary>
/// Represents a key of a corsair keyboard.
/// </summary>
public class CorsairKey
{
#region Properties & Fields
/// <summary>
/// Gets the key-ID of the key.
/// </summary>
public CorsairKeyboardKeyId KeyId { get; }
/// <summary>
/// Gets the LED of the key.
/// </summary>
public CorsairLed Led { get; }
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="CorsairKey"/> class.
/// </summary>
/// <param name="keyId">The key-ID of the key.</param>
/// <param name="led">The LED of the key.</param>
internal CorsairKey(CorsairKeyboardKeyId keyId, CorsairLed led)
{
this.KeyId = keyId;
this.Led = led;
}
#endregion
#region Operators
public static implicit operator CorsairLed(CorsairKey key)
{
return key.Led;
}
#endregion
}
}

View File

@ -1,7 +1,6 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
using CUE.NET.Devices.Keyboard.Keys;
using CUE.NET.Groups;
namespace CUE.NET.Effects

View File

@ -5,7 +5,6 @@ using CUE.NET;
using CUE.NET.Brushes;
using CUE.NET.Devices.Generic.Enums;
using CUE.NET.Devices.Keyboard;
using CUE.NET.Devices.Keyboard.Keys;
using CUE.NET.Exceptions;
using CUE.NET.Gradients;
using CUE.NET.Groups;

View File

@ -4,7 +4,7 @@ using System.Drawing;
using System.Linq;
using System.Xml.Linq;
using CUE.NET.Brushes;
using CUE.NET.Devices.Keyboard.Enums;
using CUE.NET.Devices.Generic.Enums;
namespace CUE.NET.Profiles
{
@ -20,7 +20,7 @@ namespace CUE.NET.Profiles
/// </summary>
internal string Name { get; }
private Dictionary<CorsairKeyboardKeyId, Color> _keyLights;
private Dictionary<CorsairLedId, Color> _colors;
#endregion
@ -32,7 +32,7 @@ namespace CUE.NET.Profiles
/// <param name="profile">The profile mode to convert.</param>
public static implicit operator ProfileBrush(CueProfileMode profile)
{
return profile != null ? new ProfileBrush(profile._keyLights) : null;
return profile != null ? new ProfileBrush(profile._colors) : null;
}
#endregion
@ -62,7 +62,7 @@ namespace CUE.NET.Profiles
return new CueProfileMode(modeRoot.Element("name").Value)
{
_keyLights = modeRoot.Element("lightBackgrounds").Element("keyBgLights").Elements("lightBackground")
_colors = modeRoot.Element("lightBackgrounds").Element("keyBgLights").Elements("lightBackground")
.Select(x =>
{
string name = x.Attribute("key").Value;
@ -71,7 +71,7 @@ namespace CUE.NET.Profiles
return new
{
key = (CorsairKeyboardKeyId)Enum.Parse(typeof(CorsairKeyboardKeyId), name),
key = (CorsairLedId)Enum.Parse(typeof(CorsairLedId), name),
color = ColorTranslator.FromHtml(x.Attribute("color").Value)
};
})