CreateElFriend.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using Avalonia.Controls;
  2. using Avalonia.Controls.Shapes;
  3. using Avalonia.Media;
  4. using Avalonia.Svg;
  5. using Svg.Model;
  6. using System;
  7. namespace HelloItQuantum.Function
  8. {
  9. public static class CreateElFriend
  10. {
  11. private static Uri baseUri = new Uri("avares://HelloItQuantum/");
  12. private static Panel CreateEye(double size, Color color)
  13. {
  14. Panel panel = new Panel();
  15. Ellipse eyeball = CreateEllipse(size - 2, color);
  16. panel.Children.Add(eyeball);
  17. Image eye = CreateSvgImage("/Assets/ImgCreateFriend/eye.svg", size, null);
  18. panel.Children.Add(eye);
  19. return panel;
  20. }
  21. private static Rectangle CreateRectangle(double size, Color color)
  22. {
  23. Rectangle rectangle = new Rectangle();
  24. rectangle.Width = size;
  25. rectangle.Height = size;
  26. rectangle.RadiusX = 10;
  27. rectangle.RadiusY = 10;
  28. rectangle.Fill = new SolidColorBrush(color);
  29. return rectangle;
  30. }
  31. public static Image CreateSvgImage(string path, double height, SvgParameters? svgParameters)
  32. {
  33. SvgImage svgImage = new SvgImage();
  34. svgImage.Source = SvgSource.Load(path, baseUri, svgParameters);
  35. Image convertedImage = new Image
  36. {
  37. Source = svgImage,
  38. Height = height
  39. };
  40. return convertedImage;
  41. }
  42. public static Ellipse CreateEllipse(double size, Color color)
  43. {
  44. Ellipse ellipse = new Ellipse();
  45. ellipse.Fill = new SolidColorBrush(color);
  46. ellipse.Width = size;
  47. ellipse.Height = size;
  48. return ellipse;
  49. }
  50. public static Control CreateElement(int indexElement, Color color)
  51. {
  52. string textColor = color.ToString().Substring(3);
  53. SvgParameters svg = new SvgParameters(null, $"path {{ fill: #{textColor}; }}");
  54. switch (indexElement)
  55. {
  56. case 0: return CreateEllipse(110, color);
  57. case 1: return CreateRectangle(110, color);
  58. case 2: return CreateSvgImage("/Assets/ImgCreateFriend/body.svg", 110, svg);
  59. case 3: return CreateSvgImage("/Assets/ImgCreateFriend/foot1.svg", 60, svg);
  60. case 4: return CreateSvgImage("/Assets/ImgCreateFriend/foot2.svg", 60, svg);
  61. case 5: return CreateEye(35, color);
  62. case 6: return CreateEye(45, color);
  63. default: return CreateEllipse(110, color);
  64. }
  65. }
  66. }
  67. }