[vlc-commits] commit: skins2: refactor some code (Erwan Tulou )
git at videolan.org
git at videolan.org
Sun Jan 16 23:05:51 CET 2011
vlc | branch: master | Erwan Tulou <erwan10 at videolan.org> | Sat Jan 15 22:11:53 2011 +0100| [bc83704fd5f9ec32fcefe55e753d9dad2f44d12b] | committer: Erwan Tulou
skins2: refactor some code
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=bc83704fd5f9ec32fcefe55e753d9dad2f44d12b
---
modules/gui/skins2/controls/ctrl_tree.cpp | 53 +++--------------------------
modules/gui/skins2/controls/ctrl_tree.hpp | 5 ---
modules/gui/skins2/utils/var_tree.cpp | 17 +++++++++
modules/gui/skins2/utils/var_tree.hpp | 3 ++
4 files changed, 25 insertions(+), 53 deletions(-)
diff --git a/modules/gui/skins2/controls/ctrl_tree.cpp b/modules/gui/skins2/controls/ctrl_tree.cpp
index 2ea7482..4f538e1 100644
--- a/modules/gui/skins2/controls/ctrl_tree.cpp
+++ b/modules/gui/skins2/controls/ctrl_tree.cpp
@@ -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 );
-}
+ int firstPosIndex = m_rTree.getRank( m_firstPos, m_flat) - 1;
+ int focusItemIndex = m_rTree.getRank( item, m_flat) - 1;
-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;
-
-
- 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++;
}
}
diff --git a/modules/gui/skins2/controls/ctrl_tree.hpp b/modules/gui/skins2/controls/ctrl_tree.hpp
index b3a8200..7465b97 100644
--- a/modules/gui/skins2/controls/ctrl_tree.hpp
+++ b/modules/gui/skins2/controls/ctrl_tree.hpp
@@ -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;
diff --git a/modules/gui/skins2/utils/var_tree.cpp b/modules/gui/skins2/utils/var_tree.cpp
index 9c23f62..dc51af2 100644
--- a/modules/gui/skins2/utils/var_tree.cpp
+++ b/modules/gui/skins2/utils/var_tree.cpp
@@ -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;
+}
diff --git a/modules/gui/skins2/utils/var_tree.hpp b/modules/gui/skins2/utils/var_tree.hpp
index bfda7d7..fa0af1c 100644
--- a/modules/gui/skins2/utils/var_tree.hpp
+++ b/modules/gui/skins2/utils/var_tree.hpp
@@ -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 );
More information about the vlc-commits
mailing list