2
0

DebuggerPlugin.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /*
  2. * This source file is part of RmlUi, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://github.com/mikke89/RmlUi
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. * Copyright (c) 2019-2023 The RmlUi Team, and contributors
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. *
  27. */
  28. #ifndef RMLUI_DEBUGGER_DEBUGGERPLUGIN_H
  29. #define RMLUI_DEBUGGER_DEBUGGERPLUGIN_H
  30. #include "../../Include/RmlUi/Core/EventListener.h"
  31. #include "../../Include/RmlUi/Core/Plugin.h"
  32. namespace Rml {
  33. class ElementDocument;
  34. class SystemInterface;
  35. namespace Debugger {
  36. class ElementLog;
  37. class ElementInfo;
  38. class ElementContextHook;
  39. class DebuggerSystemInterface;
  40. /**
  41. RmlUi plugin interface for the debugger.
  42. @author Robert Curry
  43. */
  44. class DebuggerPlugin : public Rml::Plugin, public Rml::EventListener {
  45. public:
  46. DebuggerPlugin();
  47. ~DebuggerPlugin();
  48. /// Initialises the debugging tools into the given context.
  49. /// @param[in] context The context to load the tools into.
  50. /// @return True on success, false if an error occured.
  51. bool Initialise(Context* context);
  52. /// Sets the context to be debugged.
  53. /// @param[in] context The context to be debugged.
  54. /// @return True if the debugger is initialised and the context was switched, false otherwise.
  55. bool SetContext(Context* context);
  56. /// Sets the visibility of the debugger.
  57. /// @param[in] visibility True to show the debugger, false to hide it.
  58. void SetVisible(bool visibility);
  59. /// Returns the visibility of the debugger.
  60. /// @return True if the debugger is visible, false if not.
  61. bool IsVisible();
  62. /// Renders any debug elements in the debug context.
  63. void Render();
  64. /// Called when RmlUi shuts down.
  65. void OnShutdown() override;
  66. /// Called whenever a RmlUi context is destroyed.
  67. /// @param[in] context The destroyed context.
  68. void OnContextDestroy(Context* context) override;
  69. /// Called whenever an element is destroyed.
  70. /// @param[in] element The destroyed element.
  71. void OnElementDestroy(Element* element) override;
  72. /// Event handler for events from the debugger elements.
  73. /// @param[in] event The event to process.
  74. void ProcessEvent(Event& event) override;
  75. /// Access the singleton instance of the debugger
  76. /// @return nullptr or an instance of the plugin
  77. static DebuggerPlugin* GetInstance();
  78. private:
  79. bool LoadFont();
  80. bool LoadMenuElement();
  81. bool LoadInfoElement();
  82. bool LoadLogElement();
  83. void SetupInfoListeners(Rml::Context* new_context);
  84. // Release all loaded elements
  85. void ReleaseElements();
  86. // The context hosting the debug documents.
  87. Context* host_context;
  88. // The context we're debugging.
  89. Context* debug_context;
  90. // The debug elements.
  91. ElementDocument* menu_element;
  92. ElementInfo* info_element;
  93. ElementLog* log_element;
  94. ElementContextHook* hook_element;
  95. Rml::SystemInterface* application_interface;
  96. UniquePtr<DebuggerSystemInterface> log_interface;
  97. UniquePtr<ElementInstancer> hook_element_instancer, debug_document_instancer, info_element_instancer, log_element_instancer;
  98. bool render_outlines;
  99. // Singleton instance
  100. static DebuggerPlugin* instance;
  101. };
  102. } // namespace Debugger
  103. } // namespace Rml
  104. #endif