EditorImageGradientComponent.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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_CLASS_ALLOCATOR(EditorImageGradientComponent, AZ::ComponentAllocator);
  38. AZ_RTTI_NO_TYPE_INFO_DECL();
  39. static void Reflect(AZ::ReflectContext* context);
  40. static constexpr const char* const s_categoryName = "Gradients";
  41. static constexpr const char* const s_componentName = "Image Gradient";
  42. static constexpr const char* const s_componentDescription = "Generates a gradient by sampling an image asset";
  43. static constexpr const char* const s_icon = "Editor/Icons/Components/Gradient.svg";
  44. static constexpr const char* const s_viewportIcon = "Editor/Icons/Components/Viewport/Gradient.svg";
  45. static constexpr const char* const s_helpUrl = "";
  46. static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& services);
  47. static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& services);
  48. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& services);
  49. static void GetDependentServices(AZ::ComponentDescriptor::DependencyArrayType& services);
  50. //! Component overrides ...
  51. void Init() override;
  52. void Activate() override;
  53. void Deactivate() override;
  54. void BuildGameEntity(AZ::Entity* gameEntity) override;
  55. // AzToolsFramework::EditorVisibilityNotificationBus overrides ...
  56. void OnEntityVisibilityChanged(bool visibility) override;
  57. // DependencyNotificationBus overrides ...
  58. void OnCompositionChanged() override;
  59. void OnCompositionRegionChanged(const AZ::Aabb& dirtyRegion) override;
  60. protected:
  61. bool SavePaintedData();
  62. // PaintBrushNotificationBus overrides
  63. void OnPaintModeBegin() override;
  64. void OnPaintModeEnd() override;
  65. void OnBrushStrokeBegin(const AZ::Color& color) override;
  66. void OnBrushStrokeEnd() override;
  67. void OnPaint(const AZ::Color& color, const AZ::Aabb& dirtyArea, ValueLookupFn& valueLookupFn, BlendFn& blendFn) override;
  68. void OnSmooth(
  69. const AZ::Color& color,
  70. const AZ::Aabb& dirtyArea,
  71. ValueLookupFn& valueLookupFn,
  72. AZStd::span<const AZ::Vector3> valuePointOffsets,
  73. SmoothFn& smoothFn) override;
  74. AZ::Color OnGetColor(const AZ::Vector3& brushCenter) const override;
  75. bool GetImageOptionsReadOnly() const;
  76. AZ::u32 ConfigurationChanged();
  77. private:
  78. ImageCreatorUtils::PaintableImageAssetHelper<EditorImageGradientComponent, EditorImageGradientComponentMode>
  79. m_paintableImageAssetHelper;
  80. //! Preview of the gradient image
  81. GradientPreviewer m_previewer;
  82. //! Copies of the runtime component and configuration - we use these to run the full runtime logic in the Editor.
  83. ImageGradientComponent m_component;
  84. ImageGradientConfig m_configuration;
  85. bool m_visible = true;
  86. bool m_runtimeComponentActive = false;
  87. };
  88. }