metaforce/Editor/icons/icons.cpp

95 lines
2.8 KiB
C++
Raw Normal View History

2016-01-18 23:33:23 +00:00
#include "icons.hpp"
2016-03-04 23:04:53 +00:00
#include "athena/MemoryReader.hpp"
2016-01-18 23:33:23 +00:00
#include <zlib.h>
extern "C" uint8_t URDE_ICONS[];
extern "C" size_t URDE_ICONS_SZ;
2018-12-08 05:30:43 +00:00
namespace urde {
2016-03-04 23:04:53 +00:00
static logvisor::Module Log("URDE::icons");
2016-01-18 23:33:23 +00:00
2018-12-08 05:30:43 +00:00
specter::IconAtlas<8, 8> g_IconAtlas;
2016-01-18 23:33:23 +00:00
2018-12-08 05:30:43 +00:00
void InitializeIcons(specter::ViewResources& viewRes) {
athena::io::MemoryReader r(URDE_ICONS, URDE_ICONS_SZ);
size_t fmt = r.readUint32Big();
if (fmt != 16)
2020-04-11 22:51:39 +00:00
Log.report(logvisor::Fatal, FMT_STRING("incorrect icon texture format"));
2018-12-08 05:30:43 +00:00
size_t width = r.readUint16Big();
size_t height = r.readUint16Big();
size_t mips = r.readUint32Big();
size_t decompSz = r.readUint32Big();
2016-01-18 23:33:23 +00:00
2018-12-08 05:30:43 +00:00
std::unique_ptr<uint8_t[]> texels(new uint8_t[decompSz]);
uLongf destSz = decompSz;
size_t pos = r.position();
if (uncompress(texels.get(), &destSz, URDE_ICONS + pos, URDE_ICONS_SZ - pos) != Z_OK)
2020-04-11 22:51:39 +00:00
Log.report(logvisor::Fatal, FMT_STRING("unable to decompress icons"));
2016-01-18 23:33:23 +00:00
2018-12-08 05:30:43 +00:00
viewRes.m_factory->commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) {
g_IconAtlas.initializeAtlas(ctx.newStaticTexture(width, height, mips, boo::TextureFormat::RGBA8,
boo::TextureClampMode::Repeat, texels.get(), destSz));
return true;
} BooTrace);
2016-01-18 23:33:23 +00:00
}
2018-12-08 05:30:43 +00:00
void DestroyIcons() { g_IconAtlas.destroyAtlas(); }
2018-12-08 05:30:43 +00:00
specter::Icon& GetIcon(SpaceIcon icon) {
switch (icon) {
case SpaceIcon::ResourceBrowser:
return g_IconAtlas.getIcon(0, 0);
case SpaceIcon::ParticleEditor:
return g_IconAtlas.getIcon(0, 1);
case SpaceIcon::WorldEditor:
return g_IconAtlas.getIcon(0, 2);
case SpaceIcon::InformationCenter:
return g_IconAtlas.getIcon(0, 3);
case SpaceIcon::ModelViewer:
return g_IconAtlas.getIcon(0, 4);
case SpaceIcon::GameMode:
return g_IconAtlas.getIcon(0, 5);
default:
return g_IconAtlas.getIcon(6, 0);
}
2016-01-18 23:33:23 +00:00
}
2018-12-08 05:30:43 +00:00
specter::Icon& GetIcon(MonoIcon icon) {
switch (icon) {
case MonoIcon::Sync:
return g_IconAtlas.getIcon(7, 0);
case MonoIcon::Edit:
return g_IconAtlas.getIcon(7, 1);
case MonoIcon::Caution:
return g_IconAtlas.getIcon(7, 2);
case MonoIcon::Save:
return g_IconAtlas.getIcon(7, 3);
case MonoIcon::Filter:
return g_IconAtlas.getIcon(7, 4);
case MonoIcon::Document:
return g_IconAtlas.getIcon(7, 5);
case MonoIcon::ZoomOut:
return g_IconAtlas.getIcon(7, 6);
case MonoIcon::ZoomIn:
return g_IconAtlas.getIcon(7, 7);
case MonoIcon::Exclaim:
return g_IconAtlas.getIcon(6, 0);
case MonoIcon::Clock:
return g_IconAtlas.getIcon(6, 1);
case MonoIcon::Gamepad:
return g_IconAtlas.getIcon(6, 2);
case MonoIcon::Unlink:
return g_IconAtlas.getIcon(6, 3);
case MonoIcon::Link:
return g_IconAtlas.getIcon(6, 4);
case MonoIcon::Folder:
return g_IconAtlas.getIcon(6, 5);
case MonoIcon::Info:
return g_IconAtlas.getIcon(6, 6);
default:
return g_IconAtlas.getIcon(6, 0);
}
2016-01-18 23:33:23 +00:00
}
2018-12-08 05:30:43 +00:00
} // namespace urde