From 1307ddb194d12a637e42b952e44cd25c50275780 Mon Sep 17 00:00:00 2001 From: diegomrno Date: Tue, 19 Nov 2024 15:16:10 +0100 Subject: [PATCH] feat: Add main window for modules --- main/include/modules/interface.h | 55 +++++++++++++---------- main/src/modules/interface.cpp | 76 +++++++++++++++++++------------- main/src/vortex.cpp | 6 +-- 3 files changed, 81 insertions(+), 56 deletions(-) diff --git a/main/include/modules/interface.h b/main/include/modules/interface.h index 3e51141..9a526e9 100755 --- a/main/include/modules/interface.h +++ b/main/include/modules/interface.h @@ -31,6 +31,8 @@ class ModuleInterface // Module API (declarations needs to be here) public: virtual ~ModuleInterface() {} + + // Main functions virtual void execute() {}; virtual void destroy() {}; virtual void render() {}; @@ -38,32 +40,53 @@ class ModuleInterface void Start(); void Stop(); + // Hooks void OnInputEvent(); void OnOutputEvent(); - - template - void AddArg(const std::string& key, T value); - + // Misc void AddLogo(const uint8_t* hexa, size_t size); void AddLogo(const std::string& relative_path); + + // Functions of the modules (gives the Vortex abstraction/features) void AddFunction(std::function foo, const std::string& name); void AddFunction(std::function foo, const std::string& name); void AddFunction(std::function foo, const std::string& name); void AddFunction(std::function foo, const std::string& name); + void ExecuteFunction(const std::string& name); + void ExecuteFunction(const std::string& name, ArgumentValues& args); + void ExecuteFunction(const std::string& name, ReturnValues& ret); + void ExecuteFunction(const std::string& name, ArgumentValues& args, ReturnValues& ret); - // IMPORTANT : These AddOutputEvent declaration are in reality "Handlers" of output events triggered by other compenents. - // Remember: - // - A output event is triggered via VortexMaker::ExecuteOutputEvent() by the current component to all concerned extern components with the output event added. - // - A input event is triggered via VortexMaker::ExecuteInputEvent() by a extern component to the current component with the input component added. + // Output Events + // A output event is triggered via VortexMaker::ExecuteOutputEvent() by the current component to all concerned extern components with the output event added. void AddOutputEvent(std::function foo, const std::string& name); void AddOutputEvent(std::function foo, const std::string& name); void AddOutputEvent(std::function foo, const std::string& name); void AddOutputEvent(std::function foo, const std::string& name); + void AddOutputEvent(const ModuleOutputEvent& event); + + // Input Events + // A input event is triggered via VortexMaker::ExecuteInputEvent() by a extern component to the current component with the input component added. void AddInputEvent(std::function foo, const std::string& name); void AddInputEvent(std::function foo, const std::string& name); void AddInputEvent(std::function foo, const std::string& name); void AddInputEvent(std::function foo, const std::string& name); + void AddInputEvent(const ModuleInputEvent& event); + + // GUI stuffs + void SetMainWindow(const std::shared_ptr& win); + void AddWindow(const std::shared_ptr& win); + + // Content Browser stuffs + void AddContentBrowserItemHandler(); + void AddContentBrowserItemIdentifier(); + + // Logs & Metrics + void LogInfo(const std::string& message); + void LogWarning(const std::string& message); + void LogError(const std::string& message); + void LogFatal(const std::string& message); // TODO : AddParameterToFunction // TODO : AddParameterToInputEvent @@ -71,20 +94,11 @@ class ModuleInterface // TODO : AddReturnToFunction // TODO : AddReturnToInputEvent // TODO : AddReturnToOutputEvent - - // TODO : AddSpawnableWindow - // TODO : AddContentBrowserItemHandler - // TODO : AddContentBrowserItemIdentifier // TODO : AddCommonUtility - // TODO : AddMainWindow //void AddFunction(void (*item)(), const std::string& name, Parameters params); std::shared_ptr GetInterface(); - void ExecuteFunction(const std::string& name); - void ExecuteFunction(const std::string& name, ArgumentValues& args); - void ExecuteFunction(const std::string& name, ReturnValues& ret); - void ExecuteFunction(const std::string& name, ArgumentValues& args, ReturnValues& ret); void ExecuteOutputEvent(const std::string& name, ArgumentValues& args, ReturnValues& ret); void ExecuteInputEvent(const std::string& name, ArgumentValues& args, ReturnValues& ret); @@ -97,16 +111,10 @@ class ModuleInterface template void AddModuleItemParam(const void *item, std::pair parameter); - void AddModuleOutputEvent(const ModuleOutputEvent& event); - void AddModuleInputEvent(const ModuleInputEvent& event); void AddModuleRenderInstance(const std::shared_ptr &event); void AddModuleFunction(const ModuleFunction& event); std::vector> GetModuleRenderInstances(); - void LogInfo(const std::string& message); - void LogWarning(const std::string& message); - void LogError(const std::string& message); - void LogFatal(const std::string& message); void CallOutputEvent(const std::string &event_name, ArgumentValues& args, ReturnValues& ret); void CallInputEvent(const std::string &module_name, const std::string &event_name, ArgumentValues& args, ReturnValues& ret); @@ -138,6 +146,7 @@ class ModuleInterface size_t m_logo_size; std::string m_state = "unknow"; + std::shared_ptr m_main_window; std::vector> m_functions; std::vector> m_output_events; diff --git a/main/src/modules/interface.cpp b/main/src/modules/interface.cpp index 10615f3..e455a57 100755 --- a/main/src/modules/interface.cpp +++ b/main/src/modules/interface.cpp @@ -25,7 +25,7 @@ void ModuleInterface::AddModuleFunction(const ModuleFunction &function) * * @param event The ModuleOutputEvent to add. */ -void ModuleInterface::AddModuleOutputEvent(const ModuleOutputEvent &event) +void ModuleInterface::AddOutputEvent(const ModuleOutputEvent &event) { // Create a shared_ptr to the ModuleOutputEvent std::shared_ptr p_event = std::make_shared(event); @@ -34,8 +34,28 @@ void ModuleInterface::AddModuleOutputEvent(const ModuleOutputEvent &event) this->m_output_events.push_back(p_event); } -void ModuleInterface::AddModuleInputEvent(const ModuleInputEvent &event) +void ModuleInterface::AddInputEvent(const ModuleInputEvent &event) { + // Create a shared_ptr to the ModuleOutputEvent + std::shared_ptr p_event = std::make_shared(event); + + // Add the shared_ptr to the list of output events + this->m_input_events.push_back(p_event); +} + +void ModuleInterface::SetMainWindow(const std::shared_ptr &win) +{ + // Remove potential old main window + for(auto& window : Cherry::Application::Get().m_AppWindows) + { + if(m_main_window->m_IdName == window->m_IdName) + { + Cherry::DeleteAppWindow(window); + } + } + + // Add/Set the new one + Cherry::AddAppWindow(win); } /** @@ -51,30 +71,6 @@ void ModuleInterface::AddModuleRenderInstance(const std::shared_ptrm_render_instances.push_back(renderInstance); } -/** - * @brief Adds an argument to the ModuleInterface's argument container. - * - * This function adds a key-value pair to the ModuleInterface's argument container. - * If the container does not exist, it creates a new one and adds the argument. - * - * @tparam T The type of the argument value. - * @param key The key for the argument. - * @param value The value of the argument. - */ -template -void ModuleInterface::AddArg(const std::string &key, T value) -{ - if (this->m_args == nullptr) - { - // Create a new argument container if it doesn't exist - std::shared_ptr args = std::make_shared(); - this->m_args = args; - } - - // Add the argument to the container - this->m_args->add(key.c_str(), value); -} - /** * @brief Sets the logo for the ModuleInterface. * @@ -132,18 +128,38 @@ void ModuleInterface::AddOutputEvent(std::function foo, const std::string &name) { + // Create a shared_ptr to the ModuleOutputEvent + std::shared_ptr p_event = std::make_shared(foo, name); + + // Add the shared_ptr to the list of output events + this->m_input_events.push_back(p_event); } void ModuleInterface::AddInputEvent(std::function foo, const std::string &name) { + // Create a shared_ptr to the ModuleOutputEvent + std::shared_ptr p_event = std::make_shared(foo, name); + + // Add the shared_ptr to the list of output events + this->m_input_events.push_back(p_event); } void ModuleInterface::AddInputEvent(std::function foo, const std::string &name) { + // Create a shared_ptr to the ModuleOutputEvent + std::shared_ptr p_event = std::make_shared(foo, name); + + // Add the shared_ptr to the list of output events + this->m_input_events.push_back(p_event); } void ModuleInterface::AddInputEvent(std::function foo, const std::string &name) { + // Create a shared_ptr to the ModuleOutputEvent + std::shared_ptr p_event = std::make_shared(foo, name); + + // Add the shared_ptr to the list of output events + this->m_input_events.push_back(p_event); } /** @@ -637,13 +653,13 @@ void ModuleInterface::Stop() } } -void ModuleInterface::CallOutputEvent(const std::string &event_name, ArgumentValues& args, ReturnValues& ret) -{ +void ModuleInterface::CallOutputEvent(const std::string &event_name, ArgumentValues &args, ReturnValues &ret) +{ VortexMaker::CallOutputEvent(event_name, args, ret, this->m_name); } -void ModuleInterface::CallInputEvent(const std::string &module_name, const std::string &event_name, ArgumentValues& args, ReturnValues& ret) -{ +void ModuleInterface::CallInputEvent(const std::string &module_name, const std::string &event_name, ArgumentValues &args, ReturnValues &ret) +{ VortexMaker::CallInputEvent(module_name, event_name, args, ret, this->m_name); } diff --git a/main/src/vortex.cpp b/main/src/vortex.cpp index eb19c8a..b1b2cd0 100755 --- a/main/src/vortex.cpp +++ b/main/src/vortex.cpp @@ -413,18 +413,18 @@ VORTEX_API void VortexMaker::CallOutputEvent(const std::string &event_name, Argu if (output_event->m_function) { // Trigger a information trigger in the input event - output_event->trigger_happening(origin + ":call_input_event", HappeningState::INFO, "Calling module input event \"" + output_event->m_name + "\" of module \"" + em->m_name + "\" from \"" + origin + "\""); + output_event->trigger_happening(origin + ":call_output_event", HappeningState::INFO, "Calling module output event \"" + output_event->m_name + "\" of module \"" + em->m_name + "\" from \"" + origin + "\""); // Call the corresponding event function with the provided arguments output_event->m_function(args, ret); // Trigger a information trigger in the input event - output_event->trigger_happening(origin + ":call_input_event", HappeningState::INFO, "Input event \"" + output_event->m_name + "\" of module \"" + em->m_name + "\" called succefully from \"" + origin + "\" !"); + output_event->trigger_happening(origin + ":call_output_event", HappeningState::INFO, "Output event \"" + output_event->m_name + "\" of module \"" + em->m_name + "\" called succefully from \"" + origin + "\" !"); } else { // Trigger a information trigger in the input event - output_event->trigger_happening(origin + ":call_input_event", HappeningState::INFO, "Trying to call \"" + output_event->m_name + "\" of module \"" + em->m_name + "\" from \"" + origin + "\" but it not exist !"); + output_event->trigger_happening(origin + ":call_output_event", HappeningState::INFO, "Trying to call \"" + output_event->m_name + "\" of module \"" + em->m_name + "\" from \"" + origin + "\" but it not exist !"); } } }