imgui.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*
  2. * Copyright 2011-2025 Branimir Karadzic. All rights reserved.
  3. * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
  4. */
  5. #ifndef IMGUI_H_HEADER_GUARD
  6. #define IMGUI_H_HEADER_GUARD
  7. #include <bgfx/bgfx.h>
  8. #include <bx/bx.h>
  9. #include <dear-imgui/imgui.h>
  10. #include <iconfontheaders/icons_kenney.h>
  11. #include <iconfontheaders/icons_font_awesome.h>
  12. #define IMGUI_MBUT_LEFT 0x01
  13. #define IMGUI_MBUT_RIGHT 0x02
  14. #define IMGUI_MBUT_MIDDLE 0x04
  15. inline uint32_t imguiRGBA(uint8_t _r, uint8_t _g, uint8_t _b, uint8_t _a = 255)
  16. {
  17. return 0
  18. | (uint32_t(_r) << 0)
  19. | (uint32_t(_g) << 8)
  20. | (uint32_t(_b) << 16)
  21. | (uint32_t(_a) << 24)
  22. ;
  23. }
  24. namespace bx { struct AllocatorI; }
  25. void imguiCreate(float _fontSize = 18.0f, bx::AllocatorI* _allocator = NULL);
  26. void imguiDestroy();
  27. void imguiBeginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, uint16_t _width, uint16_t _height, int _inputChar = -1, bgfx::ViewId _view = 255);
  28. void imguiEndFrame();
  29. namespace entry { class AppI; }
  30. void showExampleDialog(entry::AppI* _app, const char* _errorText = NULL);
  31. namespace ImGui
  32. {
  33. #define IMGUI_FLAGS_NONE UINT8_C(0x00)
  34. #define IMGUI_FLAGS_ALPHA_BLEND UINT8_C(0x01)
  35. struct TextureBgfx
  36. {
  37. bgfx::TextureHandle handle;
  38. uint8_t flags;
  39. uint8_t mip;
  40. uint32_t unused;
  41. };
  42. ///
  43. inline ImTextureID toId(bgfx::TextureHandle _handle, uint8_t _flags, uint8_t _mip)
  44. {
  45. TextureBgfx tex
  46. {
  47. .handle = _handle,
  48. .flags = _flags,
  49. .mip = _mip,
  50. .unused = 0,
  51. };
  52. return bx::bitCast<ImTextureID>(tex);
  53. }
  54. // Helper function for passing bgfx::TextureHandle to ImGui::Image.
  55. inline void Image(bgfx::TextureHandle _handle
  56. , uint8_t _flags
  57. , uint8_t _mip
  58. , const ImVec2& _size
  59. , const ImVec2& _uv0 = ImVec2(0.0f, 0.0f)
  60. , const ImVec2& _uv1 = ImVec2(1.0f, 1.0f)
  61. , const ImVec4& _tintCol = ImVec4(1.0f, 1.0f, 1.0f, 1.0f)
  62. , const ImVec4& _borderCol = ImVec4(0.0f, 0.0f, 0.0f, 0.0f)
  63. )
  64. {
  65. ImageWithBg(toId(_handle, _flags, _mip), _size, _uv0, _uv1, _borderCol, _tintCol);
  66. }
  67. // Helper function for passing bgfx::TextureHandle to ImGui::Image.
  68. inline void Image(bgfx::TextureHandle _handle
  69. , const ImVec2& _size
  70. , const ImVec2& _uv0 = ImVec2(0.0f, 0.0f)
  71. , const ImVec2& _uv1 = ImVec2(1.0f, 1.0f)
  72. , const ImVec4& _tintCol = ImVec4(1.0f, 1.0f, 1.0f, 1.0f)
  73. , const ImVec4& _borderCol = ImVec4(0.0f, 0.0f, 0.0f, 0.0f)
  74. )
  75. {
  76. Image(_handle, IMGUI_FLAGS_ALPHA_BLEND, 0, _size, _uv0, _uv1, _tintCol, _borderCol);
  77. }
  78. // Helper function for passing bgfx::TextureHandle to ImGui::ImageButton.
  79. inline bool ImageButton(bgfx::TextureHandle _handle
  80. , uint8_t _flags
  81. , uint8_t _mip
  82. , const ImVec2& _size
  83. , const ImVec2& _uv0 = ImVec2(0.0f, 0.0f)
  84. , const ImVec2& _uv1 = ImVec2(1.0f, 1.0f)
  85. , const ImVec4& _bgCol = ImVec4(0.0f, 0.0f, 0.0f, 0.0f)
  86. , const ImVec4& _tintCol = ImVec4(1.0f, 1.0f, 1.0f, 1.0f)
  87. )
  88. {
  89. return ImageButton("image", toId(_handle, _flags, _mip), _size, _uv0, _uv1, _bgCol, _tintCol);
  90. }
  91. // Helper function for passing bgfx::TextureHandle to ImGui::ImageButton.
  92. inline bool ImageButton(bgfx::TextureHandle _handle
  93. , const ImVec2& _size
  94. , const ImVec2& _uv0 = ImVec2(0.0f, 0.0f)
  95. , const ImVec2& _uv1 = ImVec2(1.0f, 1.0f)
  96. , const ImVec4& _bgCol = ImVec4(0.0f, 0.0f, 0.0f, 0.0f)
  97. , const ImVec4& _tintCol = ImVec4(1.0f, 1.0f, 1.0f, 1.0f)
  98. )
  99. {
  100. return ImageButton(_handle, IMGUI_FLAGS_ALPHA_BLEND, 0, _size, _uv0, _uv1, _bgCol, _tintCol);
  101. }
  102. ///
  103. inline void NextLine()
  104. {
  105. SetCursorPosY(GetCursorPosY() + GetTextLineHeightWithSpacing() );
  106. }
  107. ///
  108. inline bool MouseOverArea()
  109. {
  110. return false
  111. || ImGui::IsAnyItemActive()
  112. || ImGui::IsAnyItemHovered()
  113. || ImGui::IsWindowHovered(ImGuiHoveredFlags_AnyWindow)
  114. // || ImGuizmo::IsOver()
  115. ;
  116. }
  117. } // namespace ImGui
  118. #endif // IMGUI_H_HEADER_GUARD