UiInterface.h 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright (C) 2009-2015, Panagiotis Christopoulos Charitos.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. #include "anki/ui/UiObject.h"
  7. namespace anki {
  8. /// @addtogroup ui
  9. /// @{
  10. using UiImagePtr = IntrusivePtr<UiImage>;
  11. /// Interfacing UI system with external systems.
  12. class UiInterface
  13. {
  14. public:
  15. UiInterface(UiAllocator alloc)
  16. : m_alloc(alloc)
  17. {}
  18. virtual ~UiInterface() = default;
  19. UiAllocator getAllocator() const
  20. {
  21. return m_alloc;
  22. }
  23. /// @name Image related methods.
  24. /// @{
  25. virtual ANKI_USE_RESULT Error loadImage(
  26. const CString& filename, UiImagePtr& img) = 0;
  27. /// Create a 8bit image. Used for fonts.
  28. virtual ANKI_USE_RESULT Error createR8Image(const SArray<U8>& data,
  29. const UVec2& size, UiImagePtr& img) = 0;
  30. /// @}
  31. /// @name Misc methods.
  32. /// @{
  33. virtual ANKI_USE_RESULT Error readFile(const CString& filename,
  34. DArrayAuto<U8>& data) = 0;
  35. /// @}
  36. /// @name Painting related methods.
  37. /// @{
  38. virtual void drawImage(UiImagePtr image, const Rect& uvs,
  39. const Rect& drawingRect, const UVec2& canvasSize) = 0;
  40. virtual void drawLines(const SArray<UVec2>& lines, const Color& color,
  41. const UVec2& canvasSize) = 0;
  42. /// @}
  43. protected:
  44. UiAllocator m_alloc;
  45. };
  46. /// UI image interface.
  47. class UiImage
  48. {
  49. friend class IntrusivePtr<UiImage>;
  50. friend IntrusivePtr<UiImage>::Deleter;
  51. public:
  52. UiImage(UiInterface* interface)
  53. : m_alloc(interface->getAllocator())
  54. {}
  55. virtual ~UiImage() = default;
  56. private:
  57. UiAllocator m_alloc;
  58. Atomic<I32> m_refcount = {0};
  59. Atomic<I32>& getRefcount()
  60. {
  61. return m_refcount;
  62. }
  63. UiAllocator getAllocator() const
  64. {
  65. return m_alloc;
  66. }
  67. };
  68. /// @}
  69. } // end namespace anki