Common.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright (C) 2009-present, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #pragma once
  6. // Include ImGUI
  7. #include <AnKi/Ui/ImGuiConfig.h>
  8. #include <ImGui/imgui.h>
  9. #include <ImGui/imgui_internal.h>
  10. #include <AnKi/Util/Ptr.h>
  11. #include <AnKi/Gr/Texture.h>
  12. namespace anki {
  13. // Forward
  14. class UiManager;
  15. class GrManager;
  16. /// @addtogroup ui
  17. /// @{
  18. #define ANKI_UI_LOGI(...) ANKI_LOG("UI", kNormal, __VA_ARGS__)
  19. #define ANKI_UI_LOGE(...) ANKI_LOG("UI", kError, __VA_ARGS__)
  20. #define ANKI_UI_LOGW(...) ANKI_LOG("UI", kWarning, __VA_ARGS__)
  21. #define ANKI_UI_LOGF(...) ANKI_LOG("UI", kFatal, __VA_ARGS__)
  22. class UiMemoryPool : public HeapMemoryPool, public MakeSingleton<UiMemoryPool>
  23. {
  24. template<typename>
  25. friend class MakeSingleton;
  26. private:
  27. UiMemoryPool(AllocAlignedCallback allocCb, void* allocCbUserData)
  28. : HeapMemoryPool(allocCb, allocCbUserData, "UiMemPool")
  29. {
  30. }
  31. ~UiMemoryPool() = default;
  32. };
  33. ANKI_DEFINE_SUBMODULE_UTIL_CONTAINERS(Ui, UiMemoryPool)
  34. /// The base of all UI objects.
  35. class UiObject
  36. {
  37. public:
  38. virtual ~UiObject() = default;
  39. void retain()
  40. {
  41. m_refcount.fetchAdd(1);
  42. }
  43. void release()
  44. {
  45. const U32 ref = m_refcount.fetchSub(1);
  46. if(ref == 1)
  47. {
  48. deleteInstance(UiMemoryPool::getSingleton(), this);
  49. }
  50. }
  51. protected:
  52. UiObject() = default;
  53. private:
  54. Atomic<I32> m_refcount = {0};
  55. };
  56. class UiCanvas;
  57. using UiCanvasPtr = IntrusiveNoDelPtr<UiCanvas>;
  58. inline Vec2 toAnki(const ImVec2& v)
  59. {
  60. return Vec2(v.x, v.y);
  61. }
  62. /// @}
  63. } // end namespace anki