ocornut_imgui.cpp 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  1. /*
  2. * Copyright 2014-2015 Daniel Collin. All rights reserved.
  3. * License: https://github.com/bkaradzic/bgfx#license-bsd-2-clause
  4. */
  5. #include <bgfx/bgfx.h>
  6. #include <bx/allocator.h>
  7. #include <bx/fpumath.h>
  8. #include <bx/timer.h>
  9. #include <ocornut-imgui/imgui.h>
  10. #include "imgui.h"
  11. #include "ocornut_imgui.h"
  12. #ifndef USE_ENTRY
  13. # if defined(SCI_NAMESPACE)
  14. # define USE_ENTRY 1
  15. # else
  16. # define USE_ENTRY 0
  17. # endif // defined(SCI_NAMESPACE)
  18. #endif // USE_ENTRY
  19. #if USE_ENTRY
  20. # include "../entry/entry.h"
  21. #endif // USE_ENTRY
  22. #if defined(SCI_NAMESPACE)
  23. # include "../entry/input.h"
  24. # include "scintilla.h"
  25. #endif // defined(SCI_NAMESPACE)
  26. #include "vs_ocornut_imgui.bin.h"
  27. #include "fs_ocornut_imgui.bin.h"
  28. #include "roboto_regular.ttf.h"
  29. #include "robotomono_regular.ttf.h"
  30. #include "icons_kenney.ttf.h"
  31. #include "icons_font_awesome.ttf.h"
  32. struct FontRangeMerge
  33. {
  34. const void* data;
  35. size_t size;
  36. ImWchar ranges[3];
  37. };
  38. static FontRangeMerge s_fontRangeMerge[] =
  39. {
  40. { s_iconsKenneyTtf, sizeof(s_iconsKenneyTtf), { ICON_MIN_KI, ICON_MAX_KI, 0 } },
  41. { s_iconsFontAwesomeTtf, sizeof(s_iconsFontAwesomeTtf), { ICON_MIN_FA, ICON_MAX_FA, 0 } },
  42. };
  43. struct OcornutImguiContext
  44. {
  45. static void* memAlloc(size_t _size);
  46. static void memFree(void* _ptr);
  47. static void renderDrawLists(ImDrawData* _drawData);
  48. void render(ImDrawData* _drawData)
  49. {
  50. const ImGuiIO& io = ImGui::GetIO();
  51. const float width = io.DisplaySize.x;
  52. const float height = io.DisplaySize.y;
  53. {
  54. float ortho[16];
  55. bx::mtxOrtho(ortho, 0.0f, width, height, 0.0f, -1.0f, 1.0f);
  56. bgfx::setViewTransform(m_viewId, NULL, ortho);
  57. }
  58. #if USE_ENTRY
  59. for (uint32_t ii = 1; ii < BX_COUNTOF(m_window); ++ii)
  60. {
  61. Window& window = m_window[ii];
  62. if (bgfx::isValid(window.m_fbh) )
  63. {
  64. const uint8_t viewId = window.m_viewId;
  65. bgfx::setViewClear(viewId
  66. , BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH
  67. , 0x303030ff
  68. , 1.0f
  69. , 0
  70. );
  71. bgfx::setViewFrameBuffer(viewId, window.m_fbh);
  72. bgfx::setViewRect(viewId
  73. , 0
  74. , 0
  75. , window.m_state.m_width
  76. , window.m_state.m_height
  77. );
  78. float ortho[16];
  79. bx::mtxOrtho(ortho
  80. , 0.0f
  81. , float(window.m_state.m_width)
  82. , float(window.m_state.m_height)
  83. , 0.0f
  84. , -1.0f
  85. , 1.0f
  86. );
  87. bgfx::setViewTransform(viewId
  88. , NULL
  89. , ortho
  90. );
  91. }
  92. }
  93. #endif // USE_ENTRY
  94. // Render command lists
  95. for (int32_t ii = 0, num = _drawData->CmdListsCount; ii < num; ++ii)
  96. {
  97. bgfx::TransientVertexBuffer tvb;
  98. bgfx::TransientIndexBuffer tib;
  99. const ImDrawList* drawList = _drawData->CmdLists[ii];
  100. uint32_t numVertices = (uint32_t)drawList->VtxBuffer.size();
  101. uint32_t numIndices = (uint32_t)drawList->IdxBuffer.size();
  102. if (!bgfx::checkAvailTransientVertexBuffer(numVertices, m_decl)
  103. || !bgfx::checkAvailTransientIndexBuffer(numIndices) )
  104. {
  105. // not enough space in transient buffer just quit drawing the rest...
  106. break;
  107. }
  108. bgfx::allocTransientVertexBuffer(&tvb, numVertices, m_decl);
  109. bgfx::allocTransientIndexBuffer(&tib, numIndices);
  110. ImDrawVert* verts = (ImDrawVert*)tvb.data;
  111. memcpy(verts, drawList->VtxBuffer.begin(), numVertices * sizeof(ImDrawVert) );
  112. ImDrawIdx* indices = (ImDrawIdx*)tib.data;
  113. memcpy(indices, drawList->IdxBuffer.begin(), numIndices * sizeof(ImDrawIdx) );
  114. uint32_t offset = 0;
  115. for (const ImDrawCmd* cmd = drawList->CmdBuffer.begin(), *cmdEnd = drawList->CmdBuffer.end(); cmd != cmdEnd; ++cmd)
  116. {
  117. if (cmd->UserCallback)
  118. {
  119. cmd->UserCallback(drawList, cmd);
  120. }
  121. else if (0 != cmd->ElemCount)
  122. {
  123. uint64_t state = 0
  124. | BGFX_STATE_RGB_WRITE
  125. | BGFX_STATE_ALPHA_WRITE
  126. | BGFX_STATE_MSAA
  127. ;
  128. bgfx::TextureHandle th = m_texture;
  129. bgfx::ProgramHandle program = m_program;
  130. if (NULL != cmd->TextureId)
  131. {
  132. union { ImTextureID ptr; struct { bgfx::TextureHandle handle; uint8_t flags; uint8_t mip; } s; } texture = { cmd->TextureId };
  133. state |= 0 != (IMGUI_FLAGS_ALPHA_BLEND & texture.s.flags)
  134. ? BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA)
  135. : BGFX_STATE_NONE
  136. ;
  137. th = texture.s.handle;
  138. if (0 != texture.s.mip)
  139. {
  140. extern bgfx::ProgramHandle imguiGetImageProgram(uint8_t _mip);
  141. program = imguiGetImageProgram(texture.s.mip);
  142. }
  143. }
  144. else
  145. {
  146. state |= BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA);
  147. }
  148. const uint16_t xx = uint16_t(bx::fmax(cmd->ClipRect.x, 0.0f) );
  149. const uint16_t yy = uint16_t(bx::fmax(cmd->ClipRect.y, 0.0f) );
  150. bgfx::setScissor(xx, yy
  151. , uint16_t(bx::fmin(cmd->ClipRect.z, 65535.0f)-xx)
  152. , uint16_t(bx::fmin(cmd->ClipRect.w, 65535.0f)-yy)
  153. );
  154. bgfx::setState(state);
  155. bgfx::setTexture(0, s_tex, th);
  156. bgfx::setVertexBuffer(&tvb, 0, numVertices);
  157. bgfx::setIndexBuffer(&tib, offset, cmd->ElemCount);
  158. bgfx::submit(cmd->ViewId, program);
  159. }
  160. offset += cmd->ElemCount;
  161. }
  162. }
  163. }
  164. void create(float _fontSize, bx::AllocatorI* _allocator)
  165. {
  166. m_viewId = 255;
  167. m_allocator = _allocator;
  168. m_lastScroll = 0;
  169. m_last = bx::getHPCounter();
  170. ImGuiIO& io = ImGui::GetIO();
  171. io.RenderDrawListsFn = renderDrawLists;
  172. if (NULL != m_allocator)
  173. {
  174. io.MemAllocFn = memAlloc;
  175. io.MemFreeFn = memFree;
  176. }
  177. io.DisplaySize = ImVec2(1280.0f, 720.0f);
  178. io.DeltaTime = 1.0f / 60.0f;
  179. io.IniFilename = NULL;
  180. setupStyle(true);
  181. #if defined(SCI_NAMESPACE)
  182. io.KeyMap[ImGuiKey_Tab] = (int)entry::Key::Tab;
  183. io.KeyMap[ImGuiKey_LeftArrow] = (int)entry::Key::Left;
  184. io.KeyMap[ImGuiKey_RightArrow] = (int)entry::Key::Right;
  185. io.KeyMap[ImGuiKey_UpArrow] = (int)entry::Key::Up;
  186. io.KeyMap[ImGuiKey_DownArrow] = (int)entry::Key::Down;
  187. io.KeyMap[ImGuiKey_Home] = (int)entry::Key::Home;
  188. io.KeyMap[ImGuiKey_End] = (int)entry::Key::End;
  189. io.KeyMap[ImGuiKey_Delete] = (int)entry::Key::Delete;
  190. io.KeyMap[ImGuiKey_Backspace] = (int)entry::Key::Backspace;
  191. io.KeyMap[ImGuiKey_Enter] = (int)entry::Key::Return;
  192. io.KeyMap[ImGuiKey_Escape] = (int)entry::Key::Esc;
  193. io.KeyMap[ImGuiKey_A] = (int)entry::Key::KeyA;
  194. io.KeyMap[ImGuiKey_C] = (int)entry::Key::KeyC;
  195. io.KeyMap[ImGuiKey_V] = (int)entry::Key::KeyV;
  196. io.KeyMap[ImGuiKey_X] = (int)entry::Key::KeyX;
  197. io.KeyMap[ImGuiKey_Y] = (int)entry::Key::KeyY;
  198. io.KeyMap[ImGuiKey_Z] = (int)entry::Key::KeyZ;
  199. #endif // defined(SCI_NAMESPACE)
  200. const bgfx::Memory* vsmem;
  201. const bgfx::Memory* fsmem;
  202. switch (bgfx::getRendererType() )
  203. {
  204. case bgfx::RendererType::Direct3D9:
  205. vsmem = bgfx::makeRef(vs_ocornut_imgui_dx9, sizeof(vs_ocornut_imgui_dx9) );
  206. fsmem = bgfx::makeRef(fs_ocornut_imgui_dx9, sizeof(fs_ocornut_imgui_dx9) );
  207. break;
  208. case bgfx::RendererType::Direct3D11:
  209. case bgfx::RendererType::Direct3D12:
  210. vsmem = bgfx::makeRef(vs_ocornut_imgui_dx11, sizeof(vs_ocornut_imgui_dx11) );
  211. fsmem = bgfx::makeRef(fs_ocornut_imgui_dx11, sizeof(fs_ocornut_imgui_dx11) );
  212. break;
  213. case bgfx::RendererType::Metal:
  214. vsmem = bgfx::makeRef(vs_ocornut_imgui_mtl, sizeof(vs_ocornut_imgui_mtl) );
  215. fsmem = bgfx::makeRef(fs_ocornut_imgui_mtl, sizeof(fs_ocornut_imgui_mtl) );
  216. break;
  217. default:
  218. vsmem = bgfx::makeRef(vs_ocornut_imgui_glsl, sizeof(vs_ocornut_imgui_glsl) );
  219. fsmem = bgfx::makeRef(fs_ocornut_imgui_glsl, sizeof(fs_ocornut_imgui_glsl) );
  220. break;
  221. }
  222. bgfx::ShaderHandle vsh = bgfx::createShader(vsmem);
  223. bgfx::ShaderHandle fsh = bgfx::createShader(fsmem);
  224. m_program = bgfx::createProgram(vsh, fsh, true);
  225. m_decl
  226. .begin()
  227. .add(bgfx::Attrib::Position, 2, bgfx::AttribType::Float)
  228. .add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float)
  229. .add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true)
  230. .end();
  231. s_tex = bgfx::createUniform("s_tex", bgfx::UniformType::Int1);
  232. uint8_t* data;
  233. int32_t width;
  234. int32_t height;
  235. {
  236. ImFontConfig config;
  237. config.FontDataOwnedByAtlas = false;
  238. config.MergeMode = false;
  239. // config.MergeGlyphCenterV = true;
  240. m_font[ImGui::Font::Regular] = io.Fonts->AddFontFromMemoryTTF( (void*)s_robotoRegularTtf, sizeof(s_robotoRegularTtf), _fontSize, &config);
  241. m_font[ImGui::Font::Mono ] = io.Fonts->AddFontFromMemoryTTF( (void*)s_robotoMonoRegularTtf, sizeof(s_robotoMonoRegularTtf), _fontSize-3.0f, &config);
  242. config.MergeMode = true;
  243. config.DstFont = m_font[ImGui::Font::Regular];
  244. for (uint32_t ii = 0; ii < BX_COUNTOF(s_fontRangeMerge); ++ii)
  245. {
  246. const FontRangeMerge& frm = s_fontRangeMerge[ii];
  247. io.Fonts->AddFontFromMemoryTTF( (void*)frm.data
  248. , (int)frm.size
  249. , _fontSize-3.0f
  250. , &config
  251. , frm.ranges
  252. );
  253. }
  254. }
  255. io.Fonts->GetTexDataAsRGBA32(&data, &width, &height);
  256. m_texture = bgfx::createTexture2D(
  257. (uint16_t)width
  258. , (uint16_t)height
  259. , false
  260. , 1
  261. , bgfx::TextureFormat::BGRA8
  262. , 0
  263. , bgfx::copy(data, width*height*4)
  264. );
  265. ImGui::InitDockContext();
  266. }
  267. void destroy()
  268. {
  269. ImGui::ShutdownDockContext();
  270. ImGui::Shutdown();
  271. bgfx::destroyUniform(s_tex);
  272. bgfx::destroyTexture(m_texture);
  273. bgfx::destroyProgram(m_program);
  274. m_allocator = NULL;
  275. }
  276. void setupStyle(bool _dark)
  277. {
  278. // Doug Binks' darl color scheme
  279. // https://gist.github.com/dougbinks/8089b4bbaccaaf6fa204236978d165a9
  280. ImGuiStyle& style = ImGui::GetStyle();
  281. style.FrameRounding = 4.0f;
  282. // light style from Pacome Danhiez (user itamago)
  283. // https://github.com/ocornut/imgui/pull/511#issuecomment-175719267
  284. style.Colors[ImGuiCol_Text] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f);
  285. style.Colors[ImGuiCol_TextDisabled] = ImVec4(0.60f, 0.60f, 0.60f, 1.00f);
  286. style.Colors[ImGuiCol_WindowBg] = ImVec4(0.94f, 0.94f, 0.94f, 1.00f);
  287. style.Colors[ImGuiCol_ChildWindowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
  288. style.Colors[ImGuiCol_Border] = ImVec4(0.00f, 0.00f, 0.00f, 0.39f);
  289. style.Colors[ImGuiCol_BorderShadow] = ImVec4(1.00f, 1.00f, 1.00f, 0.10f);
  290. style.Colors[ImGuiCol_FrameBg] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
  291. style.Colors[ImGuiCol_FrameBgHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.40f);
  292. style.Colors[ImGuiCol_FrameBgActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f);
  293. style.Colors[ImGuiCol_TitleBg] = ImVec4(0.96f, 0.96f, 0.96f, 1.00f);
  294. style.Colors[ImGuiCol_TitleBgCollapsed] = ImVec4(1.00f, 1.00f, 1.00f, 0.51f);
  295. style.Colors[ImGuiCol_TitleBgActive] = ImVec4(0.82f, 0.82f, 0.82f, 1.00f);
  296. style.Colors[ImGuiCol_MenuBarBg] = ImVec4(0.86f, 0.86f, 0.86f, 1.00f);
  297. style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.98f, 0.98f, 0.98f, 0.53f);
  298. style.Colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.69f, 0.69f, 0.69f, 0.80f);
  299. style.Colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.49f, 0.49f, 0.49f, 0.80f);
  300. style.Colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.49f, 0.49f, 0.49f, 1.00f);
  301. style.Colors[ImGuiCol_ComboBg] = ImVec4(0.86f, 0.86f, 0.86f, 0.99f);
  302. style.Colors[ImGuiCol_CheckMark] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
  303. style.Colors[ImGuiCol_SliderGrab] = ImVec4(0.26f, 0.59f, 0.98f, 0.78f);
  304. style.Colors[ImGuiCol_SliderGrabActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
  305. style.Colors[ImGuiCol_Button] = ImVec4(0.26f, 0.59f, 0.98f, 0.40f);
  306. style.Colors[ImGuiCol_ButtonHovered] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
  307. style.Colors[ImGuiCol_ButtonActive] = ImVec4(0.06f, 0.53f, 0.98f, 1.00f);
  308. style.Colors[ImGuiCol_Header] = ImVec4(0.26f, 0.59f, 0.98f, 0.31f);
  309. style.Colors[ImGuiCol_HeaderHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.80f);
  310. style.Colors[ImGuiCol_HeaderActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
  311. style.Colors[ImGuiCol_Column] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f);
  312. style.Colors[ImGuiCol_ColumnHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.78f);
  313. style.Colors[ImGuiCol_ColumnActive] = ImVec4(0.26f, 0.59f, 0.98f, 1.00f);
  314. style.Colors[ImGuiCol_ResizeGrip] = ImVec4(1.00f, 1.00f, 1.00f, 0.50f);
  315. style.Colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.26f, 0.59f, 0.98f, 0.67f);
  316. style.Colors[ImGuiCol_ResizeGripActive] = ImVec4(0.26f, 0.59f, 0.98f, 0.95f);
  317. style.Colors[ImGuiCol_CloseButton] = ImVec4(0.59f, 0.59f, 0.59f, 0.50f);
  318. style.Colors[ImGuiCol_CloseButtonHovered] = ImVec4(0.98f, 0.39f, 0.36f, 1.00f);
  319. style.Colors[ImGuiCol_CloseButtonActive] = ImVec4(0.98f, 0.39f, 0.36f, 1.00f);
  320. style.Colors[ImGuiCol_PlotLines] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f);
  321. style.Colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f);
  322. style.Colors[ImGuiCol_PlotHistogram] = ImVec4(0.90f, 0.70f, 0.00f, 1.00f);
  323. style.Colors[ImGuiCol_PlotHistogramHovered] = ImVec4(1.00f, 0.60f, 0.00f, 1.00f);
  324. style.Colors[ImGuiCol_TextSelectedBg] = ImVec4(0.26f, 0.59f, 0.98f, 0.35f);
  325. style.Colors[ImGuiCol_PopupBg] = ImVec4(1.00f, 1.00f, 1.00f, 0.94f);
  326. style.Colors[ImGuiCol_ModalWindowDarkening] = ImVec4(0.20f, 0.20f, 0.20f, 0.35f);
  327. if (_dark)
  328. {
  329. for (int i = 0; i <= ImGuiCol_COUNT; i++)
  330. {
  331. ImVec4& col = style.Colors[i];
  332. float H, S, V;
  333. ImGui::ColorConvertRGBtoHSV( col.x, col.y, col.z, H, S, V );
  334. if( S < 0.1f )
  335. {
  336. V = 1.0f - V;
  337. }
  338. ImGui::ColorConvertHSVtoRGB( H, S, V, col.x, col.y, col.z );
  339. }
  340. }
  341. }
  342. void beginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, int _width, int _height, char _inputChar, uint8_t _viewId)
  343. {
  344. m_viewId = _viewId;
  345. ImGuiIO& io = ImGui::GetIO();
  346. if (_inputChar < 0x7f)
  347. {
  348. io.AddInputCharacter(_inputChar); // ASCII or GTFO! :(
  349. }
  350. io.DisplaySize = ImVec2( (float)_width, (float)_height);
  351. const int64_t now = bx::getHPCounter();
  352. const int64_t frameTime = now - m_last;
  353. m_last = now;
  354. const double freq = double(bx::getHPFrequency() );
  355. io.DeltaTime = float(frameTime/freq);
  356. io.MousePos = ImVec2( (float)_mx, (float)_my);
  357. io.MouseDown[0] = 0 != (_button & IMGUI_MBUT_LEFT);
  358. io.MouseDown[1] = 0 != (_button & IMGUI_MBUT_RIGHT);
  359. io.MouseDown[2] = 0 != (_button & IMGUI_MBUT_MIDDLE);
  360. io.MouseWheel = (float)(_scroll - m_lastScroll);
  361. m_lastScroll = _scroll;
  362. #if defined(SCI_NAMESPACE)
  363. uint8_t modifiers = inputGetModifiersState();
  364. io.KeyShift = 0 != (modifiers & (entry::Modifier::LeftShift | entry::Modifier::RightShift) );
  365. io.KeyCtrl = 0 != (modifiers & (entry::Modifier::LeftCtrl | entry::Modifier::RightCtrl ) );
  366. io.KeyAlt = 0 != (modifiers & (entry::Modifier::LeftAlt | entry::Modifier::RightAlt ) );
  367. for (int32_t ii = 0; ii < (int32_t)entry::Key::Count; ++ii)
  368. {
  369. io.KeysDown[ii] = inputGetKeyState(entry::Key::Enum(ii) );
  370. }
  371. #endif // defined(SCI_NAMESPACE)
  372. ImGui::NewFrame();
  373. ImGuizmo::BeginFrame();
  374. ImGui::PushStyleVar(ImGuiStyleVar_ViewId, (float)_viewId);
  375. }
  376. void endFrame()
  377. {
  378. ImGui::PopStyleVar(1);
  379. ImGui::Render();
  380. }
  381. bx::AllocatorI* m_allocator;
  382. bgfx::VertexDecl m_decl;
  383. bgfx::ProgramHandle m_program;
  384. bgfx::TextureHandle m_texture;
  385. bgfx::UniformHandle s_tex;
  386. ImFont* m_font[ImGui::Font::Count];
  387. int64_t m_last;
  388. int32_t m_lastScroll;
  389. uint8_t m_viewId;
  390. };
  391. static OcornutImguiContext s_ctx;
  392. void* OcornutImguiContext::memAlloc(size_t _size)
  393. {
  394. return BX_ALLOC(s_ctx.m_allocator, _size);
  395. }
  396. void OcornutImguiContext::memFree(void* _ptr)
  397. {
  398. BX_FREE(s_ctx.m_allocator, _ptr);
  399. }
  400. void OcornutImguiContext::renderDrawLists(ImDrawData* _drawData)
  401. {
  402. s_ctx.render(_drawData);
  403. }
  404. void IMGUI_create(float _fontSize, bx::AllocatorI* _allocator)
  405. {
  406. s_ctx.create(_fontSize, _allocator);
  407. }
  408. void IMGUI_destroy()
  409. {
  410. s_ctx.destroy();
  411. }
  412. void IMGUI_beginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, int _width, int _height, char _inputChar, uint8_t _viewId)
  413. {
  414. s_ctx.beginFrame(_mx, _my, _button, _scroll, _width, _height, _inputChar, _viewId);
  415. }
  416. void IMGUI_endFrame()
  417. {
  418. s_ctx.endFrame();
  419. }
  420. namespace ImGui
  421. {
  422. void PushFont(Font::Enum _font)
  423. {
  424. PushFont(s_ctx.m_font[_font]);
  425. }
  426. } // namespace ImGui