|
@@ -1,4 +1,5 @@
|
|
using System;
|
|
using System;
|
|
|
|
+using System.Buffers;
|
|
using System.Collections.ObjectModel;
|
|
using System.Collections.ObjectModel;
|
|
using System.IO;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Linq;
|
|
@@ -8,8 +9,10 @@ using System.Windows.Media.Imaging;
|
|
using PixiEditor.Helpers;
|
|
using PixiEditor.Helpers;
|
|
using PixiEditor.Models.Controllers;
|
|
using PixiEditor.Models.Controllers;
|
|
using PixiEditor.Models.Enums;
|
|
using PixiEditor.Models.Enums;
|
|
|
|
+using PixiEditor.Models.IO;
|
|
using PixiEditor.Models.Layers;
|
|
using PixiEditor.Models.Layers;
|
|
using PixiEditor.Models.Position;
|
|
using PixiEditor.Models.Position;
|
|
|
|
+using PixiEditor.ViewModels;
|
|
|
|
|
|
namespace PixiEditor.Models.DataHolders
|
|
namespace PixiEditor.Models.DataHolders
|
|
{
|
|
{
|
|
@@ -23,6 +26,8 @@ namespace PixiEditor.Models.DataHolders
|
|
{
|
|
{
|
|
Width = width;
|
|
Width = width;
|
|
Height = height;
|
|
Height = height;
|
|
|
|
+ RequestCloseDocumentCommand = new RelayCommand(RequestCloseDocument);
|
|
|
|
+ UndoManager = new UndoManager();
|
|
DocumentSizeChanged?.Invoke(this, new DocumentSizeChangedEventArgs(0, 0, width, height));
|
|
DocumentSizeChanged?.Invoke(this, new DocumentSizeChangedEventArgs(0, 0, width, height));
|
|
}
|
|
}
|
|
|
|
|
|
@@ -30,6 +35,8 @@ namespace PixiEditor.Models.DataHolders
|
|
|
|
|
|
public event EventHandler<LayersChangedEventArgs> LayersChanged;
|
|
public event EventHandler<LayersChangedEventArgs> LayersChanged;
|
|
|
|
|
|
|
|
+ public RelayCommand RequestCloseDocumentCommand { get; set; }
|
|
|
|
+
|
|
private string documentFilePath = string.Empty;
|
|
private string documentFilePath = string.Empty;
|
|
|
|
|
|
public string DocumentFilePath
|
|
public string DocumentFilePath
|
|
@@ -82,6 +89,20 @@ namespace PixiEditor.Models.DataHolders
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private Selection selection = new Selection(Array.Empty<Coordinates>());
|
|
|
|
+
|
|
|
|
+ public Selection ActiveSelection
|
|
|
|
+ {
|
|
|
|
+ get => selection;
|
|
|
|
+ set
|
|
|
|
+ {
|
|
|
|
+ selection = value;
|
|
|
|
+ RaisePropertyChanged("ActiveSelection");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public UndoManager UndoManager { get; set; }
|
|
|
|
+
|
|
public ObservableCollection<Layer> Layers { get; set; } = new ObservableCollection<Layer>();
|
|
public ObservableCollection<Layer> Layers { get; set; } = new ObservableCollection<Layer>();
|
|
|
|
|
|
public Layer ActiveLayer => Layers.Count > 0 ? Layers[ActiveLayerIndex] : null;
|
|
public Layer ActiveLayer => Layers.Count > 0 ? Layers[ActiveLayerIndex] : null;
|
|
@@ -97,6 +118,24 @@ namespace PixiEditor.Models.DataHolders
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ public void SaveWithDialog()
|
|
|
|
+ {
|
|
|
|
+ bool savedSuccessfully = Exporter.SaveAsEditableFileWithDialog(this, out string path);
|
|
|
|
+ DocumentFilePath = path;
|
|
|
|
+ ChangesSaved = savedSuccessfully;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void Save()
|
|
|
|
+ {
|
|
|
|
+ Save(DocumentFilePath);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void Save(string path)
|
|
|
|
+ {
|
|
|
|
+ DocumentFilePath = Exporter.SaveAsEditableFile(this, path);
|
|
|
|
+ ChangesSaved = true;
|
|
|
|
+ }
|
|
|
|
+
|
|
public ObservableCollection<Color> Swatches { get; set; } = new ObservableCollection<Color>();
|
|
public ObservableCollection<Color> Swatches { get; set; } = new ObservableCollection<Color>();
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -247,6 +286,9 @@ namespace PixiEditor.Models.DataHolders
|
|
"Clip canvas"));
|
|
"Clip canvas"));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ /// <summary>
|
|
|
|
+ /// Centers content inside document.
|
|
|
|
+ /// </summary>
|
|
public void CenterContent()
|
|
public void CenterContent()
|
|
{
|
|
{
|
|
DoubleCords points = GetEdgePoints();
|
|
DoubleCords points = GetEdgePoints();
|
|
@@ -277,6 +319,11 @@ namespace PixiEditor.Models.DataHolders
|
|
"Center content"));
|
|
"Center content"));
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ private void RequestCloseDocument(object parameter)
|
|
|
|
+ {
|
|
|
|
+ ViewModelMain.Current.DocumentSubViewModel.RequestCloseDocument(this);
|
|
|
|
+ }
|
|
|
|
+
|
|
private int GetOffsetXForAnchor(int srcWidth, int destWidth, AnchorPoint anchor)
|
|
private int GetOffsetXForAnchor(int srcWidth, int destWidth, AnchorPoint anchor)
|
|
{
|
|
{
|
|
if (anchor.HasFlag(AnchorPoint.Center))
|
|
if (anchor.HasFlag(AnchorPoint.Center))
|