metaforce/specter/lib/ViewResources.cpp

81 lines
2.7 KiB
C++
Raw Normal View History

#include "Specter/ViewResources.hpp"
namespace Specter
{
static LogVisor::LogModule Log("Specter::ViewResources");
2015-12-04 01:35:01 +00:00
void ViewResources::init(boo::IGraphicsDataFactory* factory, FontCache* fcache,
const IThemeData* theme, float pf)
{
if (!factory || !fcache || !theme)
Log.report(LogVisor::FatalError, "all arguments of ViewResources::init() must be non-null");
m_pixelFactor = pf;
2015-12-04 01:35:01 +00:00
m_theme = theme;
m_factory = factory;
2015-12-04 01:35:01 +00:00
m_fcache = fcache;
unsigned dpi = 72.f * m_pixelFactor;
m_curveFont = fcache->prepCurvesFont(m_factory, AllCharFilter, false, 8.f, dpi);
switch (factory->platform())
{
case boo::IGraphicsDataFactory::Platform::OGL:
init<boo::GLDataFactory>(static_cast<boo::GLDataFactory*>(factory), *theme, fcache);
break;
#if _WIN32
case boo::IGraphicsDataFactory::Platform::D3D11:
case boo::IGraphicsDataFactory::Platform::D3D12:
init<boo::ID3DDataFactory>(static_cast<boo::ID3DDataFactory*>(factory), *theme, fcache);
break;
#elif BOO_HAS_METAL
case boo::IGraphicsDataFactory::Platform::Metal:
init<boo::MetalDataFactory>(static_cast<boo::MetalDataFactory*>(factory), *theme, fcache);
break;
#endif
default:
Log.report(LogVisor::FatalError, _S("unable to init view system for %s"), factory->platformName());
}
2015-12-05 00:42:46 +00:00
m_resData = factory->commit();
}
void ViewResources::prepFontCacheSync()
2015-12-04 01:35:01 +00:00
{
unsigned dpi = 72.f * m_pixelFactor;
2015-12-13 03:07:12 +00:00
if (m_fcacheInterrupt) return;
2015-12-04 01:35:01 +00:00
m_mainFont = m_fcache->prepMainFont(m_factory, AllCharFilter, false, 10.f, dpi);
2015-12-13 03:07:12 +00:00
if (m_fcacheInterrupt) return;
2015-12-04 01:35:01 +00:00
m_monoFont = m_fcache->prepMonoFont(m_factory, AllCharFilter, false, 10.f, dpi);
2015-12-13 03:07:12 +00:00
if (m_fcacheInterrupt) return;
2015-12-04 01:35:01 +00:00
m_heading14 = m_fcache->prepMainFont(m_factory, LatinAndJapaneseCharFilter, false, 14.f, dpi);
2015-12-13 03:07:12 +00:00
if (m_fcacheInterrupt) return;
2015-12-04 01:35:01 +00:00
m_heading18 = m_fcache->prepMainFont(m_factory, LatinAndJapaneseCharFilter, false, 18.f, dpi);
2015-12-13 03:07:12 +00:00
if (m_fcacheInterrupt) return;
m_titleFont = m_fcache->prepMainFont(m_factory, LatinCharFilter, false, 36.f, dpi);
2015-12-13 03:07:12 +00:00
if (m_fcacheInterrupt) return;
2015-12-04 01:35:01 +00:00
m_fcache->closeBuiltinFonts();
m_fcacheReady = true;
}
void ViewResources::prepFontCacheAsync(boo::IWindow* window)
{
m_fcacheReady = false;
m_fcacheThread = std::thread([this, window]()
{
window->getLoadContextDataFactory();
prepFontCacheSync();
});
}
void ViewResources::resetPixelFactor(float pf)
{
m_pixelFactor = pf;
unsigned dpi = 72.f * m_pixelFactor;
m_curveFont = m_fcache->prepCurvesFont(m_factory, AllCharFilter, false, 8.f, dpi);
prepFontCacheSync();
2015-12-04 01:35:01 +00:00
}
void ViewResources::resetTheme(const IThemeData* theme)
2015-12-04 01:35:01 +00:00
{
m_theme = theme;
}
}