2016-03-04 23:03:47 +00:00
|
|
|
#include "specter/ViewResources.hpp"
|
2015-12-03 03:26:50 +00:00
|
|
|
|
2018-12-08 05:24:02 +00:00
|
|
|
namespace specter {
|
2016-03-04 23:03:47 +00:00
|
|
|
static logvisor::Module Log("specter::ViewResources");
|
2015-12-03 03:26:50 +00:00
|
|
|
|
2018-12-08 05:24:02 +00:00
|
|
|
void ViewResources::init(boo::IGraphicsDataFactory* factory, FontCache* fcache, const IThemeData* theme, float pf) {
|
|
|
|
if (!factory || !fcache || !theme)
|
|
|
|
Log.report(logvisor::Fatal, "all arguments of ViewResources::init() must be non-null");
|
|
|
|
m_pixelFactor = pf;
|
|
|
|
m_factory = factory;
|
|
|
|
m_theme = theme;
|
|
|
|
m_fcache = fcache;
|
|
|
|
unsigned dpi = 72.f * m_pixelFactor;
|
2016-03-30 19:15:32 +00:00
|
|
|
|
2018-12-08 05:24:02 +00:00
|
|
|
m_curveFont = fcache->prepCurvesFont(AllCharFilter, false, 8.f, dpi);
|
2016-03-30 19:15:32 +00:00
|
|
|
|
2018-12-08 05:24:02 +00:00
|
|
|
factory->commitTransaction([&](boo::IGraphicsDataFactory::Context& ctx) {
|
|
|
|
init(ctx, *theme, fcache);
|
|
|
|
return true;
|
|
|
|
} BooTrace);
|
2015-12-03 03:26:50 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:24:02 +00:00
|
|
|
void ViewResources::destroyResData() {
|
|
|
|
m_viewRes.destroy();
|
|
|
|
m_textRes.destroy();
|
|
|
|
m_splitRes.destroy();
|
|
|
|
m_toolbarRes.destroy();
|
|
|
|
m_buttonRes.destroy();
|
2017-11-05 06:16:45 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:24:02 +00:00
|
|
|
void ViewResources::prepFontCacheSync() {
|
|
|
|
unsigned dpi = 72.f * m_pixelFactor;
|
|
|
|
if (m_fcacheInterrupt.load())
|
|
|
|
return;
|
|
|
|
m_mainFont = m_fcache->prepMainFont(AllCharFilter, false, 10.f, dpi);
|
|
|
|
if (m_fcacheInterrupt.load())
|
|
|
|
return;
|
|
|
|
m_monoFont10 = m_fcache->prepMonoFont(AllCharFilter, false, 10.f, dpi);
|
|
|
|
if (m_fcacheInterrupt.load())
|
|
|
|
return;
|
|
|
|
m_monoFont18 = m_fcache->prepMonoFont(AllCharFilter, false, 18.f, dpi);
|
|
|
|
if (m_fcacheInterrupt.load())
|
|
|
|
return;
|
|
|
|
m_heading14 = m_fcache->prepMainFont(LatinAndJapaneseCharFilter, false, 14.f, dpi);
|
|
|
|
if (m_fcacheInterrupt.load())
|
|
|
|
return;
|
|
|
|
m_heading18 = m_fcache->prepMainFont(LatinAndJapaneseCharFilter, false, 18.f, dpi);
|
|
|
|
if (m_fcacheInterrupt.load())
|
|
|
|
return;
|
|
|
|
m_titleFont = m_fcache->prepMainFont(LatinCharFilter, false, 36.f, dpi);
|
|
|
|
if (m_fcacheInterrupt.load())
|
|
|
|
return;
|
|
|
|
m_fcache->closeBuiltinFonts();
|
|
|
|
m_fcacheReady.store(true);
|
2015-12-13 02:26:41 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:24:02 +00:00
|
|
|
void ViewResources::prepFontCacheAsync(boo::IWindow* window) {
|
|
|
|
m_fcacheReady.store(false);
|
|
|
|
m_fcacheThread = std::thread([this]() { prepFontCacheSync(); });
|
2015-12-13 02:26:41 +00:00
|
|
|
}
|
|
|
|
|
2018-12-08 05:24:02 +00:00
|
|
|
void ViewResources::resetPixelFactor(float pf) {
|
|
|
|
m_pixelFactor = pf;
|
|
|
|
unsigned dpi = 72.f * m_pixelFactor;
|
|
|
|
m_curveFont = m_fcache->prepCurvesFont(AllCharFilter, false, 8.f, dpi);
|
|
|
|
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
|