Commit bc83704f authored by Erwan Tulou's avatar Erwan Tulou

skins2: refactor some code

parent b630fa63
......@@ -685,43 +685,13 @@ void CtrlTree::draw( OSGraphics &rImage, int xDest, int yDest, int w, int h)
bool CtrlTree::ensureVisible( VarTree::Iterator item )
{
// Find the item to focus
int focusItemIndex = 0;
VarTree::Iterator it;
m_rTree.ensureExpanded( item );
for( it = m_flat ? m_rTree.firstLeaf() : m_rTree.begin();
it != m_rTree.end();
it = m_flat ? m_rTree.getNextLeaf( it )
: m_rTree.getNextVisibleItem( it ) )
{
if( it->getId() == item->getId() ) break;
focusItemIndex++;
}
return ensureVisible( focusItemIndex );
}
bool CtrlTree::ensureVisible( int focusItemIndex )
{
// Find m_firstPos
VarTree::Iterator it;
int firstPosIndex = 0;
for( it = m_flat ? m_rTree.firstLeaf() : m_rTree.begin();
it != m_rTree.end();
it = m_flat ? m_rTree.getNextLeaf( it )
: m_rTree.getNextVisibleItem( it ) )
{
if( it == m_firstPos ) break;
firstPosIndex++;
}
if( it == m_rTree.end() ) return false;
int firstPosIndex = m_rTree.getRank( m_firstPos, m_flat) - 1;
int focusItemIndex = m_rTree.getRank( item, m_flat) - 1;
if( it != m_rTree.end()
&& ( focusItemIndex < firstPosIndex
|| focusItemIndex > firstPosIndex + maxItems() - 1 ) )
if( focusItemIndex < firstPosIndex ||
focusItemIndex > firstPosIndex + maxItems() - 1 )
{
// Scroll to have the wanted stream visible
VarPercent &rVarPos = m_rTree.getPositionVar();
......@@ -746,22 +716,9 @@ void CtrlTree::autoScroll()
{
if( it->isPlaying() )
{
m_rTree.ensureExpanded( it );
break;
}
}
for( it = m_flat ? m_rTree.firstLeaf() : m_rTree.begin();
it != m_rTree.end();
it = m_flat ? m_rTree.getNextLeaf( it )
: m_rTree.getNextVisibleItem( it ) )
{
if( it->isPlaying() )
{
ensureVisible( playIndex );
ensureVisible( it );
break;
}
playIndex++;
}
}
......
......@@ -78,11 +78,6 @@ public:
/// \return true if it changed the position
bool ensureVisible( VarTree::Iterator item );
/// Make sure an item is visible
/// \param itemIndex the absolute index in the tree
/// \return true if it changed the position
bool ensureVisible( int itemIndex );
private:
/// Tree associated to the control
VarTree &m_rTree;
......
......@@ -421,3 +421,20 @@ void VarTree::cascadeDelete()
it->cascadeDelete();
}
}
int VarTree::getRank( Iterator item, bool flat )
{
int index = 1;
Iterator it;
for( it = flat ? firstLeaf() : begin();
it != end();
it = flat ? getNextLeaf( it ) : getNextVisibleItem( it ) )
{
if( it->isDeleted() )
continue;
if( it == item )
break;
index++;
}
return (it == item) ? index : -1;
}
......@@ -167,6 +167,9 @@ public:
/// Given an iterator to an item, return the previous leaf
Iterator getPrevLeaf( Iterator it );
/// return rank of visible item starting from 1
int getRank( Iterator it, bool flat );
/// Find a children node with the given id
Iterator findById( int id );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment