mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Profile editor - Refactored a lot of VMs so they clean up nicely
This commit is contained in:
1 parent
0dac4c7387
commit
4db66e1e3e
37 files changed
+531
-496
No files matched your search
@@ -1,9 +1,8 @@
|
||||
using System;
|
||||
using Stylet;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.Visualization
|
||||
{
|
||||
public abstract class CanvasViewModel : PropertyChangedBase, IDisposable
|
||||
public abstract class CanvasViewModel : Screen
|
||||
{
|
||||
private double _x;
|
||||
private double _y;
|
||||
@@ -19,18 +18,5 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
|
||||
get => _y;
|
||||
set => SetAndNotify(ref _y, value);
|
||||
}
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
protected virtual void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,9 @@ using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Extensions;
|
||||
using Artemis.UI.Screens.Shared;
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.Visualization
|
||||
{
|
||||
@@ -15,25 +15,17 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
|
||||
{
|
||||
private readonly ILayerEditorService _layerEditorService;
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private readonly ProfileViewModel _profileViewModel;
|
||||
private readonly PanZoomViewModel _panZoomViewModel;
|
||||
private bool _isSelected;
|
||||
private Geometry _shapeGeometry;
|
||||
private Rect _viewportRectangle;
|
||||
|
||||
public ProfileLayerViewModel(Layer layer, ProfileViewModel profileViewModel, IProfileEditorService profileEditorService, ILayerEditorService layerEditorService)
|
||||
public ProfileLayerViewModel(Layer layer, PanZoomViewModel panZoomViewModel, IProfileEditorService profileEditorService, ILayerEditorService layerEditorService)
|
||||
{
|
||||
_profileViewModel = profileViewModel;
|
||||
_panZoomViewModel = panZoomViewModel;
|
||||
_profileEditorService = profileEditorService;
|
||||
_layerEditorService = layerEditorService;
|
||||
Layer = layer;
|
||||
|
||||
|
||||
Update();
|
||||
Layer.RenderPropertiesUpdated += LayerOnRenderPropertiesUpdated;
|
||||
_profileEditorService.ProfileElementSelected += OnProfileElementSelected;
|
||||
_profileEditorService.SelectedProfileElementUpdated += OnSelectedProfileElementUpdated;
|
||||
_profileEditorService.ProfilePreviewUpdated += ProfileEditorServiceOnProfilePreviewUpdated;
|
||||
_profileViewModel.PanZoomViewModel.PropertyChanged += PanZoomViewModelOnPropertyChanged;
|
||||
}
|
||||
|
||||
public Layer Layer { get; }
|
||||
@@ -59,8 +51,8 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
|
||||
get
|
||||
{
|
||||
if (IsSelected)
|
||||
return Math.Max(2 / _profileViewModel.PanZoomViewModel.Zoom, 1);
|
||||
return Math.Max(2 / _profileViewModel.PanZoomViewModel.Zoom, 1) / 2;
|
||||
return Math.Max(2 / _panZoomViewModel.Zoom, 1);
|
||||
return Math.Max(2 / _panZoomViewModel.Zoom, 1) / 2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,23 +78,9 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
Layer.RenderPropertiesUpdated -= LayerOnRenderPropertiesUpdated;
|
||||
_profileEditorService.ProfileElementSelected -= OnProfileElementSelected;
|
||||
_profileEditorService.SelectedProfileElementUpdated -= OnSelectedProfileElementUpdated;
|
||||
_profileEditorService.ProfilePreviewUpdated -= ProfileEditorServiceOnProfilePreviewUpdated;
|
||||
_profileViewModel.PanZoomViewModel.PropertyChanged -= PanZoomViewModelOnPropertyChanged;
|
||||
}
|
||||
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
private void PanZoomViewModelOnPropertyChanged(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(_profileViewModel.PanZoomViewModel.Zoom))
|
||||
if (e.PropertyName == nameof(_panZoomViewModel.Zoom))
|
||||
{
|
||||
NotifyOfPropertyChange(nameof(StrokeThickness));
|
||||
NotifyOfPropertyChange(nameof(LayerStrokeThickness));
|
||||
@@ -193,6 +171,33 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
|
||||
}
|
||||
}
|
||||
|
||||
#region Overrides of Screen
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnInitialActivate()
|
||||
{
|
||||
Update();
|
||||
Layer.RenderPropertiesUpdated += LayerOnRenderPropertiesUpdated;
|
||||
_profileEditorService.ProfileElementSelected += OnProfileElementSelected;
|
||||
_profileEditorService.SelectedProfileElementUpdated += OnSelectedProfileElementUpdated;
|
||||
_profileEditorService.ProfilePreviewUpdated += ProfileEditorServiceOnProfilePreviewUpdated;
|
||||
_panZoomViewModel.PropertyChanged += PanZoomViewModelOnPropertyChanged;
|
||||
base.OnInitialActivate();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnClose()
|
||||
{
|
||||
Layer.RenderPropertiesUpdated -= LayerOnRenderPropertiesUpdated;
|
||||
_profileEditorService.ProfileElementSelected -= OnProfileElementSelected;
|
||||
_profileEditorService.SelectedProfileElementUpdated -= OnSelectedProfileElementUpdated;
|
||||
_profileEditorService.ProfilePreviewUpdated -= ProfileEditorServiceOnProfilePreviewUpdated;
|
||||
_panZoomViewModel.PropertyChanged -= PanZoomViewModelOnPropertyChanged;
|
||||
base.OnClose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Event handlers
|
||||
|
||||
private void LayerOnRenderPropertiesUpdated(object sender, EventArgs e)
|
||||
|
||||
@@ -106,7 +106,7 @@
|
||||
<TranslateTransform X="{Binding PanZoomViewModel.PanX}" Y="{Binding PanZoomViewModel.PanY}" />
|
||||
</TransformGroup>
|
||||
</Grid.RenderTransform>
|
||||
<ItemsControl ItemsSource="{Binding CanvasViewModels}">
|
||||
<ItemsControl ItemsSource="{Binding Items}">
|
||||
<ItemsControl.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<Canvas />
|
||||
|
||||
@@ -15,7 +15,7 @@ using Stylet;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.Visualization
|
||||
{
|
||||
public class ProfileViewModel : Screen, IProfileEditorPanelViewModel, IHandle<MainWindowFocusChangedEvent>, IHandle<MainWindowKeyEvent>
|
||||
public class ProfileViewModel : Conductor<CanvasViewModel>.Collection.AllActive, IProfileEditorPanelViewModel, IHandle<MainWindowFocusChangedEvent>, IHandle<MainWindowKeyEvent>
|
||||
{
|
||||
private readonly IProfileEditorService _profileEditorService;
|
||||
private readonly ICoreService _coreService;
|
||||
@@ -28,7 +28,6 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
|
||||
private VisualizationToolViewModel _activeToolViewModel;
|
||||
private bool _canApplyToLayer;
|
||||
private bool _canSelectEditTool;
|
||||
private BindableCollection<CanvasViewModel> _canvasViewModels;
|
||||
private BindableCollection<ArtemisDevice> _devices;
|
||||
private BindableCollection<ArtemisLed> _highlightedLeds;
|
||||
private PluginSetting<bool> _highlightSelectedLayer;
|
||||
@@ -36,7 +35,6 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
|
||||
private PanZoomViewModel _panZoomViewModel;
|
||||
private Layer _previousSelectedLayer;
|
||||
private int _previousTool;
|
||||
private BindableCollection<ArtemisLed> _selectedLeds;
|
||||
private DateTime _lastUpdate;
|
||||
|
||||
public ProfileViewModel(IProfileEditorService profileEditorService,
|
||||
@@ -54,22 +52,10 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
|
||||
_visualizationToolVmFactory = visualizationToolVmFactory;
|
||||
_profileLayerVmFactory = profileLayerVmFactory;
|
||||
|
||||
Execute.OnUIThreadSync(() =>
|
||||
{
|
||||
PanZoomViewModel = new PanZoomViewModel {LimitToZero = false};
|
||||
|
||||
CanvasViewModels = new BindableCollection<CanvasViewModel>();
|
||||
Devices = new BindableCollection<ArtemisDevice>();
|
||||
HighlightedLeds = new BindableCollection<ArtemisLed>();
|
||||
SelectedLeds = new BindableCollection<ArtemisLed>();
|
||||
});
|
||||
|
||||
ApplySurfaceConfiguration(_surfaceService.ActiveSurface);
|
||||
ActivateToolByIndex(0);
|
||||
|
||||
eventAggregator.Subscribe(this);
|
||||
}
|
||||
|
||||
|
||||
public bool CanSelectEditTool
|
||||
{
|
||||
get => _canSelectEditTool;
|
||||
@@ -82,12 +68,6 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
|
||||
set => SetAndNotify(ref _panZoomViewModel, value);
|
||||
}
|
||||
|
||||
public BindableCollection<CanvasViewModel> CanvasViewModels
|
||||
{
|
||||
get => _canvasViewModels;
|
||||
set => SetAndNotify(ref _canvasViewModels, value);
|
||||
}
|
||||
|
||||
public BindableCollection<ArtemisDevice> Devices
|
||||
{
|
||||
get => _devices;
|
||||
@@ -100,12 +80,6 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
|
||||
set => SetAndNotify(ref _highlightedLeds, value);
|
||||
}
|
||||
|
||||
public BindableCollection<ArtemisLed> SelectedLeds
|
||||
{
|
||||
get => _selectedLeds;
|
||||
set => SetAndNotify(ref _selectedLeds, value);
|
||||
}
|
||||
|
||||
public PluginSetting<bool> AlwaysApplyDataBindings
|
||||
{
|
||||
get => _alwaysApplyDataBindings;
|
||||
@@ -126,10 +100,10 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
|
||||
// Remove the tool from the canvas
|
||||
if (_activeToolViewModel != null)
|
||||
{
|
||||
lock (CanvasViewModels)
|
||||
lock (Items)
|
||||
{
|
||||
CanvasViewModels.Remove(_activeToolViewModel);
|
||||
NotifyOfPropertyChange(() => CanvasViewModels);
|
||||
Items.Remove(_activeToolViewModel);
|
||||
NotifyOfPropertyChange(() => Items);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,10 +112,10 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
|
||||
// Add the new tool to the canvas
|
||||
if (_activeToolViewModel != null)
|
||||
{
|
||||
lock (CanvasViewModels)
|
||||
lock (Items)
|
||||
{
|
||||
CanvasViewModels.Add(_activeToolViewModel);
|
||||
NotifyOfPropertyChange(() => CanvasViewModels);
|
||||
Items.Add(_activeToolViewModel);
|
||||
NotifyOfPropertyChange(() => Items);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -163,15 +137,16 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
|
||||
set => SetAndNotify(ref _canApplyToLayer, value);
|
||||
}
|
||||
|
||||
public List<ArtemisLed> GetLedsInRectangle(Rect selectedRect)
|
||||
{
|
||||
return Devices.SelectMany(d => d.Leds)
|
||||
.Where(led => led.RgbLed.AbsoluteLedRectangle.ToWindowsRect(1).IntersectsWith(selectedRect))
|
||||
.ToList();
|
||||
}
|
||||
|
||||
protected override void OnInitialActivate()
|
||||
{
|
||||
PanZoomViewModel = new PanZoomViewModel {LimitToZero = false};
|
||||
|
||||
Devices = new BindableCollection<ArtemisDevice>();
|
||||
HighlightedLeds = new BindableCollection<ArtemisLed>();
|
||||
|
||||
ApplySurfaceConfiguration(_surfaceService.ActiveSurface);
|
||||
ActivateToolByIndex(0);
|
||||
|
||||
ApplyActiveProfile();
|
||||
|
||||
AlwaysApplyDataBindings = _settingsService.GetSetting("ProfileEditor.AlwaysApplyDataBindings", true);
|
||||
@@ -203,10 +178,6 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
|
||||
AlwaysApplyDataBindings.Save();
|
||||
HighlightSelectedLayer.Save();
|
||||
|
||||
foreach (CanvasViewModel canvasViewModel in CanvasViewModels)
|
||||
canvasViewModel.Dispose();
|
||||
CanvasViewModels.Clear();
|
||||
|
||||
base.OnClose();
|
||||
}
|
||||
|
||||
@@ -217,23 +188,20 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
|
||||
|
||||
private void ApplyActiveProfile()
|
||||
{
|
||||
List<ProfileLayerViewModel> layerViewModels = CanvasViewModels.Where(vm => vm is ProfileLayerViewModel).Cast<ProfileLayerViewModel>().ToList();
|
||||
List<ProfileLayerViewModel> layerViewModels = Items.Where(vm => vm is ProfileLayerViewModel).Cast<ProfileLayerViewModel>().ToList();
|
||||
List<Layer> layers = _profileEditorService.SelectedProfile?.GetAllLayers() ?? new List<Layer>();
|
||||
|
||||
// Add new layers missing a VM
|
||||
foreach (Layer layer in layers)
|
||||
{
|
||||
if (layerViewModels.All(vm => vm.Layer != layer))
|
||||
CanvasViewModels.Add(_profileLayerVmFactory.Create(layer, this));
|
||||
Items.Add(_profileLayerVmFactory.Create(layer, PanZoomViewModel));
|
||||
}
|
||||
|
||||
// Remove layers that no longer exist
|
||||
IEnumerable<ProfileLayerViewModel> toRemove = layerViewModels.Where(vm => !layers.Contains(vm.Layer));
|
||||
foreach (ProfileLayerViewModel profileLayerViewModel in toRemove)
|
||||
{
|
||||
profileLayerViewModel.Dispose();
|
||||
CanvasViewModels.Remove(profileLayerViewModel);
|
||||
}
|
||||
Items.Remove(profileLayerViewModel);
|
||||
}
|
||||
|
||||
private void ApplySurfaceConfiguration(ArtemisSurface surface)
|
||||
@@ -270,20 +238,19 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
|
||||
|
||||
private void ActivateToolByIndex(int value)
|
||||
{
|
||||
// Consider using DI if dependencies start to add up
|
||||
switch (value)
|
||||
{
|
||||
case 0:
|
||||
ActiveToolViewModel = _visualizationToolVmFactory.ViewpointMoveToolViewModel(this);
|
||||
ActiveToolViewModel = _visualizationToolVmFactory.ViewpointMoveToolViewModel(PanZoomViewModel);
|
||||
break;
|
||||
case 1:
|
||||
ActiveToolViewModel = _visualizationToolVmFactory.EditToolViewModel(this);
|
||||
ActiveToolViewModel = _visualizationToolVmFactory.EditToolViewModel(PanZoomViewModel);
|
||||
break;
|
||||
case 2:
|
||||
ActiveToolViewModel = _visualizationToolVmFactory.SelectionToolViewModel(this);
|
||||
ActiveToolViewModel = _visualizationToolVmFactory.SelectionToolViewModel(PanZoomViewModel);
|
||||
break;
|
||||
case 3:
|
||||
ActiveToolViewModel = _visualizationToolVmFactory.SelectionRemoveToolViewModel(this);
|
||||
ActiveToolViewModel = _visualizationToolVmFactory.SelectionRemoveToolViewModel(PanZoomViewModel);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -324,43 +291,6 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
|
||||
|
||||
#endregion
|
||||
|
||||
#region Context menu actions
|
||||
|
||||
public void CreateLayer()
|
||||
{
|
||||
}
|
||||
|
||||
public void ApplyToLayer()
|
||||
{
|
||||
if (!(_profileEditorService.SelectedProfileElement is Layer layer))
|
||||
return;
|
||||
|
||||
layer.ClearLeds();
|
||||
layer.AddLeds(SelectedLeds);
|
||||
|
||||
_profileEditorService.UpdateSelectedProfileElement();
|
||||
}
|
||||
|
||||
public void SelectAll()
|
||||
{
|
||||
SelectedLeds.Clear();
|
||||
SelectedLeds.AddRange(Devices.SelectMany(d => d.Leds));
|
||||
}
|
||||
|
||||
public void InverseSelection()
|
||||
{
|
||||
List<ArtemisLed> current = SelectedLeds.ToList();
|
||||
SelectedLeds.Clear();
|
||||
SelectedLeds.AddRange(Devices.SelectMany(d => d.Leds).Except(current));
|
||||
}
|
||||
|
||||
public void ClearSelection()
|
||||
{
|
||||
SelectedLeds.Clear();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Event handlers
|
||||
|
||||
private void OnFrameRendered(object sender, FrameRenderedEventArgs e)
|
||||
@@ -368,7 +298,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization
|
||||
TimeSpan delta = DateTime.Now - _lastUpdate;
|
||||
_lastUpdate = DateTime.Now;
|
||||
|
||||
if (!AlwaysApplyDataBindings.Value || _profileEditorService.SelectedProfile == null || ((ProfileEditorViewModel) Parent).LayerPropertiesViewModel.Playing)
|
||||
if (!AlwaysApplyDataBindings.Value || _profileEditorService.SelectedProfile == null || _profileEditorService.Playing)
|
||||
return;
|
||||
|
||||
foreach (IDataBindingRegistration dataBindingRegistration in _profileEditorService.SelectedProfile.GetAllFolders()
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
d:DesignWidth="800"
|
||||
d:DataContext="{d:DesignInstance {x:Type tools:EditToolViewModel}}">
|
||||
<Canvas UseLayoutRounding="False">
|
||||
<userControls1:LayerShapeControl Zoom="{Binding ProfileViewModel.PanZoomViewModel.Zoom}"
|
||||
<userControls1:LayerShapeControl Zoom="{Binding PanZoomViewModel.Zoom}"
|
||||
ShapePath="{Binding ShapePath}"
|
||||
ShapeAnchor="{Binding ShapeAnchor}"
|
||||
ShapeGeometry="{Binding ShapeGeometry}"
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Events;
|
||||
using Artemis.UI.Screens.Shared;
|
||||
using Artemis.UI.Services.Interfaces;
|
||||
using Artemis.UI.Shared.Services;
|
||||
using SkiaSharp;
|
||||
@@ -22,17 +23,12 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
|
||||
private SKPath _shapePath;
|
||||
private SKPoint _topLeft;
|
||||
|
||||
public EditToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService, ILayerEditorService layerEditorService)
|
||||
: base(profileViewModel, profileEditorService)
|
||||
public EditToolViewModel(PanZoomViewModel panZoomViewModel, IProfileEditorService profileEditorService, ILayerEditorService layerEditorService)
|
||||
: base(panZoomViewModel, profileEditorService)
|
||||
{
|
||||
_layerEditorService = layerEditorService;
|
||||
Cursor = Cursors.Arrow;
|
||||
Update();
|
||||
|
||||
profileEditorService.ProfileSelected += (sender, args) => Update();
|
||||
profileEditorService.ProfileElementSelected += (sender, args) => Update();
|
||||
profileEditorService.SelectedProfileElementUpdated += (sender, args) => Update();
|
||||
profileEditorService.ProfilePreviewUpdated += (sender, args) => Update();
|
||||
}
|
||||
|
||||
public SKPath ShapePath
|
||||
@@ -60,12 +56,12 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
|
||||
|
||||
ShapePath = _layerEditorService.GetLayerPath(layer, true, true, true);
|
||||
ShapeAnchor = _layerEditorService.GetLayerAnchorPosition(layer).ToSKPoint();
|
||||
|
||||
Rect layerBounds = _layerEditorService.GetLayerBounds(layer);
|
||||
TransformGroup layerTransformGroup = _layerEditorService.GetLayerTransformGroup(layer);
|
||||
Execute.PostToUIThread(() =>
|
||||
{
|
||||
RectangleGeometry shapeGeometry = new(_layerEditorService.GetLayerBounds(layer))
|
||||
{
|
||||
Transform = _layerEditorService.GetLayerTransformGroup(layer)
|
||||
};
|
||||
RectangleGeometry shapeGeometry = new(layerBounds) {Transform = layerTransformGroup};
|
||||
shapeGeometry.Freeze();
|
||||
ShapeGeometry = shapeGeometry;
|
||||
});
|
||||
@@ -74,6 +70,37 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
|
||||
_topLeft = _layerEditorService.GetLayerPath(layer, true, true, true).Points[0];
|
||||
}
|
||||
|
||||
#region Overrides of Screen
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnInitialActivate()
|
||||
{
|
||||
ProfileEditorService.ProfileSelected += UpdateEventHandler;
|
||||
ProfileEditorService.ProfileElementSelected += UpdateEventHandler;
|
||||
ProfileEditorService.SelectedProfileElementUpdated += UpdateEventHandler;
|
||||
ProfileEditorService.ProfilePreviewUpdated += UpdateEventHandler;
|
||||
|
||||
Update();
|
||||
base.OnInitialActivate();
|
||||
}
|
||||
|
||||
private void UpdateEventHandler(object sender, EventArgs e)
|
||||
{
|
||||
Update();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected override void OnClose()
|
||||
{
|
||||
ProfileEditorService.ProfileSelected -= UpdateEventHandler;
|
||||
ProfileEditorService.ProfileElementSelected -= UpdateEventHandler;
|
||||
ProfileEditorService.SelectedProfileElementUpdated -= UpdateEventHandler;
|
||||
ProfileEditorService.ProfilePreviewUpdated -= UpdateEventHandler;
|
||||
base.OnClose();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Rotation
|
||||
|
||||
private bool _rotating;
|
||||
|
||||
+5
-13
@@ -5,6 +5,7 @@ using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Properties;
|
||||
using Artemis.UI.Screens.Shared;
|
||||
using Artemis.UI.Shared.Services;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
|
||||
@@ -13,7 +14,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
|
||||
{
|
||||
private Rect _dragRectangle;
|
||||
|
||||
public SelectionRemoveToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService) : base(profileViewModel, profileEditorService)
|
||||
public SelectionRemoveToolViewModel(PanZoomViewModel panZoomViewModel, IProfileEditorService profileEditorService) : base(panZoomViewModel, profileEditorService)
|
||||
{
|
||||
using (MemoryStream stream = new(Resources.aero_pen_min))
|
||||
{
|
||||
@@ -31,13 +32,11 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
|
||||
{
|
||||
base.MouseUp(sender, e);
|
||||
|
||||
Point position = ProfileViewModel.PanZoomViewModel.GetRelativeMousePosition(sender, e);
|
||||
Point position = PanZoomViewModel.GetRelativeMousePosition(sender, e);
|
||||
Rect selectedRect = new(MouseDownStartPosition, position);
|
||||
|
||||
// Get selected LEDs
|
||||
List<ArtemisLed> selectedLeds = ProfileViewModel.GetLedsInRectangle(selectedRect);
|
||||
ProfileViewModel.SelectedLeds.Clear();
|
||||
ProfileViewModel.SelectedLeds.AddRange(selectedLeds);
|
||||
List<ArtemisLed> selectedLeds = ProfileEditorService.GetLedsInRectangle(selectedRect);
|
||||
|
||||
// Apply the selection to the selected layer layer
|
||||
if (ProfileEditorService.SelectedProfileElement is Layer layer)
|
||||
@@ -59,15 +58,8 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
|
||||
return;
|
||||
}
|
||||
|
||||
Point position = ProfileViewModel.PanZoomViewModel.GetRelativeMousePosition(sender, e);
|
||||
Point position = PanZoomViewModel.GetRelativeMousePosition(sender, e);
|
||||
Rect selectedRect = new(MouseDownStartPosition, position);
|
||||
List<ArtemisLed> selectedLeds = ProfileViewModel.GetLedsInRectangle(selectedRect);
|
||||
|
||||
// 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,6 +7,7 @@ using Artemis.Core;
|
||||
using Artemis.Core.LayerBrushes;
|
||||
using Artemis.Core.Services;
|
||||
using Artemis.UI.Properties;
|
||||
using Artemis.UI.Screens.Shared;
|
||||
using Artemis.UI.Shared.Services;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
|
||||
@@ -16,9 +17,8 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
|
||||
private readonly ILayerBrushService _layerBrushService;
|
||||
private Rect _dragRectangle;
|
||||
|
||||
public SelectionToolViewModel(ProfileViewModel profileViewModel,
|
||||
IProfileEditorService profileEditorService,
|
||||
ILayerBrushService layerBrushService) : base(profileViewModel, profileEditorService)
|
||||
public SelectionToolViewModel(PanZoomViewModel panZoomViewModel, IProfileEditorService profileEditorService, ILayerBrushService layerBrushService)
|
||||
: base(panZoomViewModel, profileEditorService)
|
||||
{
|
||||
_layerBrushService = layerBrushService;
|
||||
using (MemoryStream stream = new(Resources.aero_crosshair))
|
||||
@@ -37,11 +37,11 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
|
||||
{
|
||||
base.MouseUp(sender, e);
|
||||
|
||||
Point position = ProfileViewModel.PanZoomViewModel.GetRelativeMousePosition(sender, e);
|
||||
Point position = PanZoomViewModel.GetRelativeMousePosition(sender, e);
|
||||
Rect selectedRect = new(MouseDownStartPosition, position);
|
||||
|
||||
// Get selected LEDs
|
||||
List<ArtemisLed> selectedLeds = ProfileViewModel.GetLedsInRectangle(selectedRect);
|
||||
List<ArtemisLed> selectedLeds = ProfileEditorService.GetLedsInRectangle(selectedRect);
|
||||
|
||||
// Apply the selection to the selected layer layer
|
||||
if (ProfileEditorService.SelectedProfileElement is Layer layer)
|
||||
@@ -77,14 +77,9 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
|
||||
return;
|
||||
}
|
||||
|
||||
Point position = ProfileViewModel.PanZoomViewModel.GetRelativeMousePosition(sender, e);
|
||||
Point position = PanZoomViewModel.GetRelativeMousePosition(sender, e);
|
||||
Rect selectedRect = new(MouseDownStartPosition, position);
|
||||
List<ArtemisLed> selectedLeds = ProfileViewModel.GetLedsInRectangle(selectedRect);
|
||||
|
||||
// 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));
|
||||
List<ArtemisLed> selectedLeds = ProfileEditorService.GetLedsInRectangle(selectedRect);
|
||||
|
||||
DragRectangle = selectedRect;
|
||||
}
|
||||
|
||||
+4
-3
@@ -1,20 +1,21 @@
|
||||
using System.Windows.Input;
|
||||
using Artemis.UI.Screens.Shared;
|
||||
using Artemis.UI.Shared.Services;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
|
||||
{
|
||||
public class ViewpointMoveToolViewModel : VisualizationToolViewModel
|
||||
{
|
||||
public ViewpointMoveToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService) : base(profileViewModel, profileEditorService)
|
||||
public ViewpointMoveToolViewModel(PanZoomViewModel panZoomViewModel, IProfileEditorService profileEditorService) : base(panZoomViewModel, profileEditorService)
|
||||
{
|
||||
Cursor = Cursors.Hand;
|
||||
ProfileViewModel.PanZoomViewModel.LastPanPosition = null;
|
||||
PanZoomViewModel.LastPanPosition = null;
|
||||
}
|
||||
|
||||
public override void MouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
base.MouseMove(sender, e);
|
||||
ProfileViewModel.PanZoomViewModel.ProcessMouseMove(sender, e);
|
||||
PanZoomViewModel.ProcessMouseMove(sender, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
-4
@@ -1,6 +1,9 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using Artemis.Core;
|
||||
using Artemis.UI.Screens.Shared;
|
||||
using Artemis.UI.Shared.Services;
|
||||
|
||||
namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
|
||||
@@ -11,18 +14,18 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
|
||||
private bool _isMouseDown;
|
||||
private Point _mouseDownStartPosition;
|
||||
|
||||
protected VisualizationToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService)
|
||||
protected VisualizationToolViewModel(PanZoomViewModel panZoomViewModel, IProfileEditorService profileEditorService)
|
||||
{
|
||||
// Not relevant for visualization tools as they overlay the entire canvas
|
||||
X = 0;
|
||||
Y = 0;
|
||||
|
||||
ProfileViewModel = profileViewModel;
|
||||
PanZoomViewModel = panZoomViewModel;
|
||||
ProfileEditorService = profileEditorService;
|
||||
Cursor = Cursors.Arrow;
|
||||
}
|
||||
|
||||
public ProfileViewModel ProfileViewModel { get; }
|
||||
public PanZoomViewModel PanZoomViewModel { get; }
|
||||
public IProfileEditorService ProfileEditorService { get; }
|
||||
|
||||
public Cursor Cursor
|
||||
@@ -46,7 +49,7 @@ namespace Artemis.UI.Screens.ProfileEditor.Visualization.Tools
|
||||
public virtual void MouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
IsMouseDown = true;
|
||||
MouseDownStartPosition = ProfileViewModel.PanZoomViewModel.GetRelativeMousePosition(sender, e);
|
||||
MouseDownStartPosition = PanZoomViewModel.GetRelativeMousePosition(sender, e);
|
||||
}
|
||||
|
||||
public virtual void MouseUp(object sender, MouseButtonEventArgs e)
|
||||
|
||||
Reference in new issue
Block a user