EditorImageGradientComponent.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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 <GradientSignal/Editor/EditorGradientComponentBase.h>
  10. #include <GradientSignal/Components/ImageGradientComponent.h>
  11. #include <GradientSignal/Editor/GradientPreviewer.h>
  12. #include <GradientSignal/Editor/PaintableImageAssetHelper.h>
  13. #include <AzFramework/PaintBrush/PaintBrushNotificationBus.h>
  14. #include <Editor/EditorImageGradientComponentMode.h>
  15. namespace GradientSignal
  16. {
  17. class EditorImageGradientComponent;
  18. // Due to the EditorImageGradientComponent having a member where it passes itself as the type below
  19. // `PaintableImageAssetHelper<EditorImageGradientComponent, EditorImageGradientComponentMode>`
  20. // The AzTypeInfo can't be queried due to EditorImageGradientComponent still be defined
  21. // First the AzTypeInfo is defined using the forward declaration above
  22. // Next the `AZ_RTTI_NO_TYPE_INFO_DECL` is used to declare the RTTI member and static functions within the class
  23. // Finally the AZ_RTTI_NO_TYPE_INFO_IMPL is used to implement the RTTI functions in the cpp file
  24. AZ_TYPE_INFO_SPECIALIZE(EditorImageGradientComponent, EditorImageGradientComponentTypeId);
  25. // This class inherits from EditorComponentBase instead of EditorGradientComponentBase / EditorWrappedComponentBase so that
  26. // we can have control over where the Editor-specific parameters for image creation and editing appear in the component
  27. // relative to the other runtime-only settings.
  28. class EditorImageGradientComponent
  29. : public AzToolsFramework::Components::EditorComponentBase
  30. , protected AzToolsFramework::EditorVisibilityNotificationBus::Handler
  31. , protected LmbrCentral::DependencyNotificationBus::Handler
  32. , private AzFramework::PaintBrushNotificationBus::Handler
  33. {
  34. public:
  35. AZ_EDITOR_COMPONENT_INTRUSIVE_DESCRIPTOR_TYPE(EditorImageGradientComponent);
  36. AZ_COMPONENT_BASE(EditorImageGradientComponent);
  37. AZ_RTTI_NO_TYPE_INFO_DECL();
  38. static void Reflect(AZ::ReflectContext* context);
  39. static constexpr const char* const s_categoryName = "Gradients";
  40. static constexpr const char* const s_componentName = "Image Gradient";
  41. static constexpr const char* const s_componentDescription = "Generates a gradient by sampling an image asset";
  42. static constexpr const char* const s_icon = "Editor/Icons/Components/Gradient.svg";
  43. static constexpr const char* const s_viewportIcon = "Editor/Icons/Components/Viewport/Gradient.svg";
  44. static constexpr const char* const s_helpUrl = "";
  45. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& services);
  46. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& services);
  47. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& services);
  48. static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& services);
  49. //! Component overrides ...
  50. void Init() override;
  51. void Activate() override;
  52. void Deactivate() override;
  53. void BuildGameEntity(AZ::Entity* gameEntity) override;
  54. // AzToolsFramework::EditorVisibilityNotificationBus overrides ...
  55. void OnEntityVisibilityChanged(bool visibility) override;
  56. // DependencyNotificationBus overrides ...
  57. void OnCompositionChanged() override;
  58. void OnCompositionRegionChanged(const AZ::Aabb& dirtyRegion) override;
  59. protected:
  60. bool SavePaintedData();
  61. // PaintBrushNotificationBus overrides
  62. void OnPaintModeBegin() override;
  63. void OnPaintModeEnd() override;
  64. void OnBrushStrokeBegin(const AZ::Color& color) override;
  65. void OnBrushStrokeEnd() override;
  66. void OnPaint(const AZ::Color& color, const AZ::Aabb& dirtyArea, ValueLookupFn& valueLookupFn, BlendFn& blendFn) override;
  67. void OnSmooth(
  68. const AZ::Color& color,
  69. const AZ::Aabb& dirtyArea,
  70. ValueLookupFn& valueLookupFn,
  71. AZStd::span<const AZ::Vector3> valuePointOffsets,
  72. SmoothFn& smoothFn) override;
  73. AZ::Color OnGetColor(const AZ::Vector3& brushCenter) const override;
  74. bool GetImageOptionsReadOnly() const;
  75. AZ::u32 ConfigurationChanged();
  76. private:
  77. ImageCreatorUtils::PaintableImageAssetHelper<EditorImageGradientComponent, EditorImageGradientComponentMode>
  78. m_paintableImageAssetHelper;
  79. //! Preview of the gradient image
  80. GradientPreviewer m_previewer;
  81. //! Copies of the runtime component and configuration - we use these to run the full runtime logic in the Editor.
  82. ImageGradientComponent m_component;
  83. ImageGradientConfig m_configuration;
  84. bool m_visible = true;
  85. bool m_runtimeComponentActive = false;
  86. };
  87. }