RectangleToolExecutor.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233
  1. using ChunkyImageLib.DataHolders;
  2. using PixiEditor.AvaloniaUI.Models.Handlers.Tools;
  3. using PixiEditor.AvaloniaUI.Models.Tools;
  4. using PixiEditor.ChangeableDocument.Actions;
  5. using PixiEditor.ChangeableDocument.Actions.Generated;
  6. using PixiEditor.DrawingApi.Core.Numerics;
  7. using PixiEditor.Numerics;
  8. namespace PixiEditor.AvaloniaUI.Models.DocumentModels.UpdateableChangeExecutors;
  9. #nullable enable
  10. internal class RectangleToolExecutor : ShapeToolExecutor<IRectangleToolHandler>
  11. {
  12. public override ExecutorType Type => ExecutorType.ToolLinked;
  13. private void DrawRectangle(VecI curPos, bool firstDraw)
  14. {
  15. RectI rect;
  16. if (firstDraw)
  17. rect = new RectI(curPos, VecI.Zero);
  18. else if (toolViewModel!.DrawSquare)
  19. rect = GetSquaredCoordinates(startPos, curPos);
  20. else
  21. rect = RectI.FromTwoPixels(startPos, curPos);
  22. lastRect = rect;
  23. internals!.ActionAccumulator.AddActions(new DrawRectangle_Action(memberGuid, new ShapeData(rect.Center, rect.Size, 0, strokeWidth, strokeColor, fillColor), drawOnMask, document!.AnimationHandler.ActiveFrameBindable));
  24. }
  25. protected override void DrawShape(VecI currentPos, bool first) => DrawRectangle(currentPos, first);
  26. protected override IAction TransformMovedAction(ShapeData data, ShapeCorners corners) => new DrawRectangle_Action(memberGuid, data, drawOnMask, document!.AnimationHandler.ActiveFrameBindable);
  27. protected override IAction EndDrawAction() => new EndDrawRectangle_Action();
  28. }