diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2019-11-25 02:44:26 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2019-11-25 02:44:26 +0000 |
| commit | c7319683cf2ebbe52704f3ad59d79518da7c49f3 (patch) | |
| tree | 90d61525b59845e375660df212d7cd3dbb24ce5d | |
| parent | clang-formatted AssetLoader (diff) | |
| download | DiligentTools-c7319683cf2ebbe52704f3ad59d79518da7c49f3.tar.gz DiligentTools-c7319683cf2ebbe52704f3ad59d79518da7c49f3.zip | |
clang-formatted ImGuiImpl
| -rw-r--r-- | Imgui/interface/ImGuiImplAndroid.h | 20 | ||||
| -rw-r--r-- | Imgui/interface/ImGuiImplDiligent.h | 14 | ||||
| -rw-r--r-- | Imgui/interface/ImGuiImplIOS.h | 28 | ||||
| -rw-r--r-- | Imgui/interface/ImGuiImplLinuxX11.h | 22 | ||||
| -rw-r--r-- | Imgui/interface/ImGuiImplLinuxXCB.h | 9 | ||||
| -rw-r--r-- | Imgui/interface/ImGuiImplMacOS.h | 2 | ||||
| -rw-r--r-- | Imgui/interface/ImGuiImplUWP.h | 28 | ||||
| -rw-r--r-- | Imgui/interface/ImGuiImplWin32.h | 18 | ||||
| -rw-r--r-- | Imgui/interface/ImGuiUtils.h | 20 | ||||
| -rw-r--r-- | Imgui/src/ImGuiImplAndroid.cpp | 41 | ||||
| -rw-r--r-- | Imgui/src/ImGuiImplDiligent.cpp | 158 | ||||
| -rw-r--r-- | Imgui/src/ImGuiImplLinuxX11.cpp | 120 | ||||
| -rw-r--r-- | Imgui/src/ImGuiImplLinuxXCB.cpp | 145 | ||||
| -rw-r--r-- | Imgui/src/ImGuiImplUWP.cpp | 76 | ||||
| -rw-r--r-- | Imgui/src/ImGuiImplWin32.cpp | 30 |
15 files changed, 382 insertions, 349 deletions
diff --git a/Imgui/interface/ImGuiImplAndroid.h b/Imgui/interface/ImGuiImplAndroid.h index 7639f28..80d878e 100644 --- a/Imgui/interface/ImGuiImplAndroid.h +++ b/Imgui/interface/ImGuiImplAndroid.h @@ -34,21 +34,23 @@ namespace Diligent class ImGuiImplAndroid final : public ImGuiImplDiligent { public: - ImGuiImplAndroid(IRenderDevice* pDevice, - TEXTURE_FORMAT BackBufferFmt, - TEXTURE_FORMAT DepthBufferFmt, - Uint32 DisplayWidht, - Uint32 DisplayHeight, - Uint32 InitialVertexBufferSize = ImGuiImplDiligent::DefaultInitialVBSize, - Uint32 InitialIndexBufferSize = ImGuiImplDiligent::DefaultInitialIBSize); + ImGuiImplAndroid(IRenderDevice* pDevice, + TEXTURE_FORMAT BackBufferFmt, + TEXTURE_FORMAT DepthBufferFmt, + Uint32 DisplayWidht, + Uint32 DisplayHeight, + Uint32 InitialVertexBufferSize = ImGuiImplDiligent::DefaultInitialVBSize, + Uint32 InitialIndexBufferSize = ImGuiImplDiligent::DefaultInitialIBSize); ~ImGuiImplAndroid(); + // clang-format off ImGuiImplAndroid (const ImGuiImplAndroid&) = delete; ImGuiImplAndroid ( ImGuiImplAndroid&&) = delete; ImGuiImplAndroid& operator = (const ImGuiImplAndroid&) = delete; ImGuiImplAndroid& operator = ( ImGuiImplAndroid&&) = delete; + // clang-format on - virtual void NewFrame()override final; + virtual void NewFrame() override final; bool BeginDrag(float x, float y); bool DragMove(float x, float y); @@ -58,4 +60,4 @@ private: std::chrono::time_point<std::chrono::high_resolution_clock> m_LastTimestamp = {}; }; -} +} // namespace Diligent diff --git a/Imgui/interface/ImGuiImplDiligent.h b/Imgui/interface/ImGuiImplDiligent.h index dadc6eb..8370241 100644 --- a/Imgui/interface/ImGuiImplDiligent.h +++ b/Imgui/interface/ImGuiImplDiligent.h @@ -41,17 +41,19 @@ public: static constexpr Uint32 DefaultInitialVBSize = 1024; static constexpr Uint32 DefaultInitialIBSize = 2048; - ImGuiImplDiligent(IRenderDevice* pDevice, - TEXTURE_FORMAT BackBufferFmt, - TEXTURE_FORMAT DepthBufferFmt, - Uint32 InitialVertexBufferSize = DefaultInitialVBSize, - Uint32 InitialIndexBufferSize = DefaultInitialIBSize); + ImGuiImplDiligent(IRenderDevice* pDevice, + TEXTURE_FORMAT BackBufferFmt, + TEXTURE_FORMAT DepthBufferFmt, + Uint32 InitialVertexBufferSize = DefaultInitialVBSize, + Uint32 InitialIndexBufferSize = DefaultInitialIBSize); virtual ~ImGuiImplDiligent(); + // clang-format off ImGuiImplDiligent (const ImGuiImplDiligent&) = delete; ImGuiImplDiligent ( ImGuiImplDiligent&&) = delete; ImGuiImplDiligent& operator = (const ImGuiImplDiligent&) = delete; ImGuiImplDiligent& operator = ( ImGuiImplDiligent&&) = delete; + // clang-format on virtual void NewFrame(); virtual void Render(IDeviceContext* pCtx); @@ -64,4 +66,4 @@ private: std::unique_ptr<ImGuiImplDiligent_Internal> m_pImpl; }; -} +} // namespace Diligent diff --git a/Imgui/interface/ImGuiImplIOS.h b/Imgui/interface/ImGuiImplIOS.h index a8192d4..569a01a 100644 --- a/Imgui/interface/ImGuiImplIOS.h +++ b/Imgui/interface/ImGuiImplIOS.h @@ -32,28 +32,30 @@ namespace Diligent class ImGuiImplIOS final : public ImGuiImplDiligent { public: - ImGuiImplIOS(IRenderDevice* pDevice, - TEXTURE_FORMAT BackBufferFmt, - TEXTURE_FORMAT DepthBufferFmt, - Uint32 DisplayWidth, - Uint32 DisplayHeight, - Uint32 InitialVertexBufferSize = ImGuiImplDiligent::DefaultInitialVBSize, - Uint32 InitialIndexBufferSize = ImGuiImplDiligent::DefaultInitialIBSize); + ImGuiImplIOS(IRenderDevice* pDevice, + TEXTURE_FORMAT BackBufferFmt, + TEXTURE_FORMAT DepthBufferFmt, + Uint32 DisplayWidth, + Uint32 DisplayHeight, + Uint32 InitialVertexBufferSize = ImGuiImplDiligent::DefaultInitialVBSize, + Uint32 InitialIndexBufferSize = ImGuiImplDiligent::DefaultInitialIBSize); ~ImGuiImplIOS(); + // clang-format off ImGuiImplIOS (const ImGuiImplIOS&) = delete; ImGuiImplIOS ( ImGuiImplIOS&&) = delete; ImGuiImplIOS& operator = (const ImGuiImplIOS&) = delete; ImGuiImplIOS& operator = ( ImGuiImplIOS&&) = delete; + // clang-format on - virtual void NewFrame()override final; - virtual void Render(IDeviceContext* pCtx)override final; - void SetDisplaySize(Uint32 DisplayWidth, Uint32 DisplayHeight); - bool OnTouchEvent(float x, float y, bool IsActive); + virtual void NewFrame() override final; + virtual void Render(IDeviceContext* pCtx) override final; + void SetDisplaySize(Uint32 DisplayWidth, Uint32 DisplayHeight); + bool OnTouchEvent(float x, float y, bool IsActive); private: std::mutex m_Mtx; - double m_Time = 0.0; + double m_Time = 0.0; }; -} +} // namespace Diligent diff --git a/Imgui/interface/ImGuiImplLinuxX11.h b/Imgui/interface/ImGuiImplLinuxX11.h index 0398628..e4fbe09 100644 --- a/Imgui/interface/ImGuiImplLinuxX11.h +++ b/Imgui/interface/ImGuiImplLinuxX11.h @@ -34,25 +34,27 @@ namespace Diligent class ImGuiImplLinuxX11 final : public ImGuiImplDiligent { public: - ImGuiImplLinuxX11(IRenderDevice* pDevice, - TEXTURE_FORMAT BackBufferFmt, - TEXTURE_FORMAT DepthBufferFmt, - Uint32 DisplayWidht, - Uint32 DisplayHeight, - Uint32 InitialVertexBufferSize = ImGuiImplDiligent::DefaultInitialVBSize, - Uint32 InitialIndexBufferSize = ImGuiImplDiligent::DefaultInitialIBSize); + ImGuiImplLinuxX11(IRenderDevice* pDevice, + TEXTURE_FORMAT BackBufferFmt, + TEXTURE_FORMAT DepthBufferFmt, + Uint32 DisplayWidht, + Uint32 DisplayHeight, + Uint32 InitialVertexBufferSize = ImGuiImplDiligent::DefaultInitialVBSize, + Uint32 InitialIndexBufferSize = ImGuiImplDiligent::DefaultInitialIBSize); ~ImGuiImplLinuxX11(); + // clang-format off ImGuiImplLinuxX11 (const ImGuiImplLinuxX11&) = delete; ImGuiImplLinuxX11 ( ImGuiImplLinuxX11&&) = delete; ImGuiImplLinuxX11& operator = (const ImGuiImplLinuxX11&) = delete; ImGuiImplLinuxX11& operator = ( ImGuiImplLinuxX11&&) = delete; + // clang-format on - bool HandleXEvent(XEvent* event); - virtual void NewFrame()override final; + bool HandleXEvent(XEvent* event); + virtual void NewFrame() override final; private: std::chrono::time_point<std::chrono::high_resolution_clock> m_LastTimestamp = {}; }; -} +} // namespace Diligent diff --git a/Imgui/interface/ImGuiImplLinuxXCB.h b/Imgui/interface/ImGuiImplLinuxXCB.h index 62658b4..71571e6 100644 --- a/Imgui/interface/ImGuiImplLinuxXCB.h +++ b/Imgui/interface/ImGuiImplLinuxXCB.h @@ -46,19 +46,22 @@ public: Uint32 InitialIndexBufferSize = ImGuiImplDiligent::DefaultInitialIBSize); ~ImGuiImplLinuxXCB(); + // clang-format off ImGuiImplLinuxXCB (const ImGuiImplLinuxXCB&) = delete; ImGuiImplLinuxXCB ( ImGuiImplLinuxXCB&&) = delete; ImGuiImplLinuxXCB& operator = (const ImGuiImplLinuxXCB&) = delete; ImGuiImplLinuxXCB& operator = ( ImGuiImplLinuxXCB&&) = delete; + // clang-format on - bool HandleXCBEvent(xcb_generic_event_t* event); - virtual void NewFrame()override final; + bool HandleXCBEvent(xcb_generic_event_t* event); + virtual void NewFrame() override final; private: void HandleKeyEvent(xcb_key_release_event_t* event); _XCBKeySymbols* m_syms = nullptr; + std::chrono::time_point<std::chrono::high_resolution_clock> m_LastTimestamp = {}; }; -} +} // namespace Diligent diff --git a/Imgui/interface/ImGuiImplMacOS.h b/Imgui/interface/ImGuiImplMacOS.h index 504072f..28b6a32 100644 --- a/Imgui/interface/ImGuiImplMacOS.h +++ b/Imgui/interface/ImGuiImplMacOS.h @@ -44,10 +44,12 @@ public: Uint32 InitialIndexBufferSize = ImGuiImplDiligent::DefaultInitialIBSize); ~ImGuiImplMacOS(); + // clang-format off ImGuiImplMacOS (const ImGuiImplMacOS&) = delete; ImGuiImplMacOS ( ImGuiImplMacOS&&) = delete; ImGuiImplMacOS& operator = (const ImGuiImplMacOS&) = delete; ImGuiImplMacOS& operator = ( ImGuiImplMacOS&&) = delete; + // clang-format on virtual void NewFrame()override final; virtual void Render(IDeviceContext* _Nonnull pCtx)override final; diff --git a/Imgui/interface/ImGuiImplUWP.h b/Imgui/interface/ImGuiImplUWP.h index 97fbacf..788bae2 100644 --- a/Imgui/interface/ImGuiImplUWP.h +++ b/Imgui/interface/ImGuiImplUWP.h @@ -32,21 +32,23 @@ namespace Diligent class ImGuiImplUWP final : public ImGuiImplDiligent { public: - ImGuiImplUWP(IRenderDevice* pDevice, - TEXTURE_FORMAT BackBufferFmt, - TEXTURE_FORMAT DepthBufferFmt, - Uint32 DisplayWidth, - Uint32 DisplayHeight, - Uint32 InitialVertexBufferSize = ImGuiImplDiligent::DefaultInitialVBSize, - Uint32 InitialIndexBufferSize = ImGuiImplDiligent::DefaultInitialIBSize); + ImGuiImplUWP(IRenderDevice* pDevice, + TEXTURE_FORMAT BackBufferFmt, + TEXTURE_FORMAT DepthBufferFmt, + Uint32 DisplayWidth, + Uint32 DisplayHeight, + Uint32 InitialVertexBufferSize = ImGuiImplDiligent::DefaultInitialVBSize, + Uint32 InitialIndexBufferSize = ImGuiImplDiligent::DefaultInitialIBSize); ~ImGuiImplUWP(); + // clang-format off ImGuiImplUWP (const ImGuiImplUWP&) = delete; ImGuiImplUWP ( ImGuiImplUWP&&) = delete; ImGuiImplUWP& operator = (const ImGuiImplUWP&) = delete; ImGuiImplUWP& operator = ( ImGuiImplUWP&&) = delete; + // clang-format on - virtual void NewFrame()override final; + virtual void NewFrame() override final; void SetDisplaySize(Uint32 DisplayWidth, Uint32 DisplayHeight) { @@ -55,10 +57,10 @@ public: } private: - INT64 m_Time = 0; - INT64 m_TicksPerSecond = 0; - Uint32 m_DisplayWidth = 0; - Uint32 m_DisplayHeight = 0; + INT64 m_Time = 0; + INT64 m_TicksPerSecond = 0; + Uint32 m_DisplayWidth = 0; + Uint32 m_DisplayHeight = 0; }; -} +} // namespace Diligent diff --git a/Imgui/interface/ImGuiImplWin32.h b/Imgui/interface/ImGuiImplWin32.h index f926112..a10ffa9 100644 --- a/Imgui/interface/ImGuiImplWin32.h +++ b/Imgui/interface/ImGuiImplWin32.h @@ -32,22 +32,24 @@ namespace Diligent class ImGuiImplWin32 final : public ImGuiImplDiligent { public: - ImGuiImplWin32(HWND hWnd, - IRenderDevice* pDevice, - TEXTURE_FORMAT BackBufferFmt, - TEXTURE_FORMAT DepthBufferFmt, - Uint32 InitialVertexBufferSize = ImGuiImplDiligent::DefaultInitialVBSize, - Uint32 InitialIndexBufferSize = ImGuiImplDiligent::DefaultInitialIBSize); + ImGuiImplWin32(HWND hWnd, + IRenderDevice* pDevice, + TEXTURE_FORMAT BackBufferFmt, + TEXTURE_FORMAT DepthBufferFmt, + Uint32 InitialVertexBufferSize = ImGuiImplDiligent::DefaultInitialVBSize, + Uint32 InitialIndexBufferSize = ImGuiImplDiligent::DefaultInitialIBSize); ~ImGuiImplWin32(); LRESULT Win32_ProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam); + // clang-format off ImGuiImplWin32 (const ImGuiImplWin32&) = delete; ImGuiImplWin32 ( ImGuiImplWin32&&) = delete; ImGuiImplWin32& operator = (const ImGuiImplWin32&) = delete; ImGuiImplWin32& operator = ( ImGuiImplWin32&&) = delete; + // clang-format on - virtual void NewFrame()override final; + virtual void NewFrame() override final; }; -} +} // namespace Diligent diff --git a/Imgui/interface/ImGuiUtils.h b/Imgui/interface/ImGuiUtils.h index 7bbe806..26992f8 100644 --- a/Imgui/interface/ImGuiUtils.h +++ b/Imgui/interface/ImGuiUtils.h @@ -36,7 +36,7 @@ class ImGuiScopedDisabler { public: explicit ImGuiScopedDisabler(bool Disable, float AlphaScale = 0.25f) : - m_IsDisabled(Disable) + m_IsDisabled{Disable} { if (m_IsDisabled) { @@ -58,15 +58,16 @@ private: const bool m_IsDisabled; }; -} +} // namespace Diligent namespace ImGui { -template<typename T> +template <typename T> inline bool Checkbox(const char* label, T* v) { bool b = *v != 0; + auto pressed = Checkbox(label, &b); if (pressed) *v = b ? 1 : 0; @@ -89,29 +90,30 @@ inline void HelpMarker(const char* desc, bool IsSameLine = true, const char* mar } } -template<typename T, typename = typename std::enable_if<std::numeric_limits<T>::is_integer>::type> +template <typename T, typename = typename std::enable_if<std::numeric_limits<T>::is_integer>::type> bool SliderIntT(const char* label, T* v, int v_min, int v_max, const char* format = "%d") { int i = static_cast<int>(*v); + auto value_changed = ImGui::SliderInt(label, &i, v_min, v_max, format); if (value_changed) *v = static_cast<T>(i); return value_changed; } -template<typename T> +template <typename T> bool Combo(const char* label, T* current_item, const std::pair<T, const char*> items[], int items_count, int popup_max_height_in_items = -1) { int item_idx = 0; - while(item_idx < items_count && items[item_idx].first != *current_item) + while (item_idx < items_count && items[item_idx].first != *current_item) ++item_idx; - if(item_idx >= items_count) + if (item_idx >= items_count) { UNEXPECTED("Current item was not found in the items list"); return false; } std::vector<const char*> names(items_count); - for(int i=0; i < items_count; ++i) + for (int i = 0; i < items_count; ++i) names[i] = items[i].second; auto value_changed = Combo(label, &item_idx, names.data(), items_count, popup_max_height_in_items); if (value_changed) @@ -120,4 +122,4 @@ bool Combo(const char* label, T* current_item, const std::pair<T, const char*> i return value_changed; } -} +} // namespace ImGui diff --git a/Imgui/src/ImGuiImplAndroid.cpp b/Imgui/src/ImGuiImplAndroid.cpp index 55101f5..e8f69de 100644 --- a/Imgui/src/ImGuiImplAndroid.cpp +++ b/Imgui/src/ImGuiImplAndroid.cpp @@ -28,19 +28,18 @@ namespace Diligent { -ImGuiImplAndroid::ImGuiImplAndroid(IRenderDevice* pDevice, - TEXTURE_FORMAT BackBufferFmt, - TEXTURE_FORMAT DepthBufferFmt, - Uint32 DisplayWidth, - Uint32 DisplayHeight, - Uint32 InitialVertexBufferSize, - Uint32 InitialIndexBufferSize) : - ImGuiImplDiligent(pDevice, BackBufferFmt, DepthBufferFmt, InitialVertexBufferSize, InitialIndexBufferSize) +ImGuiImplAndroid::ImGuiImplAndroid(IRenderDevice* pDevice, + TEXTURE_FORMAT BackBufferFmt, + TEXTURE_FORMAT DepthBufferFmt, + Uint32 DisplayWidth, + Uint32 DisplayHeight, + Uint32 InitialVertexBufferSize, + Uint32 InitialIndexBufferSize) : + ImGuiImplDiligent{pDevice, BackBufferFmt, DepthBufferFmt, InitialVertexBufferSize, InitialIndexBufferSize} { - - auto& io = ImGui::GetIO(); - io.DisplaySize = ImVec2(DisplayWidth, DisplayHeight); - io.FontGlobalScale = 2; + auto& io = ImGui::GetIO(); + io.DisplaySize = ImVec2(DisplayWidth, DisplayHeight); + io.FontGlobalScale = 2; io.BackendPlatformName = "Diligent-ImGuiImplAndroid"; m_LastTimestamp = std::chrono::high_resolution_clock::now(); @@ -52,35 +51,35 @@ ImGuiImplAndroid::~ImGuiImplAndroid() void ImGuiImplAndroid::NewFrame() { - auto now = std::chrono::high_resolution_clock::now(); - auto elapsed_ns = now - m_LastTimestamp; + auto now = std::chrono::high_resolution_clock::now(); + auto elapsed_ns = now - m_LastTimestamp; m_LastTimestamp = now; - auto& io = ImGui::GetIO(); - io.DeltaTime = static_cast<float>(elapsed_ns.count() / 1e+9); + auto& io = ImGui::GetIO(); + io.DeltaTime = static_cast<float>(elapsed_ns.count() / 1e+9); ImGuiImplDiligent::NewFrame(); } bool ImGuiImplAndroid::BeginDrag(float x, float y) { - auto& io = ImGui::GetIO(); - io.MousePos = ImVec2(x, y); + auto& io = ImGui::GetIO(); + io.MousePos = ImVec2(x, y); io.MouseDown[0] = true; return io.WantCaptureMouse; } bool ImGuiImplAndroid::DragMove(float x, float y) { - auto& io = ImGui::GetIO(); + auto& io = ImGui::GetIO(); io.MousePos = ImVec2(x, y); return io.WantCaptureMouse; } bool ImGuiImplAndroid::EndDrag() { - auto& io = ImGui::GetIO(); + auto& io = ImGui::GetIO(); io.MouseDown[0] = false; return io.WantCaptureMouse; } -} +} // namespace Diligent diff --git a/Imgui/src/ImGuiImplDiligent.cpp b/Imgui/src/ImGuiImplDiligent.cpp index 4df6974..03e3e76 100644 --- a/Imgui/src/ImGuiImplDiligent.cpp +++ b/Imgui/src/ImGuiImplDiligent.cpp @@ -36,24 +36,26 @@ namespace Diligent class ImGuiImplDiligent_Internal { public: - ImGuiImplDiligent_Internal(IRenderDevice* pDevice, - TEXTURE_FORMAT BackBufferFmt, - TEXTURE_FORMAT DepthBufferFmt, - Uint32 InitialVertexBufferSize, - Uint32 InitialIndexBufferSize) : - m_pDevice (pDevice), - m_BackBufferFmt (BackBufferFmt), - m_DepthBufferFmt (DepthBufferFmt), - m_VertexBufferSize(InitialVertexBufferSize), - m_IndexBufferSize (InitialIndexBufferSize) + ImGuiImplDiligent_Internal(IRenderDevice* pDevice, + TEXTURE_FORMAT BackBufferFmt, + TEXTURE_FORMAT DepthBufferFmt, + Uint32 InitialVertexBufferSize, + Uint32 InitialIndexBufferSize) : + // clang-format off + m_pDevice {pDevice}, + m_BackBufferFmt {BackBufferFmt}, + m_DepthBufferFmt {DepthBufferFmt}, + m_VertexBufferSize{InitialVertexBufferSize}, + m_IndexBufferSize {InitialIndexBufferSize} + // clang-format on { // Setup back-end capabilities flags IMGUI_CHECKVERSION(); ImGui::CreateContext(); - ImGuiIO& io = ImGui::GetIO(); + ImGuiIO& io = ImGui::GetIO(); io.BackendRendererName = "ImGuiImplDiligent"; - io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes. - io.IniFilename = nullptr; + io.BackendFlags |= ImGuiBackendFlags_RendererHasVtxOffset; // We can honor the ImDrawCmd::VtxOffset field, allowing for large meshes. + io.IniFilename = nullptr; CreateDeviceObjects(); } @@ -73,17 +75,17 @@ public: private: void CreateFontsTexture(); - RefCntAutoPtr<IRenderDevice> m_pDevice; - RefCntAutoPtr<IBuffer> m_pVB; - RefCntAutoPtr<IBuffer> m_pIB; - RefCntAutoPtr<IBuffer> m_pVertexConstantBuffer; - RefCntAutoPtr<IPipelineState> m_pPSO; - RefCntAutoPtr<ITextureView> m_pFontSRV; - RefCntAutoPtr<IShaderResourceBinding> m_pSRB; - const TEXTURE_FORMAT m_BackBufferFmt; - const TEXTURE_FORMAT m_DepthBufferFmt; - Uint32 m_VertexBufferSize = 0; - Uint32 m_IndexBufferSize = 0; + RefCntAutoPtr<IRenderDevice> m_pDevice; + RefCntAutoPtr<IBuffer> m_pVB; + RefCntAutoPtr<IBuffer> m_pIB; + RefCntAutoPtr<IBuffer> m_pVertexConstantBuffer; + RefCntAutoPtr<IPipelineState> m_pPSO; + RefCntAutoPtr<ITextureView> m_pFontSRV; + RefCntAutoPtr<IShaderResourceBinding> m_pSRB; + const TEXTURE_FORMAT m_BackBufferFmt; + const TEXTURE_FORMAT m_DepthBufferFmt; + Uint32 m_VertexBufferSize = 0; + Uint32 m_IndexBufferSize = 0; }; void ImGuiImplDiligent_Internal::NewFrame() @@ -173,7 +175,7 @@ void ImGuiImplDiligent_Internal::CreateDeviceObjects() } PipelineStateDesc PSODesc; - PSODesc.Name = "ImGUI PSO"; + PSODesc.Name = "ImGUI PSO"; auto& GraphicsPipeline = PSODesc.GraphicsPipeline; GraphicsPipeline.NumRenderTargets = 1; @@ -188,7 +190,7 @@ void ImGuiImplDiligent_Internal::CreateDeviceObjects() GraphicsPipeline.RasterizerDesc.ScissorEnable = True; GraphicsPipeline.DepthStencilDesc.DepthEnable = False; - auto& RT0 = GraphicsPipeline.BlendDesc.RenderTargets[0]; + auto& RT0 = GraphicsPipeline.BlendDesc.RenderTargets[0]; RT0.BlendEnable = True; RT0.SrcBlend = BLEND_FACTOR_SRC_ALPHA; RT0.DestBlend = BLEND_FACTOR_INV_SRC_ALPHA; @@ -198,19 +200,19 @@ void ImGuiImplDiligent_Internal::CreateDeviceObjects() RT0.BlendOpAlpha = BLEND_OPERATION_ADD; RT0.RenderTargetWriteMask = COLOR_MASK_ALL; - LayoutElement VSInputs[] - { - { 0, 0, 2, VT_FLOAT32}, // pos - { 1, 0, 2, VT_FLOAT32}, // uv - { 2, 0, 4, VT_UINT8, True} // col - }; + LayoutElement VSInputs[] // + { + {0, 0, 2, VT_FLOAT32}, // pos + {1, 0, 2, VT_FLOAT32}, // uv + {2, 0, 4, VT_UINT8, True} // col + }; GraphicsPipeline.InputLayout.NumElements = _countof(VSInputs); GraphicsPipeline.InputLayout.LayoutElements = VSInputs; ShaderResourceVariableDesc Variables[] = - { - {SHADER_TYPE_PIXEL, "Texture", SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE} - }; + { + {SHADER_TYPE_PIXEL, "Texture", SHADER_RESOURCE_VARIABLE_TYPE_MUTABLE} // + }; PSODesc.ResourceLayout.Variables = Variables; PSODesc.ResourceLayout.NumVariables = _countof(Variables); @@ -218,10 +220,10 @@ void ImGuiImplDiligent_Internal::CreateDeviceObjects() SamLinearWrap.AddressU = TEXTURE_ADDRESS_WRAP; SamLinearWrap.AddressV = TEXTURE_ADDRESS_WRAP; SamLinearWrap.AddressW = TEXTURE_ADDRESS_WRAP; - StaticSamplerDesc StaticSamplers[] = - { - {SHADER_TYPE_PIXEL, "Texture", SamLinearWrap} - }; + StaticSamplerDesc StaticSamplers[] = + { + {SHADER_TYPE_PIXEL, "Texture", SamLinearWrap} // + }; PSODesc.ResourceLayout.StaticSamplers = StaticSamplers; PSODesc.ResourceLayout.NumStaticSamplers = _countof(StaticSamplers); @@ -243,9 +245,9 @@ void ImGuiImplDiligent_Internal::CreateDeviceObjects() void ImGuiImplDiligent_Internal::CreateFontsTexture() { // Build texture atlas - ImGuiIO& io = ImGui::GetIO(); + ImGuiIO& io = ImGui::GetIO(); unsigned char* pixels = nullptr; - int width = 0, height = 0; + int width = 0, height = 0; io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height); TextureDesc FontTexDesc; @@ -257,8 +259,8 @@ void ImGuiImplDiligent_Internal::CreateFontsTexture() FontTexDesc.BindFlags = BIND_SHADER_RESOURCE; FontTexDesc.Usage = USAGE_STATIC; - TextureSubResData Mip0Data[] = { {pixels, FontTexDesc.Width * 4} }; - TextureData InitData(Mip0Data, _countof(Mip0Data)); + TextureSubResData Mip0Data[] = {{pixels, FontTexDesc.Width * 4}}; + TextureData InitData(Mip0Data, _countof(Mip0Data)); RefCntAutoPtr<ITexture> pFontTex; m_pDevice->CreateTexture(FontTexDesc, &InitData, &pFontTex); @@ -278,12 +280,12 @@ void ImGuiImplDiligent_Internal::RenderDrawData(IDeviceContext* pCtx, ImDrawData // Avoid rendering when minimized if (pDrawData->DisplaySize.x <= 0.0f || pDrawData->DisplaySize.y <= 0.0f) return; - + // Create and grow vertex/index buffers if needed if (!m_pVB || static_cast<int>(m_VertexBufferSize) < pDrawData->TotalVtxCount) { m_pVB.Release(); - while(static_cast<int>(m_VertexBufferSize) < pDrawData->TotalVtxCount) + while (static_cast<int>(m_VertexBufferSize) < pDrawData->TotalVtxCount) m_VertexBufferSize *= 2; BufferDesc VBDesc; @@ -294,11 +296,11 @@ void ImGuiImplDiligent_Internal::RenderDrawData(IDeviceContext* pCtx, ImDrawData VBDesc.CPUAccessFlags = CPU_ACCESS_WRITE; m_pDevice->CreateBuffer(VBDesc, nullptr, &m_pVB); } - + if (!m_pIB || static_cast<int>(m_IndexBufferSize) < pDrawData->TotalIdxCount) { m_pIB.Release(); - while(static_cast<int>(m_IndexBufferSize) < pDrawData->TotalIdxCount) + while (static_cast<int>(m_IndexBufferSize) < pDrawData->TotalIdxCount) m_IndexBufferSize *= 2; BufferDesc IBDesc; @@ -312,9 +314,10 @@ void ImGuiImplDiligent_Internal::RenderDrawData(IDeviceContext* pCtx, ImDrawData { MapHelper<ImDrawVert> Verices(pCtx, m_pVB, MAP_WRITE, MAP_FLAG_DISCARD); - MapHelper<ImDrawIdx> Indices(pCtx, m_pIB, MAP_WRITE, MAP_FLAG_DISCARD); + MapHelper<ImDrawIdx> Indices(pCtx, m_pIB, MAP_WRITE, MAP_FLAG_DISCARD); + ImDrawVert* vtx_dst = Verices; - ImDrawIdx* idx_dst = Indices; + ImDrawIdx* idx_dst = Indices; for (int n = 0; n < pDrawData->CmdListsCount; n++) { const ImDrawList* cmd_list = pDrawData->CmdLists[n]; @@ -331,32 +334,35 @@ void ImGuiImplDiligent_Internal::RenderDrawData(IDeviceContext* pCtx, ImDrawData // DisplayPos is (0,0) for single viewport apps. { MapHelper<float4x4> CBData(pCtx, m_pVertexConstantBuffer, MAP_WRITE, MAP_FLAG_DISCARD); + float L = pDrawData->DisplayPos.x; float R = pDrawData->DisplayPos.x + pDrawData->DisplaySize.x; float T = pDrawData->DisplayPos.y; float B = pDrawData->DisplayPos.y + pDrawData->DisplaySize.y; + // clang-format off *CBData = float4x4 { - 2.0f/(R-L), 0.0f, 0.0f, 0.0f, - 0.0f, 2.0f/(T-B), 0.0f, 0.0f, - 0.0f, 0.0f, 0.5f, 0.0f, - (R+L)/(L-R), (T+B)/(B-T), 0.5f, 1.0f + 2.0f / (R - L), 0.0f, 0.0f, 0.0f, + 0.0f, 2.0f / (T - B), 0.0f, 0.0f, + 0.0f, 0.0f, 0.5f, 0.0f, + (R + L) / (L - R), (T + B) / (B - T), 0.5f, 1.0f }; + // clang-format on } - auto DisplayWidth = static_cast<Uint32>(pDrawData->DisplaySize.x); - auto DisplayHeight = static_cast<Uint32>(pDrawData->DisplaySize.y); - auto SetupRenderState = [&]() + auto DisplayWidth = static_cast<Uint32>(pDrawData->DisplaySize.x); + auto DisplayHeight = static_cast<Uint32>(pDrawData->DisplaySize.y); + auto SetupRenderState = [&]() // { // Setup shader and vertex buffers - Uint32 Offsets[] = {0}; - IBuffer* pVBs[] = {m_pVB}; + Uint32 Offsets[] = {0}; + IBuffer* pVBs[] = {m_pVB}; pCtx->SetVertexBuffers(0, 1, pVBs, Offsets, RESOURCE_STATE_TRANSITION_MODE_TRANSITION, SET_VERTEX_BUFFERS_FLAG_RESET); pCtx->SetIndexBuffer(m_pIB, 0, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); pCtx->SetPipelineState(m_pPSO); pCtx->CommitShaderResources(m_pSRB, RESOURCE_STATE_TRANSITION_MODE_TRANSITION); - const float blend_factor[4] = { 0.f, 0.f, 0.f, 0.f }; + const float blend_factor[4] = {0.f, 0.f, 0.f, 0.f}; pCtx->SetBlendFactors(blend_factor); Viewport vp; @@ -367,13 +373,14 @@ void ImGuiImplDiligent_Internal::RenderDrawData(IDeviceContext* pCtx, ImDrawData vp.TopLeftX = vp.TopLeftY = 0; pCtx->SetViewports(1, &vp, DisplayWidth, DisplayHeight); }; - + SetupRenderState(); // Render command lists // (Because we merged all buffers into a single one, we maintain our own offset into them) int global_idx_offset = 0; int global_vtx_offset = 0; + ImVec2 clip_off = pDrawData->DisplayPos; for (int n = 0; n < pDrawData->CmdListsCount; n++) { @@ -394,17 +401,18 @@ void ImGuiImplDiligent_Internal::RenderDrawData(IDeviceContext* pCtx, ImDrawData { // Apply scissor/clipping rectangle const Rect r = - { - static_cast<Int32>(pcmd->ClipRect.x - clip_off.x), - static_cast<Int32>(pcmd->ClipRect.y - clip_off.y), - static_cast<Int32>(pcmd->ClipRect.z - clip_off.x), - static_cast<Int32>(pcmd->ClipRect.w - clip_off.y) - }; + { + static_cast<Int32>(pcmd->ClipRect.x - clip_off.x), + static_cast<Int32>(pcmd->ClipRect.y - clip_off.y), + static_cast<Int32>(pcmd->ClipRect.z - clip_off.x), + static_cast<Int32>(pcmd->ClipRect.w - clip_off.y) // + }; pCtx->SetScissorRects(1, &r, DisplayWidth, DisplayHeight); // Bind texture, Draw auto* texture_srv = reinterpret_cast<ITextureView*>(pcmd->TextureId); - VERIFY_EXPR(texture_srv == m_pFontSRV); (void)texture_srv; + VERIFY_EXPR(texture_srv == m_pFontSRV); + (void)texture_srv; //ctx->PSSetShaderResources(0, 1, &texture_srv); DrawIndexedAttribs DrawAttrs(pcmd->ElemCount, sizeof(ImDrawIdx) == 2 ? VT_UINT16 : VT_UINT32, DRAW_FLAG_VERIFY_STATES); DrawAttrs.FirstIndexLocation = pcmd->IdxOffset + global_idx_offset; @@ -419,11 +427,11 @@ void ImGuiImplDiligent_Internal::RenderDrawData(IDeviceContext* pCtx, ImDrawData -ImGuiImplDiligent::ImGuiImplDiligent(IRenderDevice* pDevice, - TEXTURE_FORMAT BackBufferFmt, - TEXTURE_FORMAT DepthBufferFmt, - Uint32 InitialVertexBufferSize, - Uint32 InitialIndexBufferSize) : +ImGuiImplDiligent::ImGuiImplDiligent(IRenderDevice* pDevice, + TEXTURE_FORMAT BackBufferFmt, + TEXTURE_FORMAT DepthBufferFmt, + Uint32 InitialVertexBufferSize, + Uint32 InitialIndexBufferSize) : m_pImpl(new ImGuiImplDiligent_Internal(pDevice, BackBufferFmt, DepthBufferFmt, InitialVertexBufferSize, InitialIndexBufferSize)) { } @@ -444,7 +452,7 @@ void ImGuiImplDiligent::Render(IDeviceContext* pCtx) m_pImpl->RenderDrawData(pCtx, ImGui::GetDrawData()); } - // Use if you want to reset your rendering device without losing ImGui state. +// Use if you want to reset your rendering device without losing ImGui state. void ImGuiImplDiligent::InvalidateDeviceObjects() { m_pImpl->InvalidateDeviceObjects(); @@ -455,6 +463,4 @@ void ImGuiImplDiligent::CreateDeviceObjects() m_pImpl->CreateDeviceObjects(); } -} - - +} // namespace Diligent diff --git a/Imgui/src/ImGuiImplLinuxX11.cpp b/Imgui/src/ImGuiImplLinuxX11.cpp index 2497978..bf0b74f 100644 --- a/Imgui/src/ImGuiImplLinuxX11.cpp +++ b/Imgui/src/ImGuiImplLinuxX11.cpp @@ -26,15 +26,15 @@ #include <X11/Xutil.h> #ifdef Bool -# undef Bool +# undef Bool #endif #ifdef True -# undef True +# undef True #endif #ifdef False -# undef False +# undef False #endif @@ -45,44 +45,44 @@ namespace Diligent { -ImGuiImplLinuxX11::ImGuiImplLinuxX11(IRenderDevice* pDevice, - TEXTURE_FORMAT BackBufferFmt, - TEXTURE_FORMAT DepthBufferFmt, - Uint32 DisplayWidth, - Uint32 DisplayHeight, - Uint32 InitialVertexBufferSize, - Uint32 InitialIndexBufferSize) : - ImGuiImplDiligent(pDevice, BackBufferFmt, DepthBufferFmt, InitialVertexBufferSize, InitialIndexBufferSize) +ImGuiImplLinuxX11::ImGuiImplLinuxX11(IRenderDevice* pDevice, + TEXTURE_FORMAT BackBufferFmt, + TEXTURE_FORMAT DepthBufferFmt, + Uint32 DisplayWidth, + Uint32 DisplayHeight, + Uint32 InitialVertexBufferSize, + Uint32 InitialIndexBufferSize) : + ImGuiImplDiligent(pDevice, BackBufferFmt, DepthBufferFmt, InitialVertexBufferSize, InitialIndexBufferSize) { - auto& io = ImGui::GetIO(); + auto& io = ImGui::GetIO(); io.DisplaySize = ImVec2(DisplayWidth, DisplayHeight); - + io.BackendPlatformName = "Diligent-ImGuiImplLinuxX11"; - + // Keyboard mapping. ImGui will use those indices to peek into the io.KeysDown[] array that we will update during the application lifetime. - io.KeyMap[ImGuiKey_Tab] = 256; - io.KeyMap[ImGuiKey_LeftArrow] = 257; - io.KeyMap[ImGuiKey_RightArrow] = 258; - io.KeyMap[ImGuiKey_UpArrow] = 259; - io.KeyMap[ImGuiKey_DownArrow] = 260; - io.KeyMap[ImGuiKey_PageUp] = 261; - io.KeyMap[ImGuiKey_PageDown] = 262; - io.KeyMap[ImGuiKey_Home] = 263; - io.KeyMap[ImGuiKey_End] = 264; - io.KeyMap[ImGuiKey_Insert] = 265; - io.KeyMap[ImGuiKey_Delete] = 266; - io.KeyMap[ImGuiKey_Backspace] = 267; - io.KeyMap[ImGuiKey_Space] = 268; - io.KeyMap[ImGuiKey_Enter] = 269; + io.KeyMap[ImGuiKey_Tab] = 256; + io.KeyMap[ImGuiKey_LeftArrow] = 257; + io.KeyMap[ImGuiKey_RightArrow] = 258; + io.KeyMap[ImGuiKey_UpArrow] = 259; + io.KeyMap[ImGuiKey_DownArrow] = 260; + io.KeyMap[ImGuiKey_PageUp] = 261; + io.KeyMap[ImGuiKey_PageDown] = 262; + io.KeyMap[ImGuiKey_Home] = 263; + io.KeyMap[ImGuiKey_End] = 264; + io.KeyMap[ImGuiKey_Insert] = 265; + io.KeyMap[ImGuiKey_Delete] = 266; + io.KeyMap[ImGuiKey_Backspace] = 267; + io.KeyMap[ImGuiKey_Space] = 268; + io.KeyMap[ImGuiKey_Enter] = 269; //io.KeyMap[ImGuiKey_Escape] = 270; io.KeyMap[ImGuiKey_KeyPadEnter] = 271; - io.KeyMap[ImGuiKey_A] = 'A'; - io.KeyMap[ImGuiKey_C] = 'C'; - io.KeyMap[ImGuiKey_V] = 'V'; - io.KeyMap[ImGuiKey_X] = 'X'; - io.KeyMap[ImGuiKey_Y] = 'Y'; - io.KeyMap[ImGuiKey_Z] = 'Z'; + io.KeyMap[ImGuiKey_A] = 'A'; + io.KeyMap[ImGuiKey_C] = 'C'; + io.KeyMap[ImGuiKey_V] = 'V'; + io.KeyMap[ImGuiKey_X] = 'X'; + io.KeyMap[ImGuiKey_Y] = 'Y'; + io.KeyMap[ImGuiKey_Z] = 'Z'; m_LastTimestamp = std::chrono::high_resolution_clock::now(); } @@ -93,11 +93,11 @@ ImGuiImplLinuxX11::~ImGuiImplLinuxX11() void ImGuiImplLinuxX11::NewFrame() { - auto now = std::chrono::high_resolution_clock::now(); - auto elapsed_ns = now - m_LastTimestamp; + auto now = std::chrono::high_resolution_clock::now(); + auto elapsed_ns = now - m_LastTimestamp; m_LastTimestamp = now; - auto& io = ImGui::GetIO(); - io.DeltaTime = static_cast<float>(elapsed_ns.count() / 1e+9); + auto& io = ImGui::GetIO(); + io.DeltaTime = static_cast<float>(elapsed_ns.count() / 1e+9); ImGuiImplDiligent::NewFrame(); } @@ -111,9 +111,9 @@ bool ImGuiImplLinuxX11::HandleXEvent(XEvent* event) case ButtonPress: case ButtonRelease: { - bool IsPressed = event->type == ButtonPress; - auto* xbe = reinterpret_cast<XButtonEvent *>(event); - switch(xbe->button) + bool IsPressed = event->type == ButtonPress; + auto* xbe = reinterpret_cast<XButtonEvent*>(event); + switch (xbe->button) { case Button1: io.MouseDown[0] = IsPressed; break; // Left case Button2: io.MouseDown[2] = IsPressed; break; // Middle @@ -126,33 +126,34 @@ bool ImGuiImplLinuxX11::HandleXEvent(XEvent* event) case MotionNotify: { - XMotionEvent* xme = (XMotionEvent *)event; - io.MousePos = ImVec2(xme->x, xme->y); + XMotionEvent* xme = (XMotionEvent*)event; + io.MousePos = ImVec2(xme->x, xme->y); return io.WantCaptureMouse; } case ConfigureNotify: { - XConfigureEvent *xce = (XConfigureEvent *)event; - io.DisplaySize = ImVec2(xce->width, xce->height); + XConfigureEvent* xce = (XConfigureEvent*)event; + io.DisplaySize = ImVec2(xce->width, xce->height); return false; } case KeyPress: - case KeyRelease: + case KeyRelease: { bool IsPressed = event->type == KeyPress; - io.KeyCtrl = (event->xkey.state & ControlMask) != 0; - io.KeyShift = (event->xkey.state & ShiftMask) != 0; - io.KeyAlt = (event->xkey.state & Mod1Mask) != 0; + io.KeyCtrl = (event->xkey.state & ControlMask) != 0; + io.KeyShift = (event->xkey.state & ShiftMask) != 0; + io.KeyAlt = (event->xkey.state & Mod1Mask) != 0; - KeySym keysym = 0; + KeySym keysym = 0; constexpr int buff_sz = 80; - char buffer[buff_sz]; - int num_char = XLookupString((XKeyEvent *)event, buffer, buff_sz, &keysym, 0); - int k = 0; - switch(keysym) + char buffer[buff_sz]; + int num_char = XLookupString((XKeyEvent*)event, buffer, buff_sz, &keysym, 0); + int k = 0; + switch (keysym) { + // clang-format off case XK_Tab: k = io.KeyMap[ImGuiKey_Tab]; break; case XK_Left: k = io.KeyMap[ImGuiKey_LeftArrow]; break; case XK_Right: k = io.KeyMap[ImGuiKey_RightArrow]; break; @@ -169,24 +170,25 @@ bool ImGuiImplLinuxX11::HandleXEvent(XEvent* event) case XK_Return: k = io.KeyMap[ImGuiKey_Enter]; break; case XK_Escape: k = io.KeyMap[ImGuiKey_Escape]; break; case XK_KP_Enter: k = io.KeyMap[ImGuiKey_KeyPadEnter];break; + // clang-format on } - if (k!=0) + if (k != 0) io.KeysDown[k] = IsPressed; if (k == 0 && IsPressed) { - for (int i=0; i < num_char; ++i) + for (int i = 0; i < num_char; ++i) io.AddInputCharacter(buffer[i]); } return io.WantCaptureKeyboard; } - default: + default: break; } - return false; + return false; } -} +} // namespace Diligent diff --git a/Imgui/src/ImGuiImplLinuxXCB.cpp b/Imgui/src/ImGuiImplLinuxXCB.cpp index 5e73702..3470c00 100644 --- a/Imgui/src/ImGuiImplLinuxXCB.cpp +++ b/Imgui/src/ImGuiImplLinuxXCB.cpp @@ -28,15 +28,15 @@ #include "xcb_keysyms/xcb_keysyms.h" #ifdef Bool -# undef Bool +# undef Bool #endif #ifdef True -# undef True +# undef True #endif #ifdef False -# undef False +# undef False #endif #include "ImGuiImplLinuxXCB.h" @@ -52,38 +52,38 @@ ImGuiImplLinuxXCB::ImGuiImplLinuxXCB(xcb_connection_t* connection, Uint32 DisplayHeight, Uint32 InitialVertexBufferSize, Uint32 InitialIndexBufferSize) : - ImGuiImplDiligent(pDevice, BackBufferFmt, DepthBufferFmt, InitialVertexBufferSize, InitialIndexBufferSize) + ImGuiImplDiligent{pDevice, BackBufferFmt, DepthBufferFmt, InitialVertexBufferSize, InitialIndexBufferSize} { m_syms = xcb_key_symbols_alloc((xcb_connection_t*)connection); - auto& io = ImGui::GetIO(); + auto& io = ImGui::GetIO(); io.DisplaySize = ImVec2(DisplayWidth, DisplayHeight); - + io.BackendPlatformName = "Diligent-ImGuiImplLinuxXCB"; // Keyboard mapping. ImGui will use those indices to peek into the io.KeysDown[] array that we will update during the application lifetime. - io.KeyMap[ImGuiKey_Tab] = 0x17; - io.KeyMap[ImGuiKey_LeftArrow] = 0x71; - io.KeyMap[ImGuiKey_RightArrow] = 0x72; - io.KeyMap[ImGuiKey_UpArrow] = 0x6F; - io.KeyMap[ImGuiKey_DownArrow] = 0x74; - io.KeyMap[ImGuiKey_PageUp] = 0x70; - io.KeyMap[ImGuiKey_PageDown] = 0x75; - io.KeyMap[ImGuiKey_Home] = 0x6E; - io.KeyMap[ImGuiKey_End] = 0x73; - io.KeyMap[ImGuiKey_Insert] = 0x76; - io.KeyMap[ImGuiKey_Delete] = 0x77; - io.KeyMap[ImGuiKey_Backspace] = 0x16; + io.KeyMap[ImGuiKey_Tab] = 0x17; + io.KeyMap[ImGuiKey_LeftArrow] = 0x71; + io.KeyMap[ImGuiKey_RightArrow] = 0x72; + io.KeyMap[ImGuiKey_UpArrow] = 0x6F; + io.KeyMap[ImGuiKey_DownArrow] = 0x74; + io.KeyMap[ImGuiKey_PageUp] = 0x70; + io.KeyMap[ImGuiKey_PageDown] = 0x75; + io.KeyMap[ImGuiKey_Home] = 0x6E; + io.KeyMap[ImGuiKey_End] = 0x73; + io.KeyMap[ImGuiKey_Insert] = 0x76; + io.KeyMap[ImGuiKey_Delete] = 0x77; + io.KeyMap[ImGuiKey_Backspace] = 0x16; //io.KeyMap[ImGuiKey_Space] = 0;//VK_SPACE; io.KeyMap[ImGuiKey_Enter] = 0x24; io.KeyMap[ImGuiKey_Escape] = 0x09; io.KeyMap[ImGuiKey_KeyPadEnter] = 0x68; - io.KeyMap[ImGuiKey_A] = 'A'; - io.KeyMap[ImGuiKey_C] = 'C'; - io.KeyMap[ImGuiKey_V] = 'V'; - io.KeyMap[ImGuiKey_X] = 'X'; - io.KeyMap[ImGuiKey_Y] = 'Y'; - io.KeyMap[ImGuiKey_Z] = 'Z'; + io.KeyMap[ImGuiKey_A] = 'A'; + io.KeyMap[ImGuiKey_C] = 'C'; + io.KeyMap[ImGuiKey_V] = 'V'; + io.KeyMap[ImGuiKey_X] = 'X'; + io.KeyMap[ImGuiKey_Y] = 'Y'; + io.KeyMap[ImGuiKey_Z] = 'Z'; m_LastTimestamp = std::chrono::high_resolution_clock::now(); } @@ -98,11 +98,11 @@ ImGuiImplLinuxXCB::~ImGuiImplLinuxXCB() void ImGuiImplLinuxXCB::NewFrame() { - auto now = std::chrono::high_resolution_clock::now(); - auto elapsed_ns = now - m_LastTimestamp; + auto now = std::chrono::high_resolution_clock::now(); + auto elapsed_ns = now - m_LastTimestamp; m_LastTimestamp = now; - auto& io = ImGui::GetIO(); - io.DeltaTime = static_cast<float>(elapsed_ns.count() / 1e+9); + auto& io = ImGui::GetIO(); + io.DeltaTime = static_cast<float>(elapsed_ns.count() / 1e+9); ImGuiImplDiligent::NewFrame(); } @@ -119,9 +119,10 @@ void ImGuiImplLinuxXCB::HandleKeyEvent(xcb_key_release_event_t* event) io.KeyShift = event->state & XCB_KEY_BUT_MASK_SHIFT; io.KeyAlt = event->state & XCB_KEY_BUT_MASK_MOD_1; - int k = 0; - switch (event->detail) - { + int k = 0; + switch (event->detail) + { + // clang-format off case 0x09: k = io.KeyMap[ImGuiKey_Escape]; break; case 0x6F: k = io.KeyMap[ImGuiKey_UpArrow]; break; case 0x74: k = io.KeyMap[ImGuiKey_DownArrow]; break; @@ -137,9 +138,10 @@ void ImGuiImplLinuxXCB::HandleKeyEvent(xcb_key_release_event_t* event) case 0x68: k = io.KeyMap[ImGuiKey_KeyPadEnter];break; case 0x70: k = io.KeyMap[ImGuiKey_PageUp]; break; case 0x75: k = io.KeyMap[ImGuiKey_PageDown]; break; - } + // clang-format on + } - if(k == 0 && IsKeyPressed) + if (k == 0 && IsKeyPressed) { xcb_keysym_t keysym = xcb_key_press_lookup_keysym(m_syms, event, 0); switch (keysym) @@ -154,31 +156,31 @@ void ImGuiImplLinuxXCB::HandleKeyEvent(xcb_key_release_event_t* event) case XK_Alt_L: case XK_Alt_R: /*s_KMod |= TW_KMOD_ALT;*/ break; -#ifdef XK_Enter +# ifdef XK_Enter case XK_Enter: k = TW_KEY_RETURN; break; -#endif +# endif -#ifdef XK_KP_Home +# ifdef XK_KP_Home case XK_KP_Home: k = io.KeyMap[ImGuiKey_Home]; break; case XK_KP_End: k = io.KeyMap[ImGuiKey_End]; break; case XK_KP_Delete: k = io.KeyMap[ImGuiKey_Delete]; break; -#endif +# endif -#ifdef XK_KP_Up +# ifdef XK_KP_Up case XK_KP_Up: k = io.KeyMap[ImGuiKey_UpArrow]; break; case XK_KP_Down: k = io.KeyMap[ImGuiKey_DownArrow]; break; case XK_KP_Right: k = io.KeyMap[ImGuiKey_RightArrow]; break; case XK_KP_Left: k = io.KeyMap[ImGuiKey_LeftArrow]; break; -#endif +# endif -#ifdef XK_KP_Page_Up +# ifdef XK_KP_Page_Up case XK_KP_Page_Up: k = io.KeyMap[ImGuiKey_PageUp]; break; case XK_KP_Page_Down: k = io.KeyMap[ImGuiKey_PageDown]; break; -#endif +# endif -#ifdef XK_KP_Tab +# ifdef XK_KP_Tab case XK_KP_Tab: k = io.KeyMap[ImGuiKey_Tab]; break; -#endif +# endif #endif default: if (keysym > 12 && keysym < 127) @@ -189,29 +191,29 @@ void ImGuiImplLinuxXCB::HandleKeyEvent(xcb_key_release_event_t* event) keysym += (int)'A' - (int)'a'; else { - switch(keysym) + switch (keysym) { - case '`': keysym = '~'; break; - case '1': keysym = '!'; break; - case '2': keysym = '@'; break; - case '3': keysym = '#'; break; - case '4': keysym = '$'; break; - case '5': keysym = '%'; break; - case '6': keysym = '^'; break; - case '7': keysym = '&'; break; - case '8': keysym = '*'; break; - case '9': keysym = '('; break; - case '0': keysym = ')'; break; - case '-': keysym = '_'; break; - case '=': keysym = '+'; break; - case '[': keysym = '{'; break; - case ']': keysym = '}'; break; + case '`': keysym = '~'; break; + case '1': keysym = '!'; break; + case '2': keysym = '@'; break; + case '3': keysym = '#'; break; + case '4': keysym = '$'; break; + case '5': keysym = '%'; break; + case '6': keysym = '^'; break; + case '7': keysym = '&'; break; + case '8': keysym = '*'; break; + case '9': keysym = '('; break; + case '0': keysym = ')'; break; + case '-': keysym = '_'; break; + case '=': keysym = '+'; break; + case '[': keysym = '{'; break; + case ']': keysym = '}'; break; case '\\': keysym = '|'; break; - case ';': keysym = ':'; break; + case ';': keysym = ':'; break; case '\'': keysym = '\"'; break; - case ',': keysym = '<'; break; - case '.': keysym = '>'; break; - case '/': keysym = '?'; break; + case ',': keysym = '<'; break; + case '.': keysym = '>'; break; + case '/': keysym = '?'; break; } } } @@ -234,15 +236,15 @@ bool ImGuiImplLinuxXCB::HandleXCBEvent(xcb_generic_event_t* event) { case XCB_MOTION_NOTIFY: { - xcb_motion_notify_event_t *motion = (xcb_motion_notify_event_t *)event; - io.MousePos = ImVec2(motion->event_x, motion->event_y); + xcb_motion_notify_event_t* motion = (xcb_motion_notify_event_t*)event; + io.MousePos = ImVec2(motion->event_x, motion->event_y); return io.WantCaptureMouse; } break; case XCB_BUTTON_PRESS: { - xcb_button_press_event_t *press = (xcb_button_press_event_t *)event; + xcb_button_press_event_t* press = (xcb_button_press_event_t*)event; switch (press->detail) { case XCB_BUTTON_INDEX_1: io.MouseDown[0] = true; break; // left @@ -251,14 +253,14 @@ bool ImGuiImplLinuxXCB::HandleXCBEvent(xcb_generic_event_t* event) case XCB_BUTTON_INDEX_4: io.MouseWheel += 1; break; case XCB_BUTTON_INDEX_5: io.MouseWheel -= 1; break; } - + return io.WantCaptureMouse; } break; case XCB_BUTTON_RELEASE: { - xcb_button_release_event_t *press = (xcb_button_release_event_t *)event; + xcb_button_release_event_t* press = (xcb_button_release_event_t*)event; switch (press->detail) { case XCB_BUTTON_INDEX_1: io.MouseDown[0] = false; break; // left @@ -273,7 +275,7 @@ bool ImGuiImplLinuxXCB::HandleXCBEvent(xcb_generic_event_t* event) case XCB_KEY_RELEASE: case XCB_KEY_PRESS: { - xcb_key_press_event_t* keyEvent = (xcb_key_press_event_t *)event; + xcb_key_press_event_t* keyEvent = (xcb_key_press_event_t*)event; HandleKeyEvent(keyEvent); return io.WantCaptureKeyboard; } @@ -281,7 +283,8 @@ bool ImGuiImplLinuxXCB::HandleXCBEvent(xcb_generic_event_t* event) case XCB_CONFIGURE_NOTIFY: { - const xcb_configure_notify_event_t *cfgEvent = (const xcb_configure_notify_event_t *)event; + const xcb_configure_notify_event_t* cfgEvent = (const xcb_configure_notify_event_t*)event; + io.DisplaySize = ImVec2(cfgEvent->width, cfgEvent->height); return false; } @@ -294,4 +297,4 @@ bool ImGuiImplLinuxXCB::HandleXCBEvent(xcb_generic_event_t* event) return false; } -} +} // namespace Diligent diff --git a/Imgui/src/ImGuiImplUWP.cpp b/Imgui/src/ImGuiImplUWP.cpp index b09f318..d85af42 100644 --- a/Imgui/src/ImGuiImplUWP.cpp +++ b/Imgui/src/ImGuiImplUWP.cpp @@ -22,7 +22,7 @@ */ #ifndef NOMINMAX -# define NOMINMAX +# define NOMINMAX #endif #include <wrl.h> #include <wrl/client.h> @@ -34,47 +34,47 @@ namespace Diligent { -ImGuiImplUWP::ImGuiImplUWP(IRenderDevice* pDevice, - TEXTURE_FORMAT BackBufferFmt, - TEXTURE_FORMAT DepthBufferFmt, - Uint32 DisplayWidth, - Uint32 DisplayHeight, - Uint32 InitialVertexBufferSize, - Uint32 InitialIndexBufferSize) : - ImGuiImplDiligent(pDevice, BackBufferFmt, DepthBufferFmt, InitialVertexBufferSize, InitialIndexBufferSize), - m_DisplayWidth (DisplayWidth), - m_DisplayHeight (DisplayHeight) +ImGuiImplUWP::ImGuiImplUWP(IRenderDevice* pDevice, + TEXTURE_FORMAT BackBufferFmt, + TEXTURE_FORMAT DepthBufferFmt, + Uint32 DisplayWidth, + Uint32 DisplayHeight, + Uint32 InitialVertexBufferSize, + Uint32 InitialIndexBufferSize) : + ImGuiImplDiligent{pDevice, BackBufferFmt, DepthBufferFmt, InitialVertexBufferSize, InitialIndexBufferSize}, + m_DisplayWidth{DisplayWidth}, + m_DisplayHeight{DisplayHeight} { - ::QueryPerformanceFrequency((LARGE_INTEGER *)&m_TicksPerSecond); - ::QueryPerformanceCounter((LARGE_INTEGER *)&m_Time); + ::QueryPerformanceFrequency((LARGE_INTEGER*)&m_TicksPerSecond); + ::QueryPerformanceCounter((LARGE_INTEGER*)&m_Time); // Setup back-end capabilities flags - ImGuiIO& io = ImGui::GetIO(); + ImGuiIO& io = ImGui::GetIO(); io.BackendPlatformName = "imgui_impl_uwp"; // Keyboard mapping. ImGui will use those indices to peek into the io.KeysDown[] array that we will update during the application lifetime. - io.KeyMap[ImGuiKey_Tab] = VK_TAB; - io.KeyMap[ImGuiKey_LeftArrow] = VK_LEFT; - io.KeyMap[ImGuiKey_RightArrow] = VK_RIGHT; - io.KeyMap[ImGuiKey_UpArrow] = VK_UP; - io.KeyMap[ImGuiKey_DownArrow] = VK_DOWN; - io.KeyMap[ImGuiKey_PageUp] = VK_PRIOR; - io.KeyMap[ImGuiKey_PageDown] = VK_NEXT; - io.KeyMap[ImGuiKey_Home] = VK_HOME; - io.KeyMap[ImGuiKey_End] = VK_END; - io.KeyMap[ImGuiKey_Insert] = VK_INSERT; - io.KeyMap[ImGuiKey_Delete] = VK_DELETE; - io.KeyMap[ImGuiKey_Backspace] = VK_BACK; - io.KeyMap[ImGuiKey_Space] = VK_SPACE; - io.KeyMap[ImGuiKey_Enter] = VK_RETURN; - io.KeyMap[ImGuiKey_Escape] = VK_ESCAPE; + io.KeyMap[ImGuiKey_Tab] = VK_TAB; + io.KeyMap[ImGuiKey_LeftArrow] = VK_LEFT; + io.KeyMap[ImGuiKey_RightArrow] = VK_RIGHT; + io.KeyMap[ImGuiKey_UpArrow] = VK_UP; + io.KeyMap[ImGuiKey_DownArrow] = VK_DOWN; + io.KeyMap[ImGuiKey_PageUp] = VK_PRIOR; + io.KeyMap[ImGuiKey_PageDown] = VK_NEXT; + io.KeyMap[ImGuiKey_Home] = VK_HOME; + io.KeyMap[ImGuiKey_End] = VK_END; + io.KeyMap[ImGuiKey_Insert] = VK_INSERT; + io.KeyMap[ImGuiKey_Delete] = VK_DELETE; + io.KeyMap[ImGuiKey_Backspace] = VK_BACK; + io.KeyMap[ImGuiKey_Space] = VK_SPACE; + io.KeyMap[ImGuiKey_Enter] = VK_RETURN; + io.KeyMap[ImGuiKey_Escape] = VK_ESCAPE; io.KeyMap[ImGuiKey_KeyPadEnter] = VK_RETURN; - io.KeyMap[ImGuiKey_A] = 'A'; - io.KeyMap[ImGuiKey_C] = 'C'; - io.KeyMap[ImGuiKey_V] = 'V'; - io.KeyMap[ImGuiKey_X] = 'X'; - io.KeyMap[ImGuiKey_Y] = 'Y'; - io.KeyMap[ImGuiKey_Z] = 'Z'; + io.KeyMap[ImGuiKey_A] = 'A'; + io.KeyMap[ImGuiKey_C] = 'C'; + io.KeyMap[ImGuiKey_V] = 'V'; + io.KeyMap[ImGuiKey_X] = 'X'; + io.KeyMap[ImGuiKey_Y] = 'Y'; + io.KeyMap[ImGuiKey_Z] = 'Z'; } ImGuiImplUWP::~ImGuiImplUWP() @@ -90,13 +90,13 @@ void ImGuiImplUWP::NewFrame() // Setup time step INT64 current_time; - ::QueryPerformanceCounter((LARGE_INTEGER *)¤t_time); + ::QueryPerformanceCounter((LARGE_INTEGER*)¤t_time); io.DeltaTime = (float)(current_time - m_Time) / m_TicksPerSecond; - m_Time = current_time; + m_Time = current_time; io.KeySuper = false; ImGuiImplDiligent::NewFrame(); } -} +} // namespace Diligent diff --git a/Imgui/src/ImGuiImplWin32.cpp b/Imgui/src/ImGuiImplWin32.cpp index 58f3f6e..f665b5e 100644 --- a/Imgui/src/ImGuiImplWin32.cpp +++ b/Imgui/src/ImGuiImplWin32.cpp @@ -22,7 +22,7 @@ */ #ifndef NOMINMAX -# define NOMINMAX +# define NOMINMAX #endif #include <Windows.h> @@ -35,13 +35,13 @@ IMGUI_IMPL_API LRESULT ImGui_ImplWin32_WndProcHandler(HWND hwnd, UINT msg, WPARA namespace Diligent { -ImGuiImplWin32::ImGuiImplWin32(HWND hWnd, - IRenderDevice* pDevice, - TEXTURE_FORMAT BackBufferFmt, - TEXTURE_FORMAT DepthBufferFmt, - Uint32 InitialVertexBufferSize, - Uint32 InitialIndexBufferSize) : - ImGuiImplDiligent(pDevice, BackBufferFmt, DepthBufferFmt, InitialVertexBufferSize, InitialIndexBufferSize) +ImGuiImplWin32::ImGuiImplWin32(HWND hWnd, + IRenderDevice* pDevice, + TEXTURE_FORMAT BackBufferFmt, + TEXTURE_FORMAT DepthBufferFmt, + Uint32 InitialVertexBufferSize, + Uint32 InitialIndexBufferSize) : + ImGuiImplDiligent{pDevice, BackBufferFmt, DepthBufferFmt, InitialVertexBufferSize, InitialIndexBufferSize} { ImGui_ImplWin32_Init(hWnd); } @@ -67,10 +67,14 @@ LRESULT ImGuiImplWin32::Win32_ProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LP ImGuiIO& io = ImGui::GetIO(); switch (msg) { - case WM_LBUTTONDOWN: case WM_LBUTTONDBLCLK: - case WM_RBUTTONDOWN: case WM_RBUTTONDBLCLK: - case WM_MBUTTONDOWN: case WM_MBUTTONDBLCLK: - case WM_XBUTTONDOWN: case WM_XBUTTONDBLCLK: + case WM_LBUTTONDOWN: + case WM_LBUTTONDBLCLK: + case WM_RBUTTONDOWN: + case WM_RBUTTONDBLCLK: + case WM_MBUTTONDOWN: + case WM_MBUTTONDBLCLK: + case WM_XBUTTONDOWN: + case WM_XBUTTONDBLCLK: case WM_LBUTTONUP: case WM_RBUTTONUP: case WM_MBUTTONUP: @@ -92,4 +96,4 @@ LRESULT ImGuiImplWin32::Win32_ProcHandler(HWND hwnd, UINT msg, WPARAM wParam, LP return res; } -} +} // namespace Diligent |
