Added: Interface auto scaling to view renderer
--HG-- branch : experimental-ui-scaling
This commit is contained in:
parent
bc98a23af3
commit
cf357edcb9
2 changed files with 76 additions and 16 deletions
|
@ -176,6 +176,12 @@ namespace NLGUI
|
|||
*/
|
||||
void getScreenOOSize (float &oow, float &ooh);
|
||||
|
||||
/*
|
||||
* UI scaling
|
||||
*/
|
||||
void setInterfaceScale(float scale, sint32 width = 0, sint32 height = 0);
|
||||
float getInterfaceScale() const { return _InterfaceScale; }
|
||||
|
||||
/*
|
||||
* is the Screen minimized?
|
||||
*/
|
||||
|
@ -526,6 +532,13 @@ namespace NLGUI
|
|||
float _OneOverScreenW, _OneOverScreenH;
|
||||
bool _IsMinimized;
|
||||
|
||||
// UI scaling
|
||||
float _InterfaceScale;
|
||||
float _InterfaceUserScale;
|
||||
sint32 _InterfaceBaseW, _InterfaceBaseH;
|
||||
sint32 _EffectiveScreenW, _EffectiveScreenH;
|
||||
|
||||
void updateInterfaceScale();
|
||||
|
||||
//map linking a uint to a bitmap. Used to display figurs
|
||||
std::vector<sint32> _IndexesToTextureIds;
|
||||
|
@ -585,14 +598,12 @@ namespace NLGUI
|
|||
static CViewRenderer *instance;
|
||||
static NL3D::UDriver *driver;
|
||||
static NL3D::UTextContext *textcontext;
|
||||
|
||||
public:
|
||||
static NL3D::UTextContext* getTextContext(){ return textcontext; }
|
||||
|
||||
/// Set of hw cursor images
|
||||
static std::set< std::string > *hwCursors;
|
||||
static float hwCursorScale;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -91,16 +91,13 @@ namespace NLGUI
|
|||
if(w!=0 && h!=0)
|
||||
{
|
||||
_IsMinimized= false;
|
||||
_ScreenW = w;
|
||||
_ScreenH = h;
|
||||
if(_ScreenW>0)
|
||||
_OneOverScreenW = 1.0f / (float)_ScreenW;
|
||||
else
|
||||
_OneOverScreenW = 1000;
|
||||
if(_ScreenH>0)
|
||||
_OneOverScreenH = 1.0f / (float)_ScreenH;
|
||||
else
|
||||
_OneOverScreenH = 1000;
|
||||
if (w != _ScreenW || h != _ScreenH)
|
||||
{
|
||||
_ScreenW = w;
|
||||
_ScreenH = h;
|
||||
|
||||
updateInterfaceScale();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -109,14 +106,48 @@ namespace NLGUI
|
|||
}
|
||||
}
|
||||
|
||||
void CViewRenderer::updateInterfaceScale()
|
||||
{
|
||||
if(_ScreenW>0)
|
||||
_OneOverScreenW = 1.0f / (float)_ScreenW;
|
||||
else
|
||||
_OneOverScreenW = 1000;
|
||||
if(_ScreenH>0)
|
||||
_OneOverScreenH = 1.0f / (float)_ScreenH;
|
||||
else
|
||||
_OneOverScreenH = 1000;
|
||||
|
||||
_InterfaceScale = _InterfaceUserScale;
|
||||
if (_InterfaceBaseW > 0 && _InterfaceBaseH > 0)
|
||||
{
|
||||
float wRatio = (float)_ScreenW / _InterfaceBaseW;
|
||||
float rRatio = (float)_ScreenH / _InterfaceBaseH;
|
||||
_InterfaceScale *= std::min(wRatio, rRatio);
|
||||
}
|
||||
|
||||
if (_InterfaceScale != 1.0f)
|
||||
{
|
||||
_OneOverScreenW *= _InterfaceScale;
|
||||
_OneOverScreenH *= _InterfaceScale;
|
||||
|
||||
_EffectiveScreenW = sint(_ScreenW / _InterfaceScale);
|
||||
_EffectiveScreenH = sint(_ScreenH / _InterfaceScale);
|
||||
}
|
||||
else
|
||||
{
|
||||
_EffectiveScreenW = _ScreenW;
|
||||
_EffectiveScreenH = _ScreenH;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* getScreenSize : get the screen window size
|
||||
*/
|
||||
void CViewRenderer::getScreenSize (uint32 &w, uint32 &h)
|
||||
{
|
||||
w = _ScreenW;
|
||||
h = _ScreenH;
|
||||
w = _EffectiveScreenW;
|
||||
h = _EffectiveScreenH;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -128,6 +159,20 @@ namespace NLGUI
|
|||
ooh= _OneOverScreenH;
|
||||
}
|
||||
|
||||
void CViewRenderer::setInterfaceScale(float scale, sint32 width/*=0*/, sint32 height/*=0*/)
|
||||
{
|
||||
// prevent #div/0
|
||||
if (sint(scale*100) > 0)
|
||||
_InterfaceUserScale = scale;
|
||||
else
|
||||
_InterfaceUserScale = 1.0f;
|
||||
|
||||
_InterfaceBaseW = width;
|
||||
_InterfaceBaseH = height;
|
||||
|
||||
updateInterfaceScale();
|
||||
}
|
||||
|
||||
void CViewRenderer::setup()
|
||||
{
|
||||
_ClipX = _ClipY = 0;
|
||||
|
@ -135,8 +180,10 @@ namespace NLGUI
|
|||
_ClipH = 600;
|
||||
_ScreenW = 800;
|
||||
_ScreenH = 600;
|
||||
_OneOverScreenW= 1.0f / (float)_ScreenW;
|
||||
_OneOverScreenH= 1.0f / (float)_ScreenH;
|
||||
_InterfaceScale = 1.0f;
|
||||
_InterfaceUserScale = 1.0f;
|
||||
_InterfaceBaseW = 0;
|
||||
_InterfaceBaseH = 0;
|
||||
_IsMinimized= false;
|
||||
_WFigurTexture= 0;
|
||||
_HFigurTexture= 0;
|
||||
|
@ -152,6 +199,8 @@ namespace NLGUI
|
|||
_EmptyLayer[i]= true;
|
||||
}
|
||||
_BlankGlobalTexture = NULL;
|
||||
|
||||
updateInterfaceScale();
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue