mirror of
https://github.com/DarthAffe/RGBSyncPlus
synced 2026-11-10 20:46:28 +00:00
Initial implementation
This commit is contained in:
1 parent
278e22020e
commit
fd662dcf34
63 files changed
+4881
No files matched your search
@@ -0,0 +1,77 @@
|
||||
using System;
|
||||
using System.Windows.Input;
|
||||
|
||||
namespace RGBSyncPlus.Helper
|
||||
{
|
||||
public class ActionCommand : ICommand
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private readonly Func<bool> _canExecute;
|
||||
private readonly Action _command;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
||||
public event EventHandler CanExecuteChanged;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public ActionCommand(Action command, Func<bool> canExecute = null)
|
||||
{
|
||||
this._command = command;
|
||||
this._canExecute = canExecute;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
public bool CanExecute(object parameter) => _canExecute?.Invoke() ?? true;
|
||||
|
||||
public void Execute(object parameter) => _command?.Invoke();
|
||||
|
||||
public void RaiseCanExecuteChanged() => CanExecuteChanged?.Invoke(this, new EventArgs());
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class ActionCommand<T> : ICommand
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private readonly Func<T, bool> _canExecute;
|
||||
private readonly Action<T> _command;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
||||
public event EventHandler CanExecuteChanged;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public ActionCommand(Action<T> command, Func<T, bool> canExecute = null)
|
||||
{
|
||||
this._command = command;
|
||||
this._canExecute = canExecute;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
public bool CanExecute(object parameter) => _canExecute?.Invoke((T)parameter) ?? true;
|
||||
|
||||
public void Execute(object parameter) => _command?.Invoke((T)parameter);
|
||||
|
||||
public void RaiseCanExecuteChanged() => CanExecuteChanged?.Invoke(this, new EventArgs());
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
|
||||
namespace RGBSyncPlus.Helper
|
||||
{
|
||||
public static class ExceptionExtension
|
||||
{
|
||||
#region Methods
|
||||
|
||||
public static string GetFullMessage(this Exception ex, string message = "")
|
||||
{
|
||||
if (ex == null) return string.Empty;
|
||||
|
||||
message += ex.Message;
|
||||
|
||||
if (ex.InnerException != null)
|
||||
message += "\r\nInnerException: " + GetFullMessage(ex.InnerException);
|
||||
|
||||
return message;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
|
||||
namespace RGBSyncPlus.Helper
|
||||
{
|
||||
public static class MathHelper
|
||||
{
|
||||
#region Methods
|
||||
|
||||
public static double Clamp(double value, double min, double max) => Math.Max(min, Math.Min(max, value));
|
||||
public static float Clamp(float value, float min, float max) => (float)Clamp((double)value, min, max);
|
||||
public static int Clamp(int value, int min, int max) => Math.Max(min, Math.Min(max, value));
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using RGB.NET.Core;
|
||||
using RGBSyncPlus.Model;
|
||||
|
||||
namespace RGBSyncPlus.Helper
|
||||
{
|
||||
public static class RGBNetExtension
|
||||
{
|
||||
public static string GetDeviceName(this IRGBDevice device) => $"{device.DeviceInfo.Manufacturer} {device.DeviceInfo.Model} ({device.DeviceInfo.DeviceType})";
|
||||
|
||||
public static IEnumerable<Led> GetLeds(this IEnumerable<SyncLed> syncLeds)
|
||||
=> syncLeds.Select(GetLed).Where(led => led != null);
|
||||
|
||||
public static Led GetLed(this SyncLed syncLed)
|
||||
{
|
||||
if (syncLed == null) return null;
|
||||
return RGBSurface.Instance.Leds.FirstOrDefault(l => (l.Id == syncLed.LedId) && (l.Device.GetDeviceName() == syncLed.Device));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user