UiManager.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #pragma once
  16. #include <OgreRenderQueueListener.h>
  17. #include <OgreSingleton.h>
  18. #include <OgreUTFString.h>
  19. #include <tinyxml.h>
  20. #include "UiFont.h"
  21. #include "UiWidget.h"
  22. /**
  23. * The UI manager.
  24. */
  25. class UiManager
  26. : public Ogre::RenderQueueListener, public Ogre::Singleton<UiManager>
  27. {
  28. public:
  29. /**
  30. * Constructor.
  31. */
  32. UiManager();
  33. /**
  34. * Destructor.
  35. */
  36. virtual ~UiManager();
  37. /**
  38. * Initializes the manager.
  39. *
  40. * Loads all available fonts and screens from fonts.xml and
  41. * screens.xml, respectably.
  42. */
  43. void Initialise();
  44. /**
  45. * Updates the UI elements in the manager.
  46. */
  47. void Update();
  48. /**
  49. * Handles resizing events.
  50. */
  51. void OnResize();
  52. /**
  53. * Adds a font to the manager.
  54. *
  55. * @param font[in] The font to add.
  56. */
  57. void AddFont(UiFont* font);
  58. /**
  59. * Retrieves a font by name.
  60. *
  61. * @param name[in] Name of the font.
  62. * @return The font by the specified name, or NULL if there is none.
  63. */
  64. UiFont* GetFont(const Ogre::String& name);
  65. /**
  66. * Adds a prototype to the manager.
  67. *
  68. * @param name[in] The prototype manager.
  69. * @param prototype[in] The prototyme, as an XML node.
  70. * @todo What exactly is a prototype here?
  71. */
  72. void AddPrototype(const Ogre::String& name, TiXmlNode* prototype);
  73. /**
  74. * Retrieves a prototype by name.
  75. *
  76. * @param name[in] Name of the prototype.
  77. * @return The prototype by the specified name, or NULL if there is
  78. * none.
  79. * @todo What exactly is a prototype here?
  80. */
  81. TiXmlNode* GetPrototype(const Ogre::String& name) const;
  82. /**
  83. * Adds a UI widget to the manager.
  84. *
  85. * @param widget[in] The widget to add.
  86. */
  87. void AddWidget(UiWidget* widget);
  88. /**
  89. * Retrieves a UI widget by name.
  90. *
  91. * @param name[in] Name of the widget.
  92. * @return The widget by the specified name, or NULL if there is none.
  93. */
  94. UiWidget* GetWidget(const Ogre::String& name);
  95. /**
  96. * Retrieves a UI widget by name.
  97. *
  98. * @param name[in] Name of the widget.
  99. * @return The widget by the specified name, or NULL if there is none.
  100. */
  101. UiWidget* ScriptGetWidget(const char* name);
  102. /**
  103. * Updates the render queue.
  104. *
  105. * @param queueGroupId[in] The queue group ID.
  106. * @param invocation[in] Unused.
  107. * @param skipThisInvocation[in] Unused.
  108. */
  109. void renderQueueStarted(
  110. Ogre::uint8 queueGroupId, const Ogre::String& invocation,
  111. bool& skipThisInvocation
  112. );
  113. private:
  114. /**
  115. * List of fonts in the manager.
  116. */
  117. std::vector<UiFont*> fonts_;
  118. /**
  119. * A UI prototype.
  120. *
  121. * @todo What exactly is a prototype here?
  122. */
  123. struct UiPrototype{
  124. /**
  125. * The prototype node.
  126. */
  127. Ogre::String name;
  128. /**
  129. * The prototype structure as an XML node.
  130. */
  131. TiXmlNode* node;
  132. };
  133. /**
  134. * List of prototypes.
  135. */
  136. std::vector<UiPrototype> prototypes_;
  137. /**
  138. * List of widgets.
  139. */
  140. std::vector<UiWidget*> widgets_;
  141. };