diff options
Diffstat (limited to '3rdparty/bgfx/examples/common/imgui')
-rw-r--r-- | 3rdparty/bgfx/examples/common/imgui/imgui.cpp | 6 | ||||
-rw-r--r-- | 3rdparty/bgfx/examples/common/imgui/imgui.h | 64 | ||||
-rw-r--r-- | 3rdparty/bgfx/examples/common/imgui/ocornut_imgui.cpp | 493 | ||||
-rw-r--r-- | 3rdparty/bgfx/examples/common/imgui/scintilla.cpp | 4 |
4 files changed, 495 insertions, 72 deletions
diff --git a/3rdparty/bgfx/examples/common/imgui/imgui.cpp b/3rdparty/bgfx/examples/common/imgui/imgui.cpp index 1ff8e090818..073191fde57 100644 --- a/3rdparty/bgfx/examples/common/imgui/imgui.cpp +++ b/3rdparty/bgfx/examples/common/imgui/imgui.cpp @@ -466,7 +466,7 @@ struct Imgui _size = sizeof(s_droidSansTtf); } - IMGUI_create(_data, _size, _fontSize, _allocator); + IMGUI_create(_data, _size, _fontSize, m_allocator); m_nvg = nvgCreate(1, m_view); nvgCreateFontMem(m_nvg, "default", (unsigned char*)_data, INT32_MAX, 0); @@ -3080,8 +3080,8 @@ struct Imgui bool visible(int32_t _elemY, int32_t _elemHeight, int32_t _scissorY, int32_t _scissorHeight) { - return _elemY > _scissorY - && (_elemY+_elemHeight) < (_scissorY+_scissorHeight); + return (_elemY+_elemHeight) > _scissorY + && (_elemY) < (_scissorY+_scissorHeight); } inline Area& getCurrentArea() diff --git a/3rdparty/bgfx/examples/common/imgui/imgui.h b/3rdparty/bgfx/examples/common/imgui/imgui.h index acd6e6daf98..e85b9d3a16a 100644 --- a/3rdparty/bgfx/examples/common/imgui/imgui.h +++ b/3rdparty/bgfx/examples/common/imgui/imgui.h @@ -26,8 +26,9 @@ #ifndef IMGUI_H_HEADER_GUARD #define IMGUI_H_HEADER_GUARD -#include <bgfx.h> +#include <bgfx/bgfx.h> #include <ocornut-imgui/imgui.h> +#include <ocornut-imgui/imgui_wm.h> #define IMGUI_MBUT_LEFT 0x01 #define IMGUI_MBUT_RIGHT 0x02 @@ -207,20 +208,65 @@ bool imguiMouseOverArea(); namespace ImGui { +#define IMGUI_FLAGS_NONE UINT16_C(0x0000) +#define IMGUI_FLAGS_ALPHA_BLEND UINT16_C(0x0001) + + // Helper function for passing bgfx::TextureHandle to ImGui::Image. + inline void Image(bgfx::TextureHandle _handle + , uint16_t _flags + , const ImVec2& _size + , const ImVec2& _uv0 = ImVec2(0.0f, 0.0f) + , const ImVec2& _uv1 = ImVec2(1.0f, 1.0f) + , const ImVec4& _tintCol = ImVec4(1.0f, 1.0f, 1.0f, 1.0f) + , const ImVec4& _borderCol = ImVec4(0.0f, 0.0f, 0.0f, 0.0f) + ) + { + union { struct { uint16_t flags; bgfx::TextureHandle handle; } s; ImTextureID ptr; } texture; + texture.s.flags = _flags; + texture.s.handle = _handle; + Image(texture.ptr, _size, _uv0, _uv1, _tintCol, _borderCol); + } + // Helper function for passing bgfx::TextureHandle to ImGui::Image. - inline void Image(bgfx::TextureHandle _handle, const ImVec2& _size, const ImVec2& _uv0 = ImVec2(0, 0), const ImVec2& _uv1 = ImVec2(1, 1), const ImVec4& _tint_col = ImVec4(1, 1, 1, 1), const ImVec4& _border_col = ImVec4(0, 0, 0, 0) ) + inline void Image(bgfx::TextureHandle _handle + , const ImVec2& _size + , const ImVec2& _uv0 = ImVec2(0.0f, 0.0f) + , const ImVec2& _uv1 = ImVec2(1.0f, 1.0f) + , const ImVec4& _tintCol = ImVec4(1.0f, 1.0f, 1.0f, 1.0f) + , const ImVec4& _borderCol = ImVec4(0.0f, 0.0f, 0.0f, 0.0f) + ) + { + Image(_handle, IMGUI_FLAGS_ALPHA_BLEND, _size, _uv0, _uv1, _tintCol, _borderCol); + } + + // Helper function for passing bgfx::TextureHandle to ImGui::ImageButton. + inline bool ImageButton(bgfx::TextureHandle _handle + , uint16_t _flags + , const ImVec2& _size + , const ImVec2& _uv0 = ImVec2(0.0f, 0.0f) + , const ImVec2& _uv1 = ImVec2(1.0f, 1.0f) + , int _framePadding = -1 + , const ImVec4& _bgCol = ImVec4(0.0f, 0.0f, 0.0f, 0.0f) + , const ImVec4& _tintCol = ImVec4(1.0f, 1.0f, 1.0f, 1.0f) + ) { - union { bgfx::TextureHandle handle; ImTextureID ptr; } texture; - texture.handle = _handle; - Image(texture.ptr, _size, _uv0, _uv1, _tint_col, _border_col); + union { struct { uint16_t flags; bgfx::TextureHandle handle; } s; ImTextureID ptr; } texture; + texture.s.flags = _flags; + texture.s.handle = _handle; + return ImageButton(texture.ptr, _size, _uv0, _uv1, _framePadding, _bgCol, _tintCol); } // Helper function for passing bgfx::TextureHandle to ImGui::ImageButton. - inline bool ImageButton(bgfx::TextureHandle _handle, const ImVec2& _size, const ImVec2& _uv0 = ImVec2(0,0), const ImVec2& _uv1 = ImVec2(1,1), int _frame_padding = -1, const ImVec4& _bg_col = ImVec4(0,0,0,0), const ImVec4& _tint_col = ImVec4(1,1,1,1)) + inline bool ImageButton(bgfx::TextureHandle _handle + , const ImVec2& _size + , const ImVec2& _uv0 = ImVec2(0.0f, 0.0f) + , const ImVec2& _uv1 = ImVec2(1.0f, 1.0f) + , int _framePadding = -1 + , const ImVec4& _bgCol = ImVec4(0.0f, 0.0f, 0.0f, 0.0f) + , const ImVec4& _tintCol = ImVec4(1.0f, 1.0f, 1.0f, 1.0f) + ) { - union { bgfx::TextureHandle handle; ImTextureID ptr; } texture; - texture.handle = _handle; - return ImageButton(texture.ptr, _size, _uv0, _uv1, _frame_padding, _bg_col, _tint_col); + return ImageButton(_handle, IMGUI_FLAGS_ALPHA_BLEND, _size, _uv0, _uv1, _framePadding, _bgCol, _tintCol); } } // namespace ImGui diff --git a/3rdparty/bgfx/examples/common/imgui/ocornut_imgui.cpp b/3rdparty/bgfx/examples/common/imgui/ocornut_imgui.cpp index aff41ac376a..8efddcc65f8 100644 --- a/3rdparty/bgfx/examples/common/imgui/ocornut_imgui.cpp +++ b/3rdparty/bgfx/examples/common/imgui/ocornut_imgui.cpp @@ -3,15 +3,24 @@ * License: http://www.opensource.org/licenses/BSD-2-Clause */ -#include <bgfx.h> +#include <bgfx/bgfx.h> #include <bx/allocator.h> #include <bx/fpumath.h> #include <bx/timer.h> #include <ocornut-imgui/imgui.h> +#include <ocornut-imgui/imgui_wm.h> #include "imgui.h" #include "ocornut_imgui.h" #include <stb/stb_image.c> +#ifndef USE_ENTRY +# define USE_ENTRY defined(SCI_NAMESPACE) +#endif // USE_ENTRY + +#if USE_ENTRY +# include "../entry/entry.h" +#endif // USE_ENTRY + #if defined(SCI_NAMESPACE) # include "../entry/input.h" # include "scintilla.h" @@ -20,86 +29,334 @@ #include "vs_ocornut_imgui.bin.h" #include "fs_ocornut_imgui.bin.h" +void viewCallback(const ImDrawList* _parentList, const ImDrawCmd* _cmd); + +class PlatformWindow : public ImGuiWM::PlatformWindow +{ + typedef ImGuiWM::PlatformWindow Super; + +public: + PlatformWindow(bool _mainWindow, bool _isDragWindow) + : ImGuiWM::PlatformWindow(_mainWindow, _isDragWindow) + , m_pos(0.0f, 0.0f) + , m_size(0.0f, 0.0f) + , m_drag(false) + { +#if USE_ENTRY + if (!_mainWindow + && !_isDragWindow) + { + m_window = entry::createWindow(0, 0, 640, 380); + extern void pwToWindow(entry::WindowHandle _handle, PlatformWindow* _pw); + pwToWindow(m_window, this); + } + else + { + m_window.idx = 0; + } +#endif // USE_ENTRY + } + + virtual ~PlatformWindow() BX_OVERRIDE + { + } + + virtual bool Init(ImGuiWM::PlatformWindow* /*_parent*/) BX_OVERRIDE + { + return true; + } + + virtual const ImVec2& GetPosition() const BX_OVERRIDE + { + return m_pos; + } + + virtual const ImVec2& GetSize() const BX_OVERRIDE + { + return m_size; + } + + virtual void Show() BX_OVERRIDE + { + } + + virtual void Hide() BX_OVERRIDE + { + } + + virtual void SetSize(const ImVec2& _size) BX_OVERRIDE + { +#if USE_ENTRY + if (0 != m_window.idx + && m_size.x != _size.x + && m_size.y != _size.y) + { + entry::setWindowSize(m_window, int32_t(_size.x), int32_t(_size.y) ); + } +#endif // USE_ENTRY + + m_size = _size; + } + + virtual void SetPosition(const ImVec2& _pos) BX_OVERRIDE + { + +#if USE_ENTRY + if (0 != m_window.idx + && m_pos.x != _pos.x + && m_pos.y != _pos.y) + { + entry::setWindowPos(m_window, int32_t(_pos.x), int32_t(_pos.y) ); + } +#endif // USE_ENTRY + + m_pos = _pos; + } + + virtual void SetTitle(const char* _title) BX_OVERRIDE + { +#if USE_ENTRY + entry::setWindowTitle(m_window, _title); +#else + BX_UNUSED(_title); +#endif // USE_ENTRY + } + + virtual void PreUpdate() BX_OVERRIDE + { + } + + virtual void PaintBegin() + { +#if USE_ENTRY + if (!m_bIsDragWindow) + { + ImDrawList* drawList = ImGui::GetWindowDrawList(); + union { entry::WindowHandle handle; void* ptr; } cast = { m_window }; + drawList->AddCallback(viewCallback, cast.ptr); + drawList->PushClipRect(ImVec4(0.0f, 0.0f, m_size.x, m_size.y) ); + } +#endif // USE_ENTRY + } + + virtual void Paint() BX_OVERRIDE + { + if (!m_bIsDragWindow) + { + Super::Paint(); + } + } + + virtual void PaintEnd() + { +#if USE_ENTRY + if (!m_bIsDragWindow) + { + ImDrawList* drawList = ImGui::GetWindowDrawList(); + drawList->PopClipRect(); + drawList->AddCallback(viewCallback, NULL); + } +#endif // USE_ENTRY + } + + virtual void Destroy() BX_OVERRIDE + { + } + + virtual void StartDrag() BX_OVERRIDE + { + m_drag = true; + } + + virtual void StopDrag() BX_OVERRIDE + { + m_drag = false; + } + + virtual bool IsDraging() BX_OVERRIDE + { + return m_drag; + } + +private: + ImVec2 m_pos; + ImVec2 m_size; + bool m_drag; + +#if USE_ENTRY + entry::WindowHandle m_window; +#endif // USE_ENTRY +}; + +class WindowManager : public ImGuiWM::WindowManager +{ + typedef ImGuiWM::WindowManager Super; + +public: + WindowManager() + { + } + + virtual ~WindowManager() BX_OVERRIDE + { + } + +protected: + virtual ImGuiWM::PlatformWindow* CreatePlatformWindow(bool _main, ImGuiWM::PlatformWindow* _parent, bool _isDragWindow) BX_OVERRIDE + { +#if USE_ENTRY +#else + if (!_main + && !_isDragWindow) + { + return NULL; + } +#endif // USE_ENTRY + + PlatformWindow* window = new (ImGui::MemAlloc(sizeof(PlatformWindow) ) ) PlatformWindow(_main, _isDragWindow); + window->Init(_parent); + return static_cast<ImGuiWM::PlatformWindow*>(window); + } + + virtual void LogFormatted(const char* _str) BX_OVERRIDE + { + BX_TRACE("%s", _str); BX_UNUSED(_str); + } + + virtual void InternalRun() BX_OVERRIDE + { + PreUpdate(); + Update(); + } +}; + struct OcornutImguiContext { static void* memAlloc(size_t _size); static void memFree(void* _ptr); - static void renderDrawLists(ImDrawData* draw_data); + static void renderDrawLists(ImDrawData* _drawData); - void render(ImDrawData* draw_data) + void render(ImDrawData* _drawData) { - const float width = ImGui::GetIO().DisplaySize.x; - const float height = ImGui::GetIO().DisplaySize.y; + const ImGuiIO& io = ImGui::GetIO(); + const float width = io.DisplaySize.x; + const float height = io.DisplaySize.y; - float ortho[16]; - bx::mtxOrtho(ortho, 0.0f, width, height, 0.0f, -1.0f, 1.0f); + { + float ortho[16]; + bx::mtxOrtho(ortho, 0.0f, width, height, 0.0f, -1.0f, 1.0f); + bgfx::setViewTransform(m_viewId, NULL, ortho); + } - bgfx::setViewTransform(m_viewId, NULL, ortho); +#if USE_ENTRY + for (uint32_t ii = 1; ii < BX_COUNTOF(m_window); ++ii) + { + Window& window = m_window[ii]; + if (bgfx::isValid(window.m_fbh) ) + { + const uint8_t viewId = window.m_viewId; + bgfx::setViewClear(viewId + , BGFX_CLEAR_COLOR|BGFX_CLEAR_DEPTH + , 0x303030ff + rand() + , 1.0f + , 0 + ); + bgfx::setViewFrameBuffer(viewId, window.m_fbh); + bgfx::setViewRect(viewId + , 0 + , 0 + , window.m_state.m_width + , window.m_state.m_height + ); + float ortho[16]; + bx::mtxOrtho(ortho + , 0.0f + , float(window.m_state.m_width) + , float(window.m_state.m_height) + , 0.0f + , -1.0f + , 1.0f + ); + bgfx::setViewTransform(viewId + , NULL + , ortho + ); + } + } +#endif // USE_ENTRY // Render command lists - for (int32_t ii = 0; ii < draw_data->CmdListsCount; ++ii) + for (int32_t ii = 0, num = _drawData->CmdListsCount; ii < num; ++ii) { bgfx::TransientVertexBuffer tvb; bgfx::TransientIndexBuffer tib; - const ImDrawList* cmd_list = draw_data->CmdLists[ii]; - uint32_t vtx_size = (uint32_t)cmd_list->VtxBuffer.size(); - uint32_t idx_size = (uint32_t)cmd_list->IdxBuffer.size(); + const ImDrawList* drawList = _drawData->CmdLists[ii]; + uint32_t numVertices = (uint32_t)drawList->VtxBuffer.size(); + uint32_t numIndices = (uint32_t)drawList->IdxBuffer.size(); - if (!bgfx::checkAvailTransientVertexBuffer(vtx_size, m_decl) || !bgfx::checkAvailTransientIndexBuffer(idx_size) ) + if (!bgfx::checkAvailTransientVertexBuffer(numVertices, m_decl) + || !bgfx::checkAvailTransientIndexBuffer(numIndices) ) { // not enough space in transient buffer just quit drawing the rest... break; } - bgfx::allocTransientVertexBuffer(&tvb, vtx_size, m_decl); - bgfx::allocTransientIndexBuffer(&tib, idx_size); + bgfx::allocTransientVertexBuffer(&tvb, numVertices, m_decl); + bgfx::allocTransientIndexBuffer(&tib, numIndices); ImDrawVert* verts = (ImDrawVert*)tvb.data; - memcpy(verts, cmd_list->VtxBuffer.begin(), vtx_size * sizeof(ImDrawVert) ); + memcpy(verts, drawList->VtxBuffer.begin(), numVertices * sizeof(ImDrawVert) ); ImDrawIdx* indices = (ImDrawIdx*)tib.data; - memcpy(indices, cmd_list->IdxBuffer.begin(), idx_size * sizeof(ImDrawIdx) ); + memcpy(indices, drawList->IdxBuffer.begin(), numIndices * sizeof(ImDrawIdx) ); - uint32_t elem_offset = 0; - const ImDrawCmd* pcmd_begin = cmd_list->CmdBuffer.begin(); - const ImDrawCmd* pcmd_end = cmd_list->CmdBuffer.end(); - for (const ImDrawCmd* pcmd = pcmd_begin; pcmd != pcmd_end; pcmd++) + uint32_t offset = 0; + for (const ImDrawCmd* cmd = drawList->CmdBuffer.begin(), *cmdEnd = drawList->CmdBuffer.end(); cmd != cmdEnd; ++cmd) { - if (pcmd->UserCallback) + if (cmd->UserCallback) { - pcmd->UserCallback(cmd_list, pcmd); - elem_offset += pcmd->ElemCount; - continue; + cmd->UserCallback(drawList, cmd); } - if (0 == pcmd->ElemCount) + else if (0 != cmd->ElemCount) { - continue; + uint64_t state = 0 + | BGFX_STATE_RGB_WRITE + | BGFX_STATE_ALPHA_WRITE + | BGFX_STATE_MSAA + ; + + bgfx::TextureHandle th = m_texture; + + if (NULL != cmd->TextureId) + { + union { ImTextureID ptr; struct { uint16_t flags; bgfx::TextureHandle handle; } s; } texture = { cmd->TextureId }; + state |= 0 != (IMGUI_FLAGS_ALPHA_BLEND & texture.s.flags) + ? BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA) + : BGFX_STATE_NONE + ; + th = texture.s.handle; + } + else + { + 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) ); + bgfx::setScissor(xx, yy + , uint16_t(bx::fmin(cmd->ClipRect.z, 65535.0f)-xx) + , uint16_t(bx::fmin(cmd->ClipRect.w, 65535.0f)-yy) + ); + + bgfx::setState(state); + bgfx::setTexture(0, s_tex, th); + bgfx::setVertexBuffer(&tvb, 0, numVertices); + bgfx::setIndexBuffer(&tib, offset, cmd->ElemCount); + bgfx::submit(m_viewId, m_program); } - bgfx::setState(0 - | BGFX_STATE_RGB_WRITE - | BGFX_STATE_ALPHA_WRITE - | BGFX_STATE_BLEND_FUNC(BGFX_STATE_BLEND_SRC_ALPHA, BGFX_STATE_BLEND_INV_SRC_ALPHA) - | BGFX_STATE_MSAA - ); - bgfx::setScissor(uint16_t(bx::fmax(pcmd->ClipRect.x, 0.0f) ) - , uint16_t(bx::fmax(pcmd->ClipRect.y, 0.0f) ) - , uint16_t(bx::fmin(pcmd->ClipRect.z, 65535.0f)-bx::fmax(pcmd->ClipRect.x, 0.0f) ) - , uint16_t(bx::fmin(pcmd->ClipRect.w, 65535.0f)-bx::fmax(pcmd->ClipRect.y, 0.0f) ) - ); - union { void* ptr; bgfx::TextureHandle handle; } texture = { pcmd->TextureId }; - - bgfx::setTexture(0, s_tex, 0 != texture.handle.idx - ? texture.handle - : m_texture - ); - - bgfx::setVertexBuffer(&tvb, 0, vtx_size); - bgfx::setIndexBuffer(&tib, elem_offset, pcmd->ElemCount); - bgfx::submit(m_viewId, m_program); - - elem_offset += pcmd->ElemCount; + offset += cmd->ElemCount; } } } @@ -176,9 +433,9 @@ struct OcornutImguiContext m_decl .begin() - .add(bgfx::Attrib::Position, 2, bgfx::AttribType::Float) + .add(bgfx::Attrib::Position, 2, bgfx::AttribType::Float) .add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float) - .add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true) + .add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true) .end(); s_tex = bgfx::createUniform("s_tex", bgfx::UniformType::Int1); @@ -202,10 +459,61 @@ struct OcornutImguiContext ImGuiStyle& style = ImGui::GetStyle(); style.FrameRounding = 4.0f; + + m_wm = BX_NEW(m_allocator, WindowManager); + m_wm->Init(); + +#if 0 + { + class Window : public ImGuiWM::Window + { + public: + Window(const char* _title) + : ImGuiWM::Window() + { + SetTitle(_title); + } + + virtual void OnGui() BX_OVERRIDE + { + } + }; + + class WindowX : public ImGuiWM::Window + { + public: + WindowX(const char* _title) + : ImGuiWM::Window() + { + SetTitle(_title); + } + + virtual void OnGui() BX_OVERRIDE + { +#if defined(SCI_NAMESPACE) && 0 + bool opened = true; + ImGuiScintilla("Scintilla Editor", &opened, ImVec2(640.0f, 480.0f) ); +#endif // 0 + } + }; + + Window* w0 = new Window("test"); + WindowX* w1 = new WindowX("abcd"); + Window* w2 = new Window("xyzw"); + Window* w3 = new Window("0123"); + + m_wm->Dock(w0); + m_wm->DockWith(w1, w0, ImGuiWM::E_DOCK_ORIENTATION_RIGHT); + m_wm->DockWith(w2, w1, ImGuiWM::E_DOCK_ORIENTATION_BOTTOM); + m_wm->DockWith(w3, w0, ImGuiWM::E_DOCK_ORIENTATION_BOTTOM); + } +#endif // 0 } void destroy() { + m_wm->Exit(); + BX_DELETE(m_allocator, m_wm); ImGui::Shutdown(); bgfx::destroyUniform(s_tex); @@ -217,7 +525,9 @@ struct OcornutImguiContext void beginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, int _width, int _height, char _inputChar, uint8_t _viewId) { - m_viewId = _viewId; + m_viewId = _viewId; + m_defaultViewId = _viewId; + ImGuiIO& io = ImGui::GetIO(); if (_inputChar < 0x7f) { @@ -261,15 +571,11 @@ struct OcornutImguiContext bool opened = true; ShowExampleAppCustomNodeGraph(&opened); #endif // 0 - -#if defined(SCI_NAMESPACE) && 0 - bool opened = true; - ImGuiScintilla("Scintilla Editor", &opened, ImVec2(640.0f, 480.0f) ); -#endif // 0 } void endFrame() { + m_wm->Run(); ImGui::Render(); } @@ -278,13 +584,84 @@ struct OcornutImguiContext bgfx::ProgramHandle m_program; bgfx::TextureHandle m_texture; bgfx::UniformHandle s_tex; + WindowManager* m_wm; int64_t m_last; int32_t m_lastScroll; uint8_t m_viewId; + uint8_t m_defaultViewId; + +#if USE_ENTRY + struct Window + { + Window() + { + m_fbh.idx = bgfx::invalidHandle; + } + + entry::WindowState m_state; + PlatformWindow* m_pw; + bgfx::FrameBufferHandle m_fbh; + uint8_t m_viewId; + }; + + Window m_window[16]; +#endif // USE_ENTRY }; static OcornutImguiContext s_ctx; +#if USE_ENTRY + +void viewCallback(const ImDrawList* /*_parentList*/, const ImDrawCmd* _cmd) +{ + union { void* ptr; entry::WindowHandle handle; } cast = { _cmd->UserCallbackData }; + + if (0 != cast.handle.idx) + { + s_ctx.m_viewId = s_ctx.m_window[cast.handle.idx].m_viewId; + } + else + { + s_ctx.m_viewId = s_ctx.m_defaultViewId; + } +} + +void pwToWindow(entry::WindowHandle _handle, PlatformWindow* _pw) +{ + s_ctx.m_window[_handle.idx].m_pw = _pw; +} + +void imguiUpdateWindow(const entry::WindowState& _state) +{ + OcornutImguiContext::Window& window = s_ctx.m_window[_state.m_handle.idx]; + + if (window.m_state.m_nwh != _state.m_nwh + || (window.m_state.m_width != _state.m_width + || window.m_state.m_height != _state.m_height) ) + { + // When window changes size or native window handle changed + // frame buffer must be recreated. + if (bgfx::isValid(window.m_fbh) ) + { + bgfx::destroyFrameBuffer(window.m_fbh); + window.m_fbh.idx = bgfx::invalidHandle; + } + + if (NULL != _state.m_nwh) + { + window.m_fbh = bgfx::createFrameBuffer(_state.m_nwh, _state.m_width, _state.m_height); + window.m_viewId = 200 + _state.m_handle.idx; + } + else + { + window.m_viewId = s_ctx.m_defaultViewId; + } + } + + memcpy(&window.m_state, &_state, sizeof(entry::WindowState) ); +} +#endif // USE_ENTRY + void* OcornutImguiContext::memAlloc(size_t _size) { return BX_ALLOC(s_ctx.m_allocator, _size); diff --git a/3rdparty/bgfx/examples/common/imgui/scintilla.cpp b/3rdparty/bgfx/examples/common/imgui/scintilla.cpp index d88a75efa2d..f9f0d06ea22 100644 --- a/3rdparty/bgfx/examples/common/imgui/scintilla.cpp +++ b/3rdparty/bgfx/examples/common/imgui/scintilla.cpp @@ -1105,7 +1105,7 @@ ScintillaEditor* ImGuiScintilla(const char* _name, bool* _opened, const ImVec2& { ScintillaEditor* sci = NULL; - if (ImGui::Begin(_name, _opened, _size) ) +// if (ImGui::Begin(_name, _opened, _size) ) { ImGuiStorage* storage = ImGui::GetStateStorage(); @@ -1121,7 +1121,7 @@ ScintillaEditor* ImGuiScintilla(const char* _name, bool* _opened, const ImVec2& sci->draw(); } - ImGui::End(); +// ImGui::End(); return sci; } |