diff -r 000000000000 -r 15bf7259bb7c uiacceltk/hitchcock/coretoolkit/inc/HuiFxParameter.inl --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/uiacceltk/hitchcock/coretoolkit/inc/HuiFxParameter.inl Tue Feb 02 07:56:43 2010 +0200 @@ -0,0 +1,321 @@ +/* +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +* All rights reserved. +* This component and the accompanying materials are made available +* under the terms of "Eclipse Public License v1.0" +* which accompanies this distribution, and is available +* at the URL "http://www.eclipse.org/legal/epl-v10.html". +* +* Initial Contributors: +* Nokia Corporation - initial contribution. +* +* Contributors: +* +* Description: +* +*/ + +#ifndef HUIFXPARAMETER_INL +#define HUIFXPARAMETER_INL + +#include + +#include "HuiFxTimeLine.h" + +template +CHuiFxGenericParameter::CHuiFxGenericParameter(TYPE* aValue): + iValue(aValue), + iRelValue(*aValue), + iTimeLine(NULL), + iTime(0.0f), + iAnimationFinished(EFalse), + iLastFrameDrawn(EFalse), + iRefPoint(EReferencePointIdentity), + iRefValue(0.0f), + iStartRef(EReferencePointUndefined), + iStartValue(0.0f), + iStartMultiplier(1.0f), + iEndRef(EReferencePointUndefined), + iEndValue(0.0f), + iEndMultiplier(1.0f) + { + } + +void CleanupFxParameterL(MHuiFxParameter* aParameter); + +template +CHuiFxGenericParameter *CHuiFxGenericParameter::CloneL() const +{ + CHuiFxGenericParameter *p = new (ELeave) CHuiFxGenericParameter(iValue); + p->iRelValue = iRelValue; + if (iTimeLine) + { + CleanupFxParameterL(p); + p->iTimeLine = iTimeLine->CloneL(); + CleanupStack::Pop(); + } + else + { + p->iTimeLine = NULL; + } + p->iTime = iTime; + p->iAnimationFinished = iAnimationFinished; + p->iLastFrameDrawn = iLastFrameDrawn; + p->iRefPoint = iRefPoint; + p->iRefValue = iRefValue; + p->iStartRef = iStartRef; + p->iStartValue = iStartValue; + p->iStartMultiplier = iStartMultiplier; + p->iEndRef = iEndRef; + p->iEndValue = iEndValue; + p->iEndMultiplier = iEndMultiplier; + p->iValue = iValue; + return p; +} +void ReRefInternal(TReal32 *aValue, TReal32 **aValue2); +void ReRefInternal(TRgb *aValue, TRgb **aValue2); +void ReRefInternal(TReal32 *aValue, TRgb **aValue2); +void ReRefInternal(TRgb *aValue, TReal32 **aValue2); + +template +void CHuiFxGenericParameter::ReRef(TReal32 *aValue) + { + ReRefInternal(aValue, &iValue); + } +template +void CHuiFxGenericParameter::ReRef(TRgb *aValue) + { + ReRefInternal(aValue, &iValue); + } +template +CHuiFxGenericParameter::~CHuiFxGenericParameter() + { + delete iTimeLine; + iTimeLine = NULL; + } + +template +void CHuiFxGenericParameter::SetTimeLine(TIMELINE_TYPE* aTimeLine) + { + if (iTimeLine != aTimeLine) + { + delete iTimeLine; + iTimeLine = aTimeLine; + iAnimationFinished = EFalse; + iLastFrameDrawn = EFalse; + } + } + +template +void CHuiFxGenericParameter::SetValue(TYPE aValue) + { + iRelValue = *iValue = aValue; + } + +template +THuiFxParameterType CHuiFxGenericParameter::Type() const + { + return TYPE_CODE; + } + +template +TBool CHuiFxGenericParameter::IsAnimated() const + { + if (!iTimeLine) + { + return EFalse; + } + return !iAnimationFinished; + } + +template +void CHuiFxGenericParameter::SetReferencePoint(THuiFxReferencePoint aRef) + { + iRefPoint = aRef; + } + +template +THuiFxReferencePoint CHuiFxGenericParameter::ReferencePoint() const + { + return iRefPoint; + } + +template +void CHuiFxGenericParameter::SetReferenceValue(TReal32 aValue) + { + iRefValue = aValue; + } + +template +TReal32 CHuiFxGenericParameter::ReferenceValue() const + { + return iRefValue; + } + +template +void CHuiFxGenericParameter::SetStartReference(THuiFxReferencePoint aRef) + { + iStartRef = aRef; + } + +template +THuiFxReferencePoint CHuiFxGenericParameter::StartReference() const + { + return iStartRef; + } + +template +void CHuiFxGenericParameter::SetStartValue(TReal32 aValue) + { + iStartValue = aValue; +// RDebug::Print(_L("parameter iStartValue = %f"), iStartValue ); + } + +template +void CHuiFxGenericParameter::SetStartMultiplier(TReal32 aValue) + { + iStartMultiplier = aValue; +// RDebug::Print(_L("parameter iStartValue = %f"), iStartValue ); + } + + +template +TReal32 CHuiFxGenericParameter::StartValue() const + { + return iStartValue; + } + +template +void CHuiFxGenericParameter::SetEndReference(THuiFxReferencePoint aRef) + { + iEndRef = aRef; + } + +template +THuiFxReferencePoint CHuiFxGenericParameter::EndReference() const + { + return iEndRef; + } + +template +void CHuiFxGenericParameter::SetEndValue(TReal32 aValue) + { + iEndValue = aValue; +// RDebug::Print(_L("parameter iEndValue = %f"), iEndValue ); + } + +template +TReal32 CHuiFxGenericParameter::EndValue() const + { + return iEndValue; + } + +template +void CHuiFxGenericParameter::SetEndMultiplier(TReal32 aValue) + { + iEndMultiplier = aValue; +// RDebug::Print(_L("parameter iStartValue = %f"), iStartValue ); + } + + +template +void CHuiFxGenericParameter::AdvanceTime(TReal32 aElapsedTime) + { + if (!iTimeLine) + { + return; + } + + iTime += aElapsedTime; + + switch (iTimeLine->LoopingMode()) + { + case ELoopingModeRepeat: + { + // TODO: precalc + // TODO: keep everything in fixed point + TInt fpLoopStart = (TInt)(iTimeLine->LoopStart() * iTimeLine->Duration() * 0x10000); + TInt fpLoopEnd = (TInt)(iTimeLine->LoopEnd() * iTimeLine->Duration() * 0x10000); + TInt fpTime = (TInt)(iTime * 0x10000); + + if (fpLoopEnd - fpLoopStart > 0) + { + fpTime = fpLoopStart + ((fpTime - fpLoopStart) % (fpLoopEnd - fpLoopStart)); + } + else + { + fpTime = fpLoopEnd; + } + iTime = fpTime / (TReal32)0x10000; + break; + } + case ELoopingModeNone: + if (iTime > iTimeLine->Duration()) + { + if ( iLastFrameDrawn ) + { + iAnimationFinished = ETrue; + } + else + { + iLastFrameDrawn = ETrue; + } + } + break; + } + } + +template +void CHuiFxGenericParameter::Update() + { + // Calculate the current value + if (iTimeLine) + { + iRelValue = iTimeLine->ValueAt(iTime); +// RDebug::Print(_L("parameter rel value = %f at time %f"), iRelValue, iTime ); + } + + TBool extRefUsed = ( iStartRef != EReferencePointUndefined && iEndRef != EReferencePointUndefined ); + + if ( extRefUsed ) + { + // mix start and end values + // Note: this will break horribly for anything other than scalar values + ASSERT(TYPE_CODE == EParameterTypeScalar); +// *iValue = ( 1 - (*reinterpret_cast(&iRelValue)) ) * iStartValue + (*reinterpret_cast(&iRelValue)) * iEndValue; + iRelValue = ( 1 - (*reinterpret_cast(&iRelValue)) ) * iStartValue * iStartMultiplier + (*reinterpret_cast(&iRelValue)) * iEndValue * iEndMultiplier; +// RDebug::Print(_L("parameter with extrect %f at time %f"), iRelValue, iTime); + } + + // Transform by the reference point + switch (iRefPoint) + { + case EReferencePointIdentity: + case EReferencePointUndefined: + *iValue = iRelValue; + break; + default: + // Note: this will break horribly for anything other than scalar values + ASSERT(TYPE_CODE == EParameterTypeScalar); + if ( extRefUsed ) + { + if ( iRefValue != 0 ) + { + *iValue = (*reinterpret_cast(&iRelValue)) / iRefValue; + } + else + { + // If the reference value is 0, no calculations make sense. + *iValue = iRefValue; + } +// RDebug::Print(_L("scaled parameter with extrect %f at time %f"), *iValue, iTime); + } + else + { + *iValue = (*reinterpret_cast(&iRelValue)) * iRefValue; + } + break; + } + } + +#endif // HUIFXPARAMETER_INL