mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 03:48:56 +00:00
Reference local build of RGB.NET
Rewrote UI LED-rendering, performance needs some work
This commit is contained in:
1 parent
f0db2d7942
commit
b3e035cfb3
20 files changed
+169
-132
No files matched your search
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user