animsand.cpp

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

CPP
1,572
字号
/* ***** BEGIN LICENSE BLOCK *****
 * Source last modified: $Id: animsand.cpp,v 1.2.12.1 2004/07/09 01:58:01 hubbe Exp $
 * 
 * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved.
 * 
 * The contents of this file, and the files included with this file,
 * are subject to the current version of the RealNetworks Public
 * Source License (the "RPSL") available at
 * http://www.helixcommunity.org/content/rpsl unless you have licensed
 * the file under the current version of the RealNetworks Community
 * Source License (the "RCSL") available at
 * http://www.helixcommunity.org/content/rcsl, in which case the RCSL
 * will apply. You may also obtain the license terms directly from
 * RealNetworks.  You may not use this file except in compliance with
 * the RPSL or, if you have a valid RCSL with RealNetworks applicable
 * to this file, the RCSL.  Please see the applicable RPSL or RCSL for
 * the rights, obligations and limitations governing use of the
 * contents of the file.
 * 
 * Alternatively, the contents of this file may be used under the
 * terms of the GNU General Public License Version 2 or later (the
 * "GPL") in which case the provisions of the GPL are applicable
 * instead of those above. If you wish to allow use of your version of
 * this file only under the terms of the GPL, and not to allow others
 * to use your version of this file under the terms of either the RPSL
 * or RCSL, indicate your decision by deleting the provisions above
 * and replace them with the notice and other provisions required by
 * the GPL. If you do not delete the provisions above, a recipient may
 * use your version of this file under the terms of any one of the
 * RPSL, the RCSL or the GPL.
 * 
 * This file is part of the Helix DNA Technology. RealNetworks is the
 * developer of the Original Code and owns the copyrights in the
 * portions it created.
 * 
 * This file, and the files included with this file, is distributed
 * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
 * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
 * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
 * ENJOYMENT OR NON-INFRINGEMENT.
 * 
 * Technology Compatibility Kit Test Suite(s) Location:
 *    http://www.helixcommunity.org/content/tck
 * 
 * Contributor(s):
 * 
 * ***** END LICENSE BLOCK ***** */

// system
#include <time.h>
#include <math.h>
// include
#include "hxtypes.h"
#include "hxwintyp.h"
#include "hxcom.h"
#include "hxxml.h"
#include "smiltype.h"
// pnmisc
#include "hxwinver.h"
// pncont
#include "hxslist.h"
// rnxmllib
#include "hxxmlprs.h"
// rmasmil
#include "smlelem.h"
#include "smlparse.h"
#include "animattr.h"
// smlrendr
#include "smlrmlog.h"
#include "animsand.h"
// pndebug
#include "hxheap.h"
#include "debugout.h"
#ifdef _DEBUG
#undef HX_THIS_FILE		
static const char HX_THIS_FILE[] = __FILE__;
#endif

CAnimationSandwichLayer::CAnimationSandwichLayer(CSmilAnimateElement* pElement,
                                                 UINT32               ulAttrName,
                                                 CSmilParser*         pParser)
{
    MLOG_LEAKCHECK("CON CAnimationSandwichLayer this=0x%08x\n", this);
    m_pElement         = NULL;
    m_ulAttrName       = kAttrNameUnknown;
    m_pdPacedDist      = NULL;
    m_pdPacedTime      = NULL;
    m_bRecomputePace   = FALSE;
    m_bFirstTime       = TRUE;
    m_pSmilParser      = pParser;
    m_ulLastTime       = 0;
    m_ulDelay          = 0;
    m_ulActiveDuration = 0;

    if (pElement && pElement->m_pNode)
    {
        // Make sure the attribute name makes sense
        // with this element. If this element
        // is NOT an <animateMotion>, then we expect
        // the attribute name in the element to match
        // the passed-in attribute name. If this 
        // element IS <animateMotion>, then the passed-in
        // attribute should be either "left" or "top".
        if ((pElement->m_pNode->m_tag == SMILAnimateMotion &&
             (ulAttrName == kAttrNameLeft || ulAttrName == kAttrNameTop)) ||
            (pElement->m_pNode->m_tag != SMILAnimateMotion &&
             ulAttrName == (UINT32) pElement->m_ucAttributeName))
        {
            // Assign the members
            m_pElement         = pElement;
            m_ulAttrName       = ulAttrName;
            m_ulDelay          = pElement->m_ulDelay;
            m_ulActiveDuration = pElement->m_ulActiveDuration;
            // Check if the "end" attribute constrains
            // the active duration.
            if (pElement->m_bEndOffsetSet)
            {
                UINT32 ulEndMinusBegin = ((UINT32) pElement->m_lEndOffset) - m_ulDelay;
                if (ulEndMinusBegin < m_ulActiveDuration)
                {
                    m_ulActiveDuration = ulEndMinusBegin;
                }
            }
            // If we are a paced animation, then we need to
            // decide how we are going to compute the D()
            // and T() functions.
            if (pElement->m_ucCalcMode == kCalcModePaced)
            {
                // Now we need to determine if these functions should be
                // re-computed every time. We need to do this IF any
                // attributes are relative.
                BOOL bSomeRelative = FALSE;
                for (UINT32 i = 0; i < pElement->m_ulNumValues; i++)
                {
                    if (pElement->m_ppValue[i])
                    {
                        for (UINT32 j = 0; j < CAttr::kVectorSize; j++)
                        {
                            if (pElement->m_ppValue[i]->IsRelative(j))
                            {
                                bSomeRelative = TRUE;
                            }
                        }
                    }
                }
                if (bSomeRelative)
                {
                    // We will have to recompute the functions
                    // every time we evaluate
                    m_bRecomputePace = TRUE;
                }
            }
        }
    }
}

CAnimationSandwichLayer::~CAnimationSandwichLayer()
{
    MLOG_LEAKCHECK("DES CAnimationSandwichLayer this=0x%08x\n", this);
    HX_VECTOR_DELETE(m_pdPacedDist);
    HX_VECTOR_DELETE(m_pdPacedTime);
}

const char* CAnimationSandwichLayer::GetAnimationElementID() const
{
    const char* pRet = NULL;

    if (m_pElement &&
        m_pElement->m_pNode)
    {
        pRet = (const char*) m_pElement->m_pNode->m_id;
    }

    return pRet;
}

const char* CAnimationSandwichLayer::GetTargetElementID() const
{
    const char* pRet = NULL;

    if (m_pElement && m_pElement->m_pTargetElementID)
    {
        pRet = (const char*) *m_pElement->m_pTargetElementID;
    }

    return pRet;
}

SMILNodeTag CAnimationSandwichLayer::GetTargetElementTag() const
{
    SMILNodeTag eRet = SMILUnknown;

    if (m_pElement)
    {
        eRet = m_pElement->m_eTargetElementTag;
    }

    return eRet;
}

SMILNodeTag CAnimationSandwichLayer::GetAnimationElementTag() const
{
    SMILNodeTag eRet = SMILUnknown;

    if (m_pElement && m_pElement->m_pNode)
    {
        eRet = m_pElement->m_pNode->m_tag;
    }

    return eRet;
}

BOOL CAnimationSandwichLayer::IsActive(UINT32 ulTime) const
{
    BOOL bRet = FALSE;

    if (m_pElement && ulTime >= m_ulDelay)
    {
        if (m_pElement->m_bIndefiniteActiveDuration ||
            ulTime < m_ulDelay + m_ulActiveDuration)
        {
            // During the active duration - it's active
            bRet = TRUE;
        }
    }

    return bRet;
}

BOOL CAnimationSandwichLayer::IsFrozen(UINT32 ulTime) const
{
    BOOL bRet = FALSE;

    if (m_pElement &&
        (m_pElement->m_eActualFill == FillFreeze ||
         m_pElement->m_eActualFill == FillHold))
    {
        if (!m_pElement->m_bIndefiniteActiveDuration)
        {
            if (ulTime >= m_ulDelay + m_ulActiveDuration)
            {
                // XXXMEH - now that we are calculating a remove
                // time for every timed element, we should be able
                // to use the m_ulRemoveTime. However, let's keep
                // the old code around "just in case".
                if (m_pElement->m_ulRemoveTime == ((UINT32) -1))
                {
                    UINT32 ulRemoveTime = 0;
                    HX_RESULT rv = m_pSmilParser->computeRemoveTime(m_pElement->m_pNode->m_id,
                                                                    ulRemoveTime);
                    if (SUCCEEDED(rv))
                    {
                        m_pElement->m_ulRemoveTime = ulRemoveTime;
                    }
                }
                if (ulTime <= m_pElement->m_ulRemoveTime)
                {
                    bRet = TRUE;
                }
            }
        }
    }

    return bRet;
}

BOOL CAnimationSandwichLayer::IsActiveZeroBased(UINT32 ulTime) const
{
    BOOL bRet = FALSE;

    if (m_pElement &&
        (m_pElement->m_bIndefiniteActiveDuration ||
         ulTime < m_ulActiveDuration))
    {
        // During the active duration - it's active
        bRet = TRUE;
    }

    return bRet;
}

BOOL CAnimationSandwichLayer::IsFrozenZeroBased(UINT32 ulTime) const
{
    BOOL bRet = FALSE;

    if (m_pElement &&
        (m_pElement->m_eActualFill == FillFreeze ||
         m_pElement->m_eActualFill == FillHold))
    {
        if (!m_pElement->m_bIndefiniteActiveDuration)
        {
            if (ulTime >= m_ulActiveDuration)
            {
                if (ulTime <= (m_pElement->m_ulRemoveTime - m_ulDelay))
                {
                    bRet = TRUE;
                }
            }
        }
    }

    return bRet;
}

BOOL CAnimationSandwichLayer::IsAdditive() const
{
    BOOL bRet = FALSE;

    if (m_pElement)
    {
        if (m_pElement->m_ucAdditive == kAdditiveSum)
        {
            bRet = TRUE;
        }
    }

    return bRet;
}

BOOL CAnimationSandwichLayer::IsToAnimation() const
{
    BOOL bRet = FALSE;

    if (m_pElement &&
        m_pElement->m_ucAnimationType == kAnimTypeTo)
    {
        bRet = TRUE;
    }

    return bRet;
}

CAttr CAnimationSandwichLayer::AnimationEffectFunction(UINT32 ulTime,
                                                       CAttr* pUnder,
                                                       CAttr* pDepend)
{
    CAttr cRet;

    if (pUnder)
    {
        // Initialize to the underlying value
        cRet = *pUnder;
        // Compute the zero-based time
        UINT32 ulT = ulTime - m_ulDelay; // XXXMEH - is this right?
        // Compute the time after time manipulations
        UINT32 ulTM = ComputeFilteredSimpleTime(ulT);
        // Decide if we're active or frozen
        if (IsActiveZeroBased(ulT))
        {
            // Evaluate the cumulative animation function at this time
            cRet = CumulativeAnimationFunction(ulTM, pUnder, pDepend);
            // Now we need to check if we need to fire a repeatEvent.
            //
            // Compute which iteration the last time was in
            UINT32 ulLastIter = 0;
            if (m_pElement->m_ulSimpleDuration)
            {
                ulLastIter = m_ulLastTime / m_pElement->m_ulSimpleDuration;
            }
            // Compute which iteration we are currently in
            UINT32 ulThisIter = 0;
            if (m_pElement->m_ulSimpleDuration)
            {
                ulThisIter = ulTM / m_pElement->m_ulSimpleDuration;
            }
            // If we are in different iterations, then we will
            // assume that this is the first time in the new iteration
            // and we will fire a "repeatEvent"
            if (ulLastIter != ulThisIter &&
                m_pSmilParser)
            {
                m_pSmilParser->tryToResolveBeginEndEvents("repeatEvent",
                                                          m_pElement->m_pNode->m_id,
                                                          ulTime);
                // XXXMEH - temporarily, we will also fire a "repeat(x)" event
                char szTmp[32]; /* Flawfinder: ignore */
                sprintf(szTmp, "repeat(%lu)", ulThisIter); /* Flawfinder: ignore */
                m_pSmilParser->tryToResolveBeginEndEvents((const char*) szTmp,
                                                          m_pElement->m_pNode->m_id,
                                                          ulTime);
            }
            // Save the last time
            m_ulLastTime = ulTM;
        }
        else if (IsFrozenZeroBased(ulT))
        {
            // We are in the frozen period after the active duration
            //
            // Compute the remainder time
            // XXXMEH - TODO - most of the time this "frozen time"
            // calculation can be done once up front.
            UINT32 ulModTime = 0;

⌨️ 快捷键说明

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