Device visualizer - Fixed custom LED shapes not being positioned correct

This commit is contained in:
SpoinkyNL committed 2020-07-31 23:51:28 +02:00
1 parent 1440fe95b9
commit f36049a0e1
2 files changed
+13 -11

No files matched your search

@@ -107,10 +107,11 @@ namespace Artemis.UI.Shared.Controls
{ {
if (Device == null) if (Device == null)
return Size.Empty; return Size.Empty;
var rotationRect = new Rect(0, 0, Device.RgbDevice.ActualSize.Width, Device.RgbDevice.ActualSize.Height); var rotationRect = new Rect(0, 0, Device.RgbDevice.ActualSize.Width, Device.RgbDevice.ActualSize.Height);
rotationRect.Transform(new RotateTransform(Device.Rotation).Value); rotationRect.Transform(new RotateTransform(Device.Rotation).Value);
// TODO: If availableSize exceeds what we need, scale up
return rotationRect.Size; return rotationRect.Size;
} }
@@ -13,8 +13,6 @@ namespace Artemis.UI.Shared.Controls
{ {
public DeviceVisualizerLed(ArtemisLed led) public DeviceVisualizerLed(ArtemisLed led)
{ {
if (led.Device.Scale != 1)
Console.WriteLine();
Led = led; Led = led;
LedRect = new Rect( LedRect = new Rect(
Led.RgbLed.Location.X, Led.RgbLed.Location.X,
@@ -44,7 +42,7 @@ namespace Artemis.UI.Shared.Controls
var r = Led.RgbLed.Color.GetR(); var r = Led.RgbLed.Color.GetR();
var g = Led.RgbLed.Color.GetG(); var g = Led.RgbLed.Color.GetG();
var b = Led.RgbLed.Color.GetB(); var b = Led.RgbLed.Color.GetB();
drawingContext.DrawRectangle(isDimmed drawingContext.DrawRectangle(isDimmed
? new SolidColorBrush(Color.FromArgb(100, r, g, b)) ? new SolidColorBrush(Color.FromArgb(100, r, g, b))
: new SolidColorBrush(Color.FromRgb(r, g, b)), null, LedRect); : new SolidColorBrush(Color.FromRgb(r, g, b)), null, LedRect);
@@ -68,7 +66,14 @@ namespace Artemis.UI.Shared.Controls
var penBrush = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255)); var penBrush = new SolidColorBrush(Color.FromArgb(255, 255, 255, 255));
penBrush.Freeze(); penBrush.Freeze();
drawingContext.DrawGeometry(fillBrush, new Pen(penBrush, 1), DisplayGeometry); // Create transparent pixels covering the entire LedRect so the image size matched the LedRect size
drawingContext.DrawRectangle(new SolidColorBrush(Colors.Transparent), null, LedRect);
// Translate to the top-left of the LedRect
drawingContext.PushTransform(new TranslateTransform(LedRect.X, LedRect.Y));
// Render the LED geometry
drawingContext.DrawGeometry(fillBrush, new Pen(penBrush, 1) {LineJoin = PenLineJoin.Round}, DisplayGeometry.GetOutlinedPathGeometry());
// Restore the drawing context
drawingContext.Pop();
} }
private void CreateLedGeometry() private void CreateLedGeometry()
@@ -83,7 +88,7 @@ namespace Artemis.UI.Shared.Controls
if (Led.RgbLed.Device.DeviceInfo.DeviceType == RGBDeviceType.Keyboard || Led.RgbLed.Device.DeviceInfo.DeviceType == RGBDeviceType.Keypad) if (Led.RgbLed.Device.DeviceInfo.DeviceType == RGBDeviceType.Keyboard || Led.RgbLed.Device.DeviceInfo.DeviceType == RGBDeviceType.Keypad)
CreateCustomGeometry(2.0); CreateCustomGeometry(2.0);
else else
CreateCustomGeometry(1.0); CreateCustomGeometry(0);
break; break;
case Shape.Rectangle: case Shape.Rectangle:
if (Led.RgbLed.Device.DeviceInfo.DeviceType == RGBDeviceType.Keyboard || Led.RgbLed.Device.DeviceInfo.DeviceType == RGBDeviceType.Keypad) if (Led.RgbLed.Device.DeviceInfo.DeviceType == RGBDeviceType.Keyboard || Led.RgbLed.Device.DeviceInfo.DeviceType == RGBDeviceType.Keypad)
@@ -97,11 +102,6 @@ namespace Artemis.UI.Shared.Controls
default: default:
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException();
} }
// Stroke geometry is the display geometry excluding the inner geometry
DisplayGeometry.Transform = new TranslateTransform(Led.RgbLed.Location.X, Led.RgbLed.Location.Y);
// Try to gain some performance
DisplayGeometry.Freeze();
} }
private void CreateRectangleGeometry() private void CreateRectangleGeometry()
@@ -123,6 +123,7 @@ namespace Artemis.UI.Shared.Controls
{ {
try try
{ {
// DisplayGeometry = Geometry.Parse(Led.RgbLed.ShapeData);
DisplayGeometry = Geometry.Combine( DisplayGeometry = Geometry.Combine(
Geometry.Empty, Geometry.Empty,
Geometry.Parse(Led.RgbLed.ShapeData), Geometry.Parse(Led.RgbLed.ShapeData),