95 lines
2.5 KiB
C++
95 lines
2.5 KiB
C++
#include "ProductBuiltInIcons.h"
|
|
|
|
#include <sstream>
|
|
|
|
namespace XCEngine::UI::Editor::App {
|
|
|
|
namespace {
|
|
|
|
void AppendLoadError(
|
|
std::ostringstream& stream,
|
|
std::string_view label,
|
|
const std::string& error) {
|
|
if (error.empty()) {
|
|
return;
|
|
}
|
|
|
|
if (stream.tellp() > 0) {
|
|
stream << '\n';
|
|
}
|
|
stream << label << ": " << error;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
void ProductBuiltInIcons::Initialize(
|
|
Host::NativeRenderer& renderer,
|
|
const std::filesystem::path& repoRoot) {
|
|
Shutdown();
|
|
|
|
m_renderer = &renderer;
|
|
m_repoRoot = repoRoot.lexically_normal();
|
|
|
|
std::ostringstream errorStream = {};
|
|
std::string error = {};
|
|
if (!m_renderer->LoadTextureFromFile(ResolveFolderIconPath(), m_folderIcon, error)) {
|
|
AppendLoadError(errorStream, "folder_icon.png", error);
|
|
}
|
|
|
|
error.clear();
|
|
if (!m_renderer->LoadTextureFromFile(ResolveGameObjectIconPath(), m_gameObjectIcon, error)) {
|
|
AppendLoadError(errorStream, "gameobject_icon.png", error);
|
|
}
|
|
|
|
error.clear();
|
|
if (!m_renderer->LoadTextureFromFile(ResolveSceneIconPath(), m_sceneIcon, error)) {
|
|
AppendLoadError(errorStream, "scene_icon.png", error);
|
|
}
|
|
|
|
m_lastError = errorStream.str();
|
|
}
|
|
|
|
void ProductBuiltInIcons::Shutdown() {
|
|
if (m_renderer != nullptr) {
|
|
m_renderer->ReleaseTexture(m_folderIcon);
|
|
m_renderer->ReleaseTexture(m_gameObjectIcon);
|
|
m_renderer->ReleaseTexture(m_sceneIcon);
|
|
}
|
|
|
|
m_renderer = nullptr;
|
|
m_repoRoot.clear();
|
|
m_lastError.clear();
|
|
}
|
|
|
|
const ::XCEngine::UI::UITextureHandle& ProductBuiltInIcons::Resolve(
|
|
ProductBuiltInIconKind kind) const {
|
|
switch (kind) {
|
|
case ProductBuiltInIconKind::Folder:
|
|
return m_folderIcon;
|
|
case ProductBuiltInIconKind::GameObject:
|
|
return m_gameObjectIcon;
|
|
case ProductBuiltInIconKind::Scene:
|
|
return m_sceneIcon;
|
|
default:
|
|
return m_folderIcon;
|
|
}
|
|
}
|
|
|
|
const std::string& ProductBuiltInIcons::GetLastError() const {
|
|
return m_lastError;
|
|
}
|
|
|
|
std::filesystem::path ProductBuiltInIcons::ResolveFolderIconPath() const {
|
|
return (m_repoRoot / "editor/resources/Icons/folder_icon.png").lexically_normal();
|
|
}
|
|
|
|
std::filesystem::path ProductBuiltInIcons::ResolveGameObjectIconPath() const {
|
|
return (m_repoRoot / "editor/resources/Icons/gameobject_icon.png").lexically_normal();
|
|
}
|
|
|
|
std::filesystem::path ProductBuiltInIcons::ResolveSceneIconPath() const {
|
|
return (m_repoRoot / "editor/resources/Icons/scene_icon.png").lexically_normal();
|
|
}
|
|
|
|
} // namespace XCEngine::UI::Editor::App
|