Browse Source

Removed tool enum

CPK 4 years ago
parent
commit
8148e14476

+ 0 - 0
PixiEditor/Images/BucketImage.png → PixiEditor/Images/FloodFillImage.png


+ 1 - 1
PixiEditor/Models/Controllers/BitmapOperationsUtility.cs

@@ -58,7 +58,7 @@ namespace PixiEditor.Models.Controllers
         /// <param name="tool">Tool to execute.</param>
         public void ExecuteTool(Coordinates newPos, List<Coordinates> mouseMove, BitmapOperationTool tool)
         {
-            if (Manager.ActiveDocument != null && tool != null && tool.ToolType != ToolType.None)
+            if (Manager.ActiveDocument != null && tool != null/* && tool.ToolType != ToolType.None*/)
             {
                 if (Manager.ActiveDocument.Layers.Count == 0 || mouseMove.Count == 0)
                 {

+ 0 - 2
PixiEditor/Models/Tools/ShapeTool.cs

@@ -18,8 +18,6 @@ namespace PixiEditor.Models.Tools
             Toolbar = new BasicShapeToolbar();
         }
 
-        public abstract override ToolType ToolType { get; }
-
         public abstract override LayerChange[] Use(Layer layer, Coordinates[] coordinates, Color color);
 
         protected IEnumerable<Coordinates> GetThickShape(IEnumerable<Coordinates> shape, int thickness)

+ 8 - 5
PixiEditor/Models/Tools/Tool.cs

@@ -1,4 +1,5 @@
-using System.Windows.Input;
+using System;
+using System.Windows.Input;
 using PixiEditor.Helpers;
 using PixiEditor.Models.Controllers;
 using PixiEditor.Models.Tools.ToolSettings;
@@ -9,11 +10,13 @@ namespace PixiEditor.Models.Tools
     public abstract class Tool : NotifyableObject
     {
         private bool isActive;
-        private string actionDisplay = "";
-
-        public abstract ToolType ToolType { get; }
+        private string actionDisplay = string.Empty;
+
+        public string Name => GetType().Name.Replace("Tool", string.Empty);
+
+        public Type Type => GetType();
 
-        public string ImagePath => $"/Images/{ToolType}Image.png";
+        public string ImagePath => $"/Images/{Name}Image.png";
 
         public bool HideHighlight { get; set; } = false;
 

+ 0 - 19
PixiEditor/Models/Tools/ToolType.cs

@@ -1,19 +0,0 @@
-namespace PixiEditor.Models.Tools
-{
-    public enum ToolType
-    {
-        None,
-        MoveViewport,
-        Move,
-        Pen,
-        Select,
-        Bucket,
-        Line,
-        Circle,
-        Rectangle,
-        Eraser,
-        Brightness,
-        ColorPicker,
-        Zoom
-    }
-}

+ 0 - 2
PixiEditor/Models/Tools/Tools/BrightnessTool.cs

@@ -26,8 +26,6 @@ namespace PixiEditor.Models.Tools.Tools
             Toolbar = new BrightnessToolToolbar(CorrectionFactor);
         }
 
-        public override ToolType ToolType => ToolType.Brightness;
-
         public BrightnessMode Mode { get; set; } = BrightnessMode.Default;
 
         public override void OnRecordingLeftMouseDown(MouseEventArgs e)

+ 0 - 2
PixiEditor/Models/Tools/Tools/CircleTool.cs

@@ -19,8 +19,6 @@ namespace PixiEditor.Models.Tools.Tools
             Tooltip = "Draws circle on canvas (C). Hold Shift to draw even circle.";
         }
 
-        public override ToolType ToolType => ToolType.Circle;
-
         public override void OnKeyDown(KeyEventArgs e)
         {
             if (e.Key == Key.LeftShift)

+ 0 - 2
PixiEditor/Models/Tools/Tools/ColorPickerTool.cs

@@ -14,8 +14,6 @@ namespace PixiEditor.Models.Tools.Tools
             Tooltip = "Swaps primary color with selected on canvas. (O)";
         }
 
-        public override ToolType ToolType => ToolType.ColorPicker;
-
         public override void Use(Coordinates[] coordinates)
         {
             ViewModelMain.Current.ColorsSubViewModel.PrimaryColor = GetColorUnderMouse();

+ 0 - 2
PixiEditor/Models/Tools/Tools/EraserTool.cs

@@ -18,8 +18,6 @@ namespace PixiEditor.Models.Tools.Tools
             Toolbar = new BasicToolbar();
         }
 
-        public override ToolType ToolType => ToolType.Eraser;
-
         public override LayerChange[] Use(Layer layer, Coordinates[] coordinates, Color color)
         {
             return Erase(layer, coordinates, Toolbar.GetSetting<SizeSetting>("ToolSize").Value);

+ 0 - 2
PixiEditor/Models/Tools/Tools/FloodFill.cs

@@ -15,8 +15,6 @@ namespace PixiEditor.Models.Tools.Tools
             Tooltip = "Fills area with color. (G)";
         }
 
-        public override ToolType ToolType => ToolType.Bucket;
-
         public override LayerChange[] Use(Layer layer, Coordinates[] coordinates, Color color)
         {
             return Only(ForestFire(layer, coordinates[0], color), layer);

+ 0 - 2
PixiEditor/Models/Tools/Tools/LineTool.cs

@@ -23,8 +23,6 @@ namespace PixiEditor.Models.Tools.Tools
             circleTool = new CircleTool();
         }
 
-        public override ToolType ToolType => ToolType.Line;
-
         public override void OnKeyDown(KeyEventArgs e)
         {
             if (e.Key == Key.LeftShift)

+ 0 - 2
PixiEditor/Models/Tools/Tools/MoveTool.cs

@@ -40,8 +40,6 @@ namespace PixiEditor.Models.Tools.Tools
 
         public bool MoveAll { get; set; } = false;
 
-        public override ToolType ToolType => ToolType.Move;
-
         public override void OnKeyDown(KeyEventArgs e)
         {
             if (e.Key == Key.LeftCtrl)

+ 0 - 2
PixiEditor/Models/Tools/Tools/MoveViewportTool.cs

@@ -16,8 +16,6 @@ namespace PixiEditor.Models.Tools.Tools
             ActionDisplay = "Click and move to pan viewport.";
             Tooltip = "Move viewport. (H)";
         }
-
-        public override ToolType ToolType => ToolType.MoveViewport;
 
         public override void OnMouseDown(MouseEventArgs e)
         {

+ 0 - 2
PixiEditor/Models/Tools/Tools/PenTool.cs

@@ -24,8 +24,6 @@ namespace PixiEditor.Models.Tools.Tools
             lineTool = new LineTool();
         }
 
-        public override ToolType ToolType => ToolType.Pen;
-
         public override LayerChange[] Use(Layer layer, Coordinates[] coordinates, Color color)
         {
             Coordinates startingCords = coordinates.Length > 1 ? coordinates[1] : coordinates[0];

+ 0 - 2
PixiEditor/Models/Tools/Tools/RectangleTool.cs

@@ -19,8 +19,6 @@ namespace PixiEditor.Models.Tools.Tools
             Tooltip = "Draws rectangle on canvas (R). Hold Shift to draw square.";
         }
 
-        public override ToolType ToolType => ToolType.Rectangle;
-
         public bool Filled { get; set; } = false;
 
         public override void OnKeyDown(KeyEventArgs e)

+ 0 - 2
PixiEditor/Models/Tools/Tools/SelectTool.cs

@@ -26,8 +26,6 @@ namespace PixiEditor.Models.Tools.Tools
 
         public SelectionType SelectionType { get; set; } = SelectionType.Add;
 
-        public override ToolType ToolType => ToolType.Select;
-
         public override void OnRecordingLeftMouseDown(MouseEventArgs e)
         {
             Enum.TryParse((Toolbar.GetSetting<DropdownSetting>("SelectMode")?.Value as ComboBoxItem)?.Content as string, out SelectionType selectionType);

+ 0 - 2
PixiEditor/Models/Tools/Tools/ZoomTool.cs

@@ -24,8 +24,6 @@ namespace PixiEditor.Models.Tools.Tools
             pixelsPerZoomMultiplier = workAreaWidth / ZoomSensitivityMultiplier;
         }
 
-        public override ToolType ToolType => ToolType.Zoom;
-
         public override void OnKeyDown(KeyEventArgs e)
         {
             if (e.Key == Key.LeftAlt)

+ 1 - 1
PixiEditor/PixiEditor.csproj

@@ -60,7 +60,7 @@
   </ItemGroup>
   <ItemGroup>
     <Resource Include="Images\AnchorDot.png" />
-    <Resource Include="Images\BucketImage.png" />
+    <Resource Include="Images\FloodFillImage.png" />
     <Resource Include="Images\CircleImage.png" />
     <Resource Include="Images\EraserImage.png" />
     <Resource Include="Images\BrightnessImage.png" />

+ 14 - 8
PixiEditor/ViewModels/SubViewModels/Main/ToolsViewModel.cs

@@ -1,4 +1,5 @@
-using System.Collections.ObjectModel;
+using System;
+using System.Collections.ObjectModel;
 using System.Linq;
 using System.Windows.Input;
 using PixiEditor.Helpers;
@@ -41,12 +42,17 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
                 new CircleTool(), new RectangleTool(), new EraserTool(), new ColorPickerTool(), new BrightnessTool(),
                 new ZoomTool()
             };
-            SetActiveTool(ToolType.Move);
+            SetActiveTool(typeof(MoveTool));
         }
 
-        public void SetActiveTool(ToolType tool)
+        public void SetActiveTool(Type toolType)
         {
-            Tool foundTool = ToolSet.First(x => x.ToolType == tool);
+            if (toolType == null)
+            {
+                return;
+            }
+
+            Tool foundTool = ToolSet.First(x => x.GetType() == toolType);
             SetActiveTool(foundTool);
         }
 
@@ -61,12 +67,12 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
             tool.IsActive = true;
             LastActionTool = Owner.BitmapManager.SelectedTool;
             Owner.BitmapManager.SetActiveTool(tool);
-            SetToolCursor(tool.ToolType);
+            SetToolCursor(tool.GetType());
         }
 
         public void SetTool(object parameter)
         {
-            SetActiveTool((ToolType)parameter);
+            SetActiveTool((Type)parameter);
         }
 
         private void ChangeToolSize(object parameter)
@@ -79,9 +85,9 @@ namespace PixiEditor.ViewModels.SubViewModels.Main
             }
         }
 
-        private void SetToolCursor(ToolType tool)
+        private void SetToolCursor(Type tool)
         {
-            if (tool != ToolType.None)
+            if (tool != null)
             {
                 ToolCursor = Owner.BitmapManager.SelectedTool.Cursor;
             }

+ 19 - 12
PixiEditor/ViewModels/ViewModelMain.cs

@@ -15,6 +15,7 @@ using PixiEditor.Models.Events;
 using PixiEditor.Models.IO;
 using PixiEditor.Models.Position;
 using PixiEditor.Models.Tools;
+using PixiEditor.Models.Tools.Tools;
 using PixiEditor.Models.UserPreferences;
 using PixiEditor.ViewModels.SubViewModels.Main;
 
@@ -94,18 +95,18 @@ namespace PixiEditor.ViewModels
                 Shortcuts = new List<Shortcut>
                 {
                     // Tools
-                    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),
+                    CreateToolShortcut<PenTool>(Key.B),
+                    CreateToolShortcut<EraserTool>(Key.E),
+                    CreateToolShortcut<ColorPickerTool>(Key.O),
+                    CreateToolShortcut<RectangleTool>(Key.R),
+                    CreateToolShortcut<CircleTool>(Key.C),
+                    CreateToolShortcut<LineTool>(Key.L),
+                    CreateToolShortcut<FloodFill>(Key.G),
+                    CreateToolShortcut<BrightnessTool>(Key.U),
+                    CreateToolShortcut<MoveTool>(Key.V),
+                    CreateToolShortcut<SelectTool>(Key.M),
+                    CreateToolShortcut<ZoomTool>(Key.Z),
+                    CreateToolShortcut<MoveViewportTool>(Key.H),
                     new Shortcut(Key.OemPlus, ViewportSubViewModel.ZoomCommand, 115),
                     new Shortcut(Key.OemMinus, ViewportSubViewModel.ZoomCommand, 85),
                     new Shortcut(Key.OemOpenBrackets, ToolsSubViewModel.ChangeToolSizeCommand, -1),
@@ -156,6 +157,12 @@ namespace PixiEditor.ViewModels
             return BitmapManager.ActiveDocument != null;
         }
 
+        private Shortcut CreateToolShortcut<T>(Key key, ModifierKeys modifier = ModifierKeys.None)
+            where T : Tool
+        {
+            return new Shortcut(key, ToolsSubViewModel.SelectToolCommand, typeof(T), modifier);
+        }
+
         private void CloseWindow(object property)
         {
             if (!(property is CancelEventArgs))

+ 1 - 1
PixiEditor/Views/MainWindow.xaml

@@ -208,7 +208,7 @@
                                 Style="{StaticResource ToolButtonStyle}"
                                 Command="{Binding Path=DataContext.ToolsSubViewModel.SelectToolCommand,
                             RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
-                                CommandParameter="{Binding ToolType}" ToolTip="{Binding Tooltip}">
+                                CommandParameter="{Binding Type}" ToolTip="{Binding Tooltip}">
                             <Button.Background>
                                 <ImageBrush ImageSource="{Binding ImagePath}" Stretch="Uniform" />
                             </Button.Background>

+ 2 - 2
PixiEditor/Views/UserControls/DrawingViewPort.xaml

@@ -4,7 +4,7 @@
              xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
              xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
              xmlns:local="clr-namespace:PixiEditor.Views.UserControls" 
-             xmlns:tools="clr-namespace:PixiEditor.Models.Tools"
+             xmlns:tools="clr-namespace:PixiEditor.Models.Tools.Tools"
              xmlns:vws="clr-namespace:PixiEditor.Views" 
              xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
              xmlns:behaviors="clr-namespace:PixiEditor.Helpers.Behaviours" xmlns:converters="clr-namespace:PixiEditor.Helpers.Converters"
@@ -19,7 +19,7 @@
                           x:Name="DrawingPanel"
                           CenterOnStart="True" Cursor="{Binding Cursor, ElementName=uc}" 
                           MiddleMouseClickedCommand="{Binding MiddleMouseClickedCommand, ElementName=uc}" 
-                          MiddleMouseClickedCommandParameter="{x:Static tools:ToolType.MoveViewport}"
+                          MiddleMouseClickedCommandParameter="{x:Type tools:MoveViewportTool}"
                           ViewportPosition="{Binding ViewportPosition, ElementName=uc, Mode=TwoWay}">
             <i:Interaction.Triggers>
                 <i:EventTrigger EventName="MouseMove">