|
@@ -10,7 +10,6 @@ using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows;
|
|
using System.Windows.Input;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media;
|
|
-using System.Windows.Media.Imaging;
|
|
|
|
using Microsoft.Win32;
|
|
using Microsoft.Win32;
|
|
using PixiEditor.Helpers;
|
|
using PixiEditor.Helpers;
|
|
using PixiEditor.Models.Controllers;
|
|
using PixiEditor.Models.Controllers;
|
|
@@ -30,25 +29,139 @@ namespace PixiEditor.ViewModels
|
|
public class ViewModelMain : ViewModelBase
|
|
public class ViewModelMain : ViewModelBase
|
|
{
|
|
{
|
|
private const string ConfirmationDialogMessage = "Document was modified. Do you want to save changes?";
|
|
private const string ConfirmationDialogMessage = "Document was modified. Do you want to save changes?";
|
|
|
|
+ private Tool lastActionTool;
|
|
|
|
|
|
- private Color _primaryColor = Colors.Black;
|
|
|
|
|
|
|
|
- private bool _recenterZoombox;
|
|
|
|
|
|
+ private double mouseXonCanvas;
|
|
|
|
|
|
- private Color _secondaryColor = Colors.White;
|
|
|
|
|
|
+ private double mouseYonCanvas;
|
|
|
|
|
|
- private Selection _selection;
|
|
|
|
|
|
+ private Color primaryColor = Colors.Black;
|
|
|
|
|
|
- private Cursor _toolCursor;
|
|
|
|
|
|
+ private bool recenterZoombox;
|
|
|
|
|
|
- private LayerChange[] _undoChanges;
|
|
|
|
|
|
+ private bool restoreToolOnKeyUp;
|
|
|
|
|
|
- private bool _unsavedDocumentModified;
|
|
|
|
|
|
+ private Color secondaryColor = Colors.White;
|
|
|
|
+
|
|
|
|
+ private Selection selection;
|
|
|
|
+
|
|
|
|
+ private Cursor toolCursor;
|
|
|
|
+
|
|
|
|
+ private LayerChange[] undoChanges;
|
|
|
|
+
|
|
|
|
+ private bool unsavedDocumentModified;
|
|
|
|
+
|
|
|
|
+ private bool updateReadyToInstall;
|
|
|
|
+
|
|
|
|
+ private string versionText;
|
|
|
|
+
|
|
|
|
+ private double zoomPercentage = 100;
|
|
|
|
+
|
|
|
|
+ public ViewModelMain()
|
|
|
|
+ {
|
|
|
|
+ BitmapManager = new BitmapManager();
|
|
|
|
+ BitmapManager.BitmapOperations.BitmapChanged += BitmapUtility_BitmapChanged;
|
|
|
|
+ BitmapManager.MouseController.StoppedRecordingChanges += MouseController_StoppedRecordingChanges;
|
|
|
|
+ BitmapManager.DocumentChanged += BitmapManager_DocumentChanged;
|
|
|
|
+ ChangesController = new PixelChangesController();
|
|
|
|
+ SelectToolCommand = new RelayCommand(SetTool, DocumentIsNotNull);
|
|
|
|
+ OpenNewFilePopupCommand = new RelayCommand(OpenNewFilePopup);
|
|
|
|
+ MouseMoveCommand = new RelayCommand(MouseMove);
|
|
|
|
+ MouseDownCommand = new RelayCommand(MouseDown);
|
|
|
|
+ ExportFileCommand = new RelayCommand(ExportFile, CanSave);
|
|
|
|
+ UndoCommand = new RelayCommand(Undo, CanUndo);
|
|
|
|
+ RedoCommand = new RelayCommand(Redo, CanRedo);
|
|
|
|
+ OpenFileCommand = new RelayCommand(Open);
|
|
|
|
+ SetActiveLayerCommand = new RelayCommand(SetActiveLayer);
|
|
|
|
+ NewLayerCommand = new RelayCommand(NewLayer, CanCreateNewLayer);
|
|
|
|
+ DeleteLayerCommand = new RelayCommand(DeleteLayer, CanDeleteLayer);
|
|
|
|
+ MoveToBackCommand = new RelayCommand(MoveLayerToBack, CanMoveToBack);
|
|
|
|
+ MoveToFrontCommand = new RelayCommand(MoveLayerToFront, CanMoveToFront);
|
|
|
|
+ SwapColorsCommand = new RelayCommand(SwapColors);
|
|
|
|
+ KeyDownCommand = new RelayCommand(KeyDown);
|
|
|
|
+ KeyUpCommand = new RelayCommand(KeyUp);
|
|
|
|
+ RenameLayerCommand = new RelayCommand(RenameLayer);
|
|
|
|
+ DeselectCommand = new RelayCommand(Deselect, SelectionIsNotEmpty);
|
|
|
|
+ SelectAllCommand = new RelayCommand(SelectAll, CanSelectAll);
|
|
|
|
+ CopyCommand = new RelayCommand(Copy, SelectionIsNotEmpty);
|
|
|
|
+ DuplicateCommand = new RelayCommand(Duplicate, SelectionIsNotEmpty);
|
|
|
|
+ CutCommand = new RelayCommand(Cut, SelectionIsNotEmpty);
|
|
|
|
+ PasteCommand = new RelayCommand(Paste, CanPaste);
|
|
|
|
+ ClipCanvasCommand = new RelayCommand(ClipCanvas, DocumentIsNotNull);
|
|
|
|
+ DeletePixelsCommand = new RelayCommand(DeletePixels, SelectionIsNotEmpty);
|
|
|
|
+ OpenResizePopupCommand = new RelayCommand(OpenResizePopup, DocumentIsNotNull);
|
|
|
|
+ SelectColorCommand = new RelayCommand(SelectColor);
|
|
|
|
+ RemoveSwatchCommand = new RelayCommand(RemoveSwatch);
|
|
|
|
+ SaveDocumentCommand = new RelayCommand(SaveDocument, DocumentIsNotNull);
|
|
|
|
+ OnStartupCommand = new RelayCommand(OnStartup);
|
|
|
|
+ CloseWindowCommand = new RelayCommand(CloseWindow);
|
|
|
|
+ CenterContentCommand = new RelayCommand(CenterContent, DocumentIsNotNull);
|
|
|
|
+ OpenHyperlinkCommand = new RelayCommand(OpenHyperlink);
|
|
|
|
+ ZoomCommand = new RelayCommand(ZoomViewport);
|
|
|
|
+ ChangeToolSizeCommand = new RelayCommand(ChangeToolSize);
|
|
|
|
+ RestartApplicationCommand = new RelayCommand(RestartApplication);
|
|
|
|
+ ToolSet = new ObservableCollection<Tool>
|
|
|
|
+ {
|
|
|
|
+ new MoveTool(), new PenTool(), new SelectTool(), new FloodFill(), new LineTool(),
|
|
|
|
+ new CircleTool(), new RectangleTool(), new EraserTool(), new ColorPickerTool(), new BrightnessTool(),
|
|
|
|
+ new ZoomTool()
|
|
|
|
+ };
|
|
|
|
+ ShortcutController = new ShortcutController
|
|
|
|
+ {
|
|
|
|
+ Shortcuts = new List<Shortcut>
|
|
|
|
+ {
|
|
|
|
+ //Tools
|
|
|
|
+ new Shortcut(Key.B, SelectToolCommand, ToolType.Pen),
|
|
|
|
+ new Shortcut(Key.E, SelectToolCommand, ToolType.Eraser),
|
|
|
|
+ new Shortcut(Key.O, SelectToolCommand, ToolType.ColorPicker),
|
|
|
|
+ new Shortcut(Key.R, SelectToolCommand, ToolType.Rectangle),
|
|
|
|
+ new Shortcut(Key.C, SelectToolCommand, ToolType.Circle),
|
|
|
|
+ new Shortcut(Key.L, SelectToolCommand, ToolType.Line),
|
|
|
|
+ new Shortcut(Key.G, SelectToolCommand, ToolType.Bucket),
|
|
|
|
+ new Shortcut(Key.U, SelectToolCommand, ToolType.Brightness),
|
|
|
|
+ new Shortcut(Key.V, SelectToolCommand, ToolType.Move),
|
|
|
|
+ new Shortcut(Key.M, SelectToolCommand, ToolType.Select),
|
|
|
|
+ new Shortcut(Key.Z, SelectToolCommand, ToolType.Zoom),
|
|
|
|
+ new Shortcut(Key.OemPlus, ZoomCommand, 115),
|
|
|
|
+ new Shortcut(Key.OemMinus, ZoomCommand, 85),
|
|
|
|
+ new Shortcut(Key.OemOpenBrackets, ChangeToolSizeCommand, -1),
|
|
|
|
+ new Shortcut(Key.OemCloseBrackets, ChangeToolSizeCommand, 1),
|
|
|
|
+ //Editor
|
|
|
|
+ new Shortcut(Key.X, SwapColorsCommand),
|
|
|
|
+ new Shortcut(Key.Y, RedoCommand, modifier: ModifierKeys.Control),
|
|
|
|
+ new Shortcut(Key.Z, UndoCommand, modifier: ModifierKeys.Control),
|
|
|
|
+ new Shortcut(Key.D, DeselectCommand, modifier: ModifierKeys.Control),
|
|
|
|
+ new Shortcut(Key.A, SelectAllCommand, modifier: ModifierKeys.Control),
|
|
|
|
+ new Shortcut(Key.C, CopyCommand, modifier: ModifierKeys.Control),
|
|
|
|
+ new Shortcut(Key.V, PasteCommand, modifier: ModifierKeys.Control),
|
|
|
|
+ new Shortcut(Key.J, DuplicateCommand, modifier: ModifierKeys.Control),
|
|
|
|
+ new Shortcut(Key.X, CutCommand, modifier: ModifierKeys.Control),
|
|
|
|
+ new Shortcut(Key.Delete, DeletePixelsCommand),
|
|
|
|
+ new Shortcut(Key.I, OpenResizePopupCommand, modifier: ModifierKeys.Control | ModifierKeys.Shift),
|
|
|
|
+ new Shortcut(Key.C, OpenResizePopupCommand, "canvas", ModifierKeys.Control | ModifierKeys.Shift),
|
|
|
|
+ new Shortcut(Key.F11, SystemCommands.MaximizeWindowCommand),
|
|
|
|
+ //File
|
|
|
|
+ new Shortcut(Key.O, OpenFileCommand, modifier: ModifierKeys.Control),
|
|
|
|
+ new Shortcut(Key.S, ExportFileCommand,
|
|
|
|
+ modifier: ModifierKeys.Control | ModifierKeys.Shift | ModifierKeys.Alt),
|
|
|
|
+ new Shortcut(Key.S, SaveDocumentCommand, modifier: ModifierKeys.Control),
|
|
|
|
+ new Shortcut(Key.S, SaveDocumentCommand, "AsNew", ModifierKeys.Control | ModifierKeys.Shift),
|
|
|
|
+ new Shortcut(Key.N, OpenNewFilePopupCommand, modifier: ModifierKeys.Control)
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+ UndoManager.SetMainRoot(this);
|
|
|
|
+ SetActiveTool(ToolType.Move);
|
|
|
|
+ BitmapManager.PrimaryColor = PrimaryColor;
|
|
|
|
+ ActiveSelection = new Selection(Array.Empty<Coordinates>());
|
|
|
|
+ Current = this;
|
|
|
|
+ InitUpdateChecker();
|
|
|
|
+ }
|
|
|
|
|
|
public Action CloseAction { get; set; }
|
|
public Action CloseAction { get; set; }
|
|
|
|
|
|
public static ViewModelMain Current { get; set; }
|
|
public static ViewModelMain Current { get; set; }
|
|
- public RelayCommand SelectToolCommand { get; set; } //Command that handles tool switching
|
|
|
|
|
|
+ public RelayCommand SelectToolCommand { get; set; } //Command that handles tool switching
|
|
public RelayCommand OpenNewFilePopupCommand { get; set; } //Command that generates draw area
|
|
public RelayCommand OpenNewFilePopupCommand { get; set; } //Command that generates draw area
|
|
public RelayCommand MouseMoveCommand { get; set; } //Command that is used to draw
|
|
public RelayCommand MouseMoveCommand { get; set; } //Command that is used to draw
|
|
public RelayCommand MouseDownCommand { get; set; }
|
|
public RelayCommand MouseDownCommand { get; set; }
|
|
@@ -57,6 +170,7 @@ namespace PixiEditor.ViewModels
|
|
public RelayCommand ExportFileCommand { get; set; } //Command that is used to save file
|
|
public RelayCommand ExportFileCommand { get; set; } //Command that is used to save file
|
|
public RelayCommand UndoCommand { get; set; }
|
|
public RelayCommand UndoCommand { get; set; }
|
|
public RelayCommand RedoCommand { get; set; }
|
|
public RelayCommand RedoCommand { get; set; }
|
|
|
|
+
|
|
public RelayCommand OpenFileCommand { get; set; }
|
|
public RelayCommand OpenFileCommand { get; set; }
|
|
public RelayCommand SetActiveLayerCommand { get; set; }
|
|
public RelayCommand SetActiveLayerCommand { get; set; }
|
|
public RelayCommand NewLayerCommand { get; set; }
|
|
public RelayCommand NewLayerCommand { get; set; }
|
|
@@ -85,39 +199,32 @@ namespace PixiEditor.ViewModels
|
|
public RelayCommand ChangeToolSizeCommand { get; set; }
|
|
public RelayCommand ChangeToolSizeCommand { get; set; }
|
|
public RelayCommand RestartApplicationCommand { get; set; }
|
|
public RelayCommand RestartApplicationCommand { get; set; }
|
|
|
|
|
|
-
|
|
|
|
- private double _mouseXonCanvas;
|
|
|
|
-
|
|
|
|
- private double _mouseYonCanvas;
|
|
|
|
-
|
|
|
|
- public double MouseXOnCanvas //Mouse X coordinate relative to canvas
|
|
|
|
|
|
+ public double MouseXOnCanvas // Mouse X coordinate relative to canvas
|
|
{
|
|
{
|
|
- get => _mouseXonCanvas;
|
|
|
|
|
|
+ get => mouseXonCanvas;
|
|
set
|
|
set
|
|
{
|
|
{
|
|
- _mouseXonCanvas = value;
|
|
|
|
|
|
+ mouseXonCanvas = value;
|
|
RaisePropertyChanged("MouseXOnCanvas");
|
|
RaisePropertyChanged("MouseXOnCanvas");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public double MouseYOnCanvas //Mouse Y coordinate relative to canvas
|
|
|
|
|
|
+ public double MouseYOnCanvas // Mouse Y coordinate relative to canvas
|
|
{
|
|
{
|
|
- get => _mouseYonCanvas;
|
|
|
|
|
|
+ get => mouseYonCanvas;
|
|
set
|
|
set
|
|
{
|
|
{
|
|
- _mouseYonCanvas = value;
|
|
|
|
|
|
+ mouseYonCanvas = value;
|
|
RaisePropertyChanged("MouseYOnCanvas");
|
|
RaisePropertyChanged("MouseYOnCanvas");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private string _versionText;
|
|
|
|
-
|
|
|
|
public string VersionText
|
|
public string VersionText
|
|
{
|
|
{
|
|
- get => _versionText;
|
|
|
|
|
|
+ get => versionText;
|
|
set
|
|
set
|
|
{
|
|
{
|
|
- _versionText = value;
|
|
|
|
|
|
+ versionText = value;
|
|
RaisePropertyChanged(nameof(VersionText));
|
|
RaisePropertyChanged(nameof(VersionText));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -125,22 +232,22 @@ namespace PixiEditor.ViewModels
|
|
|
|
|
|
public bool RecenterZoombox
|
|
public bool RecenterZoombox
|
|
{
|
|
{
|
|
- get => _recenterZoombox;
|
|
|
|
|
|
+ get => recenterZoombox;
|
|
set
|
|
set
|
|
{
|
|
{
|
|
- _recenterZoombox = value;
|
|
|
|
|
|
+ recenterZoombox = value;
|
|
RaisePropertyChanged("RecenterZoombox");
|
|
RaisePropertyChanged("RecenterZoombox");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public Color PrimaryColor //Primary color, hooked with left mouse button
|
|
public Color PrimaryColor //Primary color, hooked with left mouse button
|
|
{
|
|
{
|
|
- get => _primaryColor;
|
|
|
|
|
|
+ get => primaryColor;
|
|
set
|
|
set
|
|
{
|
|
{
|
|
- if (_primaryColor != value)
|
|
|
|
|
|
+ if (primaryColor != value)
|
|
{
|
|
{
|
|
- _primaryColor = value;
|
|
|
|
|
|
+ primaryColor = value;
|
|
BitmapManager.PrimaryColor = value;
|
|
BitmapManager.PrimaryColor = value;
|
|
RaisePropertyChanged("PrimaryColor");
|
|
RaisePropertyChanged("PrimaryColor");
|
|
}
|
|
}
|
|
@@ -149,12 +256,12 @@ namespace PixiEditor.ViewModels
|
|
|
|
|
|
public Color SecondaryColor
|
|
public Color SecondaryColor
|
|
{
|
|
{
|
|
- get => _secondaryColor;
|
|
|
|
|
|
+ get => secondaryColor;
|
|
set
|
|
set
|
|
{
|
|
{
|
|
- if (_secondaryColor != value)
|
|
|
|
|
|
+ if (secondaryColor != value)
|
|
{
|
|
{
|
|
- _secondaryColor = value;
|
|
|
|
|
|
+ secondaryColor = value;
|
|
RaisePropertyChanged("SecondaryColor");
|
|
RaisePropertyChanged("SecondaryColor");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -164,45 +271,41 @@ namespace PixiEditor.ViewModels
|
|
|
|
|
|
public LayerChange[] UndoChanges //This acts like UndoManager process, but it was implemented before process system, so it can be transformed into it
|
|
public LayerChange[] UndoChanges //This acts like UndoManager process, but it was implemented before process system, so it can be transformed into it
|
|
{
|
|
{
|
|
- get => _undoChanges;
|
|
|
|
|
|
+ get => undoChanges;
|
|
set
|
|
set
|
|
{
|
|
{
|
|
- _undoChanges = value;
|
|
|
|
- for (int i = 0; i < value.Length; i++)
|
|
|
|
|
|
+ undoChanges = value;
|
|
|
|
+ for (var i = 0; i < value.Length; i++)
|
|
BitmapManager.ActiveDocument.Layers[value[i].LayerIndex].SetPixels(value[i].PixelChanges);
|
|
BitmapManager.ActiveDocument.Layers[value[i].LayerIndex].SetPixels(value[i].PixelChanges);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public Cursor ToolCursor
|
|
public Cursor ToolCursor
|
|
{
|
|
{
|
|
- get => _toolCursor;
|
|
|
|
|
|
+ get => toolCursor;
|
|
set
|
|
set
|
|
{
|
|
{
|
|
- _toolCursor = value;
|
|
|
|
|
|
+ toolCursor = value;
|
|
RaisePropertyChanged("ToolCursor");
|
|
RaisePropertyChanged("ToolCursor");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private double _zoomPercentage = 100;
|
|
|
|
-
|
|
|
|
public double ZoomPercentage
|
|
public double ZoomPercentage
|
|
{
|
|
{
|
|
- get { return _zoomPercentage; }
|
|
|
|
- set
|
|
|
|
|
|
+ get => zoomPercentage;
|
|
|
|
+ set
|
|
{
|
|
{
|
|
- _zoomPercentage = value;
|
|
|
|
|
|
+ zoomPercentage = value;
|
|
RaisePropertyChanged(nameof(ZoomPercentage));
|
|
RaisePropertyChanged(nameof(ZoomPercentage));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private bool _updateReadyToInstall = false;
|
|
|
|
-
|
|
|
|
public bool UpdateReadyToInstall
|
|
public bool UpdateReadyToInstall
|
|
{
|
|
{
|
|
- get => _updateReadyToInstall;
|
|
|
|
|
|
+ get => updateReadyToInstall;
|
|
set
|
|
set
|
|
{
|
|
{
|
|
- _updateReadyToInstall = value;
|
|
|
|
|
|
+ updateReadyToInstall = value;
|
|
RaisePropertyChanged(nameof(UpdateReadyToInstall));
|
|
RaisePropertyChanged(nameof(UpdateReadyToInstall));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -214,119 +317,16 @@ namespace PixiEditor.ViewModels
|
|
|
|
|
|
public Selection ActiveSelection
|
|
public Selection ActiveSelection
|
|
{
|
|
{
|
|
- get => _selection;
|
|
|
|
|
|
+ get => selection;
|
|
set
|
|
set
|
|
{
|
|
{
|
|
- _selection = value;
|
|
|
|
|
|
+ selection = value;
|
|
RaisePropertyChanged("ActiveSelection");
|
|
RaisePropertyChanged("ActiveSelection");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private bool _restoreToolOnKeyUp = false;
|
|
|
|
- private Tool _lastActionTool;
|
|
|
|
-
|
|
|
|
public UpdateChecker UpdateChecker { get; set; }
|
|
public UpdateChecker UpdateChecker { get; set; }
|
|
|
|
|
|
- public ViewModelMain()
|
|
|
|
- {
|
|
|
|
- BitmapManager = new BitmapManager();
|
|
|
|
- BitmapManager.BitmapOperations.BitmapChanged += BitmapUtility_BitmapChanged;
|
|
|
|
- BitmapManager.MouseController.StoppedRecordingChanges += MouseController_StoppedRecordingChanges;
|
|
|
|
- BitmapManager.DocumentChanged += BitmapManager_DocumentChanged;
|
|
|
|
- ChangesController = new PixelChangesController();
|
|
|
|
- SelectToolCommand = new RelayCommand(SetTool, DocumentIsNotNull);
|
|
|
|
- OpenNewFilePopupCommand = new RelayCommand(OpenNewFilePopup);
|
|
|
|
- MouseMoveCommand = new RelayCommand(MouseMove);
|
|
|
|
- MouseDownCommand = new RelayCommand(MouseDown);
|
|
|
|
- ExportFileCommand = new RelayCommand(ExportFile, CanSave);
|
|
|
|
- UndoCommand = new RelayCommand(Undo, CanUndo);
|
|
|
|
- RedoCommand = new RelayCommand(Redo, CanRedo);
|
|
|
|
- OpenFileCommand = new RelayCommand(Open);
|
|
|
|
- SetActiveLayerCommand = new RelayCommand(SetActiveLayer);
|
|
|
|
- NewLayerCommand = new RelayCommand(NewLayer, CanCreateNewLayer);
|
|
|
|
- DeleteLayerCommand = new RelayCommand(DeleteLayer, CanDeleteLayer);
|
|
|
|
- MoveToBackCommand = new RelayCommand(MoveLayerToBack, CanMoveToBack);
|
|
|
|
- MoveToFrontCommand = new RelayCommand(MoveLayerToFront, CanMoveToFront);
|
|
|
|
- SwapColorsCommand = new RelayCommand(SwapColors);
|
|
|
|
- KeyDownCommand = new RelayCommand(KeyDown);
|
|
|
|
- KeyUpCommand = new RelayCommand(KeyUp);
|
|
|
|
- RenameLayerCommand = new RelayCommand(RenameLayer);
|
|
|
|
- DeselectCommand = new RelayCommand(Deselect, SelectionIsNotEmpty);
|
|
|
|
- SelectAllCommand = new RelayCommand(SelectAll, CanSelectAll);
|
|
|
|
- CopyCommand = new RelayCommand(Copy, SelectionIsNotEmpty);
|
|
|
|
- DuplicateCommand = new RelayCommand(Duplicate, SelectionIsNotEmpty);
|
|
|
|
- CutCommand = new RelayCommand(Cut, SelectionIsNotEmpty);
|
|
|
|
- PasteCommand = new RelayCommand(Paste, CanPaste);
|
|
|
|
- ClipCanvasCommand = new RelayCommand(ClipCanvas, DocumentIsNotNull);
|
|
|
|
- DeletePixelsCommand = new RelayCommand(DeletePixels, SelectionIsNotEmpty);
|
|
|
|
- OpenResizePopupCommand = new RelayCommand(OpenResizePopup, DocumentIsNotNull);
|
|
|
|
- SelectColorCommand = new RelayCommand(SelectColor);
|
|
|
|
- RemoveSwatchCommand = new RelayCommand(RemoveSwatch);
|
|
|
|
- SaveDocumentCommand = new RelayCommand(SaveDocument, DocumentIsNotNull);
|
|
|
|
- OnStartupCommand = new RelayCommand(OnStartup);
|
|
|
|
- CloseWindowCommand = new RelayCommand(CloseWindow);
|
|
|
|
- CenterContentCommand = new RelayCommand(CenterContent, DocumentIsNotNull);
|
|
|
|
- OpenHyperlinkCommand = new RelayCommand(OpenHyperlink);
|
|
|
|
- ZoomCommand = new RelayCommand(ZoomViewport);
|
|
|
|
- ChangeToolSizeCommand = new RelayCommand(ChangeToolSize);
|
|
|
|
- RestartApplicationCommand = new RelayCommand(RestartApplication);
|
|
|
|
- ToolSet = new ObservableCollection<Tool>
|
|
|
|
- {
|
|
|
|
- new MoveTool(), new PenTool(), new SelectTool(), new FloodFill(), new LineTool(),
|
|
|
|
- new CircleTool(), new RectangleTool(), new EraserTool(), new ColorPickerTool(), new BrightnessTool(),
|
|
|
|
- new ZoomTool()
|
|
|
|
- };
|
|
|
|
- ShortcutController = new ShortcutController
|
|
|
|
- {
|
|
|
|
- Shortcuts = new List<Shortcut>
|
|
|
|
- {
|
|
|
|
- //Tools
|
|
|
|
- new Shortcut(Key.B, SelectToolCommand, ToolType.Pen),
|
|
|
|
- new Shortcut(Key.E, SelectToolCommand, ToolType.Eraser),
|
|
|
|
- new Shortcut(Key.O, SelectToolCommand, ToolType.ColorPicker),
|
|
|
|
- new Shortcut(Key.R, SelectToolCommand, ToolType.Rectangle),
|
|
|
|
- new Shortcut(Key.C, SelectToolCommand, ToolType.Circle),
|
|
|
|
- new Shortcut(Key.L, SelectToolCommand, ToolType.Line),
|
|
|
|
- new Shortcut(Key.G, SelectToolCommand, ToolType.Bucket),
|
|
|
|
- new Shortcut(Key.U, SelectToolCommand, ToolType.Brightness),
|
|
|
|
- new Shortcut(Key.V, SelectToolCommand, ToolType.Move),
|
|
|
|
- new Shortcut(Key.M, SelectToolCommand, ToolType.Select),
|
|
|
|
- new Shortcut(Key.Z, SelectToolCommand, ToolType.Zoom),
|
|
|
|
- new Shortcut(Key.OemPlus, ZoomCommand, 115),
|
|
|
|
- new Shortcut(Key.OemMinus, ZoomCommand, 85),
|
|
|
|
- new Shortcut(Key.OemOpenBrackets, ChangeToolSizeCommand, -1),
|
|
|
|
- new Shortcut(Key.OemCloseBrackets, ChangeToolSizeCommand, 1),
|
|
|
|
- //Editor
|
|
|
|
- new Shortcut(Key.X, SwapColorsCommand),
|
|
|
|
- new Shortcut(Key.Y, RedoCommand, modifier: ModifierKeys.Control),
|
|
|
|
- new Shortcut(Key.Z, UndoCommand, modifier: ModifierKeys.Control),
|
|
|
|
- new Shortcut(Key.D, DeselectCommand, modifier: ModifierKeys.Control),
|
|
|
|
- new Shortcut(Key.A, SelectAllCommand, modifier: ModifierKeys.Control),
|
|
|
|
- new Shortcut(Key.C, CopyCommand, modifier: ModifierKeys.Control),
|
|
|
|
- new Shortcut(Key.V, PasteCommand, modifier: ModifierKeys.Control),
|
|
|
|
- new Shortcut(Key.J, DuplicateCommand, modifier: ModifierKeys.Control),
|
|
|
|
- new Shortcut(Key.X, CutCommand, modifier: ModifierKeys.Control),
|
|
|
|
- new Shortcut(Key.Delete, DeletePixelsCommand),
|
|
|
|
- new Shortcut(Key.I, OpenResizePopupCommand, modifier: ModifierKeys.Control | ModifierKeys.Shift),
|
|
|
|
- new Shortcut(Key.C, OpenResizePopupCommand, "canvas", ModifierKeys.Control | ModifierKeys.Shift),
|
|
|
|
- new Shortcut(Key.F11, SystemCommands.MaximizeWindowCommand),
|
|
|
|
- //File
|
|
|
|
- new Shortcut(Key.O, OpenFileCommand, modifier: ModifierKeys.Control),
|
|
|
|
- new Shortcut(Key.S, ExportFileCommand,
|
|
|
|
- modifier: ModifierKeys.Control | ModifierKeys.Shift | ModifierKeys.Alt),
|
|
|
|
- new Shortcut(Key.S, SaveDocumentCommand, modifier: ModifierKeys.Control),
|
|
|
|
- new Shortcut(Key.S, SaveDocumentCommand, "AsNew", ModifierKeys.Control | ModifierKeys.Shift),
|
|
|
|
- new Shortcut(Key.N, OpenNewFilePopupCommand, modifier: ModifierKeys.Control),
|
|
|
|
- }
|
|
|
|
- };
|
|
|
|
- UndoManager.SetMainRoot(this);
|
|
|
|
- SetActiveTool(ToolType.Move);
|
|
|
|
- BitmapManager.PrimaryColor = PrimaryColor;
|
|
|
|
- ActiveSelection = new Selection(Array.Empty<Coordinates>());
|
|
|
|
- Current = this;
|
|
|
|
- InitUpdateChecker();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
private void RestartApplication(object parameter)
|
|
private void RestartApplication(object parameter)
|
|
{
|
|
{
|
|
Process.Start(Path.Join(AppDomain.CurrentDomain.BaseDirectory, "PixiEditor.UpdateInstaller.exe"));
|
|
Process.Start(Path.Join(AppDomain.CurrentDomain.BaseDirectory, "PixiEditor.UpdateInstaller.exe"));
|
|
@@ -337,8 +337,8 @@ namespace PixiEditor.ViewModels
|
|
{
|
|
{
|
|
return await Task.Run(async () =>
|
|
return await Task.Run(async () =>
|
|
{
|
|
{
|
|
- bool updateAvailable = await UpdateChecker.CheckUpdateAvailable();
|
|
|
|
- bool updateFileDoesNotExists = !File.Exists($"update-{UpdateChecker.LatestReleaseInfo.TagName}.zip");
|
|
|
|
|
|
+ var updateAvailable = await UpdateChecker.CheckUpdateAvailable();
|
|
|
|
+ var updateFileDoesNotExists = !File.Exists($"update-{UpdateChecker.LatestReleaseInfo.TagName}.zip");
|
|
if (updateAvailable && updateFileDoesNotExists)
|
|
if (updateAvailable && updateFileDoesNotExists)
|
|
{
|
|
{
|
|
VersionText = "Downloading update...";
|
|
VersionText = "Downloading update...";
|
|
@@ -347,6 +347,7 @@ namespace PixiEditor.ViewModels
|
|
UpdateReadyToInstall = true;
|
|
UpdateReadyToInstall = true;
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
+
|
|
return false;
|
|
return false;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
@@ -354,33 +355,30 @@ namespace PixiEditor.ViewModels
|
|
private void InitUpdateChecker()
|
|
private void InitUpdateChecker()
|
|
{
|
|
{
|
|
var assembly = Assembly.GetExecutingAssembly();
|
|
var assembly = Assembly.GetExecutingAssembly();
|
|
- FileVersionInfo info = FileVersionInfo.GetVersionInfo(assembly.Location);
|
|
|
|
|
|
+ var info = FileVersionInfo.GetVersionInfo(assembly.Location);
|
|
UpdateChecker = new UpdateChecker(info.FileVersion);
|
|
UpdateChecker = new UpdateChecker(info.FileVersion);
|
|
VersionText = $"Version {info.FileVersion}";
|
|
VersionText = $"Version {info.FileVersion}";
|
|
}
|
|
}
|
|
|
|
|
|
private void ZoomViewport(object parameter)
|
|
private void ZoomViewport(object parameter)
|
|
{
|
|
{
|
|
- double zoom = (int)parameter;
|
|
|
|
|
|
+ double zoom = (int) parameter;
|
|
ZoomPercentage = zoom;
|
|
ZoomPercentage = zoom;
|
|
ZoomPercentage = 100;
|
|
ZoomPercentage = 100;
|
|
}
|
|
}
|
|
|
|
|
|
private void ChangeToolSize(object parameter)
|
|
private void ChangeToolSize(object parameter)
|
|
{
|
|
{
|
|
- int increment = (int)parameter;
|
|
|
|
- int newSize = BitmapManager.ToolSize + increment;
|
|
|
|
- if (newSize > 0)
|
|
|
|
- {
|
|
|
|
- BitmapManager.ToolSize = newSize;
|
|
|
|
- }
|
|
|
|
|
|
+ var increment = (int) parameter;
|
|
|
|
+ var newSize = BitmapManager.ToolSize + increment;
|
|
|
|
+ if (newSize > 0) BitmapManager.ToolSize = newSize;
|
|
}
|
|
}
|
|
|
|
|
|
private void OpenHyperlink(object parameter)
|
|
private void OpenHyperlink(object parameter)
|
|
{
|
|
{
|
|
if (parameter == null) return;
|
|
if (parameter == null) return;
|
|
- string url = (string) parameter;
|
|
|
|
- var processInfo = new ProcessStartInfo()
|
|
|
|
|
|
+ var url = (string) parameter;
|
|
|
|
+ var processInfo = new ProcessStartInfo
|
|
{
|
|
{
|
|
FileName = url,
|
|
FileName = url,
|
|
UseShellExecute = true
|
|
UseShellExecute = true
|
|
@@ -399,8 +397,8 @@ namespace PixiEditor.ViewModels
|
|
|
|
|
|
((CancelEventArgs) property).Cancel = true;
|
|
((CancelEventArgs) property).Cancel = true;
|
|
|
|
|
|
- ConfirmationType result = ConfirmationType.No;
|
|
|
|
- if (_unsavedDocumentModified)
|
|
|
|
|
|
+ var result = ConfirmationType.No;
|
|
|
|
+ if (unsavedDocumentModified)
|
|
{
|
|
{
|
|
result = ConfirmationDialog.Show(ConfirmationDialogMessage);
|
|
result = ConfirmationDialog.Show(ConfirmationDialogMessage);
|
|
if (result == ConfirmationType.Yes) SaveDocument(null);
|
|
if (result == ConfirmationType.Yes) SaveDocument(null);
|
|
@@ -413,13 +411,9 @@ namespace PixiEditor.ViewModels
|
|
{
|
|
{
|
|
var lastArg = Environment.GetCommandLineArgs().Last();
|
|
var lastArg = Environment.GetCommandLineArgs().Last();
|
|
if (Importer.IsSupportedFile(lastArg) && File.Exists(lastArg))
|
|
if (Importer.IsSupportedFile(lastArg) && File.Exists(lastArg))
|
|
- {
|
|
|
|
Open(lastArg);
|
|
Open(lastArg);
|
|
- }
|
|
|
|
else
|
|
else
|
|
- {
|
|
|
|
OpenNewFilePopup(null);
|
|
OpenNewFilePopup(null);
|
|
- }
|
|
|
|
await CheckForUpdate();
|
|
await CheckForUpdate();
|
|
}
|
|
}
|
|
|
|
|
|
@@ -430,7 +424,7 @@ namespace PixiEditor.ViewModels
|
|
|
|
|
|
private void Open(object property)
|
|
private void Open(object property)
|
|
{
|
|
{
|
|
- OpenFileDialog dialog = new OpenFileDialog
|
|
|
|
|
|
+ var dialog = new OpenFileDialog
|
|
{
|
|
{
|
|
Filter = "All Files|*.*|PixiEditor Files | *.pixi|PNG Files|*.png",
|
|
Filter = "All Files|*.*|PixiEditor Files | *.pixi|PNG Files|*.png",
|
|
DefaultExt = "pixi"
|
|
DefaultExt = "pixi"
|
|
@@ -445,17 +439,12 @@ namespace PixiEditor.ViewModels
|
|
|
|
|
|
private void Open(string path)
|
|
private void Open(string path)
|
|
{
|
|
{
|
|
- if (_unsavedDocumentModified)
|
|
|
|
|
|
+ if (unsavedDocumentModified)
|
|
{
|
|
{
|
|
var result = ConfirmationDialog.Show(ConfirmationDialogMessage);
|
|
var result = ConfirmationDialog.Show(ConfirmationDialogMessage);
|
|
if (result == ConfirmationType.Yes)
|
|
if (result == ConfirmationType.Yes)
|
|
- {
|
|
|
|
SaveDocument(null);
|
|
SaveDocument(null);
|
|
- }
|
|
|
|
- else if (result == ConfirmationType.Canceled)
|
|
|
|
- {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
|
|
+ else if (result == ConfirmationType.Canceled) return;
|
|
}
|
|
}
|
|
|
|
|
|
ResetProgramStateValues();
|
|
ResetProgramStateValues();
|
|
@@ -469,28 +458,28 @@ namespace PixiEditor.ViewModels
|
|
{
|
|
{
|
|
BitmapManager.ActiveDocument = Importer.ImportDocument(path);
|
|
BitmapManager.ActiveDocument = Importer.ImportDocument(path);
|
|
Exporter.SaveDocumentPath = path;
|
|
Exporter.SaveDocumentPath = path;
|
|
- _unsavedDocumentModified = false;
|
|
|
|
|
|
+ unsavedDocumentModified = false;
|
|
}
|
|
}
|
|
|
|
|
|
private void SaveDocument(object parameter)
|
|
private void SaveDocument(object parameter)
|
|
{
|
|
{
|
|
- bool paramIsAsNew = parameter != null && parameter.ToString()?.ToLower() == "asnew";
|
|
|
|
|
|
+ var paramIsAsNew = parameter != null && parameter.ToString()?.ToLower() == "asnew";
|
|
if (paramIsAsNew || Exporter.SaveDocumentPath == null)
|
|
if (paramIsAsNew || Exporter.SaveDocumentPath == null)
|
|
{
|
|
{
|
|
var saved = Exporter.SaveAsEditableFileWithDialog(BitmapManager.ActiveDocument, !paramIsAsNew);
|
|
var saved = Exporter.SaveAsEditableFileWithDialog(BitmapManager.ActiveDocument, !paramIsAsNew);
|
|
- _unsavedDocumentModified = _unsavedDocumentModified && !saved;
|
|
|
|
|
|
+ unsavedDocumentModified = unsavedDocumentModified && !saved;
|
|
}
|
|
}
|
|
else
|
|
else
|
|
{
|
|
{
|
|
Exporter.SaveAsEditableFile(BitmapManager.ActiveDocument, Exporter.SaveDocumentPath);
|
|
Exporter.SaveAsEditableFile(BitmapManager.ActiveDocument, Exporter.SaveDocumentPath);
|
|
- _unsavedDocumentModified = false;
|
|
|
|
|
|
+ unsavedDocumentModified = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
private void RemoveSwatch(object parameter)
|
|
private void RemoveSwatch(object parameter)
|
|
{
|
|
{
|
|
if (!(parameter is Color)) throw new ArgumentException();
|
|
if (!(parameter is Color)) throw new ArgumentException();
|
|
- Color color = (Color) parameter;
|
|
|
|
|
|
+ var color = (Color) parameter;
|
|
if (BitmapManager.ActiveDocument.Swatches.Contains(color))
|
|
if (BitmapManager.ActiveDocument.Swatches.Contains(color))
|
|
BitmapManager.ActiveDocument.Swatches.Remove(color);
|
|
BitmapManager.ActiveDocument.Swatches.Remove(color);
|
|
}
|
|
}
|
|
@@ -504,7 +493,7 @@ namespace PixiEditor.ViewModels
|
|
{
|
|
{
|
|
ActiveSelection = new Selection(Array.Empty<Coordinates>());
|
|
ActiveSelection = new Selection(Array.Empty<Coordinates>());
|
|
RecenterZoombox = !RecenterZoombox;
|
|
RecenterZoombox = !RecenterZoombox;
|
|
- _unsavedDocumentModified = true;
|
|
|
|
|
|
+ unsavedDocumentModified = true;
|
|
}
|
|
}
|
|
|
|
|
|
public void AddSwatch(Color color)
|
|
public void AddSwatch(Color color)
|
|
@@ -515,8 +504,8 @@ namespace PixiEditor.ViewModels
|
|
|
|
|
|
private void OpenResizePopup(object parameter)
|
|
private void OpenResizePopup(object parameter)
|
|
{
|
|
{
|
|
- bool isCanvasDialog = (string) parameter == "canvas";
|
|
|
|
- ResizeDocumentDialog dialog = new ResizeDocumentDialog(BitmapManager.ActiveDocument.Width,
|
|
|
|
|
|
+ var isCanvasDialog = (string) parameter == "canvas";
|
|
|
|
+ var dialog = new ResizeDocumentDialog(BitmapManager.ActiveDocument.Width,
|
|
BitmapManager.ActiveDocument.Height, isCanvasDialog);
|
|
BitmapManager.ActiveDocument.Height, isCanvasDialog);
|
|
if (dialog.ShowDialog())
|
|
if (dialog.ShowDialog())
|
|
{
|
|
{
|
|
@@ -570,7 +559,7 @@ namespace PixiEditor.ViewModels
|
|
|
|
|
|
public void SelectAll(object parameter)
|
|
public void SelectAll(object parameter)
|
|
{
|
|
{
|
|
- SelectTool select = new SelectTool();
|
|
|
|
|
|
+ var select = new SelectTool();
|
|
ActiveSelection.SetSelection(select.GetAllSelection(), SelectionType.New);
|
|
ActiveSelection.SetSelection(select.GetAllSelection(), SelectionType.New);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -606,29 +595,30 @@ namespace PixiEditor.ViewModels
|
|
|
|
|
|
private void KeyUp(object parameter)
|
|
private void KeyUp(object parameter)
|
|
{
|
|
{
|
|
- KeyEventArgs args = (KeyEventArgs)parameter;
|
|
|
|
- if (_restoreToolOnKeyUp && ShortcutController.LastShortcut != null && ShortcutController.LastShortcut.ShortcutKey == args.Key)
|
|
|
|
|
|
+ var args = (KeyEventArgs) parameter;
|
|
|
|
+ if (restoreToolOnKeyUp && ShortcutController.LastShortcut != null && ShortcutController.LastShortcut.ShortcutKey == args.Key)
|
|
{
|
|
{
|
|
- _restoreToolOnKeyUp = false;
|
|
|
|
- SetActiveTool(_lastActionTool);
|
|
|
|
|
|
+ restoreToolOnKeyUp = false;
|
|
|
|
+ SetActiveTool(lastActionTool);
|
|
ShortcutController.BlockShortcutExecution = false;
|
|
ShortcutController.BlockShortcutExecution = false;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public void KeyDown(object parameter)
|
|
public void KeyDown(object parameter)
|
|
{
|
|
{
|
|
- KeyEventArgs args = (KeyEventArgs)parameter;
|
|
|
|
- if (args.IsRepeat && !_restoreToolOnKeyUp && ShortcutController.LastShortcut != null && ShortcutController.LastShortcut.Command == SelectToolCommand)
|
|
|
|
|
|
+ var args = (KeyEventArgs) parameter;
|
|
|
|
+ if (args.IsRepeat && !restoreToolOnKeyUp && ShortcutController.LastShortcut != null && ShortcutController.LastShortcut.Command == SelectToolCommand)
|
|
{
|
|
{
|
|
- _restoreToolOnKeyUp = true;
|
|
|
|
|
|
+ restoreToolOnKeyUp = true;
|
|
ShortcutController.BlockShortcutExecution = true;
|
|
ShortcutController.BlockShortcutExecution = true;
|
|
}
|
|
}
|
|
|
|
+
|
|
ShortcutController.KeyPressed(args.Key, Keyboard.Modifiers);
|
|
ShortcutController.KeyPressed(args.Key, Keyboard.Modifiers);
|
|
}
|
|
}
|
|
|
|
|
|
private void MouseController_StoppedRecordingChanges(object sender, EventArgs e)
|
|
private void MouseController_StoppedRecordingChanges(object sender, EventArgs e)
|
|
{
|
|
{
|
|
- TriggerNewUndoChange(BitmapManager.SelectedTool);
|
|
|
|
|
|
+ TriggerNewUndoChange(BitmapManager.SelectedTool);
|
|
}
|
|
}
|
|
|
|
|
|
public void TriggerNewUndoChange(Tool toolUsed)
|
|
public void TriggerNewUndoChange(Tool toolUsed)
|
|
@@ -636,11 +626,11 @@ namespace PixiEditor.ViewModels
|
|
if (BitmapManager.IsOperationTool(toolUsed)
|
|
if (BitmapManager.IsOperationTool(toolUsed)
|
|
&& ((BitmapOperationTool) toolUsed).UseDefaultUndoMethod)
|
|
&& ((BitmapOperationTool) toolUsed).UseDefaultUndoMethod)
|
|
{
|
|
{
|
|
- Tuple<LayerChange, LayerChange>[] changes = ChangesController.PopChanges();
|
|
|
|
|
|
+ var changes = ChangesController.PopChanges();
|
|
if (changes != null && changes.Length > 0)
|
|
if (changes != null && changes.Length > 0)
|
|
{
|
|
{
|
|
- LayerChange[] newValues = changes.Select(x => x.Item1).ToArray();
|
|
|
|
- LayerChange[] oldValues = changes.Select(x => x.Item2).ToArray();
|
|
|
|
|
|
+ var newValues = changes.Select(x => x.Item1).ToArray();
|
|
|
|
+ var oldValues = changes.Select(x => x.Item2).ToArray();
|
|
UndoManager.AddUndoChange(new Change("UndoChanges", oldValues, newValues));
|
|
UndoManager.AddUndoChange(new Change("UndoChanges", oldValues, newValues));
|
|
toolUsed.AfterAddedUndo();
|
|
toolUsed.AfterAddedUndo();
|
|
}
|
|
}
|
|
@@ -651,7 +641,7 @@ namespace PixiEditor.ViewModels
|
|
{
|
|
{
|
|
ChangesController.AddChanges(new LayerChange(e.PixelsChanged, e.ChangedLayerIndex),
|
|
ChangesController.AddChanges(new LayerChange(e.PixelsChanged, e.ChangedLayerIndex),
|
|
new LayerChange(e.OldPixelsValues, e.ChangedLayerIndex));
|
|
new LayerChange(e.OldPixelsValues, e.ChangedLayerIndex));
|
|
- _unsavedDocumentModified = true;
|
|
|
|
|
|
+ unsavedDocumentModified = true;
|
|
if (BitmapManager.IsOperationTool())
|
|
if (BitmapManager.IsOperationTool())
|
|
AddSwatch(PrimaryColor);
|
|
AddSwatch(PrimaryColor);
|
|
}
|
|
}
|
|
@@ -665,14 +655,14 @@ namespace PixiEditor.ViewModels
|
|
|
|
|
|
public void MoveLayerToFront(object parameter)
|
|
public void MoveLayerToFront(object parameter)
|
|
{
|
|
{
|
|
- int oldIndex = (int) parameter;
|
|
|
|
|
|
+ var oldIndex = (int) parameter;
|
|
BitmapManager.ActiveDocument.Layers.Move(oldIndex, oldIndex + 1);
|
|
BitmapManager.ActiveDocument.Layers.Move(oldIndex, oldIndex + 1);
|
|
if (BitmapManager.ActiveDocument.ActiveLayerIndex == oldIndex) BitmapManager.SetActiveLayer(oldIndex + 1);
|
|
if (BitmapManager.ActiveDocument.ActiveLayerIndex == oldIndex) BitmapManager.SetActiveLayer(oldIndex + 1);
|
|
}
|
|
}
|
|
|
|
|
|
public void MoveLayerToBack(object parameter)
|
|
public void MoveLayerToBack(object parameter)
|
|
{
|
|
{
|
|
- int oldIndex = (int) parameter;
|
|
|
|
|
|
+ var oldIndex = (int) parameter;
|
|
BitmapManager.ActiveDocument.Layers.Move(oldIndex, oldIndex - 1);
|
|
BitmapManager.ActiveDocument.Layers.Move(oldIndex, oldIndex - 1);
|
|
if (BitmapManager.ActiveDocument.ActiveLayerIndex == oldIndex) BitmapManager.SetActiveLayer(oldIndex - 1);
|
|
if (BitmapManager.ActiveDocument.ActiveLayerIndex == oldIndex) BitmapManager.SetActiveLayer(oldIndex - 1);
|
|
}
|
|
}
|
|
@@ -704,22 +694,22 @@ namespace PixiEditor.ViewModels
|
|
|
|
|
|
public void SetActiveTool(ToolType tool)
|
|
public void SetActiveTool(ToolType tool)
|
|
{
|
|
{
|
|
- Tool foundTool = ToolSet.First(x => x.ToolType == tool);
|
|
|
|
|
|
+ var foundTool = ToolSet.First(x => x.ToolType == tool);
|
|
SetActiveTool(foundTool);
|
|
SetActiveTool(foundTool);
|
|
}
|
|
}
|
|
|
|
|
|
public void SetActiveTool(Tool tool)
|
|
public void SetActiveTool(Tool tool)
|
|
{
|
|
{
|
|
- Tool activeTool = ToolSet.FirstOrDefault(x => x.IsActive);
|
|
|
|
|
|
+ var activeTool = ToolSet.FirstOrDefault(x => x.IsActive);
|
|
if (activeTool != null) activeTool.IsActive = false;
|
|
if (activeTool != null) activeTool.IsActive = false;
|
|
|
|
|
|
tool.IsActive = true;
|
|
tool.IsActive = true;
|
|
- _lastActionTool = BitmapManager.SelectedTool;
|
|
|
|
|
|
+ lastActionTool = BitmapManager.SelectedTool;
|
|
BitmapManager.SetActiveTool(tool);
|
|
BitmapManager.SetActiveTool(tool);
|
|
SetToolCursor(tool.ToolType);
|
|
SetToolCursor(tool.ToolType);
|
|
}
|
|
}
|
|
|
|
|
|
- private void SetToolCursor(ToolType tool)
|
|
|
|
|
|
+ private void SetToolCursor(ToolType tool)
|
|
{
|
|
{
|
|
if (tool != ToolType.None)
|
|
if (tool != ToolType.None)
|
|
ToolCursor = BitmapManager.SelectedTool.Cursor;
|
|
ToolCursor = BitmapManager.SelectedTool.Cursor;
|
|
@@ -731,15 +721,13 @@ namespace PixiEditor.ViewModels
|
|
{
|
|
{
|
|
if (BitmapManager.ActiveDocument.Layers.Count == 0) return;
|
|
if (BitmapManager.ActiveDocument.Layers.Count == 0) return;
|
|
if (Mouse.LeftButton == MouseButtonState.Pressed)
|
|
if (Mouse.LeftButton == MouseButtonState.Pressed)
|
|
- {
|
|
|
|
if (!BitmapManager.MouseController.IsRecordingChanges)
|
|
if (!BitmapManager.MouseController.IsRecordingChanges)
|
|
{
|
|
{
|
|
- bool clickedOnCanvas = MouseXOnCanvas >= 0 && MouseXOnCanvas <= BitmapManager.ActiveDocument.Width &&
|
|
|
|
- MouseYOnCanvas >= 0 && MouseYOnCanvas <= BitmapManager.ActiveDocument.Height;
|
|
|
|
|
|
+ var clickedOnCanvas = MouseXOnCanvas >= 0 && MouseXOnCanvas <= BitmapManager.ActiveDocument.Width &&
|
|
|
|
+ MouseYOnCanvas >= 0 && MouseYOnCanvas <= BitmapManager.ActiveDocument.Height;
|
|
BitmapManager.MouseController.StartRecordingMouseMovementChanges(clickedOnCanvas);
|
|
BitmapManager.MouseController.StartRecordingMouseMovementChanges(clickedOnCanvas);
|
|
BitmapManager.MouseController.RecordMouseMovementChange(MousePositionConverter.CurrentCoordinates);
|
|
BitmapManager.MouseController.RecordMouseMovementChange(MousePositionConverter.CurrentCoordinates);
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
// Mouse down is guaranteed to only be raised from within this application, so by subscribing here we
|
|
// Mouse down is guaranteed to only be raised from within this application, so by subscribing here we
|
|
// only listen for mouse up events that occurred as a result of a mouse down within this application.
|
|
// only listen for mouse up events that occurred as a result of a mouse down within this application.
|
|
@@ -760,15 +748,12 @@ namespace PixiEditor.ViewModels
|
|
/// <param name="parameter"></param>
|
|
/// <param name="parameter"></param>
|
|
private void MouseMove(object parameter)
|
|
private void MouseMove(object parameter)
|
|
{
|
|
{
|
|
- Coordinates cords = new Coordinates((int)MouseXOnCanvas, (int)MouseYOnCanvas);
|
|
|
|
|
|
+ var cords = new Coordinates((int) MouseXOnCanvas, (int) MouseYOnCanvas);
|
|
MousePositionConverter.CurrentCoordinates = cords;
|
|
MousePositionConverter.CurrentCoordinates = cords;
|
|
|
|
|
|
|
|
|
|
- if (BitmapManager.MouseController.IsRecordingChanges && Mouse.LeftButton == MouseButtonState.Pressed)
|
|
|
|
- {
|
|
|
|
- BitmapManager.MouseController.RecordMouseMovementChange(cords);
|
|
|
|
- }
|
|
|
|
- BitmapManager.MouseController.MouseMoved(cords);
|
|
|
|
|
|
+ if (BitmapManager.MouseController.IsRecordingChanges && Mouse.LeftButton == MouseButtonState.Pressed) BitmapManager.MouseController.RecordMouseMovementChange(cords);
|
|
|
|
+ BitmapManager.MouseController.MouseMoved(cords);
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
@@ -777,7 +762,7 @@ namespace PixiEditor.ViewModels
|
|
/// <param name="parameter"></param>
|
|
/// <param name="parameter"></param>
|
|
public void OpenNewFilePopup(object parameter)
|
|
public void OpenNewFilePopup(object parameter)
|
|
{
|
|
{
|
|
- NewFileDialog newFile = new NewFileDialog();
|
|
|
|
|
|
+ var newFile = new NewFileDialog();
|
|
if (newFile.ShowDialog()) NewDocument(newFile.Width, newFile.Height);
|
|
if (newFile.ShowDialog()) NewDocument(newFile.Width, newFile.Height);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -787,7 +772,7 @@ namespace PixiEditor.ViewModels
|
|
/// <param name="path"></param>
|
|
/// <param name="path"></param>
|
|
public void OpenFile(string path)
|
|
public void OpenFile(string path)
|
|
{
|
|
{
|
|
- ImportFileDialog dialog = new ImportFileDialog();
|
|
|
|
|
|
+ var dialog = new ImportFileDialog();
|
|
|
|
|
|
if (path != null && File.Exists(path))
|
|
if (path != null && File.Exists(path))
|
|
dialog.FilePath = path;
|
|
dialog.FilePath = path;
|
|
@@ -795,14 +780,14 @@ namespace PixiEditor.ViewModels
|
|
if (dialog.ShowDialog())
|
|
if (dialog.ShowDialog())
|
|
{
|
|
{
|
|
NewDocument(dialog.FileWidth, dialog.FileHeight, false);
|
|
NewDocument(dialog.FileWidth, dialog.FileHeight, false);
|
|
- BitmapManager.AddNewLayer("Image",Importer.ImportImage(dialog.FilePath, dialog.FileWidth, dialog.FileHeight));
|
|
|
|
|
|
+ BitmapManager.AddNewLayer("Image", Importer.ImportImage(dialog.FilePath, dialog.FileWidth, dialog.FileHeight));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
public void NewDocument(int width, int height, bool addBaseLayer = true)
|
|
public void NewDocument(int width, int height, bool addBaseLayer = true)
|
|
{
|
|
{
|
|
BitmapManager.ActiveDocument = new Document(width, height);
|
|
BitmapManager.ActiveDocument = new Document(width, height);
|
|
- if(addBaseLayer)
|
|
|
|
|
|
+ if (addBaseLayer)
|
|
BitmapManager.AddNewLayer("Base Layer");
|
|
BitmapManager.AddNewLayer("Base Layer");
|
|
ResetProgramStateValues();
|
|
ResetProgramStateValues();
|
|
}
|
|
}
|
|
@@ -818,7 +803,7 @@ namespace PixiEditor.ViewModels
|
|
ActiveSelection = new Selection(Array.Empty<Coordinates>());
|
|
ActiveSelection = new Selection(Array.Empty<Coordinates>());
|
|
RecenterZoombox = !RecenterZoombox;
|
|
RecenterZoombox = !RecenterZoombox;
|
|
Exporter.SaveDocumentPath = null;
|
|
Exporter.SaveDocumentPath = null;
|
|
- _unsavedDocumentModified = false;
|
|
|
|
|
|
+ unsavedDocumentModified = false;
|
|
}
|
|
}
|
|
|
|
|
|
public void NewLayer(object parameter)
|
|
public void NewLayer(object parameter)
|
|
@@ -882,7 +867,7 @@ namespace PixiEditor.ViewModels
|
|
/// <param name="parameter"></param>
|
|
/// <param name="parameter"></param>
|
|
private void ExportFile(object parameter)
|
|
private void ExportFile(object parameter)
|
|
{
|
|
{
|
|
- WriteableBitmap bitmap = BitmapManager.GetCombinedLayersBitmap();
|
|
|
|
|
|
+ var bitmap = BitmapManager.GetCombinedLayersBitmap();
|
|
Exporter.Export(bitmap, new Size(bitmap.PixelWidth, bitmap.PixelHeight));
|
|
Exporter.Export(bitmap, new Size(bitmap.PixelWidth, bitmap.PixelHeight));
|
|
}
|
|
}
|
|
|
|
|