RoundRec.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Threading.Tasks;
  5. using SkiaSharp;
  6. namespace FlowChartV2.Libraries
  7. {
  8. public class RoundRec : Figure
  9. {
  10. private int r;
  11. public RoundRec(Point start, string text) : base(FigureTypes.RoundRect, text)
  12. {
  13. tsize = (int)new SKPaint().MeasureText(text) + 1;
  14. this.size = new Size(tsize, tsize * 2);
  15. int hhsize = size.h / 2, hwsize = size.w / 2;
  16. this.start = new Point(start.x - hwsize, start.y);
  17. this.left = new Point(this.start.x, this.start.y + hhsize);
  18. this.bottom = new Point(this.start.x + hwsize, this.start.y + size.h);
  19. this.right = new Point(this.start.x + size.w, this.start.y + hhsize);
  20. this.top = new Point(this.start.x + hwsize, this.start.y);
  21. this.center = new Point(this.start.x + hwsize, this.start.y + hhsize);
  22. r = size.h;
  23. }
  24. public override void Draw(ref SKCanvas canvas, SKPaint paint)
  25. {
  26. canvas.DrawRoundRect(start.x, start.y, size.w, size.h, r, r, paint);
  27. }
  28. public override void DrawText(ref SKCanvas canvas, SKPaint paint)
  29. {
  30. int x = start.x + (size.w - tsize) / 2, y = (size.h + start.y) - size.h / 2 + 4;
  31. canvas.DrawText(text, x, y, paint);
  32. }
  33. }
  34. }