From 88b077a4114cb1e6ab14041241bb3c8a1f039fad Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Fri, 4 Aug 2023 16:39:30 -0300 Subject: [PATCH 01/37] Feat: Roboto font --- src/atta/ui/layers/uiLayer.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/atta/ui/layers/uiLayer.cpp b/src/atta/ui/layers/uiLayer.cpp index 5a69d7a4..71a64fbe 100644 --- a/src/atta/ui/layers/uiLayer.cpp +++ b/src/atta/ui/layers/uiLayer.cpp @@ -4,12 +4,14 @@ // Date: 2021-09-01 // By Breno Cunha Queiroz //-------------------------------------------------- +#include #include // ImGui backends -#include -#include +#include "imgui.h" #include #include +#include +#include #include namespace atta::ui { @@ -22,7 +24,6 @@ void UILayer::onAttach() { ImPlot::CreateContext(); ImGuiIO& io = ImGui::GetIO(); - (void)io; io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking @@ -35,6 +36,7 @@ void UILayer::onAttach() { // Multiple viewports not supported for the web io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable; // Enable Multi-Viewport #endif + io.FontDefault = io.Fonts->AddFontFromFileTTF(file::solveResourcePath("fonts/roboto/Roboto-Regular.ttf").string().c_str(), 14.5f); GLFWwindow* window = glfwGetCurrentContext(); ImGui_ImplGlfw_InitForOpenGL(window, true); From 9265138f88504d01e20ed8c3cd5f14e3fbeac5e1 Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Tue, 2 Jan 2024 08:41:00 +0100 Subject: [PATCH 02/37] Refactor: Noto Sans and UI colors --- CMakeLists.txt | 2 +- src/atta/ui/editor/editor.cpp | 4 +- src/atta/ui/manager.cpp | 87 +++++++++++++++++++++------------ src/extern/solveResources.cmake | 16 +++--- 4 files changed, 68 insertions(+), 41 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0eb8c878..4dc989b8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.14) -project(atta VERSION 0.3.1 LANGUAGES CXX C) +project(atta VERSION 0.3.2 LANGUAGES CXX C) OPTION(ATTA_BUILD_TESTS "Set to ON to build also the test executables" diff --git a/src/atta/ui/editor/editor.cpp b/src/atta/ui/editor/editor.cpp index 0c5c1f4c..c080c1f1 100644 --- a/src/atta/ui/editor/editor.cpp +++ b/src/atta/ui/editor/editor.cpp @@ -30,8 +30,8 @@ void Editor::render() { _dockSpace.render(); // Demo - // bool demo = true; - // ImGui::ShowDemoWindow(&demo); + bool demo = true; + ImGui::ShowDemoWindow(&demo); // ImPlot::ShowDemoWindow(&demo); // Top interface diff --git a/src/atta/ui/manager.cpp b/src/atta/ui/manager.cpp index b05341db..a4be6707 100644 --- a/src/atta/ui/manager.cpp +++ b/src/atta/ui/manager.cpp @@ -4,6 +4,7 @@ // Date: 2021-09-28 // By Breno Cunha Queiroz //-------------------------------------------------- +#include #include #include @@ -37,6 +38,8 @@ void Manager::startUpImpl() { io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls io.ConfigFlags |= ImGuiConfigFlags_DockingEnable; // Enable Docking + io.FontDefault = io.Fonts->AddFontFromFileTTF(file::solveResourcePath("fonts/NotoSans-Regular.ttf").string().c_str(), 16.0f); + // Don't save imgui.ini io.IniFilename = NULL; #ifdef ATTA_OS_WEB @@ -84,36 +87,60 @@ void Manager::shutDownImpl() { } void Manager::setTheme() { - ImGui::StyleColorsDark(); - auto& colors = ImGui::GetStyle().Colors; - colors[ImGuiCol_WindowBg] = ImVec4{0.1f, 0.105f, 0.11f, 1.0f}; - - // Headers - colors[ImGuiCol_Header] = ImVec4{0.25f, 0.255f, 0.26f, 1.0f}; - colors[ImGuiCol_HeaderHovered] = ImVec4{0.3f, 0.305f, 0.31f, 1.0f}; - colors[ImGuiCol_HeaderActive] = ImVec4{0.15f, 0.1505f, 0.151f, 1.0f}; - - // Buttons - colors[ImGuiCol_Button] = ImVec4{0.2f, 0.205f, 0.21f, 1.0f}; - colors[ImGuiCol_ButtonHovered] = ImVec4{0.3f, 0.305f, 0.31f, 1.0f}; - colors[ImGuiCol_ButtonActive] = ImVec4{0.15f, 0.1505f, 0.151f, 1.0f}; - - // Frame BG - colors[ImGuiCol_FrameBg] = ImVec4{0.2f, 0.205f, 0.21f, 1.0f}; - colors[ImGuiCol_FrameBgHovered] = ImVec4{0.3f, 0.305f, 0.31f, 1.0f}; - colors[ImGuiCol_FrameBgActive] = ImVec4{0.15f, 0.1505f, 0.151f, 1.0f}; - - // Tabs - colors[ImGuiCol_Tab] = ImVec4{0.15f, 0.1505f, 0.151f, 1.0f}; - colors[ImGuiCol_TabHovered] = ImVec4{0.38f, 0.3805f, 0.381f, 1.0f}; - colors[ImGuiCol_TabActive] = ImVec4{0.28f, 0.2805f, 0.281f, 1.0f}; - colors[ImGuiCol_TabUnfocused] = ImVec4{0.15f, 0.1505f, 0.151f, 1.0f}; - colors[ImGuiCol_TabUnfocusedActive] = ImVec4{0.2f, 0.205f, 0.21f, 1.0f}; - - // Title - colors[ImGuiCol_TitleBg] = ImVec4{0.15f, 0.1505f, 0.151f, 1.0f}; - colors[ImGuiCol_TitleBgActive] = ImVec4{0.15f, 0.1505f, 0.151f, 1.0f}; - colors[ImGuiCol_TitleBgCollapsed] = ImVec4{0.15f, 0.1505f, 0.151f, 1.0f}; + ImVec4* colors = ImGui::GetStyle().Colors; + colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); + colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f); + colors[ImGuiCol_WindowBg] = ImVec4(0.10f, 0.10f, 0.10f, 1.00f); + colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); + colors[ImGuiCol_PopupBg] = ImVec4(0.09f, 0.09f, 0.09f, 0.98f); + colors[ImGuiCol_Border] = ImVec4(0.04f, 0.04f, 0.04f, 1.00f); + colors[ImGuiCol_BorderShadow] = ImVec4(0.04f, 0.04f, 0.04f, 1.00f); + colors[ImGuiCol_FrameBg] = ImVec4(0.04f, 0.04f, 0.04f, 1.00f); + colors[ImGuiCol_FrameBgHovered] = ImVec4(0.02f, 0.02f, 0.02f, 1.00f); + colors[ImGuiCol_FrameBgActive] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); + colors[ImGuiCol_TitleBg] = ImVec4(0.04f, 0.04f, 0.04f, 1.00f); + colors[ImGuiCol_TitleBgActive] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); + colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.04f, 0.04f, 0.04f, 1.00f); + colors[ImGuiCol_MenuBarBg] = ImVec4(0.04f, 0.04f, 0.04f, 1.00f); + colors[ImGuiCol_ScrollbarBg] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); + colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.10f, 0.10f, 0.10f, 1.00f); + colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f); + colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f); + colors[ImGuiCol_CheckMark] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f); + colors[ImGuiCol_SliderGrab] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f); + colors[ImGuiCol_SliderGrabActive] = ImVec4(0.43f, 0.43f, 0.43f, 1.00f); + colors[ImGuiCol_Button] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f); + colors[ImGuiCol_ButtonHovered] = ImVec4(0.18f, 0.18f, 0.18f, 1.00f); + colors[ImGuiCol_ButtonActive] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f); + colors[ImGuiCol_Header] = ImVec4(0.10f, 0.10f, 0.10f, 1.00f); + colors[ImGuiCol_HeaderHovered] = ImVec4(0.04f, 0.04f, 0.04f, 1.00f); + colors[ImGuiCol_HeaderActive] = ImVec4(0.04f, 0.04f, 0.04f, 1.00f); + colors[ImGuiCol_Separator] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); + colors[ImGuiCol_SeparatorHovered] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f); + colors[ImGuiCol_SeparatorActive] = ImVec4(0.31f, 0.31f, 0.31f, 1.00f); + colors[ImGuiCol_ResizeGrip] = ImVec4(0.00f, 0.00f, 0.00f, 0.39f); + colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f); + colors[ImGuiCol_ResizeGripActive] = ImVec4(0.31f, 0.31f, 0.31f, 1.00f); + colors[ImGuiCol_Tab] = ImVec4(0.06f, 0.06f, 0.06f, 1.00f); + colors[ImGuiCol_TabHovered] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f); + colors[ImGuiCol_TabActive] = ImVec4(0.10f, 0.10f, 0.10f, 1.00f); + colors[ImGuiCol_TabUnfocused] = ImVec4(0.10f, 0.10f, 0.10f, 1.00f); + colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.10f, 0.10f, 0.10f, 1.00f); + colors[ImGuiCol_DockingPreview] = ImVec4(1.00f, 1.00f, 1.00f, 0.20f); + colors[ImGuiCol_DockingEmptyBg] = ImVec4(1.00f, 1.00f, 1.00f, 0.20f); + colors[ImGuiCol_PlotLines] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); + colors[ImGuiCol_PlotLinesHovered] = ImVec4(1.00f, 0.43f, 0.35f, 1.00f); + colors[ImGuiCol_TableHeaderBg] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f); + colors[ImGuiCol_TableBorderStrong] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); + colors[ImGuiCol_TableBorderLight] = ImVec4(0.04f, 0.04f, 0.04f, 1.00f); + colors[ImGuiCol_TableRowBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); + colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.02f); + colors[ImGuiCol_TextSelectedBg] = ImVec4(1.00f, 1.00f, 1.00f, 0.20f); + colors[ImGuiCol_DragDropTarget] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f); + colors[ImGuiCol_NavHighlight] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f); + colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f); + colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f); + colors[ImGuiCol_ModalWindowDimBg] = ImVec4(1.00f, 1.00f, 1.00f, 0.08f); } void Manager::initOpenGL() { diff --git a/src/extern/solveResources.cmake b/src/extern/solveResources.cmake index ff7bc481..d5289391 100644 --- a/src/extern/solveResources.cmake +++ b/src/extern/solveResources.cmake @@ -1,8 +1,8 @@ -FetchContent_Declare(resources - URL "http://storage.googleapis.com/atta-resources/atta/resources-0.3.1.zip" - SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/resources -) - -atta_log(Info Extern "Downloading resources...") -FetchContent_Populate(resources) -atta_log(Success Extern "Resources downloaded") +#FetchContent_Declare(resources +# URL "http://storage.googleapis.com/atta-resources/atta/resources-0.3.1.zip" +# SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/resources +#) +# +#atta_log(Info Extern "Downloading resources...") +#FetchContent_Populate(resources) +#atta_log(Success Extern "Resources downloaded") From d04ccf7d97e906494fa708b44ce42ab44b1870df Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Tue, 2 Jan 2024 19:51:37 +0100 Subject: [PATCH 03/37] Refactor: ImGui style --- src/atta/ui/manager.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/atta/ui/manager.cpp b/src/atta/ui/manager.cpp index a4be6707..779f985b 100644 --- a/src/atta/ui/manager.cpp +++ b/src/atta/ui/manager.cpp @@ -87,7 +87,23 @@ void Manager::shutDownImpl() { } void Manager::setTheme() { - ImVec4* colors = ImGui::GetStyle().Colors; + // Style + ImGuiStyle& style = ImGui::GetStyle(); + style.ScrollbarRounding = 0.0f; + style.TabRounding = 0.0f; + style.DockingSeparatorSize = 1.0f; + style.WindowPadding = ImVec2(5.0f, 5.0f); + style.FramePadding = ImVec2(3.0f, 3.0f); + style.GrabMinSize = 5.0f; + style.TabBorderSize = 0.0f; + style.TabBarBorderSize = 0.0f; + style.SeparatorTextBorderSize = 1.0f; + style.SeparatorTextPadding = ImVec2(10.0f, 0.0f); + style.DisplaySafeAreaPadding = ImVec2(0.0f, 0.0f); + style.ScrollbarSize = 12.0f; + + // Colors + ImVec4* colors = style.Colors; colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f); colors[ImGuiCol_WindowBg] = ImVec4(0.10f, 0.10f, 0.10f, 1.00f); From 06cb8e32c5936af0116a772a66f7702a4c879d55 Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Wed, 3 Jan 2024 07:08:48 +0100 Subject: [PATCH 04/37] Feat: Topbar Atta logo --- src/atta/ui/CMakeLists.txt | 6 +- src/atta/ui/editor/toolBar/toolBar.cpp | 12 +- .../timeProfiler/components/tearDown.cpp | 4 +- .../tools/timeProfiler/timeProfilerWindow.cpp | 6 +- src/atta/ui/editor/topBar/topBar.cpp | 367 +++++++++--------- src/atta/ui/editor/widgets/align.cpp | 21 + src/atta/ui/editor/widgets/align.h | 12 + .../editor/{components => widgets}/button.cpp | 6 +- .../editor/{components => widgets}/button.h | 2 +- .../editor/{components => widgets}/help.cpp | 7 +- .../ui/editor/{components => widgets}/help.h | 2 +- src/atta/ui/editor/widgets/image.cpp | 16 + src/atta/ui/editor/widgets/image.h | 12 + 13 files changed, 270 insertions(+), 203 deletions(-) create mode 100644 src/atta/ui/editor/widgets/align.cpp create mode 100644 src/atta/ui/editor/widgets/align.h rename src/atta/ui/editor/{components => widgets}/button.cpp (56%) rename src/atta/ui/editor/{components => widgets}/button.h (82%) rename src/atta/ui/editor/{components => widgets}/help.cpp (81%) rename src/atta/ui/editor/{components => widgets}/help.h (88%) create mode 100644 src/atta/ui/editor/widgets/image.cpp create mode 100644 src/atta/ui/editor/widgets/image.h diff --git a/src/atta/ui/CMakeLists.txt b/src/atta/ui/CMakeLists.txt index 3dfb64a2..22f7a01b 100644 --- a/src/atta/ui/CMakeLists.txt +++ b/src/atta/ui/CMakeLists.txt @@ -8,8 +8,10 @@ set(ATTA_UI_MODULE_SOURCE editor/dockSpace.cpp editor/window.cpp - editor/components/button.cpp - editor/components/help.cpp + editor/widgets/align.cpp + editor/widgets/button.cpp + editor/widgets/help.cpp + editor/widgets/image.cpp editor/topBar/topBar.cpp editor/toolBar/toolBar.cpp diff --git a/src/atta/ui/editor/toolBar/toolBar.cpp b/src/atta/ui/editor/toolBar/toolBar.cpp index 58050c22..3f414633 100644 --- a/src/atta/ui/editor/toolBar/toolBar.cpp +++ b/src/atta/ui/editor/toolBar/toolBar.cpp @@ -11,8 +11,8 @@ #include #include #include -#include #include +#include #include #include #include @@ -39,7 +39,7 @@ void ToolBar::render() { // View button { - if (ui::ImageButton(graphics::getViewportRendering() ? "view" : "no-view", buttonH)) + if (ui::imageButton(graphics::getViewportRendering() ? "icons/view.png" : "icons/no-view.png", buttonH)) graphics::setViewportRendering(!graphics::getViewportRendering()); ImGui::SameLine(); ImGui::Dummy(ImVec2(10.0f, 0.0f)); @@ -53,7 +53,7 @@ void ToolBar::render() { ImGui::PushItemFlag(ImGuiItemFlags_Disabled, true); ImGui::PushStyleVar(ImGuiStyleVar_Alpha, ImGui::GetStyle().Alpha * 0.5f); } - if (ui::ImageButton("stop", buttonH)) { + if (ui::imageButton("icons/stop.png", buttonH)) { event::SimulationStop e; event::publish(e); } @@ -64,7 +64,7 @@ void ToolBar::render() { ImGui::SameLine(); if (Config::getState() != Config::State::RUNNING) { - if (ui::ImageButton("play", buttonH)) { + if (ui::imageButton("icons/play.png", buttonH)) { if (Config::getState() == Config::State::PAUSED) { event::SimulationContinue e; event::publish(e); @@ -74,14 +74,14 @@ void ToolBar::render() { } } } else { - if (ui::ImageButton("pause", buttonH)) { + if (ui::imageButton("icons/pause.png", buttonH)) { event::SimulationPause e; event::publish(e); } } ImGui::SameLine(); - if (ui::ImageButton("step", buttonH)) { + if (ui::imageButton("icons/step.png", buttonH)) { event::SimulationStep e; event::publish(e); } diff --git a/src/atta/ui/editor/tools/timeProfiler/components/tearDown.cpp b/src/atta/ui/editor/tools/timeProfiler/components/tearDown.cpp index a67b1597..fe5f3c56 100644 --- a/src/atta/ui/editor/tools/timeProfiler/components/tearDown.cpp +++ b/src/atta/ui/editor/tools/timeProfiler/components/tearDown.cpp @@ -6,7 +6,7 @@ //-------------------------------------------------- #include -#include +#include #include "imgui.h" @@ -95,7 +95,7 @@ void TearDown::render() { if (ImGui::Checkbox("Exclusive", &_exclusive)) exclusiveChanged = true; ImGui::SameLine(); - ui::Help("Set to exclude the time of nested function calls"); + ui::help("Set to exclude the time of nested function calls"); //----- Check for updates -----// static size_t lastRecordBegin = 0; diff --git a/src/atta/ui/editor/tools/timeProfiler/timeProfilerWindow.cpp b/src/atta/ui/editor/tools/timeProfiler/timeProfilerWindow.cpp index d36301ac..ec45fae8 100644 --- a/src/atta/ui/editor/tools/timeProfiler/timeProfilerWindow.cpp +++ b/src/atta/ui/editor/tools/timeProfiler/timeProfilerWindow.cpp @@ -5,7 +5,7 @@ // By Breno Cunha Queiroz //-------------------------------------------------- #include -#include +#include namespace atta::ui { @@ -25,10 +25,10 @@ void TimeProfilerWindow::renderImpl() { } if (!Profiler::isRecording()) { - if (ui::ImageButton("play", buttonSize)) + if (ui::imageButton("icons/play.png", buttonSize)) Profiler::startRecording(); } else { - if (ui::ImageButton("stop", buttonSize)) + if (ui::imageButton("icons/stop.png", buttonSize)) Profiler::stopRecording(); } diff --git a/src/atta/ui/editor/topBar/topBar.cpp b/src/atta/ui/editor/topBar/topBar.cpp index 54ae0e5e..70139fa7 100644 --- a/src/atta/ui/editor/topBar/topBar.cpp +++ b/src/atta/ui/editor/topBar/topBar.cpp @@ -7,6 +7,9 @@ #include #include +#include +#include +#include #include #include @@ -33,6 +36,8 @@ TopBar::TopBar() : _showPreferences(false) {} void TopBar::render() { if (ImGui::BeginMainMenuBar()) { + ui::image("icons/atta_20x20.png", vec2(20, 20)); + if (ImGui::BeginMenu("File")) { if (file::isProjectOpen()) { ImGui::Text(file::getProject()->getName().c_str()); @@ -75,9 +80,9 @@ void TopBar::render() { ImGui::EndMenu(); } - //if (ImGui::BeginMenu("Edit")) { - // if (ImGui::MenuItem("Preferences")) - // _showPreferences = true; + // if (ImGui::BeginMenu("Edit")) { + // if (ImGui::MenuItem("Preferences")) + // _showPreferences = true; // ImGui::EndMenu(); //} @@ -189,207 +194,207 @@ void TopBar::openProjectModal() { } void TopBar::openPublishedWindow() { - //#ifdef ATTA_CPPRESTSDK_SUPPORT - // static bool lastShow = false; - // std::string modalName = "Open Published##OpenPUblishedModal"; - // static std::shared_ptr client; + // #ifdef ATTA_CPPRESTSDK_SUPPORT + // static bool lastShow = false; + // std::string modalName = "Open Published##OpenPUblishedModal"; + // static std::shared_ptr client; // - // struct PublishedProject { - // // Get from json - // std::string repoUrl; - // std::string reponame; - // std::string username; + // struct PublishedProject { + // // Get from json + // std::string repoUrl; + // std::string reponame; + // std::string username; // - // // Get from project readme - // std::string title; - // std::string description; - // std::string image; - // bool readmeInitialized; - // std::shared_ptr readmeClient; + // // Get from project readme + // std::string title; + // std::string description; + // std::string image; + // bool readmeInitialized; + // std::shared_ptr readmeClient; // - // // Get image - // bool imageInitialized; - // std::shared_ptr imageClient; - // }; - // static std::vector publishedProjects; + // // Get image + // bool imageInitialized; + // std::shared_ptr imageClient; + // }; + // static std::vector publishedProjects; // - // if(_showOpenPublished && !lastShow) - // { - // // OBS: Doing this because can't open popup inside menuitem - // lastShow = _showOpenPublished; + // if(_showOpenPublished && !lastShow) + // { + // // OBS: Doing this because can't open popup inside menuitem + // lastShow = _showOpenPublished; // - // // Open client and make request - // client = std::make_shared("https://raw.githubusercontent.com/brenocq-atta/projects/main/projects.json"); - // client->request(methods::GET) - // .then([](http_response response) - // { - // if(response.status_code() == status_codes::OK) - // { - // response.headers().set_content_type(U("application/json")); - // return response.extract_json(); - // } - // return pplx::task{}; - // }) - // .then([](const pplx::task& task) - // { - // try - // { - // json::value json = task.get(); + // // Open client and make request + // client = std::make_shared("https://raw.githubusercontent.com/brenocq-atta/projects/main/projects.json"); + // client->request(methods::GET) + // .then([](http_response response) + // { + // if(response.status_code() == status_codes::OK) + // { + // response.headers().set_content_type(U("application/json")); + // return response.extract_json(); + // } + // return pplx::task{}; + // }) + // .then([](const pplx::task& task) + // { + // try + // { + // json::value json = task.get(); // - // // Update published projects - // publishedProjects.clear(); - // for(auto project : json.at("projects").as_array()) - // { - // PublishedProject p; - // p.repoUrl = project["repo"].as_string(); - // p.readmeInitialized = false; - // p.imageInitialized = false; + // // Update published projects + // publishedProjects.clear(); + // for(auto project : json.at("projects").as_array()) + // { + // PublishedProject p; + // p.repoUrl = project["repo"].as_string(); + // p.readmeInitialized = false; + // p.imageInitialized = false; // - // int start = 19;// https://github.com/ - // int userRepoDash = p.repoUrl.find('/', start); - // p.username = p.repoUrl.substr(start, userRepoDash-start); - // p.reponame = p.repoUrl.substr(userRepoDash+1, p.repoUrl.size()-userRepoDash+1); - // std::string readmeUrl = "https://raw.githubusercontent.com/" + p.username + "/" + p.reponame + "/main/README.md"; + // int start = 19;// https://github.com/ + // int userRepoDash = p.repoUrl.find('/', start); + // p.username = p.repoUrl.substr(start, userRepoDash-start); + // p.reponame = p.repoUrl.substr(userRepoDash+1, p.repoUrl.size()-userRepoDash+1); + // std::string readmeUrl = "https://raw.githubusercontent.com/" + p.username + "/" + p.reponame + "/main/README.md"; // - // p.title = p.reponame; - // p.description = "Project published by " + p.username; + // p.title = p.reponame; + // p.description = "Project published by " + p.username; // - // p.readmeClient = std::make_shared(readmeUrl); - // publishedProjects.push_back(p); - // } - // } - // catch (const http_exception& e) - // { - // LOG_WARN("ui::TopBar", "Could not get published projects json: $0", e.what()); - // } - // catch (const json::json_exception& e) - // { - // LOG_WARN("ui::TopBar", "Could not serialize published json: $0", e.what()); - // } - // }); - // } + // p.readmeClient = std::make_shared(readmeUrl); + // publishedProjects.push_back(p); + // } + // } + // catch (const http_exception& e) + // { + // LOG_WARN("ui::TopBar", "Could not get published projects json: $0", e.what()); + // } + // catch (const json::json_exception& e) + // { + // LOG_WARN("ui::TopBar", "Could not serialize published json: $0", e.what()); + // } + // }); + // } // - // if(_showOpenPublished) - // { - // if(ImGui::Begin(modalName.c_str(), &_showOpenPublished)) - // { - // // Check initialization - // for(PublishedProject& project : publishedProjects) - // { - // // Get project information from readme metadata - // if(!project.readmeInitialized) - // { - // project.readmeInitialized = true; - // project.readmeClient->request(methods::GET) - // .then([&](http_response response) - // { - // if(response.status_code() == status_codes::OK) - // return response.extract_string(); - // }) - // .then([&project](const pplx::task& task) - // { - // std::string readmeStr = task.get(); - // // Check if readme contains metadata - // if(readmeStr.substr(0,3) == "---") - // { - // int start = 4; - // while(true) - // { - // size_t endMark = readmeStr.find(':', start); - // size_t nl = readmeStr.find('\n', start); - // size_t endMeta = readmeStr.find("---", start); - // if(endMark == std::string::npos || - // nl == std::string::npos || - // endMeta == std::string::npos)// File not well formated - // break; - // if(endMeta < nl)// End of metadata - // break; + // if(_showOpenPublished) + // { + // if(ImGui::Begin(modalName.c_str(), &_showOpenPublished)) + // { + // // Check initialization + // for(PublishedProject& project : publishedProjects) + // { + // // Get project information from readme metadata + // if(!project.readmeInitialized) + // { + // project.readmeInitialized = true; + // project.readmeClient->request(methods::GET) + // .then([&](http_response response) + // { + // if(response.status_code() == status_codes::OK) + // return response.extract_string(); + // }) + // .then([&project](const pplx::task& task) + // { + // std::string readmeStr = task.get(); + // // Check if readme contains metadata + // if(readmeStr.substr(0,3) == "---") + // { + // int start = 4; + // while(true) + // { + // size_t endMark = readmeStr.find(':', start); + // size_t nl = readmeStr.find('\n', start); + // size_t endMeta = readmeStr.find("---", start); + // if(endMark == std::string::npos || + // nl == std::string::npos || + // endMeta == std::string::npos)// File not well formated + // break; + // if(endMeta < nl)// End of metadata + // break; // - // std::string marker = readmeStr.substr(start, endMark-start); - // std::string value = readmeStr.substr(endMark+1, nl-endMark-1l); - // if(value[0] == ' ') value = value.substr(1, value.size()-1); + // std::string marker = readmeStr.substr(start, endMark-start); + // std::string value = readmeStr.substr(endMark+1, nl-endMark-1l); + // if(value[0] == ' ') value = value.substr(1, value.size()-1); // - // if(marker == "title") - // project.title = value; - // else if(marker == "description") - // project.description = value; - // else if(marker == "image") - // project.image = value; + // if(marker == "title") + // project.title = value; + // else if(marker == "description") + // project.description = value; + // else if(marker == "image") + // project.image = value; // - // start = nl+1; - // } - // } - // }); - // } - // } + // start = nl+1; + // } + // } + // }); + // } + // } // // - // // Render projects - // ImGui::Text("Collection of published projects"); - // ImGui::Separator(); + // // Render projects + // ImGui::Text("Collection of published projects"); + // ImGui::Separator(); // - // if(ImGui::BeginTable("publishedProjectTable", 3, ImGuiTableFlags_Borders)) - // { - // ImGui::TableSetupColumn("desc", ImGuiTableColumnFlags_WidthStretch, 300.0f); - // ImGui::TableSetupColumn("user", ImGuiTableColumnFlags_WidthFixed, 100.0f); - // ImGui::TableSetupColumn("open", ImGuiTableColumnFlags_WidthFixed, 40.0f); + // if(ImGui::BeginTable("publishedProjectTable", 3, ImGuiTableFlags_Borders)) + // { + // ImGui::TableSetupColumn("desc", ImGuiTableColumnFlags_WidthStretch, 300.0f); + // ImGui::TableSetupColumn("user", ImGuiTableColumnFlags_WidthFixed, 100.0f); + // ImGui::TableSetupColumn("open", ImGuiTableColumnFlags_WidthFixed, 40.0f); // - // for(PublishedProject& project : publishedProjects) - // { - // ImGui::TableNextColumn(); - // ImGui::Text(project.title.c_str()); - // ImGui::Spacing(); - // ImGui::Text(project.description.c_str()); + // for(PublishedProject& project : publishedProjects) + // { + // ImGui::TableNextColumn(); + // ImGui::Text(project.title.c_str()); + // ImGui::Spacing(); + // ImGui::Text(project.description.c_str()); // - // ImGui::TableNextColumn(); - // ImGui::Text(project.username.c_str()); + // ImGui::TableNextColumn(); + // ImGui::Text(project.username.c_str()); // - // ImGui::TableNextColumn(); + // ImGui::TableNextColumn(); // - // fs::path pathToClone = file::getDefaultProjectFolder(); - // fs::path repoPath = pathToClone/project.reponame; - // if(!fs::exists(repoPath)) - // { - // // Clone repo if not cloned yet - // if(ImGui::Button(("Clone###CloneButton"+project.repoUrl).c_str())) - // { - // fs::path prevPath = fs::current_path(); - // if(!fs::exists(pathToClone)) - // fs::create_directories(pathToClone); - // fs::current_path(pathToClone); - // std::string command = "git clone git@github.com:" + project.username+"/"+project.reponame+".git"; - // LOG_VERBOSE("ui::TopBar", "Running command: $0", command); - // std::system(command.c_str()); - // fs::current_path(prevPath); - // } - // } - // else - // { - // // Open repo project - // if(ImGui::Button(("Open###OpenButton"+project.repoUrl).c_str())) - // { - // bool alreadyOpen = false; - // for(auto& rw : _repoWindows) - // if(rw.getRepoPath() == repoPath) - // { - // alreadyOpen = true; - // break; - // } + // fs::path pathToClone = file::getDefaultProjectFolder(); + // fs::path repoPath = pathToClone/project.reponame; + // if(!fs::exists(repoPath)) + // { + // // Clone repo if not cloned yet + // if(ImGui::Button(("Clone###CloneButton"+project.repoUrl).c_str())) + // { + // fs::path prevPath = fs::current_path(); + // if(!fs::exists(pathToClone)) + // fs::create_directories(pathToClone); + // fs::current_path(pathToClone); + // std::string command = "git clone git@github.com:" + project.username+"/"+project.reponame+".git"; + // LOG_VERBOSE("ui::TopBar", "Running command: $0", command); + // std::system(command.c_str()); + // fs::current_path(prevPath); + // } + // } + // else + // { + // // Open repo project + // if(ImGui::Button(("Open###OpenButton"+project.repoUrl).c_str())) + // { + // bool alreadyOpen = false; + // for(auto& rw : _repoWindows) + // if(rw.getRepoPath() == repoPath) + // { + // alreadyOpen = true; + // break; + // } // - // if(!alreadyOpen) - // _repoWindows.push_back(RepoWindow(repoPath)); - // } - // } + // if(!alreadyOpen) + // _repoWindows.push_back(RepoWindow(repoPath)); + // } + // } // - // ImGui::TableNextRow(); - // } + // ImGui::TableNextRow(); + // } // - // ImGui::EndTable(); - // } - // } - // ImGui::End(); - // } - //#endif// ATTA_CPPRESTSDK_SUPPORT + // ImGui::EndTable(); + // } + // } + // ImGui::End(); + // } + // #endif// ATTA_CPPRESTSDK_SUPPORT } void TopBar::createProjectModal() { diff --git a/src/atta/ui/editor/widgets/align.cpp b/src/atta/ui/editor/widgets/align.cpp new file mode 100644 index 00000000..48a7cc94 --- /dev/null +++ b/src/atta/ui/editor/widgets/align.cpp @@ -0,0 +1,21 @@ +//-------------------------------------------------- +// Atta UI Module +// align.h +// Date: 2024-01-03 +// By Breno Cunha Queiroz +//-------------------------------------------------- +#include + +#include "imgui.h" + +namespace atta::ui { + +void verticalAlign(float height, std::function func) { + float originalPosY = ImGui::GetCursorPosY(); + float padding = (ImGui::GetWindowContentRegionMax().y - height) * 0.5f; + ImGui::SetCursorPosY(originalPosY + padding); + func(); + ImGui::SetCursorPosY(originalPosY); +} + +} // namespace atta::ui diff --git a/src/atta/ui/editor/widgets/align.h b/src/atta/ui/editor/widgets/align.h new file mode 100644 index 00000000..713c1c98 --- /dev/null +++ b/src/atta/ui/editor/widgets/align.h @@ -0,0 +1,12 @@ +//-------------------------------------------------- +// Atta UI Module +// align.h +// Date: 2024-01-03 +// By Breno Cunha Queiroz +//-------------------------------------------------- + +namespace atta::ui { + +void verticalAlign(float height, std::function func); + +} // namespace atta::ui diff --git a/src/atta/ui/editor/components/button.cpp b/src/atta/ui/editor/widgets/button.cpp similarity index 56% rename from src/atta/ui/editor/components/button.cpp rename to src/atta/ui/editor/widgets/button.cpp index 5cbaafe9..18bab116 100644 --- a/src/atta/ui/editor/components/button.cpp +++ b/src/atta/ui/editor/widgets/button.cpp @@ -4,15 +4,15 @@ // Date: 2022-10-24 // By Breno Cunha Queiroz //-------------------------------------------------- -#include +#include #include "imgui.h" #include namespace atta::ui { -bool ImageButton(std::string name, float size) { - return ImGui::ImageButton(graphics::getImGuiImage("icons/" + name + ".png"), ImVec2(size, size), ImVec2(0, 0), ImVec2(1, 1), 0); +bool imageButton(std::string name, float size) { + return ImGui::ImageButton(gfx::getImGuiImage(name), ImVec2(size, size), ImVec2(0, 0), ImVec2(1, 1), 0); } } // namespace atta::ui diff --git a/src/atta/ui/editor/components/button.h b/src/atta/ui/editor/widgets/button.h similarity index 82% rename from src/atta/ui/editor/components/button.h rename to src/atta/ui/editor/widgets/button.h index 791d0062..7f40ffba 100644 --- a/src/atta/ui/editor/components/button.h +++ b/src/atta/ui/editor/widgets/button.h @@ -7,6 +7,6 @@ namespace atta::ui { -bool ImageButton(std::string name, float size); +bool imageButton(std::string name, float size); } // namespace atta::ui diff --git a/src/atta/ui/editor/components/help.cpp b/src/atta/ui/editor/widgets/help.cpp similarity index 81% rename from src/atta/ui/editor/components/help.cpp rename to src/atta/ui/editor/widgets/help.cpp index 8449ecdb..ae56fb74 100644 --- a/src/atta/ui/editor/components/help.cpp +++ b/src/atta/ui/editor/widgets/help.cpp @@ -4,16 +4,15 @@ // Date: 2022-10-24 // By Breno Cunha Queiroz //-------------------------------------------------- -#include +#include #include "imgui.h" namespace atta::ui { -void Help(std::string text) { +void help(std::string text) { ImGui::TextDisabled("(?)"); - if (ImGui::IsItemHovered()) - { + if (ImGui::IsItemHovered()) { ImGui::BeginTooltip(); ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f); ImGui::TextUnformatted(text.c_str()); diff --git a/src/atta/ui/editor/components/help.h b/src/atta/ui/editor/widgets/help.h similarity index 88% rename from src/atta/ui/editor/components/help.h rename to src/atta/ui/editor/widgets/help.h index 2bfa727d..b8bc531c 100644 --- a/src/atta/ui/editor/components/help.h +++ b/src/atta/ui/editor/widgets/help.h @@ -7,6 +7,6 @@ namespace atta::ui { -void Help(std::string text); +void help(std::string text); } // namespace atta::ui diff --git a/src/atta/ui/editor/widgets/image.cpp b/src/atta/ui/editor/widgets/image.cpp new file mode 100644 index 00000000..4d2a261f --- /dev/null +++ b/src/atta/ui/editor/widgets/image.cpp @@ -0,0 +1,16 @@ +//-------------------------------------------------- +// Atta UI Module +// image.cpp +// Date: 2024-01-03 +// By Breno Cunha Queiroz +//-------------------------------------------------- +#include +#include + +#include "imgui.h" + +namespace atta::ui { + +void image(std::string name, vec2 size) { ImGui::Image(gfx::getImGuiImage(name), ImVec2(size.x, size.y)); } + +} // namespace atta::ui diff --git a/src/atta/ui/editor/widgets/image.h b/src/atta/ui/editor/widgets/image.h new file mode 100644 index 00000000..a1976783 --- /dev/null +++ b/src/atta/ui/editor/widgets/image.h @@ -0,0 +1,12 @@ +//-------------------------------------------------- +// Atta UI Module +// image.h +// Date: 2024-01-03 +// By Breno Cunha Queiroz +//-------------------------------------------------- + +namespace atta::ui { + +void image(std::string name, vec2 size); + +} // namespace atta::ui From 40a0d8e7f3eed0a628931dfc1e5942ea23aef8bb Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Wed, 3 Jan 2024 07:59:03 +0100 Subject: [PATCH 05/37] Feat: Starting grid pipeline --- src/atta/graphics/CMakeLists.txt | 7 +- src/atta/graphics/manager.cpp | 3 + .../renderers/common/gridPipeline.cpp | 88 +++++++++++++++++++ .../graphics/renderers/common/gridPipeline.h | 48 ++++++++++ src/atta/graphics/renderers/fastRenderer.cpp | 7 +- src/atta/graphics/renderers/fastRenderer.h | 2 + src/atta/resource/resources/mesh.h | 2 +- 7 files changed, 152 insertions(+), 5 deletions(-) create mode 100644 src/atta/graphics/renderers/common/gridPipeline.cpp create mode 100644 src/atta/graphics/renderers/common/gridPipeline.h diff --git a/src/atta/graphics/CMakeLists.txt b/src/atta/graphics/CMakeLists.txt index 2f52f486..e052f23c 100644 --- a/src/atta/graphics/CMakeLists.txt +++ b/src/atta/graphics/CMakeLists.txt @@ -19,12 +19,13 @@ set(ATTA_GRAPHICS_MODULE_SOURCE compute/entityClick.cpp - renderers/renderer.cpp + renderers/common/drawerPipeline.cpp + renderers/common/gridPipeline.cpp + renderers/common/selectedPipeline.cpp renderers/fastRenderer.cpp renderers/pbrRenderer.cpp renderers/phongRenderer.cpp - renderers/common/selectedPipeline.cpp - renderers/common/drawerPipeline.cpp + renderers/renderer.cpp windows/window.cpp windows/nullWindow.cpp diff --git a/src/atta/graphics/manager.cpp b/src/atta/graphics/manager.cpp index 8ca92570..1ffe4518 100644 --- a/src/atta/graphics/manager.cpp +++ b/src/atta/graphics/manager.cpp @@ -409,6 +409,9 @@ void Manager::createMesh(StringId sid) { for (resource::Mesh::VertexElement element : mesh->getVertexLayout()) { BufferLayout::Element::Type type; switch (element.type) { + case resource::Mesh::VertexElement::FLOAT: + type = BufferLayout::Element::Type::FLOAT; + break; case resource::Mesh::VertexElement::VEC2: type = BufferLayout::Element::Type::VEC2; break; diff --git a/src/atta/graphics/renderers/common/gridPipeline.cpp b/src/atta/graphics/renderers/common/gridPipeline.cpp new file mode 100644 index 00000000..27ee310c --- /dev/null +++ b/src/atta/graphics/renderers/common/gridPipeline.cpp @@ -0,0 +1,88 @@ +//-------------------------------------------------- +// Atta Graphics Module +// gridPipeline.cpp +// Date: 2021-11-16 +// By Breno Cunha Queiroz +//-------------------------------------------------- +#include +#include +#include + +namespace atta::graphics { + +size_t GridPipeline::_gridId = 0; + +GridPipeline::GridPipeline(std::shared_ptr renderPass) : _numLines(0) { + Pipeline::CreateInfo pipelineInfo{}; + pipelineInfo.shader = gfx::create("shaders/grid/grid.asl"); + pipelineInfo.renderPass = renderPass; + pipelineInfo.primitive = Pipeline::Primitive::LINE; + pipelineInfo.debugName = StringId("Grid Pipeline"); + _pipeline = gfx::create(pipelineInfo); + + // Create line mesh + _gridMeshName = "atta::gfx::GridPipeline[" + std::to_string(_gridId++) + "]"; + LOG_DEBUG("GridPipeline", "Mesh id $0", _gridMeshName); + res::Mesh::CreateInfo meshInfo{}; + uint8_t* data = (uint8_t*)_lines.data(); + size_t size = _lines.size() * sizeof(Line); + meshInfo.vertices = std::vector(data, data + size); + meshInfo.vertexLayout.push_back({resource::Mesh::VertexElement::VEC3, "iPos"}); + meshInfo.vertexLayout.push_back({resource::Mesh::VertexElement::VEC4, "iColor"}); + meshInfo.vertexLayout.push_back({resource::Mesh::VertexElement::FLOAT, "iWidth"}); + res::create(_gridMeshName, meshInfo); +} + +GridPipeline::~GridPipeline() { + // TODO Delete grid +} + +void GridPipeline::update(std::shared_ptr camera) { + // Update grid + { + int i = 0; + int size = 100; + for (int j = -size; j <= size; j++) { + _lines[i++].pos = {float(j), -float(size), 0.0f}; + _lines[i++].pos = {float(j), float(size), 0.0f}; + _lines[i++].pos = {-float(size), float(j), 0.0f}; + _lines[i++].pos = {float(size), float(j), 0.0f}; + } + + for (int j = 0; j < i; j++) { + float width = 1.0f; + vec4 color = {1, 1, 1, 0.2}; + if ((j / 4) % 10 == 0) + color = {1, 1, 1, 0.4}; + + if (_lines[j].pos.y == 0.0f) + _lines[j].color = {0.6, 0.2, 0.2, 1.0f}; + else if (_lines[j].pos.x == 0.0f) + _lines[j].color = {0.2, 0.6, 0.2, 1.0f}; + else + _lines[j].color = color; + _lines[j].width = width; + } + _numLines = i; + } + + // Update mesh with grid + uint8_t* data = (uint8_t*)_lines.data(); + size_t size = _lines.size() * sizeof(Line); + res::get(_gridMeshName)->updateVertices(std::vector(data, data + size)); +} + +void GridPipeline::render(std::shared_ptr camera) { + if (_numLines == 0) + return; + + _pipeline->begin(); + { + _pipeline->setMat4("uProjection", camera->getProj()); + _pipeline->setMat4("uView", camera->getView()); + _pipeline->renderMesh(_gridMeshName, _numLines); + } + _pipeline->end(); +} + +} // namespace atta::graphics diff --git a/src/atta/graphics/renderers/common/gridPipeline.h b/src/atta/graphics/renderers/common/gridPipeline.h new file mode 100644 index 00000000..6045667d --- /dev/null +++ b/src/atta/graphics/renderers/common/gridPipeline.h @@ -0,0 +1,48 @@ +//-------------------------------------------------- +// Atta Graphics Module +// gridPipeline.h +// Date: 2021-11-16 +// By Breno Cunha Queiroz +//-------------------------------------------------- +#ifndef ATTA_GRAPHICS_RENDERERS_COMMON_GRID_PIPELINE_H +#define ATTA_GRAPHICS_RENDERERS_COMMON_GRID_PIPELINE_H +#include +#include +#include + +namespace atta::graphics { + +class GridPipeline final { + public: + GridPipeline(std::shared_ptr renderPass); + ~GridPipeline(); + + /// Update GPU line grid + void update(std::shared_ptr camera); + + /** + * @brief Render lines from grid + * + * @note GridPipeline::update should be called before rendering to make sure that the GPU data is up to date + */ + void render(std::shared_ptr camera); + + private: + std::shared_ptr _pipeline; + + struct Line { + vec3 pos; + vec4 color; + float width; + }; + static constexpr size_t MAX_LINES = 1000; + std::array _lines; + size_t _numLines; + + StringId _gridMeshName; + static size_t _gridId; +}; + +} // namespace atta::graphics + +#endif // ATTA_GRAPHICS_RENDERERS_COMMON_GRID_PIPELINE_H diff --git a/src/atta/graphics/renderers/fastRenderer.cpp b/src/atta/graphics/renderers/fastRenderer.cpp index db1e44c5..c02b1472 100644 --- a/src/atta/graphics/renderers/fastRenderer.cpp +++ b/src/atta/graphics/renderers/fastRenderer.cpp @@ -47,8 +47,9 @@ FastRenderer::FastRenderer() : Renderer("FastRenderer"), _wasResized(false) { _geometryPipeline = graphics::create(pipelineInfo); //---------- Common pipelines ----------// - _selectedPipeline = std::make_unique(_renderPass); _drawerPipeline = std::make_unique(_renderPass); + _gridPipeline = std::make_unique(_renderPass); + _selectedPipeline = std::make_unique(_renderPass); } FastRenderer::~FastRenderer() {} @@ -72,6 +73,9 @@ void FastRenderer::render(std::shared_ptr camera) { if (_renderDrawer) _drawerPipeline->update(); + // Update grid data + _gridPipeline->update(camera); + // Render _renderQueue->begin(); { @@ -113,6 +117,7 @@ void FastRenderer::render(std::shared_ptr camera) { if (_renderDrawer) _drawerPipeline->render(camera); + _gridPipeline->render(camera); } _renderPass->end(); } diff --git a/src/atta/graphics/renderers/fastRenderer.h b/src/atta/graphics/renderers/fastRenderer.h index 89b4a486..f8ee9870 100644 --- a/src/atta/graphics/renderers/fastRenderer.h +++ b/src/atta/graphics/renderers/fastRenderer.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -31,6 +32,7 @@ class FastRenderer final : public Renderer { std::shared_ptr _renderPass; std::shared_ptr _geometryPipeline; std::unique_ptr _selectedPipeline; + std::unique_ptr _gridPipeline; std::unique_ptr _drawerPipeline; bool _wasResized; }; diff --git a/src/atta/resource/resources/mesh.h b/src/atta/resource/resources/mesh.h index c1b59bbe..88bfe2fc 100644 --- a/src/atta/resource/resources/mesh.h +++ b/src/atta/resource/resources/mesh.h @@ -20,7 +20,7 @@ namespace atta::resource { class Mesh : public Resource, public memory::AllocatedObject { public: struct VertexElement { - enum Type { VEC2 = 0, VEC3, VEC4 }; + enum Type { FLOAT = 0, VEC2, VEC3, VEC4 }; Type type; std::string name; }; From e6813b52cf3cd5db27881d23671c223a16a48da5 Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Fri, 5 Jan 2024 07:41:18 +0100 Subject: [PATCH 06/37] Feat: Infinite world grid --- src/atta/graphics/apis/openGL/framebuffer.cpp | 13 +++--- src/atta/graphics/apis/vulkan/pipeline.cpp | 22 +++++----- .../renderers/common/gridPipeline.cpp | 41 +++++++++++-------- 3 files changed, 41 insertions(+), 35 deletions(-) diff --git a/src/atta/graphics/apis/openGL/framebuffer.cpp b/src/atta/graphics/apis/openGL/framebuffer.cpp index 48340966..2dfe6a1f 100644 --- a/src/atta/graphics/apis/openGL/framebuffer.cpp +++ b/src/atta/graphics/apis/openGL/framebuffer.cpp @@ -96,16 +96,15 @@ void Framebuffer::bind(bool clear) { clearColor[i] = (GLint)std::round(_clearColor[i]); glClearBufferiv(GL_COLOR, 0, clearColor); } - - if (_depthAttachmentIndex != -1 && _stencilAttachmentIndex != -1) { - glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); - glEnable(GL_DEPTH_TEST); - glEnable(GL_STENCIL_TEST); - glStencilMask(0x00); - } else if (_depthAttachmentIndex != -1) { + if (_depthAttachmentIndex != -1) { glClear(GL_DEPTH_BUFFER_BIT); glEnable(GL_DEPTH_TEST); } + if (_stencilAttachmentIndex != -1) { + glClear(GL_STENCIL_BUFFER_BIT); + glStencilMask(0x00); + glEnable(GL_STENCIL_TEST); + } } } diff --git a/src/atta/graphics/apis/vulkan/pipeline.cpp b/src/atta/graphics/apis/vulkan/pipeline.cpp index 6c46e60b..ed5c3a5c 100644 --- a/src/atta/graphics/apis/vulkan/pipeline.cpp +++ b/src/atta/graphics/apis/vulkan/pipeline.cpp @@ -88,24 +88,22 @@ Pipeline::Pipeline(const gfx::Pipeline::CreateInfo& info) : gfx::Pipeline(info), // Color blend VkPipelineColorBlendAttachmentState colorBlendAttachment{}; colorBlendAttachment.colorWriteMask = VK_COLOR_COMPONENT_R_BIT | VK_COLOR_COMPONENT_G_BIT | VK_COLOR_COMPONENT_B_BIT | VK_COLOR_COMPONENT_A_BIT; - colorBlendAttachment.blendEnable = VK_FALSE; // XXX blend is disabled for now - colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; - colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; - colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD; - colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ONE; - colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ZERO; - colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD; + colorBlendAttachment.blendEnable = VK_FALSE; + if (gfx::Image::getNumChannels(_framebuffer->getImage(0)->getFormat()) == 4) { + colorBlendAttachment.blendEnable = VK_TRUE; + colorBlendAttachment.srcColorBlendFactor = VK_BLEND_FACTOR_SRC_ALPHA; + colorBlendAttachment.dstColorBlendFactor = VK_BLEND_FACTOR_ONE_MINUS_SRC_ALPHA; + colorBlendAttachment.colorBlendOp = VK_BLEND_OP_ADD; + colorBlendAttachment.srcAlphaBlendFactor = VK_BLEND_FACTOR_ZERO; + colorBlendAttachment.dstAlphaBlendFactor = VK_BLEND_FACTOR_ONE; + colorBlendAttachment.alphaBlendOp = VK_BLEND_OP_ADD; + } VkPipelineColorBlendStateCreateInfo colorBlending{}; colorBlending.sType = VK_STRUCTURE_TYPE_PIPELINE_COLOR_BLEND_STATE_CREATE_INFO; colorBlending.logicOpEnable = VK_FALSE; - colorBlending.logicOp = VK_LOGIC_OP_COPY; colorBlending.attachmentCount = 1; colorBlending.pAttachments = &colorBlendAttachment; - colorBlending.blendConstants[0] = 0.0f; - colorBlending.blendConstants[1] = 0.0f; - colorBlending.blendConstants[2] = 0.0f; - colorBlending.blendConstants[3] = 0.0f; // Dynamic state std::vector dynamicStates = {VK_DYNAMIC_STATE_VIEWPORT, VK_DYNAMIC_STATE_SCISSOR}; diff --git a/src/atta/graphics/renderers/common/gridPipeline.cpp b/src/atta/graphics/renderers/common/gridPipeline.cpp index 27ee310c..98390729 100644 --- a/src/atta/graphics/renderers/common/gridPipeline.cpp +++ b/src/atta/graphics/renderers/common/gridPipeline.cpp @@ -41,27 +41,35 @@ void GridPipeline::update(std::shared_ptr camera) { // Update grid { int i = 0; - int size = 100; + int size = 50; + vec2i camPos = camera->getPosition(); + // Create grid for (int j = -size; j <= size; j++) { - _lines[i++].pos = {float(j), -float(size), 0.0f}; - _lines[i++].pos = {float(j), float(size), 0.0f}; - _lines[i++].pos = {-float(size), float(j), 0.0f}; - _lines[i++].pos = {float(size), float(j), 0.0f}; + _lines[i++].pos = {float(j + camPos.x), float(camPos.y - size), 0.0f}; + _lines[i++].pos = {float(j + camPos.x), float(size + camPos.y), 0.0f}; + _lines[i++].pos = {float(camPos.x - size), float(j + camPos.y), 0.0f}; + _lines[i++].pos = {float(size + camPos.x), float(j + camPos.y), 0.0f}; } - for (int j = 0; j < i; j++) { + for (int j = 0; j < i; j += 2) { + // Default line style float width = 1.0f; - vec4 color = {1, 1, 1, 0.2}; - if ((j / 4) % 10 == 0) - color = {1, 1, 1, 0.4}; + vec4 color = {1, 1, 1, 0.1}; - if (_lines[j].pos.y == 0.0f) - _lines[j].color = {0.6, 0.2, 0.2, 1.0f}; - else if (_lines[j].pos.x == 0.0f) - _lines[j].color = {0.2, 0.6, 0.2, 1.0f}; - else - _lines[j].color = color; - _lines[j].width = width; + // Line style every 10 meters + if ((int(_lines[j].pos.y) % 10 == 0 && _lines[j].pos.y == _lines[j + 1].pos.y) || + (int(_lines[j].pos.x) % 10 == 0 && _lines[j].pos.x == _lines[j + 1].pos.x)) + color = {1, 1, 1, 0.2}; + + // Line style of X and Y axes + if (_lines[j].pos.y == 0.0f && _lines[j + 1].pos.y == 0.0f) + color = {0.6, 0.2, 0.2, 1.0f}; + else if (_lines[j].pos.x == 0.0f && _lines[j + 1].pos.x == 0.0f) + color = {0.2, 0.6, 0.2, 1.0f}; + + // Update line style + _lines[j].color = _lines[j + 1].color = color; + _lines[j].width = _lines[j + 1].width = width; } _numLines = i; } @@ -80,6 +88,7 @@ void GridPipeline::render(std::shared_ptr camera) { { _pipeline->setMat4("uProjection", camera->getProj()); _pipeline->setMat4("uView", camera->getView()); + _pipeline->setVec3("uCamPos", camera->getPosition()); _pipeline->renderMesh(_gridMeshName, _numLines); } _pipeline->end(); From 7c5a8de345894c274197de4a87c972de90e1abdb Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Fri, 5 Jan 2024 08:10:52 +0100 Subject: [PATCH 07/37] Feat: Destroy world grid mesh --- src/atta/event/events/meshDestroy.h | 22 +++++++++++++++++++ src/atta/graphics/manager.cpp | 11 ++++++++++ src/atta/graphics/manager.h | 1 + .../renderers/common/gridPipeline.cpp | 5 +---- src/atta/graphics/renderers/fastRenderer.cpp | 9 ++++---- src/atta/graphics/renderers/pbrRenderer.cpp | 8 ++++++- src/atta/graphics/renderers/pbrRenderer.h | 4 +++- src/atta/graphics/renderers/phongRenderer.cpp | 8 ++++++- src/atta/graphics/renderers/phongRenderer.h | 4 +++- src/atta/graphics/shader.cpp | 2 -- src/atta/resource/manager.cpp | 6 ++++- 11 files changed, 65 insertions(+), 15 deletions(-) create mode 100644 src/atta/event/events/meshDestroy.h diff --git a/src/atta/event/events/meshDestroy.h b/src/atta/event/events/meshDestroy.h new file mode 100644 index 00000000..af3bfbcd --- /dev/null +++ b/src/atta/event/events/meshDestroy.h @@ -0,0 +1,22 @@ +//-------------------------------------------------- +// Atta Event Module +// meshDestroy.h +// Date: 2024-01-05 +// By Breno Cunha Queiroz +//-------------------------------------------------- +#ifndef ATTA_EVENT_EVENTS_MESH_DESTROY_H +#define ATTA_EVENT_EVENTS_MESH_DESTROY_H +#include + +namespace atta::event { + +class MeshDestroy : public EventTyped { + public: + MeshDestroy(StringId sid_) : sid(sid_) {} + + const StringId sid; +}; + +} // namespace atta::event + +#endif // ATTA_EVENT_EVENTS_MESH_DESTROY_H diff --git a/src/atta/graphics/manager.cpp b/src/atta/graphics/manager.cpp index 1ffe4518..ca45b4f1 100644 --- a/src/atta/graphics/manager.cpp +++ b/src/atta/graphics/manager.cpp @@ -21,6 +21,7 @@ #include #include +#include #include #include #include @@ -79,6 +80,7 @@ void Manager::startUpImpl() { //----- Resource sync -----// event::subscribe(BIND_EVENT_FUNC(Manager::onMeshLoadEvent)); event::subscribe(BIND_EVENT_FUNC(Manager::onMeshUpdateEvent)); + event::subscribe(BIND_EVENT_FUNC(Manager::onMeshDestroyEvent)); event::subscribe(BIND_EVENT_FUNC(Manager::onImageLoadEvent)); event::subscribe(BIND_EVENT_FUNC(Manager::onImageUpdateEvent)); syncResources(); @@ -93,6 +95,7 @@ void Manager::startUpImpl() { void Manager::shutDownImpl() { event::unsubscribe(BIND_EVENT_FUNC(Manager::onMeshLoadEvent)); event::unsubscribe(BIND_EVENT_FUNC(Manager::onMeshUpdateEvent)); + event::unsubscribe(BIND_EVENT_FUNC(Manager::onMeshDestroyEvent)); event::unsubscribe(BIND_EVENT_FUNC(Manager::onImageLoadEvent)); event::unsubscribe(BIND_EVENT_FUNC(Manager::onImageUpdateEvent)); @@ -372,6 +375,14 @@ void Manager::onMeshUpdateEvent(event::Event& event) { LOG_WARN("gfx::Manager", "Can not update mesh [w]$0[] that was not created", e.sid); } +void Manager::onMeshDestroyEvent(event::Event& event) { + event::MeshDestroy& e = reinterpret_cast(event); + if (_meshes.find(e.sid) != _meshes.end()) + _meshes[e.sid].reset(); + else + LOG_WARN("gfx::Manager", "Can not destroy mesh [w]$0[] that was not created", e.sid); +} + void Manager::onImageLoadEvent(event::Event& event) { event::ImageLoad& e = reinterpret_cast(event); diff --git a/src/atta/graphics/manager.h b/src/atta/graphics/manager.h index 64260e3a..e2c2e80b 100644 --- a/src/atta/graphics/manager.h +++ b/src/atta/graphics/manager.h @@ -88,6 +88,7 @@ class Manager final { void syncResources(); void onMeshLoadEvent(event::Event& event); void onMeshUpdateEvent(event::Event& event); + void onMeshDestroyEvent(event::Event& event); void onImageLoadEvent(event::Event& event); void onImageUpdateEvent(event::Event& event); void createMesh(StringId sid); diff --git a/src/atta/graphics/renderers/common/gridPipeline.cpp b/src/atta/graphics/renderers/common/gridPipeline.cpp index 98390729..fbc6a03b 100644 --- a/src/atta/graphics/renderers/common/gridPipeline.cpp +++ b/src/atta/graphics/renderers/common/gridPipeline.cpp @@ -22,7 +22,6 @@ GridPipeline::GridPipeline(std::shared_ptr renderPass) : _numLines(0 // Create line mesh _gridMeshName = "atta::gfx::GridPipeline[" + std::to_string(_gridId++) + "]"; - LOG_DEBUG("GridPipeline", "Mesh id $0", _gridMeshName); res::Mesh::CreateInfo meshInfo{}; uint8_t* data = (uint8_t*)_lines.data(); size_t size = _lines.size() * sizeof(Line); @@ -33,9 +32,7 @@ GridPipeline::GridPipeline(std::shared_ptr renderPass) : _numLines(0 res::create(_gridMeshName, meshInfo); } -GridPipeline::~GridPipeline() { - // TODO Delete grid -} +GridPipeline::~GridPipeline() { res::destroy(_gridMeshName); } void GridPipeline::update(std::shared_ptr camera) { // Update grid diff --git a/src/atta/graphics/renderers/fastRenderer.cpp b/src/atta/graphics/renderers/fastRenderer.cpp index c02b1472..761c1276 100644 --- a/src/atta/graphics/renderers/fastRenderer.cpp +++ b/src/atta/graphics/renderers/fastRenderer.cpp @@ -69,13 +69,13 @@ void FastRenderer::render(std::shared_ptr camera) { return imageGroup; }); + // Update grid data + _gridPipeline->update(camera); + // Update drawer data if (_renderDrawer) _drawerPipeline->update(); - // Update grid data - _gridPipeline->update(camera); - // Render _renderQueue->begin(); { @@ -115,9 +115,10 @@ void FastRenderer::render(std::shared_ptr camera) { } _geometryPipeline->end(); + _gridPipeline->render(camera); + if (_renderDrawer) _drawerPipeline->render(camera); - _gridPipeline->render(camera); } _renderPass->end(); } diff --git a/src/atta/graphics/renderers/pbrRenderer.cpp b/src/atta/graphics/renderers/pbrRenderer.cpp index 8a2da739..5b4d99e5 100644 --- a/src/atta/graphics/renderers/pbrRenderer.cpp +++ b/src/atta/graphics/renderers/pbrRenderer.cpp @@ -33,7 +33,7 @@ PbrRenderer::PbrRenderer() : Renderer("PbrRenderer"), _firstRender(true), _wasRe { // Framebuffer Framebuffer::CreateInfo framebufferInfo{}; - framebufferInfo.attachments.push_back({Image::Format::RGB}); + framebufferInfo.attachments.push_back({Image::Format::RGBA}); framebufferInfo.attachments.push_back({Image::Format::DEPTH24_STENCIL8}); _width = framebufferInfo.width = 500; _height = framebufferInfo.height = 500; @@ -56,6 +56,7 @@ PbrRenderer::PbrRenderer() : Renderer("PbrRenderer"), _firstRender(true), _wasRe //---------- Common pipelines ----------// //_selectedPipeline = std::make_unique(_geometryRenderPass); + _gridPipeline = std::make_unique(_geometryRenderPass); _drawerPipeline = std::make_unique(_geometryRenderPass); ////---------- Create background shader ----------// @@ -299,6 +300,9 @@ void PbrRenderer::geometryPass(std::shared_ptr camera) { return imageGroup; }); + // Update grid data + _gridPipeline->update(camera); + // Update drawer data if (_renderDrawer) _drawerPipeline->update(); @@ -405,6 +409,8 @@ void PbrRenderer::geometryPass(std::shared_ptr camera) { } _geometryPipeline->end(); + _gridPipeline->render(camera); + if (_renderDrawer) _drawerPipeline->render(camera); } diff --git a/src/atta/graphics/renderers/pbrRenderer.h b/src/atta/graphics/renderers/pbrRenderer.h index 4ff8fc80..fac3de9f 100644 --- a/src/atta/graphics/renderers/pbrRenderer.h +++ b/src/atta/graphics/renderers/pbrRenderer.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -37,8 +38,9 @@ class PbrRenderer final : public Renderer { std::shared_ptr _renderQueue; std::shared_ptr _geometryRenderPass; std::shared_ptr _geometryPipeline; - std::unique_ptr _selectedPipeline; std::unique_ptr _drawerPipeline; + std::unique_ptr _gridPipeline; + std::unique_ptr _selectedPipeline; std::shared_ptr _backgroundShader; bool _firstRender; diff --git a/src/atta/graphics/renderers/phongRenderer.cpp b/src/atta/graphics/renderers/phongRenderer.cpp index 6cb6b2ea..a920ec93 100644 --- a/src/atta/graphics/renderers/phongRenderer.cpp +++ b/src/atta/graphics/renderers/phongRenderer.cpp @@ -48,8 +48,9 @@ PhongRenderer::PhongRenderer() : Renderer("PhongRenderer"), _wasResized(false) { _geometryPipeline = graphics::create(pipelineInfo); //---------- Common pipelines ----------// - _selectedPipeline = std::make_unique(_renderPass); _drawerPipeline = std::make_unique(_renderPass); + _gridPipeline = std::make_unique(_renderPass); + _selectedPipeline = std::make_unique(_renderPass); } PhongRenderer::~PhongRenderer() {} @@ -75,6 +76,9 @@ void PhongRenderer::render(std::shared_ptr camera) { return imageGroup; }); + // Update grid data + _gridPipeline->update(camera); + // Update drawer data if (_renderDrawer) _drawerPipeline->update(); @@ -158,6 +162,8 @@ void PhongRenderer::render(std::shared_ptr camera) { } _geometryPipeline->end(); + _gridPipeline->render(camera); + if (_renderDrawer) _drawerPipeline->render(camera); } diff --git a/src/atta/graphics/renderers/phongRenderer.h b/src/atta/graphics/renderers/phongRenderer.h index 1883dadf..f90f17c7 100644 --- a/src/atta/graphics/renderers/phongRenderer.h +++ b/src/atta/graphics/renderers/phongRenderer.h @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -30,8 +31,9 @@ class PhongRenderer final : public Renderer { std::shared_ptr _renderQueue; std::shared_ptr _renderPass; std::shared_ptr _geometryPipeline; - std::unique_ptr _selectedPipeline; std::unique_ptr _drawerPipeline; + std::unique_ptr _gridPipeline; + std::unique_ptr _selectedPipeline; bool _wasResized; }; diff --git a/src/atta/graphics/shader.cpp b/src/atta/graphics/shader.cpp index 7a5b4f61..62dea7fc 100644 --- a/src/atta/graphics/shader.cpp +++ b/src/atta/graphics/shader.cpp @@ -50,8 +50,6 @@ const BufferLayout& Shader::getPerFrameImageLayout() const { return _perFrameIma const BufferLayout& Shader::getPerDrawImageLayout() const { return _perDrawImageLayout; } void Shader::processASL() { - LOG_DEBUG("gfx::Shader", "Preprocess ASL: [w]$0", _file.string()); - // Remove comments _aslCode = removeComments(_aslCode); diff --git a/src/atta/resource/manager.cpp b/src/atta/resource/manager.cpp index 67aa32aa..fa25aff0 100644 --- a/src/atta/resource/manager.cpp +++ b/src/atta/resource/manager.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -96,7 +97,10 @@ void Manager::createLoadEvent(Material* resource, StringId sid) { } template <> -void Manager::createDestroyEvent(StringId sid) {} +void Manager::createDestroyEvent(StringId sid) { + event::MeshDestroy e(sid); + event::publish(e); +} template <> void Manager::createDestroyEvent(StringId sid) {} template <> From 85a820e5cdb3ed162d22a1fb82c4f7f36dc1d23a Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Sun, 3 Mar 2024 13:37:03 +0100 Subject: [PATCH 08/37] Refactor: Starting widget gizmo --- src/atta/graphics/interface.h | 12 +- src/atta/graphics/manager.h | 22 ++-- src/atta/ui/editor/widgets/gizmo.cpp | 120 ++++++++++++++++++ src/atta/ui/editor/widgets/gizmo.h | 38 ++++++ .../ui/editor/windows/viewportWindows.cpp | 25 ---- 5 files changed, 175 insertions(+), 42 deletions(-) create mode 100644 src/atta/ui/editor/widgets/gizmo.cpp create mode 100644 src/atta/ui/editor/widgets/gizmo.h diff --git a/src/atta/graphics/interface.h b/src/atta/graphics/interface.h index ed584884..da2d8825 100644 --- a/src/atta/graphics/interface.h +++ b/src/atta/graphics/interface.h @@ -46,12 +46,12 @@ void setUiShutDownFunc(std::function uiShutDownFunc); void setUiStartUpFunc(std::function uiStartUpFunc); //----- Viewport -----// -std::vector> getViewports(); -void clearViewports(); -void addViewport(std::shared_ptr viewport); -void removeViewport(std::shared_ptr viewport); -void createDefaultViewports(); -component::EntityId viewportEntityClick(std::shared_ptr viewport, vec2i pos); +// std::vector> getViewports(); +// void clearViewports(); +// void addViewport(std::shared_ptr viewport); +// void removeViewport(std::shared_ptr viewport); +// void createDefaultViewports(); +// component::EntityId viewportEntityClick(std::shared_ptr viewport, vec2i pos); void* getImGuiImage(StringId sid); } // namespace atta::graphics diff --git a/src/atta/graphics/manager.h b/src/atta/graphics/manager.h index e2c2e80b..211632b9 100644 --- a/src/atta/graphics/manager.h +++ b/src/atta/graphics/manager.h @@ -47,12 +47,12 @@ class Manager final { friend std::shared_ptr getGraphicsAPI(); friend std::shared_ptr getWindow(); - friend std::vector> getViewports(); - friend void clearViewports(); - friend void addViewport(std::shared_ptr viewport); - friend void removeViewport(std::shared_ptr viewport); - friend void createDefaultViewports(); - friend component::EntityId viewportEntityClick(std::shared_ptr viewport, vec2i pos); + // friend std::vector> getViewports(); + // friend void clearViewports(); + // friend void addViewport(std::shared_ptr viewport); + // friend void removeViewport(std::shared_ptr viewport); + // friend void createDefaultViewports(); + // friend component::EntityId viewportEntityClick(std::shared_ptr viewport, vec2i pos); friend void* getImGuiImage(StringId sid); const std::unordered_map>& getMeshes() const; @@ -75,11 +75,11 @@ class Manager final { void recreateGraphicsAPI(); std::vector>& getViewportsImpl(); - void clearViewportsImpl(); - void addViewportImpl(std::shared_ptr viewport); - void removeViewportImpl(std::shared_ptr viewport); - void createDefaultViewportsImpl(); - component::EntityId viewportEntityClickImpl(std::shared_ptr viewport, vec2i pos); + // void clearViewportsImpl(); + // void addViewportImpl(std::shared_ptr viewport); + // void removeViewportImpl(std::shared_ptr viewport); + // void createDefaultViewportsImpl(); + // component::EntityId viewportEntityClickImpl(std::shared_ptr viewport, vec2i pos); void* getImGuiImageImpl(StringId sid); gfx::Image::Format convertFormat(res::Image::Format format) const; diff --git a/src/atta/ui/editor/widgets/gizmo.cpp b/src/atta/ui/editor/widgets/gizmo.cpp new file mode 100644 index 00000000..9a2998a6 --- /dev/null +++ b/src/atta/ui/editor/widgets/gizmo.cpp @@ -0,0 +1,120 @@ +//-------------------------------------------------- +// Atta UI Module +// guizmo.h +// Date: 2024-01-05 +// By Breno Cunha Queiroz +//-------------------------------------------------- +#include + +#include +#include + +#include +#include + +#include + +namespace atta::ui { + +Gizmo::Gizmo() : _operation(TRANSLATE), _mode(WORLD), _isOrthographic(false), _snap(false) {} + +void Gizmo::setOperation(Operation operation) { _operation = operation; } +void Gizmo::setMode(Mode mode) { _mode = mode; } +void Gizmo::setSnap(bool snap) { _snap = snap; } + +void Gizmo::setCamera(std::weak_ptr camera) { _camera = camera; } + +ImGuizmo::OPERATION convert(Operation operation) { + ImGuizmo::OPERATION result{}; + if (operation & TRANSLATE > 0) + result = result | ImGuizmo::OPERATION::TRANSLATE; + if (operation & ROTATE > 0) + result = result | ImGuizmo::OPERATION::ROTATE; + if (operation & SCALE > 0) + result = result | ImGuizmo::OPERATION::SCALE; + return result; +} + +ImGuizmo::MODE convert(Mode mode) { return mode == WORLD ? ImGuizmo::MODE::WORLD : ImGuizmo::MODE::LOCAL; } + +bool Gizmo::manipulate(component::EntityId entity) { + std::shared_ptr camera = _camera.lock(); + component::Transform* t = component::getComponent(entity); + if (t) { + mat4 transform = transpose(t->getWorldTransformMatrix(entity)); + + ImGuizmo::SetDrawlist(); + ImGuizmo::SetRect(ImGui::GetWindowPos().x + 5.0f, ImGui::GetWindowPos().y + 24.0f, 500, 500); + + ImGuizmo::OPERATION operation = convert(_operation); + ImGuizmo::MODE mode = convert(_mode); + + ImGuizmo::SetOrthographic(camera->getName() == "OrthographicCamera"); + mat4 view = transpose(camera->getView()); + mat4 proj = transpose(camera->getProj()); + proj.mat[1][1] *= -1; + + if (ImGuizmo::Manipulate(transpose(_view).data, _proj.data, operation, mode, transform.data, nullptr, snap ? snapValues : nullptr)) { + transform.transpose(); + + // Get changed + vec3 pos, scale; + quat newOri; + transform.getPosOriScale(pos, newOri, scale); + vec3 oriDelta = newOri.getEuler() - t->orientation.getEuler(); + quat ori; + ori.setEuler(t->orientation.getEuler() + oriDelta); + + // Delta world to local + component::Relationship* r = component::getComponent(entity); + if (r && r->getParent() != -1) { + // Get transform of the first entity that has transform when going up in the hierarchy + component::Transform* pt = nullptr; + component::EntityId parentId = -1; + while (pt == nullptr) { + parentId = r->getParent(); + pt = component::getComponent(parentId); + r = component::getComponent(parentId); + if (r->getParent() == -1) + break; + } + + // If found some entity with transform component, convert result to be relative to it + if (pt) { + component::Transform pTransform = pt->getWorldTransform(parentId); + vec3 pPos = pTransform.position; + vec3 pScale = pTransform.scale; + quat pOri = pTransform.orientation; + + // Calculate pos ori scale relative to parent + pos -= pPos; + scale /= pScale; + ori = ori * (-pOri); // Rotation from pOri to ori + } + } + + // Update entity transform + if (mouseOperation == ImGuizmo::OPERATION::TRANSLATE) + t->position = pos; + else if (mouseOperation == ImGuizmo::OPERATION::ROTATE) + t->orientation = ori; + else if (mouseOperation == ImGuizmo::OPERATION::SCALE) + t->scale = scale; + + // component::RigidBody2D* rb2d = component::getComponent(entity); + // if (rb2d) { + // if (mouseOperation == ImGuizmo::OPERATION::TRANSLATE || mouseOperation == ImGuizmo::OPERATION::ROTATE) { + // vec2 pos = vec2(t->position); + // float angle = -t->orientation.getEuler().z; + // rb2d->setTransform(pos, angle); + // } else if (mouseOperation == ImGuizmo::OPERATION::SCALE) { + // // TODO Recreate box2d rigid body + // } + // } + return true; + } + } + return false; +} + +} // namespace atta::ui diff --git a/src/atta/ui/editor/widgets/gizmo.h b/src/atta/ui/editor/widgets/gizmo.h new file mode 100644 index 00000000..8df3f717 --- /dev/null +++ b/src/atta/ui/editor/widgets/gizmo.h @@ -0,0 +1,38 @@ +//-------------------------------------------------- +// Atta UI Module +// guizmo.h +// Date: 2024-01-05 +// By Breno Cunha Queiroz +//-------------------------------------------------- +#include +#include + +namespace atta::ui { + +class Gizmo { + public: + enum Operation { + TRANSLATE = 1 << 0, + ROTATE = 1 << 1, + SCALE = 1 << 2, + }; + inline Operation operator|(OPERATION l, OPERATION r) { return Operation(int(l) | int(r)); } + enum Mode { WORLD = 0, LOCAL }; + + Gizmo(); + + void setOperation(Operation operation); + void setMode(Mode mode); + void setCamera(std::weak_ptr camera); + void setSnap(bool snap); + + bool manipulate(component::EntityId entity); + + private: + Operation _operation; + Mode _mode; + std::weak_ptr _camera; + bool _snap; +}; + +} // namespace atta::ui diff --git a/src/atta/ui/editor/windows/viewportWindows.cpp b/src/atta/ui/editor/windows/viewportWindows.cpp index 1fd864cc..20715075 100644 --- a/src/atta/ui/editor/windows/viewportWindows.cpp +++ b/src/atta/ui/editor/windows/viewportWindows.cpp @@ -19,8 +19,6 @@ #include #include -#include - namespace atta::ui { void ViewportWindows::render() { @@ -199,29 +197,6 @@ void ViewportWindows::render() { } } - //----- Overlay -----// - //{ - // ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoDocking | ImGuiWindowFlags_AlwaysAutoResize | - // ImGuiWindowFlags_NoSavedSettings | ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav | - // ImGuiWindowFlags_NoMove; - // ImVec2 window = ImGui::GetWindowPos(); - // ImGui::SetNextWindowPos(ImVec2(window.x + 10, window.y + 30)); - // ImGui::SetNextWindowBgAlpha(0.35f); - // bool open = true; - // if (ImGui::Begin((viewport->getSID().getString() + "Overlay").c_str(), &open, window_flags)) { - // ImGui::Text("To move the camera"); - // ImGui::BulletText("Holding mouse middle button"); - // ImGui::BulletText("Rotate with mouse"); - // ImGui::BulletText("Move with ASWD QE"); - // ImGui::Text("To move objects"); - // ImGui::BulletText("Select some object"); - // ImGui::BulletText("Translate: SHIFT+t"); - // ImGui::BulletText("Scale: SHIFT+s"); - // ImGui::BulletText("Rotate: SHIFT+r"); - // } - // ImGui::End(); - //} - //----- Resize -----// ImVec2 windowSize = ImGui::GetWindowSize(); if (windowSize.x != size.x || windowSize.y != size.y) From d8817477e43b1f7d35aca2435d2412bfb2a46218 Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Wed, 12 Jun 2024 06:50:43 +0200 Subject: [PATCH 09/37] Fix: Viewport compilation --- .../project/projectSerializerDeserialize.cpp | 13 +- .../project/projectSerializerSerialize.cpp | 11 +- src/atta/graphics/interface.cpp | 16 +- src/atta/graphics/manager.cpp | 82 ++--- src/atta/pch.h | 1 + src/atta/ui/editor/topBar/topBar.cpp | 143 +++---- src/atta/ui/editor/topBar/topBar.h | 2 + .../ui/editor/windows/viewportWindows.cpp | 348 +++++++++--------- src/atta/ui/manager.cpp | 2 +- 9 files changed, 312 insertions(+), 306 deletions(-) diff --git a/src/atta/file/project/projectSerializerDeserialize.cpp b/src/atta/file/project/projectSerializerDeserialize.cpp index 4676a67f..1c792bd0 100644 --- a/src/atta/file/project/projectSerializerDeserialize.cpp +++ b/src/atta/file/project/projectSerializerDeserialize.cpp @@ -49,12 +49,13 @@ void ProjectSerializer::deserializeComponentModule(Section& section) { void ProjectSerializer::deserializeGraphicsModule(Section& section) { if (section.contains("viewports")) { std::vector viewports = std::vector(section["viewports"]); - graphics::clearViewports(); - for (auto& viewport : viewports) { - std::shared_ptr v = std::make_shared(); - *v = viewport; - graphics::addViewport(v); - } + LOG_WARN("file::ProjectSerializer", "Deserializing viewports was not implemented yet"); + // graphics::clearViewports(); + // for (auto& viewport : viewports) { + // std::shared_ptr v = std::make_shared(); + // *v = viewport; + // graphics::addViewport(v); + // } } if (section.contains("graphicsFPS")) graphics::setGraphicsFPS(float(section["graphicsFPS"])); diff --git a/src/atta/file/project/projectSerializerSerialize.cpp b/src/atta/file/project/projectSerializerSerialize.cpp index cedd8ba2..df3bdee8 100644 --- a/src/atta/file/project/projectSerializerSerialize.cpp +++ b/src/atta/file/project/projectSerializerSerialize.cpp @@ -59,11 +59,12 @@ void ProjectSerializer::serializeComponentModule(Section& section) { } void ProjectSerializer::serializeGraphicsModule(Section& section) { - std::vector> pviewports = graphics::getViewports(); - std::vector viewports; - for (auto pv : pviewports) - viewports.push_back(*pv); - section["viewports"] = viewports; + // std::vector> pviewports = graphics::getViewports(); + // std::vector viewports; + // for (auto pv : pviewports) + // viewports.push_back(*pv); + // section["viewports"] = viewports; + LOG_WARN("file::ProjectSerializer", "Serializing viewports was not implemented yet"); section["graphicsFPS"] = graphics::getGraphicsFPS(); section["viewportFPS"] = graphics::getViewportFPS(); section["viewportRendering"] = graphics::getViewportRendering(); diff --git a/src/atta/graphics/interface.cpp b/src/atta/graphics/interface.cpp index ad2bc19f..ec6cec22 100644 --- a/src/atta/graphics/interface.cpp +++ b/src/atta/graphics/interface.cpp @@ -34,14 +34,14 @@ void setUiShutDownFunc(std::function uiShutDownFunc) { Manager::getInsta void setUiStartUpFunc(std::function uiStartUpFunc) { Manager::getInstance()._uiStartUpFunc = uiStartUpFunc; } //----- Viewport -----// -std::vector> getViewports() { return Manager::getInstance().getViewportsImpl(); } -void clearViewports() { Manager::getInstance().clearViewportsImpl(); } -void addViewport(std::shared_ptr viewport) { Manager::getInstance().addViewportImpl(viewport); } -void removeViewport(std::shared_ptr viewport) { Manager::getInstance().removeViewportImpl(viewport); } -void createDefaultViewports() { return Manager::getInstance().createDefaultViewportsImpl(); } -component::EntityId viewportEntityClick(std::shared_ptr viewport, vec2i pos) { - return Manager::getInstance().viewportEntityClickImpl(viewport, pos); -} +// std::vector> getViewports() { return Manager::getInstance().getViewportsImpl(); } +// void clearViewports() { Manager::getInstance().clearViewportsImpl(); } +// void addViewport(std::shared_ptr viewport) { Manager::getInstance().addViewportImpl(viewport); } +// void removeViewport(std::shared_ptr viewport) { Manager::getInstance().removeViewportImpl(viewport); } +// void createDefaultViewports() { return Manager::getInstance().createDefaultViewportsImpl(); } +// component::EntityId viewportEntityClick(std::shared_ptr viewport, vec2i pos) { +// return Manager::getInstance().viewportEntityClickImpl(viewport, pos); +//} void* getImGuiImage(StringId sid) { return Manager::getInstance().getImGuiImageImpl(sid); } diff --git a/src/atta/graphics/manager.cpp b/src/atta/graphics/manager.cpp index ca45b4f1..462e3836 100644 --- a/src/atta/graphics/manager.cpp +++ b/src/atta/graphics/manager.cpp @@ -89,7 +89,7 @@ void Manager::startUpImpl() { _computeEntityClick = std::make_unique(); //----- Create viewports -----// - createDefaultViewportsImpl(); + // createDefaultViewportsImpl(); } void Manager::shutDownImpl() { @@ -164,46 +164,46 @@ void Manager::recreateGraphicsAPI() { _uiStartUpFunc(); } -std::vector>& Manager::getViewportsImpl() { return _viewports; } - -void Manager::clearViewportsImpl() { - _viewportsNext.clear(); - _swapViewports = true; -} - -void Manager::addViewportImpl(std::shared_ptr viewport) { - _viewportsNext.push_back(viewport); - _swapViewports = true; -} - -void Manager::removeViewportImpl(std::shared_ptr viewport) { - // TODO make it work with zero viewports - if (_viewportsNext.size() > 1) { - for (unsigned i = 0; i < _viewportsNext.size(); i++) - if (_viewportsNext[i] == viewport) { - _viewportsNext.erase(_viewportsNext.begin() + i); - break; - } - _swapViewports = true; - } else { - LOG_WARN("graphics::Manager", "It is not possible to have 0 viewports yet"); - } -} - -void Manager::createDefaultViewportsImpl() { - _viewportsNext.clear(); - - Viewport::CreateInfo viewportInfo; - viewportInfo.renderer = std::make_shared(); - viewportInfo.camera = std::make_shared(PerspectiveCamera::CreateInfo{}); - viewportInfo.sid = StringId("Main Viewport"); - _viewportsNext.push_back(std::make_shared(viewportInfo)); - _swapViewports = true; -} - -component::EntityId Manager::viewportEntityClickImpl(std::shared_ptr viewport, vec2i pos) { - return _computeEntityClick->click(viewport, pos); -} +// std::vector>& Manager::getViewportsImpl() { return _viewports; } + +// void Manager::clearViewportsImpl() { +// _viewportsNext.clear(); +// _swapViewports = true; +// } +// +// void Manager::addViewportImpl(std::shared_ptr viewport) { +// _viewportsNext.push_back(viewport); +// _swapViewports = true; +// } +// +// void Manager::removeViewportImpl(std::shared_ptr viewport) { +// // TODO make it work with zero viewports +// if (_viewportsNext.size() > 1) { +// for (unsigned i = 0; i < _viewportsNext.size(); i++) +// if (_viewportsNext[i] == viewport) { +// _viewportsNext.erase(_viewportsNext.begin() + i); +// break; +// } +// _swapViewports = true; +// } else { +// LOG_WARN("graphics::Manager", "It is not possible to have 0 viewports yet"); +// } +// } +// +// void Manager::createDefaultViewportsImpl() { +// _viewportsNext.clear(); +// +// Viewport::CreateInfo viewportInfo; +// viewportInfo.renderer = std::make_shared(); +// viewportInfo.camera = std::make_shared(PerspectiveCamera::CreateInfo{}); +// viewportInfo.sid = StringId("Main Viewport"); +// _viewportsNext.push_back(std::make_shared(viewportInfo)); +// _swapViewports = true; +// } +// +// component::EntityId Manager::viewportEntityClickImpl(std::shared_ptr viewport, vec2i pos) { +// return _computeEntityClick->click(viewport, pos); +// } void* Manager::getImGuiImageImpl(StringId sid) { return _images[sid]->getImGuiImage(); } diff --git a/src/atta/pch.h b/src/atta/pch.h index 14ad57d1..d14dc918 100644 --- a/src/atta/pch.h +++ b/src/atta/pch.h @@ -8,6 +8,7 @@ #define ATTA_PRE_COMPILED_HEADER_H #define _USE_MATH_DEFINES // Windows M_PI fix +#include #include #include #include diff --git a/src/atta/ui/editor/topBar/topBar.cpp b/src/atta/ui/editor/topBar/topBar.cpp index 70139fa7..10d020f8 100644 --- a/src/atta/ui/editor/topBar/topBar.cpp +++ b/src/atta/ui/editor/topBar/topBar.cpp @@ -93,45 +93,45 @@ void TopBar::render() { ImGui::EndMenu(); } - if (ImGui::BeginMenu("Viewports")) { - std::vector> viewports = graphics::getViewports(); - _viewportModals.resize(viewports.size()); - int i = 0; - for (auto viewport : viewports) { - if (ImGui::MenuItem(viewport->getName().c_str())) - _viewportModals[i] = true; - i++; - } - - ImGui::Separator(); - - if (ImGui::MenuItem("Create viewport")) { - // Choose viewport name - unsigned newViewportNumber = 0; - bool found = false; - while (!found) { - found = true; - for (auto viewport : viewports) - if (viewport->getSID() == StringId("Viewport " + std::to_string(newViewportNumber))) { - found = false; - break; - } - if (!found) - newViewportNumber++; - } + // if (ImGui::BeginMenu("Viewports")) { + // std::vector> viewports = graphics::getViewports(); + // _viewportModals.resize(viewports.size()); + // int i = 0; + // for (auto viewport : viewports) { + // if (ImGui::MenuItem(viewport->getName().c_str())) + // _viewportModals[i] = true; + // i++; + // } + + // ImGui::Separator(); + + // if (ImGui::MenuItem("Create viewport")) { + // // Choose viewport name + // unsigned newViewportNumber = 0; + // bool found = false; + // while (!found) { + // found = true; + // for (auto viewport : viewports) + // if (viewport->getSID() == StringId("Viewport " + std::to_string(newViewportNumber))) { + // found = false; + // break; + // } + // if (!found) + // newViewportNumber++; + // } + + // // Create viewport + // graphics::Viewport::CreateInfo viewportInfo; + // viewportInfo.renderer = std::make_shared(); + // viewportInfo.camera = std::static_pointer_cast( + // std::make_shared(graphics::PerspectiveCamera::CreateInfo{})); + // viewportInfo.sid = StringId("Viewport " + std::to_string(newViewportNumber)); + // std::shared_ptr viewport = std::make_shared(viewportInfo); + // graphics::addViewport(viewport); + // } - // Create viewport - graphics::Viewport::CreateInfo viewportInfo; - viewportInfo.renderer = std::make_shared(); - viewportInfo.camera = std::static_pointer_cast( - std::make_shared(graphics::PerspectiveCamera::CreateInfo{})); - viewportInfo.sid = StringId("Viewport " + std::to_string(newViewportNumber)); - std::shared_ptr viewport = std::make_shared(viewportInfo); - graphics::addViewport(viewport); - } - - ImGui::EndMenu(); - } + // ImGui::EndMenu(); + //} if (ImGui::BeginMenu("Modules")) { if (ImGui::MenuItem("Graphics")) @@ -459,7 +459,7 @@ void TopBar::saveProjectModal() { component::clear(); component::createDefault(); // Replace viewports with default - graphics::createDefaultViewports(); + // XXX graphics::createDefaultViewports(); if (_quitAfterSaveModal) { event::WindowClose e; @@ -474,38 +474,39 @@ void TopBar::saveProjectModal() { } void TopBar::viewportModals() { - std::vector> viewports = graphics::getViewports(); - static std::vector newViewportModals; // If first time creating the modal - _viewportModals.resize(viewports.size()); - - // Check if first time creating viewport - newViewportModals.resize(_viewportModals.size()); - for (unsigned i = 0; i < newViewportModals.size(); i++) - newViewportModals[i] = !newViewportModals[i] && _viewportModals[i]; - - for (uint32_t i = 0; i < _viewportModals.size(); i++) { - char nameBuf[196]; - sprintf(nameBuf, "%s###ViewportProps%s", viewports[i]->getName().c_str(), viewports[i]->getSID().getString().c_str()); - - bool open = _viewportModals[i]; - if (open) { - if (newViewportModals[i]) - ImGui::SetNextWindowSize(ImVec2(200.0f, 300.0f)); - if (ImGui::Begin(nameBuf, &open)) { - viewports[i]->renderUI(); - - ImGui::Separator(); - if (ImGui::Button("Delete Viewport")) { - graphics::removeViewport(viewports[i]); - ImGui::End(); - break; - } - } - ImGui::End(); - _viewportModals[i] = open; - } - } - newViewportModals = _viewportModals; + // XXX + // std::vector> viewports = graphics::getViewports(); + // static std::vector newViewportModals; // If first time creating the modal + //_viewportModals.resize(viewports.size()); + + //// Check if first time creating viewport + // newViewportModals.resize(_viewportModals.size()); + // for (unsigned i = 0; i < newViewportModals.size(); i++) + // newViewportModals[i] = !newViewportModals[i] && _viewportModals[i]; + + // for (uint32_t i = 0; i < _viewportModals.size(); i++) { + // char nameBuf[196]; + // sprintf(nameBuf, "%s###ViewportProps%s", viewports[i]->getName().c_str(), viewports[i]->getSID().getString().c_str()); + + // bool open = _viewportModals[i]; + // if (open) { + // if (newViewportModals[i]) + // ImGui::SetNextWindowSize(ImVec2(200.0f, 300.0f)); + // if (ImGui::Begin(nameBuf, &open)) { + // viewports[i]->renderUI(); + + // ImGui::Separator(); + // if (ImGui::Button("Delete Viewport")) { + // graphics::removeViewport(viewports[i]); + // ImGui::End(); + // break; + // } + // } + // ImGui::End(); + // _viewportModals[i] = open; + // } + //} + // newViewportModals = _viewportModals; } } // namespace atta::ui diff --git a/src/atta/ui/editor/topBar/topBar.h b/src/atta/ui/editor/topBar/topBar.h index ab0f5350..3595abd1 100644 --- a/src/atta/ui/editor/topBar/topBar.h +++ b/src/atta/ui/editor/topBar/topBar.h @@ -10,6 +10,7 @@ #include namespace atta::ui { + class TopBar { public: TopBar(); @@ -39,6 +40,7 @@ class TopBar { std::vector _viewportModals; ///< Which viewports should be rendered std::vector _repoWindows; ///< Which repository windows are open }; + } // namespace atta::ui #endif // ATTA_UI_EDITOR_TOP_BAR_TOP_BAR_H diff --git a/src/atta/ui/editor/windows/viewportWindows.cpp b/src/atta/ui/editor/windows/viewportWindows.cpp index 20715075..650a157b 100644 --- a/src/atta/ui/editor/windows/viewportWindows.cpp +++ b/src/atta/ui/editor/windows/viewportWindows.cpp @@ -23,7 +23,7 @@ namespace atta::ui { void ViewportWindows::render() { PROFILE(); - std::vector> viewports = graphics::getViewports(); + // std::vector> viewports = graphics::getViewports(); static int activeViewport = 0; // Viewports fps @@ -35,179 +35,179 @@ void ViewportWindows::render() { } int i = -1; - for (auto viewport : viewports) { - // ImGui::DockBuilderDockWindow((viewport->getName()+"###Viewport"+viewport->getSID().getString()).c_str(), _dockSpace.getViewportDockId()); - char nameBuf[128]; - sprintf(nameBuf, "%s###Viewport%s", viewport->getName().c_str(), viewport->getSID().getString().c_str()); - i++; - // Render and resize - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(5.0f, 5.0f)); - bool open = true; - ImGui::Begin(nameBuf, &open); - if (graphics::getViewportRendering()) { - //----- Move camera -----// - // Check started camera movement - if (ImGui::IsMouseClicked(2) && ImGui::IsWindowHovered()) - activeViewport = i; - - // Update camera (wheel pressed) - if (activeViewport == i && ImGui::IsWindowHovered()) { - viewport->getCamera()->setViewportSize(viewport->getWidth(), viewport->getHeight()); - viewport->getCamera()->move(); - } - - //----- Mouse click -----// - vec2i click = {-1, -1}; - if (ImGui::IsMouseClicked(0) && ImGui::IsWindowHovered()) { - ImVec2 window = ImGui::GetWindowPos(); - ImVec2 cursor = ImGui::GetCursorPos(); - ImVec2 mouse = ImGui::GetMousePos(); - click = {int(mouse.x - window.x - cursor.x), int(mouse.y - window.y - cursor.y)}; - } - - if (ImGui::IsMouseClicked(1) && ImGui::IsWindowHovered()) - ImGui::OpenPopup("Editor_AddBasicShape"); - addBasicShapePopup(); - - //----- Keyboard click -----// - static ImGuizmo::OPERATION mouseOperation = ImGuizmo::OPERATION::TRANSLATE; - static ImGuizmo::MODE mouseMode = ImGuizmo::MODE::LOCAL; - static bool snap = false; - - if (ImGui::IsWindowHovered()) { - snap = false; - ImGuiIO& io = ImGui::GetIO(); - if (ImGui::IsKeyPressed(ImGuiKey_T) && io.KeyCtrl) { - mouseOperation = ImGuizmo::OPERATION::TRANSLATE; - mouseMode = ImGuizmo::MODE::LOCAL; - } else if (ImGui::IsKeyPressed(ImGuiKey_T) && io.KeyShift) { - mouseOperation = ImGuizmo::OPERATION::TRANSLATE; - mouseMode = ImGuizmo::MODE::WORLD; - } else if (ImGui::IsKeyPressed(ImGuiKey_S) && io.KeyCtrl) { - mouseOperation = ImGuizmo::OPERATION::SCALE; - mouseMode = ImGuizmo::MODE::LOCAL; - } else if (ImGui::IsKeyPressed(ImGuiKey_S) && io.KeyShift) { - mouseOperation = ImGuizmo::OPERATION::SCALE; - mouseMode = ImGuizmo::MODE::WORLD; - } else if (ImGui::IsKeyPressed(ImGuiKey_R) && io.KeyCtrl) { - mouseOperation = ImGuizmo::OPERATION::ROTATE; - mouseMode = ImGuizmo::MODE::LOCAL; - } else if (ImGui::IsKeyPressed(ImGuiKey_R) && io.KeyShift) { - mouseOperation = ImGuizmo::OPERATION::ROTATE; - mouseMode = ImGuizmo::MODE::WORLD; - } else if (io.KeyCtrl) - snap = true; - } - - //----- Render to texture -----// - ImVec2 size = ImVec2(viewport->getWidth(), viewport->getHeight()); - ImGui::Image(viewport->getImGuiTexture(), size, ImVec2(0, 0), ImVec2(1, 1)); - - //----- ImGuizmo -----// - bool imGuizmoUsingMouse = false; - component::EntityId entity = component::getSelectedEntity(); - if (entity >= 0) { - component::Transform* t = component::getComponent(entity); - - if (t) { - ImGuizmo::SetOrthographic(viewport->getCamera()->getName() == "OrthographicCamera"); - ImGuizmo::SetDrawlist(); - ImGuizmo::SetRect(ImGui::GetWindowPos().x + 5.0f, ImGui::GetWindowPos().y + 24.0f, viewport->getWidth(), viewport->getHeight()); - mat4 view = transpose(viewport->getCamera()->getView()); - mat4 proj = viewport->getCamera()->getProj(); - proj.mat[1][1] *= -1; - proj.transpose(); - - mat4 transform = transpose(t->getWorldTransformMatrix(entity)); - - float snapValue = 0.5f; - if (mouseOperation == ImGuizmo::OPERATION::ROTATE) - snapValue = 45.0f; - float snapValues[3] = {snapValue, snapValue, snapValue}; - - ImGuizmo::Manipulate(view.data, proj.data, mouseOperation, mouseMode, transform.data, nullptr, snap ? snapValues : nullptr); - - if (ImGuizmo::IsUsing()) { - imGuizmoUsingMouse = true; - transform.transpose(); - - // Get changed - vec3 pos, scale; - quat newOri; - transform.getPosOriScale(pos, newOri, scale); - vec3 oriDelta = newOri.getEuler() - t->orientation.getEuler(); - quat ori; - ori.setEuler(t->orientation.getEuler() + oriDelta); - - // Delta world to local - component::Relationship* r = component::getComponent(entity); - if (r && r->getParent() != -1) { - // Get transform of the first entity that has transform when going up in the hierarchy - component::Transform* pt = nullptr; - component::EntityId parentId = -1; - while (pt == nullptr) { - parentId = r->getParent(); - pt = component::getComponent(parentId); - r = component::getComponent(parentId); - if (r->getParent() == -1) - break; - } - - // If found some entity with transform component, convert result to be relative to it - if (pt) { - component::Transform pTransform = pt->getWorldTransform(parentId); - vec3 pPos = pTransform.position; - vec3 pScale = pTransform.scale; - quat pOri = pTransform.orientation; - - // Calculate pos ori scale relative to parent - pos -= pPos; - scale /= pScale; - ori = ori * (-pOri); // Rotation from pOri to ori - } - } - - // Update entity transform - if (mouseOperation == ImGuizmo::OPERATION::TRANSLATE) - t->position = pos; - else if (mouseOperation == ImGuizmo::OPERATION::ROTATE) - t->orientation = ori; - else if (mouseOperation == ImGuizmo::OPERATION::SCALE) - t->scale = scale; - - // component::RigidBody2D* rb2d = component::getComponent(entity); - // if (rb2d) { - // if (mouseOperation == ImGuizmo::OPERATION::TRANSLATE || mouseOperation == ImGuizmo::OPERATION::ROTATE) { - // vec2 pos = vec2(t->position); - // float angle = -t->orientation.getEuler().z; - // rb2d->setTransform(pos, angle); - // } else if (mouseOperation == ImGuizmo::OPERATION::SCALE) { - // // TODO Recreate box2d rigid body - // } - // } - } - } - } - - //----- Mouse click selection -----// - if (!imGuizmoUsingMouse) { - if (click.x >= 0 && click.y >= 0 && click.x < (int)viewport->getWidth() && click.y < (int)viewport->getHeight()) { - component::EntityId eid = graphics::viewportEntityClick(viewport, click); - component::setSelectedEntity(eid); - } - } - - //----- Resize -----// - ImVec2 windowSize = ImGui::GetWindowSize(); - if (windowSize.x != size.x || windowSize.y != size.y) - viewport->resize((uint32_t)windowSize.x - 10, (uint32_t)windowSize.y - 30); - } - ImGui::End(); - ImGui::PopStyleVar(1); - - if (!open) - graphics::removeViewport(viewport); - } + // for (auto viewport : viewports) { + // // ImGui::DockBuilderDockWindow((viewport->getName()+"###Viewport"+viewport->getSID().getString()).c_str(), + // _dockSpace.getViewportDockId()); char nameBuf[128]; sprintf(nameBuf, "%s###Viewport%s", viewport->getName().c_str(), + // viewport->getSID().getString().c_str()); i++; + // // Render and resize + // ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(5.0f, 5.0f)); + // bool open = true; + // ImGui::Begin(nameBuf, &open); + // // if (graphics::getViewportRendering()) { + // // //----- Move camera -----// + // // // Check started camera movement + // // if (ImGui::IsMouseClicked(2) && ImGui::IsWindowHovered()) + // // activeViewport = i; + + // // // Update camera (wheel pressed) + // // if (activeViewport == i && ImGui::IsWindowHovered()) { + // // viewport->getCamera()->setViewportSize(viewport->getWidth(), viewport->getHeight()); + // // viewport->getCamera()->move(); + // // } + + // // //----- Mouse click -----// + // // vec2i click = {-1, -1}; + // // if (ImGui::IsMouseClicked(0) && ImGui::IsWindowHovered()) { + // // ImVec2 window = ImGui::GetWindowPos(); + // // ImVec2 cursor = ImGui::GetCursorPos(); + // // ImVec2 mouse = ImGui::GetMousePos(); + // // click = {int(mouse.x - window.x - cursor.x), int(mouse.y - window.y - cursor.y)}; + // // } + + // // if (ImGui::IsMouseClicked(1) && ImGui::IsWindowHovered()) + // // ImGui::OpenPopup("Editor_AddBasicShape"); + // // addBasicShapePopup(); + + // // //----- Keyboard click -----// + // // static ImGuizmo::OPERATION mouseOperation = ImGuizmo::OPERATION::TRANSLATE; + // // static ImGuizmo::MODE mouseMode = ImGuizmo::MODE::LOCAL; + // // static bool snap = false; + + // // if (ImGui::IsWindowHovered()) { + // // snap = false; + // // ImGuiIO& io = ImGui::GetIO(); + // // if (ImGui::IsKeyPressed(ImGuiKey_T) && io.KeyCtrl) { + // // mouseOperation = ImGuizmo::OPERATION::TRANSLATE; + // // mouseMode = ImGuizmo::MODE::LOCAL; + // // } else if (ImGui::IsKeyPressed(ImGuiKey_T) && io.KeyShift) { + // // mouseOperation = ImGuizmo::OPERATION::TRANSLATE; + // // mouseMode = ImGuizmo::MODE::WORLD; + // // } else if (ImGui::IsKeyPressed(ImGuiKey_S) && io.KeyCtrl) { + // // mouseOperation = ImGuizmo::OPERATION::SCALE; + // // mouseMode = ImGuizmo::MODE::LOCAL; + // // } else if (ImGui::IsKeyPressed(ImGuiKey_S) && io.KeyShift) { + // // mouseOperation = ImGuizmo::OPERATION::SCALE; + // // mouseMode = ImGuizmo::MODE::WORLD; + // // } else if (ImGui::IsKeyPressed(ImGuiKey_R) && io.KeyCtrl) { + // // mouseOperation = ImGuizmo::OPERATION::ROTATE; + // // mouseMode = ImGuizmo::MODE::LOCAL; + // // } else if (ImGui::IsKeyPressed(ImGuiKey_R) && io.KeyShift) { + // // mouseOperation = ImGuizmo::OPERATION::ROTATE; + // // mouseMode = ImGuizmo::MODE::WORLD; + // // } else if (io.KeyCtrl) + // // snap = true; + // // } + + // // //----- Render to texture -----// + // // ImVec2 size = ImVec2(viewport->getWidth(), viewport->getHeight()); + // // ImGui::Image(viewport->getImGuiTexture(), size, ImVec2(0, 0), ImVec2(1, 1)); + + // // //----- ImGuizmo -----// + // // bool imGuizmoUsingMouse = false; + // // component::EntityId entity = component::getSelectedEntity(); + // // if (entity >= 0) { + // // component::Transform* t = component::getComponent(entity); + + // // if (t) { + // // ImGuizmo::SetOrthographic(viewport->getCamera()->getName() == "OrthographicCamera"); + // // ImGuizmo::SetDrawlist(); + // // ImGuizmo::SetRect(ImGui::GetWindowPos().x + 5.0f, ImGui::GetWindowPos().y + 24.0f, viewport->getWidth(), + // viewport->getHeight()); + // // mat4 view = transpose(viewport->getCamera()->getView()); + // // mat4 proj = viewport->getCamera()->getProj(); + // // proj.mat[1][1] *= -1; + // // proj.transpose(); + + // // mat4 transform = transpose(t->getWorldTransformMatrix(entity)); + + // // float snapValue = 0.5f; + // // if (mouseOperation == ImGuizmo::OPERATION::ROTATE) + // // snapValue = 45.0f; + // // float snapValues[3] = {snapValue, snapValue, snapValue}; + + // // ImGuizmo::Manipulate(view.data, proj.data, mouseOperation, mouseMode, transform.data, nullptr, snap ? snapValues : nullptr); + + // // if (ImGuizmo::IsUsing()) { + // // imGuizmoUsingMouse = true; + // // transform.transpose(); + + // // // Get changed + // // vec3 pos, scale; + // // quat newOri; + // // transform.getPosOriScale(pos, newOri, scale); + // // vec3 oriDelta = newOri.getEuler() - t->orientation.getEuler(); + // // quat ori; + // // ori.setEuler(t->orientation.getEuler() + oriDelta); + + // // // Delta world to local + // // component::Relationship* r = component::getComponent(entity); + // // if (r && r->getParent() != -1) { + // // // Get transform of the first entity that has transform when going up in the hierarchy + // // component::Transform* pt = nullptr; + // // component::EntityId parentId = -1; + // // while (pt == nullptr) { + // // parentId = r->getParent(); + // // pt = component::getComponent(parentId); + // // r = component::getComponent(parentId); + // // if (r->getParent() == -1) + // // break; + // // } + + // // // If found some entity with transform component, convert result to be relative to it + // // if (pt) { + // // component::Transform pTransform = pt->getWorldTransform(parentId); + // // vec3 pPos = pTransform.position; + // // vec3 pScale = pTransform.scale; + // // quat pOri = pTransform.orientation; + + // // // Calculate pos ori scale relative to parent + // // pos -= pPos; + // // scale /= pScale; + // // ori = ori * (-pOri); // Rotation from pOri to ori + // // } + // // } + + // // // Update entity transform + // // if (mouseOperation == ImGuizmo::OPERATION::TRANSLATE) + // // t->position = pos; + // // else if (mouseOperation == ImGuizmo::OPERATION::ROTATE) + // // t->orientation = ori; + // // else if (mouseOperation == ImGuizmo::OPERATION::SCALE) + // // t->scale = scale; + + // // // component::RigidBody2D* rb2d = component::getComponent(entity); + // // // if (rb2d) { + // // // if (mouseOperation == ImGuizmo::OPERATION::TRANSLATE || mouseOperation == ImGuizmo::OPERATION::ROTATE) { + // // // vec2 pos = vec2(t->position); + // // // float angle = -t->orientation.getEuler().z; + // // // rb2d->setTransform(pos, angle); + // // // } else if (mouseOperation == ImGuizmo::OPERATION::SCALE) { + // // // // TODO Recreate box2d rigid body + // // // } + // // // } + // // } + // // } + // // } + + // // //----- Mouse click selection -----// + // // if (!imGuizmoUsingMouse) { + // // if (click.x >= 0 && click.y >= 0 && click.x < (int)viewport->getWidth() && click.y < (int)viewport->getHeight()) { + // // component::EntityId eid = graphics::viewportEntityClick(viewport, click); + // // component::setSelectedEntity(eid); + // // } + // // } + + // // //----- Resize -----// + // // ImVec2 windowSize = ImGui::GetWindowSize(); + // // if (windowSize.x != size.x || windowSize.y != size.y) + // // viewport->resize((uint32_t)windowSize.x - 10, (uint32_t)windowSize.y - 30); + // //} + // ImGui::End(); + // ImGui::PopStyleVar(1); + + // if (!open) + // graphics::removeViewport(viewport); + //} } void ViewportWindows::addBasicShapePopup() { diff --git a/src/atta/ui/manager.cpp b/src/atta/ui/manager.cpp index 779f985b..92e9e1af 100644 --- a/src/atta/ui/manager.cpp +++ b/src/atta/ui/manager.cpp @@ -64,7 +64,7 @@ void Manager::startUpImpl() { gfx::setUiShutDownFunc([&]() { shutDownImpl(); }); gfx::setUiStartUpFunc([&]() { startUpImpl(); }); - // Create editor (make sure windows are reorganized after start up) + // Create editor window _editor = {}; } From c8de137a6539bec40d1a9e017e7d5151116d7212 Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Mon, 24 Jun 2024 17:38:27 -0400 Subject: [PATCH 10/37] Fix: Crash when vulkan not supported --- src/atta/graphics/apis/vulkan/instance.cpp | 7 +++++-- src/atta/graphics/apis/vulkan/instance.h | 3 +++ src/atta/graphics/apis/vulkan/vulkanAPI.cpp | 5 +++++ src/atta/graphics/apis/vulkan/vulkanAPI.h | 2 ++ src/atta/graphics/manager.cpp | 15 +++++++++++---- src/extern/solveResources.cmake | 2 +- 6 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/atta/graphics/apis/vulkan/instance.cpp b/src/atta/graphics/apis/vulkan/instance.cpp index 53da5476..1529a34b 100644 --- a/src/atta/graphics/apis/vulkan/instance.cpp +++ b/src/atta/graphics/apis/vulkan/instance.cpp @@ -10,7 +10,7 @@ namespace atta::graphics::vk { -Instance::Instance() { +Instance::Instance() : _instance(VK_NULL_HANDLE) { // Application info VkApplicationInfo appInfo{}; appInfo.sType = VK_STRUCTURE_TYPE_APPLICATION_INFO; @@ -46,7 +46,8 @@ Instance::Instance() { // Create instance VkResult result = vkCreateInstance(&createInfo, nullptr, &_instance); - if (result != VK_SUCCESS) + _wasCreated = result == VK_SUCCESS; + if (!_wasCreated) LOG_ERROR("gfx::vk::Instance", "Failed to create vulkan instance! Code: $0", common::toString(result)); } @@ -55,6 +56,8 @@ Instance::~Instance() { vkDestroyInstance(_instance, nullptr); } +bool Instance::wasCreated() const { return _wasCreated; } + VkInstance Instance::getHandle() const { return _instance; } void Instance::printAvailableExtensions() { diff --git a/src/atta/graphics/apis/vulkan/instance.h b/src/atta/graphics/apis/vulkan/instance.h index 59edb800..800b17e5 100644 --- a/src/atta/graphics/apis/vulkan/instance.h +++ b/src/atta/graphics/apis/vulkan/instance.h @@ -16,6 +16,8 @@ class Instance { Instance(); ~Instance(); + bool wasCreated() const; + VkInstance getHandle() const; private: @@ -29,6 +31,7 @@ class Instance { std::vector getEnabledLayers(); VkInstance _instance; + bool _wasCreated; VkDebugUtilsMessengerEXT debugMessenger; }; diff --git a/src/atta/graphics/apis/vulkan/vulkanAPI.cpp b/src/atta/graphics/apis/vulkan/vulkanAPI.cpp index 0c100e88..28c5fda9 100644 --- a/src/atta/graphics/apis/vulkan/vulkanAPI.cpp +++ b/src/atta/graphics/apis/vulkan/vulkanAPI.cpp @@ -194,6 +194,11 @@ void VulkanAPI::generateProcessedTexture(GenerateProcessedTextureInfo gptInfo) { void* VulkanAPI::getImGuiImage(StringId sid) const { return nullptr; } +bool VulkanAPI::isSupported() { + vk::Instance instance; + return instance.wasCreated(); +} + std::shared_ptr VulkanAPI::getInstance() const { return _instance; } std::shared_ptr VulkanAPI::getPhysicalDevice() const { return _physicalDevice; } diff --git a/src/atta/graphics/apis/vulkan/vulkanAPI.h b/src/atta/graphics/apis/vulkan/vulkanAPI.h index aff02b9a..f90a4a67 100644 --- a/src/atta/graphics/apis/vulkan/vulkanAPI.h +++ b/src/atta/graphics/apis/vulkan/vulkanAPI.h @@ -46,6 +46,8 @@ class VulkanAPI final : public GraphicsAPI { void* getImGuiImage(StringId sid) const override; + static bool isSupported(); + std::shared_ptr getInstance() const; std::shared_ptr getPhysicalDevice() const; std::shared_ptr getDevice() const; diff --git a/src/atta/graphics/manager.cpp b/src/atta/graphics/manager.cpp index 462e3836..df38961d 100644 --- a/src/atta/graphics/manager.cpp +++ b/src/atta/graphics/manager.cpp @@ -35,10 +35,9 @@ namespace atta::graphics { Manager::Manager() { + setGraphicsAPIImpl(GraphicsAPI::OPENGL); #if ATTA_VULKAN_SUPPORT - _desiredGraphicsAPI = GraphicsAPI::VULKAN; -#else - _desiredGraphicsAPI = GraphicsAPI::OPENGL; + setGraphicsAPIImpl(GraphicsAPI::VULKAN); #endif } @@ -153,7 +152,15 @@ std::shared_ptr Manager::getGraphicsAPIImpl() const { return _graph std::shared_ptr Manager::getWindowImpl() const { return _window; } -void Manager::setGraphicsAPIImpl(GraphicsAPI::Type type) { _desiredGraphicsAPI = type; } +void Manager::setGraphicsAPIImpl(GraphicsAPI::Type type) { +#if ATTA_VULKAN_SUPPORT + if (type == GraphicsAPI::VULKAN && !VulkanAPI::isSupported()) { + LOG_WARN("gfx::Manager", "Failed to set graphics API to Vulkan"); + return; + } +#endif + _desiredGraphicsAPI = type; +} void Manager::recreateGraphicsAPI() { if (_uiShutDownFunc) diff --git a/src/extern/solveResources.cmake b/src/extern/solveResources.cmake index d5289391..0c280dd3 100644 --- a/src/extern/solveResources.cmake +++ b/src/extern/solveResources.cmake @@ -1,5 +1,5 @@ #FetchContent_Declare(resources -# URL "http://storage.googleapis.com/atta-resources/atta/resources-0.3.1.zip" +# URL "https://atta-resources.s3.amazonaws.com/v0.3.1-ui-temp.zip" # SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/resources #) # From afba14c15853c7e773d29f320c2c04c96ed01611 Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Thu, 16 Jan 2025 18:33:53 +0100 Subject: [PATCH 11/37] Chore(UI): Upgrade ImGui to version v1.91.7 Feat(UI): ImGui theme rounding --- src/atta/ui/editor/editor.cpp | 2 +- src/atta/ui/editor/moduleWindows/ioModuleWindowCamera.cpp | 2 +- src/atta/ui/editor/widgets/button.cpp | 4 +--- src/atta/ui/editor/widgets/image.cpp | 2 +- src/atta/ui/manager.cpp | 6 +++++- src/extern/solveImgui.cmake | 2 +- 6 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/atta/ui/editor/editor.cpp b/src/atta/ui/editor/editor.cpp index c080c1f1..7b1f64dc 100644 --- a/src/atta/ui/editor/editor.cpp +++ b/src/atta/ui/editor/editor.cpp @@ -84,7 +84,7 @@ void Editor::renderCameraWindows() { ImGui::Begin((windowName + "##CameraWindow" + std::to_string(cameras[i].entity)).c_str(), &(cameras[i].showWindow)); { ImVec2 size = ImVec2(cameras[i].renderer->getWidth(), cameras[i].renderer->getHeight()); - ImGui::Image(cameras[i].renderer->getImGuiTexture(), size, ImVec2(0, 0), ImVec2(1, 1)); + ImGui::Image((ImTextureID)(intptr_t)cameras[i].renderer->getImGuiTexture(), size); } ImGui::End(); } diff --git a/src/atta/ui/editor/moduleWindows/ioModuleWindowCamera.cpp b/src/atta/ui/editor/moduleWindows/ioModuleWindowCamera.cpp index 30551d8f..5049fbda 100644 --- a/src/atta/ui/editor/moduleWindows/ioModuleWindowCamera.cpp +++ b/src/atta/ui/editor/moduleWindows/ioModuleWindowCamera.cpp @@ -73,7 +73,7 @@ void IOModuleWindow::cameraTabItem() { size = ImVec2(avail.x, avail.x / ratio); } ImGui::SetCursorPos(ImVec2((window.x - size.x) * 0.5f, (window.y - avail.y) * 0.5f)); - ImGui::Image(_cameraImages[name]->getImGuiImage(), size, ImVec2(0, 0), ImVec2(1, 1)); + ImGui::Image((ImTextureID)(intptr_t)_cameraImages[name]->getImGuiImage(), size); } } ImGui::EndChild(); diff --git a/src/atta/ui/editor/widgets/button.cpp b/src/atta/ui/editor/widgets/button.cpp index 18bab116..d7c39c27 100644 --- a/src/atta/ui/editor/widgets/button.cpp +++ b/src/atta/ui/editor/widgets/button.cpp @@ -11,8 +11,6 @@ namespace atta::ui { -bool imageButton(std::string name, float size) { - return ImGui::ImageButton(gfx::getImGuiImage(name), ImVec2(size, size), ImVec2(0, 0), ImVec2(1, 1), 0); -} +bool imageButton(std::string name, float size) { return ImGui::ImageButton(name.c_str(), (ImTextureID)(intptr_t)gfx::getImGuiImage(name), ImVec2(size, size)); } } // namespace atta::ui diff --git a/src/atta/ui/editor/widgets/image.cpp b/src/atta/ui/editor/widgets/image.cpp index 4d2a261f..20683dd8 100644 --- a/src/atta/ui/editor/widgets/image.cpp +++ b/src/atta/ui/editor/widgets/image.cpp @@ -11,6 +11,6 @@ namespace atta::ui { -void image(std::string name, vec2 size) { ImGui::Image(gfx::getImGuiImage(name), ImVec2(size.x, size.y)); } +void image(std::string name, vec2 size) { ImGui::Image((ImTextureID)(intptr_t)gfx::getImGuiImage(name), ImVec2(size.x, size.y)); } } // namespace atta::ui diff --git a/src/atta/ui/manager.cpp b/src/atta/ui/manager.cpp index 92e9e1af..0d0e5999 100644 --- a/src/atta/ui/manager.cpp +++ b/src/atta/ui/manager.cpp @@ -101,6 +101,9 @@ void Manager::setTheme() { style.SeparatorTextPadding = ImVec2(10.0f, 0.0f); style.DisplaySafeAreaPadding = ImVec2(0.0f, 0.0f); style.ScrollbarSize = 12.0f; + style.FrameRounding = 5.0f; + style.ScrollbarRounding = 5.0f; + style.TabRounding = 5.0f; // Colors ImVec4* colors = style.Colors; @@ -182,7 +185,8 @@ void Manager::initVulkan() { info.MinImageCount = 3; info.ImageCount = 3; info.CheckVkResultFn = nullptr; - ImGui_ImplVulkan_Init(&info, vulkanAPI->getRenderPass()->getHandle()); + info.RenderPass = vulkanAPI->getRenderPass()->getHandle(); + ImGui_ImplVulkan_Init(&info); // Upload Fonts if (!ImGui_ImplVulkan_CreateFontsTexture()) diff --git a/src/extern/solveImgui.cmake b/src/extern/solveImgui.cmake index bebd3dcc..2239b0ca 100644 --- a/src/extern/solveImgui.cmake +++ b/src/extern/solveImgui.cmake @@ -4,7 +4,7 @@ set(ATTA_IMGUI_TARGETS "") FetchContent_Declare( imgui GIT_REPOSITORY "https://github.com/ocornut/imgui" - GIT_TAG "v1.90-docking" + GIT_TAG "v1.91.7-docking" GIT_PROGRESS TRUE GIT_SHALLOW TRUE ) From 23fac494a48b8bc18ae8aebecb3d53d301d45d75 Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Thu, 16 Jan 2025 18:45:02 +0100 Subject: [PATCH 12/37] Feat(UI): ImPlot3D integration --- src/atta/ui/CMakeLists.txt | 2 +- src/atta/ui/editor/editor.cpp | 2 ++ src/atta/ui/manager.cpp | 7 +++++++ src/extern/extern.cmake | 1 + src/extern/solveImgui.cmake | 2 +- src/extern/solveImplot3d.cmake | 35 ++++++++++++++++++++++++++++++++++ 6 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 src/extern/solveImplot3d.cmake diff --git a/src/atta/ui/CMakeLists.txt b/src/atta/ui/CMakeLists.txt index 22f7a01b..03fcf927 100644 --- a/src/atta/ui/CMakeLists.txt +++ b/src/atta/ui/CMakeLists.txt @@ -41,6 +41,6 @@ add_library(atta_ui_module STATIC ${ATTA_UI_MODULE_SOURCE} ) -target_link_libraries(atta_ui_module PRIVATE atta_graphics_module atta_io_module atta_component_module ${ATTA_IMGUIZMO_TARGETS} ${ATTA_IMPLOT_TARGETS}) +target_link_libraries(atta_ui_module PRIVATE atta_graphics_module atta_io_module atta_component_module ${ATTA_IMGUIZMO_TARGETS} ${ATTA_IMPLOT_TARGETS} ${ATTA_IMPLOT3D_TARGETS}) atta_target_common(atta_ui_module) atta_add_libs(atta_ui_module) diff --git a/src/atta/ui/editor/editor.cpp b/src/atta/ui/editor/editor.cpp index 7b1f64dc..91eea24b 100644 --- a/src/atta/ui/editor/editor.cpp +++ b/src/atta/ui/editor/editor.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -33,6 +34,7 @@ void Editor::render() { bool demo = true; ImGui::ShowDemoWindow(&demo); // ImPlot::ShowDemoWindow(&demo); + // ImPlot3D::ShowDemoWindow(&demo); // Top interface _topBar.render(); diff --git a/src/atta/ui/manager.cpp b/src/atta/ui/manager.cpp index 0d0e5999..8491d3ff 100644 --- a/src/atta/ui/manager.cpp +++ b/src/atta/ui/manager.cpp @@ -19,6 +19,7 @@ #endif #include #include +#include // clang-format on namespace atta::ui { @@ -32,6 +33,7 @@ void Manager::startUpImpl() { IMGUI_CHECKVERSION(); ImGui::CreateContext(); ImPlot::CreateContext(); + ImPlot3D::CreateContext(); ImGuiIO& io = ImGui::GetIO(); (void)io; @@ -72,6 +74,11 @@ void Manager::shutDownImpl() { // Make sure all rendering operations are done gfx::getGraphicsAPI()->waitDevice(); + // Destroy plotting contexts + ImPlot3D::DestroyContext(); + ImPlot::DestroyContext(); + + // Destroy ImGui context switch (gfx::getGraphicsAPI()->getType()) { case gfx::GraphicsAPI::OPENGL: ImGui_ImplOpenGL3_Shutdown(); diff --git a/src/extern/extern.cmake b/src/extern/extern.cmake index b839aef1..252759c2 100644 --- a/src/extern/extern.cmake +++ b/src/extern/extern.cmake @@ -26,6 +26,7 @@ include(solveAssimp) include(solveStbImage) include(solveImguizmo) include(solveImplot) +include(solveImplot3d) include(solveBox2d) include(solveBullet) include(solveSystemd) diff --git a/src/extern/solveImgui.cmake b/src/extern/solveImgui.cmake index 2239b0ca..7e92a980 100644 --- a/src/extern/solveImgui.cmake +++ b/src/extern/solveImgui.cmake @@ -28,7 +28,7 @@ endif() add_library(imgui STATIC ${IMGUI_SOURCE} ) -target_include_directories(imgui PUBLIC +target_include_directories(imgui PUBLIC $ $ ) diff --git a/src/extern/solveImplot3d.cmake b/src/extern/solveImplot3d.cmake new file mode 100644 index 00000000..6481cb3c --- /dev/null +++ b/src/extern/solveImplot3d.cmake @@ -0,0 +1,35 @@ +set(ATTA_IMPLOT3D_SUPPORT FALSE) +set(ATTA_IMPLOT3D_TARGETS "") + +FetchContent_Declare( + implot3d + GIT_REPOSITORY "https://github.com/brenocq/implot3d" + GIT_TAG "v0.1" + GIT_PROGRESS TRUE + GIT_SHALLOW TRUE +) + +atta_log(Info Extern "Fetching ImPlot3D...") +FetchContent_MakeAvailable(implot3d) + +set(IMPLOT3D_SOURCE + ${FETCHCONTENT_BASE_DIR}/implot3d-src/implot3d.cpp + ${FETCHCONTENT_BASE_DIR}/implot3d-src/implot3d_demo.cpp + ${FETCHCONTENT_BASE_DIR}/implot3d-src/implot3d_items.cpp + ${FETCHCONTENT_BASE_DIR}/implot3d-src/implot3d_meshes.cpp +) +add_library(implot3d STATIC + ${IMPLOT3D_SOURCE} +) +target_include_directories(implot3d PUBLIC + $ + $ +) +target_link_libraries(implot3d PRIVATE glfw imgui) + +atta_add_include_dirs(${FETCHCONTENT_BASE_DIR}/implot3d-src) +atta_add_libs(implot3d) + +atta_log(Success Extern "ImPlot support (source)") +set(ATTA_IMPLOT3D_SUPPORT TRUE) +set(ATTA_IMPLOT3D_TARGETS implot3d) From e07a76e8180e0a1ec7d290ee261ede8c94403d4a Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Thu, 16 Jan 2025 19:45:03 +0100 Subject: [PATCH 13/37] Refactor(UI): ImGui style/colors --- src/atta/ui/manager.cpp | 44 ++++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/src/atta/ui/manager.cpp b/src/atta/ui/manager.cpp index 8491d3ff..50918c1e 100644 --- a/src/atta/ui/manager.cpp +++ b/src/atta/ui/manager.cpp @@ -94,23 +94,34 @@ void Manager::shutDownImpl() { } void Manager::setTheme() { - // Style ImGuiStyle& style = ImGui::GetStyle(); + + // Sizes main style.ScrollbarRounding = 0.0f; style.TabRounding = 0.0f; - style.DockingSeparatorSize = 1.0f; - style.WindowPadding = ImVec2(5.0f, 5.0f); - style.FramePadding = ImVec2(3.0f, 3.0f); + style.WindowPadding = ImVec2(8.0f, 5.0f); + style.FramePadding = ImVec2(4.0f, 3.0f); + style.ItemSpacing = ImVec2(5.0f, 4.0f); + style.ItemInnerSpacing = ImVec2(3.0f, 3.0f); + style.ScrollbarSize = 12.0f; style.GrabMinSize = 5.0f; + // Sizes borders + style.WindowBorderSize = 2.0f; style.TabBorderSize = 0.0f; - style.TabBarBorderSize = 0.0f; - style.SeparatorTextBorderSize = 1.0f; - style.SeparatorTextPadding = ImVec2(10.0f, 0.0f); - style.DisplaySafeAreaPadding = ImVec2(0.0f, 0.0f); - style.ScrollbarSize = 12.0f; + style.TabBarBorderSize = 2.0f; + style.TabBarOverlineSize = 0.0f; + // Sizes rounding style.FrameRounding = 5.0f; style.ScrollbarRounding = 5.0f; style.TabRounding = 5.0f; + // Sizes widgets + style.SeparatorTextBorderSize = 1.0f; + style.SeparatorTextAlign = ImVec2(0.5f, 0.5f); + style.SeparatorTextPadding = ImVec2(0.0f, 0.0f); + // Sizes docking + style.DockingSeparatorSize = 2.0f; + // Sizes misc + style.DisplaySafeAreaPadding = ImVec2(0.0f, 0.0f); // Colors ImVec4* colors = style.Colors; @@ -119,7 +130,7 @@ void Manager::setTheme() { colors[ImGuiCol_WindowBg] = ImVec4(0.10f, 0.10f, 0.10f, 1.00f); colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); colors[ImGuiCol_PopupBg] = ImVec4(0.09f, 0.09f, 0.09f, 0.98f); - colors[ImGuiCol_Border] = ImVec4(0.04f, 0.04f, 0.04f, 1.00f); + colors[ImGuiCol_Border] = ImVec4(0.0f, 0.0f, 0.0f, 1.00f); colors[ImGuiCol_BorderShadow] = ImVec4(0.04f, 0.04f, 0.04f, 1.00f); colors[ImGuiCol_FrameBg] = ImVec4(0.04f, 0.04f, 0.04f, 1.00f); colors[ImGuiCol_FrameBgHovered] = ImVec4(0.02f, 0.02f, 0.02f, 1.00f); @@ -138,7 +149,7 @@ void Manager::setTheme() { colors[ImGuiCol_Button] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f); colors[ImGuiCol_ButtonHovered] = ImVec4(0.18f, 0.18f, 0.18f, 1.00f); colors[ImGuiCol_ButtonActive] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f); - colors[ImGuiCol_Header] = ImVec4(0.10f, 0.10f, 0.10f, 1.00f); + colors[ImGuiCol_Header] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f); colors[ImGuiCol_HeaderHovered] = ImVec4(0.04f, 0.04f, 0.04f, 1.00f); colors[ImGuiCol_HeaderActive] = ImVec4(0.04f, 0.04f, 0.04f, 1.00f); colors[ImGuiCol_Separator] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); @@ -148,10 +159,11 @@ void Manager::setTheme() { colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f); colors[ImGuiCol_ResizeGripActive] = ImVec4(0.31f, 0.31f, 0.31f, 1.00f); colors[ImGuiCol_Tab] = ImVec4(0.06f, 0.06f, 0.06f, 1.00f); - colors[ImGuiCol_TabHovered] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f); - colors[ImGuiCol_TabActive] = ImVec4(0.10f, 0.10f, 0.10f, 1.00f); - colors[ImGuiCol_TabUnfocused] = ImVec4(0.10f, 0.10f, 0.10f, 1.00f); - colors[ImGuiCol_TabUnfocusedActive] = ImVec4(0.10f, 0.10f, 0.10f, 1.00f); + colors[ImGuiCol_TabHovered] = ImVec4(0.18f, 0.18f, 0.18f, 1.16f); + colors[ImGuiCol_TabSelected] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f); + colors[ImGuiCol_TabSelectedOverline] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); + colors[ImGuiCol_TabDimmed] = ImVec4(0.10f, 0.10f, 0.10f, 1.00f); + colors[ImGuiCol_TabDimmedSelected] = ImVec4(0.18f, 0.18f, 0.18f, 1.00f); colors[ImGuiCol_DockingPreview] = ImVec4(1.00f, 1.00f, 1.00f, 0.20f); colors[ImGuiCol_DockingEmptyBg] = ImVec4(1.00f, 1.00f, 1.00f, 0.20f); colors[ImGuiCol_PlotLines] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); @@ -163,7 +175,7 @@ void Manager::setTheme() { colors[ImGuiCol_TableRowBgAlt] = ImVec4(1.00f, 1.00f, 1.00f, 0.02f); colors[ImGuiCol_TextSelectedBg] = ImVec4(1.00f, 1.00f, 1.00f, 0.20f); colors[ImGuiCol_DragDropTarget] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f); - colors[ImGuiCol_NavHighlight] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f); + colors[ImGuiCol_NavCursor] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f); colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f); colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.80f, 0.80f, 0.80f, 0.20f); colors[ImGuiCol_ModalWindowDimBg] = ImVec4(1.00f, 1.00f, 1.00f, 0.08f); From af97896ac25574968d0f406af24afef0ae321133 Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Thu, 16 Jan 2025 19:46:43 +0100 Subject: [PATCH 14/37] Chore: Use ImPlot3D main branch --- src/extern/solveImplot3d.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extern/solveImplot3d.cmake b/src/extern/solveImplot3d.cmake index 6481cb3c..11098cc2 100644 --- a/src/extern/solveImplot3d.cmake +++ b/src/extern/solveImplot3d.cmake @@ -4,7 +4,7 @@ set(ATTA_IMPLOT3D_TARGETS "") FetchContent_Declare( implot3d GIT_REPOSITORY "https://github.com/brenocq/implot3d" - GIT_TAG "v0.1" + GIT_TAG "main" GIT_PROGRESS TRUE GIT_SHALLOW TRUE ) From 22cc26edb5d6b78478bd42ea7e587a950946de1d Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Thu, 16 Jan 2025 19:58:33 +0100 Subject: [PATCH 15/37] Refactor(UI): ImGui grab rounding --- src/atta/ui/manager.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/atta/ui/manager.cpp b/src/atta/ui/manager.cpp index 50918c1e..1af6defc 100644 --- a/src/atta/ui/manager.cpp +++ b/src/atta/ui/manager.cpp @@ -113,6 +113,7 @@ void Manager::setTheme() { // Sizes rounding style.FrameRounding = 5.0f; style.ScrollbarRounding = 5.0f; + style.GrabRounding = 5.0f; style.TabRounding = 5.0f; // Sizes widgets style.SeparatorTextBorderSize = 1.0f; From dee8723200813d6eff930f824423ecbdea2c1681 Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Sat, 18 Jan 2025 15:39:02 +0100 Subject: [PATCH 16/37] Chore: Fix web build --- .github/workflows/linux.yml | 2 +- .github/workflows/updateReadmeButtons.yml | 2 +- .github/workflows/web.yml | 2 +- src/extern/solveResources.cmake | 16 ++++++++-------- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml index da1cb9ae..b8a8ffa3 100644 --- a/.github/workflows/linux.yml +++ b/.github/workflows/linux.yml @@ -27,7 +27,7 @@ jobs: - name: Install dependencies run: | sudo apt-get update - sudo apt-get install cmake xorg-dev curl + sudo apt-get install cmake xorg-dev curl - name: Build run: ./build.sh --jobs 2 --compiler ${{ matrix.config.compiler }} diff --git a/.github/workflows/updateReadmeButtons.yml b/.github/workflows/updateReadmeButtons.yml index 78dacf8e..860251a1 100644 --- a/.github/workflows/updateReadmeButtons.yml +++ b/.github/workflows/updateReadmeButtons.yml @@ -1,6 +1,6 @@ name: Update readme buttons -on: +on: project_card: types: [created, deleted, moved] project: diff --git a/.github/workflows/web.yml b/.github/workflows/web.yml index 022d3400..1593ff7b 100644 --- a/.github/workflows/web.yml +++ b/.github/workflows/web.yml @@ -17,7 +17,7 @@ jobs: steps: - uses: mymindstorm/setup-emsdk@v13 - + - name: Checkout atta uses: actions/checkout@v2 diff --git a/src/extern/solveResources.cmake b/src/extern/solveResources.cmake index 0c280dd3..84478261 100644 --- a/src/extern/solveResources.cmake +++ b/src/extern/solveResources.cmake @@ -1,8 +1,8 @@ -#FetchContent_Declare(resources -# URL "https://atta-resources.s3.amazonaws.com/v0.3.1-ui-temp.zip" -# SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/resources -#) -# -#atta_log(Info Extern "Downloading resources...") -#FetchContent_Populate(resources) -#atta_log(Success Extern "Resources downloaded") +FetchContent_Declare(resources + URL "https://atta-resources.s3.amazonaws.com/v0.3.1-ui-temp.zip" + SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/resources +) + +atta_log(Info Extern "Downloading resources...") +FetchContent_Populate(resources) +atta_log(Success Extern "Resources downloaded") From a0b24672f1eadf36fec3b860e12ab7f953c7b009 Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Sat, 18 Jan 2025 16:38:55 +0100 Subject: [PATCH 17/37] Refactor: UI colors --- src/atta/ui/manager.cpp | 88 +++++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 38 deletions(-) diff --git a/src/atta/ui/manager.cpp b/src/atta/ui/manager.cpp index 1af6defc..c5ff4d44 100644 --- a/src/atta/ui/manager.cpp +++ b/src/atta/ui/manager.cpp @@ -106,15 +106,15 @@ void Manager::setTheme() { style.ScrollbarSize = 12.0f; style.GrabMinSize = 5.0f; // Sizes borders - style.WindowBorderSize = 2.0f; + style.WindowBorderSize = 1.0f; style.TabBorderSize = 0.0f; - style.TabBarBorderSize = 2.0f; + style.TabBarBorderSize = 1.0f; style.TabBarOverlineSize = 0.0f; // Sizes rounding - style.FrameRounding = 5.0f; - style.ScrollbarRounding = 5.0f; - style.GrabRounding = 5.0f; - style.TabRounding = 5.0f; + style.FrameRounding = 3.0f; + style.ScrollbarRounding = 3.0f; + style.GrabRounding = 3.0f; + style.TabRounding = 3.0f; // Sizes widgets style.SeparatorTextBorderSize = 1.0f; style.SeparatorTextAlign = ImVec2(0.5f, 0.5f); @@ -124,47 +124,59 @@ void Manager::setTheme() { // Sizes misc style.DisplaySafeAreaPadding = ImVec2(0.0f, 0.0f); + constexpr ImVec4 bg = ImVec4(0.20f, 0.20f, 0.20f, 1.0f); + constexpr ImVec4 titleActive = ImVec4(0.12f, 0.12f, 0.12f, 1.00f); + constexpr ImVec4 titleHovered = ImVec4(0.10f, 0.10f, 0.10f, 1.00f); + constexpr ImVec4 titleSelected = ImVec4(0.08f, 0.08f, 0.08f, 1.00f); + constexpr ImVec4 bgActive = ImVec4(0.14f, 0.14f, 0.14f, 1.00f); + constexpr ImVec4 bgHovered = ImVec4(0.12f, 0.12f, 0.12f, 1.00f); + constexpr ImVec4 bgSelected = ImVec4(0.10f, 0.10f, 0.10f, 1.00f); + constexpr ImVec4 disabled = ImVec4(0.15f, 0.15, 0.15f, 1.0f); + constexpr ImVec4 active = ImVec4(0.30f, 0.30f, 0.30f, 1.0f); + constexpr ImVec4 hovered = ImVec4(0.35f, 0.35f, 0.35f, 1.0f); + constexpr ImVec4 selected = ImVec4(0.40f, 0.40f, 0.40f, 1.0f); + // Colors ImVec4* colors = style.Colors; colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f); colors[ImGuiCol_TextDisabled] = ImVec4(0.50f, 0.50f, 0.50f, 1.00f); - colors[ImGuiCol_WindowBg] = ImVec4(0.10f, 0.10f, 0.10f, 1.00f); + colors[ImGuiCol_WindowBg] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f); colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); - colors[ImGuiCol_PopupBg] = ImVec4(0.09f, 0.09f, 0.09f, 0.98f); + colors[ImGuiCol_PopupBg] = ImVec4(0.20f, 0.20f, 0.20f, 0.98f); colors[ImGuiCol_Border] = ImVec4(0.0f, 0.0f, 0.0f, 1.00f); colors[ImGuiCol_BorderShadow] = ImVec4(0.04f, 0.04f, 0.04f, 1.00f); - colors[ImGuiCol_FrameBg] = ImVec4(0.04f, 0.04f, 0.04f, 1.00f); - colors[ImGuiCol_FrameBgHovered] = ImVec4(0.02f, 0.02f, 0.02f, 1.00f); - colors[ImGuiCol_FrameBgActive] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); - colors[ImGuiCol_TitleBg] = ImVec4(0.04f, 0.04f, 0.04f, 1.00f); - colors[ImGuiCol_TitleBgActive] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); - colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.04f, 0.04f, 0.04f, 1.00f); - colors[ImGuiCol_MenuBarBg] = ImVec4(0.04f, 0.04f, 0.04f, 1.00f); - colors[ImGuiCol_ScrollbarBg] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); - colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.10f, 0.10f, 0.10f, 1.00f); - colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f); - colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f); + colors[ImGuiCol_FrameBg] = bgActive; + colors[ImGuiCol_FrameBgHovered] = bgHovered; + colors[ImGuiCol_FrameBgActive] = bgSelected; + colors[ImGuiCol_TitleBg] = titleActive; + colors[ImGuiCol_TitleBgActive] = titleSelected; + colors[ImGuiCol_TitleBgCollapsed] = titleActive; + colors[ImGuiCol_MenuBarBg] = active; + colors[ImGuiCol_ScrollbarBg] = bg; + colors[ImGuiCol_ScrollbarGrab] = active; + colors[ImGuiCol_ScrollbarGrabHovered] = hovered; + colors[ImGuiCol_ScrollbarGrabActive] = selected; colors[ImGuiCol_CheckMark] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f); - colors[ImGuiCol_SliderGrab] = ImVec4(0.39f, 0.39f, 0.39f, 1.00f); - colors[ImGuiCol_SliderGrabActive] = ImVec4(0.43f, 0.43f, 0.43f, 1.00f); - colors[ImGuiCol_Button] = ImVec4(0.16f, 0.16f, 0.16f, 1.00f); - colors[ImGuiCol_ButtonHovered] = ImVec4(0.18f, 0.18f, 0.18f, 1.00f); - colors[ImGuiCol_ButtonActive] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f); - colors[ImGuiCol_Header] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f); - colors[ImGuiCol_HeaderHovered] = ImVec4(0.04f, 0.04f, 0.04f, 1.00f); - colors[ImGuiCol_HeaderActive] = ImVec4(0.04f, 0.04f, 0.04f, 1.00f); - colors[ImGuiCol_Separator] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); - colors[ImGuiCol_SeparatorHovered] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f); - colors[ImGuiCol_SeparatorActive] = ImVec4(0.31f, 0.31f, 0.31f, 1.00f); - colors[ImGuiCol_ResizeGrip] = ImVec4(0.00f, 0.00f, 0.00f, 0.39f); - colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.27f, 0.27f, 0.27f, 1.00f); - colors[ImGuiCol_ResizeGripActive] = ImVec4(0.31f, 0.31f, 0.31f, 1.00f); - colors[ImGuiCol_Tab] = ImVec4(0.06f, 0.06f, 0.06f, 1.00f); - colors[ImGuiCol_TabHovered] = ImVec4(0.18f, 0.18f, 0.18f, 1.16f); - colors[ImGuiCol_TabSelected] = ImVec4(0.20f, 0.20f, 0.20f, 1.00f); + colors[ImGuiCol_SliderGrab] = active; + colors[ImGuiCol_SliderGrabActive] = selected; + colors[ImGuiCol_Button] = active; + colors[ImGuiCol_ButtonHovered] = hovered; + colors[ImGuiCol_ButtonActive] = selected; + colors[ImGuiCol_Header] = bgActive; + colors[ImGuiCol_HeaderHovered] = bgHovered; + colors[ImGuiCol_HeaderActive] = bgSelected; + colors[ImGuiCol_Separator] = active; + colors[ImGuiCol_SeparatorHovered] = hovered; + colors[ImGuiCol_SeparatorActive] = selected; + colors[ImGuiCol_ResizeGrip] = active; + colors[ImGuiCol_ResizeGripHovered] = hovered; + colors[ImGuiCol_ResizeGripActive] = selected; + colors[ImGuiCol_Tab] = disabled; + colors[ImGuiCol_TabHovered] = hovered; + colors[ImGuiCol_TabSelected] = selected; colors[ImGuiCol_TabSelectedOverline] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f); - colors[ImGuiCol_TabDimmed] = ImVec4(0.10f, 0.10f, 0.10f, 1.00f); - colors[ImGuiCol_TabDimmedSelected] = ImVec4(0.18f, 0.18f, 0.18f, 1.00f); + colors[ImGuiCol_TabDimmed] = disabled; + colors[ImGuiCol_TabDimmedSelected] = selected; colors[ImGuiCol_DockingPreview] = ImVec4(1.00f, 1.00f, 1.00f, 0.20f); colors[ImGuiCol_DockingEmptyBg] = ImVec4(1.00f, 1.00f, 1.00f, 0.20f); colors[ImGuiCol_PlotLines] = ImVec4(0.00f, 0.00f, 0.00f, 1.00f); From 674a8bcf61b3f5b6b1e60a1c081063642477503d Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Sat, 18 Jan 2025 16:52:50 +0100 Subject: [PATCH 18/37] Chore: Move editor and widgets files --- src/atta/ui/CMakeLists.txt | 12 ++++++------ src/atta/ui/{editor => }/editor.cpp | 2 +- src/atta/ui/{editor => }/editor.h | 0 src/atta/ui/editor/toolBar/toolBar.cpp | 2 +- .../tools/timeProfiler/components/tearDown.cpp | 2 +- .../editor/tools/timeProfiler/timeProfilerWindow.cpp | 2 +- src/atta/ui/editor/topBar/topBar.cpp | 6 +++--- src/atta/ui/manager.h | 2 +- src/atta/ui/{editor => }/widgets/align.cpp | 2 +- src/atta/ui/{editor => }/widgets/align.h | 0 src/atta/ui/{editor => }/widgets/button.cpp | 2 +- src/atta/ui/{editor => }/widgets/button.h | 0 src/atta/ui/{editor => }/widgets/gizmo.cpp | 2 +- src/atta/ui/{editor => }/widgets/gizmo.h | 0 src/atta/ui/{editor => }/widgets/help.cpp | 2 +- src/atta/ui/{editor => }/widgets/help.h | 0 src/atta/ui/{editor => }/widgets/image.cpp | 2 +- src/atta/ui/{editor => }/widgets/image.h | 0 18 files changed, 19 insertions(+), 19 deletions(-) rename src/atta/ui/{editor => }/editor.cpp (98%) rename src/atta/ui/{editor => }/editor.h (100%) rename src/atta/ui/{editor => }/widgets/align.cpp (92%) rename src/atta/ui/{editor => }/widgets/align.h (100%) rename src/atta/ui/{editor => }/widgets/button.cpp (91%) rename src/atta/ui/{editor => }/widgets/button.h (100%) rename src/atta/ui/{editor => }/widgets/gizmo.cpp (99%) rename src/atta/ui/{editor => }/widgets/gizmo.h (100%) rename src/atta/ui/{editor => }/widgets/help.cpp (93%) rename src/atta/ui/{editor => }/widgets/help.h (100%) rename src/atta/ui/{editor => }/widgets/image.cpp (90%) rename src/atta/ui/{editor => }/widgets/image.h (100%) diff --git a/src/atta/ui/CMakeLists.txt b/src/atta/ui/CMakeLists.txt index 03fcf927..bcbb1338 100644 --- a/src/atta/ui/CMakeLists.txt +++ b/src/atta/ui/CMakeLists.txt @@ -3,16 +3,16 @@ cmake_minimum_required(VERSION 3.14) set(ATTA_UI_MODULE_SOURCE interface.cpp manager.cpp + editor.cpp + + widgets/align.cpp + widgets/button.cpp + widgets/help.cpp + widgets/image.cpp - editor/editor.cpp editor/dockSpace.cpp editor/window.cpp - editor/widgets/align.cpp - editor/widgets/button.cpp - editor/widgets/help.cpp - editor/widgets/image.cpp - editor/topBar/topBar.cpp editor/toolBar/toolBar.cpp editor/topBar/localWindows/repoWindow.cpp diff --git a/src/atta/ui/editor/editor.cpp b/src/atta/ui/editor.cpp similarity index 98% rename from src/atta/ui/editor/editor.cpp rename to src/atta/ui/editor.cpp index 91eea24b..1e0a5b5f 100644 --- a/src/atta/ui/editor/editor.cpp +++ b/src/atta/ui/editor.cpp @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/atta/ui/editor/editor.h b/src/atta/ui/editor.h similarity index 100% rename from src/atta/ui/editor/editor.h rename to src/atta/ui/editor.h diff --git a/src/atta/ui/editor/toolBar/toolBar.cpp b/src/atta/ui/editor/toolBar/toolBar.cpp index 3f414633..a35c6128 100644 --- a/src/atta/ui/editor/toolBar/toolBar.cpp +++ b/src/atta/ui/editor/toolBar/toolBar.cpp @@ -12,7 +12,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/atta/ui/editor/tools/timeProfiler/components/tearDown.cpp b/src/atta/ui/editor/tools/timeProfiler/components/tearDown.cpp index fe5f3c56..b1a7b6cd 100644 --- a/src/atta/ui/editor/tools/timeProfiler/components/tearDown.cpp +++ b/src/atta/ui/editor/tools/timeProfiler/components/tearDown.cpp @@ -6,7 +6,7 @@ //-------------------------------------------------- #include -#include +#include #include "imgui.h" diff --git a/src/atta/ui/editor/tools/timeProfiler/timeProfilerWindow.cpp b/src/atta/ui/editor/tools/timeProfiler/timeProfilerWindow.cpp index ec45fae8..16ca658f 100644 --- a/src/atta/ui/editor/tools/timeProfiler/timeProfilerWindow.cpp +++ b/src/atta/ui/editor/tools/timeProfiler/timeProfilerWindow.cpp @@ -5,7 +5,7 @@ // By Breno Cunha Queiroz //-------------------------------------------------- #include -#include +#include namespace atta::ui { diff --git a/src/atta/ui/editor/topBar/topBar.cpp b/src/atta/ui/editor/topBar/topBar.cpp index 10d020f8..4791e695 100644 --- a/src/atta/ui/editor/topBar/topBar.cpp +++ b/src/atta/ui/editor/topBar/topBar.cpp @@ -7,9 +7,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include #include diff --git a/src/atta/ui/manager.h b/src/atta/ui/manager.h index 8531fb11..233d5b82 100644 --- a/src/atta/ui/manager.h +++ b/src/atta/ui/manager.h @@ -8,7 +8,7 @@ #define ATTA_UI_MANAGER_H #include -#include +#include namespace atta::ui { diff --git a/src/atta/ui/editor/widgets/align.cpp b/src/atta/ui/widgets/align.cpp similarity index 92% rename from src/atta/ui/editor/widgets/align.cpp rename to src/atta/ui/widgets/align.cpp index 48a7cc94..2023e318 100644 --- a/src/atta/ui/editor/widgets/align.cpp +++ b/src/atta/ui/widgets/align.cpp @@ -4,7 +4,7 @@ // Date: 2024-01-03 // By Breno Cunha Queiroz //-------------------------------------------------- -#include +#include #include "imgui.h" diff --git a/src/atta/ui/editor/widgets/align.h b/src/atta/ui/widgets/align.h similarity index 100% rename from src/atta/ui/editor/widgets/align.h rename to src/atta/ui/widgets/align.h diff --git a/src/atta/ui/editor/widgets/button.cpp b/src/atta/ui/widgets/button.cpp similarity index 91% rename from src/atta/ui/editor/widgets/button.cpp rename to src/atta/ui/widgets/button.cpp index d7c39c27..affc6805 100644 --- a/src/atta/ui/editor/widgets/button.cpp +++ b/src/atta/ui/widgets/button.cpp @@ -4,7 +4,7 @@ // Date: 2022-10-24 // By Breno Cunha Queiroz //-------------------------------------------------- -#include +#include #include "imgui.h" #include diff --git a/src/atta/ui/editor/widgets/button.h b/src/atta/ui/widgets/button.h similarity index 100% rename from src/atta/ui/editor/widgets/button.h rename to src/atta/ui/widgets/button.h diff --git a/src/atta/ui/editor/widgets/gizmo.cpp b/src/atta/ui/widgets/gizmo.cpp similarity index 99% rename from src/atta/ui/editor/widgets/gizmo.cpp rename to src/atta/ui/widgets/gizmo.cpp index 9a2998a6..aeff0b0f 100644 --- a/src/atta/ui/editor/widgets/gizmo.cpp +++ b/src/atta/ui/widgets/gizmo.cpp @@ -4,7 +4,7 @@ // Date: 2024-01-05 // By Breno Cunha Queiroz //-------------------------------------------------- -#include +#include #include #include diff --git a/src/atta/ui/editor/widgets/gizmo.h b/src/atta/ui/widgets/gizmo.h similarity index 100% rename from src/atta/ui/editor/widgets/gizmo.h rename to src/atta/ui/widgets/gizmo.h diff --git a/src/atta/ui/editor/widgets/help.cpp b/src/atta/ui/widgets/help.cpp similarity index 93% rename from src/atta/ui/editor/widgets/help.cpp rename to src/atta/ui/widgets/help.cpp index ae56fb74..ca2643f4 100644 --- a/src/atta/ui/editor/widgets/help.cpp +++ b/src/atta/ui/widgets/help.cpp @@ -4,7 +4,7 @@ // Date: 2022-10-24 // By Breno Cunha Queiroz //-------------------------------------------------- -#include +#include #include "imgui.h" diff --git a/src/atta/ui/editor/widgets/help.h b/src/atta/ui/widgets/help.h similarity index 100% rename from src/atta/ui/editor/widgets/help.h rename to src/atta/ui/widgets/help.h diff --git a/src/atta/ui/editor/widgets/image.cpp b/src/atta/ui/widgets/image.cpp similarity index 90% rename from src/atta/ui/editor/widgets/image.cpp rename to src/atta/ui/widgets/image.cpp index 20683dd8..5f44fb9b 100644 --- a/src/atta/ui/editor/widgets/image.cpp +++ b/src/atta/ui/widgets/image.cpp @@ -5,7 +5,7 @@ // By Breno Cunha Queiroz //-------------------------------------------------- #include -#include +#include #include "imgui.h" diff --git a/src/atta/ui/editor/widgets/image.h b/src/atta/ui/widgets/image.h similarity index 100% rename from src/atta/ui/editor/widgets/image.h rename to src/atta/ui/widgets/image.h From 9fb1abc3e5ddf10b6f76daf69134f888df639f89 Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Sat, 18 Jan 2025 16:59:35 +0100 Subject: [PATCH 19/37] Chore: Move windows files --- src/atta/ui/CMakeLists.txt | 8 ++++---- src/atta/ui/editor.cpp | 2 +- src/atta/ui/editor.h | 12 ++++++------ src/atta/ui/editor/topBar/topBar.cpp | 2 +- src/atta/ui/widgets/align.h | 4 ++++ src/atta/ui/widgets/button.h | 4 ++++ src/atta/ui/widgets/gizmo.h | 5 +++++ src/atta/ui/widgets/help.h | 4 ++++ src/atta/ui/widgets/image.h | 4 ++++ src/atta/ui/{editor => }/windows/entityWindow.cpp | 2 +- src/atta/ui/{editor => }/windows/entityWindow.h | 6 +++--- src/atta/ui/{editor => }/windows/logWindow.cpp | 2 +- src/atta/ui/{editor => }/windows/logWindow.h | 6 +++--- .../windows/utils/fileSelectionWindow.cpp | 2 +- .../{editor => }/windows/utils/fileSelectionWindow.h | 6 +++--- src/atta/ui/{editor => }/windows/viewportWindows.cpp | 2 +- src/atta/ui/{editor => }/windows/viewportWindows.h | 6 +++--- 17 files changed, 49 insertions(+), 28 deletions(-) rename src/atta/ui/{editor => }/windows/entityWindow.cpp (99%) rename src/atta/ui/{editor => }/windows/entityWindow.h (82%) rename src/atta/ui/{editor => }/windows/logWindow.cpp (88%) rename src/atta/ui/{editor => }/windows/logWindow.h (67%) rename src/atta/ui/{editor => }/windows/utils/fileSelectionWindow.cpp (98%) rename src/atta/ui/{editor => }/windows/utils/fileSelectionWindow.h (79%) rename src/atta/ui/{editor => }/windows/viewportWindows.cpp (99%) rename src/atta/ui/{editor => }/windows/viewportWindows.h (71%) diff --git a/src/atta/ui/CMakeLists.txt b/src/atta/ui/CMakeLists.txt index bcbb1338..c0c85e7e 100644 --- a/src/atta/ui/CMakeLists.txt +++ b/src/atta/ui/CMakeLists.txt @@ -18,10 +18,10 @@ set(ATTA_UI_MODULE_SOURCE editor/topBar/localWindows/repoWindow.cpp editor/topBar/localWindows/versionWindow.cpp - editor/windows/entityWindow.cpp - editor/windows/logWindow.cpp - editor/windows/viewportWindows.cpp - editor/windows/utils/fileSelectionWindow.cpp + windows/entityWindow.cpp + windows/logWindow.cpp + windows/viewportWindows.cpp + windows/utils/fileSelectionWindow.cpp editor/moduleWindows/graphicsModuleWindow.cpp editor/moduleWindows/ioModuleWindow.cpp diff --git a/src/atta/ui/editor.cpp b/src/atta/ui/editor.cpp index 1e0a5b5f..e47c1913 100644 --- a/src/atta/ui/editor.cpp +++ b/src/atta/ui/editor.cpp @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/atta/ui/editor.h b/src/atta/ui/editor.h index cec5a0e4..8dd45052 100644 --- a/src/atta/ui/editor.h +++ b/src/atta/ui/editor.h @@ -4,8 +4,8 @@ // Date: 2021-09-01 // By Breno Cunha Queiroz //-------------------------------------------------- -#ifndef ATTA_UI_EDITOR_EDITOR_H -#define ATTA_UI_EDITOR_EDITOR_H +#ifndef ATTA_UI_EDITOR_H +#define ATTA_UI_EDITOR_H #include #include @@ -13,9 +13,9 @@ #include #include #include -#include -#include -#include +#include +#include +#include namespace atta::ui { @@ -40,4 +40,4 @@ class Editor final { } // namespace atta::ui -#endif // ATTA_UI_EDITOR_EDITOR_H +#endif // ATTA_UI_EDITOR_H diff --git a/src/atta/ui/editor/topBar/topBar.cpp b/src/atta/ui/editor/topBar/topBar.cpp index 4791e695..667aa9b6 100644 --- a/src/atta/ui/editor/topBar/topBar.cpp +++ b/src/atta/ui/editor/topBar/topBar.cpp @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include diff --git a/src/atta/ui/widgets/align.h b/src/atta/ui/widgets/align.h index 713c1c98..fa34b876 100644 --- a/src/atta/ui/widgets/align.h +++ b/src/atta/ui/widgets/align.h @@ -4,9 +4,13 @@ // Date: 2024-01-03 // By Breno Cunha Queiroz //-------------------------------------------------- +#ifndef ATTA_UI_WIDGETS_ALIGN_H +#define ATTA_UI_WIDGETS_ALIGN_H namespace atta::ui { void verticalAlign(float height, std::function func); } // namespace atta::ui + +#endif // ATTA_UI_WIDGETS_ALIGN_H diff --git a/src/atta/ui/widgets/button.h b/src/atta/ui/widgets/button.h index 7f40ffba..10eef9c1 100644 --- a/src/atta/ui/widgets/button.h +++ b/src/atta/ui/widgets/button.h @@ -4,9 +4,13 @@ // Date: 2022-10-24 // By Breno Cunha Queiroz //-------------------------------------------------- +#ifndef ATTA_UI_WIDGETS_BUTTON_H +#define ATTA_UI_WIDGETS_BUTTON_H namespace atta::ui { bool imageButton(std::string name, float size); } // namespace atta::ui + +#endif // ATTA_UI_WIDGETS_BUTTON_H diff --git a/src/atta/ui/widgets/gizmo.h b/src/atta/ui/widgets/gizmo.h index 8df3f717..5ac81562 100644 --- a/src/atta/ui/widgets/gizmo.h +++ b/src/atta/ui/widgets/gizmo.h @@ -4,6 +4,9 @@ // Date: 2024-01-05 // By Breno Cunha Queiroz //-------------------------------------------------- +#ifndef ATTA_UI_WIDGETS_GUIZMO_H +#define ATTA_UI_WIDGETS_GUIZMO_H + #include #include @@ -36,3 +39,5 @@ class Gizmo { }; } // namespace atta::ui + +#endif // ATTA_UI_WIDGETS_GUIZMO_H diff --git a/src/atta/ui/widgets/help.h b/src/atta/ui/widgets/help.h index b8bc531c..1907695e 100644 --- a/src/atta/ui/widgets/help.h +++ b/src/atta/ui/widgets/help.h @@ -4,9 +4,13 @@ // Date: 2022-10-29 // By Breno Cunha Queiroz //-------------------------------------------------- +#ifndef ATTA_UI_WIDGETS_HELP_H +#define ATTA_UI_WIDGETS_HELP_H namespace atta::ui { void help(std::string text); } // namespace atta::ui + +#endif // ATTA_UI_WIDGETS_HELP_H diff --git a/src/atta/ui/widgets/image.h b/src/atta/ui/widgets/image.h index a1976783..4d1a7ff6 100644 --- a/src/atta/ui/widgets/image.h +++ b/src/atta/ui/widgets/image.h @@ -4,9 +4,13 @@ // Date: 2024-01-03 // By Breno Cunha Queiroz //-------------------------------------------------- +#ifndef ATTA_UI_WIDGETS_IMAGE_H +#define ATTA_UI_WIDGETS_IMAGE_H namespace atta::ui { void image(std::string name, vec2 size); } // namespace atta::ui + +#endif// ATTA_UI_WIDGETS_IMAGE_H diff --git a/src/atta/ui/editor/windows/entityWindow.cpp b/src/atta/ui/windows/entityWindow.cpp similarity index 99% rename from src/atta/ui/editor/windows/entityWindow.cpp rename to src/atta/ui/windows/entityWindow.cpp index 26711ce6..88236631 100644 --- a/src/atta/ui/editor/windows/entityWindow.cpp +++ b/src/atta/ui/windows/entityWindow.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include namespace atta::ui { diff --git a/src/atta/ui/editor/windows/entityWindow.h b/src/atta/ui/windows/entityWindow.h similarity index 82% rename from src/atta/ui/editor/windows/entityWindow.h rename to src/atta/ui/windows/entityWindow.h index eb84cbc0..ad3e14d3 100644 --- a/src/atta/ui/editor/windows/entityWindow.h +++ b/src/atta/ui/windows/entityWindow.h @@ -4,8 +4,8 @@ // Date: 2021-09-02 // By Breno Cunha Queiroz //-------------------------------------------------- -#ifndef ATTA_UI_EDITOR_WINDOWS_ENTITY_WINDOW_H -#define ATTA_UI_EDITOR_WINDOWS_ENTITY_WINDOW_H +#ifndef ATTA_UI_WINDOWS_ENTITY_WINDOW_H +#define ATTA_UI_WINDOWS_ENTITY_WINDOW_H #include @@ -31,4 +31,4 @@ class EntityWindow { } // namespace atta::ui -#endif // ATTA_UI_EDITOR_WINDOWS_ENTITY_WINDOW_H +#endif // ATTA_UI_WINDOWS_ENTITY_WINDOW_H diff --git a/src/atta/ui/editor/windows/logWindow.cpp b/src/atta/ui/windows/logWindow.cpp similarity index 88% rename from src/atta/ui/editor/windows/logWindow.cpp rename to src/atta/ui/windows/logWindow.cpp index 870ab41d..a6ca65ba 100644 --- a/src/atta/ui/editor/windows/logWindow.cpp +++ b/src/atta/ui/windows/logWindow.cpp @@ -4,7 +4,7 @@ // Date: 2021-12-28 // By Breno Cunha Queiroz //-------------------------------------------------- -#include +#include #include #include diff --git a/src/atta/ui/editor/windows/logWindow.h b/src/atta/ui/windows/logWindow.h similarity index 67% rename from src/atta/ui/editor/windows/logWindow.h rename to src/atta/ui/windows/logWindow.h index d414b8ed..982df838 100644 --- a/src/atta/ui/editor/windows/logWindow.h +++ b/src/atta/ui/windows/logWindow.h @@ -4,8 +4,8 @@ // Date: 2021-12-28 // By Breno Cunha Queiroz //-------------------------------------------------- -#ifndef ATTA_UI_EDITOR_WINDOWS_LOG_WINDOW_H -#define ATTA_UI_EDITOR_WINDOWS_LOG_WINDOW_H +#ifndef ATTA_UI_WINDOWS_LOG_WINDOW_H +#define ATTA_UI_WINDOWS_LOG_WINDOW_H namespace atta::ui { @@ -16,4 +16,4 @@ class LogWindow { } // namespace atta::ui -#endif // ATTA_UI_EDITOR_WINDOWS_LOG_WINDOW_H +#endif // ATTA_UI_WINDOWS_LOG_WINDOW_H diff --git a/src/atta/ui/editor/windows/utils/fileSelectionWindow.cpp b/src/atta/ui/windows/utils/fileSelectionWindow.cpp similarity index 98% rename from src/atta/ui/editor/windows/utils/fileSelectionWindow.cpp rename to src/atta/ui/windows/utils/fileSelectionWindow.cpp index 2305a33a..586b80ca 100644 --- a/src/atta/ui/editor/windows/utils/fileSelectionWindow.cpp +++ b/src/atta/ui/windows/utils/fileSelectionWindow.cpp @@ -4,7 +4,7 @@ // Date: 2022-01-24 // By Breno Cunha Queiroz //-------------------------------------------------- -#include +#include namespace atta::ui { diff --git a/src/atta/ui/editor/windows/utils/fileSelectionWindow.h b/src/atta/ui/windows/utils/fileSelectionWindow.h similarity index 79% rename from src/atta/ui/editor/windows/utils/fileSelectionWindow.h rename to src/atta/ui/windows/utils/fileSelectionWindow.h index 85f8ed3e..12c8cabe 100644 --- a/src/atta/ui/editor/windows/utils/fileSelectionWindow.h +++ b/src/atta/ui/windows/utils/fileSelectionWindow.h @@ -4,8 +4,8 @@ // Date: 2022-01-24 // By Breno Cunha Queiroz //-------------------------------------------------- -#ifndef ATTA_UI_EDITOR_WINDOWS_UTILS_FILE_SELECTION_WINDOW_H -#define ATTA_UI_EDITOR_WINDOWS_UTILS_FILE_SELECTION_WINDOW_H +#ifndef ATTA_UI_WINDOWS_UTILS_FILE_SELECTION_WINDOW_H +#define ATTA_UI_WINDOWS_UTILS_FILE_SELECTION_WINDOW_H #include @@ -34,4 +34,4 @@ class FileSelectionWindow : public Window { } // namespace atta::ui -#endif // ATTA_UI_EDITOR_WINDOWS_UTILS_FILE_SELECTION_WINDOW_H +#endif // ATTA_UI_WINDOWS_UTILS_FILE_SELECTION_WINDOW_H diff --git a/src/atta/ui/editor/windows/viewportWindows.cpp b/src/atta/ui/windows/viewportWindows.cpp similarity index 99% rename from src/atta/ui/editor/windows/viewportWindows.cpp rename to src/atta/ui/windows/viewportWindows.cpp index 650a157b..152104df 100644 --- a/src/atta/ui/editor/windows/viewportWindows.cpp +++ b/src/atta/ui/windows/viewportWindows.cpp @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include diff --git a/src/atta/ui/editor/windows/viewportWindows.h b/src/atta/ui/windows/viewportWindows.h similarity index 71% rename from src/atta/ui/editor/windows/viewportWindows.h rename to src/atta/ui/windows/viewportWindows.h index cda25a3f..3fd2ca09 100644 --- a/src/atta/ui/editor/windows/viewportWindows.h +++ b/src/atta/ui/windows/viewportWindows.h @@ -4,8 +4,8 @@ // Date: 2021-12-28 // By Breno Cunha Queiroz //-------------------------------------------------- -#ifndef ATTA_UI_EDITOR_WINDOWS_VIEWPORT_WINDOWS_H -#define ATTA_UI_EDITOR_WINDOWS_VIEWPORT_WINDOWS_H +#ifndef ATTA_UI_WINDOWS_VIEWPORT_WINDOWS_H +#define ATTA_UI_WINDOWS_VIEWPORT_WINDOWS_H #include @@ -21,4 +21,4 @@ class ViewportWindows { } // namespace atta::ui -#endif // ATTA_UI_EDITOR_WINDOWS_VIEWPORT_WINDOWS_H +#endif // ATTA_UI_WINDOWS_VIEWPORT_WINDOWS_H From de0611e8d6c506b79e345d2be61f3d42ae439f08 Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Sat, 18 Jan 2025 17:04:59 +0100 Subject: [PATCH 20/37] Chore: Move module windows files --- src/atta/ui/CMakeLists.txt | 11 +++++------ src/atta/ui/editor.cpp | 8 ++++---- src/atta/ui/editor/topBar/topBar.cpp | 8 ++++---- .../graphicsModuleWindow.cpp | 2 +- .../moduleWindows => windows}/graphicsModuleWindow.h | 6 +++--- .../moduleWindows => windows}/ioModuleWindow.cpp | 8 ++++---- .../moduleWindows => windows}/ioModuleWindow.h | 6 +++--- .../ioModuleWindowBluetooth.cpp | 0 .../ioModuleWindowCamera.cpp | 0 .../ioModuleWindowSerial.cpp | 0 .../moduleWindows => windows}/physicsModuleWindow.cpp | 2 +- .../moduleWindows => windows}/physicsModuleWindow.h | 6 +++--- .../moduleWindows => windows}/sensorModuleWindow.cpp | 2 +- .../moduleWindows => windows}/sensorModuleWindow.h | 6 +++--- 14 files changed, 32 insertions(+), 33 deletions(-) rename src/atta/ui/{editor/moduleWindows => windows}/graphicsModuleWindow.cpp (95%) rename src/atta/ui/{editor/moduleWindows => windows}/graphicsModuleWindow.h (74%) rename src/atta/ui/{editor/moduleWindows => windows}/ioModuleWindow.cpp (79%) rename src/atta/ui/{editor/moduleWindows => windows}/ioModuleWindow.h (90%) rename src/atta/ui/{editor/moduleWindows => windows}/ioModuleWindowBluetooth.cpp (100%) rename src/atta/ui/{editor/moduleWindows => windows}/ioModuleWindowCamera.cpp (100%) rename src/atta/ui/{editor/moduleWindows => windows}/ioModuleWindowSerial.cpp (100%) rename src/atta/ui/{editor/moduleWindows => windows}/physicsModuleWindow.cpp (98%) rename src/atta/ui/{editor/moduleWindows => windows}/physicsModuleWindow.h (74%) rename src/atta/ui/{editor/moduleWindows => windows}/sensorModuleWindow.cpp (92%) rename src/atta/ui/{editor/moduleWindows => windows}/sensorModuleWindow.h (74%) diff --git a/src/atta/ui/CMakeLists.txt b/src/atta/ui/CMakeLists.txt index c0c85e7e..aa034f6c 100644 --- a/src/atta/ui/CMakeLists.txt +++ b/src/atta/ui/CMakeLists.txt @@ -18,15 +18,14 @@ set(ATTA_UI_MODULE_SOURCE editor/topBar/localWindows/repoWindow.cpp editor/topBar/localWindows/versionWindow.cpp + windows/utils/fileSelectionWindow.cpp windows/entityWindow.cpp + windows/graphicsModuleWindow.cpp + windows/ioModuleWindow.cpp windows/logWindow.cpp + windows/physicsModuleWindow.cpp + windows/sensorModuleWindow.cpp windows/viewportWindows.cpp - windows/utils/fileSelectionWindow.cpp - - editor/moduleWindows/graphicsModuleWindow.cpp - editor/moduleWindows/ioModuleWindow.cpp - editor/moduleWindows/physicsModuleWindow.cpp - editor/moduleWindows/sensorModuleWindow.cpp editor/tools/timeProfiler/timeProfilerWindow.cpp editor/tools/timeProfiler/components/tearDown.cpp diff --git a/src/atta/ui/editor.cpp b/src/atta/ui/editor.cpp index e47c1913..7af1177b 100644 --- a/src/atta/ui/editor.cpp +++ b/src/atta/ui/editor.cpp @@ -12,12 +12,12 @@ #include #include -#include -#include -#include -#include #include #include +#include +#include +#include +#include #include #include diff --git a/src/atta/ui/editor/topBar/topBar.cpp b/src/atta/ui/editor/topBar/topBar.cpp index 667aa9b6..32fd4378 100644 --- a/src/atta/ui/editor/topBar/topBar.cpp +++ b/src/atta/ui/editor/topBar/topBar.cpp @@ -22,10 +22,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include #include diff --git a/src/atta/ui/editor/moduleWindows/graphicsModuleWindow.cpp b/src/atta/ui/windows/graphicsModuleWindow.cpp similarity index 95% rename from src/atta/ui/editor/moduleWindows/graphicsModuleWindow.cpp rename to src/atta/ui/windows/graphicsModuleWindow.cpp index e72e13d2..4c873c60 100644 --- a/src/atta/ui/editor/moduleWindows/graphicsModuleWindow.cpp +++ b/src/atta/ui/windows/graphicsModuleWindow.cpp @@ -4,7 +4,7 @@ // Date: 2022-10-16 // By Breno Cunha Queiroz //-------------------------------------------------- -#include +#include #include diff --git a/src/atta/ui/editor/moduleWindows/graphicsModuleWindow.h b/src/atta/ui/windows/graphicsModuleWindow.h similarity index 74% rename from src/atta/ui/editor/moduleWindows/graphicsModuleWindow.h rename to src/atta/ui/windows/graphicsModuleWindow.h index 1adf2720..b4e60c10 100644 --- a/src/atta/ui/editor/moduleWindows/graphicsModuleWindow.h +++ b/src/atta/ui/windows/graphicsModuleWindow.h @@ -4,8 +4,8 @@ // Date: 2022-10-16 // By Breno Cunha Queiroz //-------------------------------------------------- -#ifndef ATTA_UI_EDITOR_WINDOWS_GRAPHICS_MODULE_WINDOW_H -#define ATTA_UI_EDITOR_WINDOWS_GRAPHICS_MODULE_WINDOW_H +#ifndef ATTA_UI_WINDOWS_GRAPHICS_MODULE_WINDOW_H +#define ATTA_UI_WINDOWS_GRAPHICS_MODULE_WINDOW_H #include #include @@ -22,4 +22,4 @@ class GraphicsModuleWindow : public Window { } // namespace atta::ui -#endif // ATTA_UI_EDITOR_WINDOWS_GRAPHICS_MODULE_WINDOW_H +#endif // ATTA_UI_WINDOWS_GRAPHICS_MODULE_WINDOW_H diff --git a/src/atta/ui/editor/moduleWindows/ioModuleWindow.cpp b/src/atta/ui/windows/ioModuleWindow.cpp similarity index 79% rename from src/atta/ui/editor/moduleWindows/ioModuleWindow.cpp rename to src/atta/ui/windows/ioModuleWindow.cpp index 07b7da5d..81f07ec2 100644 --- a/src/atta/ui/editor/moduleWindows/ioModuleWindow.cpp +++ b/src/atta/ui/windows/ioModuleWindow.cpp @@ -5,7 +5,7 @@ // By Breno Cunha Queiroz //-------------------------------------------------- #include "stb_image.h" -#include +#include namespace atta::ui { @@ -38,6 +38,6 @@ void IOModuleWindow::renderImpl() { } // namespace atta::ui -#include -#include -#include +#include +#include +#include diff --git a/src/atta/ui/editor/moduleWindows/ioModuleWindow.h b/src/atta/ui/windows/ioModuleWindow.h similarity index 90% rename from src/atta/ui/editor/moduleWindows/ioModuleWindow.h rename to src/atta/ui/windows/ioModuleWindow.h index b3d30168..9342f32f 100644 --- a/src/atta/ui/editor/moduleWindows/ioModuleWindow.h +++ b/src/atta/ui/windows/ioModuleWindow.h @@ -4,8 +4,8 @@ // Date: 2021-09-28 // By Breno Cunha Queiroz //-------------------------------------------------- -#ifndef ATTA_UI_EDITOR_WINDOWS_IO_MODULE_WINDOW_H -#define ATTA_UI_EDITOR_WINDOWS_IO_MODULE_WINDOW_H +#ifndef ATTA_UI_WINDOWS_IO_MODULE_WINDOW_H +#define ATTA_UI_WINDOWS_IO_MODULE_WINDOW_H #include @@ -59,4 +59,4 @@ class IOModuleWindow : public Window { } // namespace atta::ui -#endif // ATTA_UI_EDITOR_WINDOWS_IO_MODULE_WINDOW_H +#endif // ATTA_UI_WINDOWS_IO_MODULE_WINDOW_H diff --git a/src/atta/ui/editor/moduleWindows/ioModuleWindowBluetooth.cpp b/src/atta/ui/windows/ioModuleWindowBluetooth.cpp similarity index 100% rename from src/atta/ui/editor/moduleWindows/ioModuleWindowBluetooth.cpp rename to src/atta/ui/windows/ioModuleWindowBluetooth.cpp diff --git a/src/atta/ui/editor/moduleWindows/ioModuleWindowCamera.cpp b/src/atta/ui/windows/ioModuleWindowCamera.cpp similarity index 100% rename from src/atta/ui/editor/moduleWindows/ioModuleWindowCamera.cpp rename to src/atta/ui/windows/ioModuleWindowCamera.cpp diff --git a/src/atta/ui/editor/moduleWindows/ioModuleWindowSerial.cpp b/src/atta/ui/windows/ioModuleWindowSerial.cpp similarity index 100% rename from src/atta/ui/editor/moduleWindows/ioModuleWindowSerial.cpp rename to src/atta/ui/windows/ioModuleWindowSerial.cpp diff --git a/src/atta/ui/editor/moduleWindows/physicsModuleWindow.cpp b/src/atta/ui/windows/physicsModuleWindow.cpp similarity index 98% rename from src/atta/ui/editor/moduleWindows/physicsModuleWindow.cpp rename to src/atta/ui/windows/physicsModuleWindow.cpp index b62d4f32..7cf33f4c 100644 --- a/src/atta/ui/editor/moduleWindows/physicsModuleWindow.cpp +++ b/src/atta/ui/windows/physicsModuleWindow.cpp @@ -4,7 +4,7 @@ // Date: 2021-12-01 // By Breno Cunha Queiroz //-------------------------------------------------- -#include +#include #include #include diff --git a/src/atta/ui/editor/moduleWindows/physicsModuleWindow.h b/src/atta/ui/windows/physicsModuleWindow.h similarity index 74% rename from src/atta/ui/editor/moduleWindows/physicsModuleWindow.h rename to src/atta/ui/windows/physicsModuleWindow.h index d0466cd9..b1fc9503 100644 --- a/src/atta/ui/editor/moduleWindows/physicsModuleWindow.h +++ b/src/atta/ui/windows/physicsModuleWindow.h @@ -4,8 +4,8 @@ // Date: 2021-12-01 // By Breno Cunha Queiroz //-------------------------------------------------- -#ifndef ATTA_UI_EDITOR_WINDOWS_PHYSICS_MODULE_WINDOW_H -#define ATTA_UI_EDITOR_WINDOWS_PHYSICS_MODULE_WINDOW_H +#ifndef ATTA_UI_WINDOWS_PHYSICS_MODULE_WINDOW_H +#define ATTA_UI_WINDOWS_PHYSICS_MODULE_WINDOW_H #include #include @@ -22,4 +22,4 @@ class PhysicsModuleWindow : public Window { } // namespace atta::ui -#endif // ATTA_UI_EDITOR_WINDOWS_PHYSICS_MODULE_WINDOW_H +#endif // ATTA_UI_WINDOWS_PHYSICS_MODULE_WINDOW_H diff --git a/src/atta/ui/editor/moduleWindows/sensorModuleWindow.cpp b/src/atta/ui/windows/sensorModuleWindow.cpp similarity index 92% rename from src/atta/ui/editor/moduleWindows/sensorModuleWindow.cpp rename to src/atta/ui/windows/sensorModuleWindow.cpp index e704b42a..682872b0 100644 --- a/src/atta/ui/editor/moduleWindows/sensorModuleWindow.cpp +++ b/src/atta/ui/windows/sensorModuleWindow.cpp @@ -4,7 +4,7 @@ // Date: 2022-12-07 // By Breno Cunha Queiroz //-------------------------------------------------- -#include +#include #include diff --git a/src/atta/ui/editor/moduleWindows/sensorModuleWindow.h b/src/atta/ui/windows/sensorModuleWindow.h similarity index 74% rename from src/atta/ui/editor/moduleWindows/sensorModuleWindow.h rename to src/atta/ui/windows/sensorModuleWindow.h index 8113a5f3..7857f02f 100644 --- a/src/atta/ui/editor/moduleWindows/sensorModuleWindow.h +++ b/src/atta/ui/windows/sensorModuleWindow.h @@ -4,8 +4,8 @@ // Date: 2022-12-07 // By Breno Cunha Queiroz //-------------------------------------------------- -#ifndef ATTA_UI_EDITOR_WINDOWS_SENSOR_MODULE_WINDOW_H -#define ATTA_UI_EDITOR_WINDOWS_SENSOR_MODULE_WINDOW_H +#ifndef ATTA_UI_WINDOWS_SENSOR_MODULE_WINDOW_H +#define ATTA_UI_WINDOWS_SENSOR_MODULE_WINDOW_H #include #include @@ -22,4 +22,4 @@ class SensorModuleWindow : public Window { } // namespace atta::ui -#endif // ATTA_UI_EDITOR_WINDOWS_SENSOR_MODULE_WINDOW_H +#endif // ATTA_UI_WINDOWS_SENSOR_MODULE_WINDOW_H From 52aa7fd9e920771327dca9ec5d55739d2b287561 Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Sat, 18 Jan 2025 17:09:00 +0100 Subject: [PATCH 21/37] Chore: Move window file --- src/atta/ui/CMakeLists.txt | 2 +- src/atta/ui/editor/tools/timeProfiler/timeProfilerWindow.h | 2 +- src/atta/ui/editor/topBar/localWindows/versionWindow.h | 2 +- src/atta/ui/windows/graphicsModuleWindow.h | 2 +- src/atta/ui/windows/ioModuleWindow.h | 2 +- src/atta/ui/windows/physicsModuleWindow.h | 2 +- src/atta/ui/windows/sensorModuleWindow.h | 2 +- src/atta/ui/windows/utils/fileSelectionWindow.h | 2 +- src/atta/ui/{editor => windows}/window.cpp | 2 +- src/atta/ui/{editor => windows}/window.h | 6 +++--- 10 files changed, 12 insertions(+), 12 deletions(-) rename src/atta/ui/{editor => windows}/window.cpp (83%) rename src/atta/ui/{editor => windows}/window.h (93%) diff --git a/src/atta/ui/CMakeLists.txt b/src/atta/ui/CMakeLists.txt index aa034f6c..b1793fee 100644 --- a/src/atta/ui/CMakeLists.txt +++ b/src/atta/ui/CMakeLists.txt @@ -11,7 +11,6 @@ set(ATTA_UI_MODULE_SOURCE widgets/image.cpp editor/dockSpace.cpp - editor/window.cpp editor/topBar/topBar.cpp editor/toolBar/toolBar.cpp @@ -26,6 +25,7 @@ set(ATTA_UI_MODULE_SOURCE windows/physicsModuleWindow.cpp windows/sensorModuleWindow.cpp windows/viewportWindows.cpp + windows/window.cpp editor/tools/timeProfiler/timeProfilerWindow.cpp editor/tools/timeProfiler/components/tearDown.cpp diff --git a/src/atta/ui/editor/tools/timeProfiler/timeProfilerWindow.h b/src/atta/ui/editor/tools/timeProfiler/timeProfilerWindow.h index 2ba9c6ca..08a709ff 100644 --- a/src/atta/ui/editor/tools/timeProfiler/timeProfilerWindow.h +++ b/src/atta/ui/editor/tools/timeProfiler/timeProfilerWindow.h @@ -7,7 +7,7 @@ #ifndef ATTA_UI_EDITOR_TOOLS_TIME_PROFILER_TIME_PROFILER_WINDOW_H #define ATTA_UI_EDITOR_TOOLS_TIME_PROFILER_TIME_PROFILER_WINDOW_H -#include +#include #include #include #include diff --git a/src/atta/ui/editor/topBar/localWindows/versionWindow.h b/src/atta/ui/editor/topBar/localWindows/versionWindow.h index 2341cef0..cd6b5011 100644 --- a/src/atta/ui/editor/topBar/localWindows/versionWindow.h +++ b/src/atta/ui/editor/topBar/localWindows/versionWindow.h @@ -8,7 +8,7 @@ #define ATTA_UI_EDITOR_TOP_BAR_LOCAL_WINDOWS_VERSION_WINDOW_H #include -#include +#include namespace atta::ui { diff --git a/src/atta/ui/windows/graphicsModuleWindow.h b/src/atta/ui/windows/graphicsModuleWindow.h index b4e60c10..204b0d09 100644 --- a/src/atta/ui/windows/graphicsModuleWindow.h +++ b/src/atta/ui/windows/graphicsModuleWindow.h @@ -8,7 +8,7 @@ #define ATTA_UI_WINDOWS_GRAPHICS_MODULE_WINDOW_H #include -#include +#include namespace atta::ui { diff --git a/src/atta/ui/windows/ioModuleWindow.h b/src/atta/ui/windows/ioModuleWindow.h index 9342f32f..7506b525 100644 --- a/src/atta/ui/windows/ioModuleWindow.h +++ b/src/atta/ui/windows/ioModuleWindow.h @@ -7,7 +7,7 @@ #ifndef ATTA_UI_WINDOWS_IO_MODULE_WINDOW_H #define ATTA_UI_WINDOWS_IO_MODULE_WINDOW_H -#include +#include #include diff --git a/src/atta/ui/windows/physicsModuleWindow.h b/src/atta/ui/windows/physicsModuleWindow.h index b1fc9503..a4c365ff 100644 --- a/src/atta/ui/windows/physicsModuleWindow.h +++ b/src/atta/ui/windows/physicsModuleWindow.h @@ -8,7 +8,7 @@ #define ATTA_UI_WINDOWS_PHYSICS_MODULE_WINDOW_H #include -#include +#include namespace atta::ui { diff --git a/src/atta/ui/windows/sensorModuleWindow.h b/src/atta/ui/windows/sensorModuleWindow.h index 7857f02f..21ec63dc 100644 --- a/src/atta/ui/windows/sensorModuleWindow.h +++ b/src/atta/ui/windows/sensorModuleWindow.h @@ -8,7 +8,7 @@ #define ATTA_UI_WINDOWS_SENSOR_MODULE_WINDOW_H #include -#include +#include namespace atta::ui { diff --git a/src/atta/ui/windows/utils/fileSelectionWindow.h b/src/atta/ui/windows/utils/fileSelectionWindow.h index 12c8cabe..325f6c0a 100644 --- a/src/atta/ui/windows/utils/fileSelectionWindow.h +++ b/src/atta/ui/windows/utils/fileSelectionWindow.h @@ -7,7 +7,7 @@ #ifndef ATTA_UI_WINDOWS_UTILS_FILE_SELECTION_WINDOW_H #define ATTA_UI_WINDOWS_UTILS_FILE_SELECTION_WINDOW_H -#include +#include namespace atta::ui { diff --git a/src/atta/ui/editor/window.cpp b/src/atta/ui/windows/window.cpp similarity index 83% rename from src/atta/ui/editor/window.cpp rename to src/atta/ui/windows/window.cpp index c00f7b99..a52d7b25 100644 --- a/src/atta/ui/editor/window.cpp +++ b/src/atta/ui/windows/window.cpp @@ -4,4 +4,4 @@ // Date: 2021-09-28 // By Breno Cunha Queiroz //-------------------------------------------------- -#include +#include diff --git a/src/atta/ui/editor/window.h b/src/atta/ui/windows/window.h similarity index 93% rename from src/atta/ui/editor/window.h rename to src/atta/ui/windows/window.h index e17308f4..36c09363 100644 --- a/src/atta/ui/editor/window.h +++ b/src/atta/ui/windows/window.h @@ -4,8 +4,8 @@ // Date: 2021-09-28 // By Breno Cunha Queiroz //-------------------------------------------------- -#ifndef ATTA_UI_EDITOR_WINDOW_H -#define ATTA_UI_EDITOR_WINDOW_H +#ifndef ATTA_UI_WINDOWS_WINDOW_H +#define ATTA_UI_WINDOWS_WINDOW_H #include #include @@ -56,4 +56,4 @@ void Window::render() { } } // namespace atta::ui -#endif // ATTA_UI_EDITOR_WINDOW_H +#endif // ATTA_UI_WINDOWS_WINDOW_H From 67fccc8e13b4deae71cab0ff8822433cf0605dab Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Sat, 18 Jan 2025 17:15:29 +0100 Subject: [PATCH 22/37] Refactor: Move docking setup to editor class --- src/atta/ui/CMakeLists.txt | 2 -- src/atta/ui/editor.cpp | 47 ++++++++++++++++++++++++- src/atta/ui/editor.h | 9 +++-- src/atta/ui/editor/dockSpace.cpp | 59 -------------------------------- src/atta/ui/editor/dockSpace.h | 26 -------------- 5 files changed, 53 insertions(+), 90 deletions(-) delete mode 100644 src/atta/ui/editor/dockSpace.cpp delete mode 100644 src/atta/ui/editor/dockSpace.h diff --git a/src/atta/ui/CMakeLists.txt b/src/atta/ui/CMakeLists.txt index b1793fee..678bf865 100644 --- a/src/atta/ui/CMakeLists.txt +++ b/src/atta/ui/CMakeLists.txt @@ -10,8 +10,6 @@ set(ATTA_UI_MODULE_SOURCE widgets/help.cpp widgets/image.cpp - editor/dockSpace.cpp - editor/topBar/topBar.cpp editor/toolBar/toolBar.cpp editor/topBar/localWindows/repoWindow.cpp diff --git a/src/atta/ui/editor.cpp b/src/atta/ui/editor.cpp index 7af1177b..d1d539a3 100644 --- a/src/atta/ui/editor.cpp +++ b/src/atta/ui/editor.cpp @@ -28,7 +28,7 @@ namespace atta::ui { void Editor::render() { PROFILE(); - _dockSpace.render(); + setupDocking(); // Demo bool demo = true; @@ -76,6 +76,51 @@ void Editor::render() { } } +void Editor::setupDocking() { + //----- Create DockSpace -----// + const ImGuiViewport* viewport = ImGui::GetMainViewport(); + ImGui::SetNextWindowPos(viewport->WorkPos); + ImGui::SetNextWindowSize(viewport->WorkSize); + ImGui::SetNextWindowViewport(viewport->ID); + ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); + ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); + ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | + ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus | ImGuiWindowFlags_NoBackground; + + bool open = true; + ImGui::Begin("EditorDockSpace", &open, window_flags); + ImGui::PopStyleVar(3); + + ImGuiIO& io = ImGui::GetIO(); + if (io.ConfigFlags & ImGuiConfigFlags_DockingEnable) { + ImGuiID dockspace_id = ImGui::GetID("EditorDockSpace"); + ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), ImGuiDockNodeFlags_PassthruCentralNode | ImGuiDockNodeFlags_NoWindowMenuButton); + + //----- Clear previous layout -----// + if (_firstRender) { + _firstRender = false; + + ImGui::DockBuilderRemoveNode(dockspace_id); // clear any previous layout + ImGui::DockBuilderAddNode(dockspace_id, ImGuiDockNodeFlags_PassthruCentralNode | ImGuiDockNodeFlags_DockSpace); + ImGui::DockBuilderSetNodeSize(dockspace_id, viewport->Size); + + auto dock_id_scene = ImGui::DockBuilderSplitNode(dockspace_id, ImGuiDir_Right, 0.20f, nullptr, &dockspace_id); + auto dock_id_down = ImGui::DockBuilderSplitNode(dockspace_id, ImGuiDir_Down, 0.20f, nullptr, &dockspace_id); + auto dock_id_vp_top = ImGui::DockBuilderSplitNode(dockspace_id, ImGuiDir_Up, 0.00f, nullptr, &dockspace_id); + + // we now dock our windows into the docking node we made above + _viewportDockId = dockspace_id; + ImGui::DockBuilderDockWindow("Main Viewport###ViewportMain Viewport", dockspace_id); + ImGui::DockBuilderDockWindow("Log", dock_id_down); + ImGui::DockBuilderDockWindow("Scene", dock_id_scene); + ImGui::DockBuilderDockWindow("##Toolbar", dock_id_vp_top); + ImGui::DockBuilderFinish(dockspace_id); + } + } + ImGui::End(); +} + void Editor::renderCameraWindows() { // TODO think another way to show camera windows std::vector& cameras = sensor::getCameraInfos(); diff --git a/src/atta/ui/editor.h b/src/atta/ui/editor.h index 8dd45052..73a370ef 100644 --- a/src/atta/ui/editor.h +++ b/src/atta/ui/editor.h @@ -8,7 +8,6 @@ #define ATTA_UI_EDITOR_H #include -#include #include #include #include @@ -23,10 +22,16 @@ class Editor final { public: void render(); + unsigned getViewportDockId() { return _viewportDockId; } + private: + void setupDocking(); void renderCameraWindows(); - DockSpace _dockSpace; + // Docking + unsigned _viewportDockId; + bool _firstRender = true; + TopBar _topBar; ToolBar _toolBar; EntityWindow _entityWindow; diff --git a/src/atta/ui/editor/dockSpace.cpp b/src/atta/ui/editor/dockSpace.cpp deleted file mode 100644 index 283f78a8..00000000 --- a/src/atta/ui/editor/dockSpace.cpp +++ /dev/null @@ -1,59 +0,0 @@ -//-------------------------------------------------- -// Atta UI Module -// dockSpace.cpp -// Date: 2021-09-01 -// By Breno Cunha Queiroz -//-------------------------------------------------- -#include -#include - -namespace atta::ui { - -DockSpace::DockSpace() : _firstTime(true) {} - -void DockSpace::render() { - //----- Create DockSpace -----// - const ImGuiViewport* viewport = ImGui::GetMainViewport(); - ImGui::SetNextWindowPos(viewport->WorkPos); - ImGui::SetNextWindowSize(viewport->WorkSize); - ImGui::SetNextWindowViewport(viewport->ID); - ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); - ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f); - ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); - ImGuiWindowFlags window_flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | - ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus | ImGuiWindowFlags_NoBackground; - - bool open = true; - ImGui::Begin("EditorDockSpace", &open, window_flags); - ImGui::PopStyleVar(3); - - ImGuiIO& io = ImGui::GetIO(); - if (io.ConfigFlags & ImGuiConfigFlags_DockingEnable) { - ImGuiID dockspace_id = ImGui::GetID("EditorDockSpace"); - ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), ImGuiDockNodeFlags_PassthruCentralNode | ImGuiDockNodeFlags_NoWindowMenuButton); - - //----- Clear previous layout -----// - if (_firstTime) { - _firstTime = false; - - ImGui::DockBuilderRemoveNode(dockspace_id); // clear any previous layout - ImGui::DockBuilderAddNode(dockspace_id, ImGuiDockNodeFlags_PassthruCentralNode | ImGuiDockNodeFlags_DockSpace); - ImGui::DockBuilderSetNodeSize(dockspace_id, viewport->Size); - - auto dock_id_scene = ImGui::DockBuilderSplitNode(dockspace_id, ImGuiDir_Right, 0.20f, nullptr, &dockspace_id); - auto dock_id_down = ImGui::DockBuilderSplitNode(dockspace_id, ImGuiDir_Down, 0.20f, nullptr, &dockspace_id); - auto dock_id_vp_top = ImGui::DockBuilderSplitNode(dockspace_id, ImGuiDir_Up, 0.00f, nullptr, &dockspace_id); - - // we now dock our windows into the docking node we made above - _viewportDockId = dockspace_id; - ImGui::DockBuilderDockWindow("Main Viewport###ViewportMain Viewport", dockspace_id); - ImGui::DockBuilderDockWindow("Log", dock_id_down); - ImGui::DockBuilderDockWindow("Scene", dock_id_scene); - ImGui::DockBuilderDockWindow("##Toolbar", dock_id_vp_top); - ImGui::DockBuilderFinish(dockspace_id); - } - } - ImGui::End(); -} - -} // namespace atta::ui diff --git a/src/atta/ui/editor/dockSpace.h b/src/atta/ui/editor/dockSpace.h deleted file mode 100644 index 5dddc981..00000000 --- a/src/atta/ui/editor/dockSpace.h +++ /dev/null @@ -1,26 +0,0 @@ -//-------------------------------------------------- -// Atta UI Module -// dockSpace.h -// Date: 2021-09-01 -// By Breno Cunha Queiroz -//-------------------------------------------------- -#ifndef ATTA_UI_EDITOR_DOCK_SPACE_H -#define ATTA_UI_EDITOR_DOCK_SPACE_H - -namespace atta::ui { - -class DockSpace { - public: - DockSpace(); - void render(); - - unsigned getViewportDockId() { return _viewportDockId; } - - private: - unsigned _viewportDockId; - bool _firstTime; -}; - -} // namespace atta::ui - -#endif // ATTA_UI_EDITOR_DOCK_SPACE_H From 15276bbc7c4b705b6456bf5cc29be915f124cfd5 Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Sat, 18 Jan 2025 17:28:18 +0100 Subject: [PATCH 23/37] Chore: Move time profiler tool to windows folder --- src/atta/ui/CMakeLists.txt | 9 ++++----- src/atta/ui/editor.cpp | 2 +- src/atta/ui/editor/topBar/topBar.cpp | 2 +- .../timeProfiler/components/flameGraph.cpp | 2 +- .../timeProfiler/components/flameGraph.h | 6 +++--- .../timeProfiler/components/tearDown.cpp | 2 +- .../timeProfiler/components/tearDown.h | 6 +++--- .../timeProfiler/components/timeline.cpp | 2 +- .../timeProfiler/components/timeline.h | 6 +++--- .../timeProfiler/timeProfilerWindow.cpp | 12 +++++------- .../timeProfiler/timeProfilerWindow.h | 13 +++++++------ 11 files changed, 30 insertions(+), 32 deletions(-) rename src/atta/ui/{editor/tools => windows}/timeProfiler/components/flameGraph.cpp (96%) rename src/atta/ui/{editor/tools => windows}/timeProfiler/components/flameGraph.h (71%) rename src/atta/ui/{editor/tools => windows}/timeProfiler/components/tearDown.cpp (98%) rename src/atta/ui/{editor/tools => windows}/timeProfiler/components/tearDown.h (82%) rename src/atta/ui/{editor/tools => windows}/timeProfiler/components/timeline.cpp (99%) rename src/atta/ui/{editor/tools => windows}/timeProfiler/components/timeline.h (76%) rename src/atta/ui/{editor/tools => windows}/timeProfiler/timeProfilerWindow.cpp (86%) rename src/atta/ui/{editor/tools => windows}/timeProfiler/timeProfilerWindow.h (56%) diff --git a/src/atta/ui/CMakeLists.txt b/src/atta/ui/CMakeLists.txt index 678bf865..24972110 100644 --- a/src/atta/ui/CMakeLists.txt +++ b/src/atta/ui/CMakeLists.txt @@ -15,6 +15,10 @@ set(ATTA_UI_MODULE_SOURCE editor/topBar/localWindows/repoWindow.cpp editor/topBar/localWindows/versionWindow.cpp + windows/timeProfiler/timeProfilerWindow.cpp + windows/timeProfiler/components/tearDown.cpp + windows/timeProfiler/components/flameGraph.cpp + windows/timeProfiler/components/timeline.cpp windows/utils/fileSelectionWindow.cpp windows/entityWindow.cpp windows/graphicsModuleWindow.cpp @@ -25,11 +29,6 @@ set(ATTA_UI_MODULE_SOURCE windows/viewportWindows.cpp windows/window.cpp - editor/tools/timeProfiler/timeProfilerWindow.cpp - editor/tools/timeProfiler/components/tearDown.cpp - editor/tools/timeProfiler/components/flameGraph.cpp - editor/tools/timeProfiler/components/timeline.cpp - editor/drawers/physicsDrawer.cpp editor/drawers/sensorDrawer.cpp ) diff --git a/src/atta/ui/editor.cpp b/src/atta/ui/editor.cpp index d1d539a3..921a6952 100644 --- a/src/atta/ui/editor.cpp +++ b/src/atta/ui/editor.cpp @@ -12,12 +12,12 @@ #include #include -#include #include #include #include #include #include +#include #include #include diff --git a/src/atta/ui/editor/topBar/topBar.cpp b/src/atta/ui/editor/topBar/topBar.cpp index 32fd4378..7fd1fa4c 100644 --- a/src/atta/ui/editor/topBar/topBar.cpp +++ b/src/atta/ui/editor/topBar/topBar.cpp @@ -28,7 +28,7 @@ #include #include -#include +#include namespace atta::ui { diff --git a/src/atta/ui/editor/tools/timeProfiler/components/flameGraph.cpp b/src/atta/ui/windows/timeProfiler/components/flameGraph.cpp similarity index 96% rename from src/atta/ui/editor/tools/timeProfiler/components/flameGraph.cpp rename to src/atta/ui/windows/timeProfiler/components/flameGraph.cpp index a2cb5a4d..b1779081 100644 --- a/src/atta/ui/editor/tools/timeProfiler/components/flameGraph.cpp +++ b/src/atta/ui/windows/timeProfiler/components/flameGraph.cpp @@ -4,7 +4,7 @@ // Date: 2022-10-24 // By Breno Cunha Queiroz //-------------------------------------------------- -#include +#include #include "implot.h" diff --git a/src/atta/ui/editor/tools/timeProfiler/components/flameGraph.h b/src/atta/ui/windows/timeProfiler/components/flameGraph.h similarity index 71% rename from src/atta/ui/editor/tools/timeProfiler/components/flameGraph.h rename to src/atta/ui/windows/timeProfiler/components/flameGraph.h index 83aae408..3e4cabe7 100644 --- a/src/atta/ui/editor/tools/timeProfiler/components/flameGraph.h +++ b/src/atta/ui/windows/timeProfiler/components/flameGraph.h @@ -4,8 +4,8 @@ // Date: 2022-10-30 // By Breno Cunha Queiroz //-------------------------------------------------- -#ifndef ATTA_UI_EDITOR_TOOLS_TIME_PROFILER_COMPONENTS_FLAME_GRAPH_H -#define ATTA_UI_EDITOR_TOOLS_TIME_PROFILER_COMPONENTS_FLAME_GRAPH_H +#ifndef ATTA_UI_WINDOWS_TIME_PROFILER_COMPONENTS_FLAME_GRAPH_H +#define ATTA_UI_WINDOWS_TIME_PROFILER_COMPONENTS_FLAME_GRAPH_H namespace atta::ui { @@ -28,4 +28,4 @@ class FlameGraph { } // namespace atta::ui -#endif // ATTA_UI_EDITOR_TOOLS_TIME_PROFILER_COMPONENTS_FLAME_GRAPH_H +#endif // ATTA_UI_WINDOWS_TIME_PROFILER_COMPONENTS_FLAME_GRAPH_H diff --git a/src/atta/ui/editor/tools/timeProfiler/components/tearDown.cpp b/src/atta/ui/windows/timeProfiler/components/tearDown.cpp similarity index 98% rename from src/atta/ui/editor/tools/timeProfiler/components/tearDown.cpp rename to src/atta/ui/windows/timeProfiler/components/tearDown.cpp index b1a7b6cd..4b645c4d 100644 --- a/src/atta/ui/editor/tools/timeProfiler/components/tearDown.cpp +++ b/src/atta/ui/windows/timeProfiler/components/tearDown.cpp @@ -4,7 +4,7 @@ // Date: 2022-10-24 // By Breno Cunha Queiroz //-------------------------------------------------- -#include +#include #include diff --git a/src/atta/ui/editor/tools/timeProfiler/components/tearDown.h b/src/atta/ui/windows/timeProfiler/components/tearDown.h similarity index 82% rename from src/atta/ui/editor/tools/timeProfiler/components/tearDown.h rename to src/atta/ui/windows/timeProfiler/components/tearDown.h index 4f6303ad..43c5c0f5 100644 --- a/src/atta/ui/editor/tools/timeProfiler/components/tearDown.h +++ b/src/atta/ui/windows/timeProfiler/components/tearDown.h @@ -4,8 +4,8 @@ // Date: 2022-10-24 // By Breno Cunha Queiroz //-------------------------------------------------- -#ifndef ATTA_UI_EDITOR_TOOLS_TIME_PROFILER_COMPONENTS_TEAR_DOWN_H -#define ATTA_UI_EDITOR_TOOLS_TIME_PROFILER_COMPONENTS_TEAR_DOWN_H +#ifndef ATTA_UI_WINDOWS_TIME_PROFILER_COMPONENTS_TEAR_DOWN_H +#define ATTA_UI_WINDOWS_TIME_PROFILER_COMPONENTS_TEAR_DOWN_H namespace atta::ui { @@ -42,4 +42,4 @@ class TearDown { } // namespace atta::ui -#endif // ATTA_UI_EDITOR_TOOLS_TIME_PROFILER_COMPONENTS_TEAR_DOWN_H +#endif // ATTA_UI_WINDOWS_TIME_PROFILER_COMPONENTS_TEAR_DOWN_H diff --git a/src/atta/ui/editor/tools/timeProfiler/components/timeline.cpp b/src/atta/ui/windows/timeProfiler/components/timeline.cpp similarity index 99% rename from src/atta/ui/editor/tools/timeProfiler/components/timeline.cpp rename to src/atta/ui/windows/timeProfiler/components/timeline.cpp index d7981a5c..31ffc8e8 100644 --- a/src/atta/ui/editor/tools/timeProfiler/components/timeline.cpp +++ b/src/atta/ui/windows/timeProfiler/components/timeline.cpp @@ -4,7 +4,7 @@ // Date: 2022-10-24 // By Breno Cunha Queiroz //-------------------------------------------------- -#include +#include #include "implot.h" diff --git a/src/atta/ui/editor/tools/timeProfiler/components/timeline.h b/src/atta/ui/windows/timeProfiler/components/timeline.h similarity index 76% rename from src/atta/ui/editor/tools/timeProfiler/components/timeline.h rename to src/atta/ui/windows/timeProfiler/components/timeline.h index c8114235..ef1994e3 100644 --- a/src/atta/ui/editor/tools/timeProfiler/components/timeline.h +++ b/src/atta/ui/windows/timeProfiler/components/timeline.h @@ -4,8 +4,8 @@ // Date: 2022-10-30 // By Breno Cunha Queiroz //-------------------------------------------------- -#ifndef ATTA_UI_EDITOR_TOOLS_TIME_PROFILER_COMPONENTS_TIMELINE_H -#define ATTA_UI_EDITOR_TOOLS_TIME_PROFILER_COMPONENTS_TIMELINE_H +#ifndef ATTA_UI_WINDOWS_TIME_PROFILER_COMPONENTS_TIMELINE_H +#define ATTA_UI_WINDOWS_TIME_PROFILER_COMPONENTS_TIMELINE_H namespace atta::ui { @@ -26,4 +26,4 @@ class Timeline { } // namespace atta::ui -#endif // ATTA_UI_EDITOR_TOOLS_TIME_PROFILER_COMPONENTS_TIMELINE_H +#endif // ATTA_UI_WINDOWS_TIME_PROFILER_COMPONENTS_TIMELINE_H diff --git a/src/atta/ui/editor/tools/timeProfiler/timeProfilerWindow.cpp b/src/atta/ui/windows/timeProfiler/timeProfilerWindow.cpp similarity index 86% rename from src/atta/ui/editor/tools/timeProfiler/timeProfilerWindow.cpp rename to src/atta/ui/windows/timeProfiler/timeProfilerWindow.cpp index 16ca658f..91bae88e 100644 --- a/src/atta/ui/editor/tools/timeProfiler/timeProfilerWindow.cpp +++ b/src/atta/ui/windows/timeProfiler/timeProfilerWindow.cpp @@ -4,8 +4,8 @@ // Date: 2022-10-23 // By Breno Cunha Queiroz //-------------------------------------------------- -#include #include +#include namespace atta::ui { @@ -18,8 +18,7 @@ void TimeProfilerWindow::renderImpl() { const float buttonSize = ImGui::GetTextLineHeightWithSpacing(); size_t size = Profiler::getRecords().size(); - if(size) - { + if (size) { ImGui::Text("%u events", unsigned(size)); ImGui::SameLine(); } @@ -32,14 +31,13 @@ void TimeProfilerWindow::renderImpl() { Profiler::stopRecording(); } - if(size) - { + if (size) { ImGui::SameLine(); ImGui::Text("%s", Profiler::getTimeString(Profiler::getTotalTime()).c_str()); } - //if (ImGui::CollapsingHeader("Flame Graph")) - // _flameGraph.render(); + // if (ImGui::CollapsingHeader("Flame Graph")) + // _flameGraph.render(); if (ImGui::CollapsingHeader("Tear Down")) _tearDown.render(); diff --git a/src/atta/ui/editor/tools/timeProfiler/timeProfilerWindow.h b/src/atta/ui/windows/timeProfiler/timeProfilerWindow.h similarity index 56% rename from src/atta/ui/editor/tools/timeProfiler/timeProfilerWindow.h rename to src/atta/ui/windows/timeProfiler/timeProfilerWindow.h index 08a709ff..98cef066 100644 --- a/src/atta/ui/editor/tools/timeProfiler/timeProfilerWindow.h +++ b/src/atta/ui/windows/timeProfiler/timeProfilerWindow.h @@ -4,13 +4,13 @@ // Date: 2022-10-23 // By Breno Cunha Queiroz //-------------------------------------------------- -#ifndef ATTA_UI_EDITOR_TOOLS_TIME_PROFILER_TIME_PROFILER_WINDOW_H -#define ATTA_UI_EDITOR_TOOLS_TIME_PROFILER_TIME_PROFILER_WINDOW_H +#ifndef ATTA_UI_WINDOWS_TIME_PROFILER_TIME_PROFILER_WINDOW_H +#define ATTA_UI_WINDOWS_TIME_PROFILER_TIME_PROFILER_WINDOW_H +#include +#include +#include #include -#include -#include -#include namespace atta::ui { @@ -20,6 +20,7 @@ class TimeProfilerWindow : public Window { void renderImpl(); friend Window; + private: TearDown _tearDown; FlameGraph _flameGraph; @@ -28,4 +29,4 @@ class TimeProfilerWindow : public Window { } // namespace atta::ui -#endif // ATTA_UI_EDITOR_TOOLS_TIME_PROFILER_TIME_PROFILER_WINDOW_H +#endif // ATTA_UI_WINDOWS_TIME_PROFILER_TIME_PROFILER_WINDOW_H From 61ebe80e02a52c71d969312e7983f8e2a0e300f2 Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Sat, 18 Jan 2025 17:31:28 +0100 Subject: [PATCH 24/37] Chore: Move top/tool bars to panels folder --- src/atta/ui/CMakeLists.txt | 8 ++++---- src/atta/ui/editor.cpp | 2 +- src/atta/ui/editor.h | 4 ++-- src/atta/ui/{editor => panels}/toolBar/toolBar.cpp | 2 +- src/atta/ui/{editor => panels}/toolBar/toolBar.h | 6 +++--- .../{editor => panels}/topBar/localWindows/repoWindow.cpp | 2 +- .../{editor => panels}/topBar/localWindows/repoWindow.h | 6 +++--- .../topBar/localWindows/versionWindow.cpp | 2 +- .../topBar/localWindows/versionWindow.h | 6 +++--- src/atta/ui/{editor => panels}/topBar/topBar.cpp | 4 ++-- src/atta/ui/{editor => panels}/topBar/topBar.h | 8 ++++---- 11 files changed, 25 insertions(+), 25 deletions(-) rename src/atta/ui/{editor => panels}/toolBar/toolBar.cpp (99%) rename src/atta/ui/{editor => panels}/toolBar/toolBar.h (72%) rename src/atta/ui/{editor => panels}/topBar/localWindows/repoWindow.cpp (98%) rename src/atta/ui/{editor => panels}/topBar/localWindows/repoWindow.h (85%) rename src/atta/ui/{editor => panels}/topBar/localWindows/versionWindow.cpp (95%) rename src/atta/ui/{editor => panels}/topBar/localWindows/versionWindow.h (74%) rename src/atta/ui/{editor => panels}/topBar/topBar.cpp (99%) rename src/atta/ui/{editor => panels}/topBar/topBar.h (89%) diff --git a/src/atta/ui/CMakeLists.txt b/src/atta/ui/CMakeLists.txt index 24972110..618a02ae 100644 --- a/src/atta/ui/CMakeLists.txt +++ b/src/atta/ui/CMakeLists.txt @@ -10,10 +10,10 @@ set(ATTA_UI_MODULE_SOURCE widgets/help.cpp widgets/image.cpp - editor/topBar/topBar.cpp - editor/toolBar/toolBar.cpp - editor/topBar/localWindows/repoWindow.cpp - editor/topBar/localWindows/versionWindow.cpp + panels/topBar/topBar.cpp + panels/toolBar/toolBar.cpp + panels/topBar/localWindows/repoWindow.cpp + panels/topBar/localWindows/versionWindow.cpp windows/timeProfiler/timeProfilerWindow.cpp windows/timeProfiler/components/tearDown.cpp diff --git a/src/atta/ui/editor.cpp b/src/atta/ui/editor.cpp index 921a6952..be6adad4 100644 --- a/src/atta/ui/editor.cpp +++ b/src/atta/ui/editor.cpp @@ -12,7 +12,7 @@ #include #include -#include +#include #include #include #include diff --git a/src/atta/ui/editor.h b/src/atta/ui/editor.h index 73a370ef..5253029d 100644 --- a/src/atta/ui/editor.h +++ b/src/atta/ui/editor.h @@ -10,8 +10,8 @@ #include #include #include -#include -#include +#include +#include #include #include #include diff --git a/src/atta/ui/editor/toolBar/toolBar.cpp b/src/atta/ui/panels/toolBar/toolBar.cpp similarity index 99% rename from src/atta/ui/editor/toolBar/toolBar.cpp rename to src/atta/ui/panels/toolBar/toolBar.cpp index a35c6128..721ea841 100644 --- a/src/atta/ui/editor/toolBar/toolBar.cpp +++ b/src/atta/ui/panels/toolBar/toolBar.cpp @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/atta/ui/editor/toolBar/toolBar.h b/src/atta/ui/panels/toolBar/toolBar.h similarity index 72% rename from src/atta/ui/editor/toolBar/toolBar.h rename to src/atta/ui/panels/toolBar/toolBar.h index e7ab0148..961e6cfe 100644 --- a/src/atta/ui/editor/toolBar/toolBar.h +++ b/src/atta/ui/panels/toolBar/toolBar.h @@ -4,8 +4,8 @@ // Date: 2021-12-28 // By Breno Cunha Queiroz //-------------------------------------------------- -#ifndef ATTA_UI_EDITOR_TOOL_BAR_TOOL_BAR_H -#define ATTA_UI_EDITOR_TOOL_BAR_TOOL_BAR_H +#ifndef ATTA_UI_PANELS_TOOL_BAR_TOOL_BAR_H +#define ATTA_UI_PANELS_TOOL_BAR_TOOL_BAR_H #include @@ -20,4 +20,4 @@ class ToolBar { } // namespace atta::ui -#endif // ATTA_UI_EDITOR_TOOL_BAR_TOOL_BAR_H +#endif // ATTA_UI_PANELS_TOOL_BAR_TOOL_BAR_H diff --git a/src/atta/ui/editor/topBar/localWindows/repoWindow.cpp b/src/atta/ui/panels/topBar/localWindows/repoWindow.cpp similarity index 98% rename from src/atta/ui/editor/topBar/localWindows/repoWindow.cpp rename to src/atta/ui/panels/topBar/localWindows/repoWindow.cpp index b4955273..44f91eb9 100644 --- a/src/atta/ui/editor/topBar/localWindows/repoWindow.cpp +++ b/src/atta/ui/panels/topBar/localWindows/repoWindow.cpp @@ -5,7 +5,7 @@ // By Breno Cunha Queiroz //-------------------------------------------------- #include -#include +#include #include namespace atta::ui { diff --git a/src/atta/ui/editor/topBar/localWindows/repoWindow.h b/src/atta/ui/panels/topBar/localWindows/repoWindow.h similarity index 85% rename from src/atta/ui/editor/topBar/localWindows/repoWindow.h rename to src/atta/ui/panels/topBar/localWindows/repoWindow.h index 8543f107..32b145a1 100644 --- a/src/atta/ui/editor/topBar/localWindows/repoWindow.h +++ b/src/atta/ui/panels/topBar/localWindows/repoWindow.h @@ -4,8 +4,8 @@ // Date: 2021-12-26 // By Breno Cunha Queiroz //-------------------------------------------------- -#ifndef ATTA_UI_EDITOR_TOP_BAR_LOCAL_WINDOWS_REPO_WINDOW_H -#define ATTA_UI_EDITOR_TOP_BAR_LOCAL_WINDOWS_REPO_WINDOW_H +#ifndef ATTA_UI_PANELS_TOP_BAR_LOCAL_WINDOWS_REPO_WINDOW_H +#define ATTA_UI_PANELS_TOP_BAR_LOCAL_WINDOWS_REPO_WINDOW_H #include @@ -47,4 +47,4 @@ class RepoWindow { } // namespace atta::ui -#endif // ATTA_UI_EDITOR_TOP_BAR_LOCAL_WINDOWS_REPO_WINDOW_H +#endif // ATTA_UI_PANELS_TOP_BAR_LOCAL_WINDOWS_REPO_WINDOW_H diff --git a/src/atta/ui/editor/topBar/localWindows/versionWindow.cpp b/src/atta/ui/panels/topBar/localWindows/versionWindow.cpp similarity index 95% rename from src/atta/ui/editor/topBar/localWindows/versionWindow.cpp rename to src/atta/ui/panels/topBar/localWindows/versionWindow.cpp index 96f7bde9..fb9d2cad 100644 --- a/src/atta/ui/editor/topBar/localWindows/versionWindow.cpp +++ b/src/atta/ui/panels/topBar/localWindows/versionWindow.cpp @@ -5,7 +5,7 @@ // By Breno Cunha Queiroz //-------------------------------------------------- #include -#include +#include #include namespace atta::ui { diff --git a/src/atta/ui/editor/topBar/localWindows/versionWindow.h b/src/atta/ui/panels/topBar/localWindows/versionWindow.h similarity index 74% rename from src/atta/ui/editor/topBar/localWindows/versionWindow.h rename to src/atta/ui/panels/topBar/localWindows/versionWindow.h index cd6b5011..af8afaa8 100644 --- a/src/atta/ui/editor/topBar/localWindows/versionWindow.h +++ b/src/atta/ui/panels/topBar/localWindows/versionWindow.h @@ -4,8 +4,8 @@ // Date: 2022-06-11 // By Breno Cunha Queiroz //-------------------------------------------------- -#ifndef ATTA_UI_EDITOR_TOP_BAR_LOCAL_WINDOWS_VERSION_WINDOW_H -#define ATTA_UI_EDITOR_TOP_BAR_LOCAL_WINDOWS_VERSION_WINDOW_H +#ifndef ATTA_UI_PANELS_TOP_BAR_LOCAL_WINDOWS_VERSION_WINDOW_H +#define ATTA_UI_PANELS_TOP_BAR_LOCAL_WINDOWS_VERSION_WINDOW_H #include #include @@ -25,4 +25,4 @@ class VersionWindow : public Window { } // namespace atta::ui -#endif // ATTA_UI_EDITOR_TOP_BAR_LOCAL_WINDOWS_VERSION_WINDOW_H +#endif // ATTA_UI_PANELS_TOP_BAR_LOCAL_WINDOWS_VERSION_WINDOW_H diff --git a/src/atta/ui/editor/topBar/topBar.cpp b/src/atta/ui/panels/topBar/topBar.cpp similarity index 99% rename from src/atta/ui/editor/topBar/topBar.cpp rename to src/atta/ui/panels/topBar/topBar.cpp index 7fd1fa4c..5d5753ea 100644 --- a/src/atta/ui/editor/topBar/topBar.cpp +++ b/src/atta/ui/panels/topBar/topBar.cpp @@ -4,9 +4,9 @@ // Date: 2021-09-01 // By Breno Cunha Queiroz //-------------------------------------------------- -#include +#include -#include +#include #include #include #include diff --git a/src/atta/ui/editor/topBar/topBar.h b/src/atta/ui/panels/topBar/topBar.h similarity index 89% rename from src/atta/ui/editor/topBar/topBar.h rename to src/atta/ui/panels/topBar/topBar.h index 3595abd1..e8e41a8c 100644 --- a/src/atta/ui/editor/topBar/topBar.h +++ b/src/atta/ui/panels/topBar/topBar.h @@ -4,10 +4,10 @@ // Date: 2021-09-01 // By Breno Cunha Queiroz //-------------------------------------------------- -#ifndef ATTA_UI_EDITOR_TOP_BAR_TOP_BAR_H -#define ATTA_UI_EDITOR_TOP_BAR_TOP_BAR_H +#ifndef ATTA_UI_PANELS_TOP_BAR_TOP_BAR_H +#define ATTA_UI_PANELS_TOP_BAR_TOP_BAR_H -#include +#include namespace atta::ui { @@ -43,4 +43,4 @@ class TopBar { } // namespace atta::ui -#endif // ATTA_UI_EDITOR_TOP_BAR_TOP_BAR_H +#endif // ATTA_UI_PANELS_TOP_BAR_TOP_BAR_H From 5a7e322c24af1e468f0d1df783beebe0619085a4 Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Sat, 18 Jan 2025 17:33:22 +0100 Subject: [PATCH 25/37] Chore: Move drawers files --- src/atta/ui/CMakeLists.txt | 20 +++++++++---------- .../ui/{editor => }/drawers/physicsDrawer.cpp | 2 +- .../ui/{editor => }/drawers/physicsDrawer.h | 6 +++--- .../ui/{editor => }/drawers/sensorDrawer.cpp | 2 +- .../ui/{editor => }/drawers/sensorDrawer.h | 6 +++--- src/atta/ui/editor.h | 4 ++-- 6 files changed, 20 insertions(+), 20 deletions(-) rename src/atta/ui/{editor => }/drawers/physicsDrawer.cpp (99%) rename src/atta/ui/{editor => }/drawers/physicsDrawer.h (89%) rename src/atta/ui/{editor => }/drawers/sensorDrawer.cpp (98%) rename src/atta/ui/{editor => }/drawers/sensorDrawer.h (74%) diff --git a/src/atta/ui/CMakeLists.txt b/src/atta/ui/CMakeLists.txt index 618a02ae..3f466ec1 100644 --- a/src/atta/ui/CMakeLists.txt +++ b/src/atta/ui/CMakeLists.txt @@ -1,20 +1,19 @@ cmake_minimum_required(VERSION 3.14) set(ATTA_UI_MODULE_SOURCE - interface.cpp - manager.cpp - editor.cpp - - widgets/align.cpp - widgets/button.cpp - widgets/help.cpp - widgets/image.cpp + drawers/physicsDrawer.cpp + drawers/sensorDrawer.cpp panels/topBar/topBar.cpp panels/toolBar/toolBar.cpp panels/topBar/localWindows/repoWindow.cpp panels/topBar/localWindows/versionWindow.cpp + widgets/align.cpp + widgets/button.cpp + widgets/help.cpp + widgets/image.cpp + windows/timeProfiler/timeProfilerWindow.cpp windows/timeProfiler/components/tearDown.cpp windows/timeProfiler/components/flameGraph.cpp @@ -29,8 +28,9 @@ set(ATTA_UI_MODULE_SOURCE windows/viewportWindows.cpp windows/window.cpp - editor/drawers/physicsDrawer.cpp - editor/drawers/sensorDrawer.cpp + interface.cpp + manager.cpp + editor.cpp ) add_library(atta_ui_module STATIC diff --git a/src/atta/ui/editor/drawers/physicsDrawer.cpp b/src/atta/ui/drawers/physicsDrawer.cpp similarity index 99% rename from src/atta/ui/editor/drawers/physicsDrawer.cpp rename to src/atta/ui/drawers/physicsDrawer.cpp index 88c1595d..43227101 100644 --- a/src/atta/ui/editor/drawers/physicsDrawer.cpp +++ b/src/atta/ui/drawers/physicsDrawer.cpp @@ -4,7 +4,7 @@ // Date: 2021-12-03 // By Breno Cunha Queiroz //-------------------------------------------------- -#include +#include #include #include diff --git a/src/atta/ui/editor/drawers/physicsDrawer.h b/src/atta/ui/drawers/physicsDrawer.h similarity index 89% rename from src/atta/ui/editor/drawers/physicsDrawer.h rename to src/atta/ui/drawers/physicsDrawer.h index a43064ba..36ffd4f2 100644 --- a/src/atta/ui/editor/drawers/physicsDrawer.h +++ b/src/atta/ui/drawers/physicsDrawer.h @@ -4,8 +4,8 @@ // Date: 2021-12-03 // By Breno Cunha Queiroz //-------------------------------------------------- -#ifndef ATTA_UI_EDITOR_DRAWERS_PHYSICS_DRAWER_H -#define ATTA_UI_EDITOR_DRAWERS_PHYSICS_DRAWER_H +#ifndef ATTA_UI_DRAWERS_PHYSICS_DRAWER_H +#define ATTA_UI_DRAWERS_PHYSICS_DRAWER_H namespace atta::ui { @@ -28,4 +28,4 @@ class PhysicsDrawer { } // namespace atta::ui -#endif // ATTA_UI_EDITOR_DRAWERS_PHYSICS_DRAWER_H +#endif // ATTA_UI_DRAWERS_PHYSICS_DRAWER_H diff --git a/src/atta/ui/editor/drawers/sensorDrawer.cpp b/src/atta/ui/drawers/sensorDrawer.cpp similarity index 98% rename from src/atta/ui/editor/drawers/sensorDrawer.cpp rename to src/atta/ui/drawers/sensorDrawer.cpp index 41f16cd6..3d774c4d 100644 --- a/src/atta/ui/editor/drawers/sensorDrawer.cpp +++ b/src/atta/ui/drawers/sensorDrawer.cpp @@ -9,7 +9,7 @@ #include #include #include -#include +#include namespace atta::ui { diff --git a/src/atta/ui/editor/drawers/sensorDrawer.h b/src/atta/ui/drawers/sensorDrawer.h similarity index 74% rename from src/atta/ui/editor/drawers/sensorDrawer.h rename to src/atta/ui/drawers/sensorDrawer.h index 66779f19..9f437588 100644 --- a/src/atta/ui/editor/drawers/sensorDrawer.h +++ b/src/atta/ui/drawers/sensorDrawer.h @@ -4,8 +4,8 @@ // Date: 2022-03-05 // By Breno Cunha Queiroz //-------------------------------------------------- -#ifndef ATTA_UI_EDITOR_DRAWERS_SENSOR_DRAWER_H -#define ATTA_UI_EDITOR_DRAWERS_SENSOR_DRAWER_H +#ifndef ATTA_UI_DRAWERS_SENSOR_DRAWER_H +#define ATTA_UI_DRAWERS_SENSOR_DRAWER_H namespace atta::ui { @@ -20,4 +20,4 @@ class SensorDrawer { } // namespace atta::ui -#endif // ATTA_UI_EDITOR_DRAWERS_SENSOR_DRAWER_H +#endif // ATTA_UI_DRAWERS_SENSOR_DRAWER_H diff --git a/src/atta/ui/editor.h b/src/atta/ui/editor.h index 5253029d..c15ff580 100644 --- a/src/atta/ui/editor.h +++ b/src/atta/ui/editor.h @@ -8,8 +8,8 @@ #define ATTA_UI_EDITOR_H #include -#include -#include +#include +#include #include #include #include From 3c94830d18b9ba15dc769aedbc5abb9029e2e2fb Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Sun, 19 Jan 2025 07:23:40 +0100 Subject: [PATCH 26/37] Refactor: Move viewports to UI module --- src/atta/file/project/projectSerializer.cpp | 1 + .../project/projectSerializerDeserialize.cpp | 10 +-- .../project/projectSerializerSerialize.cpp | 4 +- src/atta/graphics/CMakeLists.txt | 1 - src/atta/graphics/compute/entityClick.cpp | 10 +-- src/atta/graphics/compute/entityClick.h | 5 +- src/atta/graphics/interface.cpp | 16 +---- src/atta/graphics/interface.h | 14 +--- src/atta/graphics/manager.cpp | 70 +----------------- src/atta/graphics/manager.h | 29 +------- src/atta/ui/CMakeLists.txt | 3 +- src/atta/ui/editor.cpp | 11 ++- src/atta/ui/editor.h | 9 ++- src/atta/ui/interface.cpp | 4 ++ src/atta/ui/interface.h | 4 ++ src/atta/ui/manager.cpp | 11 ++- src/atta/ui/manager.h | 5 ++ src/atta/ui/panels/toolBar/toolBar.cpp | 6 +- src/atta/ui/windows/entityWindow.cpp | 2 - src/atta/ui/windows/entityWindow.h | 2 - src/atta/ui/windows/graphicsModuleWindow.cpp | 11 +-- .../windows/viewport}/viewport.cpp | 68 +++++++++--------- .../windows/viewport}/viewport.h | 30 ++++---- .../{ => viewport}/viewportWindows.cpp | 72 +++++++++++++++++-- .../ui/windows/viewport/viewportWindows.h | 48 +++++++++++++ src/atta/ui/windows/viewportWindows.h | 24 ------- 26 files changed, 233 insertions(+), 237 deletions(-) rename src/atta/{graphics => ui/windows/viewport}/viewport.cpp (70%) rename src/atta/{graphics => ui/windows/viewport}/viewport.h (65%) rename src/atta/ui/windows/{ => viewport}/viewportWindows.cpp (83%) create mode 100644 src/atta/ui/windows/viewport/viewportWindows.h delete mode 100644 src/atta/ui/windows/viewportWindows.h diff --git a/src/atta/file/project/projectSerializer.cpp b/src/atta/file/project/projectSerializer.cpp index 16658d9f..30d58357 100644 --- a/src/atta/file/project/projectSerializer.cpp +++ b/src/atta/file/project/projectSerializer.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include diff --git a/src/atta/file/project/projectSerializerDeserialize.cpp b/src/atta/file/project/projectSerializerDeserialize.cpp index 1c792bd0..75b66d20 100644 --- a/src/atta/file/project/projectSerializerDeserialize.cpp +++ b/src/atta/file/project/projectSerializerDeserialize.cpp @@ -48,7 +48,7 @@ void ProjectSerializer::deserializeComponentModule(Section& section) { void ProjectSerializer::deserializeGraphicsModule(Section& section) { if (section.contains("viewports")) { - std::vector viewports = std::vector(section["viewports"]); + std::vector viewports = std::vector(section["viewports"]); LOG_WARN("file::ProjectSerializer", "Deserializing viewports was not implemented yet"); // graphics::clearViewports(); // for (auto& viewport : viewports) { @@ -59,10 +59,10 @@ void ProjectSerializer::deserializeGraphicsModule(Section& section) { } if (section.contains("graphicsFPS")) graphics::setGraphicsFPS(float(section["graphicsFPS"])); - if (section.contains("viewportFPS")) - graphics::setViewportFPS(float(section["viewportFPS"])); - if (section.contains("viewportRendering")) - graphics::setViewportRendering(bool(section["viewportRendering"])); + //if (section.contains("viewportFPS")) + // graphics::setViewportFPS(float(section["viewportFPS"])); + //if (section.contains("viewportRendering")) + // graphics::setViewportRendering(bool(section["viewportRendering"])); } void ProjectSerializer::deserializeResourceModule(Section& section) { diff --git a/src/atta/file/project/projectSerializerSerialize.cpp b/src/atta/file/project/projectSerializerSerialize.cpp index df3bdee8..4e78072b 100644 --- a/src/atta/file/project/projectSerializerSerialize.cpp +++ b/src/atta/file/project/projectSerializerSerialize.cpp @@ -66,8 +66,8 @@ void ProjectSerializer::serializeGraphicsModule(Section& section) { // section["viewports"] = viewports; LOG_WARN("file::ProjectSerializer", "Serializing viewports was not implemented yet"); section["graphicsFPS"] = graphics::getGraphicsFPS(); - section["viewportFPS"] = graphics::getViewportFPS(); - section["viewportRendering"] = graphics::getViewportRendering(); + // section["viewportFPS"] = graphics::getViewportFPS(); + // section["viewportRendering"] = graphics::getViewportRendering(); } void ProjectSerializer::serializeResourceModule(Section& section) { diff --git a/src/atta/graphics/CMakeLists.txt b/src/atta/graphics/CMakeLists.txt index e052f23c..c94cf74d 100644 --- a/src/atta/graphics/CMakeLists.txt +++ b/src/atta/graphics/CMakeLists.txt @@ -44,7 +44,6 @@ set(ATTA_GRAPHICS_MODULE_SOURCE renderQueue.cpp shader.cpp vertexBuffer.cpp - viewport.cpp ) if(ATTA_VULKAN_SUPPORT) diff --git a/src/atta/graphics/compute/entityClick.cpp b/src/atta/graphics/compute/entityClick.cpp index 8c8f9a87..53db9611 100644 --- a/src/atta/graphics/compute/entityClick.cpp +++ b/src/atta/graphics/compute/entityClick.cpp @@ -45,11 +45,11 @@ EntityClick::EntityClick() : _width(500), _height(500) { _geometryPipeline = graphics::create(pipelineInfo); } -component::EntityId EntityClick::click(std::shared_ptr viewport, vec2i pos) { +component::EntityId EntityClick::click(std::shared_ptr renderer, std::shared_ptr camera, vec2i pos) { component::EntityId eid = -1; component::EntityId maxEid = -1; - unsigned width = viewport->getWidth(); - unsigned height = viewport->getHeight(); + unsigned width = renderer->getWidth(); + unsigned height = renderer->getHeight(); // Resize if (width != _width || height != _height) { _geometryPipeline->resize(width, height); @@ -69,8 +69,8 @@ component::EntityId EntityClick::click(std::shared_ptr viewport, vec2i { // Render entities with eid std::vector entities = component::getNoPrototypeView(); - _geometryPipeline->setMat4("projection", viewport->getCamera()->getProj()); - _geometryPipeline->setMat4("view", viewport->getCamera()->getView()); + _geometryPipeline->setMat4("projection", camera->getProj()); + _geometryPipeline->setMat4("view", camera->getView()); for (auto entity : entities) { component::Mesh* mesh = component::getComponent(entity); diff --git a/src/atta/graphics/compute/entityClick.h b/src/atta/graphics/compute/entityClick.h index 832a512c..9ba93633 100644 --- a/src/atta/graphics/compute/entityClick.h +++ b/src/atta/graphics/compute/entityClick.h @@ -8,9 +8,10 @@ #define ATTA_GRAPHICS_COMPUTE_ENTITY_CLICK_H #include +#include #include #include -#include +#include #include namespace atta::graphics { @@ -19,7 +20,7 @@ class EntityClick { public: EntityClick(); - component::EntityId click(std::shared_ptr viewport, vec2i pos); + component::EntityId click(std::shared_ptr renderer, std::shared_ptr camera, vec2i pos); private: uint32_t _width; diff --git a/src/atta/graphics/interface.cpp b/src/atta/graphics/interface.cpp index ec6cec22..5243d840 100644 --- a/src/atta/graphics/interface.cpp +++ b/src/atta/graphics/interface.cpp @@ -23,26 +23,12 @@ void setGraphicsAPI(GraphicsAPI::Type type) { Manager::getInstance().setGraphics //----- Config -----// float getGraphicsFPS() { return Manager::getInstance()._graphicsFPS; } void setGraphicsFPS(float graphicsFPS) { Manager::getInstance()._graphicsFPS = graphicsFPS; } -float getViewportFPS() { return Manager::getInstance()._viewportFPS; } -void setViewportFPS(float viewportFPS) { Manager::getInstance()._viewportFPS = viewportFPS; } -bool getViewportRendering() { return Manager::getInstance()._viewportRendering; } -void setViewportRendering(bool viewportRendering) { Manager::getInstance()._viewportRendering = viewportRendering; } //----- UI -----// +void setUiRenderViewportsFunc(std::function uiRenderViewportsFunc) { Manager::getInstance()._uiRenderViewportsFunc = uiRenderViewportsFunc; } void setUiRenderFunc(std::function uiRenderFunc) { Manager::getInstance()._uiRenderFunc = uiRenderFunc; } void setUiShutDownFunc(std::function uiShutDownFunc) { Manager::getInstance()._uiShutDownFunc = uiShutDownFunc; } void setUiStartUpFunc(std::function uiStartUpFunc) { Manager::getInstance()._uiStartUpFunc = uiStartUpFunc; } - -//----- Viewport -----// -// std::vector> getViewports() { return Manager::getInstance().getViewportsImpl(); } -// void clearViewports() { Manager::getInstance().clearViewportsImpl(); } -// void addViewport(std::shared_ptr viewport) { Manager::getInstance().addViewportImpl(viewport); } -// void removeViewport(std::shared_ptr viewport) { Manager::getInstance().removeViewportImpl(viewport); } -// void createDefaultViewports() { return Manager::getInstance().createDefaultViewportsImpl(); } -// component::EntityId viewportEntityClick(std::shared_ptr viewport, vec2i pos) { -// return Manager::getInstance().viewportEntityClickImpl(viewport, pos); -//} - void* getImGuiImage(StringId sid) { return Manager::getInstance().getImGuiImageImpl(sid); } } // namespace atta::graphics diff --git a/src/atta/graphics/interface.h b/src/atta/graphics/interface.h index da2d8825..aaab2dd8 100644 --- a/src/atta/graphics/interface.h +++ b/src/atta/graphics/interface.h @@ -9,7 +9,6 @@ #include #include -#include #include namespace atta::graphics { @@ -35,23 +34,12 @@ void setGraphicsAPI(GraphicsAPI::Type type); //----- Config -----// float getGraphicsFPS(); void setGraphicsFPS(float graphicsFPS); -float getViewportFPS(); -void setViewportFPS(float viewportFPS); -bool getViewportRendering(); -void setViewportRendering(bool viewportRendering); //----- UI -----// +void setUiRenderViewportsFunc(std::function uiRenderViewportsFunc); void setUiRenderFunc(std::function uiRenderFunc); void setUiShutDownFunc(std::function uiShutDownFunc); void setUiStartUpFunc(std::function uiStartUpFunc); - -//----- Viewport -----// -// std::vector> getViewports(); -// void clearViewports(); -// void addViewport(std::shared_ptr viewport); -// void removeViewport(std::shared_ptr viewport); -// void createDefaultViewports(); -// component::EntityId viewportEntityClick(std::shared_ptr viewport, vec2i pos); void* getImGuiImage(StringId sid); } // namespace atta::graphics diff --git a/src/atta/graphics/manager.cpp b/src/atta/graphics/manager.cpp index df38961d..cbe2d1bf 100644 --- a/src/atta/graphics/manager.cpp +++ b/src/atta/graphics/manager.cpp @@ -59,8 +59,6 @@ void Manager::startUpImpl() { //----- Config -----// _graphicsFPS = 30.0f; - _viewportFPS = 30.0f; - _viewportRendering = true; //----- Window -----// Window::CreateInfo windowInfo{}; @@ -83,12 +81,6 @@ void Manager::startUpImpl() { event::subscribe(BIND_EVENT_FUNC(Manager::onImageLoadEvent)); event::subscribe(BIND_EVENT_FUNC(Manager::onImageUpdateEvent)); syncResources(); - - //----- Compute Shaders -----// - _computeEntityClick = std::make_unique(); - - //----- Create viewports -----// - // createDefaultViewportsImpl(); } void Manager::shutDownImpl() { @@ -100,15 +92,6 @@ void Manager::shutDownImpl() { _graphicsAPI->waitDevice(); - // Every reference to the framebuffers must be deleted before window deletion - for (auto& viewport : _viewports) - viewport.reset(); - _viewports.clear(); - for (auto& viewport : _viewportsNext) - viewport.reset(); - _viewportsNext.clear(); - - _computeEntityClick.reset(); _meshes.clear(); _images.clear(); _graphicsAPI->shutDown(); @@ -127,18 +110,12 @@ void Manager::updateImpl() { if (_graphicsFPS > 0 && (gfxTimeDiff > 1 / _graphicsFPS)) { gfxLastTime = gfxCurrTime; - // Update viewports if it was changed - if (_swapViewports) { - _viewports = _viewportsNext; - _swapViewports = false; - } - // Update window events _window->update(); - // Render viewports - for (const auto& viewport : _viewports) - viewport->render(); + // Render UI viewports + if (_uiRenderViewportsFunc) + _uiRenderViewportsFunc(); // Render UI _graphicsAPI->beginFrame(); @@ -171,47 +148,6 @@ void Manager::recreateGraphicsAPI() { _uiStartUpFunc(); } -// std::vector>& Manager::getViewportsImpl() { return _viewports; } - -// void Manager::clearViewportsImpl() { -// _viewportsNext.clear(); -// _swapViewports = true; -// } -// -// void Manager::addViewportImpl(std::shared_ptr viewport) { -// _viewportsNext.push_back(viewport); -// _swapViewports = true; -// } -// -// void Manager::removeViewportImpl(std::shared_ptr viewport) { -// // TODO make it work with zero viewports -// if (_viewportsNext.size() > 1) { -// for (unsigned i = 0; i < _viewportsNext.size(); i++) -// if (_viewportsNext[i] == viewport) { -// _viewportsNext.erase(_viewportsNext.begin() + i); -// break; -// } -// _swapViewports = true; -// } else { -// LOG_WARN("graphics::Manager", "It is not possible to have 0 viewports yet"); -// } -// } -// -// void Manager::createDefaultViewportsImpl() { -// _viewportsNext.clear(); -// -// Viewport::CreateInfo viewportInfo; -// viewportInfo.renderer = std::make_shared(); -// viewportInfo.camera = std::make_shared(PerspectiveCamera::CreateInfo{}); -// viewportInfo.sid = StringId("Main Viewport"); -// _viewportsNext.push_back(std::make_shared(viewportInfo)); -// _swapViewports = true; -// } -// -// component::EntityId Manager::viewportEntityClickImpl(std::shared_ptr viewport, vec2i pos) { -// return _computeEntityClick->click(viewport, pos); -// } - void* Manager::getImGuiImageImpl(StringId sid) { return _images[sid]->getImGuiImage(); } gfx::Image::Format Manager::convertFormat(res::Image::Format format) const { diff --git a/src/atta/graphics/manager.h b/src/atta/graphics/manager.h index 211632b9..4208071b 100644 --- a/src/atta/graphics/manager.h +++ b/src/atta/graphics/manager.h @@ -7,7 +7,6 @@ #ifndef ATTA_GRAPHICS_GRAPHICS_MANAGER_H #define ATTA_GRAPHICS_GRAPHICS_MANAGER_H -#include #include #include #include @@ -36,23 +35,14 @@ class Manager final { friend float getGraphicsFPS(); friend void setGraphicsFPS(float graphicsFPS); - friend float getViewportFPS(); - friend void setViewportFPS(float viewportFPS); - friend bool getViewportRendering(); - friend void setViewportRendering(bool viewportRendering); + friend void setUiRenderViewportsFunc(std::function uiRenderViewportsFunc); friend void setUiRenderFunc(std::function uiRenderFunc); friend void setUiStartUpFunc(std::function uiStartUpFunc); friend void setUiShutDownFunc(std::function uiShutDownFunc); friend std::shared_ptr getGraphicsAPI(); friend std::shared_ptr getWindow(); - // friend std::vector> getViewports(); - // friend void clearViewports(); - // friend void addViewport(std::shared_ptr viewport); - // friend void removeViewport(std::shared_ptr viewport); - // friend void createDefaultViewports(); - // friend component::EntityId viewportEntityClick(std::shared_ptr viewport, vec2i pos); friend void* getImGuiImage(StringId sid); const std::unordered_map>& getMeshes() const; @@ -74,12 +64,6 @@ class Manager final { void setGraphicsAPIImpl(GraphicsAPI::Type type); void recreateGraphicsAPI(); - std::vector>& getViewportsImpl(); - // void clearViewportsImpl(); - // void addViewportImpl(std::shared_ptr viewport); - // void removeViewportImpl(std::shared_ptr viewport); - // void createDefaultViewportsImpl(); - // component::EntityId viewportEntityClickImpl(std::shared_ptr viewport, vec2i pos); void* getImGuiImageImpl(StringId sid); gfx::Image::Format convertFormat(res::Image::Format format) const; @@ -106,19 +90,10 @@ class Manager final { std::unordered_map> _images; // UI + std::function _uiRenderViewportsFunc; std::function _uiRenderFunc; std::function _uiStartUpFunc; ///< Used to restart UI when graphics API changes std::function _uiShutDownFunc; ///< Used to restart UI when graphics API changes - - // Viewports - std::vector> _viewports; - std::vector> _viewportsNext; ///< Being used for now to update the viewports in the next frame without breaking imgui - bool _swapViewports; ///< If _viewports should be swapped - float _viewportFPS; ///< Desired viewport FPS (UI module handles the viewport rendering) - bool _viewportRendering; ///< If should render the viewport - - // Compute - std::unique_ptr _computeEntityClick; }; } // namespace atta::graphics diff --git a/src/atta/ui/CMakeLists.txt b/src/atta/ui/CMakeLists.txt index 3f466ec1..1e062e14 100644 --- a/src/atta/ui/CMakeLists.txt +++ b/src/atta/ui/CMakeLists.txt @@ -19,13 +19,14 @@ set(ATTA_UI_MODULE_SOURCE windows/timeProfiler/components/flameGraph.cpp windows/timeProfiler/components/timeline.cpp windows/utils/fileSelectionWindow.cpp + windows/viewport/viewport.cpp + windows/viewport/viewportWindows.cpp windows/entityWindow.cpp windows/graphicsModuleWindow.cpp windows/ioModuleWindow.cpp windows/logWindow.cpp windows/physicsModuleWindow.cpp windows/sensorModuleWindow.cpp - windows/viewportWindows.cpp windows/window.cpp interface.cpp diff --git a/src/atta/ui/editor.cpp b/src/atta/ui/editor.cpp index be6adad4..a0cc28d7 100644 --- a/src/atta/ui/editor.cpp +++ b/src/atta/ui/editor.cpp @@ -26,6 +26,12 @@ namespace atta::ui { +void Editor::startUp() { _viewportWindows.startUp(); } + +void Editor::shutDown() { _viewportWindows.shutDown(); } + +void Editor::renderViewports() { _viewportWindows.renderViewports(); } + void Editor::render() { PROFILE(); setupDocking(); @@ -47,7 +53,7 @@ void Editor::render() { // Windows _entityWindow.render(); _logWindow.render(); - _viewportWindows.render(); + _viewportWindows.renderUI(); // Module windows GraphicsModuleWindow::render(); @@ -76,6 +82,9 @@ void Editor::render() { } } +bool Editor::getViewportRendering() const { return _viewportWindows.getViewportRendering(); } +void Editor::setViewportRendering(bool viewportRendering) { _viewportWindows.setViewportRendering(viewportRendering); } + void Editor::setupDocking() { //----- Create DockSpace -----// const ImGuiViewport* viewport = ImGui::GetMainViewport(); diff --git a/src/atta/ui/editor.h b/src/atta/ui/editor.h index c15ff580..a7299066 100644 --- a/src/atta/ui/editor.h +++ b/src/atta/ui/editor.h @@ -14,14 +14,21 @@ #include #include #include -#include +#include namespace atta::ui { class Editor final { public: + void startUp(); + void shutDown(); + + void renderViewports(); void render(); + bool getViewportRendering() const; + void setViewportRendering(bool viewportRendering); + unsigned getViewportDockId() { return _viewportDockId; } private: diff --git a/src/atta/ui/interface.cpp b/src/atta/ui/interface.cpp index fd2e0bf7..fa374400 100644 --- a/src/atta/ui/interface.cpp +++ b/src/atta/ui/interface.cpp @@ -12,4 +12,8 @@ namespace atta::ui { void startUp() { Manager::getInstance().startUpImpl(); } void shutDown() { Manager::getInstance().shutDownImpl(); } +//----- Viewport -----// +bool getViewportRendering() { return Manager::getInstance().getViewportRenderingImpl(); } +void setViewportRendering(bool viewportRendering) { Manager::getInstance().setViewportRenderingImpl(viewportRendering); } + } // namespace atta::ui diff --git a/src/atta/ui/interface.h b/src/atta/ui/interface.h index 3c2191dd..c8c205e4 100644 --- a/src/atta/ui/interface.h +++ b/src/atta/ui/interface.h @@ -12,6 +12,10 @@ namespace atta::ui { void startUp(); void shutDown(); +//----- Viewport -----// +bool getViewportRendering(); +void setViewportRendering(bool viewportRendering); + } // namespace atta::ui #endif // ATTA_UI_INTERFACE_H diff --git a/src/atta/ui/manager.cpp b/src/atta/ui/manager.cpp index c5ff4d44..8bd83b0c 100644 --- a/src/atta/ui/manager.cpp +++ b/src/atta/ui/manager.cpp @@ -62,18 +62,22 @@ void Manager::startUpImpl() { } setTheme(); + gfx::setUiRenderViewportsFunc([&]() { _editor.renderViewports(); }); gfx::setUiRenderFunc([&]() { render(); }); gfx::setUiShutDownFunc([&]() { shutDownImpl(); }); gfx::setUiStartUpFunc([&]() { startUpImpl(); }); - // Create editor window - _editor = {}; + // Start up editor window + _editor.startUp(); } void Manager::shutDownImpl() { // Make sure all rendering operations are done gfx::getGraphicsAPI()->waitDevice(); + // Destroy editor + _editor.shutDown(); + // Destroy plotting contexts ImPlot3D::DestroyContext(); ImPlot::DestroyContext(); @@ -93,6 +97,9 @@ void Manager::shutDownImpl() { ImGui::DestroyContext(); } +bool Manager::getViewportRenderingImpl() const { return _editor.getViewportRendering(); } +void Manager::setViewportRenderingImpl(bool viewportRendering) { _editor.setViewportRendering(viewportRendering); } + void Manager::setTheme() { ImGuiStyle& style = ImGui::GetStyle(); diff --git a/src/atta/ui/manager.h b/src/atta/ui/manager.h index 233d5b82..ae1de9cc 100644 --- a/src/atta/ui/manager.h +++ b/src/atta/ui/manager.h @@ -18,11 +18,16 @@ class Manager final { friend void startUp(); friend void shutDown(); + friend bool getViewportRendering(); + friend void setViewportRendering(bool viewportRendering); private: void startUpImpl(); void shutDownImpl(); + bool getViewportRenderingImpl() const; + void setViewportRenderingImpl(bool viewportRendering); + void setTheme(); void initOpenGL(); void initVulkan(); diff --git a/src/atta/ui/panels/toolBar/toolBar.cpp b/src/atta/ui/panels/toolBar/toolBar.cpp index 721ea841..745ba950 100644 --- a/src/atta/ui/panels/toolBar/toolBar.cpp +++ b/src/atta/ui/panels/toolBar/toolBar.cpp @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include #include @@ -39,8 +39,8 @@ void ToolBar::render() { // View button { - if (ui::imageButton(graphics::getViewportRendering() ? "icons/view.png" : "icons/no-view.png", buttonH)) - graphics::setViewportRendering(!graphics::getViewportRendering()); + if (ui::imageButton(ui::getViewportRendering() ? "icons/view.png" : "icons/no-view.png", buttonH)) + ui::setViewportRendering(!ui::getViewportRendering()); ImGui::SameLine(); ImGui::Dummy(ImVec2(10.0f, 0.0f)); } diff --git a/src/atta/ui/windows/entityWindow.cpp b/src/atta/ui/windows/entityWindow.cpp index 88236631..cd684fda 100644 --- a/src/atta/ui/windows/entityWindow.cpp +++ b/src/atta/ui/windows/entityWindow.cpp @@ -15,8 +15,6 @@ namespace atta::ui { -EntityWindow::EntityWindow() {} - void EntityWindow::render() { ImGui::Begin("Scene"); { diff --git a/src/atta/ui/windows/entityWindow.h b/src/atta/ui/windows/entityWindow.h index ad3e14d3..88f60e40 100644 --- a/src/atta/ui/windows/entityWindow.h +++ b/src/atta/ui/windows/entityWindow.h @@ -13,8 +13,6 @@ namespace atta::ui { class EntityWindow { public: - EntityWindow(); - void render(); private: diff --git a/src/atta/ui/windows/graphicsModuleWindow.cpp b/src/atta/ui/windows/graphicsModuleWindow.cpp index 4c873c60..9804d4cb 100644 --- a/src/atta/ui/windows/graphicsModuleWindow.cpp +++ b/src/atta/ui/windows/graphicsModuleWindow.cpp @@ -17,10 +17,9 @@ GraphicsModuleWindow::GraphicsModuleWindow() { void GraphicsModuleWindow::renderImpl() { // Graphics API control - const char* graphicsAPIs[] = { - "OpenGL", + const char* graphicsAPIs[] = {"OpenGL", #if ATTA_VULKAN_SUPPORT - "Vulkan" + "Vulkan" #endif }; int currentGraphicsAPI = int(graphics::getGraphicsAPI()->getType()); @@ -29,14 +28,8 @@ void GraphicsModuleWindow::renderImpl() { // Rendering control float graphicsFPS = graphics::getGraphicsFPS(); - float viewportFPS = graphics::getViewportFPS(); - bool viewportRendering = graphics::getViewportRendering(); if (ImGui::DragFloat("Graphics FPS", &graphicsFPS, 0.1f, 10.0f, 60.0f, "%.1f") && graphicsFPS >= 10.0f) graphics::setGraphicsFPS(graphicsFPS); - if (ImGui::DragFloat("Viewport FPS", &viewportFPS, 0.1f, 0.01f, graphicsFPS, "%.1f") && viewportFPS >= 0.01f) - graphics::setViewportFPS(viewportFPS); - if (ImGui::Checkbox("Viewport rendering", &viewportRendering)) - graphics::setViewportRendering(viewportRendering); } } // namespace atta::ui diff --git a/src/atta/graphics/viewport.cpp b/src/atta/ui/windows/viewport/viewport.cpp similarity index 70% rename from src/atta/graphics/viewport.cpp rename to src/atta/ui/windows/viewport/viewport.cpp index a604a66f..28635a1e 100644 --- a/src/atta/graphics/viewport.cpp +++ b/src/atta/ui/windows/viewport/viewport.cpp @@ -1,5 +1,5 @@ //-------------------------------------------------- -// Atta Graphics Module +// Atta UI Module // viewport.cpp // Date: 2021-09-14 // By Breno Cunha Queiroz @@ -10,10 +10,10 @@ #include #include #include -#include +#include #include -namespace atta::graphics { +namespace atta::ui { Viewport::Viewport() : Viewport(CreateInfo{}) {} @@ -77,20 +77,20 @@ void Viewport::deserialize(std::istream& is) { std::string rendererName; file::read(is, rendererName); if (rendererName == "FastRenderer") { - _renderer = std::make_shared(); + _renderer = std::make_shared(); _renderer->deserialize(is); } else if (rendererName == "PhongRenderer") { - _renderer = std::make_shared(); + _renderer = std::make_shared(); _renderer->deserialize(is); } else if (rendererName == "PbrRenderer") { - _renderer = std::make_shared(); + _renderer = std::make_shared(); _renderer->deserialize(is); } else if (rendererName.size() == 0) { LOG_WARN("graphics::Viewport", "No renderer deserialized, using default renderer"); - _renderer = std::make_shared(); + _renderer = std::make_shared(); } else { LOG_WARN("graphics::Viewport", "Unknown renderer [w]$0[] when deserializing", rendererName); - _renderer = std::make_shared(); + _renderer = std::make_shared(); _renderer->deserialize(is); } @@ -98,24 +98,24 @@ void Viewport::deserialize(std::istream& is) { std::string cameraName; file::read(is, cameraName); if (cameraName == "OrthographicCamera") { - _camera = std::make_shared(OrthographicCamera::CreateInfo{}); + _camera = std::make_shared(gfx::OrthographicCamera::CreateInfo{}); _camera->deserialize(is); } else if (cameraName == "PerspectiveCamera") { - _camera = std::make_shared(PerspectiveCamera::CreateInfo{}); + _camera = std::make_shared(gfx::PerspectiveCamera::CreateInfo{}); _camera->deserialize(is); } else if (cameraName.size() == 0) { LOG_WARN("graphics::Viewport", "No camera deserialized, using default camera"); - _camera = std::make_shared(PerspectiveCamera::CreateInfo{}); + _camera = std::make_shared(gfx::PerspectiveCamera::CreateInfo{}); } else { LOG_WARN("graphics::Viewport", "Unknown camera [w]$0[] when deserializing. This may break the serialization", cameraName); - _camera = std::make_shared(PerspectiveCamera::CreateInfo{}); + _camera = std::make_shared(gfx::PerspectiveCamera::CreateInfo{}); } } void Viewport::renderUI() { //---------- Name ----------// ImGui::Text("Name"); - ImGui::InputText(("##ViewportName" + _sid.getString()).c_str(), _inputText, sizeof(_inputText)/sizeof(char)); + ImGui::InputText(("##ViewportName" + _sid.getString()).c_str(), _inputText, sizeof(_inputText) / sizeof(char)); _name = std::string(_inputText); //---------- Renderer ----------// @@ -135,18 +135,18 @@ void Viewport::renderUI() { for (size_t j = 0; j < renderers.size(); j++) { if (ImGui::Selectable(renderers[j], comboValue == j)) { switch (j) { - case 0: - if (comboValue != 0) - setRenderer(std::static_pointer_cast(std::make_shared())); - break; - case 1: - if (comboValue != 1) - setRenderer(std::static_pointer_cast(std::make_shared())); - break; - case 2: - if (comboValue != 2) - setRenderer(std::static_pointer_cast(std::make_shared())); - break; + case 0: + if (comboValue != 0) + setRenderer(std::static_pointer_cast(std::make_shared())); + break; + case 1: + if (comboValue != 1) + setRenderer(std::static_pointer_cast(std::make_shared())); + break; + case 2: + if (comboValue != 2) + setRenderer(std::static_pointer_cast(std::make_shared())); + break; } } if (comboValue == j) @@ -173,14 +173,14 @@ void Viewport::renderUI() { for (size_t j = 0; j < cameras.size(); j++) { if (ImGui::Selectable(cameras[j], comboValue == j)) { switch (j) { - case 0: - if (comboValue != 0) - setCamera(std::make_shared(OrthographicCamera::CreateInfo{})); - break; - case 1: - if (comboValue != 1) - setCamera(std::make_shared(PerspectiveCamera::CreateInfo{})); - break; + case 0: + if (comboValue != 0) + setCamera(std::make_shared(gfx::OrthographicCamera::CreateInfo{})); + break; + case 1: + if (comboValue != 1) + setCamera(std::make_shared(gfx::PerspectiveCamera::CreateInfo{})); + break; } } if (comboValue == j) @@ -191,4 +191,4 @@ void Viewport::renderUI() { _camera->renderUI(); } -} // namespace atta::graphics +} // namespace atta::ui diff --git a/src/atta/graphics/viewport.h b/src/atta/ui/windows/viewport/viewport.h similarity index 65% rename from src/atta/graphics/viewport.h rename to src/atta/ui/windows/viewport/viewport.h index 040ac5d7..c73a4e44 100644 --- a/src/atta/graphics/viewport.h +++ b/src/atta/ui/windows/viewport/viewport.h @@ -1,25 +1,25 @@ //-------------------------------------------------- -// Atta Graphics Module +// Atta UI Module // viewport.h // Date: 2021-09-14 // By Breno Cunha Queiroz //-------------------------------------------------- -#ifndef ATTA_GRAPHICS_VIEWPORT_H -#define ATTA_GRAPHICS_VIEWPORT_H +#ifndef ATTA_UI_WINDOWS_VIEWPORT_VIEWPORT_H +#define ATTA_UI_WINDOWS_VIEWPORT_VIEWPORT_H #include #include #include #include -namespace atta::graphics { +namespace atta::ui { class Viewport final : public file::Serializable { public: struct CreateInfo { StringId sid = StringId("Unnamed viewport"); - std::shared_ptr renderer = nullptr; - std::shared_ptr camera = nullptr; + std::shared_ptr renderer = nullptr; + std::shared_ptr camera = nullptr; std::string name; }; Viewport(); @@ -35,11 +35,11 @@ class Viewport final : public file::Serializable { uint32_t getHeight() const { return _renderer->getHeight(); } void* getImGuiTexture() const { return _renderer->getImGuiTexture(); } - std::shared_ptr getRenderer() const { return _renderer; } - std::shared_ptr getCamera() const { return _camera; } + std::shared_ptr getRenderer() const { return _renderer; } + std::shared_ptr getCamera() const { return _camera; } - void setRenderer(std::shared_ptr renderer) { _newRenderer = renderer; } - void setCamera(std::shared_ptr camera) { _camera = camera; } + void setRenderer(std::shared_ptr renderer) { _newRenderer = renderer; } + void setCamera(std::shared_ptr camera) { _camera = camera; } // Serializable void serialize(std::ostream& os) override; @@ -50,17 +50,17 @@ class Viewport final : public file::Serializable { private: StringId _sid; - std::shared_ptr _renderer; + std::shared_ptr _renderer; // If want to change the renderer, store new renderer in _newRenderer until next frame to avoid destroying current renderer that can still be in // use - std::shared_ptr _newRenderer; - std::shared_ptr _camera; + std::shared_ptr _newRenderer; + std::shared_ptr _camera; // UI std::string _name; char _inputText[50]; }; -} // namespace atta::graphics +} // namespace atta::ui -#endif // ATTA_GRAPHICS_VIEWPORT_H +#endif // ATTA_UI_WINDOWS_VIEWPORT_VIEWPORT_H diff --git a/src/atta/ui/windows/viewportWindows.cpp b/src/atta/ui/windows/viewport/viewportWindows.cpp similarity index 83% rename from src/atta/ui/windows/viewportWindows.cpp rename to src/atta/ui/windows/viewport/viewportWindows.cpp index 152104df..dd7c8f06 100644 --- a/src/atta/ui/windows/viewportWindows.cpp +++ b/src/atta/ui/windows/viewport/viewportWindows.cpp @@ -11,26 +11,45 @@ #include #include #include +#include #include +#include #include #include -#include +#include #include #include namespace atta::ui { -void ViewportWindows::render() { +void ViewportWindows::startUp() { + _computeEntityClick = std::make_unique(); + createDefaultViewports(); +} + +void ViewportWindows::shutDown() { + _computeEntityClick.reset(); + _viewports.clear(); + _viewportsNext.clear(); +} + +void ViewportWindows::renderViewports() { + PROFILE(); + if (_viewportRendering) + for (auto& viewport : _viewports) + viewport->render(); +} + +void ViewportWindows::renderUI() { PROFILE(); - // std::vector> viewports = graphics::getViewports(); static int activeViewport = 0; // Viewports fps static clock_t vpLastTime = std::clock(); const clock_t vpCurrTime = std::clock(); const float vpTimeDiff = float(vpCurrTime - vpLastTime) / CLOCKS_PER_SEC; - if (graphics::getViewportRendering() && (graphics::getViewportFPS() > 0 && (vpTimeDiff > 1 / graphics::getViewportFPS()))) { + if (_viewportRendering && (_viewportFPS > 0 && (vpTimeDiff > 1 / _viewportFPS))) { vpLastTime = vpCurrTime; } @@ -125,7 +144,8 @@ void ViewportWindows::render() { // // snapValue = 45.0f; // // float snapValues[3] = {snapValue, snapValue, snapValue}; - // // ImGuizmo::Manipulate(view.data, proj.data, mouseOperation, mouseMode, transform.data, nullptr, snap ? snapValues : nullptr); + // // ImGuizmo::Manipulate(view.data, proj.data, mouseOperation, mouseMode, transform.data, nullptr, snap ? snapValues : + // nullptr); // // if (ImGuizmo::IsUsing()) { // // imGuizmoUsingMouse = true; @@ -192,7 +212,7 @@ void ViewportWindows::render() { // // //----- Mouse click selection -----// // // if (!imGuizmoUsingMouse) { // // if (click.x >= 0 && click.y >= 0 && click.x < (int)viewport->getWidth() && click.y < (int)viewport->getHeight()) { - // // component::EntityId eid = graphics::viewportEntityClick(viewport, click); + // // component::EntityId eid = _computeEntityClick(viewport->getRenderer(), viewport->getCamera(), click); // // component::setSelectedEntity(eid); // // } // // } @@ -210,6 +230,43 @@ void ViewportWindows::render() { //} } +std::vector> ViewportWindows::getViewports() { return _viewports; } + +void ViewportWindows::clearViewports() { + _viewportsNext.clear(); + _swapViewports = true; +} + +void ViewportWindows::addViewport(std::shared_ptr viewport) { + _viewportsNext.push_back(viewport); + _swapViewports = true; +} + +void ViewportWindows::removeViewport(std::shared_ptr viewport) { + // TODO make it work with zero viewports + if (_viewportsNext.size() > 1) { + for (unsigned i = 0; i < _viewportsNext.size(); i++) + if (_viewportsNext[i] == viewport) { + _viewportsNext.erase(_viewportsNext.begin() + i); + break; + } + _swapViewports = true; + } else { + LOG_WARN("ui::ViewportWindows", "It is not possible to have 0 viewports yet"); + } +} + +void ViewportWindows::createDefaultViewports() { + _viewportsNext.clear(); + + Viewport::CreateInfo viewportInfo; + viewportInfo.renderer = std::make_shared(); + viewportInfo.camera = std::make_shared(gfx::PerspectiveCamera::CreateInfo{}); + viewportInfo.sid = StringId("Main Viewport"); + _viewportsNext.push_back(std::make_shared(viewportInfo)); + _swapViewports = true; +} + void ViewportWindows::addBasicShapePopup() { if (ImGui::BeginPopup("Editor_AddBasicShape")) { std::string basicShapes[] = {"Cube", "Sphere", "Cylinder", "Triangle", "Plane", "Disk"}; @@ -238,4 +295,7 @@ void ViewportWindows::addBasicShapePopup() { } } +bool ViewportWindows::getViewportRendering() const { return _viewportRendering; } +void ViewportWindows::setViewportRendering(bool viewportRendering) { _viewportRendering = viewportRendering; } + } // namespace atta::ui diff --git a/src/atta/ui/windows/viewport/viewportWindows.h b/src/atta/ui/windows/viewport/viewportWindows.h new file mode 100644 index 00000000..50ccc181 --- /dev/null +++ b/src/atta/ui/windows/viewport/viewportWindows.h @@ -0,0 +1,48 @@ +//-------------------------------------------------- +// Atta UI Module +// viewportWindows.h +// Date: 2021-12-28 +// By Breno Cunha Queiroz +//-------------------------------------------------- +#ifndef ATTA_UI_WINDOWS_VIEWPORT_VIEWPORT_WINDOWS_H +#define ATTA_UI_WINDOWS_VIEWPORT_VIEWPORT_WINDOWS_H + +#include +#include +#include + +namespace atta::ui { + +class ViewportWindows { + public: + void startUp(); + void shutDown(); + + void renderViewports(); + void renderUI(); + + std::vector> getViewports(); + void clearViewports(); + void addViewport(std::shared_ptr viewport); + void removeViewport(std::shared_ptr viewport); + void createDefaultViewports(); + + bool getViewportRendering() const; + void setViewportRendering(bool viewportRendering); + + private: + void addBasicShapePopup(); + + std::vector> _viewports; ///< Current viewports to be rendered + std::vector> _viewportsNext; ///< Being used for now to update the viewports in the next frame without breaking imgui + bool _swapViewports; ///< If _viewports should be swapped + float _viewportFPS; ///< Desired viewport FPS (UI module handles the viewport rendering) + bool _viewportRendering; ///< If should render the viewport + + // Compute + std::unique_ptr _computeEntityClick; +}; + +} // namespace atta::ui + +#endif // ATTA_UI_WINDOWS_VIEWPORT_VIEWPORT_WINDOWS_H diff --git a/src/atta/ui/windows/viewportWindows.h b/src/atta/ui/windows/viewportWindows.h deleted file mode 100644 index 3fd2ca09..00000000 --- a/src/atta/ui/windows/viewportWindows.h +++ /dev/null @@ -1,24 +0,0 @@ -//-------------------------------------------------- -// Atta UI Module -// viewportWindows.h -// Date: 2021-12-28 -// By Breno Cunha Queiroz -//-------------------------------------------------- -#ifndef ATTA_UI_WINDOWS_VIEWPORT_WINDOWS_H -#define ATTA_UI_WINDOWS_VIEWPORT_WINDOWS_H - -#include - -namespace atta::ui { - -class ViewportWindows { - public: - void render(); - - private: - void addBasicShapePopup(); -}; - -} // namespace atta::ui - -#endif // ATTA_UI_WINDOWS_VIEWPORT_WINDOWS_H From 25c72496a403fc171b7f62c48908d08a7da66040 Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Sun, 19 Jan 2025 07:50:29 +0100 Subject: [PATCH 27/37] Feat: Render main viewport Fix: Camera first person move --- src/atta/graphics/cameras/camera.cpp | 48 +-- .../ui/windows/viewport/viewportWindows.cpp | 356 +++++++++--------- .../ui/windows/viewport/viewportWindows.h | 6 +- 3 files changed, 209 insertions(+), 201 deletions(-) diff --git a/src/atta/graphics/cameras/camera.cpp b/src/atta/graphics/cameras/camera.cpp index 935751a0..58847011 100644 --- a/src/atta/graphics/cameras/camera.cpp +++ b/src/atta/graphics/cameras/camera.cpp @@ -64,70 +64,70 @@ void Camera::moveFirstPerson() { // Move front/back if (ImGui::IsKeyDown(ImGuiKey_W) || ImGui::IsKeyDown(ImGuiKey_S)) { - int key = 0; + ImGuiKey key = ImGuiKey_None; - if (io.KeysData[ImGuiKey_W].DownDuration > 0 && io.KeysData[ImGuiKey_S].DownDuration > 0) - if (io.KeysData[ImGuiKey_W].DownDuration < io.KeysData[ImGuiKey_S].DownDuration) + if (ImGui::GetKeyData(ImGuiKey_W)->DownDuration > 0 && ImGui::GetKeyData(ImGuiKey_S)->DownDuration > 0) + if (ImGui::GetKeyData(ImGuiKey_W)->DownDuration < ImGui::GetKeyData(ImGuiKey_S)->DownDuration) key = ImGuiKey_W; else key = ImGuiKey_S; - else if (io.KeysData[ImGuiKey_W].DownDuration > 0) + else if (ImGui::GetKeyData(ImGuiKey_W)->DownDuration > 0) key = ImGuiKey_W; - else if (io.KeysData[ImGuiKey_S].DownDuration > 0) + else if (ImGui::GetKeyData(ImGuiKey_S)->DownDuration > 0) key = ImGuiKey_S; if (key) { - if (io.KeysData[key].DownDuration < lastTimeFront) + if (ImGui::GetKeyData(key)->DownDuration < lastTimeFront) lastTimeFront = 0; - float delta = (io.KeysData[key].DownDuration - lastTimeFront) * (key == ImGuiKey_W ? 1 : -1) * _speed; - lastTimeFront = io.KeysData[key].DownDuration; + float delta = (ImGui::GetKeyData(key)->DownDuration - lastTimeFront) * (key == ImGuiKey_W ? 1 : -1) * _speed; + lastTimeFront = ImGui::GetKeyData(key)->DownDuration; _position += _front * delta; } } // Move left/right if (ImGui::IsKeyDown(ImGuiKey_A) || ImGui::IsKeyDown(ImGuiKey_D)) { - int key = 0; - if (io.KeysData[ImGuiKey_A].DownDuration > 0 && io.KeysData[ImGuiKey_D].DownDuration > 0) - if (io.KeysData[ImGuiKey_A].DownDuration < io.KeysData[ImGuiKey_D].DownDuration) + ImGuiKey key = ImGuiKey_None; + if (ImGui::GetKeyData(ImGuiKey_A)->DownDuration > 0 && ImGui::GetKeyData(ImGuiKey_D)->DownDuration > 0) + if (ImGui::GetKeyData(ImGuiKey_A)->DownDuration < ImGui::GetKeyData(ImGuiKey_D)->DownDuration) key = ImGuiKey_A; else key = ImGuiKey_D; - else if (io.KeysData[ImGuiKey_A].DownDuration > 0) + else if (ImGui::GetKeyData(ImGuiKey_A)->DownDuration > 0) key = ImGuiKey_A; - else if (io.KeysData[ImGuiKey_D].DownDuration > 0) + else if (ImGui::GetKeyData(ImGuiKey_D)->DownDuration > 0) key = ImGuiKey_D; if (key) { - if (io.KeysData[key].DownDuration < lastTimeLeft) + if (ImGui::GetKeyData(key)->DownDuration < lastTimeLeft) lastTimeLeft = 0; - float delta = (io.KeysData[key].DownDuration - lastTimeLeft) * (key == ImGuiKey_A ? 1 : -1) * _speed; - lastTimeLeft = io.KeysData[key].DownDuration; + float delta = (ImGui::GetKeyData(key)->DownDuration - lastTimeLeft) * (key == ImGuiKey_A ? 1 : -1) * _speed; + lastTimeLeft = ImGui::GetKeyData(key)->DownDuration; _position += _left * delta; } } // Move up/down if (ImGui::IsKeyDown(ImGuiKey_E) || ImGui::IsKeyDown(ImGuiKey_Q)) { - int key = 0; - if (io.KeysData[ImGuiKey_E].DownDuration > 0 && io.KeysData[ImGuiKey_Q].DownDuration > 0) - if (io.KeysData[ImGuiKey_E].DownDuration < io.KeysData[ImGuiKey_Q].DownDuration) + ImGuiKey key = ImGuiKey_None; + if (ImGui::GetKeyData(ImGuiKey_E)->DownDuration > 0 && ImGui::GetKeyData(ImGuiKey_Q)->DownDuration > 0) + if (ImGui::GetKeyData(ImGuiKey_E)->DownDuration < ImGui::GetKeyData(ImGuiKey_Q)->DownDuration) key = ImGuiKey_E; else key = ImGuiKey_Q; - else if (io.KeysData[ImGuiKey_E].DownDuration > 0) + else if (ImGui::GetKeyData(ImGuiKey_E)->DownDuration > 0) key = ImGuiKey_E; - else if (io.KeysData[ImGuiKey_Q].DownDuration > 0) + else if (ImGui::GetKeyData(ImGuiKey_Q)->DownDuration > 0) key = ImGuiKey_Q; if (key) { - if (io.KeysData[key].DownDuration < lastTimeUp) + if (ImGui::GetKeyData(key)->DownDuration < lastTimeUp) lastTimeUp = 0; - float delta = (io.KeysData[key].DownDuration - lastTimeUp) * (key == ImGuiKey_E ? 1 : -1) * _speed; - lastTimeUp = io.KeysData[key].DownDuration; + float delta = (ImGui::GetKeyData(key)->DownDuration - lastTimeUp) * (key == ImGuiKey_E ? 1 : -1) * _speed; + lastTimeUp = ImGui::GetKeyData(key)->DownDuration; _position += _up * delta; } } diff --git a/src/atta/ui/windows/viewport/viewportWindows.cpp b/src/atta/ui/windows/viewport/viewportWindows.cpp index dd7c8f06..0fa63863 100644 --- a/src/atta/ui/windows/viewport/viewportWindows.cpp +++ b/src/atta/ui/windows/viewport/viewportWindows.cpp @@ -36,6 +36,12 @@ void ViewportWindows::shutDown() { void ViewportWindows::renderViewports() { PROFILE(); + if (_swapViewports) { + _viewports = _viewportsNext; + _viewportsNext.clear(); + _swapViewports = false; + } + if (_viewportRendering) for (auto& viewport : _viewports) viewport->render(); @@ -54,180 +60,182 @@ void ViewportWindows::renderUI() { } int i = -1; - // for (auto viewport : viewports) { - // // ImGui::DockBuilderDockWindow((viewport->getName()+"###Viewport"+viewport->getSID().getString()).c_str(), - // _dockSpace.getViewportDockId()); char nameBuf[128]; sprintf(nameBuf, "%s###Viewport%s", viewport->getName().c_str(), - // viewport->getSID().getString().c_str()); i++; - // // Render and resize - // ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(5.0f, 5.0f)); - // bool open = true; - // ImGui::Begin(nameBuf, &open); - // // if (graphics::getViewportRendering()) { - // // //----- Move camera -----// - // // // Check started camera movement - // // if (ImGui::IsMouseClicked(2) && ImGui::IsWindowHovered()) - // // activeViewport = i; - - // // // Update camera (wheel pressed) - // // if (activeViewport == i && ImGui::IsWindowHovered()) { - // // viewport->getCamera()->setViewportSize(viewport->getWidth(), viewport->getHeight()); - // // viewport->getCamera()->move(); - // // } - - // // //----- Mouse click -----// - // // vec2i click = {-1, -1}; - // // if (ImGui::IsMouseClicked(0) && ImGui::IsWindowHovered()) { - // // ImVec2 window = ImGui::GetWindowPos(); - // // ImVec2 cursor = ImGui::GetCursorPos(); - // // ImVec2 mouse = ImGui::GetMousePos(); - // // click = {int(mouse.x - window.x - cursor.x), int(mouse.y - window.y - cursor.y)}; - // // } - - // // if (ImGui::IsMouseClicked(1) && ImGui::IsWindowHovered()) - // // ImGui::OpenPopup("Editor_AddBasicShape"); - // // addBasicShapePopup(); - - // // //----- Keyboard click -----// - // // static ImGuizmo::OPERATION mouseOperation = ImGuizmo::OPERATION::TRANSLATE; - // // static ImGuizmo::MODE mouseMode = ImGuizmo::MODE::LOCAL; - // // static bool snap = false; - - // // if (ImGui::IsWindowHovered()) { - // // snap = false; - // // ImGuiIO& io = ImGui::GetIO(); - // // if (ImGui::IsKeyPressed(ImGuiKey_T) && io.KeyCtrl) { - // // mouseOperation = ImGuizmo::OPERATION::TRANSLATE; - // // mouseMode = ImGuizmo::MODE::LOCAL; - // // } else if (ImGui::IsKeyPressed(ImGuiKey_T) && io.KeyShift) { - // // mouseOperation = ImGuizmo::OPERATION::TRANSLATE; - // // mouseMode = ImGuizmo::MODE::WORLD; - // // } else if (ImGui::IsKeyPressed(ImGuiKey_S) && io.KeyCtrl) { - // // mouseOperation = ImGuizmo::OPERATION::SCALE; - // // mouseMode = ImGuizmo::MODE::LOCAL; - // // } else if (ImGui::IsKeyPressed(ImGuiKey_S) && io.KeyShift) { - // // mouseOperation = ImGuizmo::OPERATION::SCALE; - // // mouseMode = ImGuizmo::MODE::WORLD; - // // } else if (ImGui::IsKeyPressed(ImGuiKey_R) && io.KeyCtrl) { - // // mouseOperation = ImGuizmo::OPERATION::ROTATE; - // // mouseMode = ImGuizmo::MODE::LOCAL; - // // } else if (ImGui::IsKeyPressed(ImGuiKey_R) && io.KeyShift) { - // // mouseOperation = ImGuizmo::OPERATION::ROTATE; - // // mouseMode = ImGuizmo::MODE::WORLD; - // // } else if (io.KeyCtrl) - // // snap = true; - // // } - - // // //----- Render to texture -----// - // // ImVec2 size = ImVec2(viewport->getWidth(), viewport->getHeight()); - // // ImGui::Image(viewport->getImGuiTexture(), size, ImVec2(0, 0), ImVec2(1, 1)); - - // // //----- ImGuizmo -----// - // // bool imGuizmoUsingMouse = false; - // // component::EntityId entity = component::getSelectedEntity(); - // // if (entity >= 0) { - // // component::Transform* t = component::getComponent(entity); - - // // if (t) { - // // ImGuizmo::SetOrthographic(viewport->getCamera()->getName() == "OrthographicCamera"); - // // ImGuizmo::SetDrawlist(); - // // ImGuizmo::SetRect(ImGui::GetWindowPos().x + 5.0f, ImGui::GetWindowPos().y + 24.0f, viewport->getWidth(), - // viewport->getHeight()); - // // mat4 view = transpose(viewport->getCamera()->getView()); - // // mat4 proj = viewport->getCamera()->getProj(); - // // proj.mat[1][1] *= -1; - // // proj.transpose(); - - // // mat4 transform = transpose(t->getWorldTransformMatrix(entity)); - - // // float snapValue = 0.5f; - // // if (mouseOperation == ImGuizmo::OPERATION::ROTATE) - // // snapValue = 45.0f; - // // float snapValues[3] = {snapValue, snapValue, snapValue}; - - // // ImGuizmo::Manipulate(view.data, proj.data, mouseOperation, mouseMode, transform.data, nullptr, snap ? snapValues : - // nullptr); - - // // if (ImGuizmo::IsUsing()) { - // // imGuizmoUsingMouse = true; - // // transform.transpose(); - - // // // Get changed - // // vec3 pos, scale; - // // quat newOri; - // // transform.getPosOriScale(pos, newOri, scale); - // // vec3 oriDelta = newOri.getEuler() - t->orientation.getEuler(); - // // quat ori; - // // ori.setEuler(t->orientation.getEuler() + oriDelta); - - // // // Delta world to local - // // component::Relationship* r = component::getComponent(entity); - // // if (r && r->getParent() != -1) { - // // // Get transform of the first entity that has transform when going up in the hierarchy - // // component::Transform* pt = nullptr; - // // component::EntityId parentId = -1; - // // while (pt == nullptr) { - // // parentId = r->getParent(); - // // pt = component::getComponent(parentId); - // // r = component::getComponent(parentId); - // // if (r->getParent() == -1) - // // break; - // // } - - // // // If found some entity with transform component, convert result to be relative to it - // // if (pt) { - // // component::Transform pTransform = pt->getWorldTransform(parentId); - // // vec3 pPos = pTransform.position; - // // vec3 pScale = pTransform.scale; - // // quat pOri = pTransform.orientation; - - // // // Calculate pos ori scale relative to parent - // // pos -= pPos; - // // scale /= pScale; - // // ori = ori * (-pOri); // Rotation from pOri to ori - // // } - // // } - - // // // Update entity transform - // // if (mouseOperation == ImGuizmo::OPERATION::TRANSLATE) - // // t->position = pos; - // // else if (mouseOperation == ImGuizmo::OPERATION::ROTATE) - // // t->orientation = ori; - // // else if (mouseOperation == ImGuizmo::OPERATION::SCALE) - // // t->scale = scale; - - // // // component::RigidBody2D* rb2d = component::getComponent(entity); - // // // if (rb2d) { - // // // if (mouseOperation == ImGuizmo::OPERATION::TRANSLATE || mouseOperation == ImGuizmo::OPERATION::ROTATE) { - // // // vec2 pos = vec2(t->position); - // // // float angle = -t->orientation.getEuler().z; - // // // rb2d->setTransform(pos, angle); - // // // } else if (mouseOperation == ImGuizmo::OPERATION::SCALE) { - // // // // TODO Recreate box2d rigid body - // // // } - // // // } - // // } - // // } - // // } - - // // //----- Mouse click selection -----// - // // if (!imGuizmoUsingMouse) { - // // if (click.x >= 0 && click.y >= 0 && click.x < (int)viewport->getWidth() && click.y < (int)viewport->getHeight()) { - // // component::EntityId eid = _computeEntityClick(viewport->getRenderer(), viewport->getCamera(), click); - // // component::setSelectedEntity(eid); - // // } - // // } - - // // //----- Resize -----// - // // ImVec2 windowSize = ImGui::GetWindowSize(); - // // if (windowSize.x != size.x || windowSize.y != size.y) - // // viewport->resize((uint32_t)windowSize.x - 10, (uint32_t)windowSize.y - 30); - // //} - // ImGui::End(); - // ImGui::PopStyleVar(1); - - // if (!open) - // graphics::removeViewport(viewport); - //} + for (auto viewport : _viewports) { + // TODO docking + // ImGui::DockBuilderDockWindow((viewport->getName()+"###Viewport"+viewport->getSID().getString()).c_str(), + //_dockSpace.getViewportDockId()); + char nameBuf[128]; + sprintf(nameBuf, "%s###Viewport%s", viewport->getName().c_str(), viewport->getSID().getString().c_str()); + i++; + // Render and resize + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); + bool open = true; + ImGui::Begin(nameBuf, &open); + if (_viewportRendering) { + //----- Move camera -----// + // Check started camera movement + if (ImGui::IsMouseClicked(2) && ImGui::IsWindowHovered()) + activeViewport = i; + + // Update camera (wheel pressed) + if (activeViewport == i && ImGui::IsWindowHovered()) { + viewport->getCamera()->setViewportSize(viewport->getWidth(), viewport->getHeight()); + viewport->getCamera()->move(); + } + + //----- Mouse click -----// + vec2i click = {-1, -1}; + if (ImGui::IsMouseClicked(0) && ImGui::IsWindowHovered()) { + ImVec2 window = ImGui::GetWindowPos(); + ImVec2 cursor = ImGui::GetCursorPos(); + ImVec2 mouse = ImGui::GetMousePos(); + click = {int(mouse.x - window.x - cursor.x), int(mouse.y - window.y - cursor.y)}; + } + + if (ImGui::IsMouseClicked(1) && ImGui::IsWindowHovered()) + ImGui::OpenPopup("Editor_AddBasicShape"); + addBasicShapePopup(); + + //----- Keyboard click -----// + // static ImGuizmo::OPERATION mouseOperation = ImGuizmo::OPERATION::TRANSLATE; + // static ImGuizmo::MODE mouseMode = ImGuizmo::MODE::LOCAL; + // static bool snap = false; + + // if (ImGui::IsWindowHovered()) { + // snap = false; + // ImGuiIO& io = ImGui::GetIO(); + // if (ImGui::IsKeyPressed(ImGuiKey_T) && io.KeyCtrl) { + // mouseOperation = ImGuizmo::OPERATION::TRANSLATE; + // mouseMode = ImGuizmo::MODE::LOCAL; + // } else if (ImGui::IsKeyPressed(ImGuiKey_T) && io.KeyShift) { + // mouseOperation = ImGuizmo::OPERATION::TRANSLATE; + // mouseMode = ImGuizmo::MODE::WORLD; + // } else if (ImGui::IsKeyPressed(ImGuiKey_S) && io.KeyCtrl) { + // mouseOperation = ImGuizmo::OPERATION::SCALE; + // mouseMode = ImGuizmo::MODE::LOCAL; + // } else if (ImGui::IsKeyPressed(ImGuiKey_S) && io.KeyShift) { + // mouseOperation = ImGuizmo::OPERATION::SCALE; + // mouseMode = ImGuizmo::MODE::WORLD; + // } else if (ImGui::IsKeyPressed(ImGuiKey_R) && io.KeyCtrl) { + // mouseOperation = ImGuizmo::OPERATION::ROTATE; + // mouseMode = ImGuizmo::MODE::LOCAL; + // } else if (ImGui::IsKeyPressed(ImGuiKey_R) && io.KeyShift) { + // mouseOperation = ImGuizmo::OPERATION::ROTATE; + // mouseMode = ImGuizmo::MODE::WORLD; + // } else if (io.KeyCtrl) + // snap = true; + // } + + //----- Render to texture -----// + ImVec2 size = ImVec2(viewport->getWidth(), viewport->getHeight()); + ImGui::Image((ImTextureID)(intptr_t)viewport->getImGuiTexture(), size, ImVec2(0, 0), ImVec2(1, 1)); + + // //----- ImGuizmo -----// + // bool imGuizmoUsingMouse = false; + // component::EntityId entity = component::getSelectedEntity(); + // if (entity >= 0) { + // component::Transform* t = component::getComponent(entity); + + // if (t) { + // ImGuizmo::SetOrthographic(viewport->getCamera()->getName() == "OrthographicCamera"); + // ImGuizmo::SetDrawlist(); + // ImGuizmo::SetRect(ImGui::GetWindowPos().x + 5.0f, ImGui::GetWindowPos().y + 24.0f, viewport->getWidth(), + // viewport->getHeight()); + // mat4 view = transpose(viewport->getCamera()->getView()); + // mat4 proj = viewport->getCamera()->getProj(); + // proj.mat[1][1] *= -1; + // proj.transpose(); + + // mat4 transform = transpose(t->getWorldTransformMatrix(entity)); + + // float snapValue = 0.5f; + // if (mouseOperation == ImGuizmo::OPERATION::ROTATE) + // snapValue = 45.0f; + // float snapValues[3] = {snapValue, snapValue, snapValue}; + + // ImGuizmo::Manipulate(view.data, proj.data, mouseOperation, mouseMode, transform.data, nullptr, snap ? snapValues : nullptr); + + // if (ImGuizmo::IsUsing()) { + // imGuizmoUsingMouse = true; + // transform.transpose(); + + // // Get changed + // vec3 pos, scale; + // quat newOri; + // transform.getPosOriScale(pos, newOri, scale); + // vec3 oriDelta = newOri.getEuler() - t->orientation.getEuler(); + // quat ori; + // ori.setEuler(t->orientation.getEuler() + oriDelta); + + // // Delta world to local + // component::Relationship* r = component::getComponent(entity); + // if (r && r->getParent() != -1) { + // // Get transform of the first entity that has transform when going up in the hierarchy + // component::Transform* pt = nullptr; + // component::EntityId parentId = -1; + // while (pt == nullptr) { + // parentId = r->getParent(); + // pt = component::getComponent(parentId); + // r = component::getComponent(parentId); + // if (r->getParent() == -1) + // break; + // } + + // // If found some entity with transform component, convert result to be relative to it + // if (pt) { + // component::Transform pTransform = pt->getWorldTransform(parentId); + // vec3 pPos = pTransform.position; + // vec3 pScale = pTransform.scale; + // quat pOri = pTransform.orientation; + + // // Calculate pos ori scale relative to parent + // pos -= pPos; + // scale /= pScale; + // ori = ori * (-pOri); // Rotation from pOri to ori + // } + // } + + // // Update entity transform + // if (mouseOperation == ImGuizmo::OPERATION::TRANSLATE) + // t->position = pos; + // else if (mouseOperation == ImGuizmo::OPERATION::ROTATE) + // t->orientation = ori; + // else if (mouseOperation == ImGuizmo::OPERATION::SCALE) + // t->scale = scale; + + // // component::RigidBody2D* rb2d = component::getComponent(entity); + // // if (rb2d) { + // // if (mouseOperation == ImGuizmo::OPERATION::TRANSLATE || mouseOperation == ImGuizmo::OPERATION::ROTATE) { + // // vec2 pos = vec2(t->position); + // // float angle = -t->orientation.getEuler().z; + // // rb2d->setTransform(pos, angle); + // // } else if (mouseOperation == ImGuizmo::OPERATION::SCALE) { + // // // TODO Recreate box2d rigid body + // // } + // // } + // } + // } + // } + + // //----- Mouse click selection -----// + // if (!imGuizmoUsingMouse) { + // if (click.x >= 0 && click.y >= 0 && click.x < (int)viewport->getWidth() && click.y < (int)viewport->getHeight()) { + // component::EntityId eid = _computeEntityClick(viewport->getRenderer(), viewport->getCamera(), click); + // component::setSelectedEntity(eid); + // } + // } + + //----- Resize -----// + ImVec2 windowSize = ImGui::GetWindowSize(); + if (windowSize.x != size.x || windowSize.y != size.y) + viewport->resize((uint32_t)windowSize.x - 10, (uint32_t)windowSize.y - 30); + } + ImGui::End(); + ImGui::PopStyleVar(1); + + if (!open) + removeViewport(viewport); + } } std::vector> ViewportWindows::getViewports() { return _viewports; } diff --git a/src/atta/ui/windows/viewport/viewportWindows.h b/src/atta/ui/windows/viewport/viewportWindows.h index 50ccc181..0a1805d3 100644 --- a/src/atta/ui/windows/viewport/viewportWindows.h +++ b/src/atta/ui/windows/viewport/viewportWindows.h @@ -35,9 +35,9 @@ class ViewportWindows { std::vector> _viewports; ///< Current viewports to be rendered std::vector> _viewportsNext; ///< Being used for now to update the viewports in the next frame without breaking imgui - bool _swapViewports; ///< If _viewports should be swapped - float _viewportFPS; ///< Desired viewport FPS (UI module handles the viewport rendering) - bool _viewportRendering; ///< If should render the viewport + bool _swapViewports = false; ///< If _viewports should be swapped + float _viewportFPS = 30.0; ///< Desired viewport FPS (UI module handles the viewport rendering) + bool _viewportRendering = true; ///< If should render the viewport // Compute std::unique_ptr _computeEntityClick; From b397396e1dfed97203dacf529477f31a074da72e Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Sun, 19 Jan 2025 08:27:25 +0100 Subject: [PATCH 28/37] Feat: Create viewports --- src/atta/ui/editor.cpp | 3 + src/atta/ui/editor.h | 3 + src/atta/ui/interface.cpp | 4 + src/atta/ui/interface.h | 6 + src/atta/ui/manager.cpp | 4 + src/atta/ui/manager.h | 6 + src/atta/ui/panels/topBar/topBar.cpp | 253 ++++++++---------- src/atta/ui/panels/topBar/topBar.h | 9 +- .../ui/windows/viewport/viewportWindows.cpp | 39 ++- .../ui/windows/viewport/viewportWindows.h | 6 +- 10 files changed, 184 insertions(+), 149 deletions(-) diff --git a/src/atta/ui/editor.cpp b/src/atta/ui/editor.cpp index a0cc28d7..64618a00 100644 --- a/src/atta/ui/editor.cpp +++ b/src/atta/ui/editor.cpp @@ -82,6 +82,9 @@ void Editor::render() { } } +const std::vector>& Editor::getViewports() const { return _viewportWindows.getViewports(); } +void Editor::openViewportModal(StringId sid) const { _viewportWindows.openViewportModal(sid); } +void Editor::addViewport(std::shared_ptr viewport) { _viewportWindows.addViewport(viewport); } bool Editor::getViewportRendering() const { return _viewportWindows.getViewportRendering(); } void Editor::setViewportRendering(bool viewportRendering) { _viewportWindows.setViewportRendering(viewportRendering); } diff --git a/src/atta/ui/editor.h b/src/atta/ui/editor.h index a7299066..3755eb40 100644 --- a/src/atta/ui/editor.h +++ b/src/atta/ui/editor.h @@ -26,6 +26,9 @@ class Editor final { void renderViewports(); void render(); + const std::vector>& getViewports() const; + void openViewportModal(StringId sid) const; + void addViewport(std::shared_ptr viewport); bool getViewportRendering() const; void setViewportRendering(bool viewportRendering); diff --git a/src/atta/ui/interface.cpp b/src/atta/ui/interface.cpp index fa374400..9a75f23b 100644 --- a/src/atta/ui/interface.cpp +++ b/src/atta/ui/interface.cpp @@ -13,6 +13,10 @@ void startUp() { Manager::getInstance().startUpImpl(); } void shutDown() { Manager::getInstance().shutDownImpl(); } //----- Viewport -----// +const std::vector>& getViewports() { return Manager::getInstance().getViewportsImpl(); } +void openViewportModal(StringId sid) { Manager::getInstance().openViewportModalImpl(sid); } +void addViewport(std::shared_ptr viewport) { Manager::getInstance().addViewportImpl(viewport); } + bool getViewportRendering() { return Manager::getInstance().getViewportRenderingImpl(); } void setViewportRendering(bool viewportRendering) { Manager::getInstance().setViewportRenderingImpl(viewportRendering); } diff --git a/src/atta/ui/interface.h b/src/atta/ui/interface.h index c8c205e4..f2f36af5 100644 --- a/src/atta/ui/interface.h +++ b/src/atta/ui/interface.h @@ -7,12 +7,18 @@ #ifndef ATTA_UI_INTERFACE_H #define ATTA_UI_INTERFACE_H +#include + namespace atta::ui { void startUp(); void shutDown(); //----- Viewport -----// +const std::vector>& getViewports(); +void openViewportModal(StringId sid); +void addViewport(std::shared_ptr viewport); + bool getViewportRendering(); void setViewportRendering(bool viewportRendering); diff --git a/src/atta/ui/manager.cpp b/src/atta/ui/manager.cpp index 8bd83b0c..768ad8bd 100644 --- a/src/atta/ui/manager.cpp +++ b/src/atta/ui/manager.cpp @@ -97,6 +97,10 @@ void Manager::shutDownImpl() { ImGui::DestroyContext(); } +const std::vector>& Manager::getViewportsImpl() const { return _editor.getViewports(); } +void Manager::openViewportModalImpl(StringId sid) const { _editor.openViewportModal(sid); } +void Manager::addViewportImpl(std::shared_ptr viewport) { _editor.addViewport(viewport); } + bool Manager::getViewportRenderingImpl() const { return _editor.getViewportRendering(); } void Manager::setViewportRenderingImpl(bool viewportRendering) { _editor.setViewportRendering(viewportRendering); } diff --git a/src/atta/ui/manager.h b/src/atta/ui/manager.h index ae1de9cc..a1413687 100644 --- a/src/atta/ui/manager.h +++ b/src/atta/ui/manager.h @@ -18,6 +18,9 @@ class Manager final { friend void startUp(); friend void shutDown(); + friend const std::vector>& getViewports(); + friend void openViewportModal(StringId sid); + friend void addViewport(std::shared_ptr viewport); friend bool getViewportRendering(); friend void setViewportRendering(bool viewportRendering); @@ -25,6 +28,9 @@ class Manager final { void startUpImpl(); void shutDownImpl(); + const std::vector>& getViewportsImpl() const; + void openViewportModalImpl(StringId sid) const; + void addViewportImpl(std::shared_ptr viewport); bool getViewportRenderingImpl() const; void setViewportRenderingImpl(bool viewportRendering); diff --git a/src/atta/ui/panels/topBar/topBar.cpp b/src/atta/ui/panels/topBar/topBar.cpp index 5d5753ea..665a8a9c 100644 --- a/src/atta/ui/panels/topBar/topBar.cpp +++ b/src/atta/ui/panels/topBar/topBar.cpp @@ -22,13 +22,14 @@ #include #include +#include #include #include #include #include -#include - #include +#include +#include namespace atta::ui { @@ -37,134 +38,140 @@ TopBar::TopBar() : _showPreferences(false) {} void TopBar::render() { if (ImGui::BeginMainMenuBar()) { ui::image("icons/atta_20x20.png", vec2(20, 20)); + fileMenu(); + editMenu(); + windowMenu(); + helpMenu(); + ImGui::EndMainMenuBar(); + } + openProjectModal(); + openPublishedWindow(); + createProjectModal(); + preferences(); + saveProjectModal(); + + for (int i = (int)_repoWindows.size() - 1; i >= 0; i--) { + RepoWindow& r = _repoWindows[i]; + r.render(); + if (r.getShouldClose()) + _repoWindows.erase(_repoWindows.begin() + i); + } +} - if (ImGui::BeginMenu("File")) { - if (file::isProjectOpen()) { - ImGui::Text(file::getProject()->getName().c_str()); - ImGui::Separator(); +void TopBar::fileMenu() { + if (ImGui::BeginMenu("File")) { + if (file::isProjectOpen()) { + ImGui::Text(file::getProject()->getName().c_str()); + ImGui::Separator(); #ifndef ATTA_STATIC_PROJECT - if (ImGui::MenuItem("Close")) - _showSaveProject = true; + if (ImGui::MenuItem("Close")) + _showSaveProject = true; #endif - } + } #ifndef ATTA_STATIC_PROJECT - if (ImGui::BeginMenu("Open")) { - if (ImGui::MenuItem("From file")) { - FileSelectionWindow::setOpen(true); - _waitingChooseAttaFile = true; - } - if (ImGui::MenuItem("From published")) - _showOpenPublished = true; - - ImGui::EndMenu(); + if (ImGui::BeginMenu("Open")) { + if (ImGui::MenuItem("From file")) { + FileSelectionWindow::setOpen(true); + _waitingChooseAttaFile = true; } + if (ImGui::MenuItem("From published")) + _showOpenPublished = true; + + ImGui::EndMenu(); + } #endif - if (file::isProjectOpen()) - if (ImGui::MenuItem("Save")) - file::saveProject(); + if (file::isProjectOpen()) + if (ImGui::MenuItem("Save")) + file::saveProject(); #ifndef ATTA_STATIC_PROJECT - if (ImGui::MenuItem("Save as")) - _showCreateProject = true; + if (ImGui::MenuItem("Save as")) + _showCreateProject = true; #endif - ImGui::Separator(); + ImGui::Separator(); - if (ImGui::MenuItem("Quit")) { - _showSaveProject = true; - _quitAfterSaveModal = true; - } - ImGui::EndMenu(); + if (ImGui::MenuItem("Quit")) { + _showSaveProject = true; + _quitAfterSaveModal = true; } + ImGui::EndMenu(); + } +} - // if (ImGui::BeginMenu("Edit")) { - // if (ImGui::MenuItem("Preferences")) - // _showPreferences = true; +void TopBar::editMenu() { + if (ImGui::BeginMenu("Edit")) { + if (ImGui::MenuItem("Preferences")) + _showPreferences = true; - // ImGui::EndMenu(); - //} + ImGui::EndMenu(); + } +} - if (ImGui::BeginMenu("Tools")) { - if (ImGui::MenuItem("Time Profiler")) - TimeProfilerWindow::setOpen(true); - ImGui::EndMenu(); - } +void TopBar::windowMenu() { + if (ImGui::BeginMenu("Window")) { + if (ImGui::BeginMenu("Viewports")) { + std::vector> viewports = ui::getViewports(); + for (auto viewport : viewports) + if (ImGui::MenuItem(viewport->getName().c_str())) + ui::openViewportModal(viewport->getSID()); - // if (ImGui::BeginMenu("Viewports")) { - // std::vector> viewports = graphics::getViewports(); - // _viewportModals.resize(viewports.size()); - // int i = 0; - // for (auto viewport : viewports) { - // if (ImGui::MenuItem(viewport->getName().c_str())) - // _viewportModals[i] = true; - // i++; - // } - - // ImGui::Separator(); - - // if (ImGui::MenuItem("Create viewport")) { - // // Choose viewport name - // unsigned newViewportNumber = 0; - // bool found = false; - // while (!found) { - // found = true; - // for (auto viewport : viewports) - // if (viewport->getSID() == StringId("Viewport " + std::to_string(newViewportNumber))) { - // found = false; - // break; - // } - // if (!found) - // newViewportNumber++; - // } - - // // Create viewport - // graphics::Viewport::CreateInfo viewportInfo; - // viewportInfo.renderer = std::make_shared(); - // viewportInfo.camera = std::static_pointer_cast( - // std::make_shared(graphics::PerspectiveCamera::CreateInfo{})); - // viewportInfo.sid = StringId("Viewport " + std::to_string(newViewportNumber)); - // std::shared_ptr viewport = std::make_shared(viewportInfo); - // graphics::addViewport(viewport); - // } - - // ImGui::EndMenu(); - //} - - if (ImGui::BeginMenu("Modules")) { - if (ImGui::MenuItem("Graphics")) - GraphicsModuleWindow::setOpen(true); - if (ImGui::MenuItem("IO")) - IOModuleWindow::setOpen(true); - if (ImGui::MenuItem("Physics")) - PhysicsModuleWindow::setOpen(true); - if (ImGui::MenuItem("Sensor")) - SensorModuleWindow::setOpen(true); - ImGui::EndMenu(); - } + ImGui::Separator(); + + if (ImGui::MenuItem("Create viewport")) { + // Choose viewport name + unsigned newViewportNumber = 0; + bool found = false; + while (!found) { + found = true; + for (auto viewport : viewports) + if (viewport->getSID() == StringId("Viewport " + std::to_string(newViewportNumber))) { + found = false; + break; + } + if (!found) + newViewportNumber++; + } + + // Create viewport + ui::Viewport::CreateInfo viewportInfo; + viewportInfo.renderer = std::make_shared(); + viewportInfo.camera = + std::static_pointer_cast(std::make_shared(gfx::PerspectiveCamera::CreateInfo{})); + viewportInfo.sid = StringId("Viewport " + std::to_string(newViewportNumber)); + std::shared_ptr viewport = std::make_shared(viewportInfo); + ui::addViewport(viewport); + } - if (ImGui::BeginMenu("Help")) { - if (ImGui::MenuItem("Version")) - VersionWindow::setOpen(true); ImGui::EndMenu(); } - ImGui::EndMainMenuBar(); + ImGui::Separator(); + if (ImGui::MenuItem("Graphics")) + GraphicsModuleWindow::setOpen(true); + if (ImGui::MenuItem("IO")) + IOModuleWindow::setOpen(true); + if (ImGui::MenuItem("Physics")) + PhysicsModuleWindow::setOpen(true); + if (ImGui::MenuItem("Sensor")) + SensorModuleWindow::setOpen(true); + + ImGui::Separator(); + if (ImGui::MenuItem("Time Profiler")) + TimeProfilerWindow::setOpen(true); + + ImGui::EndMenu(); } - openProjectModal(); - openPublishedWindow(); - createProjectModal(); - preferences(); - viewportModals(); - saveProjectModal(); +} - for (int i = (int)_repoWindows.size() - 1; i >= 0; i--) { - RepoWindow& r = _repoWindows[i]; - r.render(); - if (r.getShouldClose()) - _repoWindows.erase(_repoWindows.begin() + i); +void TopBar::helpMenu() { + if (ImGui::BeginMenu("Help")) { + if (ImGui::MenuItem("Version")) + VersionWindow::setOpen(true); + ImGui::EndMenu(); } } @@ -473,40 +480,4 @@ void TopBar::saveProjectModal() { } } -void TopBar::viewportModals() { - // XXX - // std::vector> viewports = graphics::getViewports(); - // static std::vector newViewportModals; // If first time creating the modal - //_viewportModals.resize(viewports.size()); - - //// Check if first time creating viewport - // newViewportModals.resize(_viewportModals.size()); - // for (unsigned i = 0; i < newViewportModals.size(); i++) - // newViewportModals[i] = !newViewportModals[i] && _viewportModals[i]; - - // for (uint32_t i = 0; i < _viewportModals.size(); i++) { - // char nameBuf[196]; - // sprintf(nameBuf, "%s###ViewportProps%s", viewports[i]->getName().c_str(), viewports[i]->getSID().getString().c_str()); - - // bool open = _viewportModals[i]; - // if (open) { - // if (newViewportModals[i]) - // ImGui::SetNextWindowSize(ImVec2(200.0f, 300.0f)); - // if (ImGui::Begin(nameBuf, &open)) { - // viewports[i]->renderUI(); - - // ImGui::Separator(); - // if (ImGui::Button("Delete Viewport")) { - // graphics::removeViewport(viewports[i]); - // ImGui::End(); - // break; - // } - // } - // ImGui::End(); - // _viewportModals[i] = open; - // } - //} - // newViewportModals = _viewportModals; -} - } // namespace atta::ui diff --git a/src/atta/ui/panels/topBar/topBar.h b/src/atta/ui/panels/topBar/topBar.h index e8e41a8c..79a695c8 100644 --- a/src/atta/ui/panels/topBar/topBar.h +++ b/src/atta/ui/panels/topBar/topBar.h @@ -18,13 +18,16 @@ class TopBar { void render(); private: + void fileMenu(); + void editMenu(); + void windowMenu(); + void helpMenu(); + void preferences(); ///< Render preferences window void openProjectModal(); ///< Render open project modal void openPublishedWindow(); ///< Render open published project modal void createProjectModal(); ///< Render create project modal void saveProjectModal(); ///< Render save project modal - /** The viewport modal is used to change the viewport settings */ - void viewportModals(); ///< Render viewport modal bool _waitingChooseAttaFile; bool _showPreferences; ///< Show preferences modal @@ -36,8 +39,6 @@ class TopBar { bool _quitAfterSaveModal; ///< If should quit application after save project modal response - /** True/false for each viewport window */ - std::vector _viewportModals; ///< Which viewports should be rendered std::vector _repoWindows; ///< Which repository windows are open }; diff --git a/src/atta/ui/windows/viewport/viewportWindows.cpp b/src/atta/ui/windows/viewport/viewportWindows.cpp index 0fa63863..7803d571 100644 --- a/src/atta/ui/windows/viewport/viewportWindows.cpp +++ b/src/atta/ui/windows/viewport/viewportWindows.cpp @@ -238,7 +238,7 @@ void ViewportWindows::renderUI() { } } -std::vector> ViewportWindows::getViewports() { return _viewports; } +const std::vector>& ViewportWindows::getViewports() const { return _viewports; } void ViewportWindows::clearViewports() { _viewportsNext.clear(); @@ -246,6 +246,7 @@ void ViewportWindows::clearViewports() { } void ViewportWindows::addViewport(std::shared_ptr viewport) { + _viewportsNext = _viewports; _viewportsNext.push_back(viewport); _swapViewports = true; } @@ -264,6 +265,42 @@ void ViewportWindows::removeViewport(std::shared_ptr viewport) { } } +void ViewportWindows::openViewportModal(StringId sid) const { + // XXX + // std::vector> viewports = graphics::getViewports(); + // static std::vector newViewportModals; // If first time creating the modal + //_viewportModals.resize(viewports.size()); + + //// Check if first time creating viewport + // newViewportModals.resize(_viewportModals.size()); + // for (unsigned i = 0; i < newViewportModals.size(); i++) + // newViewportModals[i] = !newViewportModals[i] && _viewportModals[i]; + + // for (uint32_t i = 0; i < _viewportModals.size(); i++) { + // char nameBuf[196]; + // sprintf(nameBuf, "%s###ViewportProps%s", viewports[i]->getName().c_str(), viewports[i]->getSID().getString().c_str()); + + // bool open = _viewportModals[i]; + // if (open) { + // if (newViewportModals[i]) + // ImGui::SetNextWindowSize(ImVec2(200.0f, 300.0f)); + // if (ImGui::Begin(nameBuf, &open)) { + // viewports[i]->renderUI(); + + // ImGui::Separator(); + // if (ImGui::Button("Delete Viewport")) { + // graphics::removeViewport(viewports[i]); + // ImGui::End(); + // break; + // } + // } + // ImGui::End(); + // _viewportModals[i] = open; + // } + //} + // newViewportModals = _viewportModals; +} + void ViewportWindows::createDefaultViewports() { _viewportsNext.clear(); diff --git a/src/atta/ui/windows/viewport/viewportWindows.h b/src/atta/ui/windows/viewport/viewportWindows.h index 0a1805d3..2ef04905 100644 --- a/src/atta/ui/windows/viewport/viewportWindows.h +++ b/src/atta/ui/windows/viewport/viewportWindows.h @@ -21,16 +21,16 @@ class ViewportWindows { void renderViewports(); void renderUI(); - std::vector> getViewports(); + const std::vector>& getViewports() const; void clearViewports(); void addViewport(std::shared_ptr viewport); void removeViewport(std::shared_ptr viewport); - void createDefaultViewports(); - + void openViewportModal(StringId sid) const; bool getViewportRendering() const; void setViewportRendering(bool viewportRendering); private: + void createDefaultViewports(); void addBasicShapePopup(); std::vector> _viewports; ///< Current viewports to be rendered From 3a76b81826dfbed9fac1d4b11cd228cbdac161a0 Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Sun, 19 Jan 2025 08:47:15 +0100 Subject: [PATCH 29/37] Fix: Remove viewport --- src/atta/ui/editor.cpp | 2 +- .../ui/windows/viewport/viewportWindows.cpp | 18 +++++++----------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/src/atta/ui/editor.cpp b/src/atta/ui/editor.cpp index 64618a00..5fa5d551 100644 --- a/src/atta/ui/editor.cpp +++ b/src/atta/ui/editor.cpp @@ -38,7 +38,7 @@ void Editor::render() { // Demo bool demo = true; - ImGui::ShowDemoWindow(&demo); + // ImGui::ShowDemoWindow(&demo); // ImPlot::ShowDemoWindow(&demo); // ImPlot3D::ShowDemoWindow(&demo); diff --git a/src/atta/ui/windows/viewport/viewportWindows.cpp b/src/atta/ui/windows/viewport/viewportWindows.cpp index 7803d571..7505f63f 100644 --- a/src/atta/ui/windows/viewport/viewportWindows.cpp +++ b/src/atta/ui/windows/viewport/viewportWindows.cpp @@ -252,17 +252,13 @@ void ViewportWindows::addViewport(std::shared_ptr viewport) { } void ViewportWindows::removeViewport(std::shared_ptr viewport) { - // TODO make it work with zero viewports - if (_viewportsNext.size() > 1) { - for (unsigned i = 0; i < _viewportsNext.size(); i++) - if (_viewportsNext[i] == viewport) { - _viewportsNext.erase(_viewportsNext.begin() + i); - break; - } - _swapViewports = true; - } else { - LOG_WARN("ui::ViewportWindows", "It is not possible to have 0 viewports yet"); - } + _viewportsNext = _viewports; + for (unsigned i = 0; i < _viewportsNext.size(); i++) + if (_viewportsNext[i] == viewport) { + _viewportsNext.erase(_viewportsNext.begin() + i); + break; + } + _swapViewports = true; } void ViewportWindows::openViewportModal(StringId sid) const { From 38d70c9cb7bf2c63e004ebfb41d344646d2c0f41 Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Sun, 19 Jan 2025 08:56:14 +0100 Subject: [PATCH 30/37] Fix: Make sure new viewports are docked --- src/atta/ui/editor.cpp | 33 +++++++++---------- src/atta/ui/interface.cpp | 2 ++ src/atta/ui/interface.h | 1 + src/atta/ui/manager.cpp | 2 ++ src/atta/ui/manager.h | 2 ++ .../ui/windows/viewport/viewportWindows.cpp | 5 +++ 6 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/atta/ui/editor.cpp b/src/atta/ui/editor.cpp index 5fa5d551..78ab149f 100644 --- a/src/atta/ui/editor.cpp +++ b/src/atta/ui/editor.cpp @@ -106,28 +106,27 @@ void Editor::setupDocking() { ImGuiIO& io = ImGui::GetIO(); if (io.ConfigFlags & ImGuiConfigFlags_DockingEnable) { - ImGuiID dockspace_id = ImGui::GetID("EditorDockSpace"); - ImGui::DockSpace(dockspace_id, ImVec2(0.0f, 0.0f), ImGuiDockNodeFlags_PassthruCentralNode | ImGuiDockNodeFlags_NoWindowMenuButton); + ImGuiID dockspaceId = ImGui::GetID("EditorDockSpace"); + ImGui::DockSpace(dockspaceId, ImVec2(0.0f, 0.0f), ImGuiDockNodeFlags_PassthruCentralNode | ImGuiDockNodeFlags_NoWindowMenuButton); //----- Clear previous layout -----// if (_firstRender) { _firstRender = false; - ImGui::DockBuilderRemoveNode(dockspace_id); // clear any previous layout - ImGui::DockBuilderAddNode(dockspace_id, ImGuiDockNodeFlags_PassthruCentralNode | ImGuiDockNodeFlags_DockSpace); - ImGui::DockBuilderSetNodeSize(dockspace_id, viewport->Size); - - auto dock_id_scene = ImGui::DockBuilderSplitNode(dockspace_id, ImGuiDir_Right, 0.20f, nullptr, &dockspace_id); - auto dock_id_down = ImGui::DockBuilderSplitNode(dockspace_id, ImGuiDir_Down, 0.20f, nullptr, &dockspace_id); - auto dock_id_vp_top = ImGui::DockBuilderSplitNode(dockspace_id, ImGuiDir_Up, 0.00f, nullptr, &dockspace_id); - - // we now dock our windows into the docking node we made above - _viewportDockId = dockspace_id; - ImGui::DockBuilderDockWindow("Main Viewport###ViewportMain Viewport", dockspace_id); - ImGui::DockBuilderDockWindow("Log", dock_id_down); - ImGui::DockBuilderDockWindow("Scene", dock_id_scene); - ImGui::DockBuilderDockWindow("##Toolbar", dock_id_vp_top); - ImGui::DockBuilderFinish(dockspace_id); + ImGui::DockBuilderAddNode(dockspaceId, ImGuiDockNodeFlags_PassthruCentralNode | ImGuiDockNodeFlags_DockSpace); + ImGui::DockBuilderSetNodeSize(dockspaceId, viewport->Size); + + auto dockIdCenter = ImGui::DockBuilderSplitNode(dockspaceId, ImGuiDir_Right, 0.20f, nullptr, &dockspaceId); + auto dockIdDown = ImGui::DockBuilderSplitNode(dockspaceId, ImGuiDir_Down, 0.20f, nullptr, &dockspaceId); + auto dockIdUp = ImGui::DockBuilderSplitNode(dockspaceId, ImGuiDir_Up, 0.00f, nullptr, &dockspaceId); + + // Dock our windows into the docking node we made above + _viewportDockId = dockspaceId; + ImGui::DockBuilderDockWindow("Main Viewport###ViewportMain Viewport", dockspaceId); + ImGui::DockBuilderDockWindow("Log", dockIdDown); + ImGui::DockBuilderDockWindow("Scene", dockIdCenter); + ImGui::DockBuilderDockWindow("##Toolbar", dockIdUp); + ImGui::DockBuilderFinish(dockspaceId); } } ImGui::End(); diff --git a/src/atta/ui/interface.cpp b/src/atta/ui/interface.cpp index 9a75f23b..0740f995 100644 --- a/src/atta/ui/interface.cpp +++ b/src/atta/ui/interface.cpp @@ -20,4 +20,6 @@ void addViewport(std::shared_ptr viewport) { Manager::getInstance( bool getViewportRendering() { return Manager::getInstance().getViewportRenderingImpl(); } void setViewportRendering(bool viewportRendering) { Manager::getInstance().setViewportRenderingImpl(viewportRendering); } +unsigned getViewportDockId() { return Manager::getInstance().getViewportDockIdImpl(); } + } // namespace atta::ui diff --git a/src/atta/ui/interface.h b/src/atta/ui/interface.h index f2f36af5..350f3819 100644 --- a/src/atta/ui/interface.h +++ b/src/atta/ui/interface.h @@ -21,6 +21,7 @@ void addViewport(std::shared_ptr viewport); bool getViewportRendering(); void setViewportRendering(bool viewportRendering); +unsigned getViewportDockId(); } // namespace atta::ui diff --git a/src/atta/ui/manager.cpp b/src/atta/ui/manager.cpp index 768ad8bd..c8262492 100644 --- a/src/atta/ui/manager.cpp +++ b/src/atta/ui/manager.cpp @@ -104,6 +104,8 @@ void Manager::addViewportImpl(std::shared_ptr viewport) { _editor. bool Manager::getViewportRenderingImpl() const { return _editor.getViewportRendering(); } void Manager::setViewportRenderingImpl(bool viewportRendering) { _editor.setViewportRendering(viewportRendering); } +unsigned Manager::getViewportDockIdImpl() { return _editor.getViewportDockId(); } + void Manager::setTheme() { ImGuiStyle& style = ImGui::GetStyle(); diff --git a/src/atta/ui/manager.h b/src/atta/ui/manager.h index a1413687..d8f7d595 100644 --- a/src/atta/ui/manager.h +++ b/src/atta/ui/manager.h @@ -23,6 +23,7 @@ class Manager final { friend void addViewport(std::shared_ptr viewport); friend bool getViewportRendering(); friend void setViewportRendering(bool viewportRendering); + friend unsigned getViewportDockId(); private: void startUpImpl(); @@ -33,6 +34,7 @@ class Manager final { void addViewportImpl(std::shared_ptr viewport); bool getViewportRenderingImpl() const; void setViewportRenderingImpl(bool viewportRendering); + unsigned getViewportDockIdImpl(); void setTheme(); void initOpenGL(); diff --git a/src/atta/ui/windows/viewport/viewportWindows.cpp b/src/atta/ui/windows/viewport/viewportWindows.cpp index 7505f63f..3c386ab3 100644 --- a/src/atta/ui/windows/viewport/viewportWindows.cpp +++ b/src/atta/ui/windows/viewport/viewportWindows.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include @@ -67,6 +68,10 @@ void ViewportWindows::renderUI() { char nameBuf[128]; sprintf(nameBuf, "%s###Viewport%s", viewport->getName().c_str(), viewport->getSID().getString().c_str()); i++; + + // Docking + ImGui::SetNextWindowDockID(ui::getViewportDockId(), ImGuiCond_FirstUseEver); + // Render and resize ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); bool open = true; From 7fe0be0ea6057fe7f0b57d3f13da2a294f1af63b Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Sun, 19 Jan 2025 09:00:48 +0100 Subject: [PATCH 31/37] Chore: Generate compile commands --- .gitignore | 2 ++ CMakeLists.txt | 15 ++++++++------- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index d222c948..6691710c 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,8 @@ tags imgui.ini # Debugging/Profile +.cache/ perf.* .gdb_history profile/ +compile_commands.json diff --git a/CMakeLists.txt b/CMakeLists.txt index 4dc989b8..a1f3cf1a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,17 +11,18 @@ OPTION(ATTA_WEB_BUILD_MODULE OPTION(ATTA_BUILD_DOCS "Build the documentation" OFF) -option(ATTA_STATIC_PROJECT_FILE - "Project to be linked statically to atta" +option(ATTA_STATIC_PROJECT_FILE + "Project to be linked statically to atta" "") -option(ATTA_PROFILE - "Set to ON to enable code profiling" +option(ATTA_PROFILE + "Set to ON to enable code profiling" ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(ATTA_VERSION_SAFE atta-${CMAKE_PROJECT_VERSION}) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/atta/cmakeConfig.h.in ${CMAKE_CURRENT_SOURCE_DIR}/src/atta/cmakeConfig.h) @@ -123,7 +124,7 @@ if(CMAKE_BUILD_TYPE MATCHES Debug) list(APPEND ATTA_OPTIONS -Wno-unused-parameter) # Script C linkage list(APPEND ATTA_OPTIONS -Wno-return-type-c-linkage) - # Math anonymous union + # Math anonymous union #list(APPEND ATTA_OPTIONS -Wno-nested-anon-types -Wno-gnu-anonymous-struct) # Glad opengl definitions #list(APPEND ATTA_OPTIONS -Wno-macro-redefined) @@ -218,7 +219,7 @@ if(ATTA_STATIC_PROJECT) endif() configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/src/atta/script/scripts.h.in" + "${CMAKE_CURRENT_SOURCE_DIR}/src/atta/script/scripts.h.in" "${CMAKE_CURRENT_SOURCE_DIR}/src/atta/script/scripts.h" ) @@ -236,7 +237,7 @@ if(NOT (ATTA_SYSTEM_NAME MATCHES "Web") AND NOT ATTA_STATIC_PROJECT_FILE) ########## Install files ########## # Install atta executable - install(TARGETS atta + install(TARGETS atta RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} PRIVATE_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${ATTA_VERSION_SAFE} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${ATTA_VERSION_SAFE} From a8676f0687c10219dfc2eedf67223a5e0b6b9b44 Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Sun, 19 Jan 2025 09:00:48 +0100 Subject: [PATCH 32/37] Fix: Show viewport modals --- .gitignore | 2 + CMakeLists.txt | 15 +- src/atta/ui/editor.cpp | 2 +- src/atta/ui/editor.h | 2 +- src/atta/ui/manager.cpp | 2 +- src/atta/ui/manager.h | 2 +- .../ui/windows/viewport/viewportWindows.cpp | 395 +++++++++--------- .../ui/windows/viewport/viewportWindows.h | 4 +- 8 files changed, 215 insertions(+), 209 deletions(-) diff --git a/.gitignore b/.gitignore index d222c948..6691710c 100644 --- a/.gitignore +++ b/.gitignore @@ -25,6 +25,8 @@ tags imgui.ini # Debugging/Profile +.cache/ perf.* .gdb_history profile/ +compile_commands.json diff --git a/CMakeLists.txt b/CMakeLists.txt index 4dc989b8..a1f3cf1a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,17 +11,18 @@ OPTION(ATTA_WEB_BUILD_MODULE OPTION(ATTA_BUILD_DOCS "Build the documentation" OFF) -option(ATTA_STATIC_PROJECT_FILE - "Project to be linked statically to atta" +option(ATTA_STATIC_PROJECT_FILE + "Project to be linked statically to atta" "") -option(ATTA_PROFILE - "Set to ON to enable code profiling" +option(ATTA_PROFILE + "Set to ON to enable code profiling" ON) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_POSITION_INDEPENDENT_CODE ON) set(ATTA_VERSION_SAFE atta-${CMAKE_PROJECT_VERSION}) +set(CMAKE_EXPORT_COMPILE_COMMANDS ON) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/atta/cmakeConfig.h.in ${CMAKE_CURRENT_SOURCE_DIR}/src/atta/cmakeConfig.h) @@ -123,7 +124,7 @@ if(CMAKE_BUILD_TYPE MATCHES Debug) list(APPEND ATTA_OPTIONS -Wno-unused-parameter) # Script C linkage list(APPEND ATTA_OPTIONS -Wno-return-type-c-linkage) - # Math anonymous union + # Math anonymous union #list(APPEND ATTA_OPTIONS -Wno-nested-anon-types -Wno-gnu-anonymous-struct) # Glad opengl definitions #list(APPEND ATTA_OPTIONS -Wno-macro-redefined) @@ -218,7 +219,7 @@ if(ATTA_STATIC_PROJECT) endif() configure_file( - "${CMAKE_CURRENT_SOURCE_DIR}/src/atta/script/scripts.h.in" + "${CMAKE_CURRENT_SOURCE_DIR}/src/atta/script/scripts.h.in" "${CMAKE_CURRENT_SOURCE_DIR}/src/atta/script/scripts.h" ) @@ -236,7 +237,7 @@ if(NOT (ATTA_SYSTEM_NAME MATCHES "Web") AND NOT ATTA_STATIC_PROJECT_FILE) ########## Install files ########## # Install atta executable - install(TARGETS atta + install(TARGETS atta RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} PRIVATE_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${ATTA_VERSION_SAFE} PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${ATTA_VERSION_SAFE} diff --git a/src/atta/ui/editor.cpp b/src/atta/ui/editor.cpp index 78ab149f..d5edf9ac 100644 --- a/src/atta/ui/editor.cpp +++ b/src/atta/ui/editor.cpp @@ -83,7 +83,7 @@ void Editor::render() { } const std::vector>& Editor::getViewports() const { return _viewportWindows.getViewports(); } -void Editor::openViewportModal(StringId sid) const { _viewportWindows.openViewportModal(sid); } +void Editor::openViewportModal(StringId sid) { _viewportWindows.openViewportModal(sid); } void Editor::addViewport(std::shared_ptr viewport) { _viewportWindows.addViewport(viewport); } bool Editor::getViewportRendering() const { return _viewportWindows.getViewportRendering(); } void Editor::setViewportRendering(bool viewportRendering) { _viewportWindows.setViewportRendering(viewportRendering); } diff --git a/src/atta/ui/editor.h b/src/atta/ui/editor.h index 3755eb40..f61b2f61 100644 --- a/src/atta/ui/editor.h +++ b/src/atta/ui/editor.h @@ -27,7 +27,7 @@ class Editor final { void render(); const std::vector>& getViewports() const; - void openViewportModal(StringId sid) const; + void openViewportModal(StringId sid); void addViewport(std::shared_ptr viewport); bool getViewportRendering() const; void setViewportRendering(bool viewportRendering); diff --git a/src/atta/ui/manager.cpp b/src/atta/ui/manager.cpp index c8262492..8de4a55b 100644 --- a/src/atta/ui/manager.cpp +++ b/src/atta/ui/manager.cpp @@ -98,7 +98,7 @@ void Manager::shutDownImpl() { } const std::vector>& Manager::getViewportsImpl() const { return _editor.getViewports(); } -void Manager::openViewportModalImpl(StringId sid) const { _editor.openViewportModal(sid); } +void Manager::openViewportModalImpl(StringId sid) { _editor.openViewportModal(sid); } void Manager::addViewportImpl(std::shared_ptr viewport) { _editor.addViewport(viewport); } bool Manager::getViewportRenderingImpl() const { return _editor.getViewportRendering(); } diff --git a/src/atta/ui/manager.h b/src/atta/ui/manager.h index d8f7d595..6b15e6e3 100644 --- a/src/atta/ui/manager.h +++ b/src/atta/ui/manager.h @@ -30,7 +30,7 @@ class Manager final { void shutDownImpl(); const std::vector>& getViewportsImpl() const; - void openViewportModalImpl(StringId sid) const; + void openViewportModalImpl(StringId sid); void addViewportImpl(std::shared_ptr viewport); bool getViewportRenderingImpl() const; void setViewportRenderingImpl(bool viewportRendering); diff --git a/src/atta/ui/windows/viewport/viewportWindows.cpp b/src/atta/ui/windows/viewport/viewportWindows.cpp index 3c386ab3..95733202 100644 --- a/src/atta/ui/windows/viewport/viewportWindows.cpp +++ b/src/atta/ui/windows/viewport/viewportWindows.cpp @@ -16,8 +16,8 @@ #include #include #include -#include #include +#include #include #include @@ -31,6 +31,7 @@ void ViewportWindows::startUp() { void ViewportWindows::shutDown() { _computeEntityClick.reset(); + _openModals.clear(); _viewports.clear(); _viewportsNext.clear(); } @@ -42,6 +43,7 @@ void ViewportWindows::renderViewports() { _viewportsNext.clear(); _swapViewports = false; } + _viewportsNext = _viewports; if (_viewportRendering) for (auto& viewport : _viewports) @@ -52,7 +54,7 @@ void ViewportWindows::renderUI() { PROFILE(); static int activeViewport = 0; - // Viewports fps + // Viewports FPS static clock_t vpLastTime = std::clock(); const clock_t vpCurrTime = std::clock(); const float vpTimeDiff = float(vpCurrTime - vpLastTime) / CLOCKS_PER_SEC; @@ -62,9 +64,6 @@ void ViewportWindows::renderUI() { int i = -1; for (auto viewport : _viewports) { - // TODO docking - // ImGui::DockBuilderDockWindow((viewport->getName()+"###Viewport"+viewport->getSID().getString()).c_str(), - //_dockSpace.getViewportDockId()); char nameBuf[128]; sprintf(nameBuf, "%s###Viewport%s", viewport->getName().c_str(), viewport->getSID().getString().c_str()); i++; @@ -75,165 +74,174 @@ void ViewportWindows::renderUI() { // Render and resize ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f)); bool open = true; - ImGui::Begin(nameBuf, &open); - if (_viewportRendering) { - //----- Move camera -----// - // Check started camera movement - if (ImGui::IsMouseClicked(2) && ImGui::IsWindowHovered()) - activeViewport = i; - - // Update camera (wheel pressed) - if (activeViewport == i && ImGui::IsWindowHovered()) { - viewport->getCamera()->setViewportSize(viewport->getWidth(), viewport->getHeight()); - viewport->getCamera()->move(); + if (ImGui::Begin(nameBuf, &open)) { + // Viewport context menu + if (ImGui::BeginPopupContextItem("ViewportWindowContextMenu")) { + if (ImGui::MenuItem("Edit")) + _openModals[viewport->getSID()] = true; + ImGui::EndPopup(); } - //----- Mouse click -----// - vec2i click = {-1, -1}; - if (ImGui::IsMouseClicked(0) && ImGui::IsWindowHovered()) { - ImVec2 window = ImGui::GetWindowPos(); - ImVec2 cursor = ImGui::GetCursorPos(); - ImVec2 mouse = ImGui::GetMousePos(); - click = {int(mouse.x - window.x - cursor.x), int(mouse.y - window.y - cursor.y)}; + if (_viewportRendering) { + //----- Move camera -----// + // Check started camera movement + if (ImGui::IsMouseClicked(2) && ImGui::IsWindowHovered()) + activeViewport = i; + + // Update camera (wheel pressed) + if (activeViewport == i && ImGui::IsWindowHovered()) { + viewport->getCamera()->setViewportSize(viewport->getWidth(), viewport->getHeight()); + viewport->getCamera()->move(); + } + + //----- Mouse click -----// + vec2i click = {-1, -1}; + if (ImGui::IsMouseClicked(0) && ImGui::IsWindowHovered()) { + ImVec2 window = ImGui::GetWindowPos(); + ImVec2 cursor = ImGui::GetCursorPos(); + ImVec2 mouse = ImGui::GetMousePos(); + click = {int(mouse.x - window.x - cursor.x), int(mouse.y - window.y - cursor.y)}; + } + + if (ImGui::IsMouseClicked(1) && ImGui::IsWindowHovered()) + ImGui::OpenPopup("Editor_AddBasicShape"); + addBasicShapePopup(); + + //----- Keyboard click -----// + // static ImGuizmo::OPERATION mouseOperation = ImGuizmo::OPERATION::TRANSLATE; + // static ImGuizmo::MODE mouseMode = ImGuizmo::MODE::LOCAL; + // static bool snap = false; + + // if (ImGui::IsWindowHovered()) { + // snap = false; + // ImGuiIO& io = ImGui::GetIO(); + // if (ImGui::IsKeyPressed(ImGuiKey_T) && io.KeyCtrl) { + // mouseOperation = ImGuizmo::OPERATION::TRANSLATE; + // mouseMode = ImGuizmo::MODE::LOCAL; + // } else if (ImGui::IsKeyPressed(ImGuiKey_T) && io.KeyShift) { + // mouseOperation = ImGuizmo::OPERATION::TRANSLATE; + // mouseMode = ImGuizmo::MODE::WORLD; + // } else if (ImGui::IsKeyPressed(ImGuiKey_S) && io.KeyCtrl) { + // mouseOperation = ImGuizmo::OPERATION::SCALE; + // mouseMode = ImGuizmo::MODE::LOCAL; + // } else if (ImGui::IsKeyPressed(ImGuiKey_S) && io.KeyShift) { + // mouseOperation = ImGuizmo::OPERATION::SCALE; + // mouseMode = ImGuizmo::MODE::WORLD; + // } else if (ImGui::IsKeyPressed(ImGuiKey_R) && io.KeyCtrl) { + // mouseOperation = ImGuizmo::OPERATION::ROTATE; + // mouseMode = ImGuizmo::MODE::LOCAL; + // } else if (ImGui::IsKeyPressed(ImGuiKey_R) && io.KeyShift) { + // mouseOperation = ImGuizmo::OPERATION::ROTATE; + // mouseMode = ImGuizmo::MODE::WORLD; + // } else if (io.KeyCtrl) + // snap = true; + // } + + //----- Render to texture -----// + ImVec2 size = ImVec2(viewport->getWidth(), viewport->getHeight()); + ImGui::Image((ImTextureID)(intptr_t)viewport->getImGuiTexture(), size, ImVec2(0, 0), ImVec2(1, 1)); + + // //----- ImGuizmo -----// + // bool imGuizmoUsingMouse = false; + // component::EntityId entity = component::getSelectedEntity(); + // if (entity >= 0) { + // component::Transform* t = component::getComponent(entity); + + // if (t) { + // ImGuizmo::SetOrthographic(viewport->getCamera()->getName() == "OrthographicCamera"); + // ImGuizmo::SetDrawlist(); + // ImGuizmo::SetRect(ImGui::GetWindowPos().x + 5.0f, ImGui::GetWindowPos().y + 24.0f, viewport->getWidth(), + // viewport->getHeight()); + // mat4 view = transpose(viewport->getCamera()->getView()); + // mat4 proj = viewport->getCamera()->getProj(); + // proj.mat[1][1] *= -1; + // proj.transpose(); + + // mat4 transform = transpose(t->getWorldTransformMatrix(entity)); + + // float snapValue = 0.5f; + // if (mouseOperation == ImGuizmo::OPERATION::ROTATE) + // snapValue = 45.0f; + // float snapValues[3] = {snapValue, snapValue, snapValue}; + + // ImGuizmo::Manipulate(view.data, proj.data, mouseOperation, mouseMode, transform.data, nullptr, snap ? snapValues : + // nullptr); + + // if (ImGuizmo::IsUsing()) { + // imGuizmoUsingMouse = true; + // transform.transpose(); + + // // Get changed + // vec3 pos, scale; + // quat newOri; + // transform.getPosOriScale(pos, newOri, scale); + // vec3 oriDelta = newOri.getEuler() - t->orientation.getEuler(); + // quat ori; + // ori.setEuler(t->orientation.getEuler() + oriDelta); + + // // Delta world to local + // component::Relationship* r = component::getComponent(entity); + // if (r && r->getParent() != -1) { + // // Get transform of the first entity that has transform when going up in the hierarchy + // component::Transform* pt = nullptr; + // component::EntityId parentId = -1; + // while (pt == nullptr) { + // parentId = r->getParent(); + // pt = component::getComponent(parentId); + // r = component::getComponent(parentId); + // if (r->getParent() == -1) + // break; + // } + + // // If found some entity with transform component, convert result to be relative to it + // if (pt) { + // component::Transform pTransform = pt->getWorldTransform(parentId); + // vec3 pPos = pTransform.position; + // vec3 pScale = pTransform.scale; + // quat pOri = pTransform.orientation; + + // // Calculate pos ori scale relative to parent + // pos -= pPos; + // scale /= pScale; + // ori = ori * (-pOri); // Rotation from pOri to ori + // } + // } + + // // Update entity transform + // if (mouseOperation == ImGuizmo::OPERATION::TRANSLATE) + // t->position = pos; + // else if (mouseOperation == ImGuizmo::OPERATION::ROTATE) + // t->orientation = ori; + // else if (mouseOperation == ImGuizmo::OPERATION::SCALE) + // t->scale = scale; + + // // component::RigidBody2D* rb2d = component::getComponent(entity); + // // if (rb2d) { + // // if (mouseOperation == ImGuizmo::OPERATION::TRANSLATE || mouseOperation == ImGuizmo::OPERATION::ROTATE) { + // // vec2 pos = vec2(t->position); + // // float angle = -t->orientation.getEuler().z; + // // rb2d->setTransform(pos, angle); + // // } else if (mouseOperation == ImGuizmo::OPERATION::SCALE) { + // // // TODO Recreate box2d rigid body + // // } + // // } + // } + // } + // } + + // //----- Mouse click selection -----// + // if (!imGuizmoUsingMouse) { + // if (click.x >= 0 && click.y >= 0 && click.x < (int)viewport->getWidth() && click.y < (int)viewport->getHeight()) { + // component::EntityId eid = _computeEntityClick(viewport->getRenderer(), viewport->getCamera(), click); + // component::setSelectedEntity(eid); + // } + // } + + //----- Resize -----// + ImVec2 windowSize = ImGui::GetWindowSize(); + if (windowSize.x != size.x || windowSize.y != size.y) + viewport->resize((uint32_t)windowSize.x - 10, (uint32_t)windowSize.y - 30); } - - if (ImGui::IsMouseClicked(1) && ImGui::IsWindowHovered()) - ImGui::OpenPopup("Editor_AddBasicShape"); - addBasicShapePopup(); - - //----- Keyboard click -----// - // static ImGuizmo::OPERATION mouseOperation = ImGuizmo::OPERATION::TRANSLATE; - // static ImGuizmo::MODE mouseMode = ImGuizmo::MODE::LOCAL; - // static bool snap = false; - - // if (ImGui::IsWindowHovered()) { - // snap = false; - // ImGuiIO& io = ImGui::GetIO(); - // if (ImGui::IsKeyPressed(ImGuiKey_T) && io.KeyCtrl) { - // mouseOperation = ImGuizmo::OPERATION::TRANSLATE; - // mouseMode = ImGuizmo::MODE::LOCAL; - // } else if (ImGui::IsKeyPressed(ImGuiKey_T) && io.KeyShift) { - // mouseOperation = ImGuizmo::OPERATION::TRANSLATE; - // mouseMode = ImGuizmo::MODE::WORLD; - // } else if (ImGui::IsKeyPressed(ImGuiKey_S) && io.KeyCtrl) { - // mouseOperation = ImGuizmo::OPERATION::SCALE; - // mouseMode = ImGuizmo::MODE::LOCAL; - // } else if (ImGui::IsKeyPressed(ImGuiKey_S) && io.KeyShift) { - // mouseOperation = ImGuizmo::OPERATION::SCALE; - // mouseMode = ImGuizmo::MODE::WORLD; - // } else if (ImGui::IsKeyPressed(ImGuiKey_R) && io.KeyCtrl) { - // mouseOperation = ImGuizmo::OPERATION::ROTATE; - // mouseMode = ImGuizmo::MODE::LOCAL; - // } else if (ImGui::IsKeyPressed(ImGuiKey_R) && io.KeyShift) { - // mouseOperation = ImGuizmo::OPERATION::ROTATE; - // mouseMode = ImGuizmo::MODE::WORLD; - // } else if (io.KeyCtrl) - // snap = true; - // } - - //----- Render to texture -----// - ImVec2 size = ImVec2(viewport->getWidth(), viewport->getHeight()); - ImGui::Image((ImTextureID)(intptr_t)viewport->getImGuiTexture(), size, ImVec2(0, 0), ImVec2(1, 1)); - - // //----- ImGuizmo -----// - // bool imGuizmoUsingMouse = false; - // component::EntityId entity = component::getSelectedEntity(); - // if (entity >= 0) { - // component::Transform* t = component::getComponent(entity); - - // if (t) { - // ImGuizmo::SetOrthographic(viewport->getCamera()->getName() == "OrthographicCamera"); - // ImGuizmo::SetDrawlist(); - // ImGuizmo::SetRect(ImGui::GetWindowPos().x + 5.0f, ImGui::GetWindowPos().y + 24.0f, viewport->getWidth(), - // viewport->getHeight()); - // mat4 view = transpose(viewport->getCamera()->getView()); - // mat4 proj = viewport->getCamera()->getProj(); - // proj.mat[1][1] *= -1; - // proj.transpose(); - - // mat4 transform = transpose(t->getWorldTransformMatrix(entity)); - - // float snapValue = 0.5f; - // if (mouseOperation == ImGuizmo::OPERATION::ROTATE) - // snapValue = 45.0f; - // float snapValues[3] = {snapValue, snapValue, snapValue}; - - // ImGuizmo::Manipulate(view.data, proj.data, mouseOperation, mouseMode, transform.data, nullptr, snap ? snapValues : nullptr); - - // if (ImGuizmo::IsUsing()) { - // imGuizmoUsingMouse = true; - // transform.transpose(); - - // // Get changed - // vec3 pos, scale; - // quat newOri; - // transform.getPosOriScale(pos, newOri, scale); - // vec3 oriDelta = newOri.getEuler() - t->orientation.getEuler(); - // quat ori; - // ori.setEuler(t->orientation.getEuler() + oriDelta); - - // // Delta world to local - // component::Relationship* r = component::getComponent(entity); - // if (r && r->getParent() != -1) { - // // Get transform of the first entity that has transform when going up in the hierarchy - // component::Transform* pt = nullptr; - // component::EntityId parentId = -1; - // while (pt == nullptr) { - // parentId = r->getParent(); - // pt = component::getComponent(parentId); - // r = component::getComponent(parentId); - // if (r->getParent() == -1) - // break; - // } - - // // If found some entity with transform component, convert result to be relative to it - // if (pt) { - // component::Transform pTransform = pt->getWorldTransform(parentId); - // vec3 pPos = pTransform.position; - // vec3 pScale = pTransform.scale; - // quat pOri = pTransform.orientation; - - // // Calculate pos ori scale relative to parent - // pos -= pPos; - // scale /= pScale; - // ori = ori * (-pOri); // Rotation from pOri to ori - // } - // } - - // // Update entity transform - // if (mouseOperation == ImGuizmo::OPERATION::TRANSLATE) - // t->position = pos; - // else if (mouseOperation == ImGuizmo::OPERATION::ROTATE) - // t->orientation = ori; - // else if (mouseOperation == ImGuizmo::OPERATION::SCALE) - // t->scale = scale; - - // // component::RigidBody2D* rb2d = component::getComponent(entity); - // // if (rb2d) { - // // if (mouseOperation == ImGuizmo::OPERATION::TRANSLATE || mouseOperation == ImGuizmo::OPERATION::ROTATE) { - // // vec2 pos = vec2(t->position); - // // float angle = -t->orientation.getEuler().z; - // // rb2d->setTransform(pos, angle); - // // } else if (mouseOperation == ImGuizmo::OPERATION::SCALE) { - // // // TODO Recreate box2d rigid body - // // } - // // } - // } - // } - // } - - // //----- Mouse click selection -----// - // if (!imGuizmoUsingMouse) { - // if (click.x >= 0 && click.y >= 0 && click.x < (int)viewport->getWidth() && click.y < (int)viewport->getHeight()) { - // component::EntityId eid = _computeEntityClick(viewport->getRenderer(), viewport->getCamera(), click); - // component::setSelectedEntity(eid); - // } - // } - - //----- Resize -----// - ImVec2 windowSize = ImGui::GetWindowSize(); - if (windowSize.x != size.x || windowSize.y != size.y) - viewport->resize((uint32_t)windowSize.x - 10, (uint32_t)windowSize.y - 30); } ImGui::End(); ImGui::PopStyleVar(1); @@ -241,23 +249,25 @@ void ViewportWindows::renderUI() { if (!open) removeViewport(viewport); } + + renderModals(); } const std::vector>& ViewportWindows::getViewports() const { return _viewports; } void ViewportWindows::clearViewports() { + _openModals.clear(); _viewportsNext.clear(); _swapViewports = true; } void ViewportWindows::addViewport(std::shared_ptr viewport) { - _viewportsNext = _viewports; _viewportsNext.push_back(viewport); _swapViewports = true; } void ViewportWindows::removeViewport(std::shared_ptr viewport) { - _viewportsNext = _viewports; + _openModals[viewport->getSID()] = false; for (unsigned i = 0; i < _viewportsNext.size(); i++) if (_viewportsNext[i] == viewport) { _viewportsNext.erase(_viewportsNext.begin() + i); @@ -266,40 +276,31 @@ void ViewportWindows::removeViewport(std::shared_ptr viewport) { _swapViewports = true; } -void ViewportWindows::openViewportModal(StringId sid) const { - // XXX - // std::vector> viewports = graphics::getViewports(); - // static std::vector newViewportModals; // If first time creating the modal - //_viewportModals.resize(viewports.size()); - - //// Check if first time creating viewport - // newViewportModals.resize(_viewportModals.size()); - // for (unsigned i = 0; i < newViewportModals.size(); i++) - // newViewportModals[i] = !newViewportModals[i] && _viewportModals[i]; - - // for (uint32_t i = 0; i < _viewportModals.size(); i++) { - // char nameBuf[196]; - // sprintf(nameBuf, "%s###ViewportProps%s", viewports[i]->getName().c_str(), viewports[i]->getSID().getString().c_str()); - - // bool open = _viewportModals[i]; - // if (open) { - // if (newViewportModals[i]) - // ImGui::SetNextWindowSize(ImVec2(200.0f, 300.0f)); - // if (ImGui::Begin(nameBuf, &open)) { - // viewports[i]->renderUI(); - - // ImGui::Separator(); - // if (ImGui::Button("Delete Viewport")) { - // graphics::removeViewport(viewports[i]); - // ImGui::End(); - // break; - // } - // } - // ImGui::End(); - // _viewportModals[i] = open; - // } - //} - // newViewportModals = _viewportModals; +void ViewportWindows::openViewportModal(StringId sid) { _openModals[sid] = true; } + +void ViewportWindows::renderModals() { + for (auto& viewport : _viewports) { + char nameBuf[196]; + sprintf(nameBuf, "%s###ViewportModal%s", viewport->getName().c_str(), viewport->getSID().getString().c_str()); + + StringId sid = viewport->getSID(); + bool open = _openModals[sid]; + if (open) { + ImGui::SetNextWindowSize(ImVec2(350, 250), ImGuiCond_FirstUseEver); + if (ImGui::Begin(nameBuf, &open)) { + viewport->renderUI(); + + ImGui::Separator(); + if (ImGui::Button("Delete Viewport")) { + removeViewport(viewport); + ImGui::End(); + break; + } + } + ImGui::End(); + _openModals[sid] = open; + } + } } void ViewportWindows::createDefaultViewports() { diff --git a/src/atta/ui/windows/viewport/viewportWindows.h b/src/atta/ui/windows/viewport/viewportWindows.h index 2ef04905..8009aed3 100644 --- a/src/atta/ui/windows/viewport/viewportWindows.h +++ b/src/atta/ui/windows/viewport/viewportWindows.h @@ -25,13 +25,14 @@ class ViewportWindows { void clearViewports(); void addViewport(std::shared_ptr viewport); void removeViewport(std::shared_ptr viewport); - void openViewportModal(StringId sid) const; + void openViewportModal(StringId sid); bool getViewportRendering() const; void setViewportRendering(bool viewportRendering); private: void createDefaultViewports(); void addBasicShapePopup(); + void renderModals(); std::vector> _viewports; ///< Current viewports to be rendered std::vector> _viewportsNext; ///< Being used for now to update the viewports in the next frame without breaking imgui @@ -41,6 +42,7 @@ class ViewportWindows { // Compute std::unique_ptr _computeEntityClick; + std::map _openModals; ///< Open modals for each viewport }; } // namespace atta::ui From ff49bfed3078e10f59a122540a6f0d05a9bef1b6 Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Sun, 19 Jan 2025 09:32:22 +0100 Subject: [PATCH 33/37] Refactor: File viewport gfx to ui --- src/atta/file/project/projectSerializer.cpp | 2 +- src/atta/file/project/projectSerializerDeserialize.cpp | 6 +++--- src/atta/file/project/projectSerializerSerialize.cpp | 6 +++--- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/atta/file/project/projectSerializer.cpp b/src/atta/file/project/projectSerializer.cpp index 30d58357..2dad5b0f 100644 --- a/src/atta/file/project/projectSerializer.cpp +++ b/src/atta/file/project/projectSerializer.cpp @@ -17,7 +17,7 @@ #include #include -#include +#include #include #include diff --git a/src/atta/file/project/projectSerializerDeserialize.cpp b/src/atta/file/project/projectSerializerDeserialize.cpp index 75b66d20..eb1cb451 100644 --- a/src/atta/file/project/projectSerializerDeserialize.cpp +++ b/src/atta/file/project/projectSerializerDeserialize.cpp @@ -50,11 +50,11 @@ void ProjectSerializer::deserializeGraphicsModule(Section& section) { if (section.contains("viewports")) { std::vector viewports = std::vector(section["viewports"]); LOG_WARN("file::ProjectSerializer", "Deserializing viewports was not implemented yet"); - // graphics::clearViewports(); + // ui::clearViewports(); // for (auto& viewport : viewports) { - // std::shared_ptr v = std::make_shared(); + // std::shared_ptr v = std::make_shared(); // *v = viewport; - // graphics::addViewport(v); + // ui::addViewport(v); // } } if (section.contains("graphicsFPS")) diff --git a/src/atta/file/project/projectSerializerSerialize.cpp b/src/atta/file/project/projectSerializerSerialize.cpp index 4e78072b..2224e138 100644 --- a/src/atta/file/project/projectSerializerSerialize.cpp +++ b/src/atta/file/project/projectSerializerSerialize.cpp @@ -59,9 +59,9 @@ void ProjectSerializer::serializeComponentModule(Section& section) { } void ProjectSerializer::serializeGraphicsModule(Section& section) { - // std::vector> pviewports = graphics::getViewports(); - // std::vector viewports; - // for (auto pv : pviewports) + // std::vector> pviewports = ui::getViewports(); + // std::vector viewports; + // for (auto& pv : pviewports) // viewports.push_back(*pv); // section["viewports"] = viewports; LOG_WARN("file::ProjectSerializer", "Serializing viewports was not implemented yet"); From d74f3d8226e5816943996213207739c633f1dbe5 Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Sun, 19 Jan 2025 10:00:48 +0100 Subject: [PATCH 34/37] Fix: Viewport entity click --- src/atta/ui/windows/viewport/viewportWindows.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/atta/ui/windows/viewport/viewportWindows.cpp b/src/atta/ui/windows/viewport/viewportWindows.cpp index 95733202..614ad711 100644 --- a/src/atta/ui/windows/viewport/viewportWindows.cpp +++ b/src/atta/ui/windows/viewport/viewportWindows.cpp @@ -141,8 +141,8 @@ void ViewportWindows::renderUI() { ImVec2 size = ImVec2(viewport->getWidth(), viewport->getHeight()); ImGui::Image((ImTextureID)(intptr_t)viewport->getImGuiTexture(), size, ImVec2(0, 0), ImVec2(1, 1)); - // //----- ImGuizmo -----// - // bool imGuizmoUsingMouse = false; + //----- ImGuizmo -----// + bool imGuizmoUsingMouse = false; // component::EntityId entity = component::getSelectedEntity(); // if (entity >= 0) { // component::Transform* t = component::getComponent(entity); @@ -230,12 +230,12 @@ void ViewportWindows::renderUI() { // } // //----- Mouse click selection -----// - // if (!imGuizmoUsingMouse) { - // if (click.x >= 0 && click.y >= 0 && click.x < (int)viewport->getWidth() && click.y < (int)viewport->getHeight()) { - // component::EntityId eid = _computeEntityClick(viewport->getRenderer(), viewport->getCamera(), click); - // component::setSelectedEntity(eid); - // } - // } + if (!imGuizmoUsingMouse) { + if (click.x >= 0 && click.y >= 0 && click.x < (int)viewport->getWidth() && click.y < (int)viewport->getHeight()) { + cmp::EntityId eid = _computeEntityClick->click(viewport->getRenderer(), viewport->getCamera(), click); + cmp::setSelectedEntity(eid); + } + } //----- Resize -----// ImVec2 windowSize = ImGui::GetWindowSize(); From 5edf760010c45f3d1e573be7bef77813d423a05f Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Sun, 19 Jan 2025 11:42:42 +0100 Subject: [PATCH 35/37] Feat: Show gizmo for selected entity --- src/atta/ui/CMakeLists.txt | 1 + src/atta/ui/widgets/gizmo.cpp | 55 ++++--- src/atta/ui/widgets/gizmo.h | 10 +- .../ui/windows/viewport/viewportWindows.cpp | 149 ++++-------------- .../ui/windows/viewport/viewportWindows.h | 6 + 5 files changed, 72 insertions(+), 149 deletions(-) diff --git a/src/atta/ui/CMakeLists.txt b/src/atta/ui/CMakeLists.txt index 1e062e14..7e4da02e 100644 --- a/src/atta/ui/CMakeLists.txt +++ b/src/atta/ui/CMakeLists.txt @@ -11,6 +11,7 @@ set(ATTA_UI_MODULE_SOURCE widgets/align.cpp widgets/button.cpp + widgets/gizmo.cpp widgets/help.cpp widgets/image.cpp diff --git a/src/atta/ui/widgets/gizmo.cpp b/src/atta/ui/widgets/gizmo.cpp index aeff0b0f..2833704d 100644 --- a/src/atta/ui/widgets/gizmo.cpp +++ b/src/atta/ui/widgets/gizmo.cpp @@ -16,35 +16,35 @@ namespace atta::ui { -Gizmo::Gizmo() : _operation(TRANSLATE), _mode(WORLD), _isOrthographic(false), _snap(false) {} +Gizmo::Gizmo() : _operation(TRANSLATE), _mode(WORLD), _snap(false) {} void Gizmo::setOperation(Operation operation) { _operation = operation; } void Gizmo::setMode(Mode mode) { _mode = mode; } +void Gizmo::setCamera(std::weak_ptr camera) { _camera = camera; } void Gizmo::setSnap(bool snap) { _snap = snap; } -void Gizmo::setCamera(std::weak_ptr camera) { _camera = camera; } - -ImGuizmo::OPERATION convert(Operation operation) { +ImGuizmo::OPERATION convert(Gizmo::Operation operation) { ImGuizmo::OPERATION result{}; - if (operation & TRANSLATE > 0) + if ((operation & Gizmo::TRANSLATE) > 0) result = result | ImGuizmo::OPERATION::TRANSLATE; - if (operation & ROTATE > 0) + if ((operation & Gizmo::ROTATE) > 0) result = result | ImGuizmo::OPERATION::ROTATE; - if (operation & SCALE > 0) + if ((operation & Gizmo::SCALE) > 0) result = result | ImGuizmo::OPERATION::SCALE; return result; } -ImGuizmo::MODE convert(Mode mode) { return mode == WORLD ? ImGuizmo::MODE::WORLD : ImGuizmo::MODE::LOCAL; } +ImGuizmo::MODE convert(Gizmo::Mode mode) { return mode == Gizmo::WORLD ? ImGuizmo::MODE::WORLD : ImGuizmo::MODE::LOCAL; } -bool Gizmo::manipulate(component::EntityId entity) { - std::shared_ptr camera = _camera.lock(); - component::Transform* t = component::getComponent(entity); - if (t) { +bool Gizmo::manipulate(cmp::EntityId entity) { + std::shared_ptr camera = _camera.lock(); + cmp::Transform* t = cmp::getComponent(entity); + if (camera && t) { mat4 transform = transpose(t->getWorldTransformMatrix(entity)); - ImGuizmo::SetDrawlist(); - ImGuizmo::SetRect(ImGui::GetWindowPos().x + 5.0f, ImGui::GetWindowPos().y + 24.0f, 500, 500); + ImVec2 windowPos = ImGui::GetWindowPos(); + ImVec2 windowSize = ImGui::GetWindowSize(); + ImGuizmo::SetRect(windowPos.x, windowPos.y, windowSize.x - 10.0f, windowSize.y - 8.0f); ImGuizmo::OPERATION operation = convert(_operation); ImGuizmo::MODE mode = convert(_mode); @@ -54,7 +54,12 @@ bool Gizmo::manipulate(component::EntityId entity) { mat4 proj = transpose(camera->getProj()); proj.mat[1][1] *= -1; - if (ImGuizmo::Manipulate(transpose(_view).data, _proj.data, operation, mode, transform.data, nullptr, snap ? snapValues : nullptr)) { + float snapValue = 0.5f; + if (operation == ImGuizmo::OPERATION::ROTATE) + snapValue = 45.0f; + float snapValues[3] = {snapValue, snapValue, snapValue}; + + if (ImGuizmo::Manipulate(view.data, proj.data, operation, mode, transform.data, nullptr, _snap ? snapValues : nullptr)) { transform.transpose(); // Get changed @@ -66,22 +71,22 @@ bool Gizmo::manipulate(component::EntityId entity) { ori.setEuler(t->orientation.getEuler() + oriDelta); // Delta world to local - component::Relationship* r = component::getComponent(entity); + cmp::Relationship* r = cmp::getComponent(entity); if (r && r->getParent() != -1) { // Get transform of the first entity that has transform when going up in the hierarchy - component::Transform* pt = nullptr; - component::EntityId parentId = -1; + cmp::Transform* pt = nullptr; + cmp::EntityId parentId = -1; while (pt == nullptr) { parentId = r->getParent(); - pt = component::getComponent(parentId); - r = component::getComponent(parentId); + pt = cmp::getComponent(parentId); + r = cmp::getComponent(parentId); if (r->getParent() == -1) break; } // If found some entity with transform component, convert result to be relative to it if (pt) { - component::Transform pTransform = pt->getWorldTransform(parentId); + cmp::Transform pTransform = pt->getWorldTransform(parentId); vec3 pPos = pTransform.position; vec3 pScale = pTransform.scale; quat pOri = pTransform.orientation; @@ -94,14 +99,14 @@ bool Gizmo::manipulate(component::EntityId entity) { } // Update entity transform - if (mouseOperation == ImGuizmo::OPERATION::TRANSLATE) + if (operation == ImGuizmo::OPERATION::TRANSLATE) t->position = pos; - else if (mouseOperation == ImGuizmo::OPERATION::ROTATE) + else if (operation == ImGuizmo::OPERATION::ROTATE) t->orientation = ori; - else if (mouseOperation == ImGuizmo::OPERATION::SCALE) + else if (operation == ImGuizmo::OPERATION::SCALE) t->scale = scale; - // component::RigidBody2D* rb2d = component::getComponent(entity); + // cmp::RigidBody2D* rb2d = cmp::getComponent(entity); // if (rb2d) { // if (mouseOperation == ImGuizmo::OPERATION::TRANSLATE || mouseOperation == ImGuizmo::OPERATION::ROTATE) { // vec2 pos = vec2(t->position); diff --git a/src/atta/ui/widgets/gizmo.h b/src/atta/ui/widgets/gizmo.h index 5ac81562..c36d1fa3 100644 --- a/src/atta/ui/widgets/gizmo.h +++ b/src/atta/ui/widgets/gizmo.h @@ -18,15 +18,19 @@ class Gizmo { TRANSLATE = 1 << 0, ROTATE = 1 << 1, SCALE = 1 << 2, + TRANSLATE_ROTATE = TRANSLATE | ROTATE, + TRANSLATE_SCALE = TRANSLATE | SCALE, + ROTATE_SCALE = ROTATE | SCALE, + ALL = TRANSLATE | ROTATE | SCALE }; - inline Operation operator|(OPERATION l, OPERATION r) { return Operation(int(l) | int(r)); } + friend inline Operation operator|(Operation l, Operation r) { return Operation(int(l) | int(r)); } enum Mode { WORLD = 0, LOCAL }; Gizmo(); void setOperation(Operation operation); void setMode(Mode mode); - void setCamera(std::weak_ptr camera); + void setCamera(std::weak_ptr camera); void setSnap(bool snap); bool manipulate(component::EntityId entity); @@ -34,7 +38,7 @@ class Gizmo { private: Operation _operation; Mode _mode; - std::weak_ptr _camera; + std::weak_ptr _camera; bool _snap; }; diff --git a/src/atta/ui/windows/viewport/viewportWindows.cpp b/src/atta/ui/windows/viewport/viewportWindows.cpp index 614ad711..9c8f908a 100644 --- a/src/atta/ui/windows/viewport/viewportWindows.cpp +++ b/src/atta/ui/windows/viewport/viewportWindows.cpp @@ -4,6 +4,7 @@ // Date: 2021-12-28 // By Breno Cunha Queiroz //-------------------------------------------------- +#include #include #include #include @@ -107,130 +108,36 @@ void ViewportWindows::renderUI() { ImGui::OpenPopup("Editor_AddBasicShape"); addBasicShapePopup(); - //----- Keyboard click -----// - // static ImGuizmo::OPERATION mouseOperation = ImGuizmo::OPERATION::TRANSLATE; - // static ImGuizmo::MODE mouseMode = ImGuizmo::MODE::LOCAL; - // static bool snap = false; - - // if (ImGui::IsWindowHovered()) { - // snap = false; - // ImGuiIO& io = ImGui::GetIO(); - // if (ImGui::IsKeyPressed(ImGuiKey_T) && io.KeyCtrl) { - // mouseOperation = ImGuizmo::OPERATION::TRANSLATE; - // mouseMode = ImGuizmo::MODE::LOCAL; - // } else if (ImGui::IsKeyPressed(ImGuiKey_T) && io.KeyShift) { - // mouseOperation = ImGuizmo::OPERATION::TRANSLATE; - // mouseMode = ImGuizmo::MODE::WORLD; - // } else if (ImGui::IsKeyPressed(ImGuiKey_S) && io.KeyCtrl) { - // mouseOperation = ImGuizmo::OPERATION::SCALE; - // mouseMode = ImGuizmo::MODE::LOCAL; - // } else if (ImGui::IsKeyPressed(ImGuiKey_S) && io.KeyShift) { - // mouseOperation = ImGuizmo::OPERATION::SCALE; - // mouseMode = ImGuizmo::MODE::WORLD; - // } else if (ImGui::IsKeyPressed(ImGuiKey_R) && io.KeyCtrl) { - // mouseOperation = ImGuizmo::OPERATION::ROTATE; - // mouseMode = ImGuizmo::MODE::LOCAL; - // } else if (ImGui::IsKeyPressed(ImGuiKey_R) && io.KeyShift) { - // mouseOperation = ImGuizmo::OPERATION::ROTATE; - // mouseMode = ImGuizmo::MODE::WORLD; - // } else if (io.KeyCtrl) - // snap = true; - // } - - //----- Render to texture -----// + //----- Operation selection -----// + if (ImGui::IsWindowHovered()) { + ImGuiIO& io = ImGui::GetIO(); + + if (io.KeyCtrl) + _gizmo.setMode(Gizmo::LOCAL); + if (io.KeyShift) + _gizmo.setMode(Gizmo::WORLD); + + if (ImGui::IsKeyPressed(ImGuiKey_T)) + _gizmo.setOperation(Gizmo::TRANSLATE); + else if (ImGui::IsKeyPressed(ImGuiKey_S)) + _gizmo.setOperation(Gizmo::SCALE); + else if (ImGui::IsKeyPressed(ImGuiKey_R)) + _gizmo.setOperation(Gizmo::ROTATE); + } + + //----- Render viewport to texture -----// ImVec2 size = ImVec2(viewport->getWidth(), viewport->getHeight()); ImGui::Image((ImTextureID)(intptr_t)viewport->getImGuiTexture(), size, ImVec2(0, 0), ImVec2(1, 1)); - //----- ImGuizmo -----// - bool imGuizmoUsingMouse = false; - // component::EntityId entity = component::getSelectedEntity(); - // if (entity >= 0) { - // component::Transform* t = component::getComponent(entity); - - // if (t) { - // ImGuizmo::SetOrthographic(viewport->getCamera()->getName() == "OrthographicCamera"); - // ImGuizmo::SetDrawlist(); - // ImGuizmo::SetRect(ImGui::GetWindowPos().x + 5.0f, ImGui::GetWindowPos().y + 24.0f, viewport->getWidth(), - // viewport->getHeight()); - // mat4 view = transpose(viewport->getCamera()->getView()); - // mat4 proj = viewport->getCamera()->getProj(); - // proj.mat[1][1] *= -1; - // proj.transpose(); - - // mat4 transform = transpose(t->getWorldTransformMatrix(entity)); - - // float snapValue = 0.5f; - // if (mouseOperation == ImGuizmo::OPERATION::ROTATE) - // snapValue = 45.0f; - // float snapValues[3] = {snapValue, snapValue, snapValue}; - - // ImGuizmo::Manipulate(view.data, proj.data, mouseOperation, mouseMode, transform.data, nullptr, snap ? snapValues : - // nullptr); - - // if (ImGuizmo::IsUsing()) { - // imGuizmoUsingMouse = true; - // transform.transpose(); - - // // Get changed - // vec3 pos, scale; - // quat newOri; - // transform.getPosOriScale(pos, newOri, scale); - // vec3 oriDelta = newOri.getEuler() - t->orientation.getEuler(); - // quat ori; - // ori.setEuler(t->orientation.getEuler() + oriDelta); - - // // Delta world to local - // component::Relationship* r = component::getComponent(entity); - // if (r && r->getParent() != -1) { - // // Get transform of the first entity that has transform when going up in the hierarchy - // component::Transform* pt = nullptr; - // component::EntityId parentId = -1; - // while (pt == nullptr) { - // parentId = r->getParent(); - // pt = component::getComponent(parentId); - // r = component::getComponent(parentId); - // if (r->getParent() == -1) - // break; - // } - - // // If found some entity with transform component, convert result to be relative to it - // if (pt) { - // component::Transform pTransform = pt->getWorldTransform(parentId); - // vec3 pPos = pTransform.position; - // vec3 pScale = pTransform.scale; - // quat pOri = pTransform.orientation; - - // // Calculate pos ori scale relative to parent - // pos -= pPos; - // scale /= pScale; - // ori = ori * (-pOri); // Rotation from pOri to ori - // } - // } - - // // Update entity transform - // if (mouseOperation == ImGuizmo::OPERATION::TRANSLATE) - // t->position = pos; - // else if (mouseOperation == ImGuizmo::OPERATION::ROTATE) - // t->orientation = ori; - // else if (mouseOperation == ImGuizmo::OPERATION::SCALE) - // t->scale = scale; - - // // component::RigidBody2D* rb2d = component::getComponent(entity); - // // if (rb2d) { - // // if (mouseOperation == ImGuizmo::OPERATION::TRANSLATE || mouseOperation == ImGuizmo::OPERATION::ROTATE) { - // // vec2 pos = vec2(t->position); - // // float angle = -t->orientation.getEuler().z; - // // rb2d->setTransform(pos, angle); - // // } else if (mouseOperation == ImGuizmo::OPERATION::SCALE) { - // // // TODO Recreate box2d rigid body - // // } - // // } - // } - // } - // } - - // //----- Mouse click selection -----// - if (!imGuizmoUsingMouse) { + //----- Gizmo manipulation -----// + bool gizmoUsingMouse = false; + _gizmo.setCamera(viewport->getCamera()); + cmp::EntityId eid = component::getSelectedEntity(); + if (eid >= 0 && _gizmo.manipulate(eid)) + gizmoUsingMouse = true; + + //----- Mouse click selection -----// + if (!gizmoUsingMouse) { if (click.x >= 0 && click.y >= 0 && click.x < (int)viewport->getWidth() && click.y < (int)viewport->getHeight()) { cmp::EntityId eid = _computeEntityClick->click(viewport->getRenderer(), viewport->getCamera(), click); cmp::setSelectedEntity(eid); diff --git a/src/atta/ui/windows/viewport/viewportWindows.h b/src/atta/ui/windows/viewport/viewportWindows.h index 8009aed3..47c89c29 100644 --- a/src/atta/ui/windows/viewport/viewportWindows.h +++ b/src/atta/ui/windows/viewport/viewportWindows.h @@ -9,6 +9,7 @@ #include #include +#include #include namespace atta::ui { @@ -40,8 +41,13 @@ class ViewportWindows { float _viewportFPS = 30.0; ///< Desired viewport FPS (UI module handles the viewport rendering) bool _viewportRendering = true; ///< If should render the viewport + // Gizmo + Gizmo _gizmo; + // Compute std::unique_ptr _computeEntityClick; + + // Modals std::map _openModals; ///< Open modals for each viewport }; From a4ac94f2fd781f4945895a64245a8bbf48b63b0f Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Sun, 19 Jan 2025 13:00:37 +0100 Subject: [PATCH 36/37] Fix: Guizmo interaction --- src/atta/ui/widgets/gizmo.cpp | 19 ++++++++++--------- src/atta/ui/widgets/gizmo.h | 6 +++--- .../ui/windows/viewport/viewportWindows.cpp | 16 ++++++++-------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/atta/ui/widgets/gizmo.cpp b/src/atta/ui/widgets/gizmo.cpp index 2833704d..901abec6 100644 --- a/src/atta/ui/widgets/gizmo.cpp +++ b/src/atta/ui/widgets/gizmo.cpp @@ -20,7 +20,7 @@ Gizmo::Gizmo() : _operation(TRANSLATE), _mode(WORLD), _snap(false) {} void Gizmo::setOperation(Operation operation) { _operation = operation; } void Gizmo::setMode(Mode mode) { _mode = mode; } -void Gizmo::setCamera(std::weak_ptr camera) { _camera = camera; } +void Gizmo::setViewport(std::weak_ptr viewport) { _viewport = viewport; } void Gizmo::setSnap(bool snap) { _snap = snap; } ImGuizmo::OPERATION convert(Gizmo::Operation operation) { @@ -37,21 +37,21 @@ ImGuizmo::OPERATION convert(Gizmo::Operation operation) { ImGuizmo::MODE convert(Gizmo::Mode mode) { return mode == Gizmo::WORLD ? ImGuizmo::MODE::WORLD : ImGuizmo::MODE::LOCAL; } bool Gizmo::manipulate(cmp::EntityId entity) { - std::shared_ptr camera = _camera.lock(); + std::shared_ptr viewport = _viewport.lock(); cmp::Transform* t = cmp::getComponent(entity); - if (camera && t) { + if (viewport && t) { mat4 transform = transpose(t->getWorldTransformMatrix(entity)); + ImGuizmo::SetOrthographic(viewport->getCamera()->getName() == "OrthographicCamera"); + ImGuizmo::SetDrawlist(); ImVec2 windowPos = ImGui::GetWindowPos(); - ImVec2 windowSize = ImGui::GetWindowSize(); - ImGuizmo::SetRect(windowPos.x, windowPos.y, windowSize.x - 10.0f, windowSize.y - 8.0f); + ImGuizmo::SetRect(windowPos.x, windowPos.y + 22.0f, viewport->getWidth(), viewport->getHeight()); ImGuizmo::OPERATION operation = convert(_operation); ImGuizmo::MODE mode = convert(_mode); - ImGuizmo::SetOrthographic(camera->getName() == "OrthographicCamera"); - mat4 view = transpose(camera->getView()); - mat4 proj = transpose(camera->getProj()); + mat4 view = transpose(viewport->getCamera()->getView()); + mat4 proj = transpose(viewport->getCamera()->getProj()); proj.mat[1][1] *= -1; float snapValue = 0.5f; @@ -59,7 +59,8 @@ bool Gizmo::manipulate(cmp::EntityId entity) { snapValue = 45.0f; float snapValues[3] = {snapValue, snapValue, snapValue}; - if (ImGuizmo::Manipulate(view.data, proj.data, operation, mode, transform.data, nullptr, _snap ? snapValues : nullptr)) { + ImGuizmo::Manipulate(view.data, proj.data, operation, mode, transform.data, nullptr, _snap ? snapValues : nullptr); + if (ImGuizmo::IsUsing()) { transform.transpose(); // Get changed diff --git a/src/atta/ui/widgets/gizmo.h b/src/atta/ui/widgets/gizmo.h index c36d1fa3..abb2979f 100644 --- a/src/atta/ui/widgets/gizmo.h +++ b/src/atta/ui/widgets/gizmo.h @@ -8,7 +8,7 @@ #define ATTA_UI_WIDGETS_GUIZMO_H #include -#include +#include namespace atta::ui { @@ -30,7 +30,7 @@ class Gizmo { void setOperation(Operation operation); void setMode(Mode mode); - void setCamera(std::weak_ptr camera); + void setViewport(std::weak_ptr viewport); void setSnap(bool snap); bool manipulate(component::EntityId entity); @@ -38,7 +38,7 @@ class Gizmo { private: Operation _operation; Mode _mode; - std::weak_ptr _camera; + std::weak_ptr _viewport; bool _snap; }; diff --git a/src/atta/ui/windows/viewport/viewportWindows.cpp b/src/atta/ui/windows/viewport/viewportWindows.cpp index 9c8f908a..79e888f3 100644 --- a/src/atta/ui/windows/viewport/viewportWindows.cpp +++ b/src/atta/ui/windows/viewport/viewportWindows.cpp @@ -89,12 +89,6 @@ void ViewportWindows::renderUI() { if (ImGui::IsMouseClicked(2) && ImGui::IsWindowHovered()) activeViewport = i; - // Update camera (wheel pressed) - if (activeViewport == i && ImGui::IsWindowHovered()) { - viewport->getCamera()->setViewportSize(viewport->getWidth(), viewport->getHeight()); - viewport->getCamera()->move(); - } - //----- Mouse click -----// vec2i click = {-1, -1}; if (ImGui::IsMouseClicked(0) && ImGui::IsWindowHovered()) { @@ -109,7 +103,7 @@ void ViewportWindows::renderUI() { addBasicShapePopup(); //----- Operation selection -----// - if (ImGui::IsWindowHovered()) { + if (ImGui::IsWindowHovered() && !ImGui::IsMouseDown(ImGuiMouseButton_Middle)) { ImGuiIO& io = ImGui::GetIO(); if (io.KeyCtrl) @@ -131,11 +125,17 @@ void ViewportWindows::renderUI() { //----- Gizmo manipulation -----// bool gizmoUsingMouse = false; - _gizmo.setCamera(viewport->getCamera()); + _gizmo.setViewport(viewport); cmp::EntityId eid = component::getSelectedEntity(); if (eid >= 0 && _gizmo.manipulate(eid)) gizmoUsingMouse = true; + //----- Camera control -----// + if (activeViewport == i && ImGui::IsWindowHovered()) { + viewport->getCamera()->setViewportSize(viewport->getWidth(), viewport->getHeight()); + viewport->getCamera()->move(); + } + //----- Mouse click selection -----// if (!gizmoUsingMouse) { if (click.x >= 0 && click.y >= 0 && click.x < (int)viewport->getWidth() && click.y < (int)viewport->getHeight()) { From d1ead43c0f1b00c46a6f21f091efd844a999f7dd Mon Sep 17 00:00:00 2001 From: Breno Cunha Queiroz Date: Sun, 19 Jan 2025 13:19:57 +0100 Subject: [PATCH 37/37] Chore: Update resources link --- src/extern/solveResources.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/extern/solveResources.cmake b/src/extern/solveResources.cmake index 84478261..befe4d8d 100644 --- a/src/extern/solveResources.cmake +++ b/src/extern/solveResources.cmake @@ -1,5 +1,5 @@ FetchContent_Declare(resources - URL "https://atta-resources.s3.amazonaws.com/v0.3.1-ui-temp.zip" + URL "https://atta-resources.s3.amazonaws.com/v0.3.2.zip" SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/resources )