Rect.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233
  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 Rect : Figure
  9. {
  10. public Rect(Point start, string text) : base(FigureTypes.Rectengle, text)
  11. {
  12. tsize = (int)new SKPaint().MeasureText(text) + 1;
  13. this.size = new Size(tsize - tsize / 100 * 50, Convert.ToInt32(tsize * 1.5));
  14. int hhsize = size.h / 2, hwsize = size.w / 2;
  15. this.start = new Point(start.x - hwsize, start.y);
  16. this.left = new Point(this.start.x, this.start.y + hhsize);
  17. this.bottom = new Point(this.start.x + hwsize, this.start.y + size.h);
  18. this.right = new Point(this.start.x + size.w, this.start.y + hhsize);
  19. this.top = new Point(this.start.x + hwsize, this.start.y);
  20. this.center = new Point(this.start.x + hwsize, this.start.y + hhsize);
  21. }
  22. public override void Draw(ref SKCanvas canvas, SKPaint paint)
  23. {
  24. canvas.DrawRect(start.x, start.y, size.w, size.h, paint);
  25. }
  26. public override void DrawText(ref SKCanvas canvas, SKPaint paint)
  27. {
  28. int x = start.x + (size.w - tsize) / 2, y = (size.h + start.y) - size.h / 2 + 4;
  29. canvas.DrawText(text, x, y, paint);
  30. }
  31. }
  32. }