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.

This commit is contained in:
dfighter1985 2012-06-06 04:10:34 +02:00
parent 7686107df8
commit 8f562baf72
6 changed files with 55 additions and 45 deletions

View file

@ -15,9 +15,10 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#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 &params)
{
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<CInterfaceGroup*>(CWidgetManager::getInstance()->getElementFromId(prop));
if(group == NULL)
group = dynamic_cast<CInterfaceGroup*>(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<CInterfaceGroup*>(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);
}

View file

@ -17,10 +17,7 @@
// ----------------------------------------------------------------------------
#include "stdpch.h"
#include "ctrl_tooltip.h"
#include "interface_manager.h"
#include "nel/misc/xml_auto_ptr.h"
// ----------------------------------------------------------------------------

View file

@ -26,7 +26,6 @@ namespace NLGUI
{
class CEventDescriptor;
}
class CInterfaceManager;
/**
* \author Matthieu 'Mr TRAP' Besson

View file

@ -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<CInterfaceGroup*>::const_iterator itg;
for (itg = _ChildrenGroups.begin() ; itg != _ChildrenGroups.end(); itg++)
{
CInterfaceGroup *pIG = *itg;
pIG->invalidateTexts(resetTextIndex);
}
for (vector<CViewBase*>::const_iterator itv = _Views.begin() ; itv != _Views.end(); itv++)
{
CViewBase *pVB = *itv;
CViewText *pVT = dynamic_cast<CViewText*>(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)

View file

@ -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);

View file

@ -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<CInterfaceGroup*> &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 );
}
}
}