chxavnavipanecontrol.cpp

来自「symbian 下的helix player源代码」· C++ 代码 · 共 802 行 · 第 1/2 页

CPP
802
字号
       
        
        // hide status images
        ShowPauseIndication(false);
        UpdateVisibilityHelper(m_spVolStateImage.Ptr(), false);

    }
    else
    {
        // hide status control
        UpdateVisibilityHelper(m_spStatusText.Ptr(), false);

        
        // restore status images
        bool bIsPaused = (CHXAvPlayerState::Paused == m_spPlayer->GetPlayerState().GetState());
        ShowPauseIndication(bIsPaused);
        UpdateVisibilityHelper(m_spVolStateImage.Ptr(), m_spPlayer->IsMuted());

        // timer doesn't need to be hidden anymore
        m_bHideTimerForStatusText = false;
    }

    // set ellipse animation and visibility
    ToggleEllipseAnimation(bAnimateEllipse);
    UpdateVisibilityHelper(m_spEllipseText.Ptr(), bAnimateEllipse);
    
}



////////////////////////////////////////////////
// helper
//
// calculate rect and set text for control that goes in timer area
//
void 
CHXAvNaviPaneControl::SizeAndSetTimerAreaText(refptr<CHXAvTextControl>& pControl, const TDesC& text)
{
    // determine width needed
    const CFont* pFont = pControl->GetFont();
    TInt cxText = pFont->TextWidthInPixels(text);

    TRect rcText;
    GetTimerTextMaxArea(rcText);
    if(cxText <= rcText.Width())
    {
        // shrink actual rect's left side so there is just enough
        // so that text just fits
        rcText.iTl.iX = rcText.iBr.iX - cxText;
    } // else, clip...
    
    UpdateTextHelper(pControl.Ptr(), text);
    UpdateRectHelper(pControl.Ptr(), rcText); 
}

////////////////////////////////////////////////
// helper
void 
CHXAvNaviPaneControl::GetTimerTextL(TUint msNow, TDes& timerTextOut) const
{
    HBufC* pTimeNow = CHXAvMisc::AllocTimerTextL(msNow);
    AUTO_PUSH_POP_DEL(pTimeNow);
    timerTextOut.Copy(*pTimeNow);
    
    const CHXSymClipInfo& info = m_spPlayer->GetClipInfo();

    if( info.IsLive() )
    {
        // show current time only
    }
    else
    {
        // show current time and possibly total time
        TUint msTotal = m_spPlayer->GetClipDuration();
        if(msTotal)
        {
            if(msTotal < k_msPerHour)
            {
                // only show total time if clip duration is under an hour
                HBufC* pTimeTotal = CHXAvMisc::AllocTimerTextL(msTotal);
                AUTO_PUSH_POP_DEL(pTimeTotal);
                timerTextOut.Append(_L("/"));
	        timerTextOut.Append(*pTimeTotal);
            }
        }
        else
        {
            timerTextOut.Zero();
        }
    }
	
}

void CHXAvNaviPaneControl::DoTimerTextUpdateAndDraw()
{
    m_bNeedRefresh = false;
    TRAPD(err, UpdateTimerTextL());
    if(KErrNone == err)
    {
        UpdateTimerTextVisibility();
        if( m_bNeedRefresh )
        {
            m_spRefreshCmd->Execute();
        }
    }
}

void CHXAvNaviPaneControl::DoUpdateEverythingAndDraw()
{
    m_bNeedRefresh = false;
    TRAPD(err, UpdateEverythingL());
    if( (KErrNone == err) && m_bNeedRefresh )
    {
        m_spRefreshCmd->Execute();
    }
    
}

void CHXAvNaviPaneControl::UpdateRectHelper(CCoeControl* pControl, const TRect& rc)
{
    if(pControl->Rect() != rc)
    {
        m_bNeedRefresh = true;
        pControl->SetRect(rc);
    }
}

void CHXAvNaviPaneControl::UpdateTextHelper(CHXAvTextControl* pControl, const TDesC& text)
{
    if( pControl->GetText().Compare(text) != 0 )
    {
        // text needs to change
        m_bNeedRefresh = true;
        pControl->SetText(text);
    }
}

void CHXAvNaviPaneControl::UpdateVisibilityHelper(CCoeControl* pControl, bool bShow)
{
    if( bool(pControl->IsVisible()) != bShow)
    {
        // visibility needs to change
        m_bNeedRefresh = true;
        pControl->MakeVisible(bShow);
    }
}

////////////////////////////////////////
//IHXSymPlayerStateObserver
void CHXAvNaviPaneControl::OnNewPos(ULONG32 /*msNewTime*/)
{
    //DPRINTF(SYMP_INFO, ("CHXAvNaviPaneControl::OnNewPos(): time = %lu\n", msNewTime));
    DoTimerTextUpdateAndDraw();
}


////////////////////////////////////////
// and sometimes if status text is long
//
void CHXAvNaviPaneControl::UpdateTimerTextVisibility()
{
    bool bShow = !m_bHideTimerForStatusText; //!(m_spPlayer->IsConnecting() | m_bHideTimerForStatusText);
    UpdateVisibilityHelper(m_spTimerText.Ptr(), bShow);
}

void 
CHXAvNaviPaneControl::OnAdvancePlaylist()
{
    DoUpdateEverythingAndDraw();
}

////////////////////////////////////////
//
void CHXAvNaviPaneControl::UpdateTimerTextL()
{
    TUint msNow = m_spPlayer->GetClipTime();
    
    // draw position timer text
    TBuf<50> timerText;
    GetTimerTextL(msNow, timerText); 

    SizeAndSetTimerAreaText(m_spTimerText, timerText);
}

void
CHXAvNaviPaneControl::UpdateEverythingL()
{
    // live state first
    UpdateLiveStateIndicator();

    // then text
    UpdateTimerTextL();

    // then status area (text and status bitmaps) - based on size of timer text
    UpdateStatusAreaL();

    // then timer visibility - based on size of status text
    UpdateTimerTextVisibility();
}


void 
CHXAvNaviPaneControl::ShowPauseIndication(bool bShow)
{
    if(bShow)
    {
        m_bBlinkIsVisible = true;
        UpdateVisibilityHelper(m_spPlayStateImage.Ptr(), true);
        
        // start blinking
        if( !m_cbBlink.IsPending() )
        {
            m_cbBlink.Set(k_msStatusBlinkInterval, CHXAvCallback::REPEAT);
        }
    }
    else
    {
        m_cbBlink.Stop();
        UpdateVisibilityHelper(m_spPlayStateImage.Ptr(), false);
    }
}

// from animate ellipse callback
void
CHXAvNaviPaneControl::OnAnimateEllipseTick()
{
    HX_ASSERT(m_spEllipseText->IsVisible());

    // count 0 - 3
    const TUint end = litSize(KEllipse) + 1;
    HX_ASSERT(m_ellipseCount < end);

    TPtrC text = KEllipse().Left(m_ellipseCount);
    UpdateTextHelper(m_spEllipseText.Ptr(), text);

    m_ellipseCount = ++m_ellipseCount % end;

    m_spRefreshCmd->Execute();

}

void
CHXAvNaviPaneControl::ToggleEllipseAnimation(bool bOn)
{
    if(bOn)
    {
        if( !m_cbAnimateEllipse.IsPending() )
        {
            m_cbAnimateEllipse.Set(k_msAnimateEllipseInterval, CHXAvCallback::REPEAT);
        }
    }
    else
    {
        m_cbAnimateEllipse.Stop();
    }
}

// from blink callback
void
CHXAvNaviPaneControl::ToggleStatusBlinkAndDraw()
{
    m_bBlinkIsVisible = !m_bBlinkIsVisible;
    m_spPlayStateImage->MakeVisible(m_bBlinkIsVisible);
    m_spRefreshCmd->Execute();
}


void
CHXAvNaviPaneControl::OnPlayInitiate(const char* /*url*/)
{
    DPRINTF(SYMP_INFO, ("CHXAvNaviPaneControl::OnPlayInitiate()\n"));
    DoUpdateEverythingAndDraw();
}

void
CHXAvNaviPaneControl::OnNetConnect()
{
    DPRINTF(SYMP_INFO, ("CHXAvNaviPaneControl::OnNetConnect()\n"));
    DoUpdateEverythingAndDraw();
}


void CHXAvNaviPaneControl::UpdateLiveStateIndicator()
{
    const CHXSymClipInfo& info = m_spPlayer->GetClipInfo();

    bool bShowOn = info.IsLive() && m_spPlayer->IsPlaying() && !m_spPlayer->IsBuffering();
    bool bShowOff = info.IsLive() && !bShowOn;
    
    UpdateVisibilityHelper(m_spLiveStateOnImage.Ptr(), bShowOn);
    UpdateVisibilityHelper(m_spLiveStateOffImage.Ptr(), bShowOff);
}

void
CHXAvNaviPaneControl::OnLoadSession(IHXRequest* /*request*/)
{
    DPRINTF(SYMP_INFO, ("CHXAvNaviPaneControl::OnLoadSession()\n")); 
    DoUpdateEverythingAndDraw();
}

void
CHXAvNaviPaneControl::OnResume()
{
    DPRINTF(SYMP_INFO, ("CHXAvNaviPaneControl::OnResume()\n"));
    DoUpdateEverythingAndDraw();
}
void
CHXAvNaviPaneControl::OnStop()
{
    DPRINTF(SYMP_INFO, ("CHXAvNaviPaneControl::OnStop()\n"));
    DoUpdateEverythingAndDraw();
}

void
CHXAvNaviPaneControl::OnPause()
{
    DPRINTF(SYMP_INFO, ("CHXAvNaviPaneControl::OnPause()\n"));
    DoUpdateEverythingAndDraw();
}

void 
CHXAvNaviPaneControl::OnBeginSeek()
{
    DPRINTF(SYMP_INFO, ("CHXAvNaviPaneControl::OnBeginSeek()\n"));
    DoUpdateEverythingAndDraw();
}

void
CHXAvNaviPaneControl::OnBeginBuffering(bool bIsBegin)
{
    DPRINTF(SYMP_INFO, ("CHXAvNaviPaneControl::OnBeginBuffering(): is start = '%s'\n", dbg::Bool(bIsBegin)));
    DoUpdateEverythingAndDraw();   
}

void
CHXAvNaviPaneControl::OnBuffering(UINT16 percent)
{
    DPRINTF(SYMP_INFO, ("CHXAvNaviPaneControl::OnBuffering(): %u percent\n", percent));
    DoUpdateEverythingAndDraw(); 
}

void CHXAvNaviPaneControl::OnMute(bool bMute)
{
    DPRINTF(SYMP_INFO, ("CHXAvNaviPaneControl::OnMute('%s')\n", dbg::Bool(bMute)));
    if( !m_spStatusText->IsVisible() )
    {
        // show mute image when mute
        m_spVolStateImage->MakeVisible(bMute);
        m_spRefreshCmd->Execute();
    }
}

////////////////////////////////////////
//
void 
CHXAvNaviPaneControl::Draw(const TRect& /* rect */) const
{
    // don't draw background; navi pane container draws background for us
}

//////////////////////////////
//
// CCoeControl
//
TInt CHXAvNaviPaneControl::CountComponentControls() const
{ 
    return 7;
}


//////////////////////////////
//
// CCoeControl
//
CCoeControl* CHXAvNaviPaneControl::ComponentControl(TInt aIndex) const
{
    switch( aIndex )
    {
    case 0:
	return m_spTimerText.Ptr();
    case 1:
	return m_spPlayStateImage.Ptr();
    case 2:
	return m_spStatusText.Ptr();
    case 3:
	return m_spVolStateImage.Ptr();
    case 4:
        return m_spLiveStateOnImage.Ptr();
    case 5:
        return m_spLiveStateOffImage.Ptr();
    case 6:
        return m_spEllipseText.Ptr();
    default:
        break;
    }
    HX_ASSERT(false);
    return 0;
}


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?