From a47adeaa2082de57f260b0b259e028d006479d86 Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Sun, 2 Jul 2017 20:18:34 +0200 Subject: [PATCH] Initial integration of docking that saves layout and does not crash --- .../include/imgui_dock.h | 3 +- .../{imgui => src}/imgui_dock.cpp | 0 CMakeLists.txt | 3 +- src/main.cc | 5 ++ src/modules/RenderModule.cc | 48 +++++++++++++++++-- src/modules/RenderModule.h | 1 + 6 files changed, 52 insertions(+), 8 deletions(-) rename 3rdparty/imgui_docking_minimal/{imgui => src}/imgui_dock.cpp (100%) diff --git a/3rdparty/imgui_docking_minimal/include/imgui_dock.h b/3rdparty/imgui_docking_minimal/include/imgui_dock.h index 8ade387..870544b 100644 --- a/3rdparty/imgui_docking_minimal/include/imgui_dock.h +++ b/3rdparty/imgui_docking_minimal/include/imgui_dock.h @@ -2,7 +2,6 @@ - namespace ImGui { @@ -17,4 +16,4 @@ IMGUI_API void SaveDock(); IMGUI_API void Print(); -} // namespace ImGui \ No newline at end of file +} // namespace ImGui diff --git a/3rdparty/imgui_docking_minimal/imgui/imgui_dock.cpp b/3rdparty/imgui_docking_minimal/src/imgui_dock.cpp similarity index 100% rename from 3rdparty/imgui_docking_minimal/imgui/imgui_dock.cpp rename to 3rdparty/imgui_docking_minimal/src/imgui_dock.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 5eb7ad6..f23c6b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -64,6 +64,7 @@ INCLUDE_DIRECTORIES ( 3rdparty/bgfx/3rdparty/glsl-optimizer/src/ 3rdparty/bgfx/3rdparty/glsl-optimizer/src/mesa/ ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/imgui_docking_minimal/include + ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty/bgfx/3rdparty/ocornut-imgui ${CMAKE_CURRENT_BINARY_DIR}/src ) @@ -86,7 +87,7 @@ SET ( protot_SRCS src/RuntimeModuleManager.cc 3rdparty/glfw/deps/glad.c - 3rdparty/imgui_docking_minimal/imgui/imgui_dock.cpp + 3rdparty/imgui_docking_minimal/src/imgui_dock.cpp ) SET (PROTOT_SOURCE_ROOT_PATH ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/src/main.cc b/src/main.cc index 3c9518d..021bc44 100644 --- a/src/main.cc +++ b/src/main.cc @@ -15,6 +15,7 @@ #include "Timer.h" #include "RuntimeModuleManager.h" #include "imgui/imgui.h" +#include "imgui_dock.h" #include "Globals.h" #include "Serializer.h" @@ -143,6 +144,7 @@ int main(void) imguiCreate(); GuiInputState gui_input_state; gGuiInputState = &gui_input_state; + ImGui::LoadDock(); // Timer Timer timer; @@ -228,6 +230,9 @@ int main(void) gRenderer = nullptr; + ImGui::SaveDock(); + ImGui::ShutdownDock(); imguiDestroy(); + bgfx::shutdown(); } diff --git a/src/modules/RenderModule.cc b/src/modules/RenderModule.cc index 650ccd7..93f5797 100644 --- a/src/modules/RenderModule.cc +++ b/src/modules/RenderModule.cc @@ -2,7 +2,9 @@ #include "Globals.h" #include "RenderModule.h" #include "3rdparty/ocornut-imgui/imgui.h" +#include "3rdparty/ocornut-imgui/imgui_internal.h" #include "imgui/imgui.h" +#include "imgui_dock.h" #define GLFW_EXPOSE_NATIVE_GLX #define GLFW_EXPOSE_NATIVE_X11 #include @@ -43,6 +45,10 @@ typedef Vector3f Vector3f; typedef MatrixNNf MatrixNNf; typedef VectorNf VectorNf; +static bool show_scene0 = true; +static bool show_scene1 = true; +static bool show_scene2 = true; + struct Renderer; struct module_state { @@ -128,7 +134,7 @@ static bool module_step(struct module_state *state, float dt) { bgfx::reset (width, height); int dock_top_offset = 0.0f; - int dock_width = 400; + int dock_width = 0; // ImGui::RootDock( // ImVec2(width - dock_width, dock_top_offset), // ImVec2(dock_width, height - dock_top_offset) @@ -139,6 +145,7 @@ static bool module_step(struct module_state *state, float dt) { ImGuizmo::Enable(true); state->renderer->paintGL(); + state->renderer->DrawGui(); return true; } @@ -1700,10 +1707,6 @@ void Renderer::paintGL() { } } - // Advance to next frame. Rendering thread will be kicked to - // process submitted rendering primitives. - bgfx::frame(); - // if (ImGui::BeginDock("Render Settings")) { if(ImGui::DragFloat3 ("Light0 Pos", lights[0].pos.data(), 1.0f, -10.0f, 10.0f)) { } @@ -1739,10 +1742,45 @@ void Renderer::paintGL() { // ImGui::EndDock(); + // Advance to next frame. Rendering thread will be kicked to + // process submitted rendering primitives. + bgfx::frame(); + // clear debug commands as they have to be issued every frame debugCommands.clear(); } +void Renderer::DrawGui() { + ImGuiStyle& style = ImGui::GetStyle(); + if (ImGui::GetIO().DisplaySize.y > 0) { + ImVec2 pos = ImVec2(0, 25); + ImVec2 size = ImGui::GetIO().DisplaySize; + size.y -= pos.y; + ImGui::RootDock(pos, ImVec2(size.x, size.y - 25.0f)); + + // Draw status bar (no docking) + ImGui::SetNextWindowSize(ImVec2(size.x, 25.0f), ImGuiSetCond_Always); + ImGui::SetNextWindowPos(ImVec2(0, size.y - 32.0f), ImGuiSetCond_Always); + ImGui::Begin("statusbar", nullptr, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoResize); + ImGui::Text("FPS: %f", ImGui::GetIO().Framerate); + ImGui::End(); + } + + if (ImGui::BeginDock("Docks", &show_scene0)) { + ImGui::Print(); + } + ImGui::EndDock(); + + if (ImGui::BeginDock("Dummy1", &show_scene1)) { + ImGui::Text("Placeholder!"); + } + ImGui::EndDock(); +// if (ImGui::BeginDock("Dummy2", &show_scene2)) { +// ImGui::Text("Placeholder2!"); +// } +// ImGui::EndDock(); +} + bool Renderer::updateShaders() { bool result = true; for (int i = 0; i < RenderState::Count; i++) { diff --git a/src/modules/RenderModule.h b/src/modules/RenderModule.h index 949191f..51132f4 100644 --- a/src/modules/RenderModule.h +++ b/src/modules/RenderModule.h @@ -417,6 +417,7 @@ struct Renderer { void initialize(int width, int height); void shutdown(); void paintGL(); + void DrawGui(); void resize (int x, int y, int width, int height); // check whether shader files were modified and reload them. Returns