diff --git a/src/Artemis.Core/Artemis.Core.csproj b/src/Artemis.Core/Artemis.Core.csproj index b9d5030a1..2a8ac8d4e 100644 --- a/src/Artemis.Core/Artemis.Core.csproj +++ b/src/Artemis.Core/Artemis.Core.csproj @@ -68,39 +68,6 @@ ..\packages\Ninject.Extensions.Factory.3.3.2\lib\net45\Ninject.Extensions.Factory.dll - - ..\packages\RGB.NET.Brushes.0.0.1.20\lib\net45\RGB.NET.Brushes.dll - - - ..\packages\RGB.NET.Core.0.0.1.20\lib\net45\RGB.NET.Core.dll - - - ..\packages\RGB.NET.Decorators.0.0.1.20\lib\net45\RGB.NET.Decorators.dll - - - ..\packages\RGB.NET.Devices.Asus.0.0.1.20\lib\net45\RGB.NET.Devices.Asus.dll - - - ..\packages\RGB.NET.Devices.CoolerMaster.0.0.1.20\lib\net45\RGB.NET.Devices.CoolerMaster.dll - - - ..\packages\RGB.NET.Devices.Corsair.0.0.1.20\lib\net45\RGB.NET.Devices.Corsair.dll - - - ..\packages\RGB.NET.Devices.Logitech.0.0.1.20\lib\net45\RGB.NET.Devices.Logitech.dll - - - ..\packages\RGB.NET.Devices.Msi.0.0.1.20\lib\net45\RGB.NET.Devices.Msi.dll - - - ..\packages\RGB.NET.Devices.Novation.0.0.1.20\lib\net45\RGB.NET.Devices.Novation.dll - - - ..\packages\RGB.NET.Devices.Razer.0.0.1.20\lib\net45\RGB.NET.Devices.Razer.dll - - - ..\packages\RGB.NET.Groups.0.0.1.20\lib\net45\RGB.NET.Groups.dll - ..\packages\Sanford.Multimedia.Midi.6.4.2\lib\net20\Sanford.Multimedia.Midi.dll @@ -188,10 +155,14 @@ + + + - + + @@ -207,27 +178,65 @@ + + {347c5f0f-f490-4dec-9c1c-6e84750d838d} + RGB.NET.Brushes + + + {5a4f9a75-75fe-47cd-90e5-914d5b20d232} + RGB.NET.Core + + + {7012c431-244a-453f-b7fd-59e030cdbc44} + RGB.NET.Decorators + + + {4f2f3fbd-a1e4-4968-a2ad-0514959e5e59} + RGB.NET.Devices.Asus + + + {85609427-d433-44e2-a249-ce890b66d845} + RGB.NET.Devices.CoolerMaster + + + {dda8c4c2-8abf-4fa0-9af9-c47ad0bfe47d} + RGB.NET.Devices.Corsair + + + {e7b2f174-fcc6-4fc7-9970-3138b5f4c921} + RGB.NET.Devices.Logitech + + + {4efd77c7-fdb4-4c6b-970c-0ef66d24be09} + RGB.NET.Devices.Msi + + + {db2911f6-404c-4bc8-b35f-232a7450755f} + RGB.NET.Devices.Novation + + + {24ff4acb-d679-4b2d-86d4-50ab6c02d816} + RGB.NET.Devices.Razer + + + {2a39f859-aad0-4c16-94f8-78057820b376} + RGB.NET.Groups + + + {f905c418-76bb-4ba6-88ab-0793bc2681d3} + RGB.NET.Input.Corsair + + + {e60c3c6f-903f-4d80-99d0-7a1e50af5a9d} + RGB.NET.Input + {cd23bc5e-57f0-46ce-a007-24d031146219} Artemis.Plugins + + + - - - - This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - - - - - - - - - - - - - \ No newline at end of file diff --git a/src/Artemis.Core/ProfileElements/Folder.cs b/src/Artemis.Core/ProfileElements/Folder.cs new file mode 100644 index 000000000..370b3cae3 --- /dev/null +++ b/src/Artemis.Core/ProfileElements/Folder.cs @@ -0,0 +1,23 @@ +using System.Collections.Generic; +using Artemis.Core.ProfileElements.Interfaces; +using RGB.NET.Core; + +namespace Artemis.Core.ProfileElements +{ + public class Folder : IProfileElement + { + public List Children { get; set; } + + public void Update() + { + foreach (var profileElement in Children) + profileElement.Update(); + } + + public void Render(IRGBDevice rgbDevice) + { + foreach (var profileElement in Children) + profileElement.Render(rgbDevice); + } + } +} \ No newline at end of file diff --git a/src/Artemis.Core/ProfileElements/Interfaces/IProfileElement.cs b/src/Artemis.Core/ProfileElements/Interfaces/IProfileElement.cs new file mode 100644 index 000000000..3b6886013 --- /dev/null +++ b/src/Artemis.Core/ProfileElements/Interfaces/IProfileElement.cs @@ -0,0 +1,23 @@ +using System.Collections.Generic; +using RGB.NET.Core; + +namespace Artemis.Core.ProfileElements.Interfaces +{ + public interface IProfileElement + { + /// + /// The element's children + /// + List Children { get; set; } + + /// + /// Updates the element + /// + void Update(); + + /// + /// Renders the element + /// + void Render(IRGBDevice rgbDevice); + } +} \ No newline at end of file diff --git a/src/Artemis.Core/ProfileElements/Profile.cs b/src/Artemis.Core/ProfileElements/Profile.cs new file mode 100644 index 000000000..a463fac81 --- /dev/null +++ b/src/Artemis.Core/ProfileElements/Profile.cs @@ -0,0 +1,21 @@ +using System.Collections.Generic; +using Artemis.Core.ProfileElements.Interfaces; +using RGB.NET.Core; + +namespace Artemis.Core.ProfileElements +{ + public class Profile : IProfileElement + { + public List Children { get; set; } + + public void Update() + { + } + + public void Render(IRGBDevice rgbDevice) + { + foreach (var profileElement in Children) + profileElement.Render(rgbDevice); + } + } +} \ No newline at end of file diff --git a/src/Artemis.Core/Services/CoreService.cs b/src/Artemis.Core/Services/CoreService.cs index 82c66e1f4..bd3c697f3 100644 --- a/src/Artemis.Core/Services/CoreService.cs +++ b/src/Artemis.Core/Services/CoreService.cs @@ -1,22 +1,26 @@ -using System.Threading.Tasks; +using System; +using System.Threading.Tasks; +using Artemis.Core.Exceptions; using Artemis.Core.Services.Interfaces; namespace Artemis.Core.Services { public class CoreService : ICoreService { + private readonly IRgbService _rgbService; private readonly IPluginService _pluginService; - private readonly IDeviceService _deviceService; - public CoreService(IPluginService pluginService, IDeviceService deviceService) + public CoreService(IPluginService pluginService, IRgbService rgbService) { _pluginService = pluginService; - _deviceService = deviceService; + _rgbService = rgbService; + Task.Run(Initialize); } public void Dispose() { + // Dispose services _pluginService.Dispose(); } @@ -24,9 +28,26 @@ namespace Artemis.Core.Services private async Task Initialize() { + if (IsInitialized) + throw new ArtemisCoreException("Cannot initialize the core as it is already initialized."); + + // Initialize the services await _pluginService.LoadPlugins(); - await _deviceService.LoadDevices(); - IsInitialized = true; + await _rgbService.LoadDevices(); + + OnInitialized(); } + + #region Events + + public event EventHandler Initialized; + + private void OnInitialized() + { + IsInitialized = true; + Initialized?.Invoke(this, EventArgs.Empty); + } + + #endregion } } \ No newline at end of file diff --git a/src/Artemis.Core/Services/Interfaces/ICoreService.cs b/src/Artemis.Core/Services/Interfaces/ICoreService.cs index 79ecdb825..b99f00d75 100644 --- a/src/Artemis.Core/Services/Interfaces/ICoreService.cs +++ b/src/Artemis.Core/Services/Interfaces/ICoreService.cs @@ -1,9 +1,15 @@ using System; +using Artemis.Core.Events; namespace Artemis.Core.Services.Interfaces { public interface ICoreService: IArtemisService, IDisposable { bool IsInitialized { get; set; } + + /// + /// Occurs the core has finished initializing + /// + event EventHandler Initialized; } } \ No newline at end of file diff --git a/src/Artemis.Core/Services/Interfaces/IRgbService.cs b/src/Artemis.Core/Services/Interfaces/IRgbService.cs new file mode 100644 index 000000000..ced041101 --- /dev/null +++ b/src/Artemis.Core/Services/Interfaces/IRgbService.cs @@ -0,0 +1,35 @@ +using System; +using System.Threading.Tasks; +using Artemis.Core.Events; +using RGB.NET.Core; + +namespace Artemis.Core.Services.Interfaces +{ + public interface IRgbService : IArtemisService + { + bool LoadingDevices { get; } + RGBSurface Surface { get; set; } + Task LoadDevices(); + void Dispose(); + + /// + /// Occurs when a single device has loaded + /// + event EventHandler DeviceLoaded; + + /// + /// Occurs when a single device has reloaded + /// + event EventHandler DeviceReloaded; + + /// + /// Occurs when loading all devices has started + /// + event EventHandler StartingLoadingDevices; + + /// + /// Occurs when loading all devices has finished + /// + event EventHandler FinishedLoadedDevices; + } +} \ No newline at end of file diff --git a/src/Artemis.Core/Services/PluginService.cs b/src/Artemis.Core/Services/PluginService.cs index e11e981ae..4458128f5 100644 --- a/src/Artemis.Core/Services/PluginService.cs +++ b/src/Artemis.Core/Services/PluginService.cs @@ -32,6 +32,7 @@ namespace Artemis.Core.Services public bool LoadingPlugins { get; private set; } public ReadOnlyCollection Plugins => _plugins.AsReadOnly(); + /// /// /// Loads all installed plugins. If plugins already loaded this will reload them all /// diff --git a/src/Artemis.Core/Services/DeviceService.cs b/src/Artemis.Core/Services/RgbService.cs similarity index 73% rename from src/Artemis.Core/Services/DeviceService.cs rename to src/Artemis.Core/Services/RgbService.cs index 3f45eae4a..c762510ae 100644 --- a/src/Artemis.Core/Services/DeviceService.cs +++ b/src/Artemis.Core/Services/RgbService.cs @@ -11,21 +11,25 @@ using RGB.NET.Groups; namespace Artemis.Core.Services { - public class DeviceService : IDeviceService, IDisposable + public class RgbService : IRgbService, IDisposable { - public DeviceService() + public RgbService() { Surface = RGBSurface.Instance; LoadingDevices = false; // Let's throw these for now Surface.Exception += SurfaceOnException; + Surface.UpdateMode = UpdateMode.Continuous; } + /// public bool LoadingDevices { get; private set; } + /// public RGBSurface Surface { get; set; } + /// public async Task LoadDevices() { OnStartedLoadingDevices(); @@ -33,19 +37,19 @@ namespace Artemis.Core.Services await Task.Run(() => { // TODO SpoinkyNL 8-1-18: Keep settings into account -// Surface.LoadDevices(AsusDeviceProvider.Instance); + // Surface.LoadDevices(AsusDeviceProvider.Instance); Surface.LoadDevices(CorsairDeviceProvider.Instance); Surface.LoadDevices(LogitechDeviceProvider.Instance); Surface.LoadDevices(CoolerMasterDeviceProvider.Instance); -// Surface.LoadDevices(NovationDeviceProvider.Instance); - + // Surface.LoadDevices(NovationDeviceProvider.Instance); + // TODO SpoinkyNL 8-1-18: Load alignment Surface.AlignDevies(); // Do some testing, why does this work, how does it know I want to target the surface? Check source! var ledGroup = new RectangleLedGroup(Surface.SurfaceRectangle) { - Brush = new SolidColorBrush(new Color(255, 0, 0)) {BrushCalculationMode = BrushCalculationMode.Absolute} + Brush = new SolidColorBrush(new Color(255, 0, 0)) { BrushCalculationMode = BrushCalculationMode.Absolute } }; Surface.UpdateMode = UpdateMode.Continuous; }); @@ -65,24 +69,9 @@ namespace Artemis.Core.Services #region Events - /// - /// Occurs when a single device has loaded - /// public event EventHandler DeviceLoaded; - - /// - /// Occurs when a single device has reloaded - /// public event EventHandler DeviceReloaded; - - /// - /// Occurs when loading all devices has started - /// - public event EventHandler StartedLoadingDevices; - - /// - /// Occurs when loading all devices has finished - /// + public event EventHandler StartingLoadingDevices; public event EventHandler FinishedLoadedDevices; private void OnDeviceLoaded(DeviceEventArgs e) @@ -98,7 +87,7 @@ namespace Artemis.Core.Services private void OnStartedLoadingDevices() { LoadingDevices = true; - StartedLoadingDevices?.Invoke(this, EventArgs.Empty); + StartingLoadingDevices?.Invoke(this, EventArgs.Empty); } private void OnFinishedLoadedDevices() @@ -109,9 +98,4 @@ namespace Artemis.Core.Services #endregion } - - public interface IDeviceService : IArtemisService - { - Task LoadDevices(); - } } \ No newline at end of file diff --git a/src/Artemis.Core/packages.config b/src/Artemis.Core/packages.config index 34f6373ff..7257243c9 100644 --- a/src/Artemis.Core/packages.config +++ b/src/Artemis.Core/packages.config @@ -13,20 +13,6 @@ - - - - - - - - - - - - - - diff --git a/src/Artemis.UI/App.xaml b/src/Artemis.UI/App.xaml index e35fc8d83..e024b2889 100644 --- a/src/Artemis.UI/App.xaml +++ b/src/Artemis.UI/App.xaml @@ -36,6 +36,10 @@ + + + + diff --git a/src/Artemis.UI/Artemis.UI.csproj b/src/Artemis.UI/Artemis.UI.csproj index 569fbeec4..cefcbc905 100644 --- a/src/Artemis.UI/Artemis.UI.csproj +++ b/src/Artemis.UI/Artemis.UI.csproj @@ -37,7 +37,7 @@ - ..\packages\Castle.Core.4.2.0\lib\net45\Castle.Core.dll + ..\packages\Castle.Core.4.2.1\lib\net45\Castle.Core.dll ..\packages\MahApps.Metro.1.5.0\lib\net45\MahApps.Metro.dll @@ -92,6 +92,10 @@ Designer + + + + @@ -106,6 +110,18 @@ Code + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -149,6 +165,58 @@ + + {347c5f0f-f490-4dec-9c1c-6e84750d838d} + RGB.NET.Brushes + + + {5a4f9a75-75fe-47cd-90e5-914d5b20d232} + RGB.NET.Core + + + {7012c431-244a-453f-b7fd-59e030cdbc44} + RGB.NET.Decorators + + + {4f2f3fbd-a1e4-4968-a2ad-0514959e5e59} + RGB.NET.Devices.Asus + + + {85609427-d433-44e2-a249-ce890b66d845} + RGB.NET.Devices.CoolerMaster + + + {dda8c4c2-8abf-4fa0-9af9-c47ad0bfe47d} + RGB.NET.Devices.Corsair + + + {e7b2f174-fcc6-4fc7-9970-3138b5f4c921} + RGB.NET.Devices.Logitech + + + {4efd77c7-fdb4-4c6b-970c-0ef66d24be09} + RGB.NET.Devices.Msi + + + {db2911f6-404c-4bc8-b35f-232a7450755f} + RGB.NET.Devices.Novation + + + {24ff4acb-d679-4b2d-86d4-50ab6c02d816} + RGB.NET.Devices.Razer + + + {2a39f859-aad0-4c16-94f8-78057820b376} + RGB.NET.Groups + + + {f905c418-76bb-4ba6-88ab-0793bc2681d3} + RGB.NET.Input.Corsair + + + {e60c3c6f-903f-4d80-99d0-7a1e50af5a9d} + RGB.NET.Input + {9b811f9b-86b9-4771-87af-72bae7078a36} Artemis.Core @@ -171,17 +239,16 @@ - - + This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. - + \ No newline at end of file diff --git a/src/Artemis.UI/Controls/Visualizers/LedVisualizer.cs b/src/Artemis.UI/Controls/Visualizers/LedVisualizer.cs new file mode 100644 index 000000000..436302cc3 --- /dev/null +++ b/src/Artemis.UI/Controls/Visualizers/LedVisualizer.cs @@ -0,0 +1,36 @@ +using System.Windows; +using System.Windows.Controls; +using RGB.NET.Core; + +namespace Artemis.UI.Controls.Visualizers +{ + /// + /// + /// Visualizes a in an wpf-application. + /// + public class LedVisualizer : Control + { + #region DependencyProperties + + // ReSharper disable InconsistentNaming + + /// + /// Backing-property for the -property. + /// + public static readonly DependencyProperty LedProperty = DependencyProperty.Register( + "Led", typeof(Led), typeof(LedVisualizer), new PropertyMetadata(default(Led))); + + /// + /// Gets or sets the to visualize. + /// + public Led Led + { + get => (Led) GetValue(LedProperty); + set => SetValue(LedProperty, value); + } + + // ReSharper restore InconsistentNaming + + #endregion + } +} \ No newline at end of file diff --git a/src/Artemis.UI/Controls/Visualizers/RGBDeviceVisualizer.cs b/src/Artemis.UI/Controls/Visualizers/RGBDeviceVisualizer.cs new file mode 100644 index 000000000..bfc6e281e --- /dev/null +++ b/src/Artemis.UI/Controls/Visualizers/RGBDeviceVisualizer.cs @@ -0,0 +1,78 @@ +using System.Windows; +using System.Windows.Controls; +using RGB.NET.Core; + +namespace Artemis.UI.Controls.Visualizers +{ + /// + /// + /// Visualizes a in an wpf-application. + /// + [TemplatePart(Name = PART_CANVAS, Type = typeof(Canvas))] + public class RGBDeviceVisualizer : Control + { + #region Constants + + private const string PART_CANVAS = "PART_Canvas"; + + #endregion + + #region Properties & Fields + + private Canvas _canvas; + + #endregion + + #region DependencyProperties + + // ReSharper disable InconsistentNaming + + /// + /// Backing-property for the -property. + /// + public static readonly DependencyProperty DeviceProperty = DependencyProperty.Register( + "Device", typeof(IRGBDevice), typeof(RGBDeviceVisualizer), new PropertyMetadata(default(IRGBDevice), DeviceChanged)); + + /// + /// Gets or sets the to visualize. + /// + public IRGBDevice Device + { + get => (IRGBDevice) GetValue(DeviceProperty); + set => SetValue(DeviceProperty, value); + } + + // ReSharper restore InconsistentNaming + + #endregion + + #region Methods + + /// + public override void OnApplyTemplate() + { + _canvas = (Canvas) GetTemplateChild(PART_CANVAS); + + LayoutLeds(); + } + + private static void DeviceChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs) + { + ((RGBDeviceVisualizer) dependencyObject).LayoutLeds(); + } + + private void LayoutLeds() + { + if (_canvas == null) return; + + _canvas.Children.Clear(); + + if (Device == null) return; + + foreach (Led led in Device) + _canvas.Children.Add(new LedVisualizer {Led = led}); + } + + #endregion + } +} \ No newline at end of file diff --git a/src/Artemis.UI/Controls/Visualizers/RGBSurfaceVisualizer.cs b/src/Artemis.UI/Controls/Visualizers/RGBSurfaceVisualizer.cs new file mode 100644 index 000000000..5d27f1773 --- /dev/null +++ b/src/Artemis.UI/Controls/Visualizers/RGBSurfaceVisualizer.cs @@ -0,0 +1,99 @@ +using System.Collections.Generic; +using System.Windows; +using System.Windows.Controls; +using RGB.NET.Core; + +namespace Artemis.UI.Controls.Visualizers +{ + /// + /// + /// Visualizes the in an wpf-application. + /// + [TemplatePart(Name = PART_CANVAS, Type = typeof(Canvas))] + public class RGBSurfaceVisualizer : Control + { + #region Constants + + private const string PART_CANVAS = "PART_Canvas"; + + #endregion + + #region Properties & Fields + + private RGBSurface _surface; + private Canvas _canvas; + + //TODO DarthAffe 17.06.2017: This is ugly - redesign how device connect/disconnect is generally handled! + private readonly List _newDevices = new List(); + + #endregion + + #region Constructors + + /// + /// + /// Initializes a new instance of the class. + /// + public RGBSurfaceVisualizer() + { + this.Loaded += OnLoaded; + this.Unloaded += OnUnloaded; + } + + private void OnLoaded(object sender, RoutedEventArgs routedEventArgs) + { + _surface = RGBSurface.Instance; + + _surface.SurfaceLayoutChanged += RGBSurfaceOnSurfaceLayoutChanged; + foreach (IRGBDevice device in _surface.Devices) + _newDevices.Add(device); + + UpdateSurface(); + } + + private void OnUnloaded(object sender, RoutedEventArgs routedEventArgs) + { + _surface.SurfaceLayoutChanged -= RGBSurfaceOnSurfaceLayoutChanged; + _canvas?.Children.Clear(); + _newDevices.Clear(); + } + + private void RGBSurfaceOnSurfaceLayoutChanged(SurfaceLayoutChangedEventArgs args) + { + if (args.DeviceAdded) + foreach (IRGBDevice device in args.Devices) + _newDevices.Add(device); + + UpdateSurface(); + } + + #endregion + + #region Methods + + /// + public override void OnApplyTemplate() + { + _canvas?.Children.Clear(); + _canvas = (Canvas)GetTemplateChild(PART_CANVAS); + UpdateSurface(); + } + + private void UpdateSurface() + { + if ((_canvas == null) || (_surface == null)) return; + + if (_newDevices.Count > 0) + { + foreach (IRGBDevice device in _newDevices) + _canvas.Children.Add(new RGBDeviceVisualizer { Device = device }); + _newDevices.Clear(); + } + + _canvas.Width = _surface.SurfaceRectangle.Size.Width; + _canvas.Height = _surface.SurfaceRectangle.Size.Height; + } + + #endregion + } +} diff --git a/src/Artemis.UI/Converters/ColorToSolidColorBrushConverter.cs b/src/Artemis.UI/Converters/ColorToSolidColorBrushConverter.cs new file mode 100644 index 000000000..51107717b --- /dev/null +++ b/src/Artemis.UI/Converters/ColorToSolidColorBrushConverter.cs @@ -0,0 +1,31 @@ +using System; +using System.Globalization; +using System.Windows.Data; +using System.Windows.Media; + +namespace Artemis.UI.Converters +{ + /// + /// + /// Converts into . + /// + [ValueConversion(typeof(RGB.NET.Core.Color), typeof(SolidColorBrush))] + public class ColorToSolidColorBrushConverter : IValueConverter + { + /// + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + return new SolidColorBrush(!(value is RGB.NET.Core.Color color) + ? Color.FromArgb(0, 0, 0, 0) + : Color.FromArgb(color.A, color.R, color.G, color.B)); + } + + /// + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + return !(value is SolidColorBrush brush) + ? RGB.NET.Core.Color.Transparent + : new RGB.NET.Core.Color(brush.Color.A, brush.Color.R, brush.Color.G, brush.Color.B); + } + } +} diff --git a/src/Artemis.UI/Styles/Visualizers/LedVisualizer.xaml b/src/Artemis.UI/Styles/Visualizers/LedVisualizer.xaml new file mode 100644 index 000000000..c4f447c65 --- /dev/null +++ b/src/Artemis.UI/Styles/Visualizers/LedVisualizer.xaml @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +