imgui.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /*
  2. * Copyright 2011-2019 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. // Helper function for passing bgfx::TextureHandle to ImGui::Image.
  35. inline void Image(bgfx::TextureHandle _handle
  36. , uint8_t _flags
  37. , uint8_t _mip
  38. , const ImVec2& _size
  39. , const ImVec2& _uv0 = ImVec2(0.0f, 0.0f)
  40. , const ImVec2& _uv1 = ImVec2(1.0f, 1.0f)
  41. , const ImVec4& _tintCol = ImVec4(1.0f, 1.0f, 1.0f, 1.0f)
  42. , const ImVec4& _borderCol = ImVec4(0.0f, 0.0f, 0.0f, 0.0f)
  43. )
  44. {
  45. union { struct { bgfx::TextureHandle handle; uint8_t flags; uint8_t mip; } s; ImTextureID ptr; } texture;
  46. texture.s.handle = _handle;
  47. texture.s.flags = _flags;
  48. texture.s.mip = _mip;
  49. Image(texture.ptr, _size, _uv0, _uv1, _tintCol, _borderCol);
  50. }
  51. // Helper function for passing bgfx::TextureHandle to ImGui::Image.
  52. inline void Image(bgfx::TextureHandle _handle
  53. , const ImVec2& _size
  54. , const ImVec2& _uv0 = ImVec2(0.0f, 0.0f)
  55. , const ImVec2& _uv1 = ImVec2(1.0f, 1.0f)
  56. , const ImVec4& _tintCol = ImVec4(1.0f, 1.0f, 1.0f, 1.0f)
  57. , const ImVec4& _borderCol = ImVec4(0.0f, 0.0f, 0.0f, 0.0f)
  58. )
  59. {
  60. Image(_handle, IMGUI_FLAGS_ALPHA_BLEND, 0, _size, _uv0, _uv1, _tintCol, _borderCol);
  61. }
  62. // Helper function for passing bgfx::TextureHandle to ImGui::ImageButton.
  63. inline bool ImageButton(bgfx::TextureHandle _handle
  64. , uint8_t _flags
  65. , uint8_t _mip
  66. , const ImVec2& _size
  67. , const ImVec2& _uv0 = ImVec2(0.0f, 0.0f)
  68. , const ImVec2& _uv1 = ImVec2(1.0f, 1.0f)
  69. , int _framePadding = -1
  70. , const ImVec4& _bgCol = ImVec4(0.0f, 0.0f, 0.0f, 0.0f)
  71. , const ImVec4& _tintCol = ImVec4(1.0f, 1.0f, 1.0f, 1.0f)
  72. )
  73. {
  74. union { struct { bgfx::TextureHandle handle; uint8_t flags; uint8_t mip; } s; ImTextureID ptr; } texture;
  75. texture.s.handle = _handle;
  76. texture.s.flags = _flags;
  77. texture.s.mip = _mip;
  78. return ImageButton(texture.ptr, _size, _uv0, _uv1, _framePadding, _bgCol, _tintCol);
  79. }
  80. // Helper function for passing bgfx::TextureHandle to ImGui::ImageButton.
  81. inline bool ImageButton(bgfx::TextureHandle _handle
  82. , const ImVec2& _size
  83. , const ImVec2& _uv0 = ImVec2(0.0f, 0.0f)
  84. , const ImVec2& _uv1 = ImVec2(1.0f, 1.0f)
  85. , int _framePadding = -1
  86. , const ImVec4& _bgCol = ImVec4(0.0f, 0.0f, 0.0f, 0.0f)
  87. , const ImVec4& _tintCol = ImVec4(1.0f, 1.0f, 1.0f, 1.0f)
  88. )
  89. {
  90. return ImageButton(_handle, IMGUI_FLAGS_ALPHA_BLEND, 0, _size, _uv0, _uv1, _framePadding, _bgCol, _tintCol);
  91. }
  92. inline void NextLine()
  93. {
  94. SetCursorPosY(GetCursorPosY() + GetTextLineHeightWithSpacing() );
  95. }
  96. inline bool MouseOverArea()
  97. {
  98. return false
  99. || ImGui::IsAnyItemHovered()
  100. || ImGui::IsWindowHovered(ImGuiHoveredFlags_AnyWindow)
  101. ;
  102. }
  103. } // namespace ImGui
  104. #endif // IMGUI_H_HEADER_GUARD