SystemUI.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. //
  2. // Copyright (c) 2017 the Atomic project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "../../Core/Object.h"
  24. #include "../../Math/StringHash.h"
  25. #include "../../Container/HashMap.h"
  26. #include "../../Graphics/VertexBuffer.h"
  27. #include "../../Graphics/IndexBuffer.h"
  28. #include "../../Math/Matrix4.h"
  29. #include "../../Graphics/Texture2D.h"
  30. #include "../../UI/SystemUI/SystemUIEvents.h"
  31. #include <imgui.h>
  32. namespace Atomic
  33. {
  34. class SystemUI
  35. : public Atomic::Object
  36. {
  37. ATOMIC_OBJECT(SystemUI, Atomic::Object);
  38. public:
  39. SystemUI(Atomic::Context* context);
  40. ~SystemUI();
  41. //! Get ui scale.
  42. //! \return scale of ui.
  43. float GetScale() const { return uiScale_; };
  44. //! Set ui scale.
  45. //! \param scale of ui.
  46. void SetScale(float scale);
  47. //! Add font to imgui subsystem.
  48. /*!
  49. \param font_path a string pointing to TTF font resource.
  50. \param size a font size. If 0 then size of last font is used.
  51. \param ranges optional ranges of font that should be used. Parameter is array of {start1, stop1, ..., startN, stopN, 0}.
  52. \param merge set to true if new font should be merged to last active font.
  53. \return ImFont instance that may be used for setting current font when drawing GUI.
  54. */
  55. ImFont* AddFont(const Atomic::String& font_path, float size = 0, const unsigned short* ranges = 0,
  56. bool merge = false);
  57. //! Add font to imgui subsystem.
  58. /*!
  59. \param font_path a string pointing to TTF font resource.
  60. \param size a font size. If 0 then size of last font is used.
  61. \param ranges optional ranges of font that should be used. Parameter is std::initializer_list of {start1, stop1, ..., startN, stopN, 0}.
  62. \param merge set to true if new font should be merged to last active font.
  63. \return ImFont instance that may be used for setting current font when drawing GUI.
  64. */
  65. ImFont* AddFont(
  66. const Atomic::String& font_path, float size = 0,
  67. const std::initializer_list<unsigned short>& ranges = {}, bool merge = false);
  68. protected:
  69. float uiScale_ = 1.f;
  70. Atomic::Matrix4 projection_;
  71. Atomic::VertexBuffer vertexBuffer_;
  72. Atomic::IndexBuffer indexBuffer_;
  73. Atomic::SharedPtr<Texture2D> fontTexture_;
  74. void ReallocateFontTexture();
  75. void UpdateProjectionMatrix();
  76. void OnPostUpdate(Atomic::VariantMap& args);
  77. void OnRenderDrawLists(ImDrawData* data);
  78. void OnRawEvent(VariantMap& args);
  79. };
  80. }