Plugin.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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 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 RMLUIDEBUGGERPLUGIN_H
  29. #define RMLUIDEBUGGERPLUGIN_H
  30. #include "../../Include/RmlUi/Core/EventListener.h"
  31. #include "../../Include/RmlUi/Core/Plugin.h"
  32. namespace Rml {
  33. namespace Core {
  34. class ElementDocument;
  35. class SystemInterface;
  36. }
  37. namespace Debugger {
  38. class ElementLog;
  39. class ElementInfo;
  40. class ElementContextHook;
  41. class SystemInterface;
  42. /**
  43. RmlUi plugin interface for the debugger.
  44. @author Robert Curry
  45. */
  46. class Plugin : public Core::Plugin, public Core::EventListener
  47. {
  48. public:
  49. Plugin();
  50. ~Plugin();
  51. /// Initialises the debugging tools into the given context.
  52. /// @param[in] context The context to load the tools into.
  53. /// @return True on success, false if an error occured.
  54. bool Initialise(Core::Context* context);
  55. /// Sets the context to be debugged.
  56. /// @param[in] context The context to be debugged.
  57. /// @return True if the debugger is initialised and the context was switched, false otherwise..
  58. bool SetContext(Core::Context* context);
  59. /// Sets the visibility of the debugger.
  60. /// @param[in] visibility True to show the debugger, false to hide it.
  61. void SetVisible(bool visibility);
  62. /// Returns the visibility of the debugger.
  63. /// @return True if the debugger is visible, false if not.
  64. bool IsVisible();
  65. /// Renders any debug elements in the debug context.
  66. void Render();
  67. /// Called when RmlUi shuts down.
  68. void OnShutdown() override;
  69. /// Called whenever a RmlUi context is destroyed.
  70. /// @param[in] context The destroyed context.
  71. void OnContextDestroy(Core::Context* context) override;
  72. /// Called whenever an element is destroyed.
  73. /// @param[in] element The destroyed element.
  74. void OnElementDestroy(Core::Element* element) override;
  75. /// Event handler for events from the debugger elements.
  76. /// @param[in] event The event to process.
  77. void ProcessEvent(Core::Event& event) override;
  78. /// Access the singleton instance of the debugger
  79. /// @return nullptr or an instance of the plugin
  80. static Plugin* GetInstance();
  81. private:
  82. bool LoadFont();
  83. bool LoadMenuElement();
  84. bool LoadInfoElement();
  85. bool LoadLogElement();
  86. // Release all loaded elements
  87. void ReleaseElements();
  88. // The context hosting the debug documents.
  89. Core::Context* host_context;
  90. // The context we're debugging.
  91. Core::Context* debug_context;
  92. // The debug elements.
  93. Core::ElementDocument* menu_element;
  94. ElementInfo* info_element;
  95. ElementLog* log_element;
  96. ElementContextHook* hook_element;
  97. Core::SystemInterface* application_interface;
  98. std::unique_ptr<SystemInterface> log_interface;
  99. std::unique_ptr<Core::ElementInstancer> hook_element_instancer, info_element_instancer, log_element_instancer;
  100. bool render_outlines;
  101. // Singleton instance
  102. static Plugin* instance;
  103. };
  104. }
  105. }
  106. #endif