98 lines
2.2 KiB
C++
98 lines
2.2 KiB
C++
|
|
#include "BuiltInIcons.h"
|
||
|
|
#include "Bootstrap/EditorResources.h"
|
||
|
|
#include "Support/EmbeddedPngLoader.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;
|
||
|
|
}
|
||
|
|
|
||
|
|
void LoadEmbeddedIconTexture(
|
||
|
|
Host::NativeRenderer& renderer,
|
||
|
|
UINT resourceId,
|
||
|
|
std::string_view label,
|
||
|
|
::XCEngine::UI::UITextureHandle& outTexture,
|
||
|
|
std::ostringstream& errorStream) {
|
||
|
|
std::string error = {};
|
||
|
|
if (!Support::LoadEmbeddedPngTexture(renderer, resourceId, outTexture, error)) {
|
||
|
|
AppendLoadError(errorStream, label, error);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
} // namespace
|
||
|
|
|
||
|
|
void BuiltInIcons::Initialize(Host::NativeRenderer& renderer) {
|
||
|
|
Shutdown();
|
||
|
|
|
||
|
|
m_renderer = &renderer;
|
||
|
|
|
||
|
|
std::ostringstream errorStream = {};
|
||
|
|
LoadEmbeddedIconTexture(
|
||
|
|
renderer,
|
||
|
|
IDR_PNG_FOLDER_ICON,
|
||
|
|
"folder_icon.png",
|
||
|
|
m_folderIcon,
|
||
|
|
errorStream);
|
||
|
|
LoadEmbeddedIconTexture(
|
||
|
|
renderer,
|
||
|
|
IDR_PNG_GAMEOBJECT_ICON,
|
||
|
|
"gameobject_icon.png",
|
||
|
|
m_gameObjectIcon,
|
||
|
|
errorStream);
|
||
|
|
LoadEmbeddedIconTexture(
|
||
|
|
renderer,
|
||
|
|
IDR_PNG_SCENE_ICON,
|
||
|
|
"scene_icon.png",
|
||
|
|
m_sceneIcon,
|
||
|
|
errorStream);
|
||
|
|
|
||
|
|
m_lastError = errorStream.str();
|
||
|
|
}
|
||
|
|
|
||
|
|
void BuiltInIcons::Shutdown() {
|
||
|
|
if (m_renderer != nullptr) {
|
||
|
|
m_renderer->ReleaseTexture(m_folderIcon);
|
||
|
|
m_renderer->ReleaseTexture(m_gameObjectIcon);
|
||
|
|
m_renderer->ReleaseTexture(m_sceneIcon);
|
||
|
|
}
|
||
|
|
|
||
|
|
m_renderer = nullptr;
|
||
|
|
m_lastError.clear();
|
||
|
|
}
|
||
|
|
|
||
|
|
const ::XCEngine::UI::UITextureHandle& BuiltInIcons::Resolve(
|
||
|
|
BuiltInIconKind kind) const {
|
||
|
|
switch (kind) {
|
||
|
|
case BuiltInIconKind::Folder:
|
||
|
|
return m_folderIcon;
|
||
|
|
case BuiltInIconKind::GameObject:
|
||
|
|
return m_gameObjectIcon;
|
||
|
|
case BuiltInIconKind::Scene:
|
||
|
|
return m_sceneIcon;
|
||
|
|
default:
|
||
|
|
return m_folderIcon;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
const std::string& BuiltInIcons::GetLastError() const {
|
||
|
|
return m_lastError;
|
||
|
|
}
|
||
|
|
|
||
|
|
} // namespace XCEngine::UI::Editor::App
|
||
|
|
|