Changed: Use UI scale change event to change CViewText font scale

--HG--
branch : experimental-ui-scaling
feature/pipeline-tools
Nimetu 8 years ago
parent 279f67fc2d
commit 4a722c7783

@ -38,6 +38,16 @@ namespace NLGUI
class IActionHandler;
class CGroupParagraph;
/**
* Interface for UI scale change event
*/
class IInterfaceScaleWatcher
{
public:
virtual ~IInterfaceScaleWatcher(){}
virtual void onInterfaceScaleChanged()=0;
};
/**
* A visitor to walk a tree of interface elements and apply a teartment on them.
*
@ -66,7 +76,7 @@ namespace NLGUI
* \author Nevrax France
* \date 2002
*/
class CInterfaceElement : public CReflectableRefPtrTarget, public NLMISC::IStreamable
class CInterfaceElement : public IInterfaceScaleWatcher, public CReflectableRefPtrTarget, public NLMISC::IStreamable
{
public:
@ -402,6 +412,10 @@ namespace NLGUI
*/
virtual void onInvalidateContent() {}
/* Element UI scale change event callback
*/
virtual void onInterfaceScaleChanged() {}
// called by interfaceManager for master window only
void resetInvalidCoords();

@ -70,6 +70,7 @@ namespace NLGUI
virtual void checkCoords();
virtual void updateCoords();
virtual void onAddToGroup();
virtual void onInterfaceScaleChanged();
/// From CInterfaceElement
sint32 getMaxUsedW() const;

@ -49,6 +49,7 @@ namespace NLGUI
class CProcedure;
class IEditorSelectionWatcher;
class IWidgetAdditionWatcher;
class IInterfaceScaleWatcher;
/**
GUI Widget Manager
@ -530,6 +531,11 @@ namespace NLGUI
bool unGroupSelection();
void setMultiSelection( bool b ){ multiSelection = b; }
float getInterfaceScale() const { return _InterfaceScale; }
void notifyInterfaceScaleWatchers();
void registerInterfaceScaleWatcher(IInterfaceScaleWatcher *watcher);
void unregisterInterfaceScaleWatcher(IInterfaceScaleWatcher *watcher);
bool createNewGUI( const std::string &project, const std::string &window );
private:
@ -623,6 +629,7 @@ namespace NLGUI
std::vector< IOnWidgetsDrawnHandler* > onWidgetsDrawnHandlers;
std::vector< IEditorSelectionWatcher* > selectionWatchers;
std::vector< IWidgetWatcher* > widgetWatchers;
std::vector< IInterfaceScaleWatcher* > scaleWatchers;
std::vector< std::string > editorSelection;
bool _GroupSelection;

@ -80,7 +80,7 @@ namespace NLGUI
_MultiMaxLine = 0;
_Index = 0xFFFFFFFF;
_Scale = 1.0f;
_Scale = CWidgetManager::getInstance()->getInterfaceScale();
_FontWidth= 0;
_FontHeight = 0;
_FontLegHeight = 0;
@ -113,6 +113,8 @@ namespace NLGUI
:CViewBase(param)
{
setupDefault ();
CWidgetManager::getInstance()->registerInterfaceScaleWatcher(this);
}
///constructor
@ -130,11 +132,15 @@ namespace NLGUI
_ShadowOutline = ShadowOutline;
setText(Text);
computeFontSize ();
CWidgetManager::getInstance()->registerInterfaceScaleWatcher(this);
}
// ***************************************************************************
CViewText::~CViewText()
{
CWidgetManager::getInstance()->unregisterInterfaceScaleWatcher(this);
if (_Index != 0xFFFFFFFF)
CViewRenderer::getTextContext(_FontName)->erase (_Index);
clearLines();
@ -893,9 +899,6 @@ namespace NLGUI
// ***************************************************************************
void CViewText::checkCoords ()
{
if (_Scale != CViewRenderer::getInstance()->getInterfaceScale())
invalidateContent();
if ((_MultiLine)&&(_Parent != NULL))
{
// If never setuped, and if text is not empty
@ -1840,9 +1843,6 @@ namespace NLGUI
// ***************************************************************************
void CViewText::updateTextContext ()
{
if (_Scale != CViewRenderer::getInstance()->getInterfaceScale())
computeFontSize();
NL3D::UTextContext *TextContext = CViewRenderer::getTextContext(_FontName);
TextContext->setHotSpot (UTextContext::BottomLeft);
@ -2733,10 +2733,19 @@ namespace NLGUI
}
// ***************************************************************************
void CViewText::computeFontSize ()
void CViewText::onInterfaceScaleChanged()
{
_Scale = CViewRenderer::getInstance()->getInterfaceScale();
_Scale = CWidgetManager::getInstance()->getInterfaceScale();
computeFontSize ();
invalidateContent();
CViewBase::onInterfaceScaleChanged();
}
// ***************************************************************************
void CViewText::computeFontSize ()
{
NL3D::UTextContext *TextContext = CViewRenderer::getTextContext(_FontName);
TextContext->setHotSpot (UTextContext::BottomLeft);
TextContext->setShaded (_Shadow);

@ -1850,10 +1850,9 @@ namespace NLGUI
class InvalidateTextVisitor : public CInterfaceElementVisitor
{
public:
InvalidateTextVisitor( bool reset, bool invalidate )
InvalidateTextVisitor( bool reset)
{
this->reset = reset;
this->invalidate = invalidate;
}
void visitGroup( CInterfaceGroup *group )
@ -1866,17 +1865,13 @@ namespace NLGUI
{
if( reset )
vt->resetTextIndex();
if( invalidate )
vt->invalidateContent();
else
vt->updateTextContext();
vt->updateTextContext();
}
}
}
private:
bool reset;
bool invalidate;
};
// ------------------------------------------------------------------------------------------------
@ -1889,8 +1884,6 @@ namespace NLGUI
CViewRenderer::getInstance()->checkNewScreenSize ();
CViewRenderer::getInstance()->getScreenSize (w, h);
bool scaleChanged = _InterfaceScale != CViewRenderer::getInstance()->getInterfaceScale();
// Update ui:* (limit the master containers to the height of the screen)
for (nMasterGroup = 0; nMasterGroup < _MasterGroups.size(); nMasterGroup++)
{
@ -1900,6 +1893,13 @@ namespace NLGUI
}
CViewRenderer::getInstance()->setClipWindow(0, 0, w, h);
bool scaleChanged = _InterfaceScale != CViewRenderer::getInstance()->getInterfaceScale();
if (scaleChanged)
{
_InterfaceScale = CViewRenderer::getInstance()->getInterfaceScale();
notifyInterfaceScaleWatchers();
}
// If all conditions are OK, move windows so they fit correctly with new screen size
// Do this work only InGame when Config is loaded
moveAllWindowsToNewScreenSize(w,h,true);
@ -1909,7 +1909,7 @@ namespace NLGUI
{
SMasterGroup &rMG = _MasterGroups[nMasterGroup];
InvalidateTextVisitor inv( false, scaleChanged );
InvalidateTextVisitor inv( false);
rMG.Group->visitGroupAndChildren( &inv );
rMG.Group->invalidateCoords ();
@ -3697,6 +3697,42 @@ namespace NLGUI
}
// ------------------------------------------------------------------------------------------------
void CWidgetManager::notifyInterfaceScaleWatchers()
{
std::vector< IInterfaceScaleWatcher* >::iterator itr = scaleWatchers.begin();
while( itr != scaleWatchers.end() )
{
(*itr)->onInterfaceScaleChanged();
++itr;
}
}
// ------------------------------------------------------------------------------------------------
void CWidgetManager::registerInterfaceScaleWatcher( IInterfaceScaleWatcher *watcher )
{
std::vector< IInterfaceScaleWatcher* >::const_iterator itr
= std::find( scaleWatchers.begin(), scaleWatchers.end(), watcher );
if( itr != scaleWatchers.end() )
return;
scaleWatchers.push_back( watcher );
}
// ------------------------------------------------------------------------------------------------
void CWidgetManager::unregisterInterfaceScaleWatcher( IInterfaceScaleWatcher *watcher )
{
std::vector< IInterfaceScaleWatcher* >::iterator itr
= std::find( scaleWatchers.begin(), scaleWatchers.end(), watcher );
if( itr == scaleWatchers.end() )
return;
scaleWatchers.erase( itr );
}
// ------------------------------------------------------------------------------------------------
CWidgetManager::CWidgetManager()
{
LinkHack();

Loading…
Cancel
Save