|
@@ -1,9 +1,13 @@
|
|
using Avalonia.Input;
|
|
using Avalonia.Input;
|
|
|
|
+using ChunkyImageLib.DataHolders;
|
|
using PixiEditor.AvaloniaUI.Models.Commands.Attributes.Commands;
|
|
using PixiEditor.AvaloniaUI.Models.Commands.Attributes.Commands;
|
|
|
|
+using PixiEditor.AvaloniaUI.Models.DocumentModels;
|
|
|
|
+using PixiEditor.AvaloniaUI.Models.Handlers;
|
|
using PixiEditor.AvaloniaUI.Models.Handlers.Tools;
|
|
using PixiEditor.AvaloniaUI.Models.Handlers.Tools;
|
|
using PixiEditor.AvaloniaUI.ViewModels.Tools.ToolSettings.Toolbars;
|
|
using PixiEditor.AvaloniaUI.ViewModels.Tools.ToolSettings.Toolbars;
|
|
using PixiEditor.AvaloniaUI.Views.Overlays.BrushShapeOverlay;
|
|
using PixiEditor.AvaloniaUI.Views.Overlays.BrushShapeOverlay;
|
|
using PixiEditor.DrawingApi.Core.Numerics;
|
|
using PixiEditor.DrawingApi.Core.Numerics;
|
|
|
|
+using PixiEditor.DrawingApi.Core.Surface.Vector;
|
|
using PixiEditor.Extensions.Common.Localization;
|
|
using PixiEditor.Extensions.Common.Localization;
|
|
|
|
|
|
namespace PixiEditor.AvaloniaUI.ViewModels.Tools.Tools;
|
|
namespace PixiEditor.AvaloniaUI.ViewModels.Tools.Tools;
|
|
@@ -18,6 +22,8 @@ internal class MoveToolViewModel : ToolViewModel, IMoveToolHandler
|
|
private bool transformingSelectedArea = false;
|
|
private bool transformingSelectedArea = false;
|
|
public bool MoveAllLayers { get; set; }
|
|
public bool MoveAllLayers { get; set; }
|
|
|
|
|
|
|
|
+ private bool removeSelection = false;
|
|
|
|
+
|
|
public MoveToolViewModel()
|
|
public MoveToolViewModel()
|
|
{
|
|
{
|
|
ActionDisplay = defaultActionDisplay;
|
|
ActionDisplay = defaultActionDisplay;
|
|
@@ -54,7 +60,7 @@ internal class MoveToolViewModel : ToolViewModel, IMoveToolHandler
|
|
{
|
|
{
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
if (ctrlIsDown)
|
|
if (ctrlIsDown)
|
|
{
|
|
{
|
|
ActionDisplay = new LocalizedString("MOVE_TOOL_ACTION_DISPLAY_CTRL");
|
|
ActionDisplay = new LocalizedString("MOVE_TOOL_ACTION_DISPLAY_CTRL");
|
|
@@ -69,6 +75,57 @@ internal class MoveToolViewModel : ToolViewModel, IMoveToolHandler
|
|
|
|
|
|
public override void OnSelected()
|
|
public override void OnSelected()
|
|
{
|
|
{
|
|
|
|
+ RectI? bounds = GetSelectedLayersBounds();
|
|
|
|
+ bool? isEmpty = ViewModelMain.Current.DocumentManagerSubViewModel.ActiveDocument?.SelectionPathBindable
|
|
|
|
+ ?.IsEmpty;
|
|
|
|
+ if ((!isEmpty.HasValue || isEmpty.Value) && bounds.HasValue)
|
|
|
|
+ {
|
|
|
|
+ ViewModelMain.Current.DocumentManagerSubViewModel.ActiveDocument.Operations.Select(bounds.Value);
|
|
|
|
+ VectorPath path = new VectorPath();
|
|
|
|
+ path.AddRect(bounds.Value);
|
|
|
|
+ ViewModelMain.Current.DocumentManagerSubViewModel.ActiveDocument.UpdateSelectionPath(path);
|
|
|
|
+ removeSelection = true;
|
|
|
|
+ }
|
|
|
|
+
|
|
ViewModelMain.Current.DocumentManagerSubViewModel.ActiveDocument?.Operations.TransformSelectedArea(true);
|
|
ViewModelMain.Current.DocumentManagerSubViewModel.ActiveDocument?.Operations.TransformSelectedArea(true);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public override void OnDeselecting()
|
|
|
|
+ {
|
|
|
|
+ ViewModelMain.Current.DocumentManagerSubViewModel.ActiveDocument?.Operations.TryStopToolLinkedExecutor();
|
|
|
|
+
|
|
|
|
+ if (removeSelection)
|
|
|
|
+ {
|
|
|
|
+ ViewModelMain.Current.DocumentManagerSubViewModel.ActiveDocument?.Operations.ClearSelection();
|
|
|
|
+ removeSelection = false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private static RectI? GetSelectedLayersBounds()
|
|
|
|
+ {
|
|
|
|
+ var layers = ViewModelMain.Current.DocumentManagerSubViewModel.ActiveDocument?.ExtractSelectedLayers();
|
|
|
|
+ RectI? bounds = null;
|
|
|
|
+ if (layers != null)
|
|
|
|
+ {
|
|
|
|
+ foreach (var layer in layers)
|
|
|
|
+ {
|
|
|
|
+ var foundLayer =
|
|
|
|
+ ViewModelMain.Current.DocumentManagerSubViewModel.ActiveDocument.StructureHelper.Find(layer);
|
|
|
|
+ RectI? layerBounds = foundLayer?.TightBounds;
|
|
|
|
+ if (layerBounds != null)
|
|
|
|
+ {
|
|
|
|
+ if (bounds == null)
|
|
|
|
+ {
|
|
|
|
+ bounds = layerBounds;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ bounds = bounds.Value.Union(layerBounds.Value);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return bounds;
|
|
|
|
+ }
|
|
}
|
|
}
|