Browse Source

Merge pull request #201 from Lyatus/master

Rml::UnregisterPlugin and Rml::Debugger::Shutdown
Michael R. P. Ragazzon 4 years ago
parent
commit
38d63558af

+ 3 - 0
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.
 /// Registers a generic RmlUi plugin.
 RMLUICORE_API void RegisterPlugin(Plugin* 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.
 /// 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] type The new event type.
 /// @param[in] interruptible Whether the event can be interrupted during dispatch.
 /// @param[in] interruptible Whether the event can be interrupted during dispatch.

+ 4 - 0
Include/RmlUi/Debugger/Debugger.h

@@ -42,6 +42,10 @@ namespace Debugger {
 /// @return True if the debugger was successfully initialised
 /// @return True if the debugger was successfully initialised
 RMLUIDEBUGGER_API bool Initialise(Context* context);
 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.
 /// Sets the context to be debugged.
 /// @param[in] context 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.
 /// @return True if the debugger is initialised and the context was switched, false otherwise.

+ 9 - 0
Source/Core/Core.cpp

@@ -342,6 +342,15 @@ void RegisterPlugin(Plugin* plugin)
 	PluginRegistry::RegisterPlugin(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)
 EventId RegisterEventType(const String& type, bool interruptible, bool bubbles, DefaultActionPhase default_action_phase)
 {
 {
 	return EventSpecificationInterface::InsertOrReplaceCustom(type, interruptible, bubbles, default_action_phase);
 	return EventSpecificationInterface::InsertOrReplaceCustom(type, interruptible, bubbles, default_action_phase);

+ 13 - 0
Source/Core/PluginRegistry.cpp

@@ -28,6 +28,7 @@
 
 
 #include "PluginRegistry.h"
 #include "PluginRegistry.h"
 #include "../../Include/RmlUi/Core/Plugin.h"
 #include "../../Include/RmlUi/Core/Plugin.h"
+#include <algorithm>
 
 
 namespace Rml {
 namespace Rml {
 
 
@@ -52,6 +53,18 @@ void PluginRegistry::RegisterPlugin(Plugin* plugin)
 		element_plugins.push_back(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.
 // Calls OnInitialise() on all plugins.
 void PluginRegistry::NotifyInitialise()
 void PluginRegistry::NotifyInitialise()
 {
 {

+ 1 - 0
Source/Core/PluginRegistry.h

@@ -46,6 +46,7 @@ class PluginRegistry
 {
 {
 public:
 public:
 	static void RegisterPlugin(Plugin* plugin);
 	static void RegisterPlugin(Plugin* plugin);
+	static void UnregisterPlugin(Plugin* plugin);
 
 
 	/// Calls OnInitialise() on all plugins.
 	/// Calls OnInitialise() on all plugins.
 	static void NotifyInitialise();
 	static void NotifyInitialise();

+ 14 - 0
Source/Debugger/Debugger.cpp

@@ -57,6 +57,20 @@ bool Initialise(Context* context)
 	return true;
 	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.
 // Sets the context to be debugged.
 bool SetContext(Context* context)
 bool SetContext(Context* context)
 {
 {