PenTool.cs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using PixiEditor.Models.Layers;
  2. using PixiEditor.Models.Position;
  3. using PixiEditor.Models.Tools.ToolSettings;
  4. using System.Windows.Input;
  5. using System.Windows.Media;
  6. namespace PixiEditor.Models.Tools.Tools
  7. {
  8. public class PenTool : Tool
  9. {
  10. public override ToolType ToolType => ToolType.Pen;
  11. private int _toolSizeIndex;
  12. public PenTool()
  13. {
  14. Cursor = Cursors.Pen;
  15. Tooltip = "Standard brush (B)";
  16. Toolbar = new BasicToolbar();
  17. _toolSizeIndex = Toolbar.Settings.IndexOf(Toolbar.GetSetting("ToolSize"));
  18. }
  19. public override BitmapPixelChanges Use(Layer layer, Coordinates[] coordinates, Color color)
  20. {
  21. return Draw(coordinates[0], color, (int)Toolbar.Settings[_toolSizeIndex].Value);
  22. }
  23. public BitmapPixelChanges Draw(Coordinates startingCoords, Color color, int toolSize)
  24. {
  25. int x1, y1, x2, y2;
  26. DoubleCords centeredCoords = CoordinatesCalculator.CalculateThicknessCenter(startingCoords, toolSize);
  27. x1 = centeredCoords.Coords1.X;
  28. y1 = centeredCoords.Coords1.Y;
  29. x2 = centeredCoords.Coords2.X;
  30. y2 = centeredCoords.Coords2.Y;
  31. return BitmapPixelChanges.FromSingleColoredArray(CoordinatesCalculator.RectangleToCoordinates(x1, y1, x2, y2), color);
  32. }
  33. }
  34. }