// ReSharper disable MemberCanBePrivate.Global // ReSharper disable UnusedMember.Global using System; using System.Collections.Generic; using System.Runtime.InteropServices; using RGB.NET.Core; using RGB.NET.Devices.Razer.Native; namespace RGB.NET.Devices.Razer { /// /// /// Represents a razer keypad. /// public class RazerKeypadRGBDevice : RazerRGBDevice { #region Constructors /// /// /// Initializes a new instance of the class. /// /// The specific information provided by CUE for the keypad. internal RazerKeypadRGBDevice(RazerKeypadRGBDeviceInfo info) : base(info) { } #endregion #region Methods /// protected override void InitializeLayout() { string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper(); ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Razer\Keypad\{model}.xml"), null); if (LedMapping.Count == 0) { for (int i = 0; i < _Defines.KEYPAD_MAX_ROW; i++) for (int j = 0; j < _Defines.KEYPAD_MAX_COLUMN; j++) InitializeLed(LedId.Keypad1 + ((i * _Defines.KEYPAD_MAX_COLUMN) + j), new Rectangle(j * 20, i * 20, 19, 19)); } } /// protected override object CreateLedCustomData(LedId ledId) => (int)ledId - (int)LedId.Keypad1; /// protected override IntPtr CreateEffectParams(IEnumerable leds) { _Color[] colors = new _Color[_Defines.KEYPAD_MAX_LEDS]; foreach (Led led in leds) colors[(int)led.CustomData] = new _Color(led.Color.R, led.Color.G, led.Color.B); _KeypadCustomEffect effectParams = new _KeypadCustomEffect { Color = colors }; IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); Marshal.StructureToPtr(effectParams, ptr, false); return ptr; } #endregion } }