Initial commit

This commit is contained in:
alexpete
2021-03-05 11:26:34 -08:00
commit a10351f38d
27091 changed files with 5521199 additions and 0 deletions
@@ -0,0 +1,64 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <AzCore/StringFunc/StringFunc.h>
#include <AzToolsFramework/Thumbnails/LoadingThumbnail.h>
#include <AzFramework/Application/Application.h>
namespace AzToolsFramework
{
namespace Thumbnailer
{
//////////////////////////////////////////////////////////////////////////
// LoadingThumbnail
//////////////////////////////////////////////////////////////////////////
static const char* LoadingIconPath = "Editor/Icons/AssetBrowser/in_progress.gif";
LoadingThumbnail::LoadingThumbnail(int thumbnailSize)
: Thumbnail(MAKE_TKEY(ThumbnailKey), thumbnailSize)
, m_angle(0)
{
const char* engineRoot = nullptr;
AzFramework::ApplicationRequests::Bus::BroadcastResult(engineRoot, &AzFramework::ApplicationRequests::GetEngineRoot);
AZ_Assert(engineRoot, "Engine Root not initialized");
AZStd::string iconPath;
AZ::StringFunc::Path::Join(engineRoot, LoadingIconPath, iconPath);
m_loadingMovie.setFileName(iconPath.c_str());
m_loadingMovie.setCacheMode(QMovie::CacheMode::CacheAll);
m_loadingMovie.setScaledSize(QSize(m_thumbnailSize, m_thumbnailSize));
m_loadingMovie.start();
m_pixmap = m_loadingMovie.currentPixmap();
m_state = State::Ready;
BusConnect();
}
LoadingThumbnail::~LoadingThumbnail()
{
BusDisconnect();
}
void LoadingThumbnail::UpdateTime(float)
{
m_pixmap = m_loadingMovie.currentPixmap();
Q_EMIT Updated();
}
void LoadingThumbnail::OnTick(float deltaTime, AZ::ScriptTimePoint /*time*/)
{
UpdateTime(deltaTime);
}
} // namespace Thumbnailer
} // namespace AzToolsFramework
#include "Thumbnails/moc_LoadingThumbnail.cpp"
@@ -0,0 +1,48 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#if !defined(Q_MOC_RUN)
#include <AzToolsFramework/Thumbnails/Thumbnail.h>
AZ_PUSH_DISABLE_WARNING(4251, "-Wunknown-warning-option") // 4251: class 'QImageIOHandler::d_ptr': class 'QScopedPointer<QImageIOHandlerPrivate,QScopedPointerDeleter<T>>' needs to have dll-interface to be used by clients of class 'QImageIOHandler'
#include <QMovie>
#endif
AZ_POP_DISABLE_WARNING
namespace AzToolsFramework
{
namespace Thumbnailer
{
class LoadingThumbnail
: public Thumbnail
, public AZ::TickBus::Handler
{
Q_OBJECT
public:
explicit LoadingThumbnail(int thumbnailSize);
~LoadingThumbnail() override;
void UpdateTime(float /*deltaTime*/) override;
//////////////////////////////////////////////////////////////////////////
// TickBus
//////////////////////////////////////////////////////////////////////////
//! LoadingThumbnail is not part pf any thumbnail cache, so it needs to be updated manually
void OnTick(float deltaTime, AZ::ScriptTimePoint /*time*/) override;
private:
float m_angle;
QMovie m_loadingMovie;
};
} // namespace Thumbnailer
} // namespace AzToolsFramework
@@ -0,0 +1,31 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <AzToolsFramework/Thumbnails/MissingThumbnail.h>
namespace AzToolsFramework
{
namespace Thumbnailer
{
static const char* MISSING_ICON_PATH = "Editor/Icons/AssetBrowser/Default_16.svg";
MissingThumbnail::MissingThumbnail(int thumbnailSize)
: Thumbnail(MAKE_TKEY(ThumbnailKey), thumbnailSize)
{
m_icon = QIcon(MISSING_ICON_PATH);
m_state = State::Ready;
}
} // namespace Thumbnailer
} // namespace AzToolsFramework
#include "Thumbnails/moc_MissingThumbnail.cpp"
@@ -0,0 +1,30 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#if !defined(Q_MOC_RUN)
#include <AzToolsFramework/Thumbnails/Thumbnail.h>
#endif
namespace AzToolsFramework
{
namespace Thumbnailer
{
class MissingThumbnail
: public Thumbnail
{
Q_OBJECT
public:
explicit MissingThumbnail(int thumbnailSize);
};
} // namespace Thumbnailer
} // namespace AzToolsFramework
@@ -0,0 +1,164 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <AzFramework/StringFunc/StringFunc.h>
#include <AzToolsFramework/Thumbnails/SourceControlThumbnail.h>
#include <AzToolsFramework/SourceControl/SourceControlAPI.h>
#include <AzFramework/API/ApplicationAPI.h>
namespace AzToolsFramework
{
namespace Thumbnailer
{
//////////////////////////////////////////////////////////////////////////
// SourceControlThumbnailKey
//////////////////////////////////////////////////////////////////////////
SourceControlThumbnailKey::SourceControlThumbnailKey(const char* fileName)
: ThumbnailKey()
, m_fileName(fileName)
, m_updateInterval(4)
{
m_nextUpdate = AZStd::chrono::system_clock::now();
}
const AZStd::string& SourceControlThumbnailKey::GetFileName() const
{
return m_fileName;
}
bool SourceControlThumbnailKey::UpdateThumbnail()
{
if (!IsReady() || !SourceControlThumbnail::ReadyForUpdate())
{
return false;
}
const auto now(AZStd::chrono::system_clock::now());
if (m_nextUpdate >= now)
{
return false;
}
m_nextUpdate = now + m_updateInterval;
emit UpdateThumbnailSignal();
return true;
}
//////////////////////////////////////////////////////////////////////////
// SourceControlThumbnail
//////////////////////////////////////////////////////////////////////////
static const char* WRITABLE_ICON_PATH = "Editor/Icons/AssetBrowser/Writable_16.svg";
static const char* NONWRITABLE_ICON_PATH = "Editor/Icons/AssetBrowser/NonWritable_16.svg";
bool SourceControlThumbnail::m_readyForUpdate = true;
SourceControlThumbnail::SourceControlThumbnail(SharedThumbnailKey key, int thumbnailSize)
: Thumbnail(key, thumbnailSize)
{
const char* engineRoot = nullptr;
AzFramework::ApplicationRequests::Bus::BroadcastResult(engineRoot, &AzFramework::ApplicationRequests::GetEngineRoot);
AZ_Assert(engineRoot, "Engine Root not initialized");
AzFramework::StringFunc::Path::Join(engineRoot, WRITABLE_ICON_PATH, m_writableIconPath);
AzFramework::StringFunc::Path::Join(engineRoot, NONWRITABLE_ICON_PATH, m_nonWritableIconPath);
BusConnect();
}
SourceControlThumbnail::~SourceControlThumbnail()
{
BusDisconnect();
}
void SourceControlThumbnail::FileStatusChanged(const char* filename)
{
// when file status is changed, force instant update
auto sourceControlKey = azrtti_cast<const SourceControlThumbnailKey*>(m_key.data());
AZ_Assert(sourceControlKey, "Incorrect key type, excpected SourceControlThumbnailKey");
AZStd::string myFileName(sourceControlKey->GetFileName());
AzFramework::StringFunc::Path::Normalize(myFileName);
if (AzFramework::StringFunc::Equal(myFileName.c_str(), filename))
{
Update();
}
}
void SourceControlThumbnail::RequestSourceControlStatus()
{
auto sourceControlKey = azrtti_cast<const SourceControlThumbnailKey*>(m_key.data());
AZ_Assert(sourceControlKey, "Incorrect key type, excpected SourceControlThumbnailKey");
bool isSourceControlActive = false;
SourceControlConnectionRequestBus::BroadcastResult(isSourceControlActive, &SourceControlConnectionRequests::IsActive);
if (isSourceControlActive && SourceControlCommandBus::FindFirstHandler() != nullptr)
{
m_readyForUpdate = false;
SourceControlCommandBus::Broadcast(&SourceControlCommands::GetFileInfo, sourceControlKey->GetFileName().c_str(),
AZStd::bind(&SourceControlThumbnail::SourceControlFileInfoUpdated, this, AZStd::placeholders::_1, AZStd::placeholders::_2));
}
}
void SourceControlThumbnail::SourceControlFileInfoUpdated(bool succeeded, const SourceControlFileInfo& fileInfo)
{
if (succeeded)
{
if (fileInfo.HasFlag(AzToolsFramework::SCF_Writeable))
{
m_icon = QIcon(m_writableIconPath.c_str());
}
else
{
m_icon = QIcon(m_nonWritableIconPath.c_str());
}
}
else
{
m_icon = QIcon();
}
m_readyForUpdate = true;
emit Updated();
}
void SourceControlThumbnail::Update()
{
RequestSourceControlStatus();
}
bool SourceControlThumbnail::ReadyForUpdate()
{
return m_readyForUpdate;
}
//////////////////////////////////////////////////////////////////////////
// SourceControlThumbnailCache
//////////////////////////////////////////////////////////////////////////
SourceControlThumbnailCache::SourceControlThumbnailCache()
: ThumbnailCache<SourceControlThumbnail, SourceControlKeyHash, SourceControlKeyEqual>()
{
}
SourceControlThumbnailCache::~SourceControlThumbnailCache() = default;
const char* SourceControlThumbnailCache::GetProviderName() const
{
return ProviderName;
}
bool SourceControlThumbnailCache::IsSupportedThumbnail(SharedThumbnailKey key) const
{
return azrtti_istypeof<const SourceControlThumbnailKey*>(key.data());
}
} // namespace Thumbnailer
} // namespace AzToolsFramework
#include "Thumbnails/moc_SourceControlThumbnail.cpp"
@@ -0,0 +1,124 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#if !defined(Q_MOC_RUN)
#include <AzToolsFramework/Thumbnails/Thumbnail.h>
#include <AzToolsFramework/Thumbnails/SourceControlThumbnailBus.h>
#endif
namespace AzToolsFramework
{
struct SourceControlFileInfo;
namespace Thumbnailer
{
class SourceControlThumbnailKey
: public ThumbnailKey
{
Q_OBJECT
public:
AZ_RTTI(SourceControlFileInfo, "{F6772100-A178-45A7-8F75-41426B07D829}", ThumbnailKey);
explicit SourceControlThumbnailKey(const char* fileName);
const AZStd::string& GetFileName() const;
bool UpdateThumbnail() override;
protected:
//! absolute path
AZStd::string m_fileName;
//! how often should sc thumbnails auto update
const AZStd::chrono::minutes m_updateInterval;
//! time since this sc thumbnail updated
AZStd::chrono::system_clock::time_point m_nextUpdate;
};
//! SourceControlThumbnail currently replicates the source control functionality within Material Browser
//! Additionally source control status is refreshed whenever an operation is performed through context menu
class SourceControlThumbnail
: public Thumbnail
, public SourceControlThumbnailRequestBus::Handler
{
Q_OBJECT
public:
SourceControlThumbnail(SharedThumbnailKey key, int thumbnailSize);
~SourceControlThumbnail() override;
//////////////////////////////////////////////////////////////////////////
// SourceControlNotificationBus
//////////////////////////////////////////////////////////////////////////
void FileStatusChanged(const char* filename) override;
static bool ReadyForUpdate();
public Q_SLOTS:
void Update() override;
private:
// To avoid overpopulating sc update stack with status requests, sc thumbnail does not load until this function is called
void RequestSourceControlStatus();
void SourceControlFileInfoUpdated(bool succeeded, const SourceControlFileInfo& fileInfo);
//! If another sc thumbnail is currently requesting sc status this will return false
static bool m_readyForUpdate;
AZStd::string m_writableIconPath;
AZStd::string m_nonWritableIconPath;
};
namespace
{
class SourceControlKeyHash
{
public:
size_t operator() (const SharedThumbnailKey& /*val*/) const
{
return 0;
}
};
class SourceControlKeyEqual
{
public:
bool operator()(const SharedThumbnailKey& val1, const SharedThumbnailKey& val2) const
{
auto sourceThumbnailKey1 = azrtti_cast<const SourceControlThumbnailKey*>(val1.data());
auto sourceThumbnailKey2 = azrtti_cast<const SourceControlThumbnailKey*>(val2.data());
if (!sourceThumbnailKey1 || !sourceThumbnailKey2)
{
return false;
}
return sourceThumbnailKey1->GetFileName() == sourceThumbnailKey2->GetFileName();
}
};
}
//! Stores products' thumbnails
class SourceControlThumbnailCache
: public ThumbnailCache<SourceControlThumbnail, SourceControlKeyHash, SourceControlKeyEqual>
{
public:
SourceControlThumbnailCache();
~SourceControlThumbnailCache() override;
const char* GetProviderName() const override;
static constexpr const char* ProviderName = "SourceControl Thumbnails";
protected:
bool IsSupportedThumbnail(SharedThumbnailKey key) const override;
};
} // namespace Thumbnailer
} // namespace AzToolsFramework
@@ -0,0 +1,32 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzCore/EBus/EBus.h>
namespace AzToolsFramework
{
namespace Thumbnailer
{
//! Notifications for source control thumbnail
class SourceControlThumbnailRequests
: public AZ::EBusTraits
{
public:
//! Notify listeners that file's source control status may have changed
virtual void FileStatusChanged(const char* filename) = 0;
};
using SourceControlThumbnailRequestBus = AZ::EBus<SourceControlThumbnailRequests>;
} // namespace Thumbnailer
} // namespace AzToolsFramework
@@ -0,0 +1,106 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <AzToolsFramework/Thumbnails/Thumbnail.h>
AZ_PUSH_DISABLE_WARNING(4127 4251 4800 4244, "-Wunknown-warning-option") // 4127: conditional expression is constant
// 4251: 'QTextCodec::ConverterState::flags': class 'QFlags<QTextCodec::ConversionFlag>' needs to have dll-interface to be used by clients of struct 'QTextCodec::ConverterState'
// 4800: 'QTextBoundaryFinderPrivate *const ': forcing value to bool 'true' or 'false' (performance warning)
// 4244: conversion from 'int' to 'qint8', possible loss of data
#include <QtConcurrent/QtConcurrent>
AZ_POP_DISABLE_WARNING
namespace AzToolsFramework
{
namespace Thumbnailer
{
static const int DefaultIconSize = 16;
//////////////////////////////////////////////////////////////////////////
// ThumbnailKey
//////////////////////////////////////////////////////////////////////////
bool ThumbnailKey::IsReady() const { return m_ready; }
bool ThumbnailKey::UpdateThumbnail()
{
if (!IsReady())
{
return false;
}
emit UpdateThumbnailSignal();
return true;
}
//////////////////////////////////////////////////////////////////////////
// Thumbnail
//////////////////////////////////////////////////////////////////////////
Thumbnail::Thumbnail(SharedThumbnailKey key, int thumbnailSize)
: QObject()
, m_state(State::Unloaded)
, m_thumbnailSize(thumbnailSize)
, m_key(key)
{
connect(&m_watcher, &QFutureWatcher<void>::finished, this, [this]()
{
if (m_state == State::Loading)
{
m_state = State::Ready;
}
Q_EMIT Updated();
});
}
Thumbnail::~Thumbnail() = default;
bool Thumbnail::operator==(const Thumbnail& other) const
{
return m_key == other.m_key;
}
void Thumbnail::Load()
{
if (m_state == State::Unloaded)
{
m_state = State::Loading;
QFuture<void> future = QtConcurrent::run([this](){ LoadThread(); });
m_watcher.setFuture(future);
}
}
QPixmap Thumbnail::GetPixmap() const
{
return GetPixmap(QSize(DefaultIconSize, DefaultIconSize));
}
QPixmap Thumbnail::GetPixmap(const QSize& size) const
{
if (m_icon.isNull())
{
return m_pixmap;
}
return m_icon.pixmap(size);
}
SharedThumbnailKey Thumbnail::GetKey() const
{
return m_key;
}
Thumbnail::State Thumbnail::GetState() const
{
return m_state;
}
} // namespace Thumbnailer
} // namespace AzToolsFramework
#include "Thumbnails/moc_Thumbnail.cpp"
@@ -0,0 +1,172 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#if !defined(Q_MOC_RUN)
#include <AzCore/Component/TickBus.h>
AZ_PUSH_DISABLE_WARNING(4127 4251 4800, "-Wunknown-warning-option") // 4127: conditional expression is constant
// 4251: 'QLocale::d': class 'QSharedDataPointer<QLocalePrivate>' needs to have dll-interface to be used by clients of class 'QLocale'
// 4800: 'int': forcing value to bool 'true' or 'false' (performance warning)
#include <QObject>
#include <QPixmap>
#include <QIcon>
#include <QFutureWatcher>
AZ_POP_DISABLE_WARNING
#endif
namespace AzToolsFramework
{
namespace Thumbnailer
{
//! ThumbnailKey is used to locate thumbnails in thumbnail cache
/*
ThumbnailKey contains any kind of identifiable information to retrieve thumbnails (e.g. assetId, assetType, filename, etc.)
To use thumbnail system, keep reference to your thumbnail key, and retrieve Thumbnail via ThumbnailerRequestsBus
*/
class ThumbnailKey
: public QObject
{
friend class ThumbnailContext;
Q_OBJECT
public:
AZ_RTTI(ThumbnailKey, "{43F20F6B-333D-4226-8E4F-331A62315255}");
ThumbnailKey() = default;
virtual ~ThumbnailKey() = default;
bool IsReady() const;
virtual bool UpdateThumbnail();
Q_SIGNALS:
//! Updated signal is dispatched whenever thumbnail data was changed. Anyone using this thumbnail should listen to this.
void ThumbnailUpdatedSignal() const;
//! Force update mapped thumbnails
void UpdateThumbnailSignal() const;
private:
bool m_ready = false;
};
typedef QSharedPointer<ThumbnailKey> SharedThumbnailKey;
#define MAKE_TKEY(type, ...) QSharedPointer<type>(new type(__VA_ARGS__))
//! Thumbnail is the base class in thumbnailer system.
/*
Thumbnail handles storing and updating data for each specific thumbnail
Thumbnail also emits Updated signal whenever thumbnail data changes, this signal is listened to by every ThumbnailKey that maps to this thumbnail
Because you should be storing reference to ThumbnailKey and not Thumbnail, connect to ThumbnailKey signal instead
*/
class Thumbnail
: public QObject
{
Q_OBJECT
public:
enum class State
{
Unloaded,
Loading,
Ready,
Failed
};
Thumbnail(SharedThumbnailKey key, int thumbnailSize);
~Thumbnail() override;
bool operator == (const Thumbnail& other) const;
void Load();
virtual QPixmap GetPixmap() const;
virtual QPixmap GetPixmap(const QSize& size) const;
virtual void UpdateTime(float /*deltaTime*/) {}
SharedThumbnailKey GetKey() const;
State GetState() const;
Q_SIGNALS:
void Updated() const;
public Q_SLOTS:
virtual void Update() {}
protected:
QFutureWatcher<void> m_watcher;
State m_state;
int m_thumbnailSize;
SharedThumbnailKey m_key;
QPixmap m_pixmap;
QIcon m_icon;
virtual void LoadThread() {}
};
typedef QSharedPointer<Thumbnail> SharedThumbnail;
//! Interface to retrieve thumbnails
class ThumbnailProvider
{
public:
ThumbnailProvider() = default;
virtual ~ThumbnailProvider() = default;
virtual bool GetThumbnail(SharedThumbnailKey key, SharedThumbnail& thumbnail) = 0;
virtual void SetThumbnailSize(int thumbnailSize) = 0;
//! Priority identifies ThumbnailProvider order in ThumbnailContext
//! Higher priority means this ThumbnailProvider will take precedence in generating a thumbnail when
//! a supplied ThumbnailKey is supported by multiple providers.
virtual int GetPriority() const { return 0; }
//! A unique ThumbnailProvider name identifying it in a ThumbnailContext
virtual const char* GetProviderName() const = 0;
};
typedef QSharedPointer<ThumbnailProvider> SharedThumbnailProvider;
//! ThumbnailCache manages thumbnails of specific type, derive your custom provider from this
/*
ThumbnailType - type of thumbnails managed
HasherType - hashing function for storing thumbnail keys in the hashtable
EqualKey - equality function for storing thumbnail keys in the hashtable
HasherType and EqualKey need to be provided on individual basis depending on
what constitutes a unique key and how should the key collection be optimized
*/
template<typename ThumbnailType, typename HasherType, typename EqualKey>
class ThumbnailCache
: public ThumbnailProvider
, public AZ::TickBus::Handler
{
public:
ThumbnailCache();
~ThumbnailCache() override;
//////////////////////////////////////////////////////////////////////////
// TickBus
//////////////////////////////////////////////////////////////////////////
void OnTick(float deltaTime, AZ::ScriptTimePoint time) override;
bool GetThumbnail(SharedThumbnailKey key, SharedThumbnail& thumbnail) override;
void SetThumbnailSize(int thumbnailSize) override;
protected:
int m_thumbnailSize;
AZStd::unordered_map<SharedThumbnailKey, SharedThumbnail, HasherType, EqualKey> m_cache;
//! Check if thumbnail key is handled by this provider, overload in derived class
virtual bool IsSupportedThumbnail(SharedThumbnailKey key) const = 0;
};
#define MAKE_TCACHE(cacheType, ...) QSharedPointer<cacheType>(new cacheType(__VA_ARGS__))
} // namespace Thumbnailer
} // namespace AzToolsFramework
Q_DECLARE_METATYPE(AzToolsFramework::Thumbnailer::SharedThumbnailKey)
#include <AzToolsFramework/Thumbnails/Thumbnail.inl>
@@ -0,0 +1,66 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <QSharedPointer>
namespace AzToolsFramework
{
namespace Thumbnailer
{
template <typename ThumbnailType, typename HasherType, typename EqualKey>
ThumbnailCache<ThumbnailType, HasherType, EqualKey>::ThumbnailCache()
: m_thumbnailSize(0)
{
BusConnect();
}
template <typename ThumbnailType, typename HasherType, typename EqualKey>
ThumbnailCache<ThumbnailType, HasherType, EqualKey>::~ThumbnailCache()
{
BusDisconnect();
}
template <typename ThumbnailType, typename HasherType, typename EqualKey>
void ThumbnailCache<ThumbnailType, HasherType, EqualKey>::OnTick(float deltaTime, AZ::ScriptTimePoint /*time*/)
{
for (auto& kvp : m_cache)
{
kvp.second->UpdateTime(deltaTime);
}
}
template <typename ThumbnailType, typename HasherType, typename EqualKey>
bool ThumbnailCache<ThumbnailType, HasherType, EqualKey>::GetThumbnail(
SharedThumbnailKey key, SharedThumbnail& thumbnail)
{
auto it = m_cache.find(key);
if (it != m_cache.end())
{
thumbnail = it->second;
return true;
}
if (IsSupportedThumbnail(key))
{
thumbnail = QSharedPointer<ThumbnailType>(new ThumbnailType(key, m_thumbnailSize));
m_cache[key] = thumbnail;
return true;
}
return false;
}
template <typename ThumbnailType, typename HasherType, typename EqualKey>
void ThumbnailCache<ThumbnailType, HasherType, EqualKey>::SetThumbnailSize(int thumbnailSize)
{
m_thumbnailSize = thumbnailSize;
}
} // namespace Thumbnailer
} // namespace AzToolsFramework
@@ -0,0 +1,128 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <AzFramework/StringFunc/StringFunc.h>
#include <AzToolsFramework/Thumbnails/ThumbnailContext.h>
#include <AzToolsFramework/Thumbnails/MissingThumbnail.h>
#include <AzToolsFramework/Thumbnails/LoadingThumbnail.h>
#include <AzToolsFramework/AssetBrowser/AssetBrowserBus.h>
AZ_PUSH_DISABLE_WARNING(4244 4251, "-Wunknown-warning-option") // 4251: 'QImageIOHandler::d_ptr': class 'QScopedPointer<QImageIOHandlerPrivate,QScopedPointerDeleter<T>>' needs to have dll-interface to be used by clients of class 'QImageIOHandler'
#include <AzQtComponents/Components/StyledBusyLabel.h>
AZ_POP_DISABLE_WARNING
namespace AzToolsFramework
{
namespace Thumbnailer
{
ThumbnailContext::ThumbnailContext(int thumbnailSize)
: m_missingThumbnail(new MissingThumbnail(thumbnailSize))
, m_loadingThumbnail(new LoadingThumbnail(thumbnailSize))
, m_thumbnailSize(thumbnailSize)
{
}
ThumbnailContext::~ThumbnailContext() = default;
bool ThumbnailContext::IsLoading(SharedThumbnailKey key)
{
SharedThumbnail thumbnail;
for (auto& provider : m_providers)
{
if (provider->GetThumbnail(key, thumbnail))
{
return thumbnail->GetState() == Thumbnail::State::Unloaded ||
thumbnail->GetState() == Thumbnail::State::Loading;
}
}
return false;
}
void ThumbnailContext::RedrawThumbnail()
{
AzToolsFramework::AssetBrowser::AssetBrowserViewRequestBus::Broadcast(&AzToolsFramework::AssetBrowser::AssetBrowserViewRequests::Update);
}
SharedThumbnail ThumbnailContext::GetThumbnail(SharedThumbnailKey key)
{
SharedThumbnail thumbnail;
// find provider who can handle supplied key
for (auto& provider : m_providers)
{
if (provider->GetThumbnail(key, thumbnail))
{
// if thumbnail is ready return it
if (thumbnail->GetState() == Thumbnail::State::Ready)
{
return thumbnail;
}
// if thumbnail is not loaded, start loading it, meanwhile return loading thumbnail
if (thumbnail->GetState() == Thumbnail::State::Unloaded)
{
// listen to the loading signal, so the anyone using it will update loading animation
connect(m_loadingThumbnail.data(), &Thumbnail::Updated, key.data(), &ThumbnailKey::ThumbnailUpdatedSignal);
AzQtComponents::StyledBusyLabel* busyLabel;
AzToolsFramework::AssetBrowser::AssetBrowserComponentRequestBus::BroadcastResult(busyLabel, &AzToolsFramework::AssetBrowser::AssetBrowserComponentRequests::GetStyledBusyLabel);
connect(busyLabel, &AzQtComponents::StyledBusyLabel::repaintNeeded, this, &ThumbnailContext::RedrawThumbnail);
// once the thumbnail is loaded, disconnect it from loading thumbnail
connect(thumbnail.data(), &Thumbnail::Updated, this , [this, key, thumbnail, busyLabel]()
{
disconnect(m_loadingThumbnail.data(), &Thumbnail::Updated, key.data(), &ThumbnailKey::ThumbnailUpdatedSignal);
disconnect(busyLabel, &AzQtComponents::StyledBusyLabel::repaintNeeded, this, &ThumbnailContext::RedrawThumbnail);
thumbnail->disconnect();
connect(thumbnail.data(), &Thumbnail::Updated, key.data(), &ThumbnailKey::ThumbnailUpdatedSignal);
connect(key.data(), &ThumbnailKey::UpdateThumbnailSignal, thumbnail.data(), &Thumbnail::Update);
key->m_ready = true;
Q_EMIT key->ThumbnailUpdatedSignal();
});
thumbnail->Load();
}
if (thumbnail->GetState() == Thumbnail::State::Failed)
{
return m_missingThumbnail;
}
return m_loadingThumbnail;
}
}
return m_missingThumbnail;
}
void ThumbnailContext::RegisterThumbnailProvider(SharedThumbnailProvider providerToAdd)
{
auto it = AZStd::find_if(m_providers.begin(), m_providers.end(), [providerToAdd](const SharedThumbnailProvider& provider)
{
return AZ::StringFunc::Equal(provider->GetProviderName(), providerToAdd->GetProviderName());
});
if (it != m_providers.end())
{
AZ_Error("ThumbnailContext", false, "Provider with name %s is already registered with context.", providerToAdd->GetProviderName());
return;
}
providerToAdd->SetThumbnailSize(m_thumbnailSize);
m_providers.insert(providerToAdd);
}
void ThumbnailContext::UnregisterThumbnailProvider(const char* providerName)
{
auto it = AZStd::remove_if(m_providers.begin(), m_providers.end(), [providerName](const SharedThumbnailProvider& provider)
{
return AZ::StringFunc::Equal(provider->GetProviderName(), providerName);
});
m_providers.erase(it, m_providers.end());
}
} // namespace Thumbnailer
} // namespace AzToolsFramework
#include "Thumbnails/moc_ThumbnailContext.cpp"
@@ -0,0 +1,84 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#if !defined(Q_MOC_RUN)
#include <AzCore/Memory/SystemAllocator.h>
#include <AzCore/std/containers/set.h>
#include <AzToolsFramework/Thumbnails/Thumbnail.h>
#include <AzToolsFramework/Thumbnails/ThumbnailerBus.h>
#include <QObject>
#include <QList>
#endif
class QString;
class QPixmap;
namespace AzToolsFramework
{
namespace Thumbnailer
{
class ThumbnailProvider;
//! ThumbnailContext provides distinct thumbnail location for specific context
/*
There can be any number of contexts for every unique feature that may need different types of thumbnails.
For example 'AssetBrowser' context provides thumbnails specific to Asset Browser
'PreviewContext' may provide thumbnails for Preview Widget
'MaterialBrowser' may provide thumbnails for Material Browser
etc.
*/
class ThumbnailContext
: public QObject
{
Q_OBJECT
public:
AZ_CLASS_ALLOCATOR(ThumbnailContext, AZ::SystemAllocator, 0)
explicit ThumbnailContext(int thumbnailSize);
~ThumbnailContext() override;
//! Is the thumbnail currently loading or is about to load.
bool IsLoading(SharedThumbnailKey key);
//! Retrieve thumbnail by key, generate one if needed
SharedThumbnail GetThumbnail(SharedThumbnailKey key);
//! Add new thumbnail cache
void RegisterThumbnailProvider(SharedThumbnailProvider providerToAdd);
//! Remove thumbnail cache by name if found
void UnregisterThumbnailProvider(const char* providerName);
void RedrawThumbnail();
//! Default context used for most thumbnails
static constexpr const char* DefaultContext = "Default";
private:
struct ProviderCompare {
bool operator() (const SharedThumbnailProvider& lhs, const SharedThumbnailProvider& rhs) const
{
// sorting in reverse, higher priority means the provider should be considered first
return lhs->GetPriority() > rhs->GetPriority();
}
};
//! Collection of thumbnail caches provided by this context
AZStd::multiset<SharedThumbnailProvider, ProviderCompare> m_providers;
//! Default missing thumbnail used when no thumbnail for given key can be found within this context
SharedThumbnail m_missingThumbnail;
//! Default loading thumbnail used when thumbnail is found by is not yet generated
SharedThumbnail m_loadingThumbnail;
//! Thumbnail size (width and height in pixels)
int m_thumbnailSize;
};
} // namespace Thumbnailer
} // namespace AzToolsFramework
@@ -0,0 +1,52 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <QStyledItemDelegate>
#include <AzCore/std/string/string.h>
class QWidget;
class QPainter;
class QStyleOptionViewItem;
class QAbstractItemModel;
class QModelIndex;
namespace AzToolsFramework
{
namespace Thumbnailer
{
//! Thumbnail delegate can be used as within item views to draw thumbnails
class ThumbnailDelegate
: public QStyledItemDelegate
{
Q_OBJECT
public:
explicit ThumbnailDelegate(QWidget* parent = nullptr);
~ThumbnailDelegate() override;
//////////////////////////////////////////////////////////////////////////
// QStyledItemDelegate
//////////////////////////////////////////////////////////////////////////
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const override;
void setEditorData(QWidget* editor, const QModelIndex& index) const override;
void setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const override;
//! Set location where thumbnails are searched
void SetThumbnailContext(const char* thumbnailContext);
private:
AZStd::string m_thumbnailContext;
};
} // namespace Thumbnailer
} // namespace AzToolsFramework
@@ -0,0 +1,95 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <AzCore/PlatformDef.h>
#include <AzToolsFramework/Thumbnails/ThumbnailWidget.h>
#include <AzToolsFramework/Thumbnails/ThumbnailerBus.h>
// 4127: conditional expression is constant
// 4800 'uint': forcing value to bool 'true' or 'false' (performance warning)
// 4251: 'QPainter::d_ptr': class 'QScopedPointer<QPainterPrivate,QScopedPointerDeleter<T>>' needs to have dll-interface to be used by clients of class 'QPainter'
AZ_PUSH_DISABLE_WARNING(4127 4800 4251, "-Wunknown-warning-option")
#include <QPainter>
#include <QPixmap>
#include <QtGlobal>
AZ_POP_DISABLE_WARNING
namespace AzToolsFramework
{
namespace Thumbnailer
{
ThumbnailWidget::ThumbnailWidget(QWidget* parent)
: QWidget(parent)
{
}
void ThumbnailWidget::SetThumbnailKey(SharedThumbnailKey key, const char* contextName)
{
if (m_key)
{
disconnect(m_key.data(), &ThumbnailKey::ThumbnailUpdatedSignal, this, &ThumbnailWidget::KeyUpdatedSlot);
}
m_key = key;
m_contextName = contextName;
connect(m_key.data(), &ThumbnailKey::ThumbnailUpdatedSignal, this, &ThumbnailWidget::KeyUpdatedSlot);
repaint();
}
void ThumbnailWidget::ClearThumbnail()
{
m_key.clear();
repaint();
}
int ThumbnailWidget::heightForWidth(int w) const
{
return w;
}
QSize ThumbnailWidget::sizeHint() const
{
int w = this->width();
return QSize(w, heightForWidth(w));
}
void ThumbnailWidget::paintEvent(QPaintEvent* event)
{
if (m_key)
{
// thumbnail instance is not stored locally, but retrieved each paintEvent since thumbnail mapped to a specific key may change
SharedThumbnail thumbnail;
ThumbnailerRequestsBus::BroadcastResult(thumbnail, &ThumbnailerRequests::GetThumbnail, m_key, m_contextName.c_str());
QPainter painter(this);
QPixmap pixmap = thumbnail->GetPixmap();
// preserve thumbnail image's ratio, if the widget is wider than the image, center the image hotizontally
float aspectRatio = aznumeric_cast<float>(pixmap.width()) / pixmap.height();
int originalWidth = width();
int originalHeight = height();
int realHeight = qMin(aznumeric_cast<int>(originalWidth /aspectRatio), originalHeight);
int realWidth = aznumeric_cast<int>(realHeight * aspectRatio);
int x = (originalWidth - realWidth) / 2;
painter.drawPixmap(QRect(x, 0, realHeight, realWidth), pixmap);
}
QWidget::paintEvent(event);
}
void ThumbnailWidget::KeyUpdatedSlot()
{
repaint();
}
} // namespace Thumbnailer
} // namespace AzToolsFramework
#include "Thumbnails/moc_ThumbnailWidget.cpp"
@@ -0,0 +1,57 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#if !defined(Q_MOC_RUN)
#include <AzCore/PlatformDef.h>
#include <AzToolsFramework/Thumbnails/Thumbnail.h>
AZ_PUSH_DISABLE_WARNING(4251 4800, "-Wunknown-warning-option") // 4251: 'QBrush::d': class 'QScopedPointer<QBrushData,QBrushDataPointerDeleter>' needs to have dll-interface to be used by clients of class 'QBrush'
// 4800: 'uint': forcing value to bool 'true' or 'false' (performance warning)
#include <QWidget>
#endif
AZ_POP_DISABLE_WARNING
namespace AzToolsFramework
{
namespace Thumbnailer
{
//! A widget used to display thumbnail. To display thumbnails within item views, use ThumbnailDelegate
class ThumbnailWidget
: public QWidget
{
Q_OBJECT
public:
explicit ThumbnailWidget(QWidget* parent = nullptr);
~ThumbnailWidget() override = default;
//! Call this to set what thumbnail widget will display
void SetThumbnailKey(SharedThumbnailKey key, const char* contextName = "Default");
//! Remove current thumbnail
void ClearThumbnail();
int heightForWidth(int w) const override;
QSize sizeHint() const override;
protected:
void paintEvent(QPaintEvent* event) override;
private:
SharedThumbnailKey m_key;
AZStd::string m_contextName;
private Q_SLOTS:
void KeyUpdatedSlot();
};
} // namespace Thumbnailer
} // namespace AzToolsFramework
@@ -0,0 +1,92 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzCore/EBus/EBus.h>
#include <AzCore/Asset/AssetCommon.h>
#include <AzToolsFramework/Thumbnails/Thumbnail.h>
class QPixmap;
namespace AzToolsFramework
{
namespace Thumbnailer
{
//! Interaction with thumbnailer
class ThumbnailerRequests
: public AZ::EBusTraits
{
public:
//! Add thumbnail context
virtual void RegisterContext(const char* contextName, int thumbnailSize) = 0;
//! Remove thumbnail context and all associated ThumbnailProviders
virtual void UnregisterContext(const char* contextName) = 0;
//! Return whether a given ThumbnailContext has been registered
virtual bool HasContext(const char* contextName) const = 0;
//! Add new thumbnail provider to ThumbnailContext
virtual void RegisterThumbnailProvider(SharedThumbnailProvider provider, const char* contextName) = 0;
//! Remove thumbnail provider from ThumbnailContext
virtual void UnregisterThumbnailProvider(const char* providerName, const char* contextName) = 0;
//! Retrieve thumbnail by key,
//! if no thumbnail matching found, one of ThumbnailProviders will attempt to create
//! If no compatible providers found, MissingThumbnail will be returned
virtual SharedThumbnail GetThumbnail(SharedThumbnailKey thumbnailKey, const char* contextName) = 0;
//! Return whether the thumbnail is loading.
virtual bool IsLoading(SharedThumbnailKey thumbnailKey, const char* contextName) = 0;
};
using ThumbnailerRequestBus = AZ::EBus<ThumbnailerRequests>;
using ThumbnailerRequestsBus = AZ::EBus<ThumbnailerRequests>; //deprecated
//! Request product thumbnail to be rendered
class ThumbnailerRendererRequests
: public AZ::EBusTraits
{
public:
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById;
typedef AZ::Data::AssetType BusIdType;
static const bool EnableEventQueue = true;
typedef AZStd::recursive_mutex MutexType;
virtual void RenderThumbnail(AZ::Data::AssetId assetId, int thumbnailSize) = 0;
virtual bool Installed() const { return false; }
};
using ThumbnailerRendererRequestBus = AZ::EBus<ThumbnailerRendererRequests>;
using ThumbnailerRendererRequestsBus = AZ::EBus<ThumbnailerRendererRequests>; //deprecated
//! Notify that product thumbnail was rendered
class ThumbnailerRendererNotifications
: public AZ::EBusTraits
{
public:
static const AZ::EBusAddressPolicy AddressPolicy = AZ::EBusAddressPolicy::ById;
typedef AZ::Data::AssetId BusIdType;
//! notify product thumbnail that the data is ready
virtual void ThumbnailRendered(QPixmap& thumbnailImage) = 0;
//! notify product thumbnail that the thumbnail failed to render
virtual void ThumbnailFailedToRender() = 0;
};
using ThumbnailerRendererNotificationBus = AZ::EBus<ThumbnailerRendererNotifications>;
} // namespace Thumbnailer
} // namespace AzToolsFramework
@@ -0,0 +1,112 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#include <AzCore/std/smart_ptr/make_shared.h>
#include <AzCore/Serialization/SerializeContext.h>
#include <AzToolsFramework/Thumbnails/ThumbnailerComponent.h>
#include <AzToolsFramework/Thumbnails/ThumbnailContext.h>
#include <QApplication>
#include <QStyle>
namespace AzToolsFramework
{
namespace Thumbnailer
{
ThumbnailerComponent::ThumbnailerComponent()
{
}
ThumbnailerComponent::~ThumbnailerComponent() = default;
void ThumbnailerComponent::Activate()
{
int thumbnailSize = qApp->style()->pixelMetric(QStyle::PM_SmallIconSize);
RegisterContext(ThumbnailContext::DefaultContext, thumbnailSize);
BusConnect();
}
void ThumbnailerComponent::Deactivate()
{
BusDisconnect();
m_thumbnails.clear();
}
void ThumbnailerComponent::Reflect(AZ::ReflectContext* context)
{
AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context);
if (serialize)
{
serialize->Class<ThumbnailerComponent, AZ::Component>();
}
}
void ThumbnailerComponent::GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible)
{
incompatible.push_back(AZ_CRC("ThumbnailerService", 0x65422b97));
}
void ThumbnailerComponent::GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided)
{
provided.push_back(AZ_CRC("ThumbnailerService", 0x65422b97));
}
void ThumbnailerComponent::RegisterContext(const char* contextName, int thumbnailSize)
{
AZ_Assert(m_thumbnails.find(contextName) == m_thumbnails.end(), "Context %s already registered", contextName);
m_thumbnails[contextName] = AZStd::make_shared<ThumbnailContext>(thumbnailSize);
}
void ThumbnailerComponent::UnregisterContext(const char* contextName)
{
AZ_Assert(m_thumbnails.find(contextName) != m_thumbnails.end(), "Context %s not registered", contextName);
m_thumbnails.erase(contextName);
}
bool ThumbnailerComponent::HasContext(const char* contextName) const
{
return m_thumbnails.find(contextName) != m_thumbnails.end();
}
void ThumbnailerComponent::RegisterThumbnailProvider(SharedThumbnailProvider provider, const char* contextName)
{
auto it = m_thumbnails.find(contextName);
AZ_Assert(it != m_thumbnails.end(), "Context %s not registered", contextName);
it->second->RegisterThumbnailProvider(provider);
}
void ThumbnailerComponent::UnregisterThumbnailProvider(const char* providerName, const char* contextName)
{
auto it = m_thumbnails.find(contextName);
AZ_Assert(it != m_thumbnails.end(), "Context %s not registered", contextName);
it->second->UnregisterThumbnailProvider(providerName);
}
SharedThumbnail ThumbnailerComponent::GetThumbnail(SharedThumbnailKey key, const char* contextName)
{
auto it = m_thumbnails.find(contextName);
AZ_Assert(it != m_thumbnails.end(), "Context %s not registered", contextName);
return it->second->GetThumbnail(key);
}
bool ThumbnailerComponent::IsLoading(SharedThumbnailKey key, const char* contextName)
{
auto it = m_thumbnails.find(contextName);
AZ_Assert(it != m_thumbnails.end(), "Context %s not registered", contextName);
return it->second->IsLoading(key);
}
} // namespace Thumbnailer
} // namespace AzToolsFramework
@@ -0,0 +1,58 @@
/*
* All or portions of this file Copyright (c) Amazon.com, Inc. or its affiliates or
* its licensors.
*
* For complete copyright and license terms please see the LICENSE at the root of this
* distribution (the "License"). All use of this software is governed by the License,
* or, if provided, by the license below or the license accompanying this file. Do not
* remove or modify any license notices. This file is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
#pragma once
#include <AzCore/Memory/SystemAllocator.h>
#include <AzCore/Component/Component.h>
#include <AzToolsFramework/Thumbnails/ThumbnailerBus.h>
namespace AzToolsFramework
{
namespace Thumbnailer
{
class ThumbnailContext;
class ThumbnailerComponent
: public AZ::Component
, public ThumbnailerRequestsBus::Handler
{
public:
AZ_COMPONENT(ThumbnailerComponent, "{80090CA5-6A3A-4554-B5FE-A6D74ECB2D84}")
ThumbnailerComponent();
virtual ~ThumbnailerComponent();
//////////////////////////////////////////////////////////////////////////
// AZ::Component
//////////////////////////////////////////////////////////////////////////
void Activate() override;
void Deactivate() override;
static void Reflect(AZ::ReflectContext* context);
static void GetIncompatibleServices(AZ::ComponentDescriptor::DependencyArrayType& incompatible);
static void GetProvidedServices(AZ::ComponentDescriptor::DependencyArrayType& provided);
//////////////////////////////////////////////////////////////////////////
// ThumbnailerRequests
//////////////////////////////////////////////////////////////////////////
void RegisterContext(const char* contextName, int thumbnailSize) override;
void UnregisterContext(const char* contextName) override;
bool HasContext(const char* contextName) const override;
void RegisterThumbnailProvider(SharedThumbnailProvider provider, const char* contextName) override;
void UnregisterThumbnailProvider(const char* providerName, const char* contextName) override;
SharedThumbnail GetThumbnail(SharedThumbnailKey thumbnailKey, const char* contextName) override;
bool IsLoading(SharedThumbnailKey thumbnailKey, const char* contextName) override;
private:
AZStd::unordered_map<AZStd::string, AZStd::shared_ptr<ThumbnailContext>> m_thumbnails;
};
} // Thumbnailer
} // namespace AssetBrowser