diff --git a/Include/RmlUi/Core/Core.h b/Include/RmlUi/Core/Core.h index c2f3b0eb9..1a38b795e 100644 --- a/Include/RmlUi/Core/Core.h +++ b/Include/RmlUi/Core/Core.h @@ -134,6 +134,9 @@ RMLUICORE_API bool LoadFontFace(const byte* data, int data_size, const String& f /// Registers a generic RmlUi plugin. RMLUICORE_API void RegisterPlugin(Plugin* plugin); +/// Unregisters a generic RmlUi plugin. +RMLUICORE_API void UnregisterPlugin(Plugin* plugin); + /// Registers a new event type. If the type already exists, it will replace custom event types, but not internal types. /// @param[in] type The new event type. /// @param[in] interruptible Whether the event can be interrupted during dispatch. diff --git a/Include/RmlUi/Debugger/Debugger.h b/Include/RmlUi/Debugger/Debugger.h index 5361a0705..fc82242ec 100644 --- a/Include/RmlUi/Debugger/Debugger.h +++ b/Include/RmlUi/Debugger/Debugger.h @@ -42,6 +42,10 @@ namespace Debugger { /// @return True if the debugger was successfully initialised RMLUIDEBUGGER_API bool Initialise(Context* context); +/// Shuts down the debugger. +/// @return True if the debugger was successfully shut down +RMLUIDEBUGGER_API bool Shutdown(); + /// Sets the context to be debugged. /// @param[in] context The context to be debugged. /// @return True if the debugger is initialised and the context was switched, false otherwise. diff --git a/Source/Core/Core.cpp b/Source/Core/Core.cpp index 54392a23e..24b0002e5 100644 --- a/Source/Core/Core.cpp +++ b/Source/Core/Core.cpp @@ -342,6 +342,15 @@ void RegisterPlugin(Plugin* plugin) PluginRegistry::RegisterPlugin(plugin); } +// Unregisters a generic rmlui plugin +void UnregisterPlugin(Plugin* plugin) +{ + PluginRegistry::UnregisterPlugin(plugin); + + if(initialised) + plugin->OnShutdown(); +} + EventId RegisterEventType(const String& type, bool interruptible, bool bubbles, DefaultActionPhase default_action_phase) { return EventSpecificationInterface::InsertOrReplaceCustom(type, interruptible, bubbles, default_action_phase); diff --git a/Source/Core/PluginRegistry.cpp b/Source/Core/PluginRegistry.cpp index 62a0a0681..4487edd51 100644 --- a/Source/Core/PluginRegistry.cpp +++ b/Source/Core/PluginRegistry.cpp @@ -28,6 +28,7 @@ #include "PluginRegistry.h" #include "../../Include/RmlUi/Core/Plugin.h" +#include namespace Rml { @@ -52,6 +53,18 @@ void PluginRegistry::RegisterPlugin(Plugin* plugin) element_plugins.push_back(plugin); } +void PluginRegistry::UnregisterPlugin(Plugin* plugin) +{ + int event_classes = plugin->GetEventClasses(); + + if(event_classes & Plugin::EVT_BASIC) + basic_plugins.erase(std::remove(basic_plugins.begin(), basic_plugins.end(), plugin), basic_plugins.end()); + if(event_classes & Plugin::EVT_DOCUMENT) + document_plugins.erase(std::remove(document_plugins.begin(), document_plugins.end(), plugin), document_plugins.end()); + if(event_classes & Plugin::EVT_ELEMENT) + element_plugins.erase(std::remove(element_plugins.begin(), element_plugins.end(), plugin), element_plugins.end()); +} + // Calls OnInitialise() on all plugins. void PluginRegistry::NotifyInitialise() { diff --git a/Source/Core/PluginRegistry.h b/Source/Core/PluginRegistry.h index 4acb17716..4256fddb2 100644 --- a/Source/Core/PluginRegistry.h +++ b/Source/Core/PluginRegistry.h @@ -46,6 +46,7 @@ class PluginRegistry { public: static void RegisterPlugin(Plugin* plugin); + static void UnregisterPlugin(Plugin* plugin); /// Calls OnInitialise() on all plugins. static void NotifyInitialise(); diff --git a/Source/Debugger/Debugger.cpp b/Source/Debugger/Debugger.cpp index ed5d4274f..097af233e 100644 --- a/Source/Debugger/Debugger.cpp +++ b/Source/Debugger/Debugger.cpp @@ -57,6 +57,20 @@ bool Initialise(Context* context) return true; } +// Shuts down the debugger. +bool Shutdown() +{ + DebuggerPlugin* plugin = DebuggerPlugin::GetInstance(); + if(plugin == nullptr) { + Log::Message(Log::LT_WARNING, "Unable to shutdown debugger plugin, it was not initialised!"); + return false; + } + + UnregisterPlugin(plugin); + + return true; +} + // Sets the context to be debugged. bool SetContext(Context* context) {