|
@@ -1,17 +1,9 @@
|
|
|
using System;
|
|
|
using System.Collections.Generic;
|
|
|
-using System.Collections.ObjectModel;
|
|
|
using System.ComponentModel;
|
|
|
using System.Diagnostics;
|
|
|
-using System.IO;
|
|
|
-using System.Linq;
|
|
|
-using System.Reflection;
|
|
|
-using System.Threading.Tasks;
|
|
|
using System.Windows;
|
|
|
using System.Windows.Input;
|
|
|
-using System.Windows.Media;
|
|
|
-using System.Windows.Media.Imaging;
|
|
|
-using Microsoft.Win32;
|
|
|
using PixiEditor.Helpers;
|
|
|
using PixiEditor.Models.Controllers;
|
|
|
using PixiEditor.Models.Controllers.Shortcuts;
|
|
@@ -21,44 +13,52 @@ using PixiEditor.Models.Enums;
|
|
|
using PixiEditor.Models.Events;
|
|
|
using PixiEditor.Models.IO;
|
|
|
using PixiEditor.Models.Position;
|
|
|
-using PixiEditor.Models.Processes;
|
|
|
using PixiEditor.Models.Tools;
|
|
|
-using PixiEditor.Models.Tools.Tools;
|
|
|
-using PixiEditor.UpdateModule;
|
|
|
+using PixiEditor.ViewModels.SubViewModels.Main;
|
|
|
|
|
|
namespace PixiEditor.ViewModels
|
|
|
{
|
|
|
public class ViewModelMain : ViewModelBase
|
|
|
{
|
|
|
- private const string ConfirmationDialogMessage = "Document was modified. Do you want to save changes?";
|
|
|
+ public static ViewModelMain Current { get; set; }
|
|
|
+
|
|
|
+ public Action CloseAction { get; set; }
|
|
|
+
|
|
|
+ public event EventHandler OnStartupEvent;
|
|
|
+
|
|
|
+ public RelayCommand OnStartupCommand { get; set; }
|
|
|
+
|
|
|
+ public RelayCommand CloseWindowCommand { get; set; }
|
|
|
|
|
|
- private Color primaryColor = Colors.Black;
|
|
|
+ public RelayCommand OpenHyperlinkCommand { get; set; }
|
|
|
|
|
|
- private bool recenterZoombox;
|
|
|
+ public FileViewModel FileSubViewModel { get; set; }
|
|
|
|
|
|
- private Color secondaryColor = Colors.White;
|
|
|
+ public UpdateViewModel UpdateSubViewModel { get; set; }
|
|
|
|
|
|
- private Selection selection;
|
|
|
+ public ToolsViewModel ToolsSubViewModel { get; set; }
|
|
|
|
|
|
- private Cursor toolCursor;
|
|
|
+ public IoViewModel IoSubViewModel { get; set; }
|
|
|
|
|
|
- private LayerChange[] undoChanges;
|
|
|
+ public LayersViewModel LayersSubViewModel { get; set; }
|
|
|
|
|
|
- private bool unsavedDocumentModified;
|
|
|
+ public ClipboardViewModel ClipboardSubViewModel { get; set; }
|
|
|
|
|
|
- private double mouseXonCanvas;
|
|
|
+ public UndoViewModel UndoSubViewModel { get; set; }
|
|
|
|
|
|
- private double mouseYonCanvas;
|
|
|
+ public SelectionViewModel SelectionSubViewModel { get; set; }
|
|
|
|
|
|
- private string versionText;
|
|
|
+ public ViewportViewModel ViewportSubViewModel { get; set; }
|
|
|
|
|
|
- private double zoomPercentage = 100;
|
|
|
+ public ColorsViewModel ColorsSubViewModel { get; set; }
|
|
|
|
|
|
- private Point viewPortPosition;
|
|
|
+ public DocumentViewModel DocumentSubViewModel { get; set; }
|
|
|
|
|
|
- private bool updateReadyToInstall = false;
|
|
|
+ public BitmapManager BitmapManager { get; set; }
|
|
|
|
|
|
- private bool restoreToolOnKeyUp = false;
|
|
|
+ public PixelChangesController ChangesController { get; set; }
|
|
|
+
|
|
|
+ public ShortcutController ShortcutController { get; set; }
|
|
|
|
|
|
public ViewModelMain()
|
|
|
{
|
|
@@ -66,555 +66,73 @@ namespace PixiEditor.ViewModels
|
|
|
BitmapManager.BitmapOperations.BitmapChanged += BitmapUtility_BitmapChanged;
|
|
|
BitmapManager.MouseController.StoppedRecordingChanges += MouseController_StoppedRecordingChanges;
|
|
|
BitmapManager.DocumentChanged += BitmapManager_DocumentChanged;
|
|
|
+
|
|
|
+ SelectionSubViewModel = new SelectionViewModel(this);
|
|
|
+
|
|
|
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 MoveViewportTool(), new MoveTool(), new PenTool(), new SelectTool(), new FloodFill(), new LineTool(),
|
|
|
- new CircleTool(), new RectangleTool(), new EraserTool(), new ColorPickerTool(), new BrightnessTool(),
|
|
|
- new ZoomTool()
|
|
|
- };
|
|
|
+
|
|
|
+ FileSubViewModel = new FileViewModel(this);
|
|
|
+ UpdateSubViewModel = new UpdateViewModel(this);
|
|
|
+ ToolsSubViewModel = new ToolsViewModel(this);
|
|
|
+ IoSubViewModel = new IoViewModel(this);
|
|
|
+ LayersSubViewModel = new LayersViewModel(this);
|
|
|
+ ClipboardSubViewModel = new ClipboardViewModel(this);
|
|
|
+ UndoSubViewModel = new UndoViewModel(this);
|
|
|
+ ViewportSubViewModel = new ViewportViewModel(this);
|
|
|
+ ColorsSubViewModel = new ColorsViewModel(this);
|
|
|
+ DocumentSubViewModel = new DocumentViewModel(this);
|
|
|
+
|
|
|
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.H, SelectToolCommand, ToolType.MoveViewport),
|
|
|
- new Shortcut(Key.OemPlus, ZoomCommand, 115),
|
|
|
- new Shortcut(Key.OemMinus, ZoomCommand, 85),
|
|
|
- new Shortcut(Key.OemOpenBrackets, ChangeToolSizeCommand, -1),
|
|
|
- new Shortcut(Key.OemCloseBrackets, ChangeToolSizeCommand, 1),
|
|
|
+ new Shortcut(Key.B, ToolsSubViewModel.SelectToolCommand, ToolType.Pen),
|
|
|
+ new Shortcut(Key.E, ToolsSubViewModel.SelectToolCommand, ToolType.Eraser),
|
|
|
+ new Shortcut(Key.O, ToolsSubViewModel.SelectToolCommand, ToolType.ColorPicker),
|
|
|
+ new Shortcut(Key.R, ToolsSubViewModel.SelectToolCommand, ToolType.Rectangle),
|
|
|
+ new Shortcut(Key.C, ToolsSubViewModel.SelectToolCommand, ToolType.Circle),
|
|
|
+ new Shortcut(Key.L, ToolsSubViewModel.SelectToolCommand, ToolType.Line),
|
|
|
+ new Shortcut(Key.G, ToolsSubViewModel.SelectToolCommand, ToolType.Bucket),
|
|
|
+ new Shortcut(Key.U, ToolsSubViewModel.SelectToolCommand, ToolType.Brightness),
|
|
|
+ new Shortcut(Key.V, ToolsSubViewModel.SelectToolCommand, ToolType.Move),
|
|
|
+ new Shortcut(Key.M, ToolsSubViewModel.SelectToolCommand, ToolType.Select),
|
|
|
+ new Shortcut(Key.Z, ToolsSubViewModel.SelectToolCommand, ToolType.Zoom),
|
|
|
+ new Shortcut(Key.H, ToolsSubViewModel.SelectToolCommand, ToolType.MoveViewport),
|
|
|
+ new Shortcut(Key.OemPlus, ViewportSubViewModel.ZoomCommand, 115),
|
|
|
+ new Shortcut(Key.OemMinus, ViewportSubViewModel.ZoomCommand, 85),
|
|
|
+ new Shortcut(Key.OemOpenBrackets, ToolsSubViewModel.ChangeToolSizeCommand, -1),
|
|
|
+ new Shortcut(Key.OemCloseBrackets, ToolsSubViewModel.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.X, ColorsSubViewModel.SwapColorsCommand),
|
|
|
+ new Shortcut(Key.Y, UndoSubViewModel.RedoCommand, modifier: ModifierKeys.Control),
|
|
|
+ new Shortcut(Key.Z, UndoSubViewModel.UndoCommand, modifier: ModifierKeys.Control),
|
|
|
+ new Shortcut(Key.D, SelectionSubViewModel.DeselectCommand, modifier: ModifierKeys.Control),
|
|
|
+ new Shortcut(Key.A, SelectionSubViewModel.SelectAllCommand, modifier: ModifierKeys.Control),
|
|
|
+ new Shortcut(Key.C, ClipboardSubViewModel.CopyCommand, modifier: ModifierKeys.Control),
|
|
|
+ new Shortcut(Key.V, ClipboardSubViewModel.PasteCommand, modifier: ModifierKeys.Control),
|
|
|
+ new Shortcut(Key.J, ClipboardSubViewModel.DuplicateCommand, modifier: ModifierKeys.Control),
|
|
|
+ new Shortcut(Key.X, ClipboardSubViewModel.CutCommand, modifier: ModifierKeys.Control),
|
|
|
+ new Shortcut(Key.Delete, DocumentSubViewModel.DeletePixelsCommand),
|
|
|
+ new Shortcut(Key.I, DocumentSubViewModel.OpenResizePopupCommand, modifier: ModifierKeys.Control | ModifierKeys.Shift),
|
|
|
+ new Shortcut(Key.C, DocumentSubViewModel.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),
|
|
|
+ new Shortcut(Key.O, FileSubViewModel.OpenFileCommand, modifier: ModifierKeys.Control),
|
|
|
+ new Shortcut(Key.S, FileSubViewModel.ExportFileCommand, modifier: ModifierKeys.Control | ModifierKeys.Shift | ModifierKeys.Alt),
|
|
|
+ new Shortcut(Key.S, FileSubViewModel.SaveDocumentCommand, modifier: ModifierKeys.Control),
|
|
|
+ new Shortcut(Key.S, FileSubViewModel.SaveDocumentCommand, "AsNew", ModifierKeys.Control | ModifierKeys.Shift),
|
|
|
+ new Shortcut(Key.N, FileSubViewModel.OpenNewFilePopupCommand, modifier: ModifierKeys.Control)
|
|
|
}
|
|
|
};
|
|
|
UndoManager.SetMainRoot(this);
|
|
|
- SetActiveTool(ToolType.Move);
|
|
|
- BitmapManager.PrimaryColor = PrimaryColor;
|
|
|
- ActiveSelection = new Selection(Array.Empty<Coordinates>());
|
|
|
+ BitmapManager.PrimaryColor = ColorsSubViewModel.PrimaryColor;
|
|
|
Current = this;
|
|
|
- InitUpdateChecker();
|
|
|
- }
|
|
|
-
|
|
|
- public static ViewModelMain Current { get; set; }
|
|
|
-
|
|
|
- public Action CloseAction { get; set; }
|
|
|
-
|
|
|
- public RelayCommand SelectToolCommand { get; set; } // Command that handles tool switching
|
|
|
-
|
|
|
- public RelayCommand OpenNewFilePopupCommand { get; set; } // Command that generates draw area
|
|
|
-
|
|
|
- public RelayCommand MouseMoveCommand { get; set; } // Command that is used to draw
|
|
|
-
|
|
|
- public RelayCommand MouseDownCommand { get; set; }
|
|
|
-
|
|
|
- public RelayCommand KeyDownCommand { get; set; }
|
|
|
-
|
|
|
- public RelayCommand KeyUpCommand { get; set; }
|
|
|
-
|
|
|
- public RelayCommand ExportFileCommand { get; set; } // Command that is used to save file
|
|
|
-
|
|
|
- public RelayCommand UndoCommand { get; set; }
|
|
|
-
|
|
|
- public RelayCommand RedoCommand { get; set; }
|
|
|
-
|
|
|
- public RelayCommand OpenFileCommand { get; set; }
|
|
|
-
|
|
|
- public RelayCommand SetActiveLayerCommand { get; set; }
|
|
|
-
|
|
|
- public RelayCommand NewLayerCommand { get; set; }
|
|
|
-
|
|
|
- public RelayCommand DeleteLayerCommand { get; set; }
|
|
|
-
|
|
|
- public RelayCommand RenameLayerCommand { get; set; }
|
|
|
-
|
|
|
- public RelayCommand MoveToBackCommand { get; set; }
|
|
|
-
|
|
|
- public RelayCommand MoveToFrontCommand { get; set; }
|
|
|
-
|
|
|
- public RelayCommand SwapColorsCommand { get; set; }
|
|
|
-
|
|
|
- public RelayCommand DeselectCommand { get; set; }
|
|
|
-
|
|
|
- public RelayCommand SelectAllCommand { get; set; }
|
|
|
-
|
|
|
- public RelayCommand CopyCommand { get; set; }
|
|
|
-
|
|
|
- public RelayCommand DuplicateCommand { get; set; }
|
|
|
-
|
|
|
- public RelayCommand CutCommand { get; set; }
|
|
|
-
|
|
|
- public RelayCommand PasteCommand { get; set; }
|
|
|
-
|
|
|
- public RelayCommand ClipCanvasCommand { get; set; }
|
|
|
-
|
|
|
- public RelayCommand DeletePixelsCommand { get; set; }
|
|
|
-
|
|
|
- public RelayCommand OpenResizePopupCommand { get; set; }
|
|
|
-
|
|
|
- public RelayCommand SelectColorCommand { get; set; }
|
|
|
-
|
|
|
- public RelayCommand RemoveSwatchCommand { get; set; }
|
|
|
-
|
|
|
- public RelayCommand SaveDocumentCommand { get; set; }
|
|
|
-
|
|
|
- public RelayCommand OnStartupCommand { get; set; }
|
|
|
-
|
|
|
- public RelayCommand CloseWindowCommand { get; set; }
|
|
|
-
|
|
|
- public RelayCommand CenterContentCommand { get; set; }
|
|
|
-
|
|
|
- public RelayCommand OpenHyperlinkCommand { get; set; }
|
|
|
-
|
|
|
- public RelayCommand ZoomCommand { get; set; }
|
|
|
-
|
|
|
- public RelayCommand ChangeToolSizeCommand { get; set; }
|
|
|
-
|
|
|
- public RelayCommand RestartApplicationCommand { get; set; }
|
|
|
-
|
|
|
- public double MouseXOnCanvas // Mouse X coordinate relative to canvas
|
|
|
- {
|
|
|
- get => mouseXonCanvas;
|
|
|
- set
|
|
|
- {
|
|
|
- mouseXonCanvas = value;
|
|
|
- RaisePropertyChanged("MouseXOnCanvas");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public double MouseYOnCanvas // Mouse Y coordinate relative to canvas
|
|
|
- {
|
|
|
- get => mouseYonCanvas;
|
|
|
- set
|
|
|
- {
|
|
|
- mouseYonCanvas = value;
|
|
|
- RaisePropertyChanged("MouseYOnCanvas");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public string VersionText
|
|
|
- {
|
|
|
- get => versionText;
|
|
|
- set
|
|
|
- {
|
|
|
- versionText = value;
|
|
|
- RaisePropertyChanged(nameof(VersionText));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public bool RecenterZoombox
|
|
|
- {
|
|
|
- get => recenterZoombox;
|
|
|
- set
|
|
|
- {
|
|
|
- recenterZoombox = value;
|
|
|
- RaisePropertyChanged("RecenterZoombox");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public Color PrimaryColor // Primary color, hooked with left mouse button
|
|
|
- {
|
|
|
- get => primaryColor;
|
|
|
- set
|
|
|
- {
|
|
|
- if (primaryColor != value)
|
|
|
- {
|
|
|
- primaryColor = value;
|
|
|
- BitmapManager.PrimaryColor = value;
|
|
|
- RaisePropertyChanged("PrimaryColor");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public Color SecondaryColor
|
|
|
- {
|
|
|
- get => secondaryColor;
|
|
|
- set
|
|
|
- {
|
|
|
- if (secondaryColor != value)
|
|
|
- {
|
|
|
- secondaryColor = value;
|
|
|
- RaisePropertyChanged("SecondaryColor");
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public ObservableCollection<Tool> ToolSet { get; set; }
|
|
|
-
|
|
|
- public LayerChange[] UndoChanges // This acts like UndoManager process, but it was implemented before process system, so it can be transformed into it
|
|
|
- {
|
|
|
- get => undoChanges;
|
|
|
- set
|
|
|
- {
|
|
|
- undoChanges = value;
|
|
|
- for (int i = 0; i < value.Length; i++)
|
|
|
- {
|
|
|
- BitmapManager.ActiveDocument.Layers[value[i].LayerIndex].SetPixels(value[i].PixelChanges);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public Cursor ToolCursor
|
|
|
- {
|
|
|
- get => toolCursor;
|
|
|
- set
|
|
|
- {
|
|
|
- toolCursor = value;
|
|
|
- RaisePropertyChanged("ToolCursor");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public double ZoomPercentage
|
|
|
- {
|
|
|
- get
|
|
|
- {
|
|
|
- return zoomPercentage;
|
|
|
- }
|
|
|
-
|
|
|
- set
|
|
|
- {
|
|
|
- zoomPercentage = value;
|
|
|
- RaisePropertyChanged(nameof(ZoomPercentage));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public Point ViewportPosition
|
|
|
- {
|
|
|
- get => viewPortPosition;
|
|
|
- set
|
|
|
- {
|
|
|
- viewPortPosition = value;
|
|
|
- RaisePropertyChanged(nameof(ViewportPosition));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public bool UpdateReadyToInstall
|
|
|
- {
|
|
|
- get => updateReadyToInstall;
|
|
|
- set
|
|
|
- {
|
|
|
- updateReadyToInstall = value;
|
|
|
- RaisePropertyChanged(nameof(UpdateReadyToInstall));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public BitmapManager BitmapManager { get; set; }
|
|
|
-
|
|
|
- public PixelChangesController ChangesController { get; set; }
|
|
|
-
|
|
|
- public ShortcutController ShortcutController { get; set; }
|
|
|
-
|
|
|
- public Selection ActiveSelection
|
|
|
- {
|
|
|
- get => selection;
|
|
|
- set
|
|
|
- {
|
|
|
- selection = value;
|
|
|
- RaisePropertyChanged("ActiveSelection");
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public Tool LastActionTool { get; private set; }
|
|
|
-
|
|
|
- public UpdateChecker UpdateChecker { get; set; }
|
|
|
-
|
|
|
- public async Task<bool> CheckForUpdate()
|
|
|
- {
|
|
|
- return await Task.Run(async () =>
|
|
|
- {
|
|
|
- bool updateAvailable = await UpdateChecker.CheckUpdateAvailable();
|
|
|
- bool updateFileDoesNotExists = !File.Exists(
|
|
|
- Path.Join(UpdateDownloader.DownloadLocation, $"update-{UpdateChecker.LatestReleaseInfo.TagName}.zip"));
|
|
|
- if (updateAvailable && updateFileDoesNotExists)
|
|
|
- {
|
|
|
- VersionText = "Downloading update...";
|
|
|
- await UpdateDownloader.DownloadReleaseZip(UpdateChecker.LatestReleaseInfo);
|
|
|
- VersionText = "to install update"; // Button shows "Restart" before this text
|
|
|
- UpdateReadyToInstall = true;
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- return false;
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- public void AddSwatch(Color color)
|
|
|
- {
|
|
|
- if (!BitmapManager.ActiveDocument.Swatches.Contains(color))
|
|
|
- {
|
|
|
- BitmapManager.ActiveDocument.Swatches.Add(color);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void ClipCanvas(object parameter)
|
|
|
- {
|
|
|
- BitmapManager.ActiveDocument?.ClipCanvas();
|
|
|
- }
|
|
|
-
|
|
|
- public void Duplicate(object parameter)
|
|
|
- {
|
|
|
- Copy(null);
|
|
|
- Paste(null);
|
|
|
- }
|
|
|
-
|
|
|
- public void Cut(object parameter)
|
|
|
- {
|
|
|
- Copy(null);
|
|
|
- BitmapManager.ActiveLayer.SetPixels(
|
|
|
- BitmapPixelChanges.FromSingleColoredArray(ActiveSelection.SelectedPoints.ToArray(), Colors.Transparent));
|
|
|
- }
|
|
|
-
|
|
|
- public void Paste(object parameter)
|
|
|
- {
|
|
|
- ClipboardController.PasteFromClipboard();
|
|
|
- }
|
|
|
-
|
|
|
- public void SelectAll(object parameter)
|
|
|
- {
|
|
|
- SelectTool select = new SelectTool();
|
|
|
- ActiveSelection.SetSelection(select.GetAllSelection(), SelectionType.New);
|
|
|
- }
|
|
|
-
|
|
|
- public bool DocumentIsNotNull(object property)
|
|
|
- {
|
|
|
- return BitmapManager.ActiveDocument != null;
|
|
|
- }
|
|
|
-
|
|
|
- public void Deselect(object parameter)
|
|
|
- {
|
|
|
- ActiveSelection?.Clear();
|
|
|
- }
|
|
|
-
|
|
|
- public void SetTool(object parameter)
|
|
|
- {
|
|
|
- SetActiveTool((ToolType)parameter);
|
|
|
- }
|
|
|
-
|
|
|
- public void RenameLayer(object parameter)
|
|
|
- {
|
|
|
- BitmapManager.ActiveDocument.Layers[(int)parameter].IsRenaming = true;
|
|
|
- }
|
|
|
-
|
|
|
- public void KeyDown(object parameter)
|
|
|
- {
|
|
|
- KeyEventArgs args = (KeyEventArgs)parameter;
|
|
|
- if (args.IsRepeat && !restoreToolOnKeyUp && ShortcutController.LastShortcut != null && ShortcutController.LastShortcut.Command == SelectToolCommand)
|
|
|
- {
|
|
|
- restoreToolOnKeyUp = true;
|
|
|
- ShortcutController.BlockShortcutExecution = true;
|
|
|
- }
|
|
|
-
|
|
|
- ShortcutController.KeyPressed(args.Key, Keyboard.Modifiers);
|
|
|
- }
|
|
|
-
|
|
|
- public void TriggerNewUndoChange(Tool toolUsed)
|
|
|
- {
|
|
|
- if (BitmapManager.IsOperationTool(toolUsed)
|
|
|
- && ((BitmapOperationTool)toolUsed).UseDefaultUndoMethod)
|
|
|
- {
|
|
|
- Tuple<LayerChange, LayerChange>[] changes = ChangesController.PopChanges();
|
|
|
- if (changes != null && changes.Length > 0)
|
|
|
- {
|
|
|
- LayerChange[] newValues = changes.Select(x => x.Item1).ToArray();
|
|
|
- LayerChange[] oldValues = changes.Select(x => x.Item2).ToArray();
|
|
|
- UndoManager.AddUndoChange(new Change("UndoChanges", oldValues, newValues));
|
|
|
- toolUsed.AfterAddedUndo();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void SwapColors(object parameter)
|
|
|
- {
|
|
|
- var tmp = PrimaryColor;
|
|
|
- PrimaryColor = SecondaryColor;
|
|
|
- SecondaryColor = tmp;
|
|
|
- }
|
|
|
-
|
|
|
- public void MoveLayerToFront(object parameter)
|
|
|
- {
|
|
|
- int oldIndex = (int)parameter;
|
|
|
- BitmapManager.ActiveDocument.Layers.Move(oldIndex, oldIndex + 1);
|
|
|
- if (BitmapManager.ActiveDocument.ActiveLayerIndex == oldIndex)
|
|
|
- {
|
|
|
- BitmapManager.SetActiveLayer(oldIndex + 1);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void MoveLayerToBack(object parameter)
|
|
|
- {
|
|
|
- int oldIndex = (int)parameter;
|
|
|
- BitmapManager.ActiveDocument.Layers.Move(oldIndex, oldIndex - 1);
|
|
|
- if (BitmapManager.ActiveDocument.ActiveLayerIndex == oldIndex)
|
|
|
- {
|
|
|
- BitmapManager.SetActiveLayer(oldIndex - 1);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public bool CanMoveToFront(object property)
|
|
|
- {
|
|
|
- return DocumentIsNotNull(null) && BitmapManager.ActiveDocument.Layers.Count - 1 > (int)property;
|
|
|
- }
|
|
|
-
|
|
|
- public bool CanMoveToBack(object property)
|
|
|
- {
|
|
|
- return (int)property > 0;
|
|
|
- }
|
|
|
-
|
|
|
- public void SetActiveLayer(object parameter)
|
|
|
- {
|
|
|
- BitmapManager.SetActiveLayer((int)parameter);
|
|
|
- }
|
|
|
-
|
|
|
- public void DeleteLayer(object parameter)
|
|
|
- {
|
|
|
- BitmapManager.RemoveLayer((int)parameter);
|
|
|
- }
|
|
|
-
|
|
|
- public bool CanDeleteLayer(object property)
|
|
|
- {
|
|
|
- return BitmapManager.ActiveDocument != null && BitmapManager.ActiveDocument.Layers.Count > 1;
|
|
|
- }
|
|
|
-
|
|
|
- public void SetActiveTool(ToolType tool)
|
|
|
- {
|
|
|
- Tool foundTool = ToolSet.First(x => x.ToolType == tool);
|
|
|
- SetActiveTool(foundTool);
|
|
|
- }
|
|
|
-
|
|
|
- public void SetActiveTool(Tool tool)
|
|
|
- {
|
|
|
- Tool activeTool = ToolSet.FirstOrDefault(x => x.IsActive);
|
|
|
- if (activeTool != null)
|
|
|
- {
|
|
|
- activeTool.IsActive = false;
|
|
|
- }
|
|
|
-
|
|
|
- tool.IsActive = true;
|
|
|
- LastActionTool = BitmapManager.SelectedTool;
|
|
|
- BitmapManager.SetActiveTool(tool);
|
|
|
- SetToolCursor(tool.ToolType);
|
|
|
- }
|
|
|
-
|
|
|
- // this is public for testing.
|
|
|
- public void MouseHook_OnMouseUp(object sender, Point p, MouseButton button)
|
|
|
- {
|
|
|
- GlobalMouseHook.OnMouseUp -= MouseHook_OnMouseUp;
|
|
|
- if (button == MouseButton.Left)
|
|
|
- {
|
|
|
- BitmapManager.MouseController.StopRecordingMouseMovementChanges();
|
|
|
- }
|
|
|
-
|
|
|
- BitmapManager.MouseController.MouseUp(new MouseEventArgs(
|
|
|
- Mouse.PrimaryDevice,
|
|
|
- (int)DateTimeOffset.UtcNow.ToUnixTimeSeconds()));
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// Generates new Layer and sets it as active one.
|
|
|
- /// </summary>
|
|
|
- public void OpenNewFilePopup(object parameter)
|
|
|
- {
|
|
|
- NewFileDialog newFile = new NewFileDialog();
|
|
|
- if (newFile.ShowDialog())
|
|
|
- {
|
|
|
- NewDocument(newFile.Width, newFile.Height);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// Opens file from path.
|
|
|
- /// </summary>
|
|
|
- public void OpenFile(string path)
|
|
|
- {
|
|
|
- ImportFileDialog dialog = new ImportFileDialog();
|
|
|
-
|
|
|
- if (path != null && File.Exists(path))
|
|
|
- {
|
|
|
- dialog.FilePath = path;
|
|
|
- }
|
|
|
-
|
|
|
- if (dialog.ShowDialog())
|
|
|
- {
|
|
|
- NewDocument(dialog.FileWidth, dialog.FileHeight, false);
|
|
|
- BitmapManager.AddNewLayer("Image", Importer.ImportImage(dialog.FilePath, dialog.FileWidth, dialog.FileHeight));
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public void NewDocument(int width, int height, bool addBaseLayer = true)
|
|
|
- {
|
|
|
- BitmapManager.ActiveDocument = new Document(width, height);
|
|
|
- if (addBaseLayer)
|
|
|
- {
|
|
|
- BitmapManager.AddNewLayer("Base Layer");
|
|
|
- }
|
|
|
-
|
|
|
- ResetProgramStateValues();
|
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
@@ -625,75 +143,15 @@ namespace PixiEditor.ViewModels
|
|
|
BitmapManager.PreviewLayer = null;
|
|
|
UndoManager.UndoStack.Clear();
|
|
|
UndoManager.RedoStack.Clear();
|
|
|
- ActiveSelection = new Selection(Array.Empty<Coordinates>());
|
|
|
- RecenterZoombox = !RecenterZoombox;
|
|
|
+ SelectionSubViewModel.ActiveSelection = new Selection(Array.Empty<Coordinates>());
|
|
|
+ ViewportSubViewModel.CenterViewport();
|
|
|
Exporter.SaveDocumentPath = null;
|
|
|
- unsavedDocumentModified = false;
|
|
|
+ DocumentSubViewModel.UnsavedDocumentModified = false;
|
|
|
}
|
|
|
|
|
|
- public void NewLayer(object parameter)
|
|
|
- {
|
|
|
- BitmapManager.AddNewLayer($"New Layer {BitmapManager.ActiveDocument.Layers.Count}");
|
|
|
- }
|
|
|
-
|
|
|
- public bool CanCreateNewLayer(object parameter)
|
|
|
- {
|
|
|
- return BitmapManager.ActiveDocument != null && BitmapManager.ActiveDocument.Layers.Count > 0;
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// Undo last action.
|
|
|
- /// </summary>
|
|
|
- public void Undo(object parameter)
|
|
|
- {
|
|
|
- Deselect(null);
|
|
|
- UndoManager.Undo();
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// Redo last action.
|
|
|
- /// </summary>
|
|
|
- public void Redo(object parameter)
|
|
|
- {
|
|
|
- UndoManager.Redo();
|
|
|
- }
|
|
|
-
|
|
|
- private void RestartApplication(object parameter)
|
|
|
- {
|
|
|
- try
|
|
|
- {
|
|
|
- ProcessHelper.RunAsAdmin(Path.Join(AppDomain.CurrentDomain.BaseDirectory, "PixiEditor.UpdateInstaller.exe"));
|
|
|
- Application.Current.Shutdown();
|
|
|
- }
|
|
|
- catch (Win32Exception)
|
|
|
- {
|
|
|
- MessageBox.Show("Couldn't update without administrator rights.", "Insufficient permissions", MessageBoxButton.OK, MessageBoxImage.Error);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void InitUpdateChecker()
|
|
|
- {
|
|
|
- var assembly = Assembly.GetExecutingAssembly();
|
|
|
- FileVersionInfo info = FileVersionInfo.GetVersionInfo(assembly.Location);
|
|
|
- UpdateChecker = new UpdateChecker(info.FileVersion);
|
|
|
- VersionText = $"Version {info.FileVersion}";
|
|
|
- }
|
|
|
-
|
|
|
- private void ZoomViewport(object parameter)
|
|
|
- {
|
|
|
- double zoom = (int)parameter;
|
|
|
- ZoomPercentage = zoom;
|
|
|
- ZoomPercentage = 100;
|
|
|
- }
|
|
|
-
|
|
|
- private void ChangeToolSize(object parameter)
|
|
|
+ public bool DocumentIsNotNull(object property)
|
|
|
{
|
|
|
- int increment = (int)parameter;
|
|
|
- int newSize = BitmapManager.ToolSize + increment;
|
|
|
- if (newSize > 0)
|
|
|
- {
|
|
|
- BitmapManager.ToolSize = newSize;
|
|
|
- }
|
|
|
+ return BitmapManager.ActiveDocument != null;
|
|
|
}
|
|
|
|
|
|
private void OpenHyperlink(object parameter)
|
|
@@ -703,7 +161,7 @@ namespace PixiEditor.ViewModels
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- string url = (string)parameter;
|
|
|
+ var url = (string)parameter;
|
|
|
var processInfo = new ProcessStartInfo()
|
|
|
{
|
|
|
FileName = url,
|
|
@@ -712,11 +170,6 @@ namespace PixiEditor.ViewModels
|
|
|
Process.Start(processInfo);
|
|
|
}
|
|
|
|
|
|
- private void CenterContent(object property)
|
|
|
- {
|
|
|
- BitmapManager.ActiveDocument.CenterContent();
|
|
|
- }
|
|
|
-
|
|
|
private void CloseWindow(object property)
|
|
|
{
|
|
|
if (!(property is CancelEventArgs))
|
|
@@ -726,13 +179,13 @@ namespace PixiEditor.ViewModels
|
|
|
|
|
|
((CancelEventArgs)property).Cancel = true;
|
|
|
|
|
|
- ConfirmationType result = ConfirmationType.No;
|
|
|
- if (unsavedDocumentModified)
|
|
|
+ var result = ConfirmationType.No;
|
|
|
+ if (DocumentSubViewModel.UnsavedDocumentModified)
|
|
|
{
|
|
|
- result = ConfirmationDialog.Show(ConfirmationDialogMessage);
|
|
|
+ result = ConfirmationDialog.Show(DocumentViewModel.ConfirmationDialogMessage);
|
|
|
if (result == ConfirmationType.Yes)
|
|
|
{
|
|
|
- SaveDocument(null);
|
|
|
+ FileSubViewModel.SaveDocument(false);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -742,19 +195,9 @@ namespace PixiEditor.ViewModels
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private async void OnStartup(object parameter)
|
|
|
+ private void OnStartup(object parameter)
|
|
|
{
|
|
|
- var lastArg = Environment.GetCommandLineArgs().Last();
|
|
|
- if (Importer.IsSupportedFile(lastArg) && File.Exists(lastArg))
|
|
|
- {
|
|
|
- Open(lastArg);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- OpenNewFilePopup(null);
|
|
|
- }
|
|
|
-
|
|
|
- await CheckForUpdate();
|
|
|
+ OnStartupEvent?.Invoke(this, EventArgs.Empty);
|
|
|
}
|
|
|
|
|
|
private void BitmapManager_DocumentChanged(object sender, DocumentChangedEventArgs e)
|
|
@@ -762,263 +205,28 @@ namespace PixiEditor.ViewModels
|
|
|
e.NewDocument.DocumentSizeChanged += ActiveDocument_DocumentSizeChanged;
|
|
|
}
|
|
|
|
|
|
- private void Open(object property)
|
|
|
- {
|
|
|
- OpenFileDialog dialog = new OpenFileDialog
|
|
|
- {
|
|
|
- Filter = "All Files|*.*|PixiEditor Files | *.pixi|PNG Files|*.png",
|
|
|
- DefaultExt = "pixi"
|
|
|
- };
|
|
|
- if ((bool)dialog.ShowDialog())
|
|
|
- {
|
|
|
- if (Importer.IsSupportedFile(dialog.FileName))
|
|
|
- {
|
|
|
- Open(dialog.FileName);
|
|
|
- }
|
|
|
-
|
|
|
- RecenterZoombox = !RecenterZoombox;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void Open(string path)
|
|
|
- {
|
|
|
- if (unsavedDocumentModified)
|
|
|
- {
|
|
|
- var result = ConfirmationDialog.Show(ConfirmationDialogMessage);
|
|
|
- if (result == ConfirmationType.Yes)
|
|
|
- {
|
|
|
- SaveDocument(null);
|
|
|
- }
|
|
|
- else if (result == ConfirmationType.Canceled)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- ResetProgramStateValues();
|
|
|
- if (path.EndsWith(".pixi"))
|
|
|
- {
|
|
|
- OpenDocument(path);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- OpenFile(path);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void OpenDocument(string path)
|
|
|
- {
|
|
|
- BitmapManager.ActiveDocument = Importer.ImportDocument(path);
|
|
|
- Exporter.SaveDocumentPath = path;
|
|
|
- unsavedDocumentModified = false;
|
|
|
- }
|
|
|
-
|
|
|
- private void SaveDocument(object parameter)
|
|
|
- {
|
|
|
- bool paramIsAsNew = parameter != null && parameter.ToString()?.ToLower() == "asnew";
|
|
|
- if (paramIsAsNew || Exporter.SaveDocumentPath == null)
|
|
|
- {
|
|
|
- var saved = Exporter.SaveAsEditableFileWithDialog(BitmapManager.ActiveDocument, !paramIsAsNew);
|
|
|
- unsavedDocumentModified = unsavedDocumentModified && !saved;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- Exporter.SaveAsEditableFile(BitmapManager.ActiveDocument, Exporter.SaveDocumentPath);
|
|
|
- unsavedDocumentModified = false;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void RemoveSwatch(object parameter)
|
|
|
- {
|
|
|
- if (!(parameter is Color))
|
|
|
- {
|
|
|
- throw new ArgumentException();
|
|
|
- }
|
|
|
-
|
|
|
- Color color = (Color)parameter;
|
|
|
- if (BitmapManager.ActiveDocument.Swatches.Contains(color))
|
|
|
- {
|
|
|
- BitmapManager.ActiveDocument.Swatches.Remove(color);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void SelectColor(object parameter)
|
|
|
- {
|
|
|
- PrimaryColor = parameter as Color? ?? throw new ArgumentException();
|
|
|
- }
|
|
|
-
|
|
|
private void ActiveDocument_DocumentSizeChanged(object sender, DocumentSizeChangedEventArgs e)
|
|
|
{
|
|
|
- ActiveSelection = new Selection(Array.Empty<Coordinates>());
|
|
|
- RecenterZoombox = !RecenterZoombox;
|
|
|
- unsavedDocumentModified = true;
|
|
|
- }
|
|
|
-
|
|
|
- private void OpenResizePopup(object parameter)
|
|
|
- {
|
|
|
- bool isCanvasDialog = (string)parameter == "canvas";
|
|
|
- ResizeDocumentDialog dialog = new ResizeDocumentDialog(BitmapManager.ActiveDocument.Width, BitmapManager.ActiveDocument.Height, isCanvasDialog);
|
|
|
- if (dialog.ShowDialog())
|
|
|
- {
|
|
|
- if (isCanvasDialog)
|
|
|
- {
|
|
|
- BitmapManager.ActiveDocument.ResizeCanvas(dialog.Width, dialog.Height, dialog.ResizeAnchor);
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- BitmapManager.ActiveDocument.Resize(dialog.Width, dialog.Height);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void DeletePixels(object parameter)
|
|
|
- {
|
|
|
- BitmapManager.BitmapOperations.DeletePixels(
|
|
|
- new[] { BitmapManager.ActiveLayer },
|
|
|
- ActiveSelection.SelectedPoints.ToArray());
|
|
|
- }
|
|
|
-
|
|
|
- private bool CanPaste(object property)
|
|
|
- {
|
|
|
- return DocumentIsNotNull(null) && ClipboardController.IsImageInClipboard();
|
|
|
- }
|
|
|
-
|
|
|
- private void Copy(object parameter)
|
|
|
- {
|
|
|
- ClipboardController.CopyToClipboard(
|
|
|
- BitmapManager.ActiveDocument.Layers.ToArray(),
|
|
|
- ActiveSelection.SelectedPoints.ToArray(),
|
|
|
- BitmapManager.ActiveDocument.Width,
|
|
|
- BitmapManager.ActiveDocument.Height);
|
|
|
- }
|
|
|
-
|
|
|
- private bool CanSelectAll(object property)
|
|
|
- {
|
|
|
- return BitmapManager.ActiveDocument != null && BitmapManager.ActiveDocument.Layers.Count > 0;
|
|
|
- }
|
|
|
-
|
|
|
- private bool SelectionIsNotEmpty(object property)
|
|
|
- {
|
|
|
- return ActiveSelection?.SelectedPoints != null && ActiveSelection.SelectedPoints.Count > 0;
|
|
|
- }
|
|
|
-
|
|
|
- private void KeyUp(object parameter)
|
|
|
- {
|
|
|
- KeyEventArgs args = (KeyEventArgs)parameter;
|
|
|
- if (restoreToolOnKeyUp && ShortcutController.LastShortcut != null && ShortcutController.LastShortcut.ShortcutKey == args.Key)
|
|
|
- {
|
|
|
- restoreToolOnKeyUp = false;
|
|
|
- SetActiveTool(LastActionTool);
|
|
|
- ShortcutController.BlockShortcutExecution = false;
|
|
|
- }
|
|
|
+ SelectionSubViewModel.ActiveSelection = new Selection(Array.Empty<Coordinates>());
|
|
|
+ ViewportSubViewModel.CenterViewport();
|
|
|
+ DocumentSubViewModel.UnsavedDocumentModified = true;
|
|
|
}
|
|
|
|
|
|
private void MouseController_StoppedRecordingChanges(object sender, EventArgs e)
|
|
|
{
|
|
|
- TriggerNewUndoChange(BitmapManager.SelectedTool);
|
|
|
+ UndoSubViewModel.TriggerNewUndoChange(BitmapManager.SelectedTool);
|
|
|
}
|
|
|
|
|
|
private void BitmapUtility_BitmapChanged(object sender, BitmapChangedEventArgs e)
|
|
|
{
|
|
|
ChangesController.AddChanges(
|
|
|
- new LayerChange(
|
|
|
- e.PixelsChanged,
|
|
|
- e.ChangedLayerIndex),
|
|
|
+ new LayerChange(e.PixelsChanged, e.ChangedLayerIndex),
|
|
|
new LayerChange(e.OldPixelsValues, e.ChangedLayerIndex));
|
|
|
- unsavedDocumentModified = true;
|
|
|
+ DocumentSubViewModel.UnsavedDocumentModified = true;
|
|
|
if (BitmapManager.IsOperationTool())
|
|
|
{
|
|
|
- AddSwatch(PrimaryColor);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void SetToolCursor(ToolType tool)
|
|
|
- {
|
|
|
- if (tool != ToolType.None)
|
|
|
- {
|
|
|
- ToolCursor = BitmapManager.SelectedTool.Cursor;
|
|
|
- }
|
|
|
- else
|
|
|
- {
|
|
|
- ToolCursor = Cursors.Arrow;
|
|
|
+ ColorsSubViewModel.AddSwatch(ColorsSubViewModel.PrimaryColor);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- private void MouseDown(object parameter)
|
|
|
- {
|
|
|
- if (BitmapManager.ActiveDocument.Layers.Count == 0)
|
|
|
- {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- if (Mouse.LeftButton == MouseButtonState.Pressed)
|
|
|
- {
|
|
|
- if (!BitmapManager.MouseController.IsRecordingChanges)
|
|
|
- {
|
|
|
- bool clickedOnCanvas = MouseXOnCanvas >= 0 && MouseXOnCanvas <= BitmapManager.ActiveDocument.Width &&
|
|
|
- MouseYOnCanvas >= 0 && MouseYOnCanvas <= BitmapManager.ActiveDocument.Height;
|
|
|
- BitmapManager.MouseController.StartRecordingMouseMovementChanges(clickedOnCanvas);
|
|
|
- BitmapManager.MouseController.RecordMouseMovementChange(MousePositionConverter.CurrentCoordinates);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- BitmapManager.MouseController.MouseDown(new MouseEventArgs(
|
|
|
- Mouse.PrimaryDevice,
|
|
|
- (int)DateTimeOffset.UtcNow.ToUnixTimeSeconds()));
|
|
|
-
|
|
|
- // 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.
|
|
|
- // This seems better than maintaining a global listener indefinitely.
|
|
|
- GlobalMouseHook.OnMouseUp += MouseHook_OnMouseUp;
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// Method connected with command, it executes tool "activity".
|
|
|
- /// </summary>
|
|
|
- private void MouseMove(object parameter)
|
|
|
- {
|
|
|
- Coordinates cords = new Coordinates((int)MouseXOnCanvas, (int)MouseYOnCanvas);
|
|
|
- MousePositionConverter.CurrentCoordinates = cords;
|
|
|
-
|
|
|
- if (BitmapManager.MouseController.IsRecordingChanges && Mouse.LeftButton == MouseButtonState.Pressed)
|
|
|
- {
|
|
|
- BitmapManager.MouseController.RecordMouseMovementChange(cords);
|
|
|
- }
|
|
|
-
|
|
|
- BitmapManager.MouseController.MouseMoved(cords);
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// Returns true if undo can be done.
|
|
|
- /// </summary>
|
|
|
- private bool CanUndo(object property)
|
|
|
- {
|
|
|
- return UndoManager.CanUndo;
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// Returns true if redo can be done.
|
|
|
- /// </summary>
|
|
|
- private bool CanRedo(object property)
|
|
|
- {
|
|
|
- return UndoManager.CanRedo;
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// Generates export dialog or saves directly if save data is known.
|
|
|
- /// </summary>
|
|
|
- private void ExportFile(object parameter)
|
|
|
- {
|
|
|
- WriteableBitmap bitmap = BitmapManager.GetCombinedLayersBitmap();
|
|
|
- Exporter.Export(bitmap, new Size(bitmap.PixelWidth, bitmap.PixelHeight));
|
|
|
- }
|
|
|
-
|
|
|
- /// <summary>
|
|
|
- /// Returns true if file save is possible.
|
|
|
- /// </summary>
|
|
|
- private bool CanSave(object property)
|
|
|
- {
|
|
|
- return BitmapManager.ActiveDocument != null;
|
|
|
- }
|
|
|
}
|
|
|
}
|