Open 3D Engine GradientSignal Gem API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
GradientSignal::ImageCreatorUtils::PaintableImageAssetHelperBase Class Referenceabstract

#include <PaintableImageAssetHelper.h>

Inherited by GradientSignal::ImageCreatorUtils::PaintableImageAssetHelper< GradientSignal::EditorImageGradientComponent, GradientSignal::EditorImageGradientComponentMode >, and GradientSignal::ImageCreatorUtils::PaintableImageAssetHelper< EditorComponentType, EditorComponentModeType >.

Public Types

using DefaultSaveNameCallback = AZStd::function< AZ::IO::Path()>
 Callback that provides the default name to use when creating or saving an image.
 
using OnCreateImageCallback = AZStd::function< void(AZ::Data::Asset< AZ::Data::AssetData > createdAsset)>
 

Public Member Functions

 AZ_CLASS_ALLOCATOR (PaintableImageAssetHelperBase, AZ::SystemAllocator)
 
 AZ_TYPE_INFO (PaintableImageAssetHelperBase, "{7E269EDA-7A80-4B02-9491-96F66BEF5171}")
 
void Activate (AZ::EntityComponentIdPair ownerEntityComponentIdPair, OutputFormat defaultOutputFormat, AZStd::string baseAssetLabel, DefaultSaveNameCallback defaultSaveNameCallback, OnCreateImageCallback onCreateImageCallback)
 
AZStd::string Refresh (AZ::Data::Asset< AZ::Data::AssetData > imageAsset)
 
void Deactivate ()
 
AZStd::optional< AZ::Data::Asset< AZ::Data::AssetData > > SaveImage (int imageResolutionX, int imageResolutionY, OutputFormat format, AZStd::span< const uint8_t > pixelBuffer)
 

Static Public Member Functions

static void Reflect (AZ::ReflectContext *context)
 

Protected Types

using ComponentModeDelegate = AzToolsFramework::ComponentModeFramework::ComponentModeDelegate
 Delegates the handling of component editing mode to a paint controller.
 

Protected Member Functions

void CreateNewImage ()
 Create a new image.
 
AZ::IO::Path GetIncrementingAutoSavePath (const AZ::IO::Path &currentPath) const
 Create a new filename with an incrementing number for the "auto save with incrementing names" mode.
 
bool GetSaveLocation (AZ::IO::Path &fullPath, AZStd::string &relativePath, PaintableImageAssetAutoSaveMode autoSaveMode)
 Determine where to save the image based on the autosave mode.
 
bool RefreshImageAssetStatus (AZ::Data::Asset< AZ::Data::AssetData > imageAsset)
 Refresh the current image asset load status.
 
AZStd::string GetImageAssetStatusLabel ()
 
AZStd::string GetRelativePathFromAbsolutePath (AZStd::string_view absolutePath)
 
AZ::Crc32 GetPaintModeVisibility () const
 Returns whether or not the edit mode should currently be visible.
 
void RefreshComponentModeStatus ()
 
virtual void EnableComponentMode ()=0
 
bool InComponentMode () const
 Return whether or not component mode is currently active.
 
void DisableComponentMode ()
 Disable component mode for this image asset.
 

Static Protected Member Functions

static bool ImageHasPendingJobs (const AZ::Data::AssetId &assetId)
 Check to see if an image asset has any pending asset jobs.
 

Protected Attributes

ComponentModeDelegate m_componentModeDelegate
 
AZ::Data::AssetData::AssetStatus m_currentImageAssetStatus = AZ::Data::AssetData::AssetStatus::NotLoaded
 
bool m_currentImageJobsPending = false
 
bool m_waitingForImageReload = false
 
AZStd::string m_baseAssetLabel
 
PaintableImageAssetAutoSaveMode m_autoSaveMode = PaintableImageAssetAutoSaveMode::AutoSave
 Offer a choice of different autosave modes.
 
bool m_promptedForSaveLocation = false
 
AZ::EntityComponentIdPair m_ownerEntityComponentIdPair = {}
 
DefaultSaveNameCallback m_defaultSaveNameCallback = {}
 
OnCreateImageCallback m_onCreateImageCallback = {}
 
OutputFormat m_defaultOutputFormat = OutputFormat::R8G8B8A8
 

Detailed Description

Helper class to manage all the common logic and UX for paintable image creation, editing, and saving. This is split out from PaintableImageAssetHelper so that we can minimize the amount of duplicated code caused by the templatized parameters required for hooking it up to a specific editor component mode.

Member Typedef Documentation

◆ OnCreateImageCallback

using GradientSignal::ImageCreatorUtils::PaintableImageAssetHelperBase::OnCreateImageCallback = AZStd::function<void(AZ::Data::Asset<AZ::Data::AssetData> createdAsset)>

Callback that gets notified when a new asset has been created. The typical use is for the parent component to replace its asset reference and refresh itself.

Member Function Documentation

◆ Activate()

void GradientSignal::ImageCreatorUtils::PaintableImageAssetHelperBase::Activate ( AZ::EntityComponentIdPair  ownerEntityComponentIdPair,
OutputFormat  defaultOutputFormat,
AZStd::string  baseAssetLabel,
DefaultSaveNameCallback  defaultSaveNameCallback,
OnCreateImageCallback  onCreateImageCallback 
)

Activate the PaintableImageAssetHelper. This should get called from the parent component's Activate() method.

Parameters
ownerEntityComponentIdPairThe parent component's entity id and component id, used for component mode communications.
defaultOutputFormatThe image output format that should be used for image creation and saving.
baseAssetLabelThe base label to use for the image asset (ex: "Color Texture").
defaultSaveNameCallbackA callback that provides a default save name when creating or saving an image.
onCreateImageCallbackA callback that gets called whenever an image gets created or saved.

◆ Deactivate()

void GradientSignal::ImageCreatorUtils::PaintableImageAssetHelperBase::Deactivate ( )

Deactivate the PaintableImageAssetHelper. This should get called from the parent component's Deactivate() method.

◆ EnableComponentMode()

virtual void GradientSignal::ImageCreatorUtils::PaintableImageAssetHelperBase::EnableComponentMode ( )
protectedpure virtual

Enable component mode for this image asset. This is a virtual function because it needs to know the specific type of editor component and editor component mode to enable which are defined as template parameters on the PaintableImageAssetHelper.

Implemented in GradientSignal::ImageCreatorUtils::PaintableImageAssetHelper< EditorComponentType, EditorComponentModeType >, and GradientSignal::ImageCreatorUtils::PaintableImageAssetHelper< GradientSignal::EditorImageGradientComponent, GradientSignal::EditorImageGradientComponentMode >.

◆ GetImageAssetStatusLabel()

AZStd::string GradientSignal::ImageCreatorUtils::PaintableImageAssetHelperBase::GetImageAssetStatusLabel ( )
protected

Get a display label for the image asset that includes the current asset status.

Parameters
baseNameThe base name to use for the label (ex: "Image" will produce labels like "Image (not loaded)")
Returns
The full label, based on the image asset's last refreshed status.

◆ GetRelativePathFromAbsolutePath()

AZStd::string GradientSignal::ImageCreatorUtils::PaintableImageAssetHelperBase::GetRelativePathFromAbsolutePath ( AZStd::string_view  absolutePath)
protected

Get the relative asset path from the absolute path, or empty if a relative asset path doesn't exist. This can happen if the absolute path exists outside of the project folder.

◆ Refresh()

AZStd::string GradientSignal::ImageCreatorUtils::PaintableImageAssetHelperBase::Refresh ( AZ::Data::Asset< AZ::Data::AssetData >  imageAsset)

Refresh the PaintableImageAssetHelper. This should get called from the parent component whenever the image asset changes its status.

Parameters
EditorComponentTypeThe class type of the parent editor component.
EditorComponentModeTypeThe class type for the component mode to use when editing.
imageAssetThe image asset that can be edited.
Returns
The refreshed asset label containing the asset status (ex: "Color Texture (not loaded)")

◆ RefreshComponentModeStatus()

void GradientSignal::ImageCreatorUtils::PaintableImageAssetHelperBase::RefreshComponentModeStatus ( )
protected

Enable/disable the component mode based on the current image asset load status. Only fully-loaded image assets are editable.

◆ SaveImage()

AZStd::optional< AZ::Data::Asset< AZ::Data::AssetData > > GradientSignal::ImageCreatorUtils::PaintableImageAssetHelperBase::SaveImage ( int  imageResolutionX,
int  imageResolutionY,
OutputFormat  format,
AZStd::span< const uint8_t >  pixelBuffer 
)

Save a source image with the given data, optionally prompting the user for a location depending on the autosave mode.

Parameters
imageResolutionXThe image width in pixels
imageResolutionYThe image height in pixels
formatThe output format to save the image in
pixelBufferThe pixel data to save
Returns
A reference to the saved asset on success, empty on failure

Member Data Documentation

◆ m_promptedForSaveLocation

bool GradientSignal::ImageCreatorUtils::PaintableImageAssetHelperBase::m_promptedForSaveLocation = false
protected

Track whether or not we've prompted the user for an image save location at least once since this component was created. This is intentionally not serialized so that every user is prompted at least once per editor run for autosaves. This choice prioritizes data safety over lower friction - it's too easy for autosave to overwrite data accidentally, so we want the user to specifically choose a save location at least once before overwriting without prompts. We could serialize the flag so that the user only selects a location once per component, instead of once per component per Editor run, but that serialized flag would be shared with other users, so we would have other users editing the same image that never get prompted and might overwrite data by mistake.


The documentation for this class was generated from the following file: