DrawingBackendApi.cs 1011 B

1234567891011121314151617181920212223242526272829303132333435
  1. using System;
  2. using PixiEditor.DrawingApi.Core.Exceptions;
  3. namespace PixiEditor.DrawingApi.Core.Bridge
  4. {
  5. public static class DrawingBackendApi
  6. {
  7. private static IDrawingBackend? _current;
  8. public static IDrawingBackend Current
  9. {
  10. get
  11. {
  12. if (_current == null)
  13. throw new NullReferenceException("Either drawing backend was not yet initialized or reference was somehow lost.");
  14. return _current;
  15. }
  16. }
  17. public static bool HasBackend => _current != null;
  18. public static void SetupBackend(IDrawingBackend backend, IRenderingServer server)
  19. {
  20. if (_current != null)
  21. {
  22. throw new InitializationDuplicateException("Drawing backend was already initialized.");
  23. }
  24. _current = backend;
  25. _current.RenderingDispatcher = server;
  26. backend.Setup();
  27. }
  28. }
  29. }