X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=plugins%2Fdali-script-v8%2Fsrc%2Fanimation%2Fanimation-api.cpp;h=3a63034067376376eeb05ff8b1b4dc619878c624;hp=3fba14a23eaa1598ecb9c95319c1cbccff1aeb5b;hb=556f077c8d4e57a7afdcffea9968feebefc0cf18;hpb=e8efa9549ccedae5b8377c9eb331aa8392895879 diff --git a/plugins/dali-script-v8/src/animation/animation-api.cpp b/plugins/dali-script-v8/src/animation/animation-api.cpp index 3fba14a..3a63034 100644 --- a/plugins/dali-script-v8/src/animation/animation-api.cpp +++ b/plugins/dali-script-v8/src/animation/animation-api.cpp @@ -19,12 +19,14 @@ #include "animation-api.h" #include "path-wrapper.h" +// EXTERNAL INCLUDES +#include + + // INTERNAL INCLUDES #include -#include #include #include -#include namespace Dali { @@ -35,94 +37,11 @@ namespace V8Plugin namespace // un named namespace { -// @todo think about alternative ways of passing around -struct AlphaFuncStruct -{ - const char* const name; - AlphaFunction alphaFunc; -}; -/** - * Contains a list of alpha functions that can be used. - * We use a stl map as lookup to map a string name to the function - */ -const AlphaFuncStruct AlphaFunctionTable[]= -{ - {"default" , AlphaFunctions::Default }, - {"linear" , AlphaFunctions::Linear }, - {"square" , AlphaFunctions::Square }, - {"reverse" , AlphaFunctions::Reverse }, - {"easeIn" , AlphaFunctions::EaseIn }, - {"easeOut" , AlphaFunctions::EaseOut }, - {"easeInOut" , AlphaFunctions::EaseInOut }, - {"easeInSine" , AlphaFunctions::EaseInSine }, - {"easeOutSine" , AlphaFunctions::EaseOutSine }, - {"easeInOutSine" , AlphaFunctions::EaseInOutSine }, - {"easeInSine33" , AlphaFunctions::EaseInSine33 }, - {"easeOutSine33" , AlphaFunctions::EaseOutSine33 }, - {"easeInOutSine33" , AlphaFunctions::EaseInOutSine33 }, - {"easeInOutSine50" , AlphaFunctions::EaseInOutSine50 }, - {"easeInOutSine60" , AlphaFunctions::EaseInOutSine60 }, - {"easeInOutSine70" , AlphaFunctions::EaseInOutSine70 }, - {"easeInOutSine80" , AlphaFunctions::EaseInOutSine80 }, - {"easeInOutSine90" , AlphaFunctions::EaseInOutSine90 }, - {"doubleEaseInOutSine60" , AlphaFunctions::DoubleEaseInOutSine60}, - {"easeOutQuint50" , AlphaFunctions::EaseOutQuint50 }, - {"easeOutQuint80" , AlphaFunctions::EaseOutQuint80 }, - {"bounce" , AlphaFunctions::Bounce }, - {"bounceBack" , AlphaFunctions::BounceBack }, - {"easeInBack" , AlphaFunctions::EaseInBack }, - {"easeOutBack" , AlphaFunctions::EaseOutBack }, - {"easeInOutBack" , AlphaFunctions::EaseInOutBack }, - {"sin" , AlphaFunctions::Sin }, - {"sin2x" , AlphaFunctions::Sin2x } -}; -const unsigned int AlphaFunctionTableCount = sizeof(AlphaFunctionTable)/sizeof(AlphaFunctionTable[0]); -const char* const DEFAULT_ALPHA_NAME = "default"; -static AlphaFunction DEFAULT_ALPHA_FUNCTION = AlphaFunctions::Default; - - - -AlphaFunction GetAlphaFunction( const std::string& alphaFuncName ) -{ - // This will normally get called just a few times during the application, so no point in doing anything clever - for( unsigned int i = 0; i < AlphaFunctionTableCount; i++) - { - const AlphaFuncStruct& alphaStruct( AlphaFunctionTable[i] ); - - if( std::strcmp( alphaStruct.name , alphaFuncName.c_str() ) == 0 ) - { - return alphaStruct.alphaFunc; - } - } - - DALI_LOG_ERROR("Failed to find alpha func |%s| \n", alphaFuncName.c_str() ); - return AlphaFunctions::Default; -} - -const char* const GetAlphaFunctionName( AlphaFunction alphaFunc ) -{ - // This may get called 3 times during the application, so no point - // in doing anything clever - - for( unsigned int i = 0; i < AlphaFunctionTableCount; i++) - { - const AlphaFuncStruct& alphaStruct( AlphaFunctionTable[i] ); - - - if( alphaStruct.alphaFunc == alphaFunc ) - { - return alphaStruct.name; - } - } - return "default"; -} - - struct AnimationParameters { AnimationParameters( const Animation& anim) : propertyIndex( Property::INVALID_INDEX ), - alphaFunction( DEFAULT_ALPHA_FUNCTION), + alphaFunction( AlphaFunction::DEFAULT), delay( 0.f ), duration(anim.GetDuration()), optionsFound( false ) @@ -156,11 +75,10 @@ void GetAnimationOptions( v8::Isolate* isolate, { v8::Local obj = options->ToObject(); v8::Local alphaValue = obj->Get( v8::String::NewFromUtf8( isolate, "alpha" ) ); - if( alphaValue->IsString() ) + if( alphaValue->IsUint32() ) { animParams.optionsFound = true; - std::string alphaName = V8Utils::v8StringToStdString( alphaValue ); - animParams.alphaFunction = GetAlphaFunction( alphaName ); + animParams.alphaFunction = static_cast(alphaValue->ToUint32()->Value()); } v8::Local delayValue = obj->Get( v8::String::NewFromUtf8( isolate, "delay" ) ); @@ -231,10 +149,9 @@ KeyFrames GetKeyFrames( v8::Isolate* isolate, v8::Local keyFrameArra // get keyframe.alpha v8::Handle alphaValue = keyFrameObject->Get(v8::String::NewFromUtf8( isolate, "alpha")); - if( alphaValue->IsString() ) + if( alphaValue->IsUint32() ) { - std::string alphaName = V8Utils::v8StringToStdString( alphaValue ); - AlphaFunction alphaFunction = GetAlphaFunction( alphaName ); + AlphaFunction alphaFunction = static_cast(alphaValue->ToUint32()->Value()); keyframes.Add( progress->NumberValue(), value, alphaFunction ); } else @@ -251,9 +168,9 @@ bool GetAnimationParameters( v8::Isolate* isolate, AnimationParameters& animParams, AnimationApi::AnimationParameterType type) { - // used for things like anim.AnimateBy( myImageActor, property-name, property-value (or Javascript number array)); + // used for things like anim.AnimateBy( myImageView, property-name, property-value (or Javascript number array)); // 1 extract property handle from param1. - // 2 extract property name from param2 ( can be in the format "u-color" or "uColor" + // 2 extract property name from param2 ( in the format "uColor" ) // 3 extract PropertyValue from param3 // 4 extract animation options ( delay, duration, alpha func) @@ -279,9 +196,7 @@ bool GetAnimationParameters( v8::Isolate* isolate, if( index == Property::INVALID_INDEX ) { - // convert the property name from "uColor" to "u-color" - std::string convetedName = V8Utils::JavaScriptNameToPropertyName( propertyName ); - index = animParams.target.GetPropertyIndex( convetedName ); + index = animParams.target.GetPropertyIndex( propertyName ); } animParams.propertyIndex = index; @@ -537,7 +452,7 @@ void AnimationApi::GetDisconnectAction( const v8::FunctionCallbackInfo< v8::Valu * Set the default alpha function for an animation. * @method setDefaultAlphaFunction * @for Animation - * @param {string} alpha function + * @param {Integer} alpha function */ void AnimationApi::SetDefaultAlphaFunction( const v8::FunctionCallbackInfo< v8::Value >& args ) { @@ -547,23 +462,22 @@ void AnimationApi::SetDefaultAlphaFunction( const v8::FunctionCallbackInfo< v8:: Animation anim = GetAnimation( isolate, args ); bool found( false ); - std::string alphaFunc = V8Utils::GetStringParameter( PARAMETER_0, found, isolate, args ); + int alphaFunc = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 ); if( !found ) { DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" ); } else { - AlphaFunction func = GetAlphaFunction( alphaFunc ); + AlphaFunction func = static_cast(alphaFunc); anim.SetDefaultAlphaFunction( func ); } - } /** * Get the default alpha function for an animation. * @method getDefaultAlphaFunction * @for Animation - * @return {string} alpha function + * @return {Integer} alpha function */ void AnimationApi::GetDefaultAlphaFunction( const v8::FunctionCallbackInfo& args ) { @@ -572,10 +486,10 @@ void AnimationApi::GetDefaultAlphaFunction( const v8::FunctionCallbackInfo& args ) * * // animation x position * var anim = new dali.Animation( 1 ); - * anim.animateBy( imageActor,"positionX", 30 ); + * anim.animateBy( actor,"positionX", 30 ); * anim.play(); * * // animate x,y,z position with the optional animation options @@ -921,7 +835,7 @@ void AnimationApi::Animate( const v8::FunctionCallbackInfo& args ) * alpha:"easeInOutSine" // Speeds up and slows to a gradual stop * } * - * anim.animateBy( imageActor,"position", [100,200,0], options ); + * anim.animateBy( actor,"position", [100,200,0], options ); * */ void AnimationApi::AnimateBy( const v8::FunctionCallbackInfo& args ) @@ -972,7 +886,7 @@ void AnimationApi::AnimateBy( const v8::FunctionCallbackInfo& args ) * @example * * var anim = new dali.Animation( 1 ); - * anim.animateTo( imageActor,"positionX", 30 ); + * anim.animateTo( actor,"positionX", 30 ); * anim.play(); * * @@ -983,7 +897,7 @@ void AnimationApi::AnimateBy( const v8::FunctionCallbackInfo& args ) * alpha:"easeInOutSine" // Speeds up and slows to a gradual stop * } * - * anim.animateTo( imageActor,"position", [100,200,0], options ); + * anim.animateTo( actor,"position", [100,200,0], options ); * */ void AnimationApi::AnimateTo( const v8::FunctionCallbackInfo< v8::Value >& args ) @@ -1036,7 +950,7 @@ void AnimationApi::AnimateTo( const v8::FunctionCallbackInfo< v8::Value >& args * * create some keyframes to move an actor around a square, and return to the start *
- * + * * * * var keyframes = [ @@ -1063,7 +977,7 @@ void AnimationApi::AnimateTo( const v8::FunctionCallbackInfo< v8::Value >& args * } ]; * * - * anim.animateBetween( imageActor,"position", keyframes ); + * anim.animateBetween( actor,"position", keyframes ); * */ void AnimationApi::AnimateBetween( const v8::FunctionCallbackInfo< v8::Value >& args )