imgui.h 3.8 KB

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