1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-13 10:08:31 +00:00

Small refactorings to unify code styling

This commit is contained in:
Darth Affe 2018-01-14 11:57:45 +01:00
parent ac0350a9f8
commit efe77cedbc
10 changed files with 80 additions and 101 deletions

View File

@ -335,8 +335,7 @@ namespace RGB.NET.Core
/// <returns><c>true</c> if <paramref name="obj" /> is a <see cref="Rectangle" /> equivalent to this <see cref="Rectangle" />; otherwise, <c>false</c>.</returns> /// <returns><c>true</c> if <paramref name="obj" /> is a <see cref="Rectangle" /> equivalent to this <see cref="Rectangle" />; otherwise, <c>false</c>.</returns>
public override bool Equals(object obj) public override bool Equals(object obj)
{ {
Rectangle compareRect = obj as Rectangle; if (!(obj is Rectangle compareRect))
if (ReferenceEquals(compareRect, null))
return false; return false;
if (ReferenceEquals(this, compareRect)) if (ReferenceEquals(this, compareRect))
@ -372,7 +371,7 @@ namespace RGB.NET.Core
/// <param name="rectangle1">The first <see cref="Rectangle" /> to compare.</param> /// <param name="rectangle1">The first <see cref="Rectangle" /> to compare.</param>
/// <param name="rectangle2">The second <see cref="Rectangle" /> to compare.</param> /// <param name="rectangle2">The second <see cref="Rectangle" /> to compare.</param>
/// <returns><c>true</c> if <paramref name="rectangle1" /> and <paramref name="rectangle2" /> are equal; otherwise, <c>false</c>.</returns> /// <returns><c>true</c> if <paramref name="rectangle1" /> and <paramref name="rectangle2" /> are equal; otherwise, <c>false</c>.</returns>
public static bool operator ==(Rectangle rectangle1, Rectangle rectangle2) => ReferenceEquals(rectangle1, null) ? ReferenceEquals(rectangle2, null) : rectangle1.Equals(rectangle2); public static bool operator ==(Rectangle rectangle1, Rectangle rectangle2) => rectangle1?.Equals(rectangle2) ?? ReferenceEquals(rectangle2, null);
/// <summary> /// <summary>
/// Returns a value that indicates whether two specified <see cref="Rectangle" /> are equal. /// Returns a value that indicates whether two specified <see cref="Rectangle" /> are equal.

View File

@ -60,6 +60,7 @@ namespace RGB.NET.Devices.Asus
/// <summary> /// <summary>
/// Gets or sets a function to get the culture for a specific device. /// Gets or sets a function to get the culture for a specific device.
/// </summary> /// </summary>
// ReSharper disable once AutoPropertyCanBeMadeGetOnly.Global
public Func<CultureInfo> GetCulture { get; set; } = CultureHelper.GetCurrentCulture; public Func<CultureInfo> GetCulture { get; set; } = CultureHelper.GetCurrentCulture;
#endregion #endregion

View File

@ -60,6 +60,7 @@ namespace RGB.NET.Devices.CoolerMaster
/// <summary> /// <summary>
/// Gets or sets a function to get the culture for a specific device. /// Gets or sets a function to get the culture for a specific device.
/// </summary> /// </summary>
// ReSharper disable once AutoPropertyCanBeMadeGetOnly.Global
public Func<CultureInfo> GetCulture { get; set; } = CultureHelper.GetCurrentCulture; public Func<CultureInfo> GetCulture { get; set; } = CultureHelper.GetCurrentCulture;
#endregion #endregion

View File

@ -34,15 +34,15 @@ namespace RGB.NET.Devices.CoolerMaster
if (leds.Count > 0) if (leds.Count > 0)
{ {
// 6 by 22 seems hard-coded but it's what the CM SDK expects regardless of keyboard size // 6 by 22 seems hard-coded but it's what the CM SDK expects regardless of keyboard size
_CoolerMasterSDK.COLOR_MATRIX matrix = new _CoolerMasterSDK.COLOR_MATRIX { KeyColor = new _CoolerMasterSDK.KEY_COLOR[6, 22] }; _CoolerMasterColorMatrix colorMatrix = new _CoolerMasterColorMatrix { KeyColor = new _CoolerMasterKeyColor[_CoolerMasterColorMatrix.ROWS, _CoolerMasterColorMatrix.COLUMNS] };
foreach (Led led in leds) foreach (Led led in leds)
{ {
(int row, int column) = ((int, int))led.CustomData; (int row, int column) = ((int, int))led.CustomData;
matrix.KeyColor[row, column] = new _CoolerMasterSDK.KEY_COLOR(led.Color.R, led.Color.G, led.Color.B); colorMatrix.KeyColor[row, column] = new _CoolerMasterKeyColor(led.Color.R, led.Color.G, led.Color.B);
} }
_CoolerMasterSDK.SetControlDevice(DeviceInfo.DeviceIndex); _CoolerMasterSDK.SetControlDevice(DeviceInfo.DeviceIndex);
_CoolerMasterSDK.SetAllLedColor(matrix); _CoolerMasterSDK.SetAllLedColor(colorMatrix);
_CoolerMasterSDK.RefreshLed(false); _CoolerMasterSDK.RefreshLed(false);
} }
} }

View File

@ -15,7 +15,7 @@ namespace RGB.NET.Devices.CoolerMaster
/// <summary> /// <summary>
/// Gets the <see cref="CoolerMasterPhysicalKeyboardLayout"/> of the <see cref="CoolerMasterKeyboardRGBDevice"/>. /// Gets the <see cref="CoolerMasterPhysicalKeyboardLayout"/> of the <see cref="CoolerMasterKeyboardRGBDevice"/>.
/// </summary> /// </summary>
public CoolerMasterPhysicalKeyboardLayout PhysicalLayout { get; private set; } public CoolerMasterPhysicalKeyboardLayout PhysicalLayout { get; }
/// <summary> /// <summary>
/// Gets the <see cref="CoolerMasterLogicalKeyboardLayout"/> of the <see cref="CoolerMasterKeyboardRGBDevice"/>. /// Gets the <see cref="CoolerMasterLogicalKeyboardLayout"/> of the <see cref="CoolerMasterKeyboardRGBDevice"/>.

View File

@ -0,0 +1,22 @@
using System.Runtime.InteropServices;
namespace RGB.NET.Devices.CoolerMaster.Native
{
// ReSharper disable once InconsistentNaming
internal struct _CoolerMasterColorMatrix
{
#region Constants
internal const int ROWS = 6;
internal const int COLUMNS = 22;
#endregion
#region Properties & Fields
[MarshalAs(UnmanagedType.ByValArray, SizeConst = ROWS * COLUMNS)]
public _CoolerMasterKeyColor[,] KeyColor;
#endregion
}
}

View File

@ -0,0 +1,30 @@
// ReSharper disable UnusedMethodReturnValue.Global
// ReSharper disable UnusedMember.Global
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable NotAccessedField.Global
namespace RGB.NET.Devices.CoolerMaster.Native
{
// ReSharper disable once InconsistentNaming
internal struct _CoolerMasterKeyColor
{
#region Properties & Fields
public byte R;
public byte G;
public byte B;
#endregion
#region Constructors
internal _CoolerMasterKeyColor(byte r, byte g, byte b)
{
this.R = r;
this.G = g;
this.B = b;
}
#endregion
}
}

View File

@ -74,31 +74,6 @@ namespace RGB.NET.Devices.CoolerMaster.Native
#region SDK-METHODS #region SDK-METHODS
#region Structs
// ReSharper disable InconsistentNaming
internal struct KEY_COLOR
{
public byte r;
public byte g;
public byte b;
public KEY_COLOR(byte colR, byte colG, byte colB)
{
r = colR;
g = colG;
b = colB;
}
}
internal struct COLOR_MATRIX
{
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 132)] public KEY_COLOR[,] KeyColor;
}
// ReSharper restore InconsistentNaming
#endregion
#region Pointers #region Pointers
private static GetSDKVersionPointer _getSDKVersionPointer; private static GetSDKVersionPointer _getSDKVersionPointer;
@ -141,7 +116,7 @@ namespace RGB.NET.Devices.CoolerMaster.Native
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
[return: MarshalAs(UnmanagedType.I1)] [return: MarshalAs(UnmanagedType.I1)]
private delegate bool SetAllLedColorPointer(COLOR_MATRIX colorMatrix); private delegate bool SetAllLedColorPointer(_CoolerMasterColorMatrix colorMatrix);
#endregion #endregion
@ -150,66 +125,42 @@ namespace RGB.NET.Devices.CoolerMaster.Native
/// <summary> /// <summary>
/// CM-SDK: Get SDK Dll's Version. /// CM-SDK: Get SDK Dll's Version.
/// </summary> /// </summary>
internal static int GetSDKVersion() internal static int GetSDKVersion() => _getSDKVersionPointer();
{
return _getSDKVersionPointer();
}
/// <summary> /// <summary>
/// CM-SDK: set operating device /// CM-SDK: set operating device
/// </summary> /// </summary>
internal static void SetControlDevice(CoolerMasterDevicesIndexes devicesIndexes) internal static void SetControlDevice(CoolerMasterDevicesIndexes devicesIndexes) => _setControlDevicenPointer(devicesIndexes);
{
_setControlDevicenPointer(devicesIndexes);
}
/// <summary> /// <summary>
/// CM-SDK: verify if the deviced is plugged in /// CM-SDK: verify if the deviced is plugged in
/// </summary> /// </summary>
internal static bool IsDevicePlugged() internal static bool IsDevicePlugged() => _isDevicePlugPointer();
{
return _isDevicePlugPointer();
}
/// <summary> /// <summary>
/// CM-SDK: Obtain current device layout /// CM-SDK: Obtain current device layout
/// </summary> /// </summary>
internal static CoolerMasterPhysicalKeyboardLayout GetDeviceLayout() internal static CoolerMasterPhysicalKeyboardLayout GetDeviceLayout() => _getDeviceLayoutPointer();
{
return _getDeviceLayoutPointer();
}
/// <summary> /// <summary>
/// CM-SDK: set control over devices LED /// CM-SDK: set control over devices LED
/// </summary> /// </summary>
internal static bool EnableLedControl(bool value) internal static bool EnableLedControl(bool value) => _enableLedControlPointer(value);
{
return _enableLedControlPointer(value);
}
/// <summary> /// <summary>
/// CM-SDK: Print out the lights setting from Buffer to LED /// CM-SDK: Print out the lights setting from Buffer to LED
/// </summary> /// </summary>
internal static bool RefreshLed(bool autoRefresh) internal static bool RefreshLed(bool autoRefresh) => _refreshLedPointer(autoRefresh);
{
return _refreshLedPointer(autoRefresh);
}
/// <summary> /// <summary>
/// CM-SDK: Set single Key LED color /// CM-SDK: Set single Key LED color
/// </summary> /// </summary>
internal static bool SetLedColor(int row, int column, byte r, byte g, byte b) internal static bool SetLedColor(int row, int column, byte r, byte g, byte b) => _setLedColorPointer(row, column, r, g, b);
{
return _setLedColorPointer(row, column, r, g, b);
}
/// <summary> /// <summary>
/// CM-SDK: Set Keyboard "every LED" color /// CM-SDK: Set Keyboard "every LED" color
/// </summary> /// </summary>
internal static bool SetAllLedColor(COLOR_MATRIX colorMatrix) internal static bool SetAllLedColor(_CoolerMasterColorMatrix colorMatrix) => _setAllLedColorPointer(colorMatrix);
{
return _setAllLedColorPointer(colorMatrix);
}
// ReSharper restore EventExceptionNotDocumented // ReSharper restore EventExceptionNotDocumented

View File

@ -60,7 +60,9 @@
<Compile Include="Keyboard\CoolerMasterKeyboardRGBDeviceInfo.cs" /> <Compile Include="Keyboard\CoolerMasterKeyboardRGBDeviceInfo.cs" />
<Compile Include="Keyboard\CoolerMasterKeyboardLedMappings.cs" /> <Compile Include="Keyboard\CoolerMasterKeyboardLedMappings.cs" />
<Compile Include="Mouse\CoolerMasterMouseLedMappings.cs" /> <Compile Include="Mouse\CoolerMasterMouseLedMappings.cs" />
<Compile Include="Native\_CoolerMasterColorMatrix.cs" />
<Compile Include="Native\_CoolerMasterSDK.cs" /> <Compile Include="Native\_CoolerMasterSDK.cs" />
<Compile Include="Native\_CoolerMasterKeyColor.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View File

@ -125,20 +125,11 @@ namespace RGB.NET.Devices.Logitech.Native
// ReSharper disable EventExceptionNotDocumented // ReSharper disable EventExceptionNotDocumented
internal static bool LogiLedInit() internal static bool LogiLedInit() => _logiLedInitPointer();
{
return _logiLedInitPointer();
}
internal static void LogiLedShutdown() internal static void LogiLedShutdown() => _logiLedShutdownPointer();
{
_logiLedShutdownPointer();
}
internal static bool LogiLedSetTargetDevice(LogitechDeviceCaps targetDevice) internal static bool LogiLedSetTargetDevice(LogitechDeviceCaps targetDevice) => _logiLedSetTargetDevicePointer((int)targetDevice);
{
return _logiLedSetTargetDevicePointer((int)targetDevice);
}
internal static string LogiLedGetSdkVersion() internal static string LogiLedGetSdkVersion()
{ {
@ -150,36 +141,18 @@ namespace RGB.NET.Devices.Logitech.Native
return $"{major}.{minor}.{build}"; return $"{major}.{minor}.{build}";
} }
internal static bool LogiLedGetSdkVersion(ref int majorNum, ref int minorNum, ref int buildNum) internal static bool LogiLedGetSdkVersion(ref int majorNum, ref int minorNum, ref int buildNum) => _logiLedGetSdkVersionPointer(ref majorNum, ref minorNum, ref buildNum);
{
return _logiLedGetSdkVersionPointer(ref majorNum, ref minorNum, ref buildNum);
}
internal static bool LogiLedSaveCurrentLighting() internal static bool LogiLedSaveCurrentLighting() => _lgiLedSaveCurrentLightingPointer();
{
return _lgiLedSaveCurrentLightingPointer();
}
internal static bool LogiLedRestoreLighting() internal static bool LogiLedRestoreLighting() => _logiLedRestoreLightingPointer();
{
return _logiLedRestoreLightingPointer();
}
internal static bool LogiLedSetLighting(int redPercentage, int greenPercentage, int bluePercentage) internal static bool LogiLedSetLighting(int redPercentage, int greenPercentage, int bluePercentage) => _logiLedSetLightingPointer(redPercentage, greenPercentage, bluePercentage);
{
return _logiLedSetLightingPointer(redPercentage, greenPercentage, bluePercentage);
}
internal static bool LogiLedSetLightingForKeyWithKeyName(int keyCode, internal static bool LogiLedSetLightingForKeyWithKeyName(int keyCode,
int redPercentage, int greenPercentage, int bluePercentage) int redPercentage, int greenPercentage, int bluePercentage) => _logiLedSetLightingForKeyWithKeyNamePointer(keyCode, redPercentage, greenPercentage, bluePercentage);
{
return _logiLedSetLightingForKeyWithKeyNamePointer(keyCode, redPercentage, greenPercentage, bluePercentage);
}
internal static bool LogiLedSetLightingFromBitmap(byte[] bitmap) internal static bool LogiLedSetLightingFromBitmap(byte[] bitmap) => _logiLedSetLightingFromBitmapPointer(bitmap);
{
return _logiLedSetLightingFromBitmapPointer(bitmap);
}
// ReSharper restore EventExceptionNotDocumented // ReSharper restore EventExceptionNotDocumented