Reference local build of RGB.NET

Rewrote UI LED-rendering, performance needs some work
This commit is contained in:
SpoinkyNL committed 2019-08-19 22:03:37 +02:00
1 parent f0db2d7942
commit b3e035cfb3
20 files changed
+169 -132

No files matched your search

+6 -8
View File
@@ -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" />
@@ -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);
}
}
}
@@ -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>
-4
View File
@@ -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" />