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