CurvRect.cs 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 CurvRect : Figure
  9. {
  10. public CurvRect(Point start, string text) : base(FigureTypes.CurvRect, text)
  11. {
  12. tsize = (int)new SKPaint().MeasureText(text) + 1;
  13. this.size = new Size(hfont * hfont, tsize);
  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 - size.h / 4, 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 + size.h / 4, 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. SKPoint[] points =
  25. {
  26. new SKPoint(start.x,start.y),
  27. new SKPoint(start.x + size.w + size.h / 2,start.y),
  28. new SKPoint(start.x + size.w + size.h / 2,start.y),
  29. new SKPoint(start.x + size.w,start.y + size.h),
  30. new SKPoint(start.x + size.w,start.y + size.h),
  31. new SKPoint(start.x - size.h / 2, start.y + size.h),
  32. new SKPoint(start.x - size.h / 2, start.y + size.h),
  33. new SKPoint(start.x,start.y),
  34. };
  35. canvas.DrawPoints(SKPointMode.Lines, points, paint);
  36. }
  37. public override void DrawText(ref SKCanvas canvas, SKPaint paint)
  38. {
  39. int x = start.x + (size.w - tsize) / 2, y = (size.h + start.y) - size.h / 2 + 4;
  40. canvas.DrawText(text, x, y, paint);
  41. }
  42. }
  43. }