void CtrlGeneric::notifyLayoutMaxSize( const Box *pImg1, const Box *pImg2 ) { if( pImg1 == NULL ) { if( pImg2 == NULL ) { notifyLayout(); } else { notifyLayout( pImg2->getWidth(), pImg2->getHeight() ); } } else { if( pImg2 == NULL ) { notifyLayout( pImg1->getWidth(), pImg1->getHeight() ); } else { notifyLayout( max( pImg1->getWidth(), pImg2->getWidth() ), max( pImg1->getHeight(), pImg2->getHeight() ) ); } } }
void CtrlTree::onUpdate( Subject<VarTree, tree_update> &rTree, tree_update *arg ) { if( arg->type == arg->UpdateItem ) // Item update { if( arg->b_active_item ) autoScroll(); if( isItemVisible( arg->i_id ) ) { makeImage(); notifyLayout(); } } else if ( arg->type == arg->ResetAll ) // Global change or deletion { m_firstPos = m_flat ? m_rTree.firstLeaf() : m_rTree.begin(); makeImage(); notifyLayout(); } else if ( arg->type == arg->AppendItem ) // Item-append { if( m_flat && m_firstPos->size() ) { m_firstPos = m_rTree.getNextLeaf( m_firstPos ); makeImage(); notifyLayout(); } else if( isItemVisible( arg->i_id ) ) { makeImage(); notifyLayout(); } } else if( arg->type == arg->DeleteItem ) // item-del { /* Make sure firstPos is valid */ VarTree::Iterator it_old = m_firstPos; while( m_firstPos->isDeleted() && m_firstPos != (m_flat ? m_rTree.firstLeaf() : m_rTree.begin()) ) { m_firstPos = m_flat ? m_rTree.getPrevLeaf( m_firstPos ) : m_rTree.getPrevVisibleItem( m_firstPos ); } if( m_firstPos->isDeleted() ) m_firstPos = m_rTree.begin(); if( m_firstPos != it_old || isItemVisible( arg->i_id ) ) { makeImage(); notifyLayout(); } } }
void CtrlVideo::onUpdate( Subject<VarBool> &rVariable, void *arg ) { (void)arg; // Visibility changed if( &rVariable == m_pVisible ) { msg_Dbg( getIntf(), "VideoCtrl : Visibility changed (visible=%d)", isVisible() ); notifyLayout(); } // Active Layout changed if( &rVariable == &m_pLayout->getActiveVar() ) { msg_Dbg( getIntf(), "VideoCtrl : Active Layout changed (isActive=%d)", m_pLayout->getActiveVar().get() ); } VarBool &rFullscreen = VlcProc::instance( getIntf() )->getFullscreenVar(); if( &rVariable == &rFullscreen ) { msg_Dbg( getIntf(), "VideoCtrl : fullscreen toggled (fullscreen = %d)", rFullscreen.get() ); } if( isUseable() && !isUsed() ) { VoutManager::instance( getIntf() )->requestVout( this ); } else if( !isUseable() && isUsed() ) { VoutManager::instance( getIntf() )->discardVout( this ); } }
void CtrlSliderCursor::refreshLayout() { if( m_pImg ) { // Compute the resize factors float factorX, factorY; getResizeFactors( factorX, factorY ); notifyLayout( (int)(m_rCurve.getWidth() * factorX) + m_pImg->getWidth(), (int)(m_rCurve.getHeight() * factorY) + m_pImg->getHeight(), - m_pImg->getWidth() / 2, - m_pImg->getHeight() / 2 ); } else notifyLayout(); }
void CtrlList::onResize() { // Get the size of the control const Position *pPos = getPosition(); if( !pPos ) { return; } int height = pPos->getHeight(); // How many lines can be displayed ? int itemHeight = m_rFont.getSize() + LINE_INTERVAL; int maxItems = height / itemHeight; // Update the position variable VarPercent &rVarPos = m_rList.getPositionVar(); int excessItems = m_rList.size() - maxItems; if( excessItems > 0 ) { double newVal = 1.0 - (double)m_lastPos / excessItems; if( newVal >= 0 ) { // Change the position to keep the same first displayed item rVarPos.set( 1.0 - (double)m_lastPos / excessItems ); } else { // We cannot keep the current first item m_lastPos = excessItems; } } makeImage(); notifyLayout(); }
void CtrlTree::onUpdate( Subject<VarPercent> &rPercent, void* arg) { // Determine what is the first item to display VarTree::Iterator it = m_flat ? m_rTree.firstLeaf() : m_rTree.begin(); if( m_dontMove ) return; int excessItems; if( m_flat ) excessItems = m_rTree.countLeafs() - maxItems(); else excessItems = m_rTree.visibleItems() - maxItems(); if( excessItems > 0) { VarPercent &rVarPos = m_rTree.getPositionVar(); // a simple (int)(...) causes rounding errors ! #ifdef _MSC_VER # define lrint (int) #endif if( m_flat ) it = m_rTree.getLeaf(lrint( (1.0 - rVarPos.get()) * (double)excessItems ) + 1 ); else it = m_rTree.getVisibleItem(lrint( (1.0 - rVarPos.get()) * (double)excessItems ) + 1 ); } if( m_firstPos != it ) { // Redraw the control if the position has changed m_firstPos = it; makeImage(); notifyLayout(); } }
void CtrlList::onUpdate( Subject<VarPercent> &rPercent, void *arg ) { (void)rPercent; (void)arg; // Get the size of the control const Position *pPos = getPosition(); if( !pPos ) return; int height = pPos->getHeight(); // How many lines can be displayed ? int itemHeight = m_rFont.getSize() + LINE_INTERVAL; int maxItems = height / itemHeight; // Determine what is the first item to display VarPercent &rVarPos = m_rList.getPositionVar(); int firstItem = 0; int excessItems = m_rList.size() - maxItems; if( excessItems > 0 ) { // a simple (int)(...) causes rounding errors ! #ifdef _MSC_VER # define lrint (int) #endif firstItem = lrint( (1.0 - rVarPos.get()) * (double)excessItems ); } if( m_lastPos != firstItem ) { // Redraw the control if the position has changed m_lastPos = firstItem; makeImage(); notifyLayout(); } }
void CtrlImage::onUpdate( Subject<VarString> &rVariable, void* arg ) { (void)arg; VlcProc *pVlcProc = VlcProc::instance( getIntf() ); if( &rVariable == &pVlcProc->getStreamArtVar() ) { std::string str = ((VarString&)rVariable).get(); ArtManager* pArtManager = ArtManager::instance( getIntf() ); GenericBitmap* pArt = (GenericBitmap*) pArtManager->getArtBitmap( str ); m_pBitmap = pArt ? pArt : m_pOriginalBitmap; msg_Dbg( getIntf(), "art file %s to be displayed (wxh = %ix%i)", str.c_str(), m_pBitmap->getWidth(), m_pBitmap->getHeight() ); delete m_pImage; m_pImage = OSFactory::instance( getIntf() )->createOSGraphics( m_pBitmap->getWidth(), m_pBitmap->getHeight() ); m_pImage->drawBitmap( *m_pBitmap ); notifyLayout(); } }
void CtrlText::onUpdate( Subject<VarBool> &rVariable, void *arg ) { (void)arg; // Visibility changed if( &rVariable == m_pVisible ) { if( isVisible() ) { displayText( m_rVariable.get() ); notifyLayout( getPosition()->getWidth(), getPosition()->getHeight() ); } else { notifyLayout(); } } }
void CtrlText::onUpdate( Subject<VarText> &rVariable, void* arg ) { (void)rVariable; (void)arg; if( isVisible() ) { displayText( m_rVariable.get() ); notifyLayout( getPosition()->getWidth(), getPosition()->getHeight() ); } }
void CtrlSliderBg::onUpdate( Subject<VarPercent> &rVariable, void*arg ) { int position = (int)( m_rVariable.get() * (m_nbHoriz * m_nbVert - 1) ); if( position == m_position ) return; m_position = position; notifyLayout( m_bgWidth, m_bgHeight ); }
void CtrlText::displayText( const UString &rText ) { // Create the images ('normal' and 'double') from the text // 'Normal' image delete m_pImg; m_pImg = m_rFont.drawString( rText, m_color ); if( !m_pImg ) { return; } // 'Double' image const UString doubleStringWithSep = rText + SEPARATOR_STRING + rText; delete m_pImgDouble; m_pImgDouble = m_rFont.drawString( doubleStringWithSep, m_color ); // Update the current image used, as if the control size had changed onPositionChange(); if( m_alignment == kRight && getPosition() && getPosition()->getWidth() < m_pImg->getWidth() ) { m_xPos = getPosition()->getWidth() - m_pImg->getWidth(); } else if( m_alignment == kCenter && getPosition() && getPosition()->getWidth() < m_pImg->getWidth() ) { m_xPos = (getPosition()->getWidth() - m_pImg->getWidth()) / 2; } else { m_xPos = 0; } if( getPosition() ) { // If the control was in the moving state, check if the scrolling is // still necessary const string &rState = m_fsm.getState(); if( rState == "moving" || rState == "outMoving" ) { if( m_pImg && m_pImg->getWidth() >= getPosition()->getWidth() ) { m_pCurrImg = m_pImgDouble; m_pTimer->start( MOVING_TEXT_DELAY, false ); } else { m_pTimer->stop(); } } notifyLayout( getPosition()->getWidth(), getPosition()->getHeight() ); } }
void CtrlRadialSlider::onUpdate( Subject<VarPercent> &rVariable, void *arg ) { if( &rVariable == &m_rVariable ) { int position = (int)( m_rVariable.get() * ( m_numImg - 1 ) ); if( position == m_position ) return; m_position = position; notifyLayout( m_width, m_height ); } }
void CtrlGeneric::onUpdate( Subject<VarBool> &rVariable, void *arg ) { // Is it the visibility variable ? if( &rVariable == m_pVisible ) { // Redraw the layout notifyLayout(); } else { // Call the user-defined callback onVarBoolUpdate( (VarBool&)rVariable ); } }
void CtrlTree::onUpdate( Subject<VarTree, tree_update> &rTree, tree_update *arg ) { if( arg->i_type == 0 ) // Item update { if( arg->b_active_item ) { autoScroll(); ///\todo We should make image if we are visible in the view makeImage(); } } /// \todo handle delete in a more clever way else if ( arg->i_type == 1 ) // Global change or deletion { m_firstPos = m_flat ? m_rTree.firstLeaf() : m_rTree.begin(); makeImage(); } else if ( arg->i_type == 2 ) // Item-append { if( m_flat && m_firstPos->size() ) m_firstPos = m_rTree.getNextLeaf( m_firstPos ); /// \todo Check if the item is really visible in the view // (we only check if it in the document) if( arg->b_visible == true ) { makeImage(); } } else if( arg->i_type == 3 ) // item-del { /* Make sure firstPos and lastSelected are still valid */ while( m_firstPos->m_deleted && m_firstPos != m_rTree.root()->begin() ) { m_firstPos = m_flat ? m_rTree.getPrevLeaf( m_firstPos ) : m_rTree.getPrevVisibleItem( m_firstPos ); } if( m_firstPos->m_deleted ) m_firstPos = m_flat ? m_rTree.firstLeaf() : m_rTree.root()->begin(); if( arg->b_visible == true ) { makeImage(); } } notifyLayout(); }
void CtrlList::autoScroll() { // Get the size of the control const Position *pPos = getPosition(); if( !pPos ) { return; } int height = pPos->getHeight(); // How many lines can be displayed ? int itemHeight = m_rFont.getSize() + LINE_INTERVAL; int maxItems = height / itemHeight; // Find the current playing stream int playIndex = 0; VarList::ConstIterator it; for( it = m_rList.begin(); it != m_rList.end(); ++it ) { if( (*it).m_playing ) { break; } playIndex++; } if( it != m_rList.end() && ( playIndex < m_lastPos || playIndex >= m_lastPos + maxItems ) ) { // Scroll the list to have the playing stream visible VarPercent &rVarPos = m_rList.getPositionVar(); rVarPos.set( 1.0 - (float)playIndex / (float)m_rList.size() ); // The image will be changed by onUpdate(VarPercent&) } else { makeImage(); notifyLayout(); } }
void CtrlSliderCursor::refreshLayout( bool force ) { // Compute the position of the cursor int xPos, yPos; m_rCurve.getPoint( m_rVariable.get(), xPos, yPos ); // Compute the resize factors float factorX, factorY; getResizeFactors( factorX, factorY ); xPos = (int)(xPos * factorX); yPos = (int)(yPos * factorY); const Position *pPos = getPosition(); int x = pPos->getLeft() + xPos - m_pImg->getWidth() / 2; int y = pPos->getTop() + yPos - m_pImg->getHeight() / 2; rect region( x, y, m_pImg->getWidth(), m_pImg->getHeight() ); if( !force && region.x == m_currentCursorRect.x && region.y == m_currentCursorRect.y && region.width == m_currentCursorRect.width && region.height == m_currentCursorRect.height ) { return; } rect join; if( rect::join( m_currentCursorRect, region, &join ) ) { m_currentCursorRect = region; notifyLayout( join.width, join.height, join.x - pPos->getLeft(), join.y - pPos->getTop() ); } }
void CtrlVideo::onUpdate( Subject<VarBool> &rVariable, void *arg ) { (void)arg; VarBool &rFullscreen = VlcProc::instance( getIntf() )->getFullscreenVar(); if( &rVariable == m_pVisible ) { msg_Dbg( getIntf(), "VideoCtrl(%p) : control visibility changed (%i)", this, isVisible() ); notifyLayout(); } else if( &rVariable == &m_pLayout->getActiveVar() ) { msg_Dbg( getIntf(), "VideoCtrl(%p) : Active Layout changed (%i)", this, m_pLayout->getActiveVar().get() ); } else if( &rVariable == &getWindow()->getVisibleVar() ) { msg_Dbg( getIntf(), "VideoCtrl(%p) : Window visibility changed (%i)", this, getWindow()->getVisibleVar().get() ); } else if( &rVariable == &rFullscreen ) { msg_Dbg( getIntf(), "VideoCtrl(%p) : fullscreen toggled (%i)", this, rFullscreen.get() ); } if( isUseable() && !isUsed() ) { VoutManager::instance( getIntf() )->requestVout( this ); } else if( !isUseable() && isUsed() ) { VoutManager::instance( getIntf() )->discardVout( this ); } }
void CtrlCheckbox::onUpdate( Subject<AnimBitmap> &rBitmap, void *arg ) { notifyLayout(); }
void CtrlCheckbox::onUpdate( Subject<AnimBitmap> &rBitmap, void *arg ) { (void)rBitmap;(void)arg; notifyLayout( m_pImgCurrent->getWidth(), m_pImgCurrent->getHeight() ); }
void CtrlTree::onUpdate( Subject<VarTree, tree_update> &rTree, tree_update *arg ) { (void)rTree; if( arg->type == arg->ItemInserted ) { if( isItemVisible( arg->it ) ) { makeImage(); notifyLayout(); } setSliderFromFirst(); } else if( arg->type == arg->ItemUpdated ) { if( arg->it->isPlaying() ) { m_rTree.ensureExpanded( arg->it ); ensureVisible( arg->it ); makeImage(); notifyLayout(); setSliderFromFirst(); } else if( isItemVisible( arg->it ) ) { makeImage(); notifyLayout(); } } else if( arg->type == arg->DeletingItem ) { if( isItemVisible( arg->it ) ) m_bRefreshOnDelete = true; // remove all references to arg->it // if it is the one about to be deleted if( m_firstPos == arg->it ) { m_firstPos = getNearestItem( arg->it ); } if( m_lastClicked == arg->it ) { m_lastClicked = getNearestItem( arg->it ); m_lastClicked->setSelected( arg->it->isSelected() ); } } else if( arg->type == arg->ItemDeleted ) { if( m_bRefreshOnDelete ) { m_bRefreshOnDelete = false; makeImage(); notifyLayout(); } setSliderFromFirst(); } else if( arg->type == arg->ResetAll ) { m_lastClicked = m_rTree.end(); m_firstPos = getFirstFromSlider(); makeImage(); notifyLayout(); setSliderFromFirst(); } else if( arg->type == arg->SliderChanged ) { Iterator it = getFirstFromSlider(); if( m_firstPos != it ) { m_firstPos = it; makeImage(); notifyLayout(); } } }
void CtrlTree::handleEvent( EvtGeneric &rEvent ) { bool bChangedPosition = false; VarTree::Iterator toShow; bool needShow = false; if( rEvent.getAsString().find( "key:down" ) != string::npos ) { int key = ((EvtKey&)rEvent).getKey(); VarTree::Iterator it; bool previousWasSelected = false; /* Delete the selection */ if( key == KEY_DELETE ) { /* Find first non selected item before m_pLastSelected */ VarTree::Iterator it_sel = m_flat ? m_rTree.firstLeaf() : m_rTree.begin(); 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_pLastSelected ) break; if( !it->isSelected() ) it_sel = it; } /* Delete selected stuff */ m_rTree.delSelected(); /* Verify if there is still sthg selected (e.g read-only items) */ m_pLastSelected = NULL; 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->isSelected() ) m_pLastSelected = &*it; } /* if everything was deleted, use it_sel as last selection */ if( !m_pLastSelected ) { it_sel->setSelected( true ); m_pLastSelected = &*it_sel; } // Redraw the control makeImage(); notifyLayout(); } else if( key == KEY_PAGEDOWN ) { it = m_firstPos; int i = (int)(maxItems()*1.5); while( i >= 0 ) { VarTree::Iterator it_old = it; it = m_flat ? m_rTree.getNextLeaf( it ) : m_rTree.getNextVisibleItem( it ); /* End is already visible, dont' scroll */ if( it == m_rTree.end() ) { it = it_old; break; } needShow = true; i--; } if( needShow ) { ensureVisible( it ); makeImage(); notifyLayout(); } } else if (key == KEY_PAGEUP ) { it = m_firstPos; int i = maxItems(); while( i >= maxItems()/2 ) { it = m_flat ? m_rTree.getPrevLeaf( it ) : m_rTree.getPrevVisibleItem( it ); /* End is already visible, dont' scroll */ if( it == ( m_flat ? m_rTree.firstLeaf() : m_rTree.begin() ) ) { break; } i--; } ensureVisible( it ); makeImage(); notifyLayout(); } else if ( key == KEY_UP || key == KEY_DOWN || key == KEY_LEFT || key == KEY_RIGHT || key == KEY_ENTER || key == ' ' ) { 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 ) ) { VarTree::Iterator next = m_flat ? m_rTree.getNextLeaf( it ) : m_rTree.getNextVisibleItem( it ); if( key == KEY_UP ) { // Scroll up one item if( ( it->parent() && it != it->parent()->begin() ) || &*it != m_pLastSelected ) { bool nextWasSelected = ( &*next == m_pLastSelected ); it->setSelected( nextWasSelected ); if( nextWasSelected ) { m_pLastSelected = &*it; needShow = true; toShow = it; } } } else if( key == KEY_DOWN ) { // Scroll down one item if( ( it->parent() && next != it->parent()->end() ) || &*it != m_pLastSelected ) { it->setSelected( previousWasSelected ); } if( previousWasSelected ) { m_pLastSelected = &*it; needShow = true; toShow = it; previousWasSelected = false; } else { previousWasSelected = ( &*it == m_pLastSelected ); } // Fix last tree item selection if( ( m_flat ? m_rTree.getNextLeaf( it ) : m_rTree.getNextVisibleItem( it ) ) == m_rTree.end() && &*it == m_pLastSelected ) { it->setSelected( true ); } } else if( key == KEY_RIGHT ) { // Go down one level (and expand node) if( &*it == m_pLastSelected ) { if( it->isExpanded() ) { if( it->size() ) { it->setSelected( false ); it->begin()->setSelected( true ); m_pLastSelected = &*(it->begin()); } else { m_rTree.action( &*it ); } } else { it->setExpanded( true ); bChangedPosition = true; } } } else if( key == KEY_LEFT ) { // Go up one level (and close node) if( &*it == m_pLastSelected ) { if( it->isExpanded() && it->size() ) { it->setExpanded( false ); bChangedPosition = true; } else { if( it->parent() && it->parent() != &m_rTree) { it->setSelected( false ); m_pLastSelected = it->parent(); m_pLastSelected->setSelected( true ); } } } } else if( key == KEY_ENTER || key == ' ' ) { // Go up one level (and close node) if( &*it == m_pLastSelected ) { m_rTree.action( &*it ); } } } if( needShow ) ensureVisible( toShow ); // Redraw the control makeImage(); notifyLayout(); } else { // other keys to be forwarded to vlc core EvtKey& rEvtKey = (EvtKey&)rEvent; var_SetInteger( getIntf()->p_libvlc, "key-pressed", rEvtKey.getModKey() ); } } 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->setSelected( it->isSelected() || select ); select = nextSelect; } // Redraw the control makeImage(); notifyLayout(); } 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->toggleSelected(); m_pLastSelected = &*it; } // Redraw the control makeImage(); notifyLayout(); } 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->setSelected( select ); select = nextSelect; } // Redraw the control makeImage(); notifyLayout(); } 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->toggleExpanded(); 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->setSelected( false ); } // Select the new item if( it != m_rTree.end() ) { it->setSelected( true ); m_pLastSelected = &*it; } } } // Redraw the control makeImage(); notifyLayout(); } 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 ) { // XXX ctrl_slider.cpp has two more (but slightly different) // XXX implementations of `scroll'. Figure out where it belongs. int direction = static_cast<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 the position var */ if( bChangedPosition ) { VarTree::Iterator it; 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 ) ) { if( it == m_firstPos ) break; iFirst++; } int indexMax = ( m_flat ? m_rTree.countLeafs() : m_rTree.visibleItems() ) - 1; float f_new = (float)iFirst / (float)indexMax; m_dontMove = true; m_rTree.getPositionVar().set( 1.0 - f_new ); m_dontMove = false; } }
void CtrlTree::handleEvent( EvtGeneric &rEvent ) { bool needShow = false; bool needRefresh = false; Iterator toShow = m_firstPos; if( rEvent.getAsString().find( "key:down" ) != string::npos ) { int key = ((EvtKey&)rEvent).getKey(); /* Delete the selection */ if( key == KEY_DELETE ) { /* Delete selected stuff */ m_rTree.delSelected(); } else if( key == KEY_PAGEDOWN ) { int numSteps = (int)m_capacity / 2; VarPercent &rVarPos = m_rTree.getPositionVar(); rVarPos.increment( -numSteps ); } else if( key == KEY_PAGEUP ) { int numSteps = (int)m_capacity / 2; VarPercent &rVarPos = m_rTree.getPositionVar(); rVarPos.increment( numSteps ); } else if( key == KEY_UP ) { // Scroll up one item m_rTree.unselectTree(); if( m_lastClicked != m_rTree.end() ) { if( --m_lastClicked != m_rTree.end() ) { m_lastClicked->setSelected( true ); } } if( m_lastClicked == m_rTree.end() ) { m_lastClicked = m_firstPos; if( m_lastClicked != m_rTree.end() ) m_lastClicked->setSelected( true ); } needRefresh = true; needShow = true; toShow = m_lastClicked; } else if( key == KEY_DOWN ) { // Scroll down one item m_rTree.unselectTree(); if( m_lastClicked != m_rTree.end() ) { Iterator it_old = m_lastClicked; if( ++m_lastClicked != m_rTree.end() ) { m_lastClicked->setSelected( true ); } else { it_old->setSelected( true ); m_lastClicked = it_old; } } else { m_lastClicked = m_firstPos; if( m_lastClicked != m_rTree.end() ) m_lastClicked->setSelected( true ); } needRefresh = true; needShow = true; toShow = m_lastClicked; } else if( key == KEY_RIGHT ) { // Go down one level (and expand node) Iterator& it = m_lastClicked; if( it != m_rTree.end() ) { if( !m_flat && !it->isExpanded() && it->size() ) { it->setExpanded( true ); needRefresh = true; } else { m_rTree.unselectTree(); Iterator it_old = m_lastClicked; if( ++m_lastClicked != m_rTree.end() ) { m_lastClicked->setSelected( true ); } else { it_old->setSelected( true ); m_lastClicked = it_old; } needRefresh = true; needShow = true; toShow = m_lastClicked; } } } else if( key == KEY_LEFT ) { // Go up one level (and close node) Iterator& it = m_lastClicked; if( it != m_rTree.end() ) { if( m_flat ) { m_rTree.unselectTree(); if( --m_lastClicked != m_rTree.end() ) { m_lastClicked->setSelected( true ); } else { m_lastClicked = m_firstPos; if( m_lastClicked != m_rTree.end() ) m_lastClicked->setSelected( true ); } needRefresh = true; needShow = true; toShow = m_lastClicked; } else { if( it->isExpanded() ) { it->setExpanded( false ); needRefresh = true; } else { Iterator it_parent = it.getParent(); if( it_parent != m_rTree.end() ) { it->setSelected( false ); m_lastClicked = it_parent; m_lastClicked->setSelected( true ); needRefresh = true; needShow = true; toShow = m_lastClicked; } } } } } else if( key == KEY_ENTER || key == ' ' ) { // Go up one level (and close node) if( m_lastClicked != m_rTree.end() ) { m_rTree.action( &*m_lastClicked ); } } else { // other keys to be forwarded to vlc core EvtKey& rEvtKey = (EvtKey&)rEvent; var_SetInteger( getIntf()->p_libvlc, "key-pressed", rEvtKey.getModKey() ); } } else if( rEvent.getAsString().find( "mouse:left" ) != string::npos ) { EvtMouse &rEvtMouse = (EvtMouse&)rEvent; const Position *pos = getPosition(); int xPos = rEvtMouse.getXPos() - pos->getLeft(); int yPos = ( rEvtMouse.getYPos() - pos->getTop() ) / itemHeight(); Iterator itClicked = findItemAtPos( yPos ); if( itClicked != m_rTree.end() ) { if( rEvent.getAsString().find( "mouse:left:down:ctrl,shift" ) != string::npos ) { // Flag to know if the current item must be selected bool select = false; for( Iterator it = m_firstPos; it != m_rTree.end(); ++it ) { bool nextSelect = select; if( it == itClicked || it == m_lastClicked ) { if( select ) { nextSelect = false; } else { select = true; if( itClicked != m_lastClicked ) nextSelect = true; } } it->setSelected( it->isSelected() || select ); select = nextSelect; needRefresh = true; } } else if( rEvent.getAsString().find( "mouse:left:down:ctrl" ) != string::npos ) { // Invert the selection of the item itClicked->toggleSelected(); m_lastClicked = itClicked; needRefresh = true; } else if( rEvent.getAsString().find( "mouse:left:down:shift" ) != string::npos ) { bool select = false; for( Iterator it = m_firstPos; it != m_rTree.end(); ++it ) { bool nextSelect = select; if( it == itClicked || it == m_lastClicked ) { if( select ) { nextSelect = false; } else { select = true; if( itClicked != m_lastClicked ) nextSelect = true; } } it->setSelected( select ); select = nextSelect; } needRefresh = true; } else if( rEvent.getAsString().find( "mouse:left:down" ) != string::npos ) { if( !m_flat && itClicked->size() && xPos > (itClicked->depth() - 1) * itemImageWidth() && xPos < itClicked->depth() * itemImageWidth() ) { // Fold/unfold the item itClicked->toggleExpanded(); } else { // Unselect any previously selected item m_rTree.unselectTree(); // Select the new item itClicked->setSelected( true ); m_lastClicked = itClicked; } needRefresh = true; } else if( rEvent.getAsString().find( "mouse:left:dblclick" ) != string::npos ) { // Execute the action associated to this item m_rTree.action( &*itClicked ); } } } else if( rEvent.getAsString().find( "scroll" ) != string::npos ) { int direction = static_cast<EvtScroll&>(rEvent).getDirection(); if( direction == EvtScroll::kUp ) m_rTree.getPositionVar().increment( +1 ); else m_rTree.getPositionVar().increment( -1 ); } else if( rEvent.getAsString().find( "drag:over" ) != string::npos ) { EvtDragOver& evt = static_cast<EvtDragOver&>(rEvent); const Position *pos = getPosition(); int yPos = ( evt.getYPos() - pos->getTop() ) / itemHeight(); Iterator it = findItemAtPos( yPos ); if( it != m_itOver ) { m_itOver = it; needRefresh = true; } } else if( rEvent.getAsString().find( "drag:drop" ) != string::npos ) { EvtDragDrop& evt = static_cast<EvtDragDrop&>(rEvent); Playtree& rPlaytree = static_cast<Playtree&>(m_rTree); VarTree& item = ( m_itOver != m_rTree.end() ) ? *m_itOver : m_rTree; rPlaytree.insertItems( item, evt.getFiles(), false ); m_itOver = m_rTree.end(); needRefresh = true; } else if( rEvent.getAsString().find( "drag:leave" ) != string::npos ) { m_itOver = m_rTree.end(); needRefresh = true; } if( needShow ) { if( toShow == m_rTree.end() || !ensureVisible( toShow ) ) needRefresh = true; } if( needRefresh ) { setSliderFromFirst(); makeImage(); notifyLayout(); } }
void CtrlButton::onUpdate( Subject<AnimBitmap> &rBitmap, void *arg ) { notifyLayout( m_pImg->getWidth(), m_pImg->getHeight() ); }
void CtrlRadialSlider::onUpdate( Subject<VarPercent> &rVariable, void *arg ) { m_position = (int)( m_rVariable.get() * m_numImg ); notifyLayout( m_width, m_height ); }
void CtrlSliderCursor::onUpdate( Subject<VarPercent> &rVariable ) { // The position has changed notifyLayout(); }
void CtrlList::handleEvent( EvtGeneric &rEvent ) { if( rEvent.getAsString().find( "key:down" ) != std::string::npos ) { int key = ((EvtKey&)rEvent).getKey(); VarList::Iterator it = m_rList.begin(); bool previousWasSelected = false; while( it != m_rList.end() ) { VarList::Iterator next = it; ++next; if( key == KEY_UP ) { // Scroll up one item if( it != m_rList.begin() || &*it != m_pLastSelected ) { bool nextWasSelected = ( &*next == m_pLastSelected ); (*it).m_selected = nextWasSelected; if( nextWasSelected ) { m_pLastSelected = &*it; } } } else if( key == KEY_DOWN ) { // Scroll down one item if( next != m_rList.end() || &*it != m_pLastSelected ) { (*it).m_selected = previousWasSelected; } if( previousWasSelected ) { m_pLastSelected = &*it; previousWasSelected = false; } else { previousWasSelected = ( &*it == m_pLastSelected ); } } it = next; } // Redraw the control makeImage(); notifyLayout(); } else if( rEvent.getAsString().find( "mouse:left" ) != std::string::npos ) { EvtMouse &rEvtMouse = (EvtMouse&)rEvent; const Position *pos = getPosition(); int yPos = m_lastPos + ( rEvtMouse.getYPos() - pos->getTop() ) / (m_rFont.getSize() + LINE_INTERVAL); VarList::Iterator it; int index = 0; if( rEvent.getAsString().find( "mouse:left:down:ctrl,shift" ) != std::string::npos ) { // Flag to know if the current item must be selected bool select = false; for( it = m_rList.begin(); it != m_rList.end(); ++it ) { bool nextSelect = select; if( index == yPos || &*it == m_pLastSelected ) { if( select ) { nextSelect = false; } else { select = true; nextSelect = true; } } (*it).m_selected = (*it).m_selected || select; select = nextSelect; index++; } } else if( rEvent.getAsString().find( "mouse:left:down:ctrl" ) != std::string::npos ) { for( it = m_rList.begin(); it != m_rList.end(); ++it ) { if( index == yPos ) { (*it).m_selected = ! (*it).m_selected; m_pLastSelected = &*it; break; } index++; } } else if( rEvent.getAsString().find( "mouse:left:down:shift" ) != std::string::npos ) { // Flag to know if the current item must be selected bool select = false; for( it = m_rList.begin(); it != m_rList.end(); ++it ) { bool nextSelect = select; if( index == yPos || &*it == m_pLastSelected ) { if( select ) { nextSelect = false; } else { select = true; nextSelect = true; } } (*it).m_selected = select; select = nextSelect; index++; } } else if( rEvent.getAsString().find( "mouse:left:down" ) != std::string::npos ) { for( it = m_rList.begin(); it != m_rList.end(); ++it ) { if( index == yPos ) { (*it).m_selected = true; m_pLastSelected = &*it; } else { (*it).m_selected = false; } index++; } } else if( rEvent.getAsString().find( "mouse:left:dblclick" ) != std::string::npos ) { for( it = m_rList.begin(); it != m_rList.end(); ++it ) { if( index == yPos ) { (*it).m_selected = true; m_pLastSelected = &*it; // Execute the action associated to this item m_rList.action( &*it ); } else { (*it).m_selected = false; } index++; } } // Redraw the control makeImage(); notifyLayout(); } else if( rEvent.getAsString().find( "scroll" ) != std::string::npos ) { int direction = ((EvtScroll&)rEvent).getDirection(); double percentage = m_rList.getPositionVar().get(); double step = 2.0 / (double)m_rList.size(); if( direction == EvtScroll::kUp ) { percentage += step; } else { percentage -= step; } m_rList.getPositionVar().set( percentage ); } }
void CtrlTree::handleEvent( EvtGeneric &rEvent ) { bool bChangedPosition = false; VarTree::Iterator toShow; bool needShow = false; if( rEvent.getAsString().find( "key:down" ) != string::npos ) { int key = ((EvtKey&)rEvent).getKey(); VarTree::Iterator it; bool previousWasSelected = false; /* Delete the selection */ if( key == KEY_DELETE ) { /* Find first non selected item before m_pLastSelected */ VarTree::Iterator it_sel = m_flat ? m_rTree.firstLeaf() : m_rTree.begin(); 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_pLastSelected ) break; if( !it->m_selected ) it_sel = it; } /* Delete selected stuff */ m_rTree.delSelected(); /* Select it_sel */ it_sel->m_selected = true; m_pLastSelected = &*it_sel; } else if( key == KEY_PAGEDOWN ) { it = m_firstPos; int i = (int)(maxItems()*1.5); while( i >= 0 ) { VarTree::Iterator it_old = it; it = m_flat ? m_rTree.getNextLeaf( it ) : m_rTree.getNextVisibleItem( it ); /* End is already visible, dont' scroll */ if( it == m_rTree.end() ) { it = it_old; break; } needShow = true; i--; } if( needShow ) { ensureVisible( it ); makeImage(); notifyLayout(); return; } } else if (key == KEY_PAGEUP ) { it = m_firstPos; int i = maxItems(); while( i >= maxItems()/2 ) { it = m_flat ? m_rTree.getPrevLeaf( it ) : m_rTree.getPrevVisibleItem( it ); /* End is already visible, dont' scroll */ if( it == ( m_flat ? m_rTree.firstLeaf() : m_rTree.begin() ) ) { break; } i--; } ensureVisible( it ); makeImage(); notifyLayout(); return; } 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 ) ) { VarTree::Iterator next = m_flat ? m_rTree.getNextLeaf( it ) : m_rTree.getNextVisibleItem( it ); if( key == KEY_UP ) { // Scroll up one item if( ( it->parent() && it != it->parent()->begin() ) || &*it != m_pLastSelected ) { bool nextWasSelected = ( &*next == m_pLastSelected ); it->m_selected = nextWasSelected; if( nextWasSelected ) { m_pLastSelected = &*it; needShow = true; toShow = it; } } } else if( key == KEY_DOWN ) { // Scroll down one item if( ( it->parent() && next != it->parent()->end() ) || &*it != m_pLastSelected ) { (*it).m_selected = previousWasSelected; } if( previousWasSelected ) { m_pLastSelected = &*it; needShow = true; toShow = it; previousWasSelected = false; } else { previousWasSelected = ( &*it == m_pLastSelected ); } // Fix last tree item selection if( ( m_flat ? m_rTree.getNextLeaf( it ) : m_rTree.getNextVisibleItem( it ) ) == m_rTree.end() && &*it == m_pLastSelected ) { (*it).m_selected = true; } } else if( key == KEY_RIGHT ) { // Go down one level (and expand node) if( &*it == m_pLastSelected ) { if( it->m_expanded ) { if( it->size() ) { it->m_selected = false; it->begin()->m_selected = true; m_pLastSelected = &*(it->begin()); } else { m_rTree.action( &*it ); } } else { it->m_expanded = true; bChangedPosition = true; } } } else if( key == KEY_LEFT ) { // Go up one level (and close node) if( &*it == m_pLastSelected ) { if( it->m_expanded && it->size() ) { it->m_expanded = false; bChangedPosition = true; } else { if( it->parent() && it->parent() != &m_rTree) { it->m_selected = false; m_pLastSelected = it->parent(); m_pLastSelected->m_selected = true; } } } } else if( key == KEY_ENTER || key == ' ' ) { // Go up one level (and close node) if( &*it == m_pLastSelected ) { 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; } }
void CtrlTree::onPositionChange() { makeImage(); notifyLayout(); }