From a27305e295014dd4884a0e73d014d4775cb3f761 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Wed, 6 Jun 2012 04:10:34 +0200 Subject: [PATCH] CHANGED: #1471 CInterfaceGroup::InvalidateTexts is now implemented with a visitor, method removed. Also added CInterfaceGroup::visitGroupAndChildren, that only visits the group and it's sub-groups. --HG-- branch : gui-refactoring --- .../client/src/interface_v3/ctrl_scroll.cpp | 15 ++------ .../client/src/interface_v3/ctrl_tooltip.cpp | 3 -- .../client/src/interface_v3/ctrl_tooltip.h | 1 - .../src/interface_v3/interface_group.cpp | 37 +++++++----------- .../client/src/interface_v3/interface_group.h | 6 ++- .../src/interface_v3/interface_manager.cpp | 38 +++++++++++++++++-- 6 files changed, 55 insertions(+), 45 deletions(-) diff --git a/code/ryzom/client/src/interface_v3/ctrl_scroll.cpp b/code/ryzom/client/src/interface_v3/ctrl_scroll.cpp index f537561b0..da37c6764 100644 --- a/code/ryzom/client/src/interface_v3/ctrl_scroll.cpp +++ b/code/ryzom/client/src/interface_v3/ctrl_scroll.cpp @@ -15,9 +15,10 @@ // along with this program. If not, see . - -#include "stdpch.h" +/* +#include "stdpch.h"*/ #include "interface_manager.h" +#include "widget_manager.h" #include "ctrl_scroll.h" #include "nel/misc/xml_auto_ptr.h" #include "group_menu.h" @@ -68,7 +69,6 @@ void CCtrlScroll::runAH(const std::string &name, const std::string ¶ms) { if (name.empty()) return; if (_CallingAH) return; // avoid infinite loop - CInterfaceManager *pIM = CInterfaceManager::getInstance(); _CallingAH = true; CAHManager::getInstance()->runActionHandler(name, this, params); _CallingAH = false; @@ -166,7 +166,6 @@ bool CCtrlScroll::parse(xmlNodePtr node, CInterfaceGroup * parentGroup) prop = (char*) xmlGetProp( node, (xmlChar*)"target" ); if (prop) { - CInterfaceManager *pIM= CInterfaceManager::getInstance(); CInterfaceGroup *group = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(prop)); if(group == NULL) group = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(this->getId(), prop)); @@ -209,7 +208,6 @@ int CCtrlScroll::luaSetTarget(CLuaState &ls) CLuaIHM::checkArgType(ls, funcName, 1, LUA_TSTRING); std::string targetId = ls.toString(1); - CInterfaceManager *pIM= CInterfaceManager::getInstance(); CInterfaceGroup *group = dynamic_cast(CWidgetManager::getInstance()->getElementFromId(targetId)); if(group != NULL) { @@ -226,7 +224,6 @@ void CCtrlScroll::updateCoords() // update only if visible if (_Target->getActive()) { - CInterfaceManager *pIM = CInterfaceManager::getInstance(); CViewRenderer &rVR = *CViewRenderer::getInstance(); sint32 w, h; rVR.getTextureSizeFromId (_TxIdB, w, h); @@ -409,9 +406,8 @@ void CCtrlScroll::updateCoords() // ------------------------------------------------------------------------------------------------ void CCtrlScroll::draw() { - CInterfaceManager *pIM = CInterfaceManager::getInstance(); CViewRenderer &rVR = *CViewRenderer::getInstance(); - CRGBA col = pIM->getGlobalColorForContent(); + CRGBA col = CInterfaceManager::getInstance()->getGlobalColorForContent(); if (_Target) { @@ -693,7 +689,6 @@ sint32 CCtrlScroll::moveTrackY (sint32 dy) // ------------------------------------------------------------------------------------------------ void CCtrlScroll::setTextureBottomOrLeft (const std::string &txName) { - CInterfaceManager *pIM = CInterfaceManager::getInstance(); CViewRenderer &rVR = *CViewRenderer::getInstance(); _TxIdB = rVR.getTextureIdFromName(txName); } @@ -701,7 +696,6 @@ void CCtrlScroll::setTextureBottomOrLeft (const std::string &txName) // ------------------------------------------------------------------------------------------------ void CCtrlScroll::setTextureMiddle (const std::string &txName) { - CInterfaceManager *pIM = CInterfaceManager::getInstance(); CViewRenderer &rVR = *CViewRenderer::getInstance(); _TxIdM = rVR.getTextureIdFromName(txName); } @@ -709,7 +703,6 @@ void CCtrlScroll::setTextureMiddle (const std::string &txName) // ------------------------------------------------------------------------------------------------ void CCtrlScroll::setTextureTopOrRight (const std::string &txName) { - CInterfaceManager *pIM = CInterfaceManager::getInstance(); CViewRenderer &rVR = *CViewRenderer::getInstance(); _TxIdT = rVR.getTextureIdFromName(txName); } diff --git a/code/ryzom/client/src/interface_v3/ctrl_tooltip.cpp b/code/ryzom/client/src/interface_v3/ctrl_tooltip.cpp index 3d50931a5..8b17a7073 100644 --- a/code/ryzom/client/src/interface_v3/ctrl_tooltip.cpp +++ b/code/ryzom/client/src/interface_v3/ctrl_tooltip.cpp @@ -17,10 +17,7 @@ // ---------------------------------------------------------------------------- -#include "stdpch.h" - #include "ctrl_tooltip.h" -#include "interface_manager.h" #include "nel/misc/xml_auto_ptr.h" // ---------------------------------------------------------------------------- diff --git a/code/ryzom/client/src/interface_v3/ctrl_tooltip.h b/code/ryzom/client/src/interface_v3/ctrl_tooltip.h index ddd0b42c1..5564a8e5c 100644 --- a/code/ryzom/client/src/interface_v3/ctrl_tooltip.h +++ b/code/ryzom/client/src/interface_v3/ctrl_tooltip.h @@ -26,7 +26,6 @@ namespace NLGUI { class CEventDescriptor; } -class CInterfaceManager; /** * \author Matthieu 'Mr TRAP' Besson diff --git a/code/ryzom/client/src/interface_v3/interface_group.cpp b/code/ryzom/client/src/interface_v3/interface_group.cpp index 50002fc9d..ebab56ed8 100644 --- a/code/ryzom/client/src/interface_v3/interface_group.cpp +++ b/code/ryzom/client/src/interface_v3/interface_group.cpp @@ -22,7 +22,6 @@ #include "interface_group.h" #include "interface_link.h" -#include "view_text.h" #include "ctrl_scroll.h" #include "widget_manager.h" #include "group_container.h" @@ -1007,29 +1006,6 @@ void CInterfaceGroup::evalChildrenBBox(bool resizeFromChildW, bool resizeFromChi height = yMax - yMin; } -// ------------------------------------------------------------------------------------------------ -void CInterfaceGroup::invalidateTexts (bool resetTextIndex) -{ - vector::const_iterator itg; - for (itg = _ChildrenGroups.begin() ; itg != _ChildrenGroups.end(); itg++) - { - CInterfaceGroup *pIG = *itg; - pIG->invalidateTexts(resetTextIndex); - } - - for (vector::const_iterator itv = _Views.begin() ; itv != _Views.end(); itv++) - { - CViewBase *pVB = *itv; - CViewText *pVT = dynamic_cast(pVB); - if (pVT != NULL) - { - if (resetTextIndex) - pVT->resetTextIndex(); - pVT->updateTextContext (); - } - } -} - // ------------------------------------------------------------------------------------------------ CInterfaceElement* CInterfaceGroup::getElement (const std::string &id) { @@ -1716,6 +1692,19 @@ void CInterfaceGroup::visit(CInterfaceElementVisitor *visitor) CInterfaceElement::visit(visitor); } +// ------------------------------------------------------------------------------------------------ +void CInterfaceGroup::visitGroupAndChildren( CInterfaceElementVisitor *visitor ) +{ + nlassert( visitor != 0 ); + for( uint i = 0; i < _ChildrenGroups.size(); i++ ) + { + _ChildrenGroups[ i ]->visitGroupAndChildren( visitor ); + } + + visitor->visitGroup( this ); +} + + // ------------------------------------------------------------------------------------------------ void CInterfaceGroup::setUseCursor(bool use) diff --git a/code/ryzom/client/src/interface_v3/interface_group.h b/code/ryzom/client/src/interface_v3/interface_group.h index ee9357749..892fa0203 100644 --- a/code/ryzom/client/src/interface_v3/interface_group.h +++ b/code/ryzom/client/src/interface_v3/interface_group.h @@ -109,7 +109,6 @@ public: */ virtual void checkCoords(); virtual void updateCoords(); - void invalidateTexts (bool resetTextIndex); // Needed for static text to be reconstructed on screen size change /// remove all views virtual void clearViews(); @@ -272,7 +271,10 @@ public: virtual void dumpSize(uint depth = 0) const; // From CInterfaceElement - virtual void visit(CInterfaceElementVisitor *visitor); + virtual void visit(CInterfaceElementVisitor *visitor); + + /// Visits only this group's sub-groups and then the group itself + virtual void visitGroupAndChildren( CInterfaceElementVisitor *visitor ); // Check cursor void setUseCursor(bool use); diff --git a/code/ryzom/client/src/interface_v3/interface_manager.cpp b/code/ryzom/client/src/interface_v3/interface_manager.cpp index 40602c748..631dea206 100644 --- a/code/ryzom/client/src/interface_v3/interface_manager.cpp +++ b/code/ryzom/client/src/interface_v3/interface_manager.cpp @@ -3083,6 +3083,33 @@ void CInterfaceManager::moveAllWindowsToNewScreenSize(sint32 newScreenW, sint32 } } +class InvalidateTextVisitor : public CInterfaceElementVisitor +{ +public: + InvalidateTextVisitor( bool reset ) + { + this->reset = reset; + } + + void visitGroup( CInterfaceGroup *group ) + { + const std::vector< CViewBase* > &vs = group->getViews(); + for( std::vector< CViewBase* >::const_iterator itr = vs.begin(); itr != vs.end(); ++itr ) + { + CViewText *vt = dynamic_cast< CViewText* >( *itr ); + if( vt != NULL ) + { + if( reset ) + vt->resetTextIndex(); + vt->updateTextContext(); + } + } + } + +private: + bool reset; +}; + // ------------------------------------------------------------------------------------------------ void CInterfaceManager::updateAllLocalisedElements() { @@ -3114,7 +3141,9 @@ void CInterfaceManager::updateAllLocalisedElements() { CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; - rMG.Group->invalidateTexts (false); + InvalidateTextVisitor inv( false ); + + rMG.Group->visitGroupAndChildren( &inv ); rMG.Group->invalidateCoords (); for (uint8 nPriority = 0; nPriority < WIN_PRIORITY_MAX; nPriority++) { @@ -3123,7 +3152,7 @@ void CInterfaceManager::updateAllLocalisedElements() for (itw = rList.begin(); itw != rList.end(); itw++) { CInterfaceGroup *pIG = *itw; - pIG->invalidateTexts (false); + pIG->visitGroupAndChildren( &inv ); pIG->invalidateCoords (); } } @@ -4592,7 +4621,8 @@ void CInterfaceManager::resetTextIndex() { CWidgetManager::SMasterGroup &rMG = _MasterGroups[nMasterGroup]; - rMG.Group->invalidateTexts (true); + InvalidateTextVisitor inv( true ); + rMG.Group->visitGroupAndChildren( &inv ); for (uint8 nPriority = 0; nPriority < WIN_PRIORITY_MAX; nPriority++) { list &rList = rMG.PrioritizedWindows[nPriority]; @@ -4600,7 +4630,7 @@ void CInterfaceManager::resetTextIndex() for (itw = rList.begin(); itw != rList.end(); itw++) { CInterfaceGroup *pIG = *itw; - pIG->invalidateTexts (true); + pIG->visitGroupAndChildren( &inv ); } } }