ShapeTool.cs 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System.Collections.Generic;
  2. using System.Linq;
  3. using Avalonia.Input;
  4. using Avalonia.Media;
  5. using PixiEditor.Models.DataHolders;
  6. using PixiEditor.Models.Layers;
  7. using PixiEditor.Models.Position;
  8. using PixiEditor.Models.Tools.ToolSettings.Toolbars;
  9. namespace PixiEditor.Models.Tools
  10. {
  11. public abstract class ShapeTool : BitmapOperationTool
  12. {
  13. public abstract override ToolType ToolType { get; }
  14. public ShapeTool()
  15. {
  16. RequiresPreviewLayer = true;
  17. Cursor = new Cursor(StandardCursorType.Cross);
  18. Toolbar = new BasicShapeToolbar();
  19. }
  20. public abstract override LayerChange[] Use(Layer layer, Coordinates[] coordinates, Color color);
  21. protected Coordinates[] GetThickShape(Coordinates[] shape, int thickness)
  22. {
  23. List<Coordinates> output = new List<Coordinates>();
  24. for (int i = 0; i < shape.Length; i++)
  25. output.AddRange(
  26. CoordinatesCalculator.RectangleToCoordinates(
  27. CoordinatesCalculator.CalculateThicknessCenter(shape[i], thickness)));
  28. return output.Distinct().ToArray();
  29. }
  30. protected DoubleCords CalculateCoordinatesForShapeRotation(Coordinates startingCords,
  31. Coordinates secondCoordinates)
  32. {
  33. Coordinates currentCoordinates = secondCoordinates;
  34. if (startingCords.X > currentCoordinates.X && startingCords.Y > currentCoordinates.Y)
  35. return new DoubleCords(new Coordinates(currentCoordinates.X, currentCoordinates.Y),
  36. new Coordinates(startingCords.X, startingCords.Y));
  37. if (startingCords.X < currentCoordinates.X && startingCords.Y < currentCoordinates.Y)
  38. return new DoubleCords(new Coordinates(startingCords.X, startingCords.Y),
  39. new Coordinates(currentCoordinates.X, currentCoordinates.Y));
  40. if (startingCords.Y > currentCoordinates.Y)
  41. return new DoubleCords(new Coordinates(startingCords.X, currentCoordinates.Y),
  42. new Coordinates(currentCoordinates.X, startingCords.Y));
  43. if (startingCords.X > currentCoordinates.X && startingCords.Y <= currentCoordinates.Y)
  44. return new DoubleCords(new Coordinates(currentCoordinates.X, startingCords.Y),
  45. new Coordinates(startingCords.X, currentCoordinates.Y));
  46. return new DoubleCords(startingCords, secondCoordinates);
  47. }
  48. }
  49. }