DebugDrawTextComponent.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 <AzCore/Component/Component.h>
  10. #include <AzCore/Script/ScriptTimePoint.h>
  11. #include <DebugDraw/DebugDrawBus.h>
  12. #include <AzFramework/Entity/EntityDebugDisplayBus.h>
  13. namespace DebugDraw
  14. {
  15. class DebugDrawTextElement
  16. {
  17. public:
  18. AZ_CLASS_ALLOCATOR(DebugDrawTextElement, AZ::SystemAllocator);
  19. AZ_TYPE_INFO(DebugDrawTextElement, "{A49413DB-0AFC-4D38-BD4B-EDC8FA83B640}");
  20. static void Reflect(AZ::ReflectContext* context);
  21. enum class DrawMode
  22. {
  23. OnScreen,
  24. InWorld,
  25. };
  26. DrawMode m_drawMode = DrawMode::OnScreen;
  27. float m_duration = 0.0f;
  28. float m_size = 1.4f;
  29. AZStd::string m_text = "";
  30. bool m_centered = false;
  31. AZ::ScriptTimePoint m_activateTime;
  32. AZ::Color m_color = AZ::Color(1.0f, 1.0f, 1.0f, 1.0f);
  33. AZ::EntityId m_targetEntityId;
  34. AZ::Vector3 m_worldLocation = AZ::Vector3::CreateZero();
  35. AZ::ComponentId m_owningEditorComponent = AZ::InvalidComponentId;
  36. float m_fontScale = 1.0f; // Scale factor to default render font
  37. bool m_useOnScreenCoordinates = false; // Whether to use m_worldLocation.X and m_worldLocation.Y as OnScreen 2d Coordinates
  38. bool m_bCenter = false; // If true, centers drawn text relative to x coordinate
  39. };
  40. class DebugDrawTextComponent
  41. : public AZ::Component
  42. {
  43. friend class DebugDrawSystemComponent;
  44. public:
  45. AZ_COMPONENT(DebugDrawTextComponent, "{A705A8DF-31F1-49FF-8727-CC7783E09EF9}");
  46. static void Reflect(AZ::ReflectContext* context);
  47. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
  48. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
  49. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
  50. static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& dependent);
  51. DebugDrawTextComponent() = default;
  52. explicit DebugDrawTextComponent(const DebugDrawTextElement& textElement);
  53. ~DebugDrawTextComponent() override = default;
  54. // AZ::Component interface implementation
  55. void Init() override;
  56. void Activate() override;
  57. void Deactivate() override;
  58. protected:
  59. DebugDrawTextElement m_element;
  60. };
  61. }