📄 ctrl_tree.cpp
字号:
{ m_rTree.action( &*it ); } } } if( needShow ) ensureVisible( toShow ); // Redraw the control makeImage(); notifyLayout(); } else if( rEvent.getAsString().find( "mouse:left" ) != string::npos ) { EvtMouse &rEvtMouse = (EvtMouse&)rEvent; const Position *pos = getPosition(); int yPos = ( rEvtMouse.getYPos() - pos->getTop() ) / itemHeight(); int xPos = rEvtMouse.getXPos() - pos->getLeft(); VarTree::Iterator it; if( rEvent.getAsString().find( "mouse:left:down:ctrl,shift" ) != string::npos ) { VarTree::Iterator itClicked = findItemAtPos( yPos ); // Flag to know if the current item must be selected bool select = false; 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 ) ) { bool nextSelect = select; if( it == itClicked || &*it == m_pLastSelected ) { if( select ) { nextSelect = false; } else { select = true; nextSelect = true; } } it->m_selected = (*it).m_selected || select; select = nextSelect; } } else if( rEvent.getAsString().find( "mouse:left:down:ctrl" ) != string::npos ) { // Invert the selection of the item it = findItemAtPos( yPos ); if( it != m_rTree.end() ) { it->m_selected = !it->m_selected; m_pLastSelected = &*it; } } else if( rEvent.getAsString().find( "mouse:left:down:shift" ) != string::npos ) { VarTree::Iterator itClicked = findItemAtPos( yPos ); // Flag to know if the current item must be selected bool select = false; 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 ) ) { bool nextSelect = select; if( it == itClicked || &*it == m_pLastSelected ) { if( select ) { nextSelect = false; } else { select = true; nextSelect = true; } } it->m_selected = select; select = nextSelect; } } else if( rEvent.getAsString().find( "mouse:left:down" ) != string::npos ) { it = findItemAtPos(yPos); if( it != m_rTree.end() ) { if( ( it->size() && xPos > (it->depth() - 1) * itemImageWidth() && xPos < it->depth() * itemImageWidth() ) && !m_flat ) { // Fold/unfold the item it->m_expanded = !it->m_expanded; bChangedPosition = true; } else { // Unselect any previously selected item VarTree::Iterator it2; for( it2 = m_flat ? m_rTree.firstLeaf() : m_rTree.begin(); it2 != m_rTree.end(); it2 = m_flat ? m_rTree.getNextLeaf( it2 ) : m_rTree.getNextVisibleItem( it2 ) ) { it2->m_selected = false; } // Select the new item if( it != m_rTree.end() ) { it->m_selected = true; m_pLastSelected = &*it; } } } } else if( rEvent.getAsString().find( "mouse:left:dblclick" ) != string::npos ) { it = findItemAtPos(yPos); if( it != m_rTree.end() ) { // Execute the action associated to this item m_rTree.action( &*it ); } } // Redraw the control makeImage(); notifyLayout(); } else if( rEvent.getAsString().find( "scroll" ) != string::npos ) { int direction = ((EvtScroll&)rEvent).getDirection(); double percentage = m_rTree.getPositionVar().get(); double step = 2.0 / (double)( m_flat ? m_rTree.countLeafs() : m_rTree.visibleItems() ); if( direction == EvtScroll::kUp ) { percentage += step; } else { percentage -= step; } m_rTree.getPositionVar().set( percentage ); } /* We changed the nodes, let's fix teh position var */ if( bChangedPosition ) { VarTree::Iterator it; int i = 0; int iFirst = 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 ) ) { i++; if( it == m_firstPos ) { iFirst = i; break; } } iFirst += maxItems(); if( iFirst >= m_flat ? m_rTree.countLeafs() : m_rTree.visibleItems() ) iFirst = m_flat ? m_rTree.countLeafs() : m_rTree.visibleItems(); float f_new = (float)iFirst / (float)( m_flat ? m_rTree.countLeafs() :m_rTree.visibleItems() ); m_dontMove = true; m_rTree.getPositionVar().set( 1.0 - f_new ); m_dontMove = false; }}bool CtrlTree::mouseOver( int x, int y ) const{ const Position *pPos = getPosition(); return ( pPos ? x >= 0 && x <= pPos->getWidth() && y >= 0 && y <= pPos->getHeight() : false);}void CtrlTree::draw( OSGraphics &rImage, int xDest, int yDest ){ if( m_pImage ) { rImage.drawGraphics( *m_pImage, 0, 0, xDest, yDest ); }}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->m_id == item->m_id ) 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; if( it != m_rTree.end() && ( focusItemIndex < firstPosIndex || focusItemIndex > firstPosIndex + maxItems() ) ) { // Scroll to have the wanted stream visible VarPercent &rVarPos = m_rTree.getPositionVar(); rVarPos.set( 1.0 - (double)focusItemIndex / (double)( m_flat ? m_rTree.countLeafs() : m_rTree.visibleItems() ) ); return true; } return false;}void CtrlTree::autoScroll(){ // Find the current playing stream int playIndex = 0; VarTree::Iterator it; for( it = m_flat ? m_rTree.firstLeaf() : m_rTree.begin(); it != m_rTree.end(); it = m_flat ? m_rTree.getNextLeaf( it ) : m_rTree.getNextItem( it ) ) { if( it->m_playing ) { 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->m_playing ) break; playIndex++; } if( it == m_rTree.end() ) return; ensureVisible( playIndex );}void CtrlTree::makeImage(){ stats_TimerStart( getIntf(), "[Skins] Playlist image", STATS_TIMER_SKINS_PLAYTREE_IMAGE ); if( m_pImage ) { delete m_pImage; } // Get the size of the control const Position *pPos = getPosition(); if( !pPos ) { stats_TimerStop( getIntf(), STATS_TIMER_SKINS_PLAYTREE_IMAGE ); return; } int width = pPos->getWidth(); int height = pPos->getHeight(); int i_itemHeight = itemHeight(); // Create an image OSFactory *pOsFactory = OSFactory::instance( getIntf() ); m_pImage = pOsFactory->createOSGraphics( width, height ); VarTree::Iterator it = m_firstPos; if( m_pBgBitmap ) { // Draw the background bitmap ScaledBitmap bmp( getIntf(), *m_pBgBitmap, width, height ); m_pImage->drawBitmap( bmp, 0, 0 ); for( int yPos = 0; yPos < height; yPos += i_itemHeight ) { if( it != m_rTree.end() ) { if( (*it).m_selected ) { int rectHeight = __MIN( i_itemHeight, height - yPos ); m_pImage->fillRect( 0, yPos, width, rectHeight, m_selColor ); } do { it = m_flat ? m_rTree.getNextLeaf( it ) : m_rTree.getNextVisibleItem( it ); } while( it != m_rTree.end() && it->m_deleted ); } } } else { // FIXME (TRYME) // Fill background with background color uint32_t bgColor = m_bgColor1; m_pImage->fillRect( 0, 0, width, height, bgColor ); for( int yPos = 0; yPos < height; yPos += i_itemHeight ) { int rectHeight = __MIN( i_itemHeight, height - yPos ); if( it != m_rTree.end() ) { uint32_t color = ( it->m_selected ? m_selColor : bgColor ); m_pImage->fillRect( 0, yPos, width, rectHeight, color ); do { it = m_flat ? m_rTree.getNextLeaf( it ) : m_rTree.getNextVisibleItem( it ); } while( it != m_rTree.end() && it->m_deleted ); } else { m_pImage->fillRect( 0, yPos, width, rectHeight, bgColor ); } bgColor = ( bgColor == m_bgColor1 ? m_bgColor2 : m_bgColor1 ); } } int bitmapWidth = itemImageWidth(); int yPos = 0; it = m_firstPos; while( it != m_rTree.end() && yPos < height ) { const GenericBitmap *m_pCurBitmap; UString *pStr = (UString*)(it->m_cString.get()); uint32_t color = ( it->m_playing ? m_playColor : m_fgColor ); // Draw the text if( pStr != NULL ) { int depth = m_flat ? 1 : it->depth(); GenericBitmap *pText = m_rFont.drawString( *pStr, color, width - bitmapWidth * depth ); if( !pText ) { stats_TimerStop( getIntf(), STATS_TIMER_SKINS_PLAYTREE_IMAGE ); return; } if( it->size() ) m_pCurBitmap = it->m_expanded ? m_pOpenBitmap : m_pClosedBitmap; else m_pCurBitmap = m_pItemBitmap; if( m_pCurBitmap ) { // Make sure we are centered on the line int yPos2 = yPos+(i_itemHeight-m_pCurBitmap->getHeight()+1)/2; if( yPos2 >= height ) { delete pText; break; } m_pImage->drawBitmap( *m_pCurBitmap, 0, 0, bitmapWidth * (depth - 1 ), yPos2, m_pCurBitmap->getWidth(), __MIN( m_pCurBitmap->getHeight(), height - yPos2), true ); } yPos += i_itemHeight - pText->getHeight(); int ySrc = 0; if( yPos < 0 ) { ySrc = - yPos; yPos = 0; } int lineHeight = __MIN( pText->getHeight() - ySrc, height - yPos ); m_pImage->drawBitmap( *pText, 0, ySrc, bitmapWidth * depth, yPos, pText->getWidth(), lineHeight, true ); yPos += (pText->getHeight() - ySrc ); delete pText; } do { it = m_flat ? m_rTree.getNextLeaf( it ) : m_rTree.getNextVisibleItem( it ); } while( it != m_rTree.end() && it->m_deleted ); } stats_TimerStop( getIntf(), STATS_TIMER_SKINS_PLAYTREE_IMAGE );}VarTree::Iterator CtrlTree::findItemAtPos( int pos ){ // The first item is m_firstPos. // We decrement pos as we try the other items, until pos == 0. VarTree::Iterator it; for( it = m_firstPos; it != m_rTree.end() && pos != 0; it = m_flat ? m_rTree.getNextLeaf( it ) : m_rTree.getNextVisibleItem( it ) ) { pos--; } return it;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -