Files
Artemis/src/Artemis.UI/Screens/ProfileEditor/Visualization/Tools/SelectionRemoveToolViewModel.cs
T
Robert Beekman ceeaa4bf6d Profiles - Reworked profile system
Sidebar - Redesigned sidebar with customizable categories
Profiles - Added the ability to configure custom profile icons
Profiles - Added the ability to activate multiple profiles for modules at once
Profiles - Added the ability to create profiles for no modules
Profiles - Added the ability to suspend a profile or an entire category
Profiles - Added profile activation conditions
Profiles - Added file-based importing/exporting
Profile editor - Condensed UI, removed tabs 
Profile editor - Disable condition operators until a left-side is picked
2021-06-03 22:34:43 +02:00

66 lines
2.2 KiB
C#

using System.Collections.Generic;
using System.IO;
using System.Linq;
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
{
public class SelectionRemoveToolViewModel : VisualizationToolViewModel
{
private Rect _dragRectangle;
public SelectionRemoveToolViewModel(PanZoomViewModel panZoomViewModel, IProfileEditorService profileEditorService) : base(panZoomViewModel, profileEditorService)
{
using (MemoryStream stream = new(Resources.aero_pen_min))
{
Cursor = new Cursor(stream);
}
}
public Rect DragRectangle
{
get => _dragRectangle;
set => SetAndNotify(ref _dragRectangle, value);
}
public override void MouseUp(object sender, MouseButtonEventArgs e)
{
base.MouseUp(sender, e);
Point position = PanZoomViewModel.GetRelativeMousePosition(sender, e);
Rect selectedRect = new(MouseDownStartPosition, position);
// Get selected LEDs
List<ArtemisLed> selectedLeds = ProfileEditorService.GetLedsInRectangle(selectedRect);
// Apply the selection to the selected layer layer
if (ProfileEditorService.SelectedProfileElement is Layer layer)
{
List<ArtemisLed> remainingLeds = layer.Leds.Except(selectedLeds).ToList();
layer.ClearLeds();
layer.AddLeds(remainingLeds);
ProfileEditorService.SaveSelectedProfileElement();
}
}
public override void MouseMove(object sender, MouseEventArgs e)
{
base.MouseMove(sender, e);
if (!IsMouseDown)
{
DragRectangle = new Rect(-1, -1, 0, 0);
return;
}
Point position = PanZoomViewModel.GetRelativeMousePosition(sender, e);
Rect selectedRect = new(MouseDownStartPosition, position);
DragRectangle = selectedRect;
}
}
}