2016-03-04 23:03:47 +00:00
|
|
|
#include "specter/ViewResources.hpp"
|
2015-12-03 03:26:50 +00:00
|
|
|
|
2016-03-04 23:03:47 +00:00
|
|
|
namespace specter
|
2015-12-03 03:26:50 +00:00
|
|
|
{
|
2016-03-04 23:03:47 +00:00
|
|
|
static logvisor::Module Log("specter::ViewResources");
|
2015-12-03 03:26:50 +00:00
|
|
|
|
2018-05-14 03:37:01 +00:00
|
|
|
void ViewResources::init(boo::IGraphicsDataFactory* factory, FontCache* fcache, const IThemeData* theme, float pf)
|
2015-12-03 03:26:50 +00:00
|
|
|
{
|
2016-01-10 06:40:23 +00:00
|
|
|
if (!factory || !fcache || !theme)
|
2016-03-04 23:03:47 +00:00
|
|
|
Log.report(logvisor::Fatal, "all arguments of ViewResources::init() must be non-null");
|
2015-12-08 01:44:46 +00:00
|
|
|
m_pixelFactor = pf;
|
2015-12-03 03:26:50 +00:00
|
|
|
m_factory = factory;
|
2016-03-30 19:15:32 +00:00
|
|
|
m_theme = theme;
|
2015-12-04 01:35:01 +00:00
|
|
|
m_fcache = fcache;
|
2015-12-13 02:26:41 +00:00
|
|
|
unsigned dpi = 72.f * m_pixelFactor;
|
2016-03-30 19:15:32 +00:00
|
|
|
|
2018-01-10 06:18:56 +00:00
|
|
|
m_curveFont = fcache->prepCurvesFont(AllCharFilter, false, 8.f, dpi);
|
2016-03-30 19:15:32 +00:00
|
|
|
|
2018-05-25 06:39:09 +00:00
|
|
|
factory->commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) {
|
2016-03-30 19:15:32 +00:00
|
|
|
switch (ctx.platform())
|
|
|
|
{
|
2017-12-06 03:25:33 +00:00
|
|
|
#if BOO_HAS_GL
|
2016-08-24 04:35:06 +00:00
|
|
|
case boo::IGraphicsDataFactory::Platform::OpenGL:
|
2016-03-30 19:15:32 +00:00
|
|
|
init<boo::GLDataFactory::Context>(static_cast<boo::GLDataFactory::Context&>(ctx), *theme, fcache);
|
|
|
|
break;
|
2017-12-06 03:25:33 +00:00
|
|
|
#endif
|
2015-12-03 03:26:50 +00:00
|
|
|
#if _WIN32
|
2016-03-30 19:15:32 +00:00
|
|
|
case boo::IGraphicsDataFactory::Platform::D3D11:
|
2018-05-25 06:39:09 +00:00
|
|
|
init<boo::D3DDataFactory::Context>(static_cast<boo::D3DDataFactory::Context&>(ctx), *theme, fcache);
|
2016-03-30 19:15:32 +00:00
|
|
|
break;
|
2016-02-23 02:33:59 +00:00
|
|
|
#endif
|
|
|
|
#if BOO_HAS_METAL
|
2016-03-30 19:15:32 +00:00
|
|
|
case boo::IGraphicsDataFactory::Platform::Metal:
|
|
|
|
init<boo::MetalDataFactory::Context>(static_cast<boo::MetalDataFactory::Context&>(ctx), *theme, fcache);
|
|
|
|
break;
|
2016-02-23 02:33:59 +00:00
|
|
|
#endif
|
|
|
|
#if BOO_HAS_VULKAN
|
2016-03-30 19:15:32 +00:00
|
|
|
case boo::IGraphicsDataFactory::Platform::Vulkan:
|
|
|
|
init<boo::VulkanDataFactory::Context>(static_cast<boo::VulkanDataFactory::Context&>(ctx), *theme, fcache);
|
|
|
|
break;
|
2015-12-03 03:26:50 +00:00
|
|
|
#endif
|
2016-03-30 19:15:32 +00:00
|
|
|
default:
|
|
|
|
Log.report(logvisor::Fatal, _S("unable to init view system for %s"), ctx.platformName());
|
|
|
|
}
|
|
|
|
return true;
|
2018-05-25 06:39:09 +00:00
|
|
|
} BooTrace);
|
2015-12-03 03:26:50 +00:00
|
|
|
}
|
|
|
|
|
2017-11-05 06:16:45 +00:00
|
|
|
void ViewResources::destroyResData()
|
|
|
|
{
|
|
|
|
m_viewRes.destroy();
|
|
|
|
m_textRes.destroy();
|
|
|
|
m_splitRes.destroy();
|
|
|
|
m_toolbarRes.destroy();
|
|
|
|
m_buttonRes.destroy();
|
|
|
|
}
|
|
|
|
|
2015-12-13 02:26:41 +00:00
|
|
|
void ViewResources::prepFontCacheSync()
|
2015-12-04 01:35:01 +00:00
|
|
|
{
|
2015-12-13 02:26:41 +00:00
|
|
|
unsigned dpi = 72.f * m_pixelFactor;
|
2018-06-02 00:03:08 +00:00
|
|
|
if (m_fcacheInterrupt.load())
|
2018-05-14 03:37:01 +00:00
|
|
|
return;
|
2018-01-10 06:18:56 +00:00
|
|
|
m_mainFont = m_fcache->prepMainFont(AllCharFilter, false, 10.f, dpi);
|
2018-06-02 00:03:08 +00:00
|
|
|
if (m_fcacheInterrupt.load())
|
2018-05-14 03:37:01 +00:00
|
|
|
return;
|
|
|
|
m_monoFont10 = m_fcache->prepMonoFont(AllCharFilter, false, 10.f, dpi);
|
2018-06-02 00:03:08 +00:00
|
|
|
if (m_fcacheInterrupt.load())
|
2018-05-14 03:37:01 +00:00
|
|
|
return;
|
|
|
|
m_monoFont18 = m_fcache->prepMonoFont(AllCharFilter, false, 18.f, dpi);
|
2018-06-02 00:03:08 +00:00
|
|
|
if (m_fcacheInterrupt.load())
|
2018-05-14 03:37:01 +00:00
|
|
|
return;
|
2018-01-10 06:18:56 +00:00
|
|
|
m_heading14 = m_fcache->prepMainFont(LatinAndJapaneseCharFilter, false, 14.f, dpi);
|
2018-06-02 00:03:08 +00:00
|
|
|
if (m_fcacheInterrupt.load())
|
2018-05-14 03:37:01 +00:00
|
|
|
return;
|
2018-01-10 06:18:56 +00:00
|
|
|
m_heading18 = m_fcache->prepMainFont(LatinAndJapaneseCharFilter, false, 18.f, dpi);
|
2018-06-02 00:03:08 +00:00
|
|
|
if (m_fcacheInterrupt.load())
|
2018-05-14 03:37:01 +00:00
|
|
|
return;
|
2018-01-10 06:18:56 +00:00
|
|
|
m_titleFont = m_fcache->prepMainFont(LatinCharFilter, false, 36.f, dpi);
|
2018-06-02 00:03:08 +00:00
|
|
|
if (m_fcacheInterrupt.load())
|
2018-05-14 03:37:01 +00:00
|
|
|
return;
|
2015-12-04 01:35:01 +00:00
|
|
|
m_fcache->closeBuiltinFonts();
|
2018-06-02 00:03:08 +00:00
|
|
|
m_fcacheReady.store(true);
|
2015-12-13 02:26:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewResources::prepFontCacheAsync(boo::IWindow* window)
|
|
|
|
{
|
2018-06-02 00:03:08 +00:00
|
|
|
m_fcacheReady.store(false);
|
2018-05-25 06:39:09 +00:00
|
|
|
m_fcacheThread = std::thread([this]() { prepFontCacheSync(); });
|
2015-12-13 02:26:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ViewResources::resetPixelFactor(float pf)
|
|
|
|
{
|
|
|
|
m_pixelFactor = pf;
|
|
|
|
unsigned dpi = 72.f * m_pixelFactor;
|
2018-01-10 06:18:56 +00:00
|
|
|
m_curveFont = m_fcache->prepCurvesFont(AllCharFilter, false, 8.f, dpi);
|
2015-12-13 02:26:41 +00:00
|
|
|
prepFontCacheSync();
|
2015-12-04 01:35:01 +00:00
|
|
|
}
|
|
|
|
|
2018-05-14 03:37:01 +00:00
|
|
|
void ViewResources::resetTheme(const IThemeData* theme) { m_theme = theme; }
|
2015-12-04 01:35:01 +00:00
|
|
|
|
2018-05-14 03:37:01 +00:00
|
|
|
} // namespace specter
|