Browse Source

Toolbar and rest of tools ported

Krzysztof Krysiński 2 years ago
parent
commit
e1c984df9b

+ 8 - 4
src/PixiEditor.Avalonia/PixiEditor.Avalonia/Models/DocumentModels/UpdateableChangeExecutors/EraserToolExecutor.cs

@@ -5,6 +5,7 @@ using PixiEditor.DrawingApi.Core.ColorsImpl;
 using PixiEditor.DrawingApi.Core.Numerics;
 using PixiEditor.Extensions.Palettes;
 using PixiEditor.Models.Containers;
+using PixiEditor.Models.Containers.Toolbars;
 using PixiEditor.Models.Containers.Tools;
 using PixiEditor.Models.Enums;
 
@@ -21,8 +22,10 @@ internal class EraserToolExecutor : UpdateableChangeExecutor
     {
         IStructureMemberHandler? member = document!.SelectedStructureMember;
         IEraserToolHandler? eraserTool = GetHandler<IEraserToolHandler>();
-        BasicToolbar? toolbar = eraserTool?.Toolbar as BasicToolbar;
-        if (vm is null || eraserTool is null || member is null || toolbar is null)
+        IBasicToolbar? toolbar = eraserTool?.Toolbar as IBasicToolbar;
+        IColorsHandler? colorsHandler = GetHandler<IColorsHandler>();
+
+        if (colorsHandler is null || eraserTool is null || member is null || toolbar is null)
             return ExecutionState.Error;
         drawOnMask = member is ILayerHandler layer ? layer.ShouldDrawOnMask : true;
         if (drawOnMask && !member.HasMaskBindable)
@@ -30,11 +33,12 @@ internal class EraserToolExecutor : UpdateableChangeExecutor
         if (!drawOnMask && member is not ILayerHandler)
             return ExecutionState.Error;
 
+
         guidValue = member.GuidValue;
-        color = vm.ColorsSubViewModel.PrimaryColor;
+        color = GetHandler<IColorsHandler>().PrimaryColor;
         toolSize = toolbar.ToolSize;
 
-        vm.ColorsSubViewModel.AddSwatch(new PaletteColor(color.R, color.G, color.B));
+        colorsHandler.AddSwatch(new PaletteColor(color.R, color.G, color.B));
         IAction? action = new LineBasedPen_Action(guidValue, DrawingApi.Core.ColorsImpl.Colors.Transparent, controller!.LastPixelPosition, toolSize, true,
             drawOnMask);
         internals!.ActionAccumulator.AddActions(action);

+ 2 - 1
src/PixiEditor.Avalonia/PixiEditor.Avalonia/Models/DocumentModels/UpdateableChangeExecutors/PenToolExecutor.cs

@@ -4,6 +4,7 @@ using PixiEditor.DrawingApi.Core.ColorsImpl;
 using PixiEditor.DrawingApi.Core.Numerics;
 using PixiEditor.Extensions.Palettes;
 using PixiEditor.Models.Containers;
+using PixiEditor.Models.Containers.Toolbars;
 using PixiEditor.Models.Containers.Tools;
 using PixiEditor.Models.Enums;
 
@@ -23,7 +24,7 @@ internal class PenToolExecutor : UpdateableChangeExecutor
         IColorsHandler? colorsHandler = GetHandler<IColorsHandler>();
 
         IPenToolHandler? penTool = GetHandler<IPenToolHandler>();
-        if (colorsHandler is null || penTool is null || member is null || penTool?.Toolbar is not BasicToolbar toolbar)
+        if (colorsHandler is null || penTool is null || member is null || penTool?.Toolbar is not IBasicToolbar toolbar)
             return ExecutionState.Error;
         drawOnMask = member is not ILayerHandler layer || layer.ShouldDrawOnMask;
         if (drawOnMask && !member.HasMaskBindable)

+ 2 - 1
src/PixiEditor.Avalonia/PixiEditor.Avalonia/Models/DocumentModels/UpdateableChangeExecutors/SelectToolExecutor.cs

@@ -2,6 +2,7 @@
 using PixiEditor.ChangeableDocument.Actions.Generated;
 using PixiEditor.ChangeableDocument.Enums;
 using PixiEditor.DrawingApi.Core.Numerics;
+using PixiEditor.Models.Containers.Toolbars;
 using PixiEditor.Models.Containers.Tools;
 using PixiEditor.Models.Enums;
 
@@ -10,7 +11,7 @@ namespace PixiEditor.Models.DocumentModels.UpdateableChangeExecutors;
 internal class SelectToolExecutor : UpdateableChangeExecutor
 {
     private ISelectToolHandler? toolViewModel;
-    private Toolbar? toolbar;
+    private IToolbar? toolbar;
     private VecI startPos;
     private SelectionShape selectShape;
     private SelectionMode selectMode;

+ 3 - 4
src/PixiEditor.Avalonia/PixiEditor.Avalonia/Models/DocumentModels/UpdateableChangeExecutors/ShapeToolExecutor.cs

@@ -3,12 +3,11 @@ using PixiEditor.ChangeableDocument.Actions;
 using PixiEditor.DrawingApi.Core.ColorsImpl;
 using PixiEditor.DrawingApi.Core.Numerics;
 using PixiEditor.Extensions.Palettes;
+using PixiEditor.Helpers.Extensions;
 using PixiEditor.Models.Containers;
+using PixiEditor.Models.Containers.Toolbars;
 using PixiEditor.Models.Containers.Tools;
 using PixiEditor.Models.Enums;
-using PixiEditor.ViewModels.SubViewModels.Document;
-using PixiEditor.ViewModels.SubViewModels.Tools;
-using PixiEditor.ViewModels.SubViewModels.Tools.ToolSettings.Toolbars;
 
 namespace PixiEditor.Models.DocumentModels.UpdateableChangeExecutors;
 
@@ -33,7 +32,7 @@ internal abstract class ShapeToolExecutor<T> : UpdateableChangeExecutor where T
     {
         IColorsHandler? colorsVM = GetHandler<IColorsHandler>();
         toolViewModel = GetHandler<T>();
-        BasicShapeToolbar? toolbar = (BasicShapeToolbar?)toolViewModel?.Toolbar;
+        IBasicShapeToolbar? toolbar = (IBasicShapeToolbar?)toolViewModel?.Toolbar;
         IStructureMemberHandler? member = document?.SelectedStructureMember;
         if (colorsVM is null || toolbar is null || member is null)
             return ExecutionState.Error;

+ 3 - 0
src/PixiEditor.Avalonia/PixiEditor.Avalonia/Models/Handlers/IToolHandler.cs

@@ -1,6 +1,7 @@
 using Avalonia.Input;
 using PixiEditor.DrawingApi.Core.Numerics;
 using PixiEditor.Extensions.Common.Localization;
+using PixiEditor.Models.Containers.Toolbars;
 
 namespace PixiEditor.Models.Containers;
 
@@ -15,6 +16,8 @@ internal interface IToolHandler : IHandler
 
     public bool HideHighlight { get; }
 
+    public IToolbar Toolbar { get; set; }
+
     public abstract LocalizedString Tooltip { get; }
 
     /// <summary>

+ 9 - 0
src/PixiEditor.Avalonia/PixiEditor.Avalonia/Models/Handlers/Toolbars/IBasicShapeToolbar.cs

@@ -0,0 +1,9 @@
+using Avalonia.Media;
+
+namespace PixiEditor.Models.Containers.Toolbars;
+
+public interface IBasicShapeToolbar : IBasicToolbar
+{
+    public bool Fill { get; set; }
+    public Color FillColor { get; set; }
+}

+ 6 - 0
src/PixiEditor.Avalonia/PixiEditor.Avalonia/Models/Handlers/Toolbars/IBasicToolbar.cs

@@ -0,0 +1,6 @@
+namespace PixiEditor.Models.Containers.Toolbars;
+
+public interface IBasicToolbar : IToolbar
+{
+    public int ToolSize { get; set; }
+}

+ 5 - 0
src/PixiEditor.Avalonia/PixiEditor.Avalonia/ViewModels/SubViewModels/ToolsViewModel.cs

@@ -13,4 +13,9 @@ internal class ToolsViewModel : SubViewModel<MainViewModel>, IToolsHandler
     {
         throw new NotImplementedException();
     }
+
+    public void RestorePreviousTool()
+    {
+        throw new NotImplementedException();
+    }
 }