Rhombus.cs 1.7 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 Rhombus : Figure
  9. {
  10. public Rhombus(Point start, string text) : base(FigureTypes.Rhombus, text)
  11. {
  12. tsize = (int)new SKPaint().MeasureText(text) + 1;
  13. this.size = new Size(Convert.ToInt32(tsize * 1.3), Convert.ToInt32(tsize * 1.3));
  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. SKPoint[] points =
  25. {
  26. new SKPoint(top.x,top.y),
  27. new SKPoint(right.x,right.y),
  28. new SKPoint(right.x,right.y),
  29. new SKPoint(bottom.x,bottom.y),
  30. new SKPoint(bottom.x,bottom.y),
  31. new SKPoint(left.x,left.y),
  32. new SKPoint(left.x,left.y),
  33. new SKPoint(top.x,top.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. }