summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/bgfx/examples/common/imgui/imgui.cpp
diff options
context:
space:
mode:
author mooglyguy <therealmogminer@gmail.com>2018-12-05 19:45:08 +0100
committer mooglyguy <therealmogminer@gmail.com>2018-12-05 19:45:08 +0100
commit0bd02131b644b61088789f52f31b750c9aecaa6d (patch)
tree811c679a1bba8b24fc7967cdfe73640254d64156 /3rdparty/bgfx/examples/common/imgui/imgui.cpp
parent9a81ec7eaf00d73a23db5c003dc45b55d4b76c4a (diff)
3rdparty: Updated bgfx, bimg, and bx to latest upstream. [Ryan Holtz]
Diffstat (limited to '3rdparty/bgfx/examples/common/imgui/imgui.cpp')
-rw-r--r--3rdparty/bgfx/examples/common/imgui/imgui.cpp113
1 files changed, 58 insertions, 55 deletions
diff --git a/3rdparty/bgfx/examples/common/imgui/imgui.cpp b/3rdparty/bgfx/examples/common/imgui/imgui.cpp
index 3a29d57efc9..6cd4b13c191 100644
--- a/3rdparty/bgfx/examples/common/imgui/imgui.cpp
+++ b/3rdparty/bgfx/examples/common/imgui/imgui.cpp
@@ -8,11 +8,13 @@
#include <bx/allocator.h>
#include <bx/math.h>
#include <bx/timer.h>
-#include <ocornut-imgui/imgui.h>
+#include <dear-imgui/imgui.h>
#include "imgui.h"
#include "../bgfx_utils.h"
+//#define USE_ENTRY 1
+
#ifndef USE_ENTRY
# if defined(SCI_NAMESPACE)
# define USE_ENTRY 1
@@ -23,10 +25,10 @@
#if USE_ENTRY
# include "../entry/entry.h"
+# include "../entry/input.h"
#endif // USE_ENTRY
#if defined(SCI_NAMESPACE)
-# include "../entry/input.h"
# include "scintilla.h"
#endif // defined(SCI_NAMESPACE)
@@ -63,13 +65,11 @@ static FontRangeMerge s_fontRangeMerge[] =
{ s_iconsFontAwesomeTtf, sizeof(s_iconsFontAwesomeTtf), { ICON_MIN_FA, ICON_MAX_FA, 0 } },
};
-static void* memAlloc(size_t _size);
-static void memFree(void* _ptr);
+static void* memAlloc(size_t _size, void* _userData);
+static void memFree(void* _ptr, void* _userData);
struct OcornutImguiContext
{
- static void renderDrawLists(ImDrawData* _drawData);
-
void render(ImDrawData* _drawData)
{
const ImGuiIO& io = ImGui::GetIO();
@@ -79,29 +79,7 @@ struct OcornutImguiContext
bgfx::setViewName(m_viewId, "ImGui");
bgfx::setViewMode(m_viewId, bgfx::ViewMode::Sequential);
- const bgfx::HMD* hmd = bgfx::getHMD();
const bgfx::Caps* caps = bgfx::getCaps();
- if (NULL != hmd && 0 != (hmd->flags & BGFX_HMD_RENDERING) )
- {
- float proj[16];
- bx::mtxProj(proj, hmd->eye[0].fov, 0.1f, 100.0f, bgfx::getCaps()->homogeneousDepth);
-
- static float time = 0.0f;
- time += 0.05f;
-
- const float dist = 10.0f;
- const float offset0 = -proj[8] + (hmd->eye[0].viewOffset[0] / dist * proj[0]);
- const float offset1 = -proj[8] + (hmd->eye[1].viewOffset[0] / dist * proj[0]);
-
- float ortho[2][16];
- const float viewOffset = width/4.0f;
- const float viewWidth = width/2.0f;
- bx::mtxOrtho(ortho[0], viewOffset, viewOffset + viewWidth, height, 0.0f, 0.0f, 1000.0f, offset0, caps->homogeneousDepth);
- bx::mtxOrtho(ortho[1], viewOffset, viewOffset + viewWidth, height, 0.0f, 0.0f, 1000.0f, offset1, caps->homogeneousDepth);
- bgfx::setViewTransform(m_viewId, NULL, ortho[0], BGFX_VIEW_STEREO, ortho[1]);
- bgfx::setViewRect(m_viewId, 0, 0, hmd->width, hmd->height);
- }
- else
{
float ortho[16];
bx::mtxOrtho(ortho, 0.0f, width, height, 0.0f, 0.0f, 1000.0f, 0.0f, caps->homogeneousDepth);
@@ -144,8 +122,8 @@ struct OcornutImguiContext
else if (0 != cmd->ElemCount)
{
uint64_t state = 0
- | BGFX_STATE_RGB_WRITE
- | BGFX_STATE_ALPHA_WRITE
+ | BGFX_STATE_WRITE_RGB
+ | BGFX_STATE_WRITE_A
| BGFX_STATE_MSAA
;
@@ -172,18 +150,18 @@ struct OcornutImguiContext
state |= BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA);
}
- const uint16_t xx = uint16_t(bx::fmax(cmd->ClipRect.x, 0.0f) );
- const uint16_t yy = uint16_t(bx::fmax(cmd->ClipRect.y, 0.0f) );
+ const uint16_t xx = uint16_t(bx::max(cmd->ClipRect.x, 0.0f) );
+ const uint16_t yy = uint16_t(bx::max(cmd->ClipRect.y, 0.0f) );
bgfx::setScissor(xx, yy
- , uint16_t(bx::fmin(cmd->ClipRect.z, 65535.0f)-xx)
- , uint16_t(bx::fmin(cmd->ClipRect.w, 65535.0f)-yy)
+ , uint16_t(bx::min(cmd->ClipRect.z, 65535.0f)-xx)
+ , uint16_t(bx::min(cmd->ClipRect.w, 65535.0f)-yy)
);
bgfx::setState(state);
bgfx::setTexture(0, s_tex, th);
bgfx::setVertexBuffer(0, &tvb, 0, numVertices);
bgfx::setIndexBuffer(&tib, offset, cmd->ElemCount);
- bgfx::submit(cmd->ViewId, program);
+ bgfx::submit(m_viewId, program);
}
offset += cmd->ElemCount;
@@ -205,10 +183,11 @@ struct OcornutImguiContext
m_lastScroll = 0;
m_last = bx::getHPCounter();
+ ImGui::SetAllocatorFunctions(memAlloc, memFree, NULL);
+
+ m_imgui = ImGui::CreateContext();
+
ImGuiIO& io = ImGui::GetIO();
- io.RenderDrawListsFn = renderDrawLists;
- io.MemAllocFn = memAlloc;
- io.MemFreeFn = memFree;
io.DisplaySize = ImVec2(1280.0f, 720.0f);
io.DeltaTime = 1.0f / 60.0f;
@@ -216,16 +195,20 @@ struct OcornutImguiContext
setupStyle(true);
-#if defined(SCI_NAMESPACE)
+#if USE_ENTRY
io.KeyMap[ImGuiKey_Tab] = (int)entry::Key::Tab;
io.KeyMap[ImGuiKey_LeftArrow] = (int)entry::Key::Left;
io.KeyMap[ImGuiKey_RightArrow] = (int)entry::Key::Right;
io.KeyMap[ImGuiKey_UpArrow] = (int)entry::Key::Up;
io.KeyMap[ImGuiKey_DownArrow] = (int)entry::Key::Down;
+ io.KeyMap[ImGuiKey_PageUp] = (int)entry::Key::PageUp;
+ io.KeyMap[ImGuiKey_PageDown] = (int)entry::Key::PageDown;
io.KeyMap[ImGuiKey_Home] = (int)entry::Key::Home;
io.KeyMap[ImGuiKey_End] = (int)entry::Key::End;
+ io.KeyMap[ImGuiKey_Insert] = (int)entry::Key::Insert;
io.KeyMap[ImGuiKey_Delete] = (int)entry::Key::Delete;
io.KeyMap[ImGuiKey_Backspace] = (int)entry::Key::Backspace;
+ io.KeyMap[ImGuiKey_Space] = (int)entry::Key::Space;
io.KeyMap[ImGuiKey_Enter] = (int)entry::Key::Return;
io.KeyMap[ImGuiKey_Escape] = (int)entry::Key::Esc;
io.KeyMap[ImGuiKey_A] = (int)entry::Key::KeyA;
@@ -234,7 +217,29 @@ struct OcornutImguiContext
io.KeyMap[ImGuiKey_X] = (int)entry::Key::KeyX;
io.KeyMap[ImGuiKey_Y] = (int)entry::Key::KeyY;
io.KeyMap[ImGuiKey_Z] = (int)entry::Key::KeyZ;
-#endif // defined(SCI_NAMESPACE)
+
+ io.ConfigFlags |= 0
+ | ImGuiConfigFlags_NavEnableGamepad
+ | ImGuiConfigFlags_NavEnableKeyboard
+ ;
+
+ io.NavInputs[ImGuiNavInput_Activate] = (int)entry::Key::GamepadA;
+ io.NavInputs[ImGuiNavInput_Cancel] = (int)entry::Key::GamepadB;
+// io.NavInputs[ImGuiNavInput_Input] = (int)entry::Key::;
+// io.NavInputs[ImGuiNavInput_Menu] = (int)entry::Key::;
+ io.NavInputs[ImGuiNavInput_DpadLeft] = (int)entry::Key::GamepadLeft;
+ io.NavInputs[ImGuiNavInput_DpadRight] = (int)entry::Key::GamepadRight;
+ io.NavInputs[ImGuiNavInput_DpadUp] = (int)entry::Key::GamepadUp;
+ io.NavInputs[ImGuiNavInput_DpadDown] = (int)entry::Key::GamepadDown;
+// io.NavInputs[ImGuiNavInput_LStickLeft] = (int)entry::Key::;
+// io.NavInputs[ImGuiNavInput_LStickRight] = (int)entry::Key::;
+// io.NavInputs[ImGuiNavInput_LStickUp] = (int)entry::Key::;
+// io.NavInputs[ImGuiNavInput_LStickDown] = (int)entry::Key::;
+// io.NavInputs[ImGuiNavInput_FocusPrev] = (int)entry::Key::;
+// io.NavInputs[ImGuiNavInput_FocusNext] = (int)entry::Key::;
+// io.NavInputs[ImGuiNavInput_TweakSlow] = (int)entry::Key::;
+// io.NavInputs[ImGuiNavInput_TweakFast] = (int)entry::Key::;
+#endif // USE_ENTRY
bgfx::RendererType::Enum type = bgfx::getRendererType();
m_program = bgfx::createProgram(
@@ -306,7 +311,7 @@ struct OcornutImguiContext
void destroy()
{
ImGui::ShutdownDockContext();
- ImGui::Shutdown();
+ ImGui::DestroyContext(m_imgui);
bgfx::destroy(s_tex);
bgfx::destroy(m_texture);
@@ -332,7 +337,8 @@ struct OcornutImguiContext
ImGui::StyleColorsLight(&style);
}
- style.FrameRounding = 4.0f;
+ style.FrameRounding = 4.0f;
+ style.WindowBorderSize = 0.0f;
}
void beginFrame(
@@ -369,7 +375,7 @@ struct OcornutImguiContext
io.MouseWheel = (float)(_scroll - m_lastScroll);
m_lastScroll = _scroll;
-#if defined(SCI_NAMESPACE)
+#if USE_ENTRY
uint8_t modifiers = inputGetModifiersState();
io.KeyShift = 0 != (modifiers & (entry::Modifier::LeftShift | entry::Modifier::RightShift) );
io.KeyCtrl = 0 != (modifiers & (entry::Modifier::LeftCtrl | entry::Modifier::RightCtrl ) );
@@ -378,20 +384,20 @@ struct OcornutImguiContext
{
io.KeysDown[ii] = inputGetKeyState(entry::Key::Enum(ii) );
}
-#endif // defined(SCI_NAMESPACE)
+#endif // USE_ENTRY
ImGui::NewFrame();
- ImGui::PushStyleVar(ImGuiStyleVar_ViewId, (float)_viewId);
ImGuizmo::BeginFrame();
}
void endFrame()
{
- ImGui::PopStyleVar(1);
ImGui::Render();
+ render(ImGui::GetDrawData() );
}
+ ImGuiContext* m_imgui;
bx::AllocatorI* m_allocator;
bgfx::VertexDecl m_decl;
bgfx::ProgramHandle m_program;
@@ -407,21 +413,18 @@ struct OcornutImguiContext
static OcornutImguiContext s_ctx;
-static void* memAlloc(size_t _size)
+static void* memAlloc(size_t _size, void* _userData)
{
+ BX_UNUSED(_userData);
return BX_ALLOC(s_ctx.m_allocator, _size);
}
-static void memFree(void* _ptr)
+static void memFree(void* _ptr, void* _userData)
{
+ BX_UNUSED(_userData);
BX_FREE(s_ctx.m_allocator, _ptr);
}
-void OcornutImguiContext::renderDrawLists(ImDrawData* _drawData)
-{
- s_ctx.render(_drawData);
-}
-
void imguiCreate(float _fontSize, bx::AllocatorI* _allocator)
{
s_ctx.create(_fontSize, _allocator);
@@ -456,8 +459,8 @@ BX_PRAGMA_DIAGNOSTIC_PUSH();
BX_PRAGMA_DIAGNOSTIC_IGNORED_CLANG("-Wunknown-pragmas")
//BX_PRAGMA_DIAGNOSTIC_IGNORED_CLANG_GCC("-Wunused-but-set-variable"); // warning: variable ‘L1’ set but not used
BX_PRAGMA_DIAGNOSTIC_IGNORED_CLANG_GCC("-Wtype-limits"); // warning: comparison is always true due to limited range of data type
-#define STBTT_malloc(_size, _userData) memAlloc(_size)
-#define STBTT_free(_ptr, _userData) memFree(_ptr)
+#define STBTT_malloc(_size, _userData) memAlloc(_size, _userData)
+#define STBTT_free(_ptr, _userData) memFree(_ptr, _userData)
#define STB_RECT_PACK_IMPLEMENTATION
#include <stb/stb_rect_pack.h>
#define STB_TRUETYPE_IMPLEMENTATION