ImGuiSystemComponent.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include <Atom/Feature/ImGui/SystemBus.h>
  10. #include <AzCore/Component/Component.h>
  11. #include <AzCore/Component/TickBus.h>
  12. #include <AzFramework/Input/Events/InputTextEventListener.h>
  13. #include <AzFramework/Input/Events/InputChannelEventListener.h>
  14. #include <AzFramework/Windowing/WindowBus.h>
  15. namespace AZ
  16. {
  17. namespace Render
  18. {
  19. class ImGuiFeatureProcessor;
  20. class ImGuiPass;
  21. class ImGuiSystemComponent final
  22. : public AZ::Component
  23. , public ImGuiSystemRequestBus::Handler
  24. {
  25. public:
  26. AZ_COMPONENT(ImGuiSystemComponent, "1A8549B6-B8CC-4C45-9312-DD8A032DA71F");
  27. static void Reflect(AZ::ReflectContext* context);
  28. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
  29. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
  30. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatbile);
  31. ImGuiSystemComponent();
  32. ~ImGuiSystemComponent() override = default;
  33. /// AZ::Component
  34. void Activate() override;
  35. void Deactivate() override;
  36. private:
  37. /// ImGuiSystemRequestBus::Handler
  38. void SetGlobalSizeScale(float scale) override;
  39. void SetGlobalFontScale(float scale) override;
  40. void HideAllImGuiPasses() override;
  41. void ShowAllImGuiPasses() override;
  42. void PushDefaultImGuiPass(ImGuiPass* imguiPass) override;
  43. void RemoveDefaultImGuiPass(ImGuiPass* imguiPass) override;
  44. ImGuiPass* GetDefaultImGuiPass() override;
  45. bool PushActiveContextFromDefaultPass() override;
  46. bool PushActiveContextFromPass(const AZStd::vector<AZStd::string>& passHierarchy) override;
  47. bool PopActiveContext() override;
  48. ImGuiContext* GetActiveContext() override;
  49. bool RenderImGuiBuffersToCurrentViewport(const ImDrawData& drawData) override;
  50. using PassFunction = AZStd::function<void(ImGuiPass* pass)>;
  51. void ForAllImGuiPasses(PassFunction func);
  52. AZStd::vector<ImGuiContext*> m_activeContextStack;
  53. AZStd::vector<ImGuiPass*> m_defaultImguiPassStack;
  54. float m_fontScale = 1.0f; ///< Global scale applied only to the font
  55. float m_sizeScale = 1.0f; ///< Global size scale. This doesn't apply to fonts.
  56. };
  57. } // namespace RPI
  58. } // namespace AZ