1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-13 05:48:35 +00:00

Fix auto connecting nodes

This commit is contained in:
Robert 2023-04-07 16:18:07 +02:00
parent 73933ee324
commit 88558efcb1
4 changed files with 41 additions and 17 deletions

View File

@ -45,7 +45,7 @@ public class DeviceVisualizer : Control
/// <inheritdoc /> /// <inheritdoc />
public override void Render(DrawingContext drawingContext) public override void Render(DrawingContext drawingContext)
{ {
if (Device == null || _deviceBounds.Width == 0 || _deviceBounds.Height == 0) if (Device == null || _deviceBounds.Width == 0 || _deviceBounds.Height == 0 || _loading)
return; return;
// Determine the scale required to fit the desired size of the control // Determine the scale required to fit the desired size of the control
@ -208,6 +208,8 @@ public class DeviceVisualizer : Control
public static readonly StyledProperty<ObservableCollection<ArtemisLed>?> HighlightedLedsProperty = public static readonly StyledProperty<ObservableCollection<ArtemisLed>?> HighlightedLedsProperty =
AvaloniaProperty.Register<DeviceVisualizer, ObservableCollection<ArtemisLed>?>(nameof(HighlightedLeds)); AvaloniaProperty.Register<DeviceVisualizer, ObservableCollection<ArtemisLed>?>(nameof(HighlightedLeds));
private bool _loading;
/// <summary> /// <summary>
/// Gets or sets a list of LEDs to highlight /// Gets or sets a list of LEDs to highlight
/// </summary> /// </summary>
@ -273,6 +275,7 @@ public class DeviceVisualizer : Control
return; return;
_deviceBounds = MeasureDevice(); _deviceBounds = MeasureDevice();
_loading = true;
Device.RgbDevice.PropertyChanged += DevicePropertyChanged; Device.RgbDevice.PropertyChanged += DevicePropertyChanged;
Device.DeviceUpdated += DeviceUpdated; Device.DeviceUpdated += DeviceUpdated;
@ -288,15 +291,15 @@ public class DeviceVisualizer : Control
ArtemisDevice? device = Device; ArtemisDevice? device = Device;
Dispatcher.UIThread.Post(() => Dispatcher.UIThread.Post(() =>
{ {
if (device.Layout?.Image == null || !File.Exists(device.Layout.Image.LocalPath))
{
_deviceImage?.Dispose();
_deviceImage = null;
return;
}
try try
{ {
if (device.Layout?.Image == null || !File.Exists(device.Layout.Image.LocalPath))
{
_deviceImage?.Dispose();
_deviceImage = null;
return;
}
// Create a bitmap that'll be used to render the device and LED images just once // Create a bitmap that'll be used to render the device and LED images just once
// Render 4 times the actual size of the device to make sure things look sharp when zoomed in // Render 4 times the actual size of the device to make sure things look sharp when zoomed in
RenderTargetBitmap renderTargetBitmap = new(new PixelSize((int) device.RgbDevice.ActualSize.Width * 2, (int) device.RgbDevice.ActualSize.Height * 2)); RenderTargetBitmap renderTargetBitmap = new(new PixelSize((int) device.RgbDevice.ActualSize.Width * 2, (int) device.RgbDevice.ActualSize.Height * 2));
@ -314,12 +317,16 @@ public class DeviceVisualizer : Control
_deviceImage?.Dispose(); _deviceImage?.Dispose();
_deviceImage = renderTargetBitmap; _deviceImage = renderTargetBitmap;
Dispatcher.UIThread.Post(InvalidateMeasure); InvalidateMeasure();
} }
catch (Exception) catch (Exception)
{ {
// ignored // ignored
} }
finally
{
_loading = false;
}
}); });
} }

View File

@ -156,7 +156,21 @@
<TextBlock Grid.Row="0" Classes="h5 no-margin">Release notes</TextBlock> <TextBlock Grid.Row="0" Classes="h5 no-margin">Release notes</TextBlock>
<Separator Grid.Row="1" Classes="card-separator" /> <Separator Grid.Row="1" Classes="card-separator" />
<avalonia:MarkdownScrollViewer Grid.Row="2" Markdown="{CompiledBinding Changelog}" MarkdownStyleName="FluentAvalonia"/> <avalonia:MarkdownScrollViewer Grid.Row="2" Markdown="{CompiledBinding Changelog}" MarkdownStyleName="FluentAvalonia">
<avalonia:MarkdownScrollViewer.Styles>
<Style Selector="ctxt|CHyperlink">
<Setter Property="Foreground" Value="{DynamicResource SystemAccentColorLight3}" />
</Style>
<Style Selector="ctxt|CHyperlink:pointerover">
<Setter Property="Foreground" Value="{DynamicResource SystemAccentColorLight1}" />
</Style>
<Style Selector="Grid.List">
<Style.Setters>
<Setter Property="Margin" Value="20,0,0,0"/>
</Style.Setters>
</Style>
</avalonia:MarkdownScrollViewer.Styles>
</avalonia:MarkdownScrollViewer>
</Grid> </Grid>
</Border> </Border>
</Grid> </Grid>

View File

@ -50,7 +50,6 @@ public class NodePickerViewModel : ActivatableViewModelBase
this.WhenActivated(d => this.WhenActivated(d =>
{ {
SearchText = null; SearchText = null;
TargetPin = null;
nodeSourceList.Edit(list => nodeSourceList.Edit(list =>
{ {
@ -59,7 +58,11 @@ public class NodePickerViewModel : ActivatableViewModelBase
}); });
IsVisible = true; IsVisible = true;
Disposable.Create(() => IsVisible = false).DisposeWith(d); Disposable.Create(() =>
{
IsVisible = false;
TargetPin = null;
}).DisposeWith(d);
}); });
} }
@ -102,6 +105,7 @@ public class NodePickerViewModel : ActivatableViewModelBase
node.Y = Math.Round(Position.Y / 10d, 0, MidpointRounding.AwayFromZero) * 10d; node.Y = Math.Round(Position.Y / 10d, 0, MidpointRounding.AwayFromZero) * 10d;
if (TargetPin != null) if (TargetPin != null)
{
using (_nodeEditorService.CreateCommandScope(_nodeScript, "Create node for pin")) using (_nodeEditorService.CreateCommandScope(_nodeScript, "Create node for pin"))
{ {
_nodeEditorService.ExecuteCommand(_nodeScript, new AddNode(_nodeScript, node)); _nodeEditorService.ExecuteCommand(_nodeScript, new AddNode(_nodeScript, node));
@ -114,6 +118,7 @@ public class NodePickerViewModel : ActivatableViewModelBase
if (source != null) if (source != null)
_nodeEditorService.ExecuteCommand(_nodeScript, new ConnectPins(source, TargetPin)); _nodeEditorService.ExecuteCommand(_nodeScript, new ConnectPins(source, TargetPin));
} }
}
else else
_nodeEditorService.ExecuteCommand(_nodeScript, new AddNode(_nodeScript, node)); _nodeEditorService.ExecuteCommand(_nodeScript, new AddNode(_nodeScript, node));
} }

View File

@ -44,12 +44,10 @@
</Border> </Border>
</StackPanel> </StackPanel>
</DataTemplate> </DataTemplate>
<DataTemplate DataType="core:Numeric">
<TextBlock Text="{Binding}" FontFamily="Consolas"/>
</DataTemplate>
<DataTemplate DataType="system:Object"> <DataTemplate DataType="system:Object">
<TextBlock Text="{Binding Converter={StaticResource JsonConverter}}" FontFamily="Consolas"/> <Border Classes="card-condensed" Margin="0,5,5,5 ">
<TextBlock Text="{Binding Converter={StaticResource JsonConverter}}" FontFamily="Consolas"/>
</Border>
</DataTemplate> </DataTemplate>
</ContentControl.DataTemplates> </ContentControl.DataTemplates>
</ContentControl> </ContentControl>