ShapeTool.cs 2.5 KB

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