diff --git a/src/Artemis.Core/Artemis.Core.csproj b/src/Artemis.Core/Artemis.Core.csproj index f8040f588..5f0cfe6fd 100644 --- a/src/Artemis.Core/Artemis.Core.csproj +++ b/src/Artemis.Core/Artemis.Core.csproj @@ -73,17 +73,22 @@ ..\packages\Ninject.Extensions.Factory.3.3.2\lib\net45\Ninject.Extensions.Factory.dll + - ..\packages\RGB.NET.Brushes.0.1.25\lib\net45\RGB.NET.Brushes.dll + False + ..\..\..\RGB.NET\bin\net45\RGB.NET.Brushes.dll - ..\packages\RGB.NET.Core.0.1.25\lib\net45\RGB.NET.Core.dll + False + ..\..\..\RGB.NET\bin\net45\RGB.NET.Core.dll - ..\packages\RGB.NET.Decorators.0.1.25\lib\net45\RGB.NET.Decorators.dll + False + ..\..\..\RGB.NET\bin\net45\RGB.NET.Decorators.dll - ..\packages\RGB.NET.Groups.0.1.25\lib\net45\RGB.NET.Groups.dll + False + ..\..\..\RGB.NET\bin\net45\RGB.NET.Groups.dll ..\packages\Stylet.1.1.22\lib\net45\Stylet.dll @@ -108,6 +113,8 @@ + + diff --git a/src/Artemis.Core/Extensions/RgbColorExtensions.cs b/src/Artemis.Core/Extensions/RgbColorExtensions.cs new file mode 100644 index 000000000..e3dcef4c9 --- /dev/null +++ b/src/Artemis.Core/Extensions/RgbColorExtensions.cs @@ -0,0 +1,14 @@ +using RGB.NET.Core; +using Color = System.Windows.Media.Color; + +namespace Artemis.Core.Extensions +{ + public static class RgbColorExtensions + { + public static Color ToMediaColor(this global::RGB.NET.Core.Color color) + { + var (_, r, g, b) = color.GetRGBBytes(); + return Color.FromRgb(r, g, b); + } + } +} \ No newline at end of file diff --git a/src/Artemis.Core/Extensions/RgbRectangleExtensions.cs b/src/Artemis.Core/Extensions/RgbRectangleExtensions.cs new file mode 100644 index 000000000..c3b54251a --- /dev/null +++ b/src/Artemis.Core/Extensions/RgbRectangleExtensions.cs @@ -0,0 +1,12 @@ +using System.Drawing; + +namespace Artemis.Core.Extensions +{ + public static class RgbRectangleExtensions + { + public static Rectangle ToDrawingRectangle(this global::RGB.NET.Core.Rectangle rectangle) + { + return new Rectangle((int) rectangle.X, (int) rectangle.Y, (int) rectangle.Width, (int) rectangle.Height); + } + } +} \ No newline at end of file diff --git a/src/Artemis.Core/RGB.NET/GraphicsDecorator.cs b/src/Artemis.Core/RGB.NET/GraphicsDecorator.cs index ae909234d..aff6a9663 100644 --- a/src/Artemis.Core/RGB.NET/GraphicsDecorator.cs +++ b/src/Artemis.Core/RGB.NET/GraphicsDecorator.cs @@ -1,4 +1,5 @@ -using System.Drawing; +using System; +using System.Drawing; using System.Linq; using RGB.NET.Core; using RGB.NET.Groups; @@ -21,7 +22,8 @@ namespace Artemis.Core.RGB.NET public Color ManipulateColor(Rectangle rectangle, BrushRenderTarget renderTarget, Color color) { - var pixel = _bitmap.GetPixel((int) (renderTarget.Rectangle.X + renderTarget.Rectangle.Width / 2), (int) (renderTarget.Rectangle.Y + renderTarget.Rectangle.Height / 2)); + var point = renderTarget.Point; + var pixel = _bitmap.GetPixel((int) point.X, (int) point.Y); return new Color(pixel.A, pixel.R, pixel.G, pixel.B); } diff --git a/src/Artemis.Core/Services/RgbService.cs b/src/Artemis.Core/Services/RgbService.cs index 372bbcdb2..2f6050d1e 100644 --- a/src/Artemis.Core/Services/RgbService.cs +++ b/src/Artemis.Core/Services/RgbService.cs @@ -38,30 +38,33 @@ namespace Artemis.Core.Services public RGBSurface Surface { get; set; } public GraphicsDecorator GraphicsDecorator { get; private set; } - + public void AddDeviceProvider(IRGBDeviceProvider deviceProvider) { - Surface.LoadDevices(deviceProvider); - Surface.AlignDevices(); + Surface.LoadDevices(deviceProvider); + Surface.AlignDevices(); - lock (_loadedDevices) - { - foreach (var surfaceDevice in deviceProvider.Devices) - { - if (!_loadedDevices.Contains(surfaceDevice)) - { - _loadedDevices.Add(surfaceDevice); - OnDeviceLoaded(new DeviceEventArgs(surfaceDevice)); - } - else - OnDeviceReloaded(new DeviceEventArgs(surfaceDevice)); - } - } + if (deviceProvider.Devices == null) + return; - // Apply the application wide brush and decorator - var background = new ListLedGroup(Surface.Leds) { Brush = new SolidColorBrush(new Color(255, 255, 255, 255)) }; - GraphicsDecorator = new GraphicsDecorator(background); - background.Brush.AddDecorator(GraphicsDecorator); + lock (_loadedDevices) + { + foreach (var surfaceDevice in deviceProvider.Devices) + { + if (!_loadedDevices.Contains(surfaceDevice)) + { + _loadedDevices.Add(surfaceDevice); + OnDeviceLoaded(new DeviceEventArgs(surfaceDevice)); + } + else + OnDeviceReloaded(new DeviceEventArgs(surfaceDevice)); + } + } + + // Apply the application wide brush and decorator + var background = new ListLedGroup(Surface.Leds) {Brush = new SolidColorBrush(new Color(255, 255, 255, 255))}; + GraphicsDecorator = new GraphicsDecorator(background); + background.Brush.AddDecorator(GraphicsDecorator); } public void Dispose() @@ -91,7 +94,7 @@ namespace Artemis.Core.Services { DeviceReloaded?.Invoke(this, e); } - + #endregion } } \ No newline at end of file diff --git a/src/Artemis.Core/packages.config b/src/Artemis.Core/packages.config index e060ef6e0..a033fbcaa 100644 --- a/src/Artemis.Core/packages.config +++ b/src/Artemis.Core/packages.config @@ -7,10 +7,6 @@ - - - - diff --git a/src/Artemis.Plugins.Devices.Corsair/Artemis.Plugins.Devices.Corsair.csproj b/src/Artemis.Plugins.Devices.Corsair/Artemis.Plugins.Devices.Corsair.csproj index 17c81f079..aeaf33e25 100644 --- a/src/Artemis.Plugins.Devices.Corsair/Artemis.Plugins.Devices.Corsair.csproj +++ b/src/Artemis.Plugins.Devices.Corsair/Artemis.Plugins.Devices.Corsair.csproj @@ -33,12 +33,12 @@ 4 - - ..\packages\RGB.NET.Core.0.1.25\lib\net45\RGB.NET.Core.dll - False + + ..\..\..\RGB.NET\bin\net45\RGB.NET.Core.dll - ..\packages\RGB.NET.Devices.Corsair.0.1.25\lib\net45\RGB.NET.Devices.Corsair.dll + False + ..\..\..\RGB.NET\bin\net45\RGB.NET.Devices.Corsair.dll @@ -72,13 +72,6 @@ - - - - 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}. - - - (robocopy $(TargetDir) %25ProgramData%25\Artemis\plugins\$(ProjectName) /E /NFL /NDL /NJH /NJS /nc /ns /np) ^& IF %25ERRORLEVEL%25 LEQ 4 exit /B 0 diff --git a/src/Artemis.Plugins.Devices.Corsair/packages.config b/src/Artemis.Plugins.Devices.Corsair/packages.config index da764fca9..fc1cee430 100644 --- a/src/Artemis.Plugins.Devices.Corsair/packages.config +++ b/src/Artemis.Plugins.Devices.Corsair/packages.config @@ -1,7 +1,4 @@  - - - \ No newline at end of file diff --git a/src/Artemis.Plugins.LayerTypes.Brush/Artemis.Plugins.LayerTypes.Brush.csproj b/src/Artemis.Plugins.LayerTypes.Brush/Artemis.Plugins.LayerTypes.Brush.csproj index fad0435d5..8445ba521 100644 --- a/src/Artemis.Plugins.LayerTypes.Brush/Artemis.Plugins.LayerTypes.Brush.csproj +++ b/src/Artemis.Plugins.LayerTypes.Brush/Artemis.Plugins.LayerTypes.Brush.csproj @@ -39,7 +39,8 @@ ..\packages\QRCoder.1.2.5\lib\net40\QRCoder.dll - ..\packages\RGB.NET.Core.0.1.25\lib\net45\RGB.NET.Core.dll + False + ..\..\..\RGB.NET\bin\net45\RGB.NET.Core.dll ..\packages\Stylet.1.1.22\lib\net45\Stylet.dll diff --git a/src/Artemis.Plugins.LayerTypes.Brush/packages.config b/src/Artemis.Plugins.LayerTypes.Brush/packages.config index 177f104ab..c8a756cdc 100644 --- a/src/Artemis.Plugins.LayerTypes.Brush/packages.config +++ b/src/Artemis.Plugins.LayerTypes.Brush/packages.config @@ -1,7 +1,6 @@  - \ No newline at end of file diff --git a/src/Artemis.Plugins.Modules.General/Artemis.Plugins.Modules.General.csproj b/src/Artemis.Plugins.Modules.General/Artemis.Plugins.Modules.General.csproj index fdeb10fc3..9e4e5cd89 100644 --- a/src/Artemis.Plugins.Modules.General/Artemis.Plugins.Modules.General.csproj +++ b/src/Artemis.Plugins.Modules.General/Artemis.Plugins.Modules.General.csproj @@ -39,7 +39,8 @@ ..\packages\QRCoder.1.3.5\lib\net40\QRCoder.dll - ..\packages\RGB.NET.Core.0.1.25\lib\net45\RGB.NET.Core.dll + False + ..\..\..\RGB.NET\bin\net45\RGB.NET.Core.dll ..\packages\Stylet.1.1.17\lib\net45\Stylet.dll diff --git a/src/Artemis.Plugins.Modules.General/GeneralModule.cs b/src/Artemis.Plugins.Modules.General/GeneralModule.cs index 7e4db098d..1f193aaed 100644 --- a/src/Artemis.Plugins.Modules.General/GeneralModule.cs +++ b/src/Artemis.Plugins.Modules.General/GeneralModule.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Drawing; using Artemis.Core; +using Artemis.Core.Extensions; using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Models; using Artemis.Core.Services.Interfaces; @@ -57,12 +58,12 @@ namespace Artemis.Plugins.Modules.General public override void Render(double deltaTime, RGBSurface surface, Graphics graphics) { - _circlePosition += deltaTime * 200; - if (_circlePosition > 500) - _circlePosition = -200; - var rect = new Rectangle((int) _circlePosition * 4, 0 , 200, 200); - graphics.FillEllipse(new SolidBrush(Color.Blue), rect); - return; +// _circlePosition += deltaTime * 200; +// if (_circlePosition > 500) +// _circlePosition = -200; +// var rect = new Rectangle((int) _circlePosition * 4, 0 , 200, 200); +// graphics.FillEllipse(new SolidBrush(Color.Blue), rect); +// return; // Lets do this in the least performant way possible foreach (var surfaceLed in _surface.Leds) @@ -71,7 +72,7 @@ namespace Artemis.Plugins.Modules.General continue; var brush = new SolidBrush(_colors[surfaceLed]); - var rectangle = new Rectangle((int) surfaceLed.LedRectangle.X, (int) surfaceLed.LedRectangle.Y, (int) surfaceLed.LedRectangle.Width, (int) surfaceLed.LedRectangle.Height); + var rectangle = surfaceLed.AbsoluteLedRectangle.ToDrawingRectangle(); graphics.FillRectangle(brush, rectangle); UpdateLedColor(surfaceLed, deltaTime); } diff --git a/src/Artemis.Plugins.Modules.General/packages.config b/src/Artemis.Plugins.Modules.General/packages.config index 651f46fbb..17b3103fd 100644 --- a/src/Artemis.Plugins.Modules.General/packages.config +++ b/src/Artemis.Plugins.Modules.General/packages.config @@ -1,7 +1,6 @@  - diff --git a/src/Artemis.UI/Artemis.UI.csproj b/src/Artemis.UI/Artemis.UI.csproj index bfe22e6ac..c2b59f685 100644 --- a/src/Artemis.UI/Artemis.UI.csproj +++ b/src/Artemis.UI/Artemis.UI.csproj @@ -99,17 +99,13 @@ ..\packages\PropertyChanged.Fody.2.6.1\lib\net452\PropertyChanged.dll - - ..\packages\RGB.NET.Brushes.0.1.25\lib\net45\RGB.NET.Brushes.dll - - ..\packages\RGB.NET.Core.0.1.25\lib\net45\RGB.NET.Core.dll - - - ..\packages\RGB.NET.Decorators.0.1.25\lib\net45\RGB.NET.Decorators.dll + False + ..\..\..\RGB.NET\bin\net45\RGB.NET.Core.dll - ..\packages\RGB.NET.Groups.0.1.25\lib\net45\RGB.NET.Groups.dll + False + ..\..\..\RGB.NET\bin\net45\RGB.NET.Groups.dll ..\packages\SharpVectors.Reloaded.1.3.0\lib\net40\SharpVectors.Converters.Wpf.dll @@ -179,6 +175,8 @@ + + diff --git a/src/Artemis.UI/Extensions/RgbColorExtensions.cs b/src/Artemis.UI/Extensions/RgbColorExtensions.cs new file mode 100644 index 000000000..ef4ea741d --- /dev/null +++ b/src/Artemis.UI/Extensions/RgbColorExtensions.cs @@ -0,0 +1,15 @@ +using System; +using RGB.NET.Core; +using Color = System.Windows.Media.Color; + +namespace Artemis.UI.Extensions +{ + public static class RgbColorExtensions + { + public static Color ToMediaColor(this RGB.NET.Core.Color color) + { + var (_, r, g, b) = color.GetRGBBytes(); + return Color.FromRgb(r, g, b); + } + } +} \ No newline at end of file diff --git a/src/Artemis.UI/Extensions/RgbRectangleExtensions.cs b/src/Artemis.UI/Extensions/RgbRectangleExtensions.cs new file mode 100644 index 000000000..83ef976a9 --- /dev/null +++ b/src/Artemis.UI/Extensions/RgbRectangleExtensions.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using RGB.NET.Core; + +namespace Artemis.UI.Extensions +{ + public static class RgbRectangleExtensions + { + public static System.Drawing.Rectangle ToDrawingRectangle(this Rectangle rectangle) + { + return new System.Drawing.Rectangle((int) rectangle.X, (int) rectangle.Y, (int) rectangle.Width, (int) rectangle.Height); + } + } +} \ No newline at end of file diff --git a/src/Artemis.UI/ViewModels/Controls/RgbDevice/RgbLedViewModel.cs b/src/Artemis.UI/ViewModels/Controls/RgbDevice/RgbLedViewModel.cs index 0d1a6d16a..cd50dacf7 100644 --- a/src/Artemis.UI/ViewModels/Controls/RgbDevice/RgbLedViewModel.cs +++ b/src/Artemis.UI/ViewModels/Controls/RgbDevice/RgbLedViewModel.cs @@ -1,13 +1,11 @@ using System; using System.Windows; using System.Windows.Media; -using System.Windows.Shapes; +using Artemis.UI.Extensions; +using PropertyChanged; using RGB.NET.Core; -using SharpVectors.Converters; -using SharpVectors.Renderers.Wpf; using Stylet; using Color = System.Windows.Media.Color; -using Shape = RGB.NET.Core.Shape; namespace Artemis.UI.ViewModels.Controls.RgbDevice { @@ -21,103 +19,77 @@ namespace Artemis.UI.ViewModels.Controls.RgbDevice Update(); } + [DoNotNotify] public Led Led { get; } public double X { get; private set; } - public double Y { get; private set; } - public double Width { get; private set; } - public double Height { get; private set; } - public Color FillColor { get; set; } - - public DrawingImage DisplayDrawing { get; private set; } + public Geometry DisplayGeometry { get; private set; } + public Color DisplayColor { get; private set; } public string Tooltip => $"{Led.Id} - {Led.LedRectangle}"; private void CreateLedGeometry() { - var relativeRectangle = new Rect(0, 0, Led.LedRectangle.Width, Led.LedRectangle.Height); + var geometryRectangle = new Rect(0, 0, 1, 1); Geometry geometry; + switch (Led.Shape) { case Shape.Custom: - geometry = Geometry.Parse(Led.ShapeData); + try + { + geometry = Geometry.Parse(Led.ShapeData); + } + catch (Exception) + { + geometry = new RectangleGeometry(geometryRectangle); + } + break; case Shape.Rectangle: - geometry = new RectangleGeometry(relativeRectangle, 2, 2); + geometry = new RectangleGeometry(geometryRectangle); break; case Shape.Circle: - geometry = new EllipseGeometry(relativeRectangle); + geometry = new EllipseGeometry(geometryRectangle); break; default: throw new ArgumentOutOfRangeException(); } - var drawing = new GeometryDrawing(null, new Pen(null, 2), geometry); - // The pen needs some adjustments when drawing custom shapes, a thickness of 2 just means you get a very thick pen that covers the - // entire shape.. I'm not sure why to be honest sssh don't tell - if (Led.Shape == Shape.Custom) - { - drawing.Pen.Thickness = 0.075; - drawing.Pen.LineJoin = PenLineJoin.Round; - } - - DisplayDrawing = new DrawingImage(drawing); - NotifyOfPropertyChange(() => DisplayDrawing); + DisplayGeometry = Geometry.Combine( + Geometry.Empty, + geometry, + GeometryCombineMode.Union, + new ScaleTransform(Led.LedRectangle.Width, Led.LedRectangle.Height) + ); } public void Update() { - // Not leveraging on OnPropertyChanged since that'll update for each updated property - var changed = false; - - var newFillColor = Color.FromRgb((byte) Math.Round(255 * Led.Color.R), (byte) Math.Round(255 * Led.Color.G), (byte) Math.Round(255 * Led.Color.B)); - if (!newFillColor.Equals(FillColor)) - { - FillColor = newFillColor; - changed = true; - } + var newColor = Led.Color.ToMediaColor(); + SetColor(newColor); if (Math.Abs(Led.LedRectangle.X - X) > 0.1) - { X = Led.LedRectangle.X; - changed = true; - } if (Math.Abs(Led.LedRectangle.Y - Y) > 0.1) - { Y = Led.LedRectangle.Y; - changed = true; - } if (Math.Abs(Led.LedRectangle.Width - Width) > 0.1) - { Width = Led.LedRectangle.Width; - changed = true; - } if (Math.Abs(Led.LedRectangle.Height - Height) > 0.1) - { Height = Led.LedRectangle.Height; - changed = true; - } + } - if (DisplayDrawing != null && changed) - { - Execute.OnUIThread(() => - { - if (DisplayDrawing.Drawing is GeometryDrawing geometryDrawing) - { - geometryDrawing.Brush = new SolidColorBrush(FillColor) {Opacity = 0.3}; - geometryDrawing.Pen.Brush = new SolidColorBrush(FillColor); - } - - NotifyOfPropertyChange(() => DisplayDrawing); - }); - } + public void SetColor(Color color) + { + if (!DisplayColor.Equals(color)) + DisplayColor = color; } } } \ No newline at end of file diff --git a/src/Artemis.UI/Views/Controls/RgbDevice/RgbDeviceView.xaml b/src/Artemis.UI/Views/Controls/RgbDevice/RgbDeviceView.xaml index 13da70e30..a2377915c 100644 --- a/src/Artemis.UI/Views/Controls/RgbDevice/RgbDeviceView.xaml +++ b/src/Artemis.UI/Views/Controls/RgbDevice/RgbDeviceView.xaml @@ -18,16 +18,15 @@ - + - \ No newline at end of file diff --git a/src/Artemis.UI/Views/Controls/RgbDevice/RgbLedView.xaml b/src/Artemis.UI/Views/Controls/RgbDevice/RgbLedView.xaml index 58221db4e..012b3327c 100644 --- a/src/Artemis.UI/Views/Controls/RgbDevice/RgbLedView.xaml +++ b/src/Artemis.UI/Views/Controls/RgbDevice/RgbLedView.xaml @@ -8,5 +8,20 @@ mc:Ignorable="d" d:DataContext="{d:DesignInstance rgbDevice:RgbLedViewModel}" d:DesignHeight="450" d:DesignWidth="800"> - + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/Artemis.UI/packages.config b/src/Artemis.UI/packages.config index a83696401..5d176bdf8 100644 --- a/src/Artemis.UI/packages.config +++ b/src/Artemis.UI/packages.config @@ -14,10 +14,6 @@ - - - -