1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Reference local build of RGB.NET

Rewrote UI LED-rendering, performance needs some work
This commit is contained in:
SpoinkyNL 2019-08-19 22:03:37 +02:00
parent d0feed790a
commit 71a6181df7
20 changed files with 169 additions and 132 deletions

View File

@ -73,17 +73,22 @@
<Reference Include="Ninject.Extensions.Factory, Version=3.3.2.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7, processorArchitecture=MSIL"> <Reference Include="Ninject.Extensions.Factory, Version=3.3.2.0, Culture=neutral, PublicKeyToken=c7192dc5380945e7, processorArchitecture=MSIL">
<HintPath>..\packages\Ninject.Extensions.Factory.3.3.2\lib\net45\Ninject.Extensions.Factory.dll</HintPath> <HintPath>..\packages\Ninject.Extensions.Factory.3.3.2\lib\net45\Ninject.Extensions.Factory.dll</HintPath>
</Reference> </Reference>
<Reference Include="PresentationCore" />
<Reference Include="RGB.NET.Brushes, Version=0.1.25.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="RGB.NET.Brushes, Version=0.1.25.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\RGB.NET.Brushes.0.1.25\lib\net45\RGB.NET.Brushes.dll</HintPath> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\RGB.NET\bin\net45\RGB.NET.Brushes.dll</HintPath>
</Reference> </Reference>
<Reference Include="RGB.NET.Core, Version=0.1.25.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="RGB.NET.Core, Version=0.1.25.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\RGB.NET.Core.0.1.25\lib\net45\RGB.NET.Core.dll</HintPath> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\RGB.NET\bin\net45\RGB.NET.Core.dll</HintPath>
</Reference> </Reference>
<Reference Include="RGB.NET.Decorators, Version=0.1.25.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="RGB.NET.Decorators, Version=0.1.25.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\RGB.NET.Decorators.0.1.25\lib\net45\RGB.NET.Decorators.dll</HintPath> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\RGB.NET\bin\net45\RGB.NET.Decorators.dll</HintPath>
</Reference> </Reference>
<Reference Include="RGB.NET.Groups, Version=0.1.25.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="RGB.NET.Groups, Version=0.1.25.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\RGB.NET.Groups.0.1.25\lib\net45\RGB.NET.Groups.dll</HintPath> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\RGB.NET\bin\net45\RGB.NET.Groups.dll</HintPath>
</Reference> </Reference>
<Reference Include="Stylet, Version=1.1.22.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Stylet, Version=1.1.22.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Stylet.1.1.22\lib\net45\Stylet.dll</HintPath> <HintPath>..\packages\Stylet.1.1.22\lib\net45\Stylet.dll</HintPath>
@ -108,6 +113,8 @@
<Compile Include="Constants.cs" /> <Compile Include="Constants.cs" />
<Compile Include="Events\DeviceEventArgs.cs" /> <Compile Include="Events\DeviceEventArgs.cs" />
<Compile Include="Exceptions\ArtemisCoreException.cs" /> <Compile Include="Exceptions\ArtemisCoreException.cs" />
<Compile Include="Extensions\RgbColorExtensions.cs" />
<Compile Include="Extensions\RgbRectangleExtensions.cs" />
<Compile Include="Models\DataModelDescription.cs" /> <Compile Include="Models\DataModelDescription.cs" />
<Compile Include="Ninject\PluginSettingsProvider.cs" /> <Compile Include="Ninject\PluginSettingsProvider.cs" />
<Compile Include="Plugins\Abstract\ModuleDataModel.cs" /> <Compile Include="Plugins\Abstract\ModuleDataModel.cs" />

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}

View File

@ -1,4 +1,5 @@
using System.Drawing; using System;
using System.Drawing;
using System.Linq; using System.Linq;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Groups; using RGB.NET.Groups;
@ -21,7 +22,8 @@ namespace Artemis.Core.RGB.NET
public Color ManipulateColor(Rectangle rectangle, BrushRenderTarget renderTarget, Color color) 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); return new Color(pixel.A, pixel.R, pixel.G, pixel.B);
} }

View File

@ -38,30 +38,33 @@ namespace Artemis.Core.Services
public RGBSurface Surface { get; set; } public RGBSurface Surface { get; set; }
public GraphicsDecorator GraphicsDecorator { get; private set; } public GraphicsDecorator GraphicsDecorator { get; private set; }
public void AddDeviceProvider(IRGBDeviceProvider deviceProvider) public void AddDeviceProvider(IRGBDeviceProvider deviceProvider)
{ {
Surface.LoadDevices(deviceProvider); Surface.LoadDevices(deviceProvider);
Surface.AlignDevices(); Surface.AlignDevices();
lock (_loadedDevices) if (deviceProvider.Devices == null)
{ return;
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 lock (_loadedDevices)
var background = new ListLedGroup(Surface.Leds) { Brush = new SolidColorBrush(new Color(255, 255, 255, 255)) }; {
GraphicsDecorator = new GraphicsDecorator(background); foreach (var surfaceDevice in deviceProvider.Devices)
background.Brush.AddDecorator(GraphicsDecorator); {
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() public void Dispose()
@ -91,7 +94,7 @@ namespace Artemis.Core.Services
{ {
DeviceReloaded?.Invoke(this, e); DeviceReloaded?.Invoke(this, e);
} }
#endregion #endregion
} }
} }

View File

@ -7,10 +7,6 @@
<package id="Ninject.Extensions.ChildKernel" version="3.3.0" targetFramework="net461" /> <package id="Ninject.Extensions.ChildKernel" version="3.3.0" targetFramework="net461" />
<package id="Ninject.Extensions.Conventions" version="3.3.0" targetFramework="net461" /> <package id="Ninject.Extensions.Conventions" version="3.3.0" targetFramework="net461" />
<package id="Ninject.Extensions.Factory" version="3.3.2" targetFramework="net461" /> <package id="Ninject.Extensions.Factory" version="3.3.2" targetFramework="net461" />
<package id="RGB.NET.Brushes" version="0.1.25" targetFramework="net472" />
<package id="RGB.NET.Core" version="0.1.25" targetFramework="net472" />
<package id="RGB.NET.Decorators" version="0.1.25" targetFramework="net472" />
<package id="RGB.NET.Groups" version="0.1.25" targetFramework="net472" />
<package id="Stylet" version="1.1.22" targetFramework="net461" /> <package id="Stylet" version="1.1.22" targetFramework="net461" />
<package id="System.Diagnostics.DiagnosticSource" version="4.5.1" targetFramework="net472" /> <package id="System.Diagnostics.DiagnosticSource" version="4.5.1" targetFramework="net472" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" /> <package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />

View File

@ -33,12 +33,12 @@
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="RGB.NET.Core, Version=0.1.25.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="RGB.NET.Core">
<HintPath>..\packages\RGB.NET.Core.0.1.25\lib\net45\RGB.NET.Core.dll</HintPath> <HintPath>..\..\..\RGB.NET\bin\net45\RGB.NET.Core.dll</HintPath>
<Private>False</Private>
</Reference> </Reference>
<Reference Include="RGB.NET.Devices.Corsair, Version=0.1.25.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="RGB.NET.Devices.Corsair, Version=0.1.25.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\RGB.NET.Devices.Corsair.0.1.25\lib\net45\RGB.NET.Devices.Corsair.dll</HintPath> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\RGB.NET\bin\net45\RGB.NET.Devices.Corsair.dll</HintPath>
</Reference> </Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
@ -72,13 +72,6 @@
</None> </None>
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\RGB.NET.Resources.Corsair.0.3.0.234\build\RGB.NET.Resources.Corsair.targets" Condition="Exists('..\packages\RGB.NET.Resources.Corsair.0.3.0.234\build\RGB.NET.Resources.Corsair.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>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}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\RGB.NET.Resources.Corsair.0.3.0.234\build\RGB.NET.Resources.Corsair.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\RGB.NET.Resources.Corsair.0.3.0.234\build\RGB.NET.Resources.Corsair.targets'))" />
</Target>
<PropertyGroup> <PropertyGroup>
<PostBuildEvent>(robocopy $(TargetDir) %25ProgramData%25\Artemis\plugins\$(ProjectName) /E /NFL /NDL /NJH /NJS /nc /ns /np) ^&amp; IF %25ERRORLEVEL%25 LEQ 4 exit /B 0</PostBuildEvent> <PostBuildEvent>(robocopy $(TargetDir) %25ProgramData%25\Artemis\plugins\$(ProjectName) /E /NFL /NDL /NJH /NJS /nc /ns /np) ^&amp; IF %25ERRORLEVEL%25 LEQ 4 exit /B 0</PostBuildEvent>
</PropertyGroup> </PropertyGroup>

View File

@ -1,7 +1,4 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="RGB.NET.Core" version="0.1.25" targetFramework="net472" />
<package id="RGB.NET.Devices.Corsair" version="0.1.25" targetFramework="net472" />
<package id="RGB.NET.Resources.Corsair" version="0.3.0.234" targetFramework="net472" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" /> <package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
</packages> </packages>

View File

@ -39,7 +39,8 @@
<HintPath>..\packages\QRCoder.1.2.5\lib\net40\QRCoder.dll</HintPath> <HintPath>..\packages\QRCoder.1.2.5\lib\net40\QRCoder.dll</HintPath>
</Reference> </Reference>
<Reference Include="RGB.NET.Core, Version=0.1.25.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="RGB.NET.Core, Version=0.1.25.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\RGB.NET.Core.0.1.25\lib\net45\RGB.NET.Core.dll</HintPath> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\RGB.NET\bin\net45\RGB.NET.Core.dll</HintPath>
</Reference> </Reference>
<Reference Include="Stylet, Version=1.1.22.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Stylet, Version=1.1.22.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Stylet.1.1.22\lib\net45\Stylet.dll</HintPath> <HintPath>..\packages\Stylet.1.1.22\lib\net45\Stylet.dll</HintPath>

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="QRCoder" version="1.2.5" targetFramework="net461" /> <package id="QRCoder" version="1.2.5" targetFramework="net461" />
<package id="RGB.NET.Core" version="0.1.25" targetFramework="net472" />
<package id="Stylet" version="1.1.22" targetFramework="net461" /> <package id="Stylet" version="1.1.22" targetFramework="net461" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" /> <package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
</packages> </packages>

View File

@ -39,7 +39,8 @@
<HintPath>..\packages\QRCoder.1.3.5\lib\net40\QRCoder.dll</HintPath> <HintPath>..\packages\QRCoder.1.3.5\lib\net40\QRCoder.dll</HintPath>
</Reference> </Reference>
<Reference Include="RGB.NET.Core, Version=0.1.25.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="RGB.NET.Core, Version=0.1.25.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\RGB.NET.Core.0.1.25\lib\net45\RGB.NET.Core.dll</HintPath> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\RGB.NET\bin\net45\RGB.NET.Core.dll</HintPath>
</Reference> </Reference>
<Reference Include="Stylet, Version=1.1.17.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Stylet, Version=1.1.17.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Stylet.1.1.17\lib\net45\Stylet.dll</HintPath> <HintPath>..\packages\Stylet.1.1.17\lib\net45\Stylet.dll</HintPath>

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Drawing; using System.Drawing;
using Artemis.Core; using Artemis.Core;
using Artemis.Core.Extensions;
using Artemis.Core.Plugins.Abstract; using Artemis.Core.Plugins.Abstract;
using Artemis.Core.Plugins.Models; using Artemis.Core.Plugins.Models;
using Artemis.Core.Services.Interfaces; using Artemis.Core.Services.Interfaces;
@ -57,12 +58,12 @@ namespace Artemis.Plugins.Modules.General
public override void Render(double deltaTime, RGBSurface surface, Graphics graphics) public override void Render(double deltaTime, RGBSurface surface, Graphics graphics)
{ {
_circlePosition += deltaTime * 200; // _circlePosition += deltaTime * 200;
if (_circlePosition > 500) // if (_circlePosition > 500)
_circlePosition = -200; // _circlePosition = -200;
var rect = new Rectangle((int) _circlePosition * 4, 0 , 200, 200); // var rect = new Rectangle((int) _circlePosition * 4, 0 , 200, 200);
graphics.FillEllipse(new SolidBrush(Color.Blue), rect); // graphics.FillEllipse(new SolidBrush(Color.Blue), rect);
return; // return;
// Lets do this in the least performant way possible // Lets do this in the least performant way possible
foreach (var surfaceLed in _surface.Leds) foreach (var surfaceLed in _surface.Leds)
@ -71,7 +72,7 @@ namespace Artemis.Plugins.Modules.General
continue; continue;
var brush = new SolidBrush(_colors[surfaceLed]); 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); graphics.FillRectangle(brush, rectangle);
UpdateLedColor(surfaceLed, deltaTime); UpdateLedColor(surfaceLed, deltaTime);
} }

View File

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<packages> <packages>
<package id="QRCoder" version="1.3.5" targetFramework="net461" /> <package id="QRCoder" version="1.3.5" targetFramework="net461" />
<package id="RGB.NET.Core" version="0.1.25" targetFramework="net472" />
<package id="Stylet" version="1.1.17" targetFramework="net461" /> <package id="Stylet" version="1.1.17" targetFramework="net461" />
<package id="System.Drawing.Common" version="4.5.0" targetFramework="net461" /> <package id="System.Drawing.Common" version="4.5.0" targetFramework="net461" />
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" /> <package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />

View File

@ -99,17 +99,13 @@
<Reference Include="PropertyChanged, Version=2.6.1.0, Culture=neutral, PublicKeyToken=ee3ee20bcf148ddd, processorArchitecture=MSIL"> <Reference Include="PropertyChanged, Version=2.6.1.0, Culture=neutral, PublicKeyToken=ee3ee20bcf148ddd, processorArchitecture=MSIL">
<HintPath>..\packages\PropertyChanged.Fody.2.6.1\lib\net452\PropertyChanged.dll</HintPath> <HintPath>..\packages\PropertyChanged.Fody.2.6.1\lib\net452\PropertyChanged.dll</HintPath>
</Reference> </Reference>
<Reference Include="RGB.NET.Brushes, Version=0.1.25.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\RGB.NET.Brushes.0.1.25\lib\net45\RGB.NET.Brushes.dll</HintPath>
</Reference>
<Reference Include="RGB.NET.Core, Version=0.1.25.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="RGB.NET.Core, Version=0.1.25.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\RGB.NET.Core.0.1.25\lib\net45\RGB.NET.Core.dll</HintPath> <SpecificVersion>False</SpecificVersion>
</Reference> <HintPath>..\..\..\RGB.NET\bin\net45\RGB.NET.Core.dll</HintPath>
<Reference Include="RGB.NET.Decorators, Version=0.1.25.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\RGB.NET.Decorators.0.1.25\lib\net45\RGB.NET.Decorators.dll</HintPath>
</Reference> </Reference>
<Reference Include="RGB.NET.Groups, Version=0.1.25.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="RGB.NET.Groups, Version=0.1.25.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\RGB.NET.Groups.0.1.25\lib\net45\RGB.NET.Groups.dll</HintPath> <SpecificVersion>False</SpecificVersion>
<HintPath>..\..\..\RGB.NET\bin\net45\RGB.NET.Groups.dll</HintPath>
</Reference> </Reference>
<Reference Include="SharpVectors.Converters.Wpf, Version=1.3.0.0, Culture=neutral, PublicKeyToken=b532964b8548be77, processorArchitecture=MSIL"> <Reference Include="SharpVectors.Converters.Wpf, Version=1.3.0.0, Culture=neutral, PublicKeyToken=b532964b8548be77, processorArchitecture=MSIL">
<HintPath>..\packages\SharpVectors.Reloaded.1.3.0\lib\net40\SharpVectors.Converters.Wpf.dll</HintPath> <HintPath>..\packages\SharpVectors.Reloaded.1.3.0\lib\net40\SharpVectors.Converters.Wpf.dll</HintPath>
@ -179,6 +175,8 @@
<Compile Include="Controls\Visualizers\RGBDeviceVisualizer.cs" /> <Compile Include="Controls\Visualizers\RGBDeviceVisualizer.cs" />
<Compile Include="Controls\Visualizers\RGBSurfaceVisualizer.cs" /> <Compile Include="Controls\Visualizers\RGBSurfaceVisualizer.cs" />
<Compile Include="Converters\ColorToSolidColorBrushConverter.cs" /> <Compile Include="Converters\ColorToSolidColorBrushConverter.cs" />
<Compile Include="Extensions\RgbColorExtensions.cs" />
<Compile Include="Extensions\RgbRectangleExtensions.cs" />
<Compile Include="Ninject\UIModule.cs" /> <Compile Include="Ninject\UIModule.cs" />
<Compile Include="Services\Interfaces\IArtemisUIService.cs" /> <Compile Include="Services\Interfaces\IArtemisUIService.cs" />
<Compile Include="Stylet\ArtemisViewManager.cs" /> <Compile Include="Stylet\ArtemisViewManager.cs" />

View File

@ -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);
}
}
}

View File

@ -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);
}
}
}

View File

@ -1,13 +1,11 @@
using System; using System;
using System.Windows; using System.Windows;
using System.Windows.Media; using System.Windows.Media;
using System.Windows.Shapes; using Artemis.UI.Extensions;
using PropertyChanged;
using RGB.NET.Core; using RGB.NET.Core;
using SharpVectors.Converters;
using SharpVectors.Renderers.Wpf;
using Stylet; using Stylet;
using Color = System.Windows.Media.Color; using Color = System.Windows.Media.Color;
using Shape = RGB.NET.Core.Shape;
namespace Artemis.UI.ViewModels.Controls.RgbDevice namespace Artemis.UI.ViewModels.Controls.RgbDevice
{ {
@ -21,103 +19,77 @@ namespace Artemis.UI.ViewModels.Controls.RgbDevice
Update(); Update();
} }
[DoNotNotify]
public Led Led { get; } public Led Led { get; }
public double X { get; private set; } public double X { get; private set; }
public double Y { get; private set; } public double Y { get; private set; }
public double Width { get; private set; } public double Width { get; private set; }
public double Height { get; private set; } public double Height { get; private set; }
public Color FillColor { get; set; } public Geometry DisplayGeometry { get; private set; }
public Color DisplayColor { get; private set; }
public DrawingImage DisplayDrawing { get; private set; }
public string Tooltip => $"{Led.Id} - {Led.LedRectangle}"; public string Tooltip => $"{Led.Id} - {Led.LedRectangle}";
private void CreateLedGeometry() 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; Geometry geometry;
switch (Led.Shape) switch (Led.Shape)
{ {
case Shape.Custom: case Shape.Custom:
geometry = Geometry.Parse(Led.ShapeData); try
{
geometry = Geometry.Parse(Led.ShapeData);
}
catch (Exception)
{
geometry = new RectangleGeometry(geometryRectangle);
}
break; break;
case Shape.Rectangle: case Shape.Rectangle:
geometry = new RectangleGeometry(relativeRectangle, 2, 2); geometry = new RectangleGeometry(geometryRectangle);
break; break;
case Shape.Circle: case Shape.Circle:
geometry = new EllipseGeometry(relativeRectangle); geometry = new EllipseGeometry(geometryRectangle);
break; break;
default: default:
throw new ArgumentOutOfRangeException(); 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 DisplayGeometry = Geometry.Combine(
// entire shape.. I'm not sure why to be honest sssh don't tell Geometry.Empty,
if (Led.Shape == Shape.Custom) geometry,
{ GeometryCombineMode.Union,
drawing.Pen.Thickness = 0.075; new ScaleTransform(Led.LedRectangle.Width, Led.LedRectangle.Height)
drawing.Pen.LineJoin = PenLineJoin.Round; );
}
DisplayDrawing = new DrawingImage(drawing);
NotifyOfPropertyChange(() => DisplayDrawing);
} }
public void Update() public void Update()
{ {
// Not leveraging on OnPropertyChanged since that'll update for each updated property var newColor = Led.Color.ToMediaColor();
var changed = false; SetColor(newColor);
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;
}
if (Math.Abs(Led.LedRectangle.X - X) > 0.1) if (Math.Abs(Led.LedRectangle.X - X) > 0.1)
{
X = Led.LedRectangle.X; X = Led.LedRectangle.X;
changed = true;
}
if (Math.Abs(Led.LedRectangle.Y - Y) > 0.1) if (Math.Abs(Led.LedRectangle.Y - Y) > 0.1)
{
Y = Led.LedRectangle.Y; Y = Led.LedRectangle.Y;
changed = true;
}
if (Math.Abs(Led.LedRectangle.Width - Width) > 0.1) if (Math.Abs(Led.LedRectangle.Width - Width) > 0.1)
{
Width = Led.LedRectangle.Width; Width = Led.LedRectangle.Width;
changed = true;
}
if (Math.Abs(Led.LedRectangle.Height - Height) > 0.1) if (Math.Abs(Led.LedRectangle.Height - Height) > 0.1)
{
Height = Led.LedRectangle.Height; Height = Led.LedRectangle.Height;
changed = true; }
}
if (DisplayDrawing != null && changed) public void SetColor(Color color)
{ {
Execute.OnUIThread(() => if (!DisplayColor.Equals(color))
{ DisplayColor = color;
if (DisplayDrawing.Drawing is GeometryDrawing geometryDrawing)
{
geometryDrawing.Brush = new SolidColorBrush(FillColor) {Opacity = 0.3};
geometryDrawing.Pen.Brush = new SolidColorBrush(FillColor);
}
NotifyOfPropertyChange(() => DisplayDrawing);
});
}
} }
} }
} }

View File

@ -18,16 +18,15 @@
</ItemsControl.ItemsPanel> </ItemsControl.ItemsPanel>
<ItemsControl.ItemContainerStyle> <ItemsControl.ItemContainerStyle>
<Style TargetType="ContentPresenter"> <Style TargetType="ContentPresenter">
<Setter Property="Canvas.Left" Value="{Binding Led.LedRectangle.X}" /> <Setter Property="Canvas.Left" Value="{Binding X}" />
<Setter Property="Canvas.Top" Value="{Binding Led.LedRectangle.Y}" /> <Setter Property="Canvas.Top" Value="{Binding Y}" />
</Style> </Style>
</ItemsControl.ItemContainerStyle> </ItemsControl.ItemContainerStyle>
<ItemsControl.ItemTemplate> <ItemsControl.ItemTemplate>
<DataTemplate> <DataTemplate>
<ContentControl Width="{Binding Led.LedRectangle.Width}" Height="{Binding Led.LedRectangle.Width}" xaml:View.Model="{Binding}" ToolTip="{Binding Tooltip}" /> <ContentControl Width="{Binding Width}" Height="{Binding Height}" xaml:View.Model="{Binding}" ToolTip="{Binding Tooltip}" />
</DataTemplate> </DataTemplate>
</ItemsControl.ItemTemplate> </ItemsControl.ItemTemplate>
</ItemsControl> </ItemsControl>
</Grid> </Grid>
</UserControl> </UserControl>

View File

@ -8,5 +8,20 @@
mc:Ignorable="d" mc:Ignorable="d"
d:DataContext="{d:DesignInstance rgbDevice:RgbLedViewModel}" d:DataContext="{d:DesignInstance rgbDevice:RgbLedViewModel}"
d:DesignHeight="450" d:DesignWidth="800"> d:DesignHeight="450" d:DesignWidth="800">
<Image Width="Auto" Height="Auto" Source="{Binding DisplayDrawing}" Margin="2" /> <Border Width="{Binding Width}" Height="{Binding Height}">
<Border.Background>
<ImageBrush AlignmentX="Center" AlignmentY="Center"
Stretch="Fill"
ImageSource="{Binding Led.Image}" />
</Border.Background>
<Path Data="{Binding DisplayGeometry}" ClipToBounds="False" StrokeThickness="2">
<Path.Fill>
<SolidColorBrush Color="{Binding DisplayColor}" Opacity="0.25" />
</Path.Fill>
<!-- TODO: Causes big perf degradation because it makes the entire path recalculate its size -->
<Path.Stroke>
<SolidColorBrush Color="{Binding DisplayColor}" />
</Path.Stroke>
</Path>
</Border>
</UserControl> </UserControl>

View File

@ -14,10 +14,6 @@
<package id="Ninject.Extensions.Conventions" version="3.3.0" targetFramework="net461" /> <package id="Ninject.Extensions.Conventions" version="3.3.0" targetFramework="net461" />
<package id="Ninject.Extensions.Factory" version="3.3.2" targetFramework="net461" /> <package id="Ninject.Extensions.Factory" version="3.3.2" targetFramework="net461" />
<package id="PropertyChanged.Fody" version="2.6.1" targetFramework="net461" /> <package id="PropertyChanged.Fody" version="2.6.1" targetFramework="net461" />
<package id="RGB.NET.Brushes" version="0.1.25" targetFramework="net472" />
<package id="RGB.NET.Core" version="0.1.25" targetFramework="net472" />
<package id="RGB.NET.Decorators" version="0.1.25" targetFramework="net472" />
<package id="RGB.NET.Groups" version="0.1.25" targetFramework="net472" />
<package id="SharpVectors.Reloaded" version="1.3.0" targetFramework="net472" /> <package id="SharpVectors.Reloaded" version="1.3.0" targetFramework="net472" />
<package id="SQLitePCLRaw.bundle_green" version="1.1.12" targetFramework="net472" /> <package id="SQLitePCLRaw.bundle_green" version="1.1.12" targetFramework="net472" />
<package id="SQLitePCLRaw.core" version="1.1.12" targetFramework="net472" /> <package id="SQLitePCLRaw.core" version="1.1.12" targetFramework="net472" />