Skip to content

Commit

Permalink
fix merge conflict
Browse files Browse the repository at this point in the history
  • Loading branch information
Equbuxu committed Dec 25, 2020
2 parents 146bde0 + 0b8a564 commit 319d928
Show file tree
Hide file tree
Showing 27 changed files with 118 additions and 127 deletions.
File renamed without changes
2 changes: 1 addition & 1 deletion PixiEditor/Models/Controllers/BitmapOperationsUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void DeletePixels(Layer[] layers, Coordinates[] pixels)
/// <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)
{
if (Manager.ActiveDocument.Layers.Count == 0 || mouseMove.Count == 0)
{
Expand Down
2 changes: 0 additions & 2 deletions PixiEditor/Models/Tools/ShapeTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ public ShapeTool()
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)
Expand Down
95 changes: 54 additions & 41 deletions PixiEditor/Models/Tools/Tool.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,34 @@
using System.Windows.Input;
using PixiEditor.Helpers;
using System;
using System.Windows.Input;
using PixiEditor.Helpers;
using PixiEditor.Models.Controllers;
using PixiEditor.Models.Tools.ToolSettings;
using PixiEditor.Models.Tools.ToolSettings.Toolbars;

namespace PixiEditor.Models.Tools
{
public abstract class Tool : NotifyableObject
{
private bool isActive;
private string actionDisplay = "";

public abstract ToolType ToolType { get; }
using PixiEditor.Models.Tools.ToolSettings;
using PixiEditor.Models.Tools.ToolSettings.Toolbars;

namespace PixiEditor.Models.Tools
{
public abstract class Tool : NotifyableObject
{
protected string name;
private bool isActive;
private string actionDisplay = string.Empty;

public string ToolName
{
get
{
if (string.IsNullOrWhiteSpace(name))
{
return GetType().Name.Replace("Tool", string.Empty);
}

return name;
}
}

public string ImagePath => $"/Images/{ToolType}Image.png";
public string ImagePath => $"/Images/{ToolName}Image.png";

public bool HideHighlight { get; set; } = false;
public bool HideHighlight { get; set; } = false;

public string Tooltip { get; set; }

Expand All @@ -28,53 +41,53 @@ public string ActionDisplay
RaisePropertyChanged("ActionDisplay");
}
}

public bool IsActive
{
get => isActive;
set
{
isActive = value;
RaisePropertyChanged("IsActive");
}
}

public Cursor Cursor { get; set; } = Cursors.Arrow;

public Toolbar Toolbar { get; set; } = new EmptyToolbar();

public bool CanStartOutsideCanvas { get; set; } = false;


public bool IsActive
{
get => isActive;
set
{
isActive = value;
RaisePropertyChanged("IsActive");
}
}

public Cursor Cursor { get; set; } = Cursors.Arrow;

public Toolbar Toolbar { get; set; } = new EmptyToolbar();

public bool CanStartOutsideCanvas { get; set; } = false;

public virtual void OnMouseDown(MouseEventArgs e)
{
}

public virtual void OnMouseUp(MouseEventArgs e)
{
}


public virtual void OnKeyDown(KeyEventArgs e)
{
}

}

public virtual void OnKeyUp(KeyEventArgs e)
{
}

}

public virtual void OnRecordingLeftMouseDown(MouseEventArgs e)
{
}


public virtual void OnStoppedRecordingMouseUp(MouseEventArgs e)
{
}


public virtual void OnMouseMove(MouseEventArgs e)
{
}


public virtual void AfterAddedUndo(UndoManager undoManager)
{
}
}
}
}
19 changes: 0 additions & 19 deletions PixiEditor/Models/Tools/ToolType.cs

This file was deleted.

2 changes: 0 additions & 2 deletions PixiEditor/Models/Tools/Tools/BrightnessTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ public BrightnessTool()
Toolbar = new BrightnessToolToolbar(CorrectionFactor);
}

public override ToolType ToolType => ToolType.Brightness;

public BrightnessMode Mode { get; set; } = BrightnessMode.Default;

public override void OnRecordingLeftMouseDown(MouseEventArgs e)
Expand Down
2 changes: 0 additions & 2 deletions PixiEditor/Models/Tools/Tools/CircleTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ public CircleTool()
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)
Expand Down
2 changes: 0 additions & 2 deletions PixiEditor/Models/Tools/Tools/ColorPickerTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ public ColorPickerTool()
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();
Expand Down
2 changes: 0 additions & 2 deletions PixiEditor/Models/Tools/Tools/EraserTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ public EraserTool()
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);
Expand Down
2 changes: 0 additions & 2 deletions PixiEditor/Models/Tools/Tools/FloodFill.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ public FloodFill()
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);
Expand Down
2 changes: 0 additions & 2 deletions PixiEditor/Models/Tools/Tools/LineTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ public LineTool()
circleTool = new CircleTool();
}

public override ToolType ToolType => ToolType.Line;

public override void OnKeyDown(KeyEventArgs e)
{
if (e.Key == Key.LeftShift)
Expand Down
2 changes: 0 additions & 2 deletions PixiEditor/Models/Tools/Tools/MoveTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ public MoveTool()

public bool MoveAll { get; set; } = false;

public override ToolType ToolType => ToolType.Move;

public override void OnKeyDown(KeyEventArgs e)
{
if (e.Key == Key.LeftCtrl)
Expand Down
2 changes: 0 additions & 2 deletions PixiEditor/Models/Tools/Tools/MoveViewportTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ public MoveViewportTool()
ActionDisplay = "Click and move to pan viewport.";
Tooltip = "Move viewport. (H)";
}

public override ToolType ToolType => ToolType.MoveViewport;

public override void OnMouseDown(MouseEventArgs e)
{
Expand Down
2 changes: 0 additions & 2 deletions PixiEditor/Models/Tools/Tools/PenTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ public PenTool()
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];
Expand Down
2 changes: 0 additions & 2 deletions PixiEditor/Models/Tools/Tools/RectangleTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ public RectangleTool()
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)
Expand Down
2 changes: 0 additions & 2 deletions PixiEditor/Models/Tools/Tools/SelectTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ public SelectTool()

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);
Expand Down
2 changes: 0 additions & 2 deletions PixiEditor/Models/Tools/Tools/ZoomTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ public ZoomTool()
pixelsPerZoomMultiplier = workAreaWidth / ZoomSensitivityMultiplier;
}

public override ToolType ToolType => ToolType.Zoom;

public override void OnKeyDown(KeyEventArgs e)
{
if (e.Key == Key.LeftAlt)
Expand Down
2 changes: 1 addition & 1 deletion PixiEditor/PixiEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -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" />
Expand Down
37 changes: 28 additions & 9 deletions PixiEditor/ViewModels/SubViewModels/Main/ToolsViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.ObjectModel;
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Windows.Input;
using PixiEditor.Helpers;
Expand Down Expand Up @@ -41,13 +42,13 @@ public ToolsViewModel(ViewModelMain owner)
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<T>()
where T : Tool
{
Tool foundTool = ToolSet.First(x => x.ToolType == tool);
SetActiveTool(foundTool);
SetActiveTool(typeof(T));
}

public void SetActiveTool(Tool tool)
Expand All @@ -61,12 +62,19 @@ public void SetActiveTool(Tool tool)
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);
if (parameter is Type type)
{
SetActiveTool(type);
return;
}

Tool tool = (Tool)parameter;
SetActiveTool(tool.GetType());
}

private void ChangeToolSize(object parameter)
Expand All @@ -79,9 +87,20 @@ private void ChangeToolSize(object parameter)
}
}

private void SetToolCursor(ToolType tool)
private void SetActiveTool(Type toolType)
{
if (toolType == null && toolType.IsAssignableTo(typeof(Tool)))
{
return;
}

Tool foundTool = ToolSet.First(x => x.GetType() == toolType);
SetActiveTool(foundTool);
}

private void SetToolCursor(Type tool)
{
if (tool != ToolType.None)
if (tool != null)
{
ToolCursor = Owner.BitmapManager.SelectedTool.Cursor;
}
Expand Down
Loading

0 comments on commit 319d928

Please sign in to comment.