metaforce/Editor/icons/icons.cpp

107 lines
3.1 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;
2016-03-05 00:03:41 +00:00
namespace urde
2016-01-18 23:33:23 +00:00
{
2016-03-04 23:04:53 +00:00
static logvisor::Module Log("URDE::icons");
2016-01-18 23:33:23 +00:00
2016-03-04 23:04:53 +00:00
specter::IconAtlas<8,8> g_IconAtlas;
2016-01-18 23:33:23 +00:00
void InitializeIcons(specter::ViewResources& viewRes)
2016-01-18 23:33:23 +00:00
{
2016-03-04 23:04:53 +00:00
athena::io::MemoryReader r(URDE_ICONS, URDE_ICONS_SZ);
2016-01-18 23:33:23 +00:00
size_t fmt = r.readUint32Big();
if (fmt != 16)
2016-03-04 23:04:53 +00:00
Log.report(logvisor::Fatal, "incorrect icon texture format");
2016-01-18 23:33:23 +00:00
size_t width = r.readUint16Big();
size_t height = r.readUint16Big();
size_t mips = r.readUint32Big();
size_t decompSz = r.readUint32Big();
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)
2016-03-04 23:04:53 +00:00
Log.report(logvisor::Fatal, "unable to decompress icons");
2016-01-18 23:33:23 +00:00
viewRes.m_factory->commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx)
2016-03-30 19:16:01 +00:00
{
g_IconAtlas.initializeAtlas(ctx.newStaticTexture(width, height, mips,
boo::TextureFormat::RGBA8,
boo::TextureClampMode::Repeat,
2016-03-30 19:16:01 +00:00
texels.get(), destSz));
return true;
} BooTrace);
2016-01-18 23:33:23 +00:00
}
void DestroyIcons()
{
g_IconAtlas.destroyAtlas();
}
2016-03-04 23:04:53 +00:00
specter::Icon& GetIcon(SpaceIcon icon)
2016-01-18 23:33:23 +00:00
{
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);
2016-02-02 08:31:05 +00:00
case SpaceIcon::ModelViewer:
return g_IconAtlas.getIcon(0, 4);
2016-12-13 02:56:43 +00:00
case SpaceIcon::GameMode:
return g_IconAtlas.getIcon(0, 5);
2016-03-08 20:29:59 +00:00
default:
return g_IconAtlas.getIcon(6, 0);
2016-01-18 23:33:23 +00:00
}
}
2016-03-04 23:04:53 +00:00
specter::Icon& GetIcon(MonoIcon icon)
2016-01-18 23:33:23 +00:00
{
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);
2016-03-08 20:29:59 +00:00
default:
return g_IconAtlas.getIcon(6, 0);
2016-01-18 23:33:23 +00:00
}
}
}