|
@@ -126,6 +126,7 @@ namespace PixiEditor.ViewModels
|
|
new Shortcut(Key.OemMinus, ZoomCommand, 85),
|
|
new Shortcut(Key.OemMinus, ZoomCommand, 85),
|
|
new Shortcut(Key.OemOpenBrackets, ChangeToolSizeCommand, -1),
|
|
new Shortcut(Key.OemOpenBrackets, ChangeToolSizeCommand, -1),
|
|
new Shortcut(Key.OemCloseBrackets, ChangeToolSizeCommand, 1),
|
|
new Shortcut(Key.OemCloseBrackets, ChangeToolSizeCommand, 1),
|
|
|
|
+
|
|
// Editor
|
|
// Editor
|
|
new Shortcut(Key.X, SwapColorsCommand),
|
|
new Shortcut(Key.X, SwapColorsCommand),
|
|
new Shortcut(Key.Y, RedoCommand, modifier: ModifierKeys.Control),
|
|
new Shortcut(Key.Y, RedoCommand, modifier: ModifierKeys.Control),
|
|
@@ -140,9 +141,12 @@ namespace PixiEditor.ViewModels
|
|
new Shortcut(Key.I, OpenResizePopupCommand, modifier: ModifierKeys.Control | ModifierKeys.Shift),
|
|
new Shortcut(Key.I, OpenResizePopupCommand, modifier: ModifierKeys.Control | ModifierKeys.Shift),
|
|
new Shortcut(Key.C, OpenResizePopupCommand, "canvas", ModifierKeys.Control | ModifierKeys.Shift),
|
|
new Shortcut(Key.C, OpenResizePopupCommand, "canvas", ModifierKeys.Control | ModifierKeys.Shift),
|
|
new Shortcut(Key.F11, SystemCommands.MaximizeWindowCommand),
|
|
new Shortcut(Key.F11, SystemCommands.MaximizeWindowCommand),
|
|
|
|
+
|
|
// File
|
|
// File
|
|
new Shortcut(Key.O, OpenFileCommand, modifier: ModifierKeys.Control),
|
|
new Shortcut(Key.O, OpenFileCommand, modifier: ModifierKeys.Control),
|
|
- new Shortcut(Key.S, ExportFileCommand,
|
|
|
|
|
|
+ new Shortcut(
|
|
|
|
+ Key.S,
|
|
|
|
+ ExportFileCommand,
|
|
modifier: ModifierKeys.Control | ModifierKeys.Shift | ModifierKeys.Alt),
|
|
modifier: ModifierKeys.Control | ModifierKeys.Shift | ModifierKeys.Alt),
|
|
new Shortcut(Key.S, SaveDocumentCommand, modifier: ModifierKeys.Control),
|
|
new Shortcut(Key.S, SaveDocumentCommand, modifier: ModifierKeys.Control),
|
|
new Shortcut(Key.S, SaveDocumentCommand, "AsNew", ModifierKeys.Control | ModifierKeys.Shift),
|
|
new Shortcut(Key.S, SaveDocumentCommand, "AsNew", ModifierKeys.Control | ModifierKeys.Shift),
|
|
@@ -157,10 +161,10 @@ namespace PixiEditor.ViewModels
|
|
InitUpdateChecker();
|
|
InitUpdateChecker();
|
|
}
|
|
}
|
|
|
|
|
|
- public Action CloseAction { get; set; }
|
|
|
|
-
|
|
|
|
public static ViewModelMain Current { get; set; }
|
|
public static ViewModelMain Current { get; set; }
|
|
|
|
|
|
|
|
+ public Action CloseAction { 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
|
|
@@ -363,12 +367,6 @@ namespace PixiEditor.ViewModels
|
|
|
|
|
|
public UpdateChecker UpdateChecker { get; set; }
|
|
public UpdateChecker UpdateChecker { get; set; }
|
|
|
|
|
|
- private void RestartApplication(object parameter)
|
|
|
|
- {
|
|
|
|
- Process.Start(Path.Join(AppDomain.CurrentDomain.BaseDirectory, "PixiEditor.UpdateInstaller.exe"));
|
|
|
|
- Application.Current.Shutdown();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public async Task<bool> CheckForUpdate()
|
|
public async Task<bool> CheckForUpdate()
|
|
{
|
|
{
|
|
return await Task.Run(async () =>
|
|
return await Task.Run(async () =>
|
|
@@ -388,187 +386,6 @@ namespace PixiEditor.ViewModels
|
|
});
|
|
});
|
|
}
|
|
}
|
|
|
|
|
|
- private void InitUpdateChecker()
|
|
|
|
- {
|
|
|
|
- Assembly 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)
|
|
|
|
- {
|
|
|
|
- int increment = (int)parameter;
|
|
|
|
- int newSize = BitmapManager.ToolSize + increment;
|
|
|
|
- if (newSize > 0)
|
|
|
|
- {
|
|
|
|
- BitmapManager.ToolSize = newSize;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private void OpenHyperlink(object parameter)
|
|
|
|
- {
|
|
|
|
- if (parameter == null)
|
|
|
|
- {
|
|
|
|
- return;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- string url = (string)parameter;
|
|
|
|
- ProcessStartInfo processInfo = new ProcessStartInfo
|
|
|
|
- {
|
|
|
|
- FileName = url,
|
|
|
|
- UseShellExecute = true
|
|
|
|
- };
|
|
|
|
- Process.Start(processInfo);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private void CenterContent(object property)
|
|
|
|
- {
|
|
|
|
- BitmapManager.ActiveDocument.CenterContent();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private void CloseWindow(object property)
|
|
|
|
- {
|
|
|
|
- if (!(property is CancelEventArgs))
|
|
|
|
- {
|
|
|
|
- throw new ArgumentException();
|
|
|
|
- } ((CancelEventArgs)property).Cancel = true;
|
|
|
|
-
|
|
|
|
- ConfirmationType result = ConfirmationType.No;
|
|
|
|
- if (unsavedDocumentModified)
|
|
|
|
- {
|
|
|
|
- result = ConfirmationDialog.Show(ConfirmationDialogMessage);
|
|
|
|
- if (result == ConfirmationType.Yes)
|
|
|
|
- {
|
|
|
|
- SaveDocument(null);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- if (result != ConfirmationType.Canceled)
|
|
|
|
- {
|
|
|
|
- ((CancelEventArgs)property).Cancel = false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private async void OnStartup(object parameter)
|
|
|
|
- {
|
|
|
|
- string lastArg = Environment.GetCommandLineArgs().Last();
|
|
|
|
- if (Importer.IsSupportedFile(lastArg) && File.Exists(lastArg))
|
|
|
|
- {
|
|
|
|
- Open(lastArg);
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- OpenNewFilePopup(null);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- await CheckForUpdate();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private void BitmapManager_DocumentChanged(object sender, DocumentChangedEventArgs e)
|
|
|
|
- {
|
|
|
|
- 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)
|
|
|
|
- {
|
|
|
|
- ConfirmationType 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)
|
|
|
|
- {
|
|
|
|
- bool 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;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public void AddSwatch(Color color)
|
|
public void AddSwatch(Color color)
|
|
{
|
|
{
|
|
if (!BitmapManager.ActiveDocument.Swatches.Contains(color))
|
|
if (!BitmapManager.ActiveDocument.Swatches.Contains(color))
|
|
@@ -577,32 +394,6 @@ namespace PixiEditor.ViewModels
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- 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());
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public void ClipCanvas(object parameter)
|
|
public void ClipCanvas(object parameter)
|
|
{
|
|
{
|
|
BitmapManager.ActiveDocument?.ClipCanvas();
|
|
BitmapManager.ActiveDocument?.ClipCanvas();
|
|
@@ -618,7 +409,8 @@ namespace PixiEditor.ViewModels
|
|
{
|
|
{
|
|
Copy(null);
|
|
Copy(null);
|
|
BitmapManager.ActiveLayer.SetPixels(
|
|
BitmapManager.ActiveLayer.SetPixels(
|
|
- BitmapPixelChanges.FromSingleColoredArray(ActiveSelection.SelectedPoints.ToArray(),
|
|
|
|
|
|
+ BitmapPixelChanges.FromSingleColoredArray(
|
|
|
|
+ ActiveSelection.SelectedPoints.ToArray(),
|
|
Colors.Transparent));
|
|
Colors.Transparent));
|
|
}
|
|
}
|
|
|
|
|
|
@@ -627,28 +419,12 @@ namespace PixiEditor.ViewModels
|
|
ClipboardController.PasteFromClipboard();
|
|
ClipboardController.PasteFromClipboard();
|
|
}
|
|
}
|
|
|
|
|
|
- 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);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public void SelectAll(object parameter)
|
|
public void SelectAll(object parameter)
|
|
{
|
|
{
|
|
SelectTool select = new SelectTool();
|
|
SelectTool select = new SelectTool();
|
|
ActiveSelection.SetSelection(select.GetAllSelection(), SelectionType.New);
|
|
ActiveSelection.SetSelection(select.GetAllSelection(), SelectionType.New);
|
|
}
|
|
}
|
|
|
|
|
|
- private bool CanSelectAll(object property)
|
|
|
|
- {
|
|
|
|
- return BitmapManager.ActiveDocument != null && BitmapManager.ActiveDocument.Layers.Count > 0;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public bool DocumentIsNotNull(object property)
|
|
public bool DocumentIsNotNull(object property)
|
|
{
|
|
{
|
|
return BitmapManager.ActiveDocument != null;
|
|
return BitmapManager.ActiveDocument != null;
|
|
@@ -659,11 +435,6 @@ namespace PixiEditor.ViewModels
|
|
ActiveSelection?.Clear();
|
|
ActiveSelection?.Clear();
|
|
}
|
|
}
|
|
|
|
|
|
- private bool SelectionIsNotEmpty(object property)
|
|
|
|
- {
|
|
|
|
- return ActiveSelection?.SelectedPoints != null && ActiveSelection.SelectedPoints.Count > 0;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public void SetTool(object parameter)
|
|
public void SetTool(object parameter)
|
|
{
|
|
{
|
|
SetActiveTool((ToolType)parameter);
|
|
SetActiveTool((ToolType)parameter);
|
|
@@ -674,17 +445,6 @@ namespace PixiEditor.ViewModels
|
|
BitmapManager.ActiveDocument.Layers[(int)parameter].IsRenaming = true;
|
|
BitmapManager.ActiveDocument.Layers[(int)parameter].IsRenaming = true;
|
|
}
|
|
}
|
|
|
|
|
|
- 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;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public void KeyDown(object parameter)
|
|
public void KeyDown(object parameter)
|
|
{
|
|
{
|
|
KeyEventArgs args = (KeyEventArgs)parameter;
|
|
KeyEventArgs args = (KeyEventArgs)parameter;
|
|
@@ -697,11 +457,6 @@ namespace PixiEditor.ViewModels
|
|
ShortcutController.KeyPressed(args.Key, Keyboard.Modifiers);
|
|
ShortcutController.KeyPressed(args.Key, Keyboard.Modifiers);
|
|
}
|
|
}
|
|
|
|
|
|
- private void MouseController_StoppedRecordingChanges(object sender, EventArgs e)
|
|
|
|
- {
|
|
|
|
- TriggerNewUndoChange(BitmapManager.SelectedTool);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public void TriggerNewUndoChange(Tool toolUsed)
|
|
public void TriggerNewUndoChange(Tool toolUsed)
|
|
{
|
|
{
|
|
if (BitmapManager.IsOperationTool(toolUsed)
|
|
if (BitmapManager.IsOperationTool(toolUsed)
|
|
@@ -718,18 +473,7 @@ namespace PixiEditor.ViewModels
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private void BitmapUtility_BitmapChanged(object sender, BitmapChangedEventArgs e)
|
|
|
|
- {
|
|
|
|
- ChangesController.AddChanges(new LayerChange(e.PixelsChanged, e.ChangedLayerIndex),
|
|
|
|
- new LayerChange(e.OldPixelsValues, e.ChangedLayerIndex));
|
|
|
|
- unsavedDocumentModified = true;
|
|
|
|
- if (BitmapManager.IsOperationTool())
|
|
|
|
- {
|
|
|
|
- AddSwatch(PrimaryColor);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public void SwapColors(object parameter)
|
|
|
|
|
|
+ public void SwapColors(object parameter)
|
|
{
|
|
{
|
|
Color tmp = PrimaryColor;
|
|
Color tmp = PrimaryColor;
|
|
PrimaryColor = SecondaryColor;
|
|
PrimaryColor = SecondaryColor;
|
|
@@ -801,42 +545,6 @@ namespace PixiEditor.ViewModels
|
|
SetToolCursor(tool.ToolType);
|
|
SetToolCursor(tool.ToolType);
|
|
}
|
|
}
|
|
|
|
|
|
- private void SetToolCursor(ToolType tool)
|
|
|
|
- {
|
|
|
|
- if (tool != ToolType.None)
|
|
|
|
- {
|
|
|
|
- ToolCursor = BitmapManager.SelectedTool.Cursor;
|
|
|
|
- }
|
|
|
|
- else
|
|
|
|
- {
|
|
|
|
- ToolCursor = Cursors.Arrow;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- 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);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- // 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;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
// this is public for testing.
|
|
// this is public for testing.
|
|
public void MouseHook_OnMouseUp(object sender, Point p)
|
|
public void MouseHook_OnMouseUp(object sender, Point p)
|
|
{
|
|
{
|
|
@@ -845,26 +553,8 @@ namespace PixiEditor.ViewModels
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
- /// Method connected with command, it executes tool "activity"
|
|
|
|
- /// </summary>
|
|
|
|
- /// <param name="parameter"></param>
|
|
|
|
- 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>
|
|
|
|
- /// Generates new Layer and sets it as active one
|
|
|
|
|
|
+ /// Generates new Layer and sets it as active one.
|
|
/// </summary>
|
|
/// </summary>
|
|
- /// <param name="parameter"></param>
|
|
|
|
public void OpenNewFilePopup(object parameter)
|
|
public void OpenNewFilePopup(object parameter)
|
|
{
|
|
{
|
|
NewFileDialog newFile = new NewFileDialog();
|
|
NewFileDialog newFile = new NewFileDialog();
|
|
@@ -877,7 +567,6 @@ namespace PixiEditor.ViewModels
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Opens file from path.
|
|
/// Opens file from path.
|
|
/// </summary>
|
|
/// </summary>
|
|
- /// <param name="path"></param>
|
|
|
|
public void OpenFile(string path)
|
|
public void OpenFile(string path)
|
|
{
|
|
{
|
|
ImportFileDialog dialog = new ImportFileDialog();
|
|
ImportFileDialog dialog = new ImportFileDialog();
|
|
@@ -929,12 +618,9 @@ namespace PixiEditor.ViewModels
|
|
return BitmapManager.ActiveDocument != null && BitmapManager.ActiveDocument.Layers.Count > 0;
|
|
return BitmapManager.ActiveDocument != null && BitmapManager.ActiveDocument.Layers.Count > 0;
|
|
}
|
|
}
|
|
|
|
|
|
- #region Undo/Redo
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
- /// Undo last action
|
|
|
|
|
|
+ /// Undo last action.
|
|
/// </summary>
|
|
/// </summary>
|
|
- /// <param name="parameter"></param>
|
|
|
|
public void Undo(object parameter)
|
|
public void Undo(object parameter)
|
|
{
|
|
{
|
|
Deselect(null);
|
|
Deselect(null);
|
|
@@ -942,42 +628,352 @@ namespace PixiEditor.ViewModels
|
|
}
|
|
}
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
- /// Returns true if undo can be done.
|
|
|
|
|
|
+ /// Redo last action.
|
|
/// </summary>
|
|
/// </summary>
|
|
- /// <param name="property"></param>
|
|
|
|
- /// <returns></returns>
|
|
|
|
- private bool CanUndo(object property)
|
|
|
|
|
|
+ public void Redo(object parameter)
|
|
{
|
|
{
|
|
- return UndoManager.CanUndo;
|
|
|
|
|
|
+ UndoManager.Redo();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void RestartApplication(object parameter)
|
|
|
|
+ {
|
|
|
|
+ Process.Start(Path.Join(AppDomain.CurrentDomain.BaseDirectory, "PixiEditor.UpdateInstaller.exe"));
|
|
|
|
+ Application.Current.Shutdown();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void InitUpdateChecker()
|
|
|
|
+ {
|
|
|
|
+ Assembly 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)
|
|
|
|
+ {
|
|
|
|
+ int increment = (int)parameter;
|
|
|
|
+ int newSize = BitmapManager.ToolSize + increment;
|
|
|
|
+ if (newSize > 0)
|
|
|
|
+ {
|
|
|
|
+ BitmapManager.ToolSize = newSize;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void OpenHyperlink(object parameter)
|
|
|
|
+ {
|
|
|
|
+ if (parameter == null)
|
|
|
|
+ {
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ string url = (string)parameter;
|
|
|
|
+ ProcessStartInfo processInfo = new ProcessStartInfo
|
|
|
|
+ {
|
|
|
|
+ FileName = url,
|
|
|
|
+ UseShellExecute = true
|
|
|
|
+ };
|
|
|
|
+ Process.Start(processInfo);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void CenterContent(object property)
|
|
|
|
+ {
|
|
|
|
+ BitmapManager.ActiveDocument.CenterContent();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void CloseWindow(object property)
|
|
|
|
+ {
|
|
|
|
+ if (!(property is CancelEventArgs))
|
|
|
|
+ {
|
|
|
|
+ throw new ArgumentException();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ ((CancelEventArgs)property).Cancel = true;
|
|
|
|
+
|
|
|
|
+ ConfirmationType result = ConfirmationType.No;
|
|
|
|
+ if (unsavedDocumentModified)
|
|
|
|
+ {
|
|
|
|
+ result = ConfirmationDialog.Show(ConfirmationDialogMessage);
|
|
|
|
+ if (result == ConfirmationType.Yes)
|
|
|
|
+ {
|
|
|
|
+ SaveDocument(null);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if (result != ConfirmationType.Canceled)
|
|
|
|
+ {
|
|
|
|
+ ((CancelEventArgs)property).Cancel = false;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private async void OnStartup(object parameter)
|
|
|
|
+ {
|
|
|
|
+ string lastArg = Environment.GetCommandLineArgs().Last();
|
|
|
|
+ if (Importer.IsSupportedFile(lastArg) && File.Exists(lastArg))
|
|
|
|
+ {
|
|
|
|
+ Open(lastArg);
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ OpenNewFilePopup(null);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ await CheckForUpdate();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void BitmapManager_DocumentChanged(object sender, DocumentChangedEventArgs e)
|
|
|
|
+ {
|
|
|
|
+ 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)
|
|
|
|
+ {
|
|
|
|
+ ConfirmationType 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)
|
|
|
|
+ {
|
|
|
|
+ bool 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 SelectionIsNotEmpty(object property)
|
|
|
|
+ {
|
|
|
|
+ return ActiveSelection?.SelectedPoints != null && ActiveSelection.SelectedPoints.Count > 0;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private bool CanSelectAll(object property)
|
|
|
|
+ {
|
|
|
|
+ return BitmapManager.ActiveDocument != null && BitmapManager.ActiveDocument.Layers.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;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void MouseController_StoppedRecordingChanges(object sender, EventArgs e)
|
|
|
|
+ {
|
|
|
|
+ TriggerNewUndoChange(BitmapManager.SelectedTool);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void BitmapUtility_BitmapChanged(object sender, BitmapChangedEventArgs e)
|
|
|
|
+ {
|
|
|
|
+ ChangesController.AddChanges(
|
|
|
|
+ new LayerChange(e.PixelsChanged, e.ChangedLayerIndex),
|
|
|
|
+ new LayerChange(e.OldPixelsValues, e.ChangedLayerIndex));
|
|
|
|
+ unsavedDocumentModified = true;
|
|
|
|
+ if (BitmapManager.IsOperationTool())
|
|
|
|
+ {
|
|
|
|
+ AddSwatch(PrimaryColor);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void SetToolCursor(ToolType tool)
|
|
|
|
+ {
|
|
|
|
+ if (tool != ToolType.None)
|
|
|
|
+ {
|
|
|
|
+ ToolCursor = BitmapManager.SelectedTool.Cursor;
|
|
|
|
+ }
|
|
|
|
+ else
|
|
|
|
+ {
|
|
|
|
+ ToolCursor = Cursors.Arrow;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ 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);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ // 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>
|
|
/// <summary>
|
|
- /// Redo last action
|
|
|
|
|
|
+ /// Method connected with command, it executes tool "activity".
|
|
/// </summary>
|
|
/// </summary>
|
|
- /// <param name="parameter"></param>
|
|
|
|
- public void Redo(object parameter)
|
|
|
|
|
|
+ private void MouseMove(object parameter)
|
|
{
|
|
{
|
|
- UndoManager.Redo();
|
|
|
|
|
|
+ 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>
|
|
/// <summary>
|
|
/// Returns true if redo can be done.
|
|
/// Returns true if redo can be done.
|
|
/// </summary>
|
|
/// </summary>
|
|
- /// <param name="property"></param>
|
|
|
|
- /// <returns></returns>
|
|
|
|
private bool CanRedo(object property)
|
|
private bool CanRedo(object property)
|
|
{
|
|
{
|
|
return UndoManager.CanRedo;
|
|
return UndoManager.CanRedo;
|
|
}
|
|
}
|
|
|
|
|
|
- #endregion
|
|
|
|
-
|
|
|
|
- #region SaveFile
|
|
|
|
-
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Generates export dialog or saves directly if save data is known.
|
|
/// Generates export dialog or saves directly if save data is known.
|
|
/// </summary>
|
|
/// </summary>
|
|
- /// <param name="parameter"></param>
|
|
|
|
private void ExportFile(object parameter)
|
|
private void ExportFile(object parameter)
|
|
{
|
|
{
|
|
System.Windows.Media.Imaging.WriteableBitmap bitmap = BitmapManager.GetCombinedLayersBitmap();
|
|
System.Windows.Media.Imaging.WriteableBitmap bitmap = BitmapManager.GetCombinedLayersBitmap();
|
|
@@ -987,13 +983,9 @@ namespace PixiEditor.ViewModels
|
|
/// <summary>
|
|
/// <summary>
|
|
/// Returns true if file save is possible.
|
|
/// Returns true if file save is possible.
|
|
/// </summary>
|
|
/// </summary>
|
|
- /// <param name="property"></param>
|
|
|
|
- /// <returns></returns>
|
|
|
|
private bool CanSave(object property)
|
|
private bool CanSave(object property)
|
|
{
|
|
{
|
|
return BitmapManager.ActiveDocument != null;
|
|
return BitmapManager.ActiveDocument != null;
|
|
}
|
|
}
|
|
-
|
|
|
|
- #endregion
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|