|
@@ -7,11 +7,13 @@ using PixiEditor.ChangeableDocument.Changeables.Interfaces;
|
|
using PixiEditor.ChangeableDocument.Enums;
|
|
using PixiEditor.ChangeableDocument.Enums;
|
|
using PixiEditor.Helpers;
|
|
using PixiEditor.Helpers;
|
|
using PixiEditor.Models.DocumentModels;
|
|
using PixiEditor.Models.DocumentModels;
|
|
|
|
+using PixiEditor.Models.Position;
|
|
using PixiEditor.ViewModels.Prototype;
|
|
using PixiEditor.ViewModels.Prototype;
|
|
using SkiaSharp;
|
|
using SkiaSharp;
|
|
|
|
|
|
namespace PixiEditor.ViewModels.SubViewModels.Document;
|
|
namespace PixiEditor.ViewModels.SubViewModels.Document;
|
|
|
|
|
|
|
|
+#nullable enable
|
|
internal class DocumentViewModel : NotifyableObject
|
|
internal class DocumentViewModel : NotifyableObject
|
|
{
|
|
{
|
|
public const string ConfirmationDialogTitle = "Unsaved changes";
|
|
public const string ConfirmationDialogTitle = "Unsaved changes";
|
|
@@ -26,14 +28,14 @@ internal class DocumentViewModel : NotifyableObject
|
|
RaisePropertyChanged(nameof(Busy));
|
|
RaisePropertyChanged(nameof(Busy));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public FolderViewModel StructureRoot { get; }
|
|
public FolderViewModel StructureRoot { get; }
|
|
|
|
|
|
public int Width => size.X;
|
|
public int Width => size.X;
|
|
public int Height => size.Y;
|
|
public int Height => size.Y;
|
|
-
|
|
|
|
|
|
+
|
|
public StructureMemberViewModel? SelectedStructureMember => FindFirstSelectedMember();
|
|
public StructureMemberViewModel? SelectedStructureMember => FindFirstSelectedMember();
|
|
-
|
|
|
|
|
|
+
|
|
public Dictionary<ChunkResolution, WriteableBitmap> Bitmaps { get; set; } = new()
|
|
public Dictionary<ChunkResolution, WriteableBitmap> Bitmaps { get; set; } = new()
|
|
{
|
|
{
|
|
[ChunkResolution.Full] = new WriteableBitmap(64, 64, 96, 96, PixelFormats.Pbgra32, null),
|
|
[ChunkResolution.Full] = new WriteableBitmap(64, 64, 96, 96, PixelFormats.Pbgra32, null),
|
|
@@ -48,24 +50,24 @@ internal class DocumentViewModel : NotifyableObject
|
|
public Dictionary<ChunkResolution, SKSurface> Surfaces { get; set; } = new();
|
|
public Dictionary<ChunkResolution, SKSurface> Surfaces { get; set; } = new();
|
|
|
|
|
|
public VecI SizeBindable => size;
|
|
public VecI SizeBindable => size;
|
|
-
|
|
|
|
|
|
+
|
|
public StructureMemberViewModel? FindFirstSelectedMember() => Helpers.StructureHelper.FindFirstWhere(member => member.IsSelected);
|
|
public StructureMemberViewModel? FindFirstSelectedMember() => Helpers.StructureHelper.FindFirstWhere(member => member.IsSelected);
|
|
|
|
|
|
public int HorizontalSymmetryAxisYBindable => horizontalSymmetryAxisY;
|
|
public int HorizontalSymmetryAxisYBindable => horizontalSymmetryAxisY;
|
|
public int VerticalSymmetryAxisXBindable => verticalSymmetryAxisX;
|
|
public int VerticalSymmetryAxisXBindable => verticalSymmetryAxisX;
|
|
-
|
|
|
|
|
|
+
|
|
public bool HorizontalSymmetryAxisEnabledBindable
|
|
public bool HorizontalSymmetryAxisEnabledBindable
|
|
{
|
|
{
|
|
get => horizontalSymmetryAxisEnabled;
|
|
get => horizontalSymmetryAxisEnabled;
|
|
set => Helpers.ActionAccumulator.AddFinishedActions(new SymmetryAxisState_Action(SymmetryAxisDirection.Horizontal, value));
|
|
set => Helpers.ActionAccumulator.AddFinishedActions(new SymmetryAxisState_Action(SymmetryAxisDirection.Horizontal, value));
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public bool VerticalSymmetryAxisEnabledBindable
|
|
public bool VerticalSymmetryAxisEnabledBindable
|
|
{
|
|
{
|
|
get => verticalSymmetryAxisEnabled;
|
|
get => verticalSymmetryAxisEnabled;
|
|
set => Helpers.ActionAccumulator.AddFinishedActions(new SymmetryAxisState_Action(SymmetryAxisDirection.Vertical, value));
|
|
set => Helpers.ActionAccumulator.AddFinishedActions(new SymmetryAxisState_Action(SymmetryAxisDirection.Vertical, value));
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public IReadOnlyReferenceLayer? ReferenceLayer => Helpers.Tracker.Document.ReferenceLayer;
|
|
public IReadOnlyReferenceLayer? ReferenceLayer => Helpers.Tracker.Document.ReferenceLayer;
|
|
|
|
|
|
public BitmapSource? ReferenceBitmap => ReferenceLayer?.Image.ToWriteableBitmap();
|
|
public BitmapSource? ReferenceBitmap => ReferenceLayer?.Image.ToWriteableBitmap();
|
|
@@ -82,31 +84,74 @@ internal class DocumentViewModel : NotifyableObject
|
|
return new Matrix(skiaMatrix.ScaleX, skiaMatrix.SkewY, skiaMatrix.SkewX, skiaMatrix.ScaleY, skiaMatrix.TransX, skiaMatrix.TransY);
|
|
return new Matrix(skiaMatrix.ScaleX, skiaMatrix.SkewY, skiaMatrix.SkewX, skiaMatrix.ScaleY, skiaMatrix.TransX, skiaMatrix.TransY);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public SKPath SelectionPathBindable => selectionPath;
|
|
public SKPath SelectionPathBindable => selectionPath;
|
|
|
|
+ public DocumentTransformViewModel TransformViewModel { get; }
|
|
|
|
|
|
private DocumentHelpers Helpers { get; }
|
|
private DocumentHelpers Helpers { get; }
|
|
|
|
|
|
- private readonly ViewModelMain owner;
|
|
|
|
|
|
+ private readonly DocumentManagerViewModel owner;
|
|
|
|
|
|
private int verticalSymmetryAxisX;
|
|
private int verticalSymmetryAxisX;
|
|
-
|
|
|
|
|
|
+
|
|
private bool horizontalSymmetryAxisEnabled;
|
|
private bool horizontalSymmetryAxisEnabled;
|
|
|
|
|
|
private bool verticalSymmetryAxisEnabled;
|
|
private bool verticalSymmetryAxisEnabled;
|
|
-
|
|
|
|
|
|
+
|
|
private bool busy = false;
|
|
private bool busy = false;
|
|
-
|
|
|
|
|
|
+
|
|
private VecI size = new VecI(64, 64);
|
|
private VecI size = new VecI(64, 64);
|
|
|
|
|
|
private int horizontalSymmetryAxisY;
|
|
private int horizontalSymmetryAxisY;
|
|
-
|
|
|
|
|
|
+
|
|
private SKPath selectionPath = new SKPath();
|
|
private SKPath selectionPath = new SKPath();
|
|
-
|
|
|
|
- public DocumentViewModel(string name)
|
|
|
|
|
|
+
|
|
|
|
+ public DocumentViewModel(DocumentManagerViewModel owner, string name)
|
|
{
|
|
{
|
|
|
|
+ this.owner = owner;
|
|
|
|
+ //Name = name;
|
|
|
|
+ TransformViewModel = new();
|
|
|
|
+ //TransformViewModel.TransformMoved += OnTransformUpdate;
|
|
|
|
+
|
|
|
|
+ Helpers = new DocumentHelpers(this);
|
|
|
|
+ StructureRoot = new FolderViewModel(this, Helpers, Helpers.Tracker.Document.StructureRoot.GuidValue);
|
|
|
|
+
|
|
|
|
+ /*UndoCommand = new RelayCommand(Undo);
|
|
|
|
+ RedoCommand = new RelayCommand(Redo);
|
|
|
|
+ ClearSelectionCommand = new RelayCommand(ClearSelection);
|
|
|
|
+ CreateNewLayerCommand = new RelayCommand(_ => Helpers.StructureHelper.CreateNewStructureMember(StructureMemberType.Layer));
|
|
|
|
+ CreateNewFolderCommand = new RelayCommand(_ => Helpers.StructureHelper.CreateNewStructureMember(StructureMemberType.Folder));
|
|
|
|
+ DeleteStructureMemberCommand = new RelayCommand(DeleteStructureMember);
|
|
|
|
+ ResizeCanvasCommand = new RelayCommand(ResizeCanvas);
|
|
|
|
+ ResizeImageCommand = new RelayCommand(ResizeImage);
|
|
|
|
+ CombineCommand = new RelayCommand(Combine);
|
|
|
|
+ ClearHistoryCommand = new RelayCommand(ClearHistory);
|
|
|
|
+ CreateMaskCommand = new RelayCommand(CreateMask);
|
|
|
|
+ DeleteMaskCommand = new RelayCommand(DeleteMask);
|
|
|
|
+ ToggleLockTransparencyCommand = new RelayCommand(ToggleLockTransparency);
|
|
|
|
+ PasteImageCommand = new RelayCommand(PasteImage);
|
|
|
|
+ CreateReferenceLayerCommand = new RelayCommand(CreateReferenceLayer);
|
|
|
|
+ ApplyTransformCommand = new RelayCommand(ApplyTransform);
|
|
|
|
+ DragSymmetryCommand = new RelayCommand(DragSymmetry);
|
|
|
|
+ EndDragSymmetryCommand = new RelayCommand(EndDragSymmetry);
|
|
|
|
+ ClipToMemberBelowCommand = new RelayCommand(ClipToMemberBelow);
|
|
|
|
+ ApplyMaskCommand = new RelayCommand(ApplyMask);
|
|
|
|
+ TransformSelectionPathCommand = new RelayCommand(TransformSelectionPath);
|
|
|
|
+ TransformSelectedAreaCommand = new RelayCommand(TransformSelectedArea);*/
|
|
|
|
+
|
|
|
|
+ foreach (var bitmap in Bitmaps)
|
|
|
|
+ {
|
|
|
|
+ var surface = SKSurface.Create(
|
|
|
|
+ new SKImageInfo(bitmap.Value.PixelWidth, bitmap.Value.PixelHeight, SKColorType.Bgra8888, SKAlphaType.Premul, SKColorSpace.CreateSrgb()),
|
|
|
|
+ bitmap.Value.BackBuffer, bitmap.Value.BackBufferStride);
|
|
|
|
+ Surfaces[bitmap.Key] = surface;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var previewSize = StructureMemberViewModel.CalculatePreviewSize(SizeBindable);
|
|
|
|
+ PreviewBitmap = new WriteableBitmap(previewSize.X, previewSize.Y, 96, 96, PixelFormats.Pbgra32, null);
|
|
|
|
+ PreviewSurface = SKSurface.Create(new SKImageInfo(previewSize.X, previewSize.Y, SKColorType.Bgra8888), PreviewBitmap.BackBuffer, PreviewBitmap.BackBufferStride);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public void SetSize(VecI size)
|
|
public void SetSize(VecI size)
|
|
{
|
|
{
|
|
this.size = size;
|
|
this.size = size;
|
|
@@ -116,33 +161,43 @@ internal class DocumentViewModel : NotifyableObject
|
|
}
|
|
}
|
|
|
|
|
|
#region Symmetry
|
|
#region Symmetry
|
|
-
|
|
|
|
|
|
+
|
|
public void SetVerticalSymmetryAxisEnabled(bool verticalSymmetryAxisEnabled)
|
|
public void SetVerticalSymmetryAxisEnabled(bool verticalSymmetryAxisEnabled)
|
|
{
|
|
{
|
|
this.verticalSymmetryAxisEnabled = verticalSymmetryAxisEnabled;
|
|
this.verticalSymmetryAxisEnabled = verticalSymmetryAxisEnabled;
|
|
RaisePropertyChanged(nameof(VerticalSymmetryAxisEnabledBindable));
|
|
RaisePropertyChanged(nameof(VerticalSymmetryAxisEnabledBindable));
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public void SetHorizontalSymmetryAxisEnabled(bool horizontalSymmetryAxisEnabled)
|
|
public void SetHorizontalSymmetryAxisEnabled(bool horizontalSymmetryAxisEnabled)
|
|
{
|
|
{
|
|
this.horizontalSymmetryAxisEnabled = horizontalSymmetryAxisEnabled;
|
|
this.horizontalSymmetryAxisEnabled = horizontalSymmetryAxisEnabled;
|
|
RaisePropertyChanged(nameof(HorizontalSymmetryAxisEnabledBindable));
|
|
RaisePropertyChanged(nameof(HorizontalSymmetryAxisEnabledBindable));
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public void SetVerticalSymmetryAxisX(int verticalSymmetryAxisX)
|
|
public void SetVerticalSymmetryAxisX(int verticalSymmetryAxisX)
|
|
{
|
|
{
|
|
this.verticalSymmetryAxisX = verticalSymmetryAxisX;
|
|
this.verticalSymmetryAxisX = verticalSymmetryAxisX;
|
|
RaisePropertyChanged(nameof(VerticalSymmetryAxisXBindable));
|
|
RaisePropertyChanged(nameof(VerticalSymmetryAxisXBindable));
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public void SetHorizontalSymmetryAxisY(int horizontalSymmetryAxisY)
|
|
public void SetHorizontalSymmetryAxisY(int horizontalSymmetryAxisY)
|
|
{
|
|
{
|
|
this.horizontalSymmetryAxisY = horizontalSymmetryAxisY;
|
|
this.horizontalSymmetryAxisY = horizontalSymmetryAxisY;
|
|
RaisePropertyChanged(nameof(HorizontalSymmetryAxisYBindable));
|
|
RaisePropertyChanged(nameof(HorizontalSymmetryAxisYBindable));
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
#endregion
|
|
#endregion
|
|
-
|
|
|
|
|
|
+
|
|
|
|
+ public void AddOrUpdateViewport(ViewportInfo info)
|
|
|
|
+ {
|
|
|
|
+ //Helpers.ActionAccumulator.AddActions(new RefreshViewport_PassthroughAction(info));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void RemoveViewport(Guid viewportGuid)
|
|
|
|
+ {
|
|
|
|
+ //Helpers.ActionAccumulator.AddActions(new RemoveViewport_PassthroughAction(viewportGuid));
|
|
|
|
+ }
|
|
|
|
+
|
|
public void SetSelectionPath(SKPath selectionPath)
|
|
public void SetSelectionPath(SKPath selectionPath)
|
|
{
|
|
{
|
|
(var toDispose, this.selectionPath) = (this.selectionPath, selectionPath);
|
|
(var toDispose, this.selectionPath) = (this.selectionPath, selectionPath);
|