1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2026-01-01 10:13:30 +00:00

Devices - Reimplemented LED images

This commit is contained in:
Robert 2021-02-11 22:49:51 +01:00
parent 956ebd3313
commit c70e7d0c00
6 changed files with 114 additions and 69 deletions

View File

@ -334,11 +334,11 @@ namespace Artemis.Core
if (layout.IsValid) if (layout.IsValid)
layout.RgbLayout!.ApplyTo(RgbDevice); layout.RgbLayout!.ApplyTo(RgbDevice);
Layout = layout;
Leds = RgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly(); Leds = RgbDevice.Select(l => new ArtemisLed(l, this)).ToList().AsReadOnly();
LedIds = new ReadOnlyDictionary<LedId, ArtemisLed>(Leds.ToDictionary(l => l.RgbLed.Id, l => l)); LedIds = new ReadOnlyDictionary<LedId, ArtemisLed>(Leds.ToDictionary(l => l.RgbLed.Id, l => l));
Layout = layout;
Layout.ApplyDevice(this); Layout.ApplyDevice(this);
Leds = Layout.Leds.Select(l => l.Led);
} }
internal void ApplyToEntity() internal void ApplyToEntity()

View File

@ -1,5 +1,4 @@
using System.Linq; using RGB.NET.Core;
using RGB.NET.Core;
using SkiaSharp; using SkiaSharp;
namespace Artemis.Core namespace Artemis.Core
@ -17,9 +16,6 @@ namespace Artemis.Core
RgbLed = led; RgbLed = led;
Device = device; Device = device;
CalculateRectangles(); CalculateRectangles();
Layout = Device.Layout?.Leds.FirstOrDefault(l => l.RgbLayout.Id == led.Id.ToString());
} }
/// <summary> /// <summary>
@ -50,13 +46,7 @@ namespace Artemis.Core
private set => SetAndNotify(ref _absoluteRectangle, value); private set => SetAndNotify(ref _absoluteRectangle, value);
} }
public ArtemisLedLayout? Layout { get; } public ArtemisLedLayout? Layout { get; internal set; }
internal void CalculateRectangles()
{
Rectangle = RgbLed.Boundary.ToSKRect();
AbsoluteRectangle = RgbLed.AbsoluteBoundary.ToSKRect();
}
/// <inheritdoc /> /// <inheritdoc />
public override string ToString() public override string ToString()
@ -72,5 +62,11 @@ namespace Artemis.Core
{ {
return RgbLed.Color.DivideRGB(Device.RedScale, Device.GreenScale, Device.BlueScale); return RgbLed.Color.DivideRGB(Device.RedScale, Device.GreenScale, Device.BlueScale);
} }
internal void CalculateRectangles()
{
Rectangle = RgbLed.Boundary.ToSKRect();
AbsoluteRectangle = RgbLed.AbsoluteBoundary.ToSKRect();
}
} }
} }

View File

@ -60,9 +60,9 @@ namespace Artemis.Core
public bool IsValid { get; } public bool IsValid { get; }
/// <summary> /// <summary>
/// Gets or sets the image of the device /// Gets the image of the device
/// </summary> /// </summary>
public Uri? Image { get; set; } public Uri? Image { get; private set; }
public List<ArtemisLedLayout> Leds { get; } public List<ArtemisLedLayout> Leds { get; }

View File

@ -7,17 +7,20 @@ namespace Artemis.Core
{ {
public class ArtemisLedLayout public class ArtemisLedLayout
{ {
internal ArtemisLedLayout(ArtemisLayout layout, ILedLayout led) internal ArtemisLedLayout(ArtemisLayout deviceLayout, ILedLayout led)
{ {
Layout = layout; DeviceLayout = deviceLayout;
RgbLayout = led; RgbLayout = led;
LayoutCustomLedData = (LayoutCustomLedData?) led.CustomData ?? new LayoutCustomLedData(); LayoutCustomLedData = (LayoutCustomLedData?) led.CustomData ?? new LayoutCustomLedData();
} }
public ArtemisLayout Layout { get; } /// <summary>
/// Gets the device layout of this LED layout
/// </summary>
public ArtemisLayout DeviceLayout { get; }
/// <summary> /// <summary>
/// Gets the RGB.NET LED Layout of this Artemis LED layout /// Gets the RGB.NET LED Layout of this LED layout
/// </summary> /// </summary>
public ILedLayout RgbLayout { get; } public ILedLayout RgbLayout { get; }
@ -38,18 +41,29 @@ namespace Artemis.Core
internal LayoutCustomLedData LayoutCustomLedData { get; set; } internal LayoutCustomLedData LayoutCustomLedData { get; set; }
public void ApplyDevice(ArtemisDevice device) internal void ApplyDevice(ArtemisDevice device)
{ {
Led = device.Leds.FirstOrDefault(d => d.RgbLed.Id.ToString() == RgbLayout.Id); Led = device.Leds.FirstOrDefault(d => d.RgbLed.Id.ToString() == RgbLayout.Id);
ApplyCustomLedData(); if (Led != null)
Led.Layout = this;
ApplyCustomLedData(device);
} }
private void ApplyCustomLedData() private void ApplyCustomLedData(ArtemisDevice artemisDevice)
{ {
if (Led == null) if (LayoutCustomLedData.LogicalLayouts == null || !LayoutCustomLedData.LogicalLayouts.Any())
return; return;
Uri layoutDirectory = new(Path.GetDirectoryName(Layout.FilePath)! + "\\", UriKind.Absolute); Uri layoutDirectory = new(Path.GetDirectoryName(DeviceLayout.FilePath)! + "\\", UriKind.Absolute);
// Prefer a matching layout or else a default layout (that has no name)
LayoutCustomLedDataLogicalLayout logicalLayout = LayoutCustomLedData.LogicalLayouts
.OrderBy(l => l.Name == artemisDevice.LogicalLayout)
.ThenBy(l => l.Name == null)
.First();
LogicalName = logicalLayout.Name;
Image = new Uri(layoutDirectory, logicalLayout.Image);
} }
} }
} }

View File

@ -23,7 +23,7 @@ namespace Artemis.UI.Shared
Led.RgbLed.Size.Height Led.RgbLed.Size.Height
); );
if (Led.Layout?.Image != null && File.Exists(Led.Layout.Image.AbsolutePath)) if (Led.Layout?.Image != null && File.Exists(Led.Layout.Image.LocalPath))
LedImage = new BitmapImage(Led.Layout.Image); LedImage = new BitmapImage(Led.Layout.Image);
CreateLedGeometry(); CreateLedGeometry();

View File

@ -56,16 +56,16 @@
<RowDefinition Height="*" /> <RowDefinition Height="*" />
</Grid.RowDefinitions> </Grid.RowDefinitions>
<TextBlock TextWrapping="Wrap" Margin="0 0 00 10"> <TextBlock TextWrapping="Wrap" Margin="0 0 00 10">
In this window you can view detailed information of the device. In this window you can view detailed information of the device.
Please note that having this window open can have a performance impact on your system. Please note that having this window open can have a performance impact on your system.
</TextBlock> </TextBlock>
<materialDesign:Card materialDesign:ShadowAssist.ShadowDepth="Depth1" Grid.Row="1" Padding="15"> <materialDesign:Card materialDesign:ShadowAssist.ShadowDepth="Depth1" Grid.Row="1" Padding="15">
<shared:DeviceVisualizer Device="{Binding Device}" <shared:DeviceVisualizer Device="{Binding Device}"
HighlightedLeds="{Binding SelectedLeds}" HighlightedLeds="{Binding SelectedLeds}"
HorizontalAlignment="Center" HorizontalAlignment="Center"
MaxHeight="400" MaxHeight="400"
ShowColors="True"/> ShowColors="True" />
</materialDesign:Card> </materialDesign:Card>
<Expander Grid.Row="2" VerticalAlignment="Center" Header="Device properties" Margin="0 15"> <Expander Grid.Row="2" VerticalAlignment="Center" Header="Device properties" Margin="0 15">
@ -87,9 +87,9 @@
<StackPanel Grid.Column="0"> <StackPanel Grid.Column="0">
<TextBlock Style="{StaticResource MaterialDesignTextBlock}">Device name</TextBlock> <TextBlock Style="{StaticResource MaterialDesignTextBlock}">Device name</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignTextBlock}" <TextBlock Style="{StaticResource MaterialDesignTextBlock}"
Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}" Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}"
TextWrapping="Wrap" TextWrapping="Wrap"
Text="{Binding Device.RgbDevice.DeviceInfo.DeviceName}" /> Text="{Binding Device.RgbDevice.DeviceInfo.DeviceName}" />
</StackPanel> </StackPanel>
</Grid> </Grid>
<Separator Style="{StaticResource MaterialDesignSeparator}" Margin="-15 5" /> <Separator Style="{StaticResource MaterialDesignSeparator}" Margin="-15 5" />
@ -105,9 +105,9 @@
<StackPanel Grid.Column="0"> <StackPanel Grid.Column="0">
<TextBlock Style="{StaticResource MaterialDesignTextBlock}">Manufacturer</TextBlock> <TextBlock Style="{StaticResource MaterialDesignTextBlock}">Manufacturer</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignTextBlock}" <TextBlock Style="{StaticResource MaterialDesignTextBlock}"
Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}" Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}"
TextWrapping="Wrap" TextWrapping="Wrap"
Text="{Binding Device.RgbDevice.DeviceInfo.Manufacturer}" /> Text="{Binding Device.RgbDevice.DeviceInfo.Manufacturer}" />
</StackPanel> </StackPanel>
</Grid> </Grid>
<Separator Style="{StaticResource MaterialDesignSeparator}" Margin="-15 5" /> <Separator Style="{StaticResource MaterialDesignSeparator}" Margin="-15 5" />
@ -123,9 +123,27 @@
<StackPanel Grid.Column="0"> <StackPanel Grid.Column="0">
<TextBlock Style="{StaticResource MaterialDesignTextBlock}">Device type</TextBlock> <TextBlock Style="{StaticResource MaterialDesignTextBlock}">Device type</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignTextBlock}" <TextBlock Style="{StaticResource MaterialDesignTextBlock}"
Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}" Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}"
TextWrapping="Wrap" TextWrapping="Wrap"
Text="{Binding Device.RgbDevice.DeviceInfo.DeviceType}" /> Text="{Binding Device.RgbDevice.DeviceInfo.DeviceType}" />
</StackPanel>
</Grid>
<Separator Style="{StaticResource MaterialDesignSeparator}" Margin="-15 5" />
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<TextBlock Style="{StaticResource MaterialDesignTextBlock}">Physical layout</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignTextBlock}"
Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}"
TextWrapping="Wrap"
Text="{Binding Device.PhysicalLayout}" />
</StackPanel> </StackPanel>
</Grid> </Grid>
<Separator Style="{StaticResource MaterialDesignSeparator}" Margin="-15 5" /> <Separator Style="{StaticResource MaterialDesignSeparator}" Margin="-15 5" />
@ -141,14 +159,14 @@
<StackPanel Grid.Column="0"> <StackPanel Grid.Column="0">
<TextBlock Style="{StaticResource MaterialDesignTextBlock}">Device image</TextBlock> <TextBlock Style="{StaticResource MaterialDesignTextBlock}">Device image</TextBlock>
<TextBox Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}" <TextBox Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}"
TextWrapping="Wrap" TextWrapping="Wrap"
Text="{Binding Device.Layout.Image, Mode=OneWay}" Text="{Binding Device.Layout.Image, Mode=OneWay}"
IsReadOnly="True" /> IsReadOnly="True" />
</StackPanel> </StackPanel>
</Grid> </Grid>
</StackPanel> </StackPanel>
</materialDesign:Card> </materialDesign:Card>
<materialDesign:Card Grid.Column="1" materialDesign:ShadowAssist.ShadowDepth="Depth1" Margin="5,0,0,0" > <materialDesign:Card Grid.Column="1" materialDesign:ShadowAssist.ShadowDepth="Depth1" Margin="5,0,0,0">
<StackPanel Margin="15" HorizontalAlignment="Stretch"> <StackPanel Margin="15" HorizontalAlignment="Stretch">
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
@ -161,9 +179,9 @@
<StackPanel Grid.Column="0"> <StackPanel Grid.Column="0">
<TextBlock Style="{StaticResource MaterialDesignTextBlock}">Size (1px = 1mm)</TextBlock> <TextBlock Style="{StaticResource MaterialDesignTextBlock}">Size (1px = 1mm)</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignTextBlock}" <TextBlock Style="{StaticResource MaterialDesignTextBlock}"
Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}" Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}"
TextWrapping="Wrap" TextWrapping="Wrap"
Text="{Binding Device.RgbDevice.Size}" /> Text="{Binding Device.RgbDevice.Size}" />
</StackPanel> </StackPanel>
</Grid> </Grid>
<Separator Style="{StaticResource MaterialDesignSeparator}" Margin="-15 5" /> <Separator Style="{StaticResource MaterialDesignSeparator}" Margin="-15 5" />
@ -178,9 +196,9 @@
<StackPanel Grid.Column="0"> <StackPanel Grid.Column="0">
<TextBlock Style="{StaticResource MaterialDesignTextBlock}">Location (1px = 1mm)</TextBlock> <TextBlock Style="{StaticResource MaterialDesignTextBlock}">Location (1px = 1mm)</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignTextBlock}" <TextBlock Style="{StaticResource MaterialDesignTextBlock}"
Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}" Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}"
TextWrapping="Wrap" TextWrapping="Wrap"
Text="{Binding Device.RgbDevice.Location}" /> Text="{Binding Device.RgbDevice.Location}" />
</StackPanel> </StackPanel>
</Grid> </Grid>
<Separator Style="{StaticResource MaterialDesignSeparator}" Margin="-15 5" /> <Separator Style="{StaticResource MaterialDesignSeparator}" Margin="-15 5" />
@ -196,9 +214,27 @@
<StackPanel Grid.Column="0"> <StackPanel Grid.Column="0">
<TextBlock Style="{StaticResource MaterialDesignTextBlock}">Rotation (degrees)</TextBlock> <TextBlock Style="{StaticResource MaterialDesignTextBlock}">Rotation (degrees)</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignTextBlock}" <TextBlock Style="{StaticResource MaterialDesignTextBlock}"
Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}" Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}"
TextWrapping="Wrap" TextWrapping="Wrap"
Text="{Binding Device.RgbDevice.Rotation.Degrees}" /> Text="{Binding Device.RgbDevice.Rotation.Degrees}" />
</StackPanel>
</Grid>
<Separator Style="{StaticResource MaterialDesignSeparator}" Margin="-15 5" />
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<StackPanel Grid.Column="0">
<TextBlock Style="{StaticResource MaterialDesignTextBlock}">Logical layout</TextBlock>
<TextBlock Style="{StaticResource MaterialDesignTextBlock}"
Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}"
TextWrapping="Wrap"
Text="{Binding Device.LogicalLayout}" />
</StackPanel> </StackPanel>
</Grid> </Grid>
<Separator Style="{StaticResource MaterialDesignSeparator}" Margin="-15 5" /> <Separator Style="{StaticResource MaterialDesignSeparator}" Margin="-15 5" />
@ -214,9 +250,9 @@
<StackPanel Grid.Column="0"> <StackPanel Grid.Column="0">
<TextBlock Style="{StaticResource MaterialDesignTextBlock}">Layout file path</TextBlock> <TextBlock Style="{StaticResource MaterialDesignTextBlock}">Layout file path</TextBlock>
<TextBox Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}" <TextBox Foreground="{DynamicResource MaterialDesignNavigationItemSubheader}"
TextWrapping="Wrap" TextWrapping="Wrap"
Text="{Binding Device.Layout.FilePath, Mode=OneWay}" Text="{Binding Device.Layout.FilePath, Mode=OneWay}"
IsReadOnly="True" /> IsReadOnly="True" />
</StackPanel> </StackPanel>
</Grid> </Grid>
</StackPanel> </StackPanel>
@ -234,8 +270,7 @@
materialDesign:DataGridAssist.CellPadding="13 8 8 8" materialDesign:DataGridAssist.CellPadding="13 8 8 8"
materialDesign:DataGridAssist.ColumnHeaderPadding="8" materialDesign:DataGridAssist.ColumnHeaderPadding="8"
SelectedItem="{Binding SelectedLed}" SelectedItem="{Binding SelectedLed}"
CanUserResizeRows="False" CanUserResizeRows="False">
>
<DataGrid.Columns> <DataGrid.Columns>
<materialDesign:DataGridTextColumn Binding="{Binding RgbLed.Id}" Header="LED ID" Width="Auto" /> <materialDesign:DataGridTextColumn Binding="{Binding RgbLed.Id}" Header="LED ID" Width="Auto" />
<materialDesign:DataGridTextColumn Binding="{Binding RgbLed.Color}" Header="Color (ARGB)" Width="Auto" /> <materialDesign:DataGridTextColumn Binding="{Binding RgbLed.Color}" Header="Color (ARGB)" Width="Auto" />