Skip to content

Commit

Permalink
Fixed syntax errors
Browse files Browse the repository at this point in the history
  • Loading branch information
flabbet committed Sep 21, 2021
1 parent db791e8 commit 1f2488d
Show file tree
Hide file tree
Showing 13 changed files with 184 additions and 178 deletions.
4 changes: 1 addition & 3 deletions PixiEditor/Helpers/Converters/IndexOfConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ public override object Convert(object value, Type targetType, object parameter,
return index;
}

return value is Layer layer && bitmapManager.ActiveDocument != null
? bitmapManager.ActiveDocument.Layers.IndexOf(layer)
: Binding.DoNothing;
return Binding.DoNothing;
}
}
}
8 changes: 4 additions & 4 deletions PixiEditor/Models/Layers/Layer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -302,14 +302,14 @@ public SKColor GetPixel(int x, int y)
return LayerBitmap.GetSRGBPixel(x, y);
}

public void SetPixelWithOffset(Coordinates coordinates, Color color)
public void SetPixelWithOffset(Coordinates coordinates, SKColor color)
{
LayerBitmap.SetPixel(coordinates.X - OffsetX, coordinates.Y - OffsetY, color);
LayerBitmap.SetSRGBPixel(coordinates.X - OffsetX, coordinates.Y - OffsetY, color);
}

public void SetPixelWithOffset(int x, int y, Color color)
public void SetPixelWithOffset(int x, int y, SKColor color)
{
LayerBitmap.SetPixel(x - OffsetX, y - OffsetY, color);
LayerBitmap.SetSRGBPixel(x - OffsetX, y - OffsetY, color);
}

/// <summary>
Expand Down
6 changes: 4 additions & 2 deletions PixiEditor/Models/Position/CoordinatesCalculator.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using PixiEditor.Models.DataHolders;
using PixiEditor.Models.Layers;
using SkiaSharp;
using System;
using System.Collections.Generic;

Expand Down Expand Up @@ -62,9 +64,9 @@ public static IEnumerable<Coordinates> RectangleToCoordinates(int x1, int y1, in
return coordinates;
}

public static void DrawRectangle(Layer layer, Color color, int x1, int y1, int x2, int y2)
public static void DrawRectangle(Layer layer, SKColor color, int x1, int y1, int x2, int y2)
{
using var ctx = layer.LayerBitmap.GetBitmapContext();
//TODO: use some kind of context
x2++;
y2++;
for (int y = y1; y < y1 + (y2 - y1); y++)
Expand Down
3 changes: 2 additions & 1 deletion PixiEditor/Models/Tools/BitmapOperationTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using PixiEditor.Models.DataHolders;
using PixiEditor.Models.Layers;
using PixiEditor.Models.Position;
using SkiaSharp;

namespace PixiEditor.Models.Tools
{
Expand All @@ -17,6 +18,6 @@ public abstract class BitmapOperationTool : Tool
public bool UseDefaultUndoMethod { get; set; } = true;
public virtual bool UsesShift => true;

public abstract void Use(Layer layer, List<Coordinates> mouseMove, Color color);
public abstract void Use(Layer layer, List<Coordinates> mouseMove, SKColor color);
}
}
6 changes: 3 additions & 3 deletions PixiEditor/Models/Tools/ShapeTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,17 @@ public ShapeTool()
}

// TODO: Add cache for lines 31, 32 (hopefully it would speed up calculation)
public abstract override LayerChange[] Use(Layer layer, List<Coordinates> coordinates, SKColor color);
public abstract override void Use(Layer layer, List<Coordinates> coordinates, SKColor color);

protected static void ThickenShape(Layer layer, Color color, IEnumerable<Coordinates> shape, int thickness)
protected static void ThickenShape(Layer layer, SKColor color, IEnumerable<Coordinates> shape, int thickness)
{
foreach (Coordinates item in shape)
{
ThickenShape(layer, color, item, thickness);
}
}

protected static void ThickenShape(Layer layer, Color color, Coordinates coords, int thickness)
protected static void ThickenShape(Layer layer, SKColor color, Coordinates coords, int thickness)
{
var dcords = CoordinatesCalculator.CalculateThicknessCenter(coords, thickness);
CoordinatesCalculator.DrawRectangle(layer, color, dcords.Coords1.X, dcords.Coords1.Y, dcords.Coords2.X, dcords.Coords2.Y);
Expand Down
87 changes: 51 additions & 36 deletions PixiEditor/Models/Tools/Tool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,72 +13,87 @@
using PixiEditor.Models.Undo;

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

public virtual string ToolName => GetType().Name.Replace("Tool", string.Empty);

public virtual string DisplayName => ToolName.AddSpacesBeforeUppercaseLetters();

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

public virtual bool HideHighlight { get; }

public abstract string Tooltip { get; }

public string ActionDisplay
{
get => actionDisplay;
set
{
actionDisplay = value;
RaisePropertyChanged("ActionDisplay");
}
}

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

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

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

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

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


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 OnKeyUp(KeyEventArgs e)
{
public virtual void AddUndoProcess(Document document)
{
//StorageBasedChange change = new StorageBasedChange(document, affectedLayers, false);

//manager.AddUndoChange(change.ToChange(), )
}

public virtual void OnStart(Coordinates clickPosition)
{
public virtual void OnMouseUp(MouseEventArgs e)
{
}

public virtual void OnStoppedRecordingMouseUp(MouseEventArgs e)

public virtual void OnKeyDown(KeyEventArgs e)
{
}

public virtual void OnMouseMove(MouseEventArgs e)

public virtual void OnKeyUp(KeyEventArgs e)
{
}

public virtual void AddUndoProcess(Document document)
public virtual void OnStart(Coordinates clickPosition)
{
//StorageBasedChange change = new StorageBasedChange(document, affectedLayers, false);
}

//manager.AddUndoChange(change.ToChange(), )
public virtual void OnRecordingLeftMouseDown(MouseEventArgs e)
{
}

public virtual void RedoProcess(UndoManager manager)
public virtual void OnStoppedRecordingMouseUp(MouseEventArgs e)
{
}

public virtual void OnMouseMove(MouseEventArgs e)
{
}


public virtual void AfterAddedUndo(UndoManager undoManager)
{
}
Expand Down
5 changes: 2 additions & 3 deletions PixiEditor/Models/Tools/Tools/BrightnessTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public override void OnKeyUp(KeyEventArgs e)
}
}

public override LayerChange[] Use(Layer layer, List<Coordinates> coordinates, SKColor color)
public override void Use(Layer layer, List<Coordinates> coordinates, SKColor color)
{
int toolSize = Toolbar.GetSetting<SizeSetting>("ToolSize").Value;
float correctionFactor = Toolbar.GetSetting<FloatSetting>("CorrectionFactor").Value;
Expand All @@ -79,9 +79,8 @@ public void ChangeBrightness(Layer layer, Coordinates coordinates, int toolSize,
centeredCoords.Coords1.Y,
centeredCoords.Coords2.X,
centeredCoords.Coords2.Y);
BitmapPixelChanges changes = new BitmapPixelChanges(new Dictionary<Coordinates, SKColor>());

using var ctx = layer.LayerBitmap.GetBitmapContext();
//using var ctx = layer.LayerBitmap.GetBitmapContext();

foreach (Coordinates coordinate in rectangleCoordinates)
{
Expand Down
30 changes: 11 additions & 19 deletions PixiEditor/Models/Tools/Tools/CircleTool.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using PixiEditor.Helpers.Extensions;
using PixiEditor.Models.DataHolders;
using PixiEditor.Models.Layers;
using PixiEditor.Models.Layers;
using PixiEditor.Models.Position;
using PixiEditor.Models.Tools.ToolSettings.Settings;
using SkiaSharp;
Expand All @@ -9,12 +7,6 @@
using System.Linq;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using PixiEditor.Helpers.Extensions;
using PixiEditor.Models.DataHolders;
using PixiEditor.Models.Layers;
using PixiEditor.Models.Position;
using PixiEditor.Models.Tools.ToolSettings.Settings;

namespace PixiEditor.Models.Tools.Tools
{
Expand Down Expand Up @@ -43,7 +35,7 @@ public override void OnKeyUp(KeyEventArgs e)
}
}

public override LayerChange[] Use(Layer layer, List<Coordinates> coordinates, SKColor color)
public override void Use(Layer layer, List<Coordinates> coordinates, SKColor color)
{
int thickness = Toolbar.GetSetting<SizeSetting>("ToolSize").Value;
DoubleCords fixedCoordinates = CalculateCoordinatesForShapeRotation(coordinates[^1], coordinates[0]);
Expand All @@ -64,7 +56,7 @@ public override LayerChange[] Use(Layer layer, List<Coordinates> coordinates, SK
/// <param name="endCoordinates">Bottom right coordinate of ellipse.</param>
/// <param name="thickness">Thickness of ellipse.</param>
/// <param name="filled">Should ellipse be filled.</param>
public void CreateEllipse(Layer layer, Color color, Coordinates startCoordinates, Coordinates endCoordinates, int thickness, bool filled)
public void CreateEllipse(Layer layer, SKColor color, Coordinates startCoordinates, Coordinates endCoordinates, int thickness, bool filled)
{
IEnumerable<Coordinates> outline = CreateEllipse(layer, color, startCoordinates, endCoordinates, thickness);
if (filled)
Expand All @@ -79,7 +71,7 @@ public void CreateEllipse(Layer layer, Color color, Coordinates startCoordinates
/// <param name="startCoordinates">Top left coordinate of ellipse.</param>
/// <param name="endCoordinates">Bottom right coordinate of ellipse.</param>
/// <param name="thickness">Thickness of ellipse.</param>
public IEnumerable<Coordinates> CreateEllipse(Layer layer, Color color, Coordinates startCoordinates, Coordinates endCoordinates, int thickness)
public IEnumerable<Coordinates> CreateEllipse(Layer layer, SKColor color, Coordinates startCoordinates, Coordinates endCoordinates, int thickness)
{
double radiusX = (endCoordinates.X - startCoordinates.X) / 2.0;
double radiusY = (endCoordinates.Y - startCoordinates.Y) / 2.0;
Expand All @@ -95,9 +87,9 @@ public IEnumerable<Coordinates> CreateEllipse(Layer layer, Color color, Coordina
return ellipse;
}

public List<Coordinates> GenerateMidpointEllipse(Layer layer, Color color, double halfWidth, double halfHeight, double centerX, double centerY)
public List<Coordinates> GenerateMidpointEllipse(Layer layer, SKColor color, double halfWidth, double halfHeight, double centerX, double centerY)
{
using var ctx = layer.LayerBitmap.GetBitmapContext();
//using var ctx = layer.LayerBitmap.GetBitmapContext();

if (halfWidth < 1 || halfHeight < 1)
{
Expand Down Expand Up @@ -153,9 +145,9 @@ public List<Coordinates> GenerateMidpointEllipse(Layer layer, Color color, doubl
return outputCoordinates;
}

public void DrawEllipseFill(Layer layer, Color color, IEnumerable<Coordinates> outlineCoordinates)
public void DrawEllipseFill(Layer layer, SKColor color, IEnumerable<Coordinates> outlineCoordinates)
{
using var ctx = layer.LayerBitmap.GetBitmapContext();
//using var ctx = layer.LayerBitmap.GetBitmapContext();

if (!outlineCoordinates.Any())
{
Expand All @@ -176,9 +168,9 @@ public void DrawEllipseFill(Layer layer, Color color, IEnumerable<Coordinates> o
}
}

private List<Coordinates> DrawFallbackRectangle(Layer layer, Color color, double halfWidth, double halfHeight, double centerX, double centerY)
private List<Coordinates> DrawFallbackRectangle(Layer layer, SKColor color, double halfWidth, double halfHeight, double centerX, double centerY)
{
using var ctx = layer.LayerBitmap.GetBitmapContext();
//using var ctx = layer.LayerBitmap.GetBitmapContext();

List<Coordinates> coordinates = new List<Coordinates>();

Expand Down Expand Up @@ -207,7 +199,7 @@ private List<Coordinates> DrawFallbackRectangle(Layer layer, Color color, double
return coordinates;
}

private Coordinates[] DrawRegionPoints(Layer layer, Color color, double x, double xc, double y, double yc)
private Coordinates[] DrawRegionPoints(Layer layer, SKColor color, double x, double xc, double y, double yc)
{
Coordinates[] outputCoordinates = new Coordinates[4];
outputCoordinates[0] = new Coordinates((int)Math.Floor(x), (int)Math.Floor(y));
Expand Down
2 changes: 1 addition & 1 deletion PixiEditor/Models/Tools/Tools/EraserTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public EraserTool(BitmapManager bitmapManager)

public override string Tooltip => "Erasers color from pixel. (E)";

public override LayerChange[] Use(Layer layer, List<Coordinates> coordinates, SKColor color)
public override void Use(Layer layer, List<Coordinates> coordinates, SKColor color)
{
Erase(layer, coordinates, Toolbar.GetSetting<SizeSetting>("ToolSize").Value);
}
Expand Down

0 comments on commit 1f2488d

Please sign in to comment.