Drawer.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Drawing.Drawing2D;
  4. using System.Drawing;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace ImpulseVision
  9. {
  10. public static class Drawer
  11. {
  12. public static GraphicsPath RoundedRectangle(Rectangle rect, float RoundSize)
  13. {
  14. GraphicsPath gp = new GraphicsPath();
  15. gp.AddArc(rect.X, rect.Y, RoundSize, RoundSize, 180, 90);
  16. gp.AddArc(rect.X + rect.Width - RoundSize, rect.Y, RoundSize, RoundSize, 270, 90);
  17. gp.AddArc(rect.X + rect.Width - RoundSize, rect.Y + rect.Height - RoundSize, RoundSize, RoundSize, 0, 90);
  18. gp.AddArc(rect.X, rect.Y + rect.Height - RoundSize, RoundSize, RoundSize, 90, 90);
  19. gp.CloseFigure();
  20. return gp;
  21. }
  22. public static void DrawBlurredLine(Graphics graph, Color lineColor, Point p1, Point p2, int maxAlpha, int penWidth)
  23. {
  24. float stepAlpha = (float)maxAlpha / penWidth;
  25. float actualAlpha = stepAlpha;
  26. for (int pWidth = penWidth; pWidth > 0; pWidth--)
  27. {
  28. Color BlurredColor = Color.FromArgb((int)actualAlpha, lineColor);
  29. Pen BlurredPen = new Pen(BlurredColor, pWidth);
  30. BlurredPen.StartCap = LineCap.Round;
  31. BlurredPen.EndCap = LineCap.Round;
  32. graph.DrawLine(BlurredPen, p1, p2);
  33. actualAlpha += stepAlpha;
  34. }
  35. }
  36. public static void DrawBlurredRectangle(Graphics graph, Color lineColor, Rectangle rect, int maxAlpha, int penWidth)
  37. {
  38. float stepAlpha = (float)maxAlpha / penWidth;
  39. float actualAlpha = stepAlpha;
  40. for (int pWidth = penWidth; pWidth > 0; pWidth--)
  41. {
  42. Color BlurredColor = Color.FromArgb((int)actualAlpha, lineColor);
  43. Pen BlurredPen = new Pen(BlurredColor, pWidth);
  44. BlurredPen.StartCap = LineCap.Round;
  45. BlurredPen.EndCap = LineCap.Round;
  46. graph.DrawRectangle(BlurredPen, rect);
  47. actualAlpha += stepAlpha;
  48. }
  49. }
  50. }
  51. }