imgui.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /*
  2. * Copyright 2011-2017 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 <ocornut-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, char _inputChar = 0, 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 TabButton(const char* _text, float _width, bool _active)
  97. {
  98. int32_t count = 1;
  99. if (_active)
  100. {
  101. ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1.0f, 0.75f, 0.0f, 0.78f) );
  102. ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.0f, 0.0f, 0.0f, 1.0f ) );
  103. count = 2;
  104. }
  105. else
  106. {
  107. ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.5f, 0.5f, 0.5f, 0.7f) );
  108. }
  109. bool retval = ImGui::Button(_text, ImVec2(_width, 20.0f) );
  110. ImGui::PopStyleColor(count);
  111. return retval;
  112. }
  113. inline bool MouseOverArea()
  114. {
  115. return false
  116. || ImGui::IsAnyItemHovered()
  117. || ImGui::IsAnyWindowHovered()
  118. ;
  119. }
  120. } // namespace ImGui
  121. #endif // IMGUI_H_HEADER_GUARD