⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 animattr.cpp

📁 著名的 helix realplayer 基于手机 symbian 系统的 播放器全套源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
            dRet = sqrt(dSum);
        }
    }

    return dRet;
}

double CAttr::GetAbsolute(CAttr* pAttr, UINT32 i, CAttr* pDepend)
{
    double dRet = 0.0;

    if (i < kVectorSize)
    {
        dRet = pAttr->m_dValue[i];
        if (pAttr->IsRelative(i) && pDepend && !pDepend->IsRelative(i))
        {
            dRet = pAttr->m_dValue[i] * pDepend->m_dValue[i] / 100.0;
        }
    }

    return dRet;
}

void CAttr::Interp(CAttr* pAttr1, double t1,
                   CAttr* pAttr2, double t2,
                   double t, CAttr* pDepend)
{
    if (Compatible(pAttr1, pAttr2) &&
        t1 < t2 && t1 <= t && t <= t2)
    {
        // Copy the first attribute
        *this = *pAttr1;
        // Perform the interpolation
        if (pAttr1->m_ulAttrType == kAttrTypeRealScalar ||
            pAttr1->m_ulAttrType == kAttrTypeRealVector)
        {
            double dFract = (t - t1) / (t2 - t1);
            for (UINT32 i = 0; i < kVectorSize; i++)
            {
                double d1 = pAttr1->m_dValue[i];
                double d2 = pAttr2->m_dValue[i];
                if (pAttr1->IsRelative(i) != pAttr2->IsRelative(i) &&
                    pDepend && !pDepend->IsRelative(i))
                {
                    // If we are trying to interpolate between
                    // an absolute and relative value, we will first
                    // convert the relative value to absolute
                    if (pAttr1->IsRelative(i) && !pAttr2->IsRelative(i))
                    {
                        // Convert attribute 1 to absolute
                        d1 = GetAbsolute(pAttr1, i, pDepend);
                    }
                    else
                    {
                        // Convert attribute 2 to absolute
                        d2 = GetAbsolute(pAttr2, i, pDepend);
                    }
                    // Since we made sure that both attributes were
                    // absolute, then the result must be absolute as well.
                    m_eType[i] = CSS2TypeLength;
                }
                m_dValue[i] = d1 + (d2 - d1) * dFract;
            }
        }
    }
}

void CAttr::Add(CAttr* pAttr, CAttr* pDepend)
{
    if (Compatible(this, pAttr))
    {
        if (m_ulAttrType == kAttrTypeRealScalar ||
            m_ulAttrType == kAttrTypeRealVector)
        {
            for (UINT32 i = 0; i < kVectorSize; i++)
            {
                double d1 = m_dValue[i];
                double d2 = pAttr->m_dValue[i];
                if (IsRelative(i) != pAttr->IsRelative(i) &&
                    pDepend && !pDepend->IsRelative(i))
                {
                    // If we are trying to add an absolute value
                    // to a relative value, we will first
                    // convert the relative value to absolute
                    if (IsRelative(i) && !pAttr->IsRelative(i))
                    {
                        // Convert attribute 1 to absolute
                        d1 = GetAbsolute(this, i, pDepend);
                    }
                    else
                    {
                        // Convert attribute 2 to absolute
                        d2 = GetAbsolute(pAttr, i, pDepend);
                    }
                    // Since we made sure that both attributes were
                    // absolute, then the result must be absolute as well.
                    m_eType[i] = CSS2TypeLength;
                }
                // Add the values
                m_dValue[i] = d1 + d2;
            }
        }
    }
}

void CAttr::Mult(double dMult)
{
    if (m_ulAttrType == kAttrTypeRealScalar ||
        m_ulAttrType == kAttrTypeRealVector)
    {
        for (UINT32 i = 0; i < kVectorSize; i++)
        {
            m_dValue[i] *= dMult;
        }
    }
}

void CAttr::Clamp()
{
    if (m_ulAttrName == kAttrNameBackgroundColor ||
        m_ulAttrName == kAttrNameColor)
    {
        for (UINT32 i = 0; i < kVectorSize; i++)
        {
            // Round to nearest integer
            m_dValue[i] = floor(m_dValue[i] + 0.5);
            // Clip bottom
            if (m_dValue[i] < 0.0)
            {
                m_dValue[i] = 0.0;
            }
            // Clip top
            if (m_dValue[i] > 255.0)
            {
                m_dValue[i] = 255.0;
            }
        }
    }
    else if (m_ulAttrName == kAttrNameZIndex)
    {
        // Round to nearest integer
        m_dValue[0] = floor(m_dValue[0] + 0.5);
        // Clip bottom
        if (m_dValue[0] < 0.0)
        {
            m_dValue[0] = 0.0;
        }
    }
    else if (m_ulAttrName == kAttrNameSoundLevel)
    {
        // Clip bottom
        if (m_dValue[0] < 0.0)
        {
            m_dValue[0] = 0.0;
        }
    }
    else if (m_ulAttrName == kAttrNameMediaOpacity ||
             m_ulAttrName == kAttrNameBackgroundOpacity)
    {
        // Clip bottom
        if (m_dValue[0] < 0.0)
        {
            m_dValue[0] = 0.0;
        }
        // Clip top
        if (m_dValue[0] > 255.0)
        {
            m_dValue[0] = 255.0;
        }
    }
}

double CAttr::GetValueDouble(UINT32 i) const
{
    double dRet = 0.0;

    if (i < kVectorSize)
    {
        dRet = m_dValue[i];
    }

    return dRet;
}

CSS2Type CAttr::GetCSS2Type(UINT32 i) const
{
    CSS2Type eRet = CSS2TypeAuto;

    if (i < kVectorSize)
    {
        eRet = m_eType[i]; 
    }

    return eRet;
}

BOOL CAttr::IsRelative(UINT32 i) const
{
    BOOL bRet = FALSE;

    if (i < kVectorSize)
    {
        bRet = (m_eType[i] == CSS2TypePercentage ? TRUE : FALSE);
    }

    return bRet;
}

const char* CAttr::GetValueString(UINT32 i) const
{
    return m_pszValue;
}

CAttr& CAttr::operator  = (const CAttr& rAttr)
{
    m_lLastError = rAttr.m_lLastError;
    m_ulAttrName = rAttr.m_ulAttrName;
    m_ulAttrType = rAttr.m_ulAttrType;
    m_dValue[0]  = rAttr.m_dValue[0];
    m_dValue[1]  = rAttr.m_dValue[1];
    m_dValue[2]  = rAttr.m_dValue[2];
    m_dValue[3]  = rAttr.m_dValue[3];
    m_eType[0]   = rAttr.m_eType[0];
    m_eType[1]   = rAttr.m_eType[1];
    m_eType[2]   = rAttr.m_eType[2];
    m_eType[3]   = rAttr.m_eType[3];
    HX_VECTOR_DELETE(m_pszValue);
    if (rAttr.m_pszValue)
    {
        m_pszValue = new char [strlen(rAttr.m_pszValue) + 1];
        if (m_pszValue)
        {
            strcpy(m_pszValue, rAttr.m_pszValue); /* Flawfinder: ignore */
        }
        else
        {
            m_lLastError = HXR_OUTOFMEMORY;
        }
    }
    return *this;
}

BOOL CAttr::Compatible(CAttr* pAttr1, CAttr* pAttr2)
{
    BOOL bRet = FALSE;

    if (pAttr1 && pAttr2)
    {
        if (pAttr1->m_ulAttrName == pAttr2->m_ulAttrName &&
            pAttr1->m_ulAttrType == pAttr2->m_ulAttrType)
        {
            bRet = TRUE;
        }
        else if (pAttr1->m_ulAttrName == kAttrNameLeftTop)
        {
            if (pAttr2->m_ulAttrName == kAttrNameLeft ||
                pAttr2->m_ulAttrName == kAttrNameTop)
            {
                bRet = TRUE;
            }
        }
        else if (pAttr2->m_ulAttrName == kAttrNameLeftTop)
        {
            if (pAttr1->m_ulAttrName == kAttrNameLeft ||
                pAttr1->m_ulAttrName == kAttrNameTop)
            {
                bRet = TRUE;
            }
        }
    }

    return bRet;
}

HX_RESULT CAttr::ParsePosLenValue(const char* pszStr,
                                  double&     rdValue,
                                  BOOL&       rbIsPercent)
{
    HX_RESULT retVal = HXR_OK;

    if (pszStr)
    {
        // Parse the numeric value
        char* pEndPtr = NULL;
        rdValue       = strtod(pszStr, &pEndPtr);
        // Now decide if it was a percent or not
        if (pEndPtr && *pEndPtr == '%')
        {
            rbIsPercent = TRUE;
        }
        else
        {
            rbIsPercent = FALSE;
        }
    }
    else
    {
        retVal = HXR_FAIL;
    }

    return retVal;
}

⌨️ 快捷键说明

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