PixiEditorTest.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. using Drawie.Backend.Core.Bridge;
  2. using Drawie.Numerics;
  3. using Drawie.RenderApi.Vulkan;
  4. using Drawie.Silk;
  5. using Drawie.Skia;
  6. using Drawie.Windowing;
  7. using DrawiEngine;
  8. using DrawiEngine.Desktop;
  9. using Microsoft.Extensions.DependencyInjection;
  10. using PixiEditor.Extensions.Runtime;
  11. using PixiEditor.Helpers;
  12. using PixiEditor.Linux;
  13. using PixiEditor.MacOs;
  14. using PixiEditor.OperatingSystem;
  15. using PixiEditor.Platform;
  16. using PixiEditor.ViewModels;
  17. using PixiEditor.Windows;
  18. namespace PixiEditor.Tests;
  19. public class PixiEditorTest
  20. {
  21. public PixiEditorTest()
  22. {
  23. if (DrawingBackendApi.HasBackend)
  24. {
  25. return;
  26. }
  27. try
  28. {
  29. var engine = DesktopDrawingEngine.CreateDefaultDesktop();
  30. var app = new TestingApp();
  31. Console.WriteLine("Running DrawieEngine with configuration:");
  32. Console.WriteLine($"\t- RenderApi: {engine.RenderApi}");
  33. Console.WriteLine($"\t- WindowingPlatform: {engine.RenderApi}");
  34. Console.WriteLine($"\t- DrawingBackend: {engine.RenderApi}");
  35. app.Initialize(engine);
  36. IWindow window = app.CreateMainWindow();
  37. window.Initialize();
  38. DrawingBackendApi.InitializeBackend(engine.RenderApi);
  39. app.Run();
  40. }
  41. catch (Exception ex)
  42. {
  43. if (!DrawingBackendApi.HasBackend)
  44. DrawingBackendApi.SetupBackend(new SkiaDrawingBackend(), new DrawieRenderingDispatcher());
  45. }
  46. }
  47. }
  48. public class FullPixiEditorTest : PixiEditorTest
  49. {
  50. public FullPixiEditorTest()
  51. {
  52. ExtensionLoader loader = new ExtensionLoader("TestExtensions", "TestExtensions/Unpacked");
  53. if (IOperatingSystem.Current == null)
  54. {
  55. IOperatingSystem os;
  56. if (System.OperatingSystem.IsWindows())
  57. {
  58. os = new WindowsOperatingSystem();
  59. }
  60. else if (System.OperatingSystem.IsLinux())
  61. {
  62. os = new LinuxOperatingSystem();
  63. }
  64. else if (System.OperatingSystem.IsMacOS())
  65. {
  66. os = new MacOperatingSystem();
  67. }
  68. else
  69. {
  70. throw new NotSupportedException("Unsupported operating system");
  71. }
  72. IOperatingSystem.RegisterOS(os);
  73. }
  74. if (IPlatform.Current == null)
  75. {
  76. IPlatform.RegisterPlatform(new TestPlatform());
  77. }
  78. var services = new ServiceCollection()
  79. .AddPlatform()
  80. .AddPixiEditor(loader)
  81. .AddExtensionServices(loader)
  82. .BuildServiceProvider();
  83. var vm = services.GetRequiredService<ViewModelMain>();
  84. vm.Setup(services);
  85. }
  86. class TestPlatform : IPlatform
  87. {
  88. public string Id { get; } = "TestPlatform";
  89. public string Name { get; } = "Tests";
  90. public bool PerformHandshake()
  91. {
  92. return true;
  93. }
  94. public void Update()
  95. {
  96. }
  97. public IAdditionalContentProvider? AdditionalContentProvider { get; } = new NullAdditionalContentProvider();
  98. }
  99. }
  100. public class TestingApp : DrawieApp
  101. {
  102. IWindow window;
  103. public override IWindow CreateMainWindow()
  104. {
  105. window = Engine.WindowingPlatform.CreateWindow("Testing app", VecI.One);
  106. return window;
  107. }
  108. protected override void OnInitialize()
  109. {
  110. window.IsVisible = false;
  111. }
  112. }