3gppttrenderer.cpp

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

CPP
1,765
字号
            {
                pTextContainer = (C3GPPTextContainer*)
                        m_pTextContainerList->GetAt(
                        m_pTextContainerListFutureTimePos);
                HX_ASSERT(pTextContainer);
                bTextContainerIsFromMainList = TRUE;
            }
            else if (m_pTextContainerRedrawList  &&
                    m_pTextContainerRedrawList->GetCount())
            {
                pTextContainer = (C3GPPTextContainer*)
                        m_pTextContainerRedrawList->GetHead();
                bTextContainerIsFromMainList = FALSE;

                if (pTextContainer  &&
                        pTextContainer->GetEndTime() <= m_ulTimeOfLastTimeSync)
                {
                    // /It's too old to be redrawn (next time) so remove it
                    // from the list:
                    pTextContainer =  NULL;
                    m_pTextContainerRedrawList->RemoveHead();
                }
            }
            else
            {
                break; // /None from either list need drawing
            }

#if defined(XXXEH_DEBUGOUT_DRAW_3GPPTT)
FILE* pFile = fopen("c:\\3gppttdrawPos.txt", ulCount?"a+":"w");
if (pFile)
{
    fprintf(pFile, "[step -1] T.C. = %p at time %lu (text containers "
        "handled = %ld), m_pTextContainerListFutureTimePos=%p\n",
        pTextContainer, m_ulTimeOfLastTimeSync, ulTextContainersHandled,
        m_pTextContainerListFutureTimePos);
    fclose(pFile);
}
ulCount++;
#endif // /XXXEH_DEBUGOUT_DRAW_3GPPTT.

            if (!pTextContainer  ||  !pTextContainer->m_pPacket)
            {
                // /There should always be something to draw at any given time
                // (unless the 3GPP-TT docs are incomplete) since one packet's
                // begin time sets the end of the prior packet.  (There is one
                // exception, and that is when we're drawing off the main list
                // and the next T.C. in the redraw list has been removed when
                // found (above) to be past its end time):
                HX_ASSERT(pTextContainer  ||  !bTextContainerIsFromMainList);
                HX_ASSERT(pTextContainer? NULL!=pTextContainer->m_pPacket : 1);
                goto cleanup; // /Something's not right
            }

/*
#if 0 // /For testing/debugging:
{
    IHXPacket* pTextPkt = pTextContainer->m_pPacket;
    static UINT32 ulDrawCount = 0;
    FILE* pFile = fopen("c:\\3gppttdump.txt", ulDrawCount?"a+":"w");
    if (pFile)
    {
        IHXBuffer* pBuff = pTextPkt?pTextPkt->GetBuffer():NULL;
        char* pText = pBuff? (char*)pBuff->GetBuffer() : "99[NULL]";
        fprintf(pFile, "Drawct  \t%lu\npkt time\t%lu\ncur time%lu\n"
                "m_pTextContainerListFutureTimePos = %p\n"
                "size    \t%d\ncontents\t{{{[len=%u]%s}}}\n\n",
                ulDrawCount, pTextPkt? pTextPkt->GetTime():9999999, m_ulTimeOfLastTimeSync,
                m_pTextContainerListFutureTimePos,
                pTextPkt? pTextPkt->GetBuffer()->GetSize():9999999,
                ((*pText)<< 8)|(*(pText+1)), &pText[2]);
        fclose(pFile);
    }
    ulDrawCount++;
}
#endif
*/

#if defined(XXXEH_DEBUGOUT_DRAW_3GPPTT)
pFile = fopen("c:\\3gppttdrawPos.txt", ulCount?"a+":"w");
if (pFile)
{
    fprintf(pFile, "[step 0] T.C. = %p (begin=%lu,\tend=%lu,\tnextActive=%lu)\t"
        "at time %lu\t(text containers handled = %ld),\t"
        "m_pTextContainerListFutureTimePos=%p\n", pTextContainer,
        pTextContainer->GetBeginTime(), pTextContainer->GetEndTime(),
        pTextContainer->GetNextActivityTime(), m_ulTimeOfLastTimeSync,
        ulTextContainersHandled, m_pTextContainerListFutureTimePos);
    fclose(pFile);
}
ulCount++;
#endif // /XXXEH_DEBUGOUT_DRAW_3GPPTT.

            // /The sample entry associated with the text sample:
            const C3GPPTextSampleEntry* pCurTextSampleEntry = NULL;

                    // /XXXEH- handle possible time-offset w/m_ulTimeOfLastTimeSync!
            if (    pTextContainer->GetNextActivityTime() <= m_ulTimeOfLastTimeSync  &&
                    pTextContainer->GetEndTime() > m_ulTimeOfLastTimeSync  &&
                    pTextContainer->m_pTextSample  &&
                    pTextContainer->m_pTextSample->GetText()  &&
                    pTextContainer->m_pTextSample->GetTextLenInBytes())
            {
#if defined(XXXEH_DEBUGOUT_DRAW_3GPPTT)
pFile = fopen("c:\\3gppttdrawPos.txt", ulCount?"a+":"w");
if (pFile)
{
    fprintf(pFile, "[step 1] T.C. = %p at time %lu (text containers handled = "
        "%ld), m_pTextContainerListFutureTimePos=%p\n", pTextContainer,
        m_ulTimeOfLastTimeSync, ulTextContainersHandled,
        m_pTextContainerListFutureTimePos);
    fclose(pFile);
}
ulCount++;
#endif // /XXXEH_DEBUGOUT_DRAW_3GPPTT.

                bATextContainerFromMainListWasHandled =
                        bTextContainerIsFromMainList;

                ulTextContainersHandled++;

                // /The sample entry associated with the text sample:
                pCurTextSampleEntry = NULL;

// /XXXEH- todo: Maybe replace the following ~15 lines w/new pTextContainer->GetSampleDescIndex() method:
                // /Find out which sample description to associate with a text
                // sample (one per packet):
                UINT32 ulPktRuleNum = pTextContainer->GetASMRuleNumber();
                // /Initialize it to rule # (which may be wrong index), then
                // find the correct index value in the ruleToFlagMap:
                UINT32 ulAssocSampleDescIndex = ulPktRuleNum;
                HX_ASSERT(m_pRuleToFlagMap  &&
                        ulAssocSampleDescIndex < m_pRuleToFlagMap->num_rules);
                if (m_pRuleToFlagMap  &&  ulAssocSampleDescIndex <
                        m_pRuleToFlagMap->num_rules)
                {
                    ulAssocSampleDescIndex =
                        m_pRuleToFlagMap->rule_to_flag_map[ulPktRuleNum];
                }
                pCurTextSampleEntry = (const C3GPPTextSampleEntry*)
                        m_textSampleEntries.GetItem(ulAssocSampleDescIndex);
                HX_ASSERT(pCurTextSampleEntry);

                ulBgColorARGB = pCurTextSampleEntry->GetBGColor();

                // /Fill background, but only if desc. differs from prev:
                if (pCurTextSampleEntry != pLastHandledTextSampleEntry
                        // /...and also only if this is 1st one at this time:
                        &&  1 == ulTextContainersHandled
                        // /...and also only if this is not a redraw due to
                        // blinking; if it is, only redraw it and leave the
                        // rest of the (non-blinking) text that's already
                        // drawn (and still time-valid) alone:
                        &&  bTextContainerIsFromMainList)
                {
                    FillRectangle(ulBgColorARGB);
                }

                if (bTextContainerIsFromMainList)
                {
                    // /This one is now in the past (hendled), so move past it:
                    m_pTextContainerList->GetNext(
                            m_pTextContainerListFutureTimePos);
                }

                const C3GPPStyleRecord& defStyle = pCurTextSampleEntry->GetDefaultStyle();
                UINT32 ulScaledHeight = defStyle.GetFontSize();

                UINT32 defFaceStyleFlags = defStyle.GetFaceStyleFlags();
                BOOL bIsBolded = (defFaceStyleFlags & HX_3GPPTT_FACE_STYLE_BOLD);
                BOOL bIsItalicized = (defFaceStyleFlags & HX_3GPPTT_FACE_STYLE_ITALIC);
                BOOL bIsUnderlined = (defFaceStyleFlags & HX_3GPPTT_FACE_STYLE_UNDERLINE);
                BOOL bIsStruckThrough = FALSE;

                char* pCurFontFaceString = NULL;

                UINT32 ulTextColorARGB = defStyle.GetTextColor();
                UINT32 ulTextColorARGBOld = 0;

                UINT16 uiFontID_override = HX_3GPPTT_INVALID_INDEX;
                
                // /Init to totally transparent (which means ignore it):
                UINT32 ulHighlightColorARGB = HX_3GPPTT_FULLY_TRANSPARENT;
                BOOL bHasHighlightColor = FALSE;

                if (pTextContainer->IsHyperlinked())
                {
                    // /Draw text in red w/underline:
                    bIsUnderlined = TRUE;
                    // /Keep the alpha value but clear RGB part to red:
                    ulTextColorARGB = (ulTextColorARGB & HX_3GPPTT_FULLY_TRANSPARENT) |
                            HX_3GPPTT_HYPERLINK_RGB_COLOR;
                }

                if (pTextContainer->m_pTextHilightColorBox)
                {
                    ulHighlightColorARGB = 
                            pTextContainer->m_pTextHilightColorBox->GetHighlightColor();
                    if (pTextContainer->m_pTextHighlightBox)
                    {
                        // /Has highlight unless highlight color is fully transparent:
                        bHasHighlightColor = (ulHighlightColorARGB < HX_3GPPTT_FULLY_TRANSPARENT);
                    }
                }

                // /Use style overrides, if any, for this time container:
                if (HX_3GPPTT_INVALID_INDEX != pTextContainer->m_uiTextStyleBoxIndex  &&
                        pTextContainer->m_pTextStyleBox)
                {
                    
                    const C3GPPStyleRecord* pStyleRecordOverride =
                            pTextContainer->m_pTextStyleBox->GetStyleRecord(
                            pTextContainer->m_uiTextStyleBoxIndex);

                    HX_ASSERT(pStyleRecordOverride);
                    if (pStyleRecordOverride)
                    {
                        UINT32 flags = pStyleRecordOverride->GetFaceStyleFlags();                 
                        bIsUnderlined = (flags & HX_3GPPTT_FACE_STYLE_UNDERLINE);
                        bIsBolded = (flags & HX_3GPPTT_FACE_STYLE_BOLD);
                        bIsItalicized = (flags & HX_3GPPTT_FACE_STYLE_ITALIC);

                        ulTextColorARGB = pStyleRecordOverride->GetTextColor();

                        ulScaledHeight = pStyleRecordOverride->GetFontSize();

                        uiFontID_override = pStyleRecordOverride->GetFontID();
                    }
                }

                if (HX_3GPPTT_INVALID_INDEX != pTextContainer->m_uiTextKaraokeBoxIndex  &&
                        pTextContainer->m_pTextKaraokeBox)
                {
                    const C3GPPTextKaraokeBox::C3GPPTextKaraokeControlEntry*
                            pCurKaraokeCtrlEntry =
                            pTextContainer->m_pTextKaraokeBox->GetKaraokeControlEntry(
                            pTextContainer->m_uiTextKaraokeBoxIndex);

                    HX_ASSERT(pCurKaraokeCtrlEntry);
                    if (pCurKaraokeCtrlEntry)
                    {
                        // /Reuse position info from last draw if this is a redraw:
                        bReuseTCsPriorDrawRect = !bTextContainerIsFromMainList;

                        // /Start time is end of prior highlight span; if
                        // that's invalid, use highlightstart time of
                        // TextKaraokeBox:
                        ulKaraokeHighlightStartTimeInGlobalTime =
                                ulKaraokeHighlightEndTimeInGlobalTime;
//#error: should be: if (0 == pTextContainer->m_uiTextKaraokeBoxIndex  ...(||?)
                        if (HX_3GPPTT_INVALID_TIME ==
                                ulKaraokeHighlightStartTimeInGlobalTime)
                        {
                            ulKaraokeHighlightStartTimeInGlobalTime =
                                    pTextContainer->GetBeginTime() +
                                    pTextContainer->m_pTextKaraokeBox->
                                    Get1stHighlightStartTime();
                        }
                        ulKaraokeHighlightEndTimeInGlobalTime =
                                pTextContainer->GetBeginTime() +
                                pCurKaraokeCtrlEntry->GetHighlightEndTime();

                        // /Set text color to hightlightColor unless curtime
                        // is outside of this TC's begin-end range:
                        if (m_ulTimeOfLastTimeSync >=
                                ulKaraokeHighlightStartTimeInGlobalTime  &&
                                m_ulTimeOfLastTimeSync <
                                ulKaraokeHighlightEndTimeInGlobalTime)
                        {
                            ulTextColorARGB = ulHighlightColorARGB;
                            pTextContainer->m_ulNextDrawUpdateTimeOffset =
                                    ulKaraokeHighlightEndTimeInGlobalTime -
                                    pTextContainer->GetBeginTime();
                            InsertInRedrawListInTemporalOrder(pTextContainer);
                        }
                        else // /We're (not yet | no longer) in the highlight period:
                        {
                            UINT32 ulPrvActTime = pTextContainer->GetPrevActivityTime();
                            // /However, if highlight has been performed
                            // and then undone, remove it from redraw list
                            // then skip this TC and get next...
                            if (HX_3GPPTT_INVALID_TIME != ulPrvActTime)
                            {
                                if (m_ulTimeOfLastTimeSync >=
                                    ulKaraokeHighlightEndTimeInGlobalTime)
                                {
#if defined(_DEBUG)
                                    HX_RESULT hxrRemove =
#endif // /_DEBUG
                                    RemoveFromRedrawList(pTextContainer);
#if defined(_DEBUG)
                                    HX_ASSERT(HXR_OK == hxrRemove);
#endif // /_DEBUG
                                    // /If we've already returned it to pre-
                                    // highlight color by drawing after its
                                    // highlight end time, then skip it now:
                                    if (ulPrvActTime >=
                                            ulKaraokeHighlightEndTimeInGlobalTime)
                                    {
                                        continue;
                                    }
                                }
                                // /...else if highlight has been done but not
                                // undone yet, set next activity time to highlight
                                // end time and then skip drawing this TC @ now:
                                else if (ulPrvActTime >
                                        ulKaraokeHighlightStartTimeInGlobalTime)
                                {
                                    // /Set next activity time in local (offset) time:
#if defined(XXXEH_SHOW_TODO_MESSAGES)
#pragma message("====##### XXXEH- todo: replace w/ ->setDrawUpdateTimeOffset() method #####====")
#endif // /XXXEH_SHOW_TODO_MESSAGES.
                                    pTextContainer->m_ulNextDrawUpdateTimeOffset =
                                            ulKaraokeHighlightEndTimeInGlobalTime -
                                            pTextContainer->GetBeginTime();
                                    InsertInRedrawListInTemporalOrder(pTextContainer);
                                    continue;
                                }
                            }
                            else // /Not yet drawn, so next draw will be highlight:
                                // if (m_ulTimeOfLastTimeSync <
                                //    ulKaraokeHighlightStartTimeInGlobalTime  &&
                                //    pTextContainer->m_ulNextDrawUpdateTimeOffset +
                                //    pTextContainer->GetBeginTime() !=
                                //    ulKaraokeHighlightStartTimeInGlobalTime)
                            {
                                // /Set next activity time in local (offset) time:
#if defined(XXXEH_SHOW_TODO_MESSAGES)
#pragma message("====##### XXXEH- todo: replace w/ ->setDrawUpdateTimeOffset() method #####====")
#endif // /XXXEH_SHOW_TODO_MESSAGES.
                                pTextContainer->m_ulNextDrawUpdateTimeOffset =
                                        ulKaraokeHighlightStartTimeInGlobalTime -
                                        pTextContainer->GetBeginTime();
                                // /Call this even if pT.C.'s end is exceeded because this
                                // method will remove & not reinsert it in that case:
                                InsertInRedrawListInTemporalOrder(pTextContainer);
                            }
                        }
                    }
                } // /end KaraokeBox handling.
                
                // /First see if we have a scroll offset:
                TextSampleScrollDirection scrolldir =
                        pCurTextSampleEntry->getScrollDirection();
                if (scrollDirNone != scrolldir)
                {
                    UINT32 ulScrollDelay = 0;
                    if (pTextContainer->m_pTextScrollDelayBox)
                    {
                        ulScrollDelay = pTextContainer->m_pTextScrollDelayBox->GetScrollDelay();
                    }

                    HX_AS

⌨️ 快捷键说明

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