Improve project panel image previews
This commit is contained in:
@@ -4,6 +4,8 @@
|
||||
#include <cctype>
|
||||
#include <cwctype>
|
||||
#include <fstream>
|
||||
#include <initializer_list>
|
||||
#include <string_view>
|
||||
#include <windows.h>
|
||||
|
||||
namespace fs = std::filesystem;
|
||||
@@ -139,6 +141,56 @@ bool RenamePathCaseAware(const fs::path& sourcePath, const fs::path& destPath) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MatchesExtension(std::wstring_view extension, std::initializer_list<std::wstring_view> candidates) {
|
||||
for (const std::wstring_view candidate : candidates) {
|
||||
if (extension == candidate) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool IsImageAssetExtension(std::wstring_view extension) {
|
||||
return MatchesExtension(extension, {
|
||||
L".png",
|
||||
L".jpg",
|
||||
L".jpeg",
|
||||
L".tga",
|
||||
L".bmp",
|
||||
L".gif",
|
||||
L".psd",
|
||||
L".hdr",
|
||||
L".pic",
|
||||
L".ppm",
|
||||
L".pgm",
|
||||
L".pbm",
|
||||
L".pnm",
|
||||
L".dds",
|
||||
L".ktx",
|
||||
L".ktx2",
|
||||
L".webp"
|
||||
});
|
||||
}
|
||||
|
||||
bool CanPreviewImageAssetExtension(std::wstring_view extension) {
|
||||
return MatchesExtension(extension, {
|
||||
L".png",
|
||||
L".jpg",
|
||||
L".jpeg",
|
||||
L".tga",
|
||||
L".bmp",
|
||||
L".gif",
|
||||
L".psd",
|
||||
L".hdr",
|
||||
L".pic",
|
||||
L".ppm",
|
||||
L".pgm",
|
||||
L".pbm",
|
||||
L".pnm"
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
const std::vector<AssetItemPtr>& ProjectManager::GetCurrentItems() const {
|
||||
@@ -535,8 +587,11 @@ AssetItemPtr ProjectManager::CreateAssetItem(const std::wstring& path, const std
|
||||
} else {
|
||||
std::wstring ext = fs::path(path).extension().wstring();
|
||||
std::transform(ext.begin(), ext.end(), ext.begin(), ::towlower);
|
||||
|
||||
if (ext == L".png" || ext == L".jpg" || ext == L".jpeg" || ext == L".tga" || ext == L".bmp") {
|
||||
item->extensionLower = WstringPathToUtf8(ext);
|
||||
item->isImageAsset = IsImageAssetExtension(ext);
|
||||
item->canUseImagePreview = CanPreviewImageAssetExtension(ext);
|
||||
|
||||
if (item->isImageAsset) {
|
||||
item->type = "Texture";
|
||||
} else if (ext == L".fbx" || ext == L".obj" || ext == L".gltf" || ext == L".glb") {
|
||||
item->type = "Model";
|
||||
|
||||
Reference in New Issue
Block a user