Profile editor - Refactored a lot of VMs so they clean up nicely

This commit is contained in:
SpoinkyNL committed 2020-12-20 18:13:56 +01:00
1 parent 0dac4c7387
commit 4db66e1e3e
37 files changed
+531 -496

No files matched your search

@@ -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,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;
}
@@ -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);
}
}
}
@@ -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)