From cf357edcb9fff57b14aafbd6374ea78828d90b01 Mon Sep 17 00:00:00 2001 From: Nimetu Date: Fri, 3 Jun 2016 14:24:56 +0300 Subject: [PATCH] Added: Interface auto scaling to view renderer --HG-- branch : experimental-ui-scaling --- code/nel/include/nel/gui/view_renderer.h | 15 ++++- code/nel/src/gui/view_renderer.cpp | 77 +++++++++++++++++++----- 2 files changed, 76 insertions(+), 16 deletions(-) diff --git a/code/nel/include/nel/gui/view_renderer.h b/code/nel/include/nel/gui/view_renderer.h index a54708b04..c737037a1 100644 --- a/code/nel/include/nel/gui/view_renderer.h +++ b/code/nel/include/nel/gui/view_renderer.h @@ -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 _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; - }; diff --git a/code/nel/src/gui/view_renderer.cpp b/code/nel/src/gui/view_renderer.cpp index 0b4d837f3..b2d793e46 100644 --- a/code/nel/src/gui/view_renderer.cpp +++ b/code/nel/src/gui/view_renderer.cpp @@ -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(); }