Plugin.h 4.1 KB

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