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:
parent
d0feed790a
commit
71a6181df7
@ -73,17 +73,22 @@
|
||||
<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>
|
||||
</Reference>
|
||||
<Reference Include="PresentationCore" />
|
||||
<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 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 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 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 Include="Stylet, Version=1.1.22.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Stylet.1.1.22\lib\net45\Stylet.dll</HintPath>
|
||||
@ -108,6 +113,8 @@
|
||||
<Compile Include="Constants.cs" />
|
||||
<Compile Include="Events\DeviceEventArgs.cs" />
|
||||
<Compile Include="Exceptions\ArtemisCoreException.cs" />
|
||||
<Compile Include="Extensions\RgbColorExtensions.cs" />
|
||||
<Compile Include="Extensions\RgbRectangleExtensions.cs" />
|
||||
<Compile Include="Models\DataModelDescription.cs" />
|
||||
<Compile Include="Ninject\PluginSettingsProvider.cs" />
|
||||
<Compile Include="Plugins\Abstract\ModuleDataModel.cs" />
|
||||
|
||||
14
src/Artemis.Core/Extensions/RgbColorExtensions.cs
Normal file
14
src/Artemis.Core/Extensions/RgbColorExtensions.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
12
src/Artemis.Core/Extensions/RgbRectangleExtensions.cs
Normal file
12
src/Artemis.Core/Extensions/RgbRectangleExtensions.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
@ -7,10 +7,6 @@
|
||||
<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.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="System.Diagnostics.DiagnosticSource" version="4.5.1" targetFramework="net472" />
|
||||
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
|
||||
|
||||
@ -33,12 +33,12 @@
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<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>
|
||||
<Private>False</Private>
|
||||
<Reference Include="RGB.NET.Core">
|
||||
<HintPath>..\..\..\RGB.NET\bin\net45\RGB.NET.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<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 Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
@ -72,13 +72,6 @@
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<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>
|
||||
<PostBuildEvent>(robocopy $(TargetDir) %25ProgramData%25\Artemis\plugins\$(ProjectName) /E /NFL /NDL /NJH /NJS /nc /ns /np) ^& IF %25ERRORLEVEL%25 LEQ 4 exit /B 0</PostBuildEvent>
|
||||
</PropertyGroup>
|
||||
|
||||
@ -1,7 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<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" />
|
||||
</packages>
|
||||
@ -39,7 +39,8 @@
|
||||
<HintPath>..\packages\QRCoder.1.2.5\lib\net40\QRCoder.dll</HintPath>
|
||||
</Reference>
|
||||
<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 Include="Stylet, Version=1.1.22.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Stylet.1.1.22\lib\net45\Stylet.dll</HintPath>
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<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="System.ValueTuple" version="4.5.0" targetFramework="net472" />
|
||||
</packages>
|
||||
@ -39,7 +39,8 @@
|
||||
<HintPath>..\packages\QRCoder.1.3.5\lib\net40\QRCoder.dll</HintPath>
|
||||
</Reference>
|
||||
<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 Include="Stylet, Version=1.1.17.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\Stylet.1.1.17\lib\net45\Stylet.dll</HintPath>
|
||||
|
||||
@ -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);
|
||||
}
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<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="System.Drawing.Common" version="4.5.0" targetFramework="net461" />
|
||||
<package id="System.ValueTuple" version="4.5.0" targetFramework="net472" />
|
||||
|
||||
@ -99,17 +99,13 @@
|
||||
<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>
|
||||
</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">
|
||||
<HintPath>..\packages\RGB.NET.Core.0.1.25\lib\net45\RGB.NET.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<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.Core.dll</HintPath>
|
||||
</Reference>
|
||||
<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 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>
|
||||
@ -179,6 +175,8 @@
|
||||
<Compile Include="Controls\Visualizers\RGBDeviceVisualizer.cs" />
|
||||
<Compile Include="Controls\Visualizers\RGBSurfaceVisualizer.cs" />
|
||||
<Compile Include="Converters\ColorToSolidColorBrushConverter.cs" />
|
||||
<Compile Include="Extensions\RgbColorExtensions.cs" />
|
||||
<Compile Include="Extensions\RgbRectangleExtensions.cs" />
|
||||
<Compile Include="Ninject\UIModule.cs" />
|
||||
<Compile Include="Services\Interfaces\IArtemisUIService.cs" />
|
||||
<Compile Include="Stylet\ArtemisViewManager.cs" />
|
||||
|
||||
15
src/Artemis.UI/Extensions/RgbColorExtensions.cs
Normal file
15
src/Artemis.UI/Extensions/RgbColorExtensions.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
17
src/Artemis.UI/Extensions/RgbRectangleExtensions.cs
Normal file
17
src/Artemis.UI/Extensions/RgbRectangleExtensions.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -18,16 +18,15 @@
|
||||
</ItemsControl.ItemsPanel>
|
||||
<ItemsControl.ItemContainerStyle>
|
||||
<Style TargetType="ContentPresenter">
|
||||
<Setter Property="Canvas.Left" Value="{Binding Led.LedRectangle.X}" />
|
||||
<Setter Property="Canvas.Top" Value="{Binding Led.LedRectangle.Y}" />
|
||||
<Setter Property="Canvas.Left" Value="{Binding X}" />
|
||||
<Setter Property="Canvas.Top" Value="{Binding Y}" />
|
||||
</Style>
|
||||
</ItemsControl.ItemContainerStyle>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<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>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@ -8,5 +8,20 @@
|
||||
mc:Ignorable="d"
|
||||
d:DataContext="{d:DesignInstance rgbDevice:RgbLedViewModel}"
|
||||
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>
|
||||
@ -14,10 +14,6 @@
|
||||
<package id="Ninject.Extensions.Conventions" version="3.3.0" 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="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="SQLitePCLRaw.bundle_green" version="1.1.12" targetFramework="net472" />
|
||||
<package id="SQLitePCLRaw.core" version="1.1.12" targetFramework="net472" />
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user