Icon integration

This commit is contained in:
Jack Andersen 2016-01-18 13:33:23 -10:00
parent 334a7875c1
commit 9f08984d1f
10 changed files with 236 additions and 23 deletions

View File

@ -1,6 +1,7 @@
#include "Space.hpp" #include "Space.hpp"
#include "ViewManager.hpp" #include "ViewManager.hpp"
#include "ResourceBrowser.hpp" #include "ResourceBrowser.hpp"
#include "icons/icons.hpp"
namespace URDE namespace URDE
{ {
@ -19,8 +20,11 @@ Specter::View* Space::buildSpaceView(Specter::ViewResources& res)
m_spaceView->setContentView(sview); m_spaceView->setContentView(sview);
Specter::Toolbar& tb = *m_spaceView->toolbar(); Specter::Toolbar& tb = *m_spaceView->toolbar();
const std::string* classStr = SpaceMenuNode::lookupClassString(m_class); const std::string* classStr = SpaceMenuNode::lookupClassString(m_class);
m_spaceSelectButton.reset(new Specter::Button(res, tb, &m_spaceSelectBind, Specter::Icon* classIcon = SpaceMenuNode::lookupClassIcon(m_class);
classStr?*classStr:"Unknown Class")); const Zeus::CColor* classColor = SpaceMenuNode::lookupClassColor(m_class);
m_spaceSelectButton.reset(new Specter::Button(res, tb, &m_spaceSelectBind, "", classIcon,
Specter::Button::Style::Block,
classColor?*classColor:Zeus::CColor::skWhite));
tb.push_back(m_spaceSelectButton.get()); tb.push_back(m_spaceSelectButton.get());
buildToolbarView(res, tb); buildToolbarView(res, tb);
return m_spaceView.get(); return m_spaceView.get();
@ -36,7 +40,7 @@ Specter::View* Space::buildSpaceView(Specter::ViewResources& res)
std::vector<Space::SpaceMenuNode::SubNodeData> Space::SpaceMenuNode::s_subNodeDats = std::vector<Space::SpaceMenuNode::SubNodeData> Space::SpaceMenuNode::s_subNodeDats =
{ {
{Class::ResourceBrowser, "resource_browser", "Resource Browser"} {Class::ResourceBrowser, "resource_browser", "Resource Browser", GetIcon(SpaceIcon::ResourceBrowser), {0.0,1.0,0.0,1.0}}
}; };
std::string Space::SpaceMenuNode::s_text = "Space Types"; std::string Space::SpaceMenuNode::s_text = "Space Types";

View File

@ -46,11 +46,13 @@ public:
Class m_cls; Class m_cls;
std::string m_key; std::string m_key;
std::string m_text; std::string m_text;
Specter::Icon& m_icon;
Zeus::CColor m_color;
const std::string* text() const {return &m_text;} const std::string* text() const {return &m_text;}
void activated(const boo::SWindowCoord& coord) {} void activated(const boo::SWindowCoord& coord) {}
SubNodeData(Class cls, const char* key, const char* text) SubNodeData(Class cls, const char* key, const char* text, Specter::Icon& icon, const Zeus::CColor& color)
: m_cls(cls), m_key(key), m_text(text) {} : m_cls(cls), m_key(key), m_text(text), m_icon(icon), m_color(color) {}
}; };
static std::vector<SubNodeData> s_subNodeDats; static std::vector<SubNodeData> s_subNodeDats;
@ -86,6 +88,20 @@ public:
return &sn.m_text; return &sn.m_text;
return nullptr; return nullptr;
} }
static Specter::Icon* lookupClassIcon(Class cls)
{
for (SubNodeData& sn : s_subNodeDats)
if (sn.m_cls == cls)
return &sn.m_icon;
return nullptr;
}
static const Zeus::CColor* lookupClassColor(Class cls)
{
for (SubNodeData& sn : s_subNodeDats)
if (sn.m_cls == cls)
return &sn.m_color;
return nullptr;
}
} m_spaceMenuNode; } m_spaceMenuNode;
struct SpaceSelectBind : Specter::IButtonBinding struct SpaceSelectBind : Specter::IButtonBinding

View File

@ -4,6 +4,7 @@
#include "SplashScreen.hpp" #include "SplashScreen.hpp"
#include "locale/locale.hpp" #include "locale/locale.hpp"
#include "ResourceBrowser.hpp" #include "ResourceBrowser.hpp"
#include "icons/icons.hpp"
#include <cstdio> #include <cstdio>
using YAMLNode = Athena::io::YAMLNode; using YAMLNode = Athena::io::YAMLNode;
@ -158,6 +159,7 @@ void ViewManager::init(boo::IApplication* app)
boo::IGraphicsDataFactory* gf = m_mainWindow->getMainContextDataFactory(); boo::IGraphicsDataFactory* gf = m_mainWindow->getMainContextDataFactory();
m_viewResources.init(gf, &m_fontCache, &m_themeData, pixelFactor); m_viewResources.init(gf, &m_fontCache, &m_themeData, pixelFactor);
m_iconsToken = InitializeIcons(m_viewResources);
m_viewResources.prepFontCacheAsync(m_mainWindow.get()); m_viewResources.prepFontCacheAsync(m_mainWindow.get());
Specter::RootView* root = SetupRootView(); Specter::RootView* root = SetupRootView();
m_showSplash = true; m_showSplash = true;

View File

@ -21,6 +21,7 @@ class ViewManager : public Specter::IViewManager
Specter::FontCache m_fontCache; Specter::FontCache m_fontCache;
Specter::DefaultThemeData m_themeData; Specter::DefaultThemeData m_themeData;
Specter::ViewResources m_viewResources; Specter::ViewResources m_viewResources;
boo::GraphicsDataToken m_iconsToken;
Specter::Translator m_translator; Specter::Translator m_translator;
std::unique_ptr<boo::IWindow> m_mainWindow; std::unique_ptr<boo::IWindow> m_mainWindow;

View File

@ -0,0 +1,88 @@
#include "icons.hpp"
#include "Athena/MemoryReader.hpp"
#include <zlib.h>
extern "C" uint8_t URDE_ICONS[];
extern "C" size_t URDE_ICONS_SZ;
namespace URDE
{
static LogVisor::LogModule Log("URDE::icons");
Specter::IconAtlas<8,8> g_IconAtlas;
boo::GraphicsDataToken InitializeIcons(Specter::ViewResources& viewRes)
{
Athena::io::MemoryReader r(URDE_ICONS, URDE_ICONS_SZ);
size_t fmt = r.readUint32Big();
if (fmt != 16)
Log.report(LogVisor::FatalError, "incorrect icon texture format");
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)
Log.report(LogVisor::FatalError, "unable to decompress icons");
g_IconAtlas.initializeAtlas(viewRes.m_factory->newStaticTexture(width, height, mips, boo::TextureFormat::RGBA8,
std::move(texels), destSz));
return viewRes.m_factory->commit();
}
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);
}
}
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);
}
}
}

View File

@ -0,0 +1,43 @@
#ifndef URDE_ICONS_HPP
#define URDE_ICONS_HPP
#include "Specter/Icon.hpp"
#include "Specter/ViewResources.hpp"
namespace URDE
{
boo::GraphicsDataToken InitializeIcons(Specter::ViewResources& viewRes);
enum class SpaceIcon
{
ResourceBrowser,
ParticleEditor,
WorldEditor,
InformationCenter
};
Specter::Icon& GetIcon(SpaceIcon icon);
enum class MonoIcon
{
Sync,
Edit,
Caution,
Save,
Filter,
Document,
ZoomOut,
ZoomIn,
Exclaim,
Clock,
Gamepad,
Unlink,
Link,
Folder,
Info
};
Specter::Icon& GetIcon(MonoIcon icon);
}
#endif // URDE_ICONS_HPP

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 37 KiB

After

Width:  |  Height:  |  Size: 42 KiB

View File

@ -137,9 +137,13 @@ int main(int argc, char* argv[])
return 1; return 1;
} }
size_t decompSz = 0;
int numMips = 0; int numMips = 0;
for (int i=512 ; i>=1 ; i/=2) for (int i=512 ; i>=1 ; i/=2)
{
decompSz += i*i*4;
++numMips; ++numMips;
}
z_stream z = {0}; z_stream z = {0};
size_t rowSz = 0; size_t rowSz = 0;
@ -282,10 +286,12 @@ int main(int argc, char* argv[])
uint16_t w = _bswap16(width); uint16_t w = _bswap16(width);
uint16_t h = _bswap16(height); uint16_t h = _bswap16(height);
uint32_t mips = _bswap32(numMips); uint32_t mips = _bswap32(numMips);
uint32_t dsz = _bswap32(decompSz);
fwrite(&fmt, 1, 4, ofp); fwrite(&fmt, 1, 4, ofp);
fwrite(&w, 1, 2, ofp); fwrite(&w, 1, 2, ofp);
fwrite(&h, 1, 2, ofp); fwrite(&h, 1, 2, ofp);
fwrite(&mips, 1, 4, ofp); fwrite(&mips, 1, 4, ofp);
fwrite(&dsz, 1, 4, ofp);
rowSz = width*4; rowSz = width*4;
rowSzC = compressBound(rowSz); rowSzC = compressBound(rowSz);
@ -299,11 +305,14 @@ int main(int argc, char* argv[])
png_read_row(pngRead, row, NULL); png_read_row(pngRead, row, NULL);
z.next_in = row; z.next_in = row;
z.avail_in = rowSz; z.avail_in = rowSz;
z.next_out = rowC; while (z.avail_in)
z.avail_out = rowSzC; {
z.total_out = 0; z.next_out = rowC;
deflate(&z, Z_NO_FLUSH); z.avail_out = rowSzC;
fwrite(rowC, 1, z.total_out, ofp); z.total_out = 0;
deflate(&z, Z_NO_FLUSH);
fwrite(rowC, 1, z.total_out, ofp);
}
} }
rowSz /= 2; rowSz /= 2;

2
hecl

@ -1 +1 @@
Subproject commit 7978e31e6fbbbd45915c2684ee0fb1a376020255 Subproject commit 30dd74476e59bcba3717dddb9ead6a26523d3a39

@ -1 +1 @@
Subproject commit cd54225b2af5cd2978b0ad3fab10561693fc54b2 Subproject commit 5ee63587e2f7c2b7b015ff9e1752606b3f5fe3cd