Files
Artemis/src/Artemis.UI/Screens/Module/ProfileEditor/Visualization/Tools/FillToolViewModel.cs
T
Robert cd1b75750e Refactored the edit tool
Fixed the fill shape but it might need some rethinking
2020-01-29 17:14:07 +01:00

49 lines
1.8 KiB
C#

using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows;
using System.Windows.Input;
using Artemis.Core.Models.Profile.LayerShapes;
using Artemis.UI.Properties;
using Artemis.UI.Services;
using Artemis.UI.Services.Interfaces;
namespace Artemis.UI.Screens.Module.ProfileEditor.Visualization.Tools
{
public class FillToolViewModel : VisualizationToolViewModel
{
private readonly ILayerEditorService _layerEditorService;
public FillToolViewModel(ProfileViewModel profileViewModel, IProfileEditorService profileEditorService, ILayerEditorService layerEditorService) : base(profileViewModel, profileEditorService)
{
_layerEditorService = layerEditorService;
using (var stream = new MemoryStream(Resources.aero_fill))
{
Cursor = new Cursor(stream);
}
}
public override void MouseUp(object sender, MouseButtonEventArgs e)
{
base.MouseUp(sender, e);
// Find out if the click is inside a layer and if so, fill it
var position = e.GetPosition((IInputElement) sender);
var panZoomVm = ProfileViewModel.PanZoomViewModel;
var layer = ProfileEditorService.SelectedProfile
.GetAllLayers()
.FirstOrDefault(l => l.Leds.Any(
led => panZoomVm.TransformContainingRect(led.RgbLed.AbsoluteLedRectangle).Contains(position))
);
if (layer == null)
return;
layer.LayerShape = new Fill(layer);
// Apply the full layer rectangle
_layerEditorService.SetShapeRenderRect(layer.LayerShape, _layerEditorService.GetLayerRect(layer));
ProfileEditorService.UpdateSelectedProfileElement();
}
}
}