Visual Computing Library
Loading...
Searching...
No Matches
imgui_impl_bgfx.h
1/*
2 * Copyright 2011-2024 Branimir Karadzic. All rights reserved.
3 * License: https://github.com/bkaradzic/bgfx/blob/master/LICENSE
4 */
5
6#ifndef VCL_BGFX_IMGUI_IMGUI_IMPL_BGFX_H
7#define VCL_BGFX_IMGUI_IMGUI_IMPL_BGFX_H
8
9#include <bgfx/bgfx.h>
10#include <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// NO
19// inline uint32_t imguiRGBA(uint8_t _r, uint8_t _g, uint8_t _b, uint8_t _a = 255)
20// {
21// return 0
22// | (uint32_t(_r) << 0)
23// | (uint32_t(_g) << 8)
24// | (uint32_t(_b) << 16)
25// | (uint32_t(_a) << 24)
26// ;
27// }
28
29namespace bx { struct AllocatorI; }
30
31IMGUI_IMPL_API void ImGui_ImplBgfx_Init();
32// void imguiCreate(float _fontSize = 18.0f, bx::AllocatorI* _allocator = NULL);
33IMGUI_IMPL_API void ImGui_ImplBgfx_Shutdown();
34// void imguiDestroy();
35
36IMGUI_IMPL_API void ImGui_ImplBgfx_NewFrame(bgfx::ViewId viewId = 255);
37// 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);
38IMGUI_IMPL_API void ImGui_ImplBgfx_RenderDrawData(ImDrawData* draw_data);
39// void imguiEndFrame();
40// IMPORTANT this will become:
41// ImGui::Render();
42// ImGui_ImplBgfx_RenderDrawData(ImGui::GetDrawData());
43
44
45// namespace entry { class AppI; }
46// void showExampleDialog(entry::AppI* _app, const char* _errorText = NULL);
47
48namespace ImGui
49{
50#define IMGUI_FLAGS_NONE UINT8_C(0x00)
51#define IMGUI_FLAGS_ALPHA_BLEND UINT8_C(0x01)
52
54 inline ImTextureID toId(bgfx::TextureHandle _handle, uint8_t _flags, uint8_t _mip)
55 {
56 union { struct { bgfx::TextureHandle handle; uint8_t flags; uint8_t mip; } s; ImTextureID id; } tex;
57 tex.s.handle = _handle;
58 tex.s.flags = _flags;
59 tex.s.mip = _mip;
60 return tex.id;
61 }
62
63 // Helper function for passing bgfx::TextureHandle to ImGui::Image.
64 inline void Image(bgfx::TextureHandle _handle
65 , uint8_t _flags
66 , uint8_t _mip
67 , const ImVec2& _size
68 , const ImVec2& _uv0 = ImVec2(0.0f, 0.0f)
69 , const ImVec2& _uv1 = ImVec2(1.0f, 1.0f)
70 , const ImVec4& _tintCol = ImVec4(1.0f, 1.0f, 1.0f, 1.0f)
71 , const ImVec4& _borderCol = ImVec4(0.0f, 0.0f, 0.0f, 0.0f)
72 )
73 {
74 Image(toId(_handle, _flags, _mip), _size, _uv0, _uv1, _tintCol, _borderCol);
75 }
76
77 // Helper function for passing bgfx::TextureHandle to ImGui::Image.
78 inline void Image(bgfx::TextureHandle _handle
79 , const ImVec2& _size
80 , const ImVec2& _uv0 = ImVec2(0.0f, 0.0f)
81 , const ImVec2& _uv1 = ImVec2(1.0f, 1.0f)
82 , const ImVec4& _tintCol = ImVec4(1.0f, 1.0f, 1.0f, 1.0f)
83 , const ImVec4& _borderCol = ImVec4(0.0f, 0.0f, 0.0f, 0.0f)
84 )
85 {
86 Image(_handle, IMGUI_FLAGS_ALPHA_BLEND, 0, _size, _uv0, _uv1, _tintCol, _borderCol);
87 }
88
89 // Helper function for passing bgfx::TextureHandle to ImGui::ImageButton.
90 inline bool ImageButton(bgfx::TextureHandle _handle
91 , uint8_t _flags
92 , uint8_t _mip
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("image", toId(_handle, _flags, _mip), _size, _uv0, _uv1, _bgCol, _tintCol);
101 }
102
103 // Helper function for passing bgfx::TextureHandle to ImGui::ImageButton.
104 inline bool ImageButton(bgfx::TextureHandle _handle
105 , const ImVec2& _size
106 , const ImVec2& _uv0 = ImVec2(0.0f, 0.0f)
107 , const ImVec2& _uv1 = ImVec2(1.0f, 1.0f)
108 , const ImVec4& _bgCol = ImVec4(0.0f, 0.0f, 0.0f, 0.0f)
109 , const ImVec4& _tintCol = ImVec4(1.0f, 1.0f, 1.0f, 1.0f)
110 )
111 {
112 return ImageButton(_handle, IMGUI_FLAGS_ALPHA_BLEND, 0, _size, _uv0, _uv1, _bgCol, _tintCol);
113 }
114
116 inline void NextLine()
117 {
118 SetCursorPosY(GetCursorPosY() + GetTextLineHeightWithSpacing() );
119 }
120
122 inline bool MouseOverArea()
123 {
124 return false
125 || ImGui::IsAnyItemActive()
126 || ImGui::IsAnyItemHovered()
127 || ImGui::IsWindowHovered(ImGuiHoveredFlags_AnyWindow)
128// || ImGuizmo::IsOver()
129 ;
130 }
131
133 // void PushEnabled(bool _enabled);
134
136 // void PopEnabled();
137
138} // namespace ImGui
139
140#endif // VCL_BGFX_IMGUI_IMGUI_IMPL_BGFX_H