From 8e8ac6c0bef1219e71a06df20b2240537220bfdb Mon Sep 17 00:00:00 2001 From: Green Sky Date: Mon, 11 Jan 2021 19:33:20 +0100 Subject: [PATCH] add sound tools --- framework/imgui/CMakeLists.txt | 3 + framework/imgui/src/mm/imgui/sound_info.cpp | 4 +- framework/imgui/src/mm/imgui/sound_info.hpp | 2 +- .../imgui/src/mm/services/engine_tools.cpp | 3 - .../imgui/src/mm/services/sound_tools.cpp | 75 +++++++++++++++++++ .../imgui/src/mm/services/sound_tools.hpp | 24 ++++++ framework/imgui/test/CMakeLists.txt | 2 +- framework/imgui/test/sound_test.cpp | 16 +++- 8 files changed, 119 insertions(+), 10 deletions(-) create mode 100644 framework/imgui/src/mm/services/sound_tools.cpp create mode 100644 framework/imgui/src/mm/services/sound_tools.hpp diff --git a/framework/imgui/CMakeLists.txt b/framework/imgui/CMakeLists.txt index 4b5b595..c308e7f 100644 --- a/framework/imgui/CMakeLists.txt +++ b/framework/imgui/CMakeLists.txt @@ -100,6 +100,9 @@ target_link_libraries(imgui_tools ################## imgui_sound add_library(imgui_sound + ./src/mm/services/sound_tools.hpp + ./src/mm/services/sound_tools.cpp + ./src/mm/imgui/sound_info.hpp ./src/mm/imgui/sound_pref.hpp diff --git a/framework/imgui/src/mm/imgui/sound_info.cpp b/framework/imgui/src/mm/imgui/sound_info.cpp index 11dda0e..8a8b81c 100644 --- a/framework/imgui/src/mm/imgui/sound_info.cpp +++ b/framework/imgui/src/mm/imgui/sound_info.cpp @@ -8,8 +8,8 @@ namespace MM { - void ImGuiSoundInfo(Engine& engine) { - if (ImGui::Begin("Sound Info")) { + void ImGuiSoundInfo(Engine& engine, bool* show) { + if (ImGui::Begin("Sound Info", show)) { auto& sound = engine.getService(); ImGui::Text("SoLoud v%d", sound.engine.getVersion()); diff --git a/framework/imgui/src/mm/imgui/sound_info.hpp b/framework/imgui/src/mm/imgui/sound_info.hpp index 8616d09..d182757 100644 --- a/framework/imgui/src/mm/imgui/sound_info.hpp +++ b/framework/imgui/src/mm/imgui/sound_info.hpp @@ -3,6 +3,6 @@ namespace MM { class Engine; // fwd - void ImGuiSoundInfo(Engine& engine); + void ImGuiSoundInfo(Engine& engine, bool* show = nullptr); } // MM diff --git a/framework/imgui/src/mm/services/engine_tools.cpp b/framework/imgui/src/mm/services/engine_tools.cpp index 88db2d0..9e9574f 100644 --- a/framework/imgui/src/mm/services/engine_tools.cpp +++ b/framework/imgui/src/mm/services/engine_tools.cpp @@ -7,9 +7,6 @@ #include -#include -#define LOGIGS(x) LOG("ImGuiSceneToolsService", x) - namespace MM::Services { bool ImGuiEngineTools::enable(Engine& engine) { diff --git a/framework/imgui/src/mm/services/sound_tools.cpp b/framework/imgui/src/mm/services/sound_tools.cpp new file mode 100644 index 0000000..dc099d7 --- /dev/null +++ b/framework/imgui/src/mm/services/sound_tools.cpp @@ -0,0 +1,75 @@ +#include "./sound_tools.hpp" +#include "mm/imgui/sound_info.hpp" + +#include +#include + +#include + +#include + +#include +#define LOGIGS(x) LOG("ImGuiSceneToolsService", x) + +namespace MM::Services { + + bool ImGuiSoundTools::enable(Engine& engine) { + auto& menu_bar = engine.getService(); + + //menu_bar.menu_tree["Engine"]["Stop Engine"] = [](Engine& e) { + //ImGui::Separator(); + //if (ImGui::MenuItem("Stop Engine")) { + //e.stop(); + //} + //}; + + menu_bar.menu_tree["Sound"]["GlobalVolume"] = [](Engine& e) { + auto& sound_e = e.getService().engine; + + auto gvolume = sound_e.getGlobalVolume(); + ImGui::SliderFloat("Global Volume", &gvolume, 0.f, 1.f); + sound_e.setGlobalVolume(gvolume); + }; + + menu_bar.menu_tree["Sound"]["Info"] = [this](Engine&) { + ImGui::MenuItem("Info", NULL, &_show_info); + }; + + return true; + } + + void ImGuiSoundTools::disable(Engine& engine) { + auto& menu_bar = engine.getService(); + + menu_bar.menu_tree["Sound"].erase("GlobalVolume"); + menu_bar.menu_tree["Sound"].erase("Info"); + } + + std::vector ImGuiSoundTools::registerUpdates(void) { + using namespace entt::literals; + return { + { + "ImGuiSoundTools::render"_hs, + "ImGuiSoundTools::render", + [this](Engine& e){ renderImGui(e); }, + UpdateStrategies::update_phase_t::MAIN, + true, + { + "ImGuiMenuBar::render"_hs + } + } + }; + } + + void ImGuiSoundTools::renderImGui(Engine& engine) { + if (_show_info) { + MM::ImGuiSoundInfo(engine, &_show_info); + } + + //if (_show_services) { + //renderServices(engine); + //} + } + +} // namespace MM::Services + diff --git a/framework/imgui/src/mm/services/sound_tools.hpp b/framework/imgui/src/mm/services/sound_tools.hpp new file mode 100644 index 0000000..204bed7 --- /dev/null +++ b/framework/imgui/src/mm/services/sound_tools.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include "./imgui_menu_bar.hpp" + +namespace MM::Services { + + class ImGuiSoundTools : public Service { + public: + const char* name(void) override { return "ImGuiSoundTools"; } + + bool enable(Engine& engine) override; + void disable(Engine& engine) override; + + std::vector registerUpdates(void) override; + + private: + bool _show_info = false; + + private: + void renderImGui(Engine& engine); + }; + +} // namespace MM::Services + diff --git a/framework/imgui/test/CMakeLists.txt b/framework/imgui/test/CMakeLists.txt index 95df3ac..1c25759 100644 --- a/framework/imgui/test/CMakeLists.txt +++ b/framework/imgui/test/CMakeLists.txt @@ -67,7 +67,7 @@ target_link_libraries(imgui_sound_test imgui_service imgui_render_task imgui_sound - #imgui_tools + imgui_tools gtest_main ) add_test(NAME imgui_sound_test COMMAND imgui_sound_test) diff --git a/framework/imgui/test/sound_test.cpp b/framework/imgui/test/sound_test.cpp index 22593b5..21159f3 100644 --- a/framework/imgui/test/sound_test.cpp +++ b/framework/imgui/test/sound_test.cpp @@ -10,9 +10,13 @@ #include #include #include +#include +#include #include +#include + #include #include #include @@ -61,9 +65,6 @@ class ImGuiSpeechy : public MM::Services::Service { "testwindow"_hs, "testwindow", [this](MM::Engine& engine) { - MM::ImGuiSoundInfo(engine); - MM::ImGuiSoundPref(engine); - renderImGui(engine); } }}; @@ -149,6 +150,15 @@ TEST(imgui_sound, basic) { engine.addService(); ASSERT_TRUE(engine.enableService()); + engine.addService(); + ASSERT_TRUE(engine.enableService()); + + engine.addService(); + ASSERT_TRUE(engine.enableService()); + + engine.addService(); + ASSERT_TRUE(engine.enableService()); + auto& rs = engine.addService(); ASSERT_TRUE(engine.enableService());