refactor(new_editor): continue architecture closeout
This commit is contained in:
63
new_editor/app/Support/EmbeddedPngLoader.cpp
Normal file
63
new_editor/app/Support/EmbeddedPngLoader.cpp
Normal file
@@ -0,0 +1,63 @@
|
||||
#include "Support/EmbeddedPngLoader.h"
|
||||
|
||||
namespace XCEngine::UI::Editor::Support {
|
||||
|
||||
bool LoadEmbeddedPngBytes(
|
||||
UINT resourceId,
|
||||
const std::uint8_t*& outData,
|
||||
std::size_t& outSize,
|
||||
std::string& outError) {
|
||||
outData = nullptr;
|
||||
outSize = 0u;
|
||||
outError.clear();
|
||||
|
||||
HMODULE module = GetModuleHandleW(nullptr);
|
||||
if (module == nullptr) {
|
||||
outError = "GetModuleHandleW(nullptr) returned null.";
|
||||
return false;
|
||||
}
|
||||
|
||||
HRSRC resource = FindResourceW(module, MAKEINTRESOURCEW(resourceId), L"PNG");
|
||||
if (resource == nullptr) {
|
||||
outError = "FindResourceW failed.";
|
||||
return false;
|
||||
}
|
||||
|
||||
HGLOBAL resourceData = LoadResource(module, resource);
|
||||
if (resourceData == nullptr) {
|
||||
outError = "LoadResource failed.";
|
||||
return false;
|
||||
}
|
||||
|
||||
const DWORD resourceSize = SizeofResource(module, resource);
|
||||
if (resourceSize == 0u) {
|
||||
outError = "SizeofResource returned zero.";
|
||||
return false;
|
||||
}
|
||||
|
||||
const void* lockedBytes = LockResource(resourceData);
|
||||
if (lockedBytes == nullptr) {
|
||||
outError = "LockResource failed.";
|
||||
return false;
|
||||
}
|
||||
|
||||
outData = reinterpret_cast<const std::uint8_t*>(lockedBytes);
|
||||
outSize = static_cast<std::size_t>(resourceSize);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool LoadEmbeddedPngTexture(
|
||||
Host::NativeRenderer& renderer,
|
||||
UINT resourceId,
|
||||
::XCEngine::UI::UITextureHandle& outTexture,
|
||||
std::string& outError) {
|
||||
const std::uint8_t* bytes = nullptr;
|
||||
std::size_t byteCount = 0u;
|
||||
if (!LoadEmbeddedPngBytes(resourceId, bytes, byteCount, outError)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return renderer.LoadTextureFromMemory(bytes, byteCount, outTexture, outError);
|
||||
}
|
||||
|
||||
} // namespace XCEngine::UI::Editor::Support
|
||||
Reference in New Issue
Block a user