Added: Allow to set UI scale with /setuiscale command

--HG--
branch : experimental-ui-scaling
This commit is contained in:
nimetu@gmail.com 2018-03-16 15:01:22 +02:00
parent 4ba3973295
commit 0af4ea6687
5 changed files with 35 additions and 5 deletions

View file

@ -122,6 +122,8 @@
<command name="loot" action="inv_temp_all" params="" /> <command name="loot" action="inv_temp_all" params="" />
<command name="setuiscale" action="set_ui_scale" params="scale=$"/>
<!-- WebIG --> <!-- WebIG -->
<command name="go" action="browse" params="name=ui:interface:webig:content:html|url=home"/> <command name="go" action="browse" params="name=ui:interface:webig:content:html|url=home"/>
<command name="webdev" action="browse" params="name=ui:interface:webig:content:html|url=http://localhost/index.html"/> <command name="webdev" action="browse" params="name=ui:interface:webig:content:html|url=http://localhost/index.html"/>

View file

@ -839,8 +839,7 @@ void CClientConfig::setValues()
READ_FLOAT_FV(Gamma) READ_FLOAT_FV(Gamma)
// UI scaling // UI scaling
READ_FLOAT_FV(InterfaceScale); READ_FLOAT_FV(InterfaceScale);
// 50% smaller / 2x bigger clamp(ClientCfg.InterfaceScale, MIN_INTERFACE_SCALE, MAX_INTERFACE_SCALE);
clamp(ClientCfg.InterfaceScale, 0.5f, 2.0f);
READ_BOOL_FV(BilinearUI); READ_BOOL_FV(BilinearUI);
// 3D Driver // 3D Driver
varPtr = ClientCfg.ConfigFile.getVarPtr ("Driver3D"); varPtr = ClientCfg.ConfigFile.getVarPtr ("Driver3D");

View file

@ -46,6 +46,9 @@ using NLMISC::CVector;
using NLMISC::CRGBA; using NLMISC::CRGBA;
using std::string; using std::string;
// limits for UI scale
const float MIN_INTERFACE_SCALE = 0.8;
const float MAX_INTERFACE_SCALE = 2.0;
//--------------------------------------------------- //---------------------------------------------------
// CClientConfig : // CClientConfig :

View file

@ -3732,6 +3732,34 @@ class CHandlerGameConfigChangeScreenRatioCustom : public IActionHandler
}; };
REGISTER_ACTION_HANDLER (CHandlerGameConfigChangeScreenRatioCustom, "game_config_change_screen_ratio_custom"); REGISTER_ACTION_HANDLER (CHandlerGameConfigChangeScreenRatioCustom, "game_config_change_screen_ratio_custom");
// ***************************************************************************
class CHandlerSetInterfaceScale : public IActionHandler
{
virtual void execute (CCtrlBase *pCaller, const string &Params)
{
std::string s;
s = getParam(Params, "scale");
if (!s.empty()) {
float scale;
if (fromString(s, scale))
{
if (scale >= MIN_INTERFACE_SCALE && scale <= MAX_INTERFACE_SCALE)
{
ClientCfg.InterfaceScale = scale;
ClientCfg.writeDouble("InterfaceScale", ClientCfg.InterfaceScale);
ClientCfg.IsInvalidated = true;
return;
}
}
}
ucstring help("/setuiscale "+toString("%.1f .. %.1f", MIN_INTERFACE_SCALE, MAX_INTERFACE_SCALE));
CInterfaceManager::getInstance()->displaySystemInfo(help);
}
};
REGISTER_ACTION_HANDLER (CHandlerSetInterfaceScale, "set_ui_scale");
// *************************************************************************** // ***************************************************************************
class CHandlerGameMissionAbandon : public IActionHandler class CHandlerGameMissionAbandon : public IActionHandler

View file

@ -2038,8 +2038,7 @@ void CInterfaceManager::drawViews(NL3D::UCamera camera)
_CurrentPlayerCharac[i] = node ? node->getValue32() : 0; _CurrentPlayerCharac[i] = node ? node->getValue32() : 0;
} }
// update value change from ingame config window // scale must be updated right before widget manager checks it
// must update it here, right before widget manager checks it
if (_InterfaceScaleChanged) if (_InterfaceScaleChanged)
{ {
CViewRenderer::getInstance()->setInterfaceScale(_InterfaceScale); CViewRenderer::getInstance()->setInterfaceScale(_InterfaceScale);
@ -2916,7 +2915,6 @@ NLMISC_COMMAND(loadui, "Load an interface file", "<loadui [all]/interface.xml>")
return result; return result;
} }
// *************************************************************************** // ***************************************************************************
void CInterfaceManager::displayWebWindow(const string & name, const string & url) void CInterfaceManager::displayWebWindow(const string & name, const string & url)
{ {