3#include "InspectorGuiHelper.h"
5#include "Resources/ResourceStore.h"
6#include "Resources/ResourceStoreStorage.h"
13void Cogs::Core::resourceStoreInspector(Context * context,
bool * show)
16 ImGui::SetNextWindowSize(ImVec2(600, 400), ImGuiCond_Once);
18 LockGuard lock(context->resourceStore->data->cache->lock);
20 std::list<std::string> keys;
21 for (
const auto & it : context->resourceStore->data->cache->resources) {
22 keys.push_back(it.first);
27 std::string windowHeader;
28 windowHeader.reserve(50);
29 windowHeader.append(
"Resources [");
30 windowHeader.append(std::to_string(keys.size()));
31 windowHeader.append(
"]");
33 guiBegin(windowHeader, show);
35 for (
const auto & key : keys) {
36 if (ImGui::TreeNode(key.c_str())) {
37 const auto & resource = context->resourceStore->data->cache->resources[key];
39 ImGui::Text(
"Name: %s", resource.name.c_str());
40 ImGui::Text(
"Path: %s", resource.path.c_str());
41 ImGui::Text(
"Size: %zu (0x%zx) bytes", resource.bytes.size(), resource.bytes.size());
43 if (ImGui::TreeNode(
"Text view")) {
45 const auto size = resource.bytes.size();
46 const auto * data =
reinterpret_cast<const char*
>(resource.bytes.data());
49 for (
size_t a = 0; a < size; ) {
51 for (; a < size; a++) {
53 else if (data[a] ==
'\n') l++;
58 for (; b < size; b++) {
59 if ((data[b] ==
'\r') || (data[b] ==
'\n'))
break;
63 ImGui::Text(
"%4d ", l);
65 ImGui::TextUnformatted(data + a, data + b);
73 if (ImGui::TreeNode(
"Hex dump")) {
74 static constexpr char tab[16] = {
75 '0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
76 '8',
'9',
'a',
'b',
'c',
'd',
'e',
'f'
79 char buf[10 + 3 * 16 + 1 + 16 + 1];
83 auto data = resource.bytes.toSpan<uint8_t>();
84 const size_t size = data.size();
86 for (
size_t o = 0; o < size; o += 16) {
87 std::memset(buf,
' ',
sizeof(buf));
89 for (
unsigned i = 0; i < 8; i++) {
90 buf[i] = tab[(o >> (24 - 4 * i)) & 0xf];
94 buf[10 + 3 * 16] =
'"';
95 buf[10 + 3 * 16 + 1 + std::min((size - o), (
size_t)16)] =
'"';
96 for (
unsigned i = 0; i < 16; i++) {
98 buf[10 + 3 * i + 0] = tab[((data[o + i] >> 4) & 0xf)];
99 buf[10 + 3 * i + 1] = tab[((data[o + i] >> 0) & 0xf)];
100 if ((33 <= data[o + i]) && (data[o + i] <= 127)) {
101 buf[10 + 3 * 16 + 1 + i] = data[o + i];
105 ImGui::TextUnformatted(buf, buf +
sizeof(buf));