From cdce85301b8cdc386fa55c991b91323361f73a28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaakko=20Ker=C3=A4nen?= Date: Mon, 3 Mar 2014 20:49:04 +0200 Subject: [PATCH] Refactor|ClientApp: Moved font related script bindings to BaseGuiApp --- doomsday/client/src/clientapp.cpp | 64 +------------------------ doomsday/libappfw/src/baseguiapp.cpp | 71 +++++++++++++++++++++++++++- 2 files changed, 72 insertions(+), 63 deletions(-) diff --git a/doomsday/client/src/clientapp.cpp b/doomsday/client/src/clientapp.cpp index 76b08c09e0..b11e114cb0 100644 --- a/doomsday/client/src/clientapp.cpp +++ b/doomsday/client/src/clientapp.cpp @@ -91,61 +91,6 @@ static Value *Function_App_GamePlugin(Context &, Function::ArgumentValues const return new TextValue(name); } -static Value *Function_App_LoadFont(Context &, Function::ArgumentValues const &args) -{ - LOG_AS("ClientApp"); - try - { - // Try to load the specific font. - Block data(App::fileSystem().root().locate(args.at(0)->asText())); - int id; - id = QFontDatabase::addApplicationFontFromData(data); - if(id < 0) - { - LOG_RES_WARNING("Failed to load font:"); - } - else - { - LOG_RES_VERBOSE("Loaded font: %s") << args.at(0)->asText(); - //qDebug() << args.at(0)->asText(); - //qDebug() << "Families:" << QFontDatabase::applicationFontFamilies(id); - } - } - catch(Error const &er) - { - LOG_RES_WARNING("Failed to load font:\n") << er.asText(); - } - return 0; -} - -static Value *Function_App_AddFontMapping(Context &, Function::ArgumentValues const &args) -{ - // arg 0: family name - // arg 1: dictionary with [Text style, Number weight] => Text fontname - - // styles: regular, italic - // weight: 0-99 (25=light, 50=normal, 75=bold) - - NativeFont::StyleMapping mapping; - - DictionaryValue const &dict = args.at(1)->as(); - DENG2_FOR_EACH_CONST(DictionaryValue::Elements, i, dict.elements()) - { - NativeFont::Spec spec; - ArrayValue const &key = i->first.value->as(); - if(key.at(0).asText() == "italic") - { - spec.style = NativeFont::Italic; - } - spec.weight = roundi(key.at(1).asNumber()); - mapping.insert(spec, i->second->asText()); - } - - NativeFont::defineMapping(args.at(0)->asText(), mapping); - - return 0; -} - static Value *Function_App_Quit(Context &, Function::ArgumentValues const &) { Sys_Quit(); @@ -319,9 +264,6 @@ ClientApp::ClientApp(int &argc, char **argv) { novideo = false; - // Override the system locale (affects number/time formatting). - QLocale::setDefault(QLocale("en_US.UTF-8")); - // Use the host system's proxy configuration. QNetworkProxyFactory::setUseSystemConfiguration(true); @@ -335,10 +277,8 @@ ClientApp::ClientApp(int &argc, char **argv) setGame(d->games.nullGame()); d->binder.init(scriptSystem().nativeModule("App")) - << DENG2_FUNC_NOARG (App_GamePlugin, "gamePlugin") - << DENG2_FUNC (App_AddFontMapping, "addFontMapping", "family" << "mappings") - << DENG2_FUNC (App_LoadFont, "loadFont", "fileName") - << DENG2_FUNC_NOARG (App_Quit, "quit"); + << DENG2_FUNC_NOARG (App_GamePlugin, "gamePlugin") + << DENG2_FUNC_NOARG (App_Quit, "quit"); } void ClientApp::initialize() diff --git a/doomsday/libappfw/src/baseguiapp.cpp b/doomsday/libappfw/src/baseguiapp.cpp index 74438a48be..8cc6a99121 100644 --- a/doomsday/libappfw/src/baseguiapp.cpp +++ b/doomsday/libappfw/src/baseguiapp.cpp @@ -19,10 +19,72 @@ #include "de/BaseGuiApp" #include "de/VRConfig" +#include +#include +#include +#include +#include + namespace de { +static Value *Function_App_LoadFont(Context &, Function::ArgumentValues const &args) +{ + LOG_AS("ClientApp"); + try + { + // Try to load the specific font. + Block data(App::fileSystem().root().locate(args.at(0)->asText())); + int id; + id = QFontDatabase::addApplicationFontFromData(data); + if(id < 0) + { + LOG_RES_WARNING("Failed to load font:"); + } + else + { + LOG_RES_VERBOSE("Loaded font: %s") << args.at(0)->asText(); + //qDebug() << args.at(0)->asText(); + //qDebug() << "Families:" << QFontDatabase::applicationFontFamilies(id); + } + } + catch(Error const &er) + { + LOG_RES_WARNING("Failed to load font:\n") << er.asText(); + } + return 0; +} + +static Value *Function_App_AddFontMapping(Context &, Function::ArgumentValues const &args) +{ + // arg 0: family name + // arg 1: dictionary with [Text style, Number weight] => Text fontname + + // styles: regular, italic + // weight: 0-99 (25=light, 50=normal, 75=bold) + + NativeFont::StyleMapping mapping; + + DictionaryValue const &dict = args.at(1)->as(); + DENG2_FOR_EACH_CONST(DictionaryValue::Elements, i, dict.elements()) + { + NativeFont::Spec spec; + ArrayValue const &key = i->first.value->as(); + if(key.at(0).asText() == "italic") + { + spec.style = NativeFont::Italic; + } + spec.weight = roundi(key.at(1).asNumber()); + mapping.insert(spec, i->second->asText()); + } + + NativeFont::defineMapping(args.at(0)->asText(), mapping); + + return 0; +} + DENG2_PIMPL_NOREF(BaseGuiApp) { + Binder binder; QScopedPointer uiState; GLShaderBank shaders; VRConfig vr; @@ -30,7 +92,14 @@ DENG2_PIMPL_NOREF(BaseGuiApp) BaseGuiApp::BaseGuiApp(int &argc, char **argv) : GuiApp(argc, argv), d(new Instance) -{} +{ + // Override the system locale (affects number/time formatting). + QLocale::setDefault(QLocale("en_US.UTF-8")); + + d->binder.init(scriptSystem().nativeModule("App")) + << DENG2_FUNC (App_AddFontMapping, "addFontMapping", "family" << "mappings") + << DENG2_FUNC (App_LoadFont, "loadFont", "fileName"); +} void BaseGuiApp::initSubsystems(SubsystemInitFlags flags) {