mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
UI - Added reusable device visualizer
Settings - Show device LED images in settings Editor - Improved performance on big surfaces
This commit is contained in:
1 parent
7c53533113
commit
46aef81600
31 files changed
+407
-402
No files matched your search
+2
-1
@@ -6,12 +6,13 @@
|
||||
xmlns:local="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput"
|
||||
xmlns:artemis="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
|
||||
xmlns:converters="clr-namespace:Artemis.UI.Shared.Converters;assembly=Artemis.UI.Shared"
|
||||
xmlns:controls="clr-namespace:Artemis.UI.Shared.Controls;assembly=Artemis.UI.Shared"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="25" d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance local:ColorGradientPropertyInputViewModel}">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Margin="0 0 5 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.LayerProperty.InputPrefix}" />
|
||||
<artemis:GradientPicker Width="132"
|
||||
<controls:GradientPicker Width="132"
|
||||
Margin="0 2"
|
||||
Padding="0 -1"
|
||||
ColorGradient="{Binding ColorGradientInputValue}" />
|
||||
|
||||
+2
-1
@@ -6,12 +6,13 @@
|
||||
xmlns:local="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
|
||||
xmlns:controls="clr-namespace:Artemis.UI.Shared.Controls;assembly=Artemis.UI.Shared"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance local:FloatPropertyInputViewModel}">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Margin="0 0 5 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.LayerProperty.InputPrefix}" />
|
||||
<shared:DraggableFloat Value="{Binding FloatInputValue}"
|
||||
<controls:DraggableFloat Value="{Binding FloatInputValue}"
|
||||
StepSize="{Binding LayerPropertyViewModel.LayerProperty.InputStepSize}"
|
||||
DragStarted="{s:Action InputDragStarted}"
|
||||
DragEnded="{s:Action InputDragEnded}" />
|
||||
|
||||
+2
-1
@@ -6,12 +6,13 @@
|
||||
xmlns:local="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
|
||||
xmlns:controls="clr-namespace:Artemis.UI.Shared.Controls;assembly=Artemis.UI.Shared"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance local:IntPropertyInputViewModel}">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Margin="0 0 5 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.LayerProperty.InputPrefix}" />
|
||||
<shared:DraggableFloat Value="{Binding IntInputValue}"
|
||||
<controls:DraggableFloat Value="{Binding IntInputValue}"
|
||||
StepSize="{Binding LayerPropertyViewModel.LayerProperty.InputStepSize}"
|
||||
DragStarted="{s:Action InputDragStarted}"
|
||||
DragEnded="{s:Action InputDragEnded}" />
|
||||
|
||||
+2
-1
@@ -6,6 +6,7 @@
|
||||
xmlns:local="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput"
|
||||
xmlns:artemis="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
|
||||
xmlns:converters="clr-namespace:Artemis.UI.Shared.Converters;assembly=Artemis.UI.Shared"
|
||||
xmlns:controls="clr-namespace:Artemis.UI.Shared.Controls;assembly=Artemis.UI.Shared"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="25" d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance local:SKColorPropertyInputViewModel}">
|
||||
@@ -14,7 +15,7 @@
|
||||
</UserControl.Resources>
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Margin="0 0 5 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.LayerProperty.InputPrefix}" />
|
||||
<artemis:ColorPicker Width="132"
|
||||
<controls:ColorPicker Width="132"
|
||||
Margin="0 -2 0 3"
|
||||
Padding="0 -1"
|
||||
Color="{Binding SKColorInputValue, Converter={StaticResource SKColorToColorConverter}}" />
|
||||
|
||||
+3
-2
@@ -6,18 +6,19 @@
|
||||
xmlns:local="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
|
||||
xmlns:controls="clr-namespace:Artemis.UI.Shared.Controls;assembly=Artemis.UI.Shared"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="25" d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance local:SKPointPropertyInputViewModel}">
|
||||
<StackPanel Orientation="Horizontal" KeyboardNavigation.IsTabStop="True">
|
||||
<TextBlock Margin="0 0 5 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.LayerProperty.InputPrefix}" />
|
||||
<shared:DraggableFloat ToolTip="X-coordinate (horizontal)"
|
||||
<controls:DraggableFloat ToolTip="X-coordinate (horizontal)"
|
||||
Value="{Binding X}"
|
||||
StepSize="{Binding LayerPropertyViewModel.LayerProperty.InputStepSize}"
|
||||
DragStarted="{s:Action InputDragStarted}"
|
||||
DragEnded="{s:Action InputDragEnded}" />
|
||||
<TextBlock Margin="5 0" VerticalAlignment="Bottom">,</TextBlock>
|
||||
<shared:DraggableFloat ToolTip="Y-coordinate (vertical)"
|
||||
<controls:DraggableFloat ToolTip="Y-coordinate (vertical)"
|
||||
Value="{Binding Y}"
|
||||
StepSize="{Binding LayerPropertyViewModel.LayerProperty.InputStepSize}"
|
||||
DragStarted="{s:Action InputDragStarted}"
|
||||
|
||||
+3
-2
@@ -6,18 +6,19 @@
|
||||
xmlns:local="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.PropertyTree.PropertyInput"
|
||||
xmlns:s="https://github.com/canton7/Stylet"
|
||||
xmlns:shared="clr-namespace:Artemis.UI.Shared;assembly=Artemis.UI.Shared"
|
||||
xmlns:controls="clr-namespace:Artemis.UI.Shared.Controls;assembly=Artemis.UI.Shared"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance local:SKSizePropertyInputViewModel}">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Margin="0 0 5 4" Width="10" VerticalAlignment="Bottom" Text="{Binding LayerPropertyViewModel.LayerProperty.InputPrefix}" />
|
||||
<shared:DraggableFloat ToolTip="Height"
|
||||
<controls:DraggableFloat ToolTip="Height"
|
||||
Value="{Binding Height}"
|
||||
StepSize="{Binding LayerPropertyViewModel.LayerProperty.InputStepSize}"
|
||||
DragStarted="{s:Action InputDragStarted}"
|
||||
DragEnded="{s:Action InputDragEnded}" />
|
||||
<TextBlock Margin="5 0" VerticalAlignment="Bottom">,</TextBlock>
|
||||
<shared:DraggableFloat ToolTip="Width"
|
||||
<controls:DraggableFloat ToolTip="Width"
|
||||
Value="{Binding Width}"
|
||||
StepSize="{Binding LayerPropertyViewModel.LayerProperty.InputStepSize}"
|
||||
DragStarted="{s:Action InputDragStarted}"
|
||||
|
||||
+1
-2
@@ -16,8 +16,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.LayerProperties.Timeline
|
||||
|
||||
public static readonly DependencyProperty PixelsPerSecondProperty = DependencyProperty.Register(nameof(PixelsPerSecond), typeof(int), typeof(PropertyTimelineHeader),
|
||||
new FrameworkPropertyMetadata(default(int), FrameworkPropertyMetadataOptions.AffectsRender));
|
||||
|
||||
|
||||
|
||||
public static readonly DependencyProperty HorizontalOffsetProperty = DependencyProperty.Register(nameof(HorizontalOffset), typeof(double), typeof(PropertyTimelineHeader),
|
||||
new FrameworkPropertyMetadata(default(double), FrameworkPropertyMetadataOptions.AffectsRender));
|
||||
|
||||
|
||||
@@ -16,14 +16,16 @@
|
||||
<DataTrigger.EnterActions>
|
||||
<BeginStoryboard>
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetProperty="(Canvas.Opacity)" To="0.8" Duration="0:0:0.25" />
|
||||
<DoubleAnimation Storyboard.TargetProperty="(Canvas.Opacity)" To="0.8"
|
||||
Duration="0:0:0.25" />
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
</DataTrigger.EnterActions>
|
||||
<DataTrigger.ExitActions>
|
||||
<BeginStoryboard>
|
||||
<Storyboard>
|
||||
<DoubleAnimation Storyboard.TargetProperty="(Canvas.Opacity)" To="1" Duration="0:0:0.25" />
|
||||
<DoubleAnimation Storyboard.TargetProperty="(Canvas.Opacity)" To="1"
|
||||
Duration="0:0:0.25" />
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
</DataTrigger.ExitActions>
|
||||
@@ -33,15 +35,6 @@
|
||||
</UserControl.Resources>
|
||||
<Canvas Style="{StaticResource SelectedStyle}">
|
||||
|
||||
<!-- The part of the layer's shape that falls outside the layer -->
|
||||
<Path Data="{Binding ShapeGeometry, Mode=OneWay}">
|
||||
<Path.Fill>
|
||||
<SolidColorBrush Color="{StaticResource Accent700}" Opacity="0.05" />
|
||||
</Path.Fill>
|
||||
<Path.Stroke>
|
||||
<SolidColorBrush Color="{StaticResource Accent700}" Opacity="0.15" />
|
||||
</Path.Stroke>
|
||||
</Path>
|
||||
|
||||
<!-- The part of the layer's shape that is inside the layer -->
|
||||
<Path Data="{Binding ShapeGeometry, Mode=OneWay}">
|
||||
@@ -51,19 +44,18 @@
|
||||
<Path.Stroke>
|
||||
<SolidColorBrush Color="{StaticResource Accent700}" />
|
||||
</Path.Stroke>
|
||||
<Path.OpacityMask>
|
||||
<VisualBrush Viewport="{Binding ViewportRectangle}" ViewportUnits="Absolute">
|
||||
<VisualBrush.Visual>
|
||||
<Path Data="{Binding LayerGeometry, Mode=OneWay}" ClipToBounds="False" Fill="Black" />
|
||||
</VisualBrush.Visual>
|
||||
</VisualBrush>
|
||||
</Path.OpacityMask>
|
||||
</Path>
|
||||
|
||||
<Path Data="{Binding LayerGeometry, Mode=OneWay}" ClipToBounds="False" StrokeThickness="1.5" StrokeLineJoin="Round" x:Name="LayerPath">
|
||||
<Path.Stroke>
|
||||
<Rectangle Width="{Binding LayerRect.Width}"
|
||||
Height="{Binding LayerRect.Height}"
|
||||
Margin="{Binding LayerRectMargin}"
|
||||
StrokeThickness="2"
|
||||
StrokeDashArray="1 1"
|
||||
StrokeLineJoin="Round"
|
||||
x:Name="LayerPath">
|
||||
<Rectangle.Stroke>
|
||||
<SolidColorBrush Color="{StaticResource Accent400}" />
|
||||
</Path.Stroke>
|
||||
</Path>
|
||||
</Rectangle.Stroke>
|
||||
</Rectangle>
|
||||
</Canvas>
|
||||
</UserControl>
|
||||
+10
-111
@@ -4,12 +4,8 @@ using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Models.Profile.LayerShapes;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using Artemis.UI.Extensions;
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
using RGB.NET.Core;
|
||||
using Stylet;
|
||||
using Rectangle = Artemis.Core.Models.Profile.LayerShapes.Rectangle;
|
||||
|
||||
namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
{
|
||||
@@ -32,12 +28,10 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
}
|
||||
|
||||
public Layer Layer { get; }
|
||||
|
||||
public Geometry LayerGeometry { get; set; }
|
||||
public Geometry OpacityGeometry { get; set; }
|
||||
public Geometry ShapeGeometry { get; set; }
|
||||
public Rect ViewportRectangle { get; set; }
|
||||
public Rect LayerRect { get; set; }
|
||||
public Thickness LayerRectMargin => LayerRect == Rect.Empty ? new Thickness() : new Thickness(LayerRect.Left, LayerRect.Top, 0, 0);
|
||||
public bool IsSelected { get; set; }
|
||||
public Geometry ShapeGeometry { get; set; }
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
@@ -50,53 +44,12 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
private void Update()
|
||||
{
|
||||
IsSelected = _profileEditorService.SelectedProfileElement == Layer;
|
||||
CreateLayerGeometry();
|
||||
if (!Layer.Leds.Any() || Layer.LayerShape == null)
|
||||
LayerRect = Rect.Empty;
|
||||
else
|
||||
LayerRect = _layerEditorService.GetLayerBounds(Layer);
|
||||
|
||||
CreateShapeGeometry();
|
||||
CreateViewportRectangle();
|
||||
}
|
||||
|
||||
private void CreateLayerGeometry()
|
||||
{
|
||||
if (!Layer.Leds.Any())
|
||||
{
|
||||
LayerGeometry = Geometry.Empty;
|
||||
OpacityGeometry = Geometry.Empty;
|
||||
ViewportRectangle = Rect.Empty;
|
||||
return;
|
||||
}
|
||||
|
||||
var group = new GeometryGroup();
|
||||
group.FillRule = FillRule.Nonzero;
|
||||
|
||||
foreach (var led in Layer.Leds)
|
||||
{
|
||||
Geometry geometry;
|
||||
switch (led.RgbLed.Shape)
|
||||
{
|
||||
case Shape.Custom:
|
||||
if (led.RgbLed.Device.DeviceInfo.DeviceType == RGBDeviceType.Keyboard || led.RgbLed.Device.DeviceInfo.DeviceType == RGBDeviceType.Keypad)
|
||||
geometry = CreateCustomGeometry(led, 2);
|
||||
else
|
||||
geometry = CreateCustomGeometry(led, 1);
|
||||
break;
|
||||
case Shape.Rectangle:
|
||||
geometry = CreateRectangleGeometry(led);
|
||||
break;
|
||||
case Shape.Circle:
|
||||
geometry = CreateCircleGeometry(led);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
group.Children.Add(geometry);
|
||||
}
|
||||
|
||||
var layerGeometry = group.GetOutlinedPathGeometry();
|
||||
var opacityGeometry = Geometry.Combine(Geometry.Empty, layerGeometry, GeometryCombineMode.Exclude, new TranslateTransform());
|
||||
|
||||
LayerGeometry = layerGeometry;
|
||||
OpacityGeometry = opacityGeometry;
|
||||
}
|
||||
|
||||
private void CreateShapeGeometry()
|
||||
@@ -126,60 +79,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
});
|
||||
}
|
||||
|
||||
private void CreateViewportRectangle()
|
||||
{
|
||||
if (!Layer.Leds.Any() || Layer.LayerShape == null)
|
||||
{
|
||||
ViewportRectangle = Rect.Empty;
|
||||
return;
|
||||
}
|
||||
|
||||
ViewportRectangle = _layerEditorService.GetLayerBounds(Layer);
|
||||
}
|
||||
|
||||
private Geometry CreateRectangleGeometry(ArtemisLed led)
|
||||
{
|
||||
var rect = led.RgbLed.AbsoluteLedRectangle.ToWindowsRect(1);
|
||||
rect.Inflate(1, 1);
|
||||
return new RectangleGeometry(rect);
|
||||
}
|
||||
|
||||
private Geometry CreateCircleGeometry(ArtemisLed led)
|
||||
{
|
||||
var rect = led.RgbLed.AbsoluteLedRectangle.ToWindowsRect(1);
|
||||
rect.Inflate(1, 1);
|
||||
return new EllipseGeometry(rect);
|
||||
}
|
||||
|
||||
private Geometry CreateCustomGeometry(ArtemisLed led, double deflateAmount)
|
||||
{
|
||||
var rect = led.RgbLed.AbsoluteLedRectangle.ToWindowsRect(1);
|
||||
rect.Inflate(1, 1);
|
||||
try
|
||||
{
|
||||
var geometry = Geometry.Combine(
|
||||
Geometry.Empty,
|
||||
Geometry.Parse(led.RgbLed.ShapeData),
|
||||
GeometryCombineMode.Union,
|
||||
new TransformGroup
|
||||
{
|
||||
Children = new TransformCollection
|
||||
{
|
||||
new ScaleTransform(rect.Width, rect.Height),
|
||||
new TranslateTransform(rect.X, rect.Y)
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
return geometry;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return CreateRectangleGeometry(led);
|
||||
}
|
||||
}
|
||||
|
||||
#region Event handlers
|
||||
#region Event handlers
|
||||
|
||||
private void LayerOnRenderPropertiesUpdated(object sender, EventArgs e)
|
||||
{
|
||||
@@ -198,8 +98,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
|
||||
private void ProfileEditorServiceOnProfilePreviewUpdated(object sender, EventArgs e)
|
||||
{
|
||||
CreateShapeGeometry();
|
||||
CreateViewportRectangle();
|
||||
Update();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
xmlns:profileEditor="clr-namespace:Artemis.UI.Screens.Module.ProfileEditor.Visualization"
|
||||
xmlns:utilities="clr-namespace:Artemis.UI.Shared.Utilities;assembly=Artemis.UI.Shared"
|
||||
xmlns:controls="clr-namespace:Artemis.UI.Shared.Controls;assembly=Artemis.UI.Shared"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="510.9" d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance {x:Type profileEditor:ProfileViewModel}}">
|
||||
@@ -107,7 +108,7 @@
|
||||
<TranslateTransform X="{Binding PanZoomViewModel.PanX}" Y="{Binding PanZoomViewModel.PanY}" />
|
||||
</TransformGroup>
|
||||
</Grid.RenderTransform>
|
||||
<ItemsControl ItemsSource="{Binding DeviceViewModels}">
|
||||
<ItemsControl ItemsSource="{Binding Devices}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<Canvas />
|
||||
@@ -121,7 +122,7 @@
|
||||
</ItemsControl.ItemContainerStyle>
|
||||
<ItemsControl.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<ContentControl s:View.Model="{Binding}" />
|
||||
<controls:DeviceVisualizer Device="{Binding}" ShowColors="True"/>
|
||||
</DataTemplate>
|
||||
</ItemsControl.ItemTemplate>
|
||||
</ItemsControl>
|
||||
@@ -154,7 +155,6 @@
|
||||
</ItemsControl>
|
||||
</Grid>
|
||||
|
||||
|
||||
<StackPanel ZIndex="1" VerticalAlignment="Bottom" HorizontalAlignment="Left" Margin="10">
|
||||
<materialDesign:Card Padding="8">
|
||||
<StackPanel Orientation="Horizontal">
|
||||
|
||||
@@ -11,6 +11,7 @@ using Artemis.Core.Plugins.Models;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.Core.Services.Storage.Interfaces;
|
||||
using Artemis.UI.Events;
|
||||
using Artemis.UI.Extensions;
|
||||
using Artemis.UI.Ninject.Factories;
|
||||
using Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools;
|
||||
using Artemis.UI.Screens.Shared;
|
||||
@@ -30,7 +31,6 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
private int _activeToolIndex;
|
||||
private VisualizationToolViewModel _activeToolViewModel;
|
||||
private int _previousTool;
|
||||
private TimerUpdateTrigger _updateTrigger;
|
||||
|
||||
public ProfileViewModel(IProfileEditorService profileEditorService,
|
||||
ILayerEditorService layerEditorService,
|
||||
@@ -47,14 +47,16 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
|
||||
Execute.OnUIThreadSync(() =>
|
||||
{
|
||||
CanvasViewModels = new ObservableCollection<CanvasViewModel>();
|
||||
DeviceViewModels = new ObservableCollection<ProfileDeviceViewModel>();
|
||||
PanZoomViewModel = new PanZoomViewModel {LimitToZero = false};
|
||||
|
||||
CanvasViewModels = new BindableCollection<CanvasViewModel>();
|
||||
Devices = new BindableCollection<ArtemisDevice>();
|
||||
DimmedLeds = new BindableCollection<ArtemisLed>();
|
||||
SelectedLeds = new BindableCollection<ArtemisLed>();
|
||||
});
|
||||
|
||||
ApplySurfaceConfiguration(_surfaceService.ActiveSurface);
|
||||
ApplyActiveProfile();
|
||||
CreateUpdateTrigger();
|
||||
ActivateToolByIndex(0);
|
||||
|
||||
eventAggregator.Subscribe(this);
|
||||
@@ -62,9 +64,14 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
|
||||
|
||||
public bool IsInitializing { get; private set; }
|
||||
public ObservableCollection<CanvasViewModel> CanvasViewModels { get; set; }
|
||||
public ObservableCollection<ProfileDeviceViewModel> DeviceViewModels { get; set; }
|
||||
|
||||
public PanZoomViewModel PanZoomViewModel { get; set; }
|
||||
|
||||
public BindableCollection<CanvasViewModel> CanvasViewModels { get; set; }
|
||||
public BindableCollection<ArtemisDevice> Devices { get; set; }
|
||||
public BindableCollection<ArtemisLed> DimmedLeds { get; set; }
|
||||
public BindableCollection<ArtemisLed> SelectedLeds { get; set; }
|
||||
|
||||
public PluginSetting<bool> HighlightSelectedLayer { get; set; }
|
||||
public PluginSetting<bool> PauseRenderingOnFocusLoss { get; set; }
|
||||
|
||||
@@ -122,7 +129,6 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
_profileEditorService.ProfileElementSelected += OnProfileElementSelected;
|
||||
_profileEditorService.SelectedProfileElementUpdated += OnSelectedProfileElementUpdated;
|
||||
|
||||
_updateTrigger.Start();
|
||||
base.OnInitialActivate();
|
||||
}
|
||||
|
||||
@@ -137,28 +143,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
HighlightSelectedLayer.Save();
|
||||
PauseRenderingOnFocusLoss.Save();
|
||||
|
||||
try
|
||||
{
|
||||
_updateTrigger.Stop();
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
// TODO: Remove when fixed in RGB.NET, or avoid double stopping
|
||||
}
|
||||
|
||||
base.OnClose();
|
||||
}
|
||||
|
||||
private void CreateUpdateTrigger()
|
||||
{
|
||||
// Borrow RGB.NET's update trigger but limit the FPS
|
||||
var targetFpsSetting = _settingsService.GetSetting("Core.TargetFrameRate", 25);
|
||||
var editorTargetFpsSetting = _settingsService.GetSetting("ProfileEditor.TargetFrameRate", 15);
|
||||
var targetFps = Math.Min(targetFpsSetting.Value, editorTargetFpsSetting.Value);
|
||||
_updateTrigger = new TimerUpdateTrigger {UpdateFrequency = 1.0 / targetFps};
|
||||
_updateTrigger.Update += UpdateLeds;
|
||||
}
|
||||
|
||||
private void OnActiveSurfaceConfigurationSelected(object sender, SurfaceConfigurationEventArgs e)
|
||||
{
|
||||
ApplySurfaceConfiguration(e.Surface);
|
||||
@@ -193,61 +180,15 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
|
||||
private void ApplySurfaceConfiguration(ArtemisSurface surface)
|
||||
{
|
||||
// Make sure all devices have an up-to-date VM
|
||||
Execute.PostToUIThread(() =>
|
||||
{
|
||||
lock (DeviceViewModels)
|
||||
{
|
||||
var existing = DeviceViewModels.ToList();
|
||||
var deviceViewModels = new List<ProfileDeviceViewModel>();
|
||||
|
||||
// Add missing/update existing
|
||||
foreach (var surfaceDeviceConfiguration in surface.Devices.OrderBy(d => d.ZIndex).ToList())
|
||||
{
|
||||
// Create VMs for missing devices
|
||||
var viewModel = existing.FirstOrDefault(vm => vm.Device.RgbDevice == surfaceDeviceConfiguration.RgbDevice);
|
||||
if (viewModel == null)
|
||||
{
|
||||
IsInitializing = true;
|
||||
viewModel = new ProfileDeviceViewModel(surfaceDeviceConfiguration);
|
||||
}
|
||||
// Update existing devices
|
||||
else
|
||||
viewModel.Device = surfaceDeviceConfiguration;
|
||||
|
||||
// Add the viewModel to the list of VMs we want to keep
|
||||
deviceViewModels.Add(viewModel);
|
||||
}
|
||||
|
||||
DeviceViewModels = new ObservableCollection<ProfileDeviceViewModel>(deviceViewModels);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void UpdateLeds(object sender, CustomUpdateData customUpdateData)
|
||||
{
|
||||
lock (DeviceViewModels)
|
||||
{
|
||||
if (IsInitializing)
|
||||
IsInitializing = DeviceViewModels.Any(d => !d.AddedLeds);
|
||||
|
||||
foreach (var profileDeviceViewModel in DeviceViewModels)
|
||||
profileDeviceViewModel.Update();
|
||||
}
|
||||
Devices.Clear();
|
||||
Devices.AddRange(surface.Devices);
|
||||
}
|
||||
|
||||
private void UpdateLedsDimStatus()
|
||||
{
|
||||
DimmedLeds.Clear();
|
||||
if (HighlightSelectedLayer.Value && _profileEditorService.SelectedProfileElement is Layer layer)
|
||||
{
|
||||
foreach (var led in DeviceViewModels.SelectMany(d => d.Leds))
|
||||
led.IsDimmed = !layer.Leds.Contains(led.Led);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var led in DeviceViewModels.SelectMany(d => d.Leds))
|
||||
led.IsDimmed = false;
|
||||
}
|
||||
DimmedLeds.AddRange(layer.Leds);
|
||||
}
|
||||
|
||||
#region Buttons
|
||||
@@ -322,27 +263,27 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
return;
|
||||
|
||||
layer.ClearLeds();
|
||||
layer.AddLeds(DeviceViewModels.SelectMany(d => d.Leds).Where(vm => vm.IsSelected).Select(vm => vm.Led));
|
||||
layer.AddLeds(SelectedLeds);
|
||||
|
||||
_profileEditorService.UpdateSelectedProfileElement();
|
||||
}
|
||||
|
||||
public void SelectAll()
|
||||
{
|
||||
foreach (var ledVm in DeviceViewModels.SelectMany(d => d.Leds))
|
||||
ledVm.IsSelected = true;
|
||||
SelectedLeds.Clear();
|
||||
SelectedLeds.AddRange(Devices.SelectMany(d => d.Leds));
|
||||
}
|
||||
|
||||
public void InverseSelection()
|
||||
{
|
||||
foreach (var ledVm in DeviceViewModels.SelectMany(d => d.Leds))
|
||||
ledVm.IsSelected = !ledVm.IsSelected;
|
||||
var current = SelectedLeds.ToList();
|
||||
SelectedLeds.Clear();
|
||||
SelectedLeds.AddRange(Devices.SelectMany(d => d.Leds).Except(current));
|
||||
}
|
||||
|
||||
public void ClearSelection()
|
||||
{
|
||||
foreach (var ledVm in DeviceViewModels.SelectMany(d => d.Leds))
|
||||
ledVm.IsSelected = false;
|
||||
SelectedLeds.Clear();
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -374,20 +315,20 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
|
||||
public void Handle(MainWindowFocusChangedEvent message)
|
||||
{
|
||||
if (PauseRenderingOnFocusLoss == null || ScreenState != ScreenState.Active)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
if (PauseRenderingOnFocusLoss.Value && !message.IsFocused)
|
||||
_updateTrigger.Stop();
|
||||
else if (PauseRenderingOnFocusLoss.Value && message.IsFocused)
|
||||
_updateTrigger.Start();
|
||||
}
|
||||
catch (NullReferenceException)
|
||||
{
|
||||
// TODO: Remove when fixed in RGB.NET, or avoid double stopping
|
||||
}
|
||||
// if (PauseRenderingOnFocusLoss == null || ScreenState != ScreenState.Active)
|
||||
// return;
|
||||
//
|
||||
// try
|
||||
// {
|
||||
// if (PauseRenderingOnFocusLoss.Value && !message.IsFocused)
|
||||
// _updateTrigger.Stop();
|
||||
// else if (PauseRenderingOnFocusLoss.Value && message.IsFocused)
|
||||
// _updateTrigger.Start();
|
||||
// }
|
||||
// catch (NullReferenceException)
|
||||
// {
|
||||
// // TODO: Remove when fixed in RGB.NET, or avoid double stopping
|
||||
// }
|
||||
}
|
||||
|
||||
public void Handle(MainWindowKeyEvent message)
|
||||
@@ -413,5 +354,12 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public List<ArtemisLed> GetLedsInRectangle(Rect selectedRect)
|
||||
{
|
||||
return Devices.SelectMany(d => d.Leds)
|
||||
.Where(led => led.RgbLed.AbsoluteLedRectangle.ToWindowsRect(1).IntersectsWith(selectedRect))
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
+9
-25
@@ -1,11 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using Artemis.UI.Extensions;
|
||||
using Artemis.UI.Properties;
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
|
||||
@@ -31,17 +28,9 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
var selectedRect = new Rect(MouseDownStartPosition, position);
|
||||
|
||||
// Get selected LEDs
|
||||
var selectedLeds = new List<ArtemisLed>();
|
||||
foreach (var device in ProfileViewModel.DeviceViewModels)
|
||||
{
|
||||
foreach (var ledViewModel in device.Leds)
|
||||
{
|
||||
if (ledViewModel.Led.RgbLed.AbsoluteLedRectangle.ToWindowsRect(1).IntersectsWith(selectedRect))
|
||||
selectedLeds.Add(ledViewModel.Led);
|
||||
// Unselect everything
|
||||
ledViewModel.IsSelected = false;
|
||||
}
|
||||
}
|
||||
var selectedLeds = ProfileViewModel.GetLedsInRectangle(selectedRect);
|
||||
ProfileViewModel.SelectedLeds.Clear();
|
||||
ProfileViewModel.SelectedLeds.AddRange(selectedLeds);
|
||||
|
||||
// Apply the selection to the selected layer layer
|
||||
if (ProfileEditorService.SelectedProfileElement is Layer layer)
|
||||
@@ -65,17 +54,12 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
|
||||
var position = ProfileViewModel.PanZoomViewModel.GetRelativeMousePosition(sender, e);
|
||||
var selectedRect = new Rect(MouseDownStartPosition, position);
|
||||
var selectedLeds = ProfileViewModel.GetLedsInRectangle(selectedRect);
|
||||
|
||||
foreach (var device in ProfileViewModel.DeviceViewModels)
|
||||
{
|
||||
foreach (var ledViewModel in device.Leds)
|
||||
{
|
||||
if (ledViewModel.Led.RgbLed.AbsoluteLedRectangle.ToWindowsRect(1).IntersectsWith(selectedRect))
|
||||
ledViewModel.IsSelected = true;
|
||||
else if (!Keyboard.IsKeyDown(Key.LeftShift) && !Keyboard.IsKeyDown(Key.RightShift))
|
||||
ledViewModel.IsSelected = false;
|
||||
}
|
||||
}
|
||||
// Unless shift is held down, clear the current selection
|
||||
if (!Keyboard.IsKeyDown(Key.LeftShift) && !Keyboard.IsKeyDown(Key.RightShift))
|
||||
ProfileViewModel.SelectedLeds.Clear();
|
||||
ProfileViewModel.SelectedLeds.AddRange(selectedLeds.Except(ProfileViewModel.SelectedLeds));
|
||||
|
||||
DragRectangle = selectedRect;
|
||||
}
|
||||
|
||||
+7
-25
@@ -1,11 +1,8 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using Artemis.Core.Models.Profile;
|
||||
using Artemis.Core.Models.Surface;
|
||||
using Artemis.UI.Extensions;
|
||||
using Artemis.UI.Properties;
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
|
||||
@@ -31,17 +28,7 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
var selectedRect = new Rect(MouseDownStartPosition, position);
|
||||
|
||||
// Get selected LEDs
|
||||
var selectedLeds = new List<ArtemisLed>();
|
||||
foreach (var device in ProfileViewModel.DeviceViewModels)
|
||||
{
|
||||
foreach (var ledViewModel in device.Leds)
|
||||
{
|
||||
if (ledViewModel.Led.RgbLed.AbsoluteLedRectangle.ToWindowsRect(1).IntersectsWith(selectedRect))
|
||||
selectedLeds.Add(ledViewModel.Led);
|
||||
// Unselect everything
|
||||
ledViewModel.IsSelected = false;
|
||||
}
|
||||
}
|
||||
var selectedLeds = ProfileViewModel.GetLedsInRectangle(selectedRect);
|
||||
|
||||
// Apply the selection to the selected layer layer
|
||||
if (ProfileEditorService.SelectedProfileElement is Layer layer)
|
||||
@@ -87,17 +74,12 @@ namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
|
||||
|
||||
var position = ProfileViewModel.PanZoomViewModel.GetRelativeMousePosition(sender, e);
|
||||
var selectedRect = new Rect(MouseDownStartPosition, position);
|
||||
var selectedLeds = ProfileViewModel.GetLedsInRectangle(selectedRect);
|
||||
|
||||
foreach (var device in ProfileViewModel.DeviceViewModels)
|
||||
{
|
||||
foreach (var ledViewModel in device.Leds)
|
||||
{
|
||||
if (ledViewModel.Led.RgbLed.AbsoluteLedRectangle.ToWindowsRect(1).IntersectsWith(selectedRect))
|
||||
ledViewModel.IsSelected = true;
|
||||
else if (!Keyboard.IsKeyDown(Key.LeftShift) && !Keyboard.IsKeyDown(Key.RightShift))
|
||||
ledViewModel.IsSelected = false;
|
||||
}
|
||||
}
|
||||
// Unless shift is held down, clear the current selection
|
||||
if (!Keyboard.IsKeyDown(Key.LeftShift) && !Keyboard.IsKeyDown(Key.RightShift))
|
||||
ProfileViewModel.SelectedLeds.Clear();
|
||||
ProfileViewModel.SelectedLeds.AddRange(selectedLeds.Except(ProfileViewModel.SelectedLeds));
|
||||
|
||||
DragRectangle = selectedRect;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user