2 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 #include "animation-api.h"
20 #include "path-wrapper.h"
23 #include <cstring> // for strcmp
24 #include <dali/integration-api/debug.h>
29 #include <animation/animation-wrapper.h>
30 #include <object/property-value-wrapper.h>
38 namespace // un named namespace
41 // @todo think about alternative ways of passing around
42 struct AlphaFuncStruct
44 const char* const name;
45 AlphaFunction alphaFunc;
48 * Contains a list of alpha functions that can be used.
50 const AlphaFuncStruct AlphaFunctionTable[]=
53 {"default" , AlphaFunction::DEFAULT },
54 {"linear" , AlphaFunction::LINEAR },
55 {"reverse" , AlphaFunction::REVERSE },
57 {"easeInSquare" , AlphaFunction::EASE_IN_SQUARE },
58 {"easeOutSquare" , AlphaFunction::EASE_OUT_SQUARE },
60 {"easeIn" , AlphaFunction::EASE_IN },
61 {"easeOut" , AlphaFunction::EASE_OUT },
62 {"easeInOut" , AlphaFunction::EASE_IN_OUT },
64 {"easeInSine" , AlphaFunction::EASE_IN_SINE },
65 {"easeOutSine" , AlphaFunction::EASE_OUT_SINE },
66 {"easeInOutSine" , AlphaFunction::EASE_IN_OUT_SINE },
68 {"bounce" , AlphaFunction::BOUNCE },
69 {"sin" , AlphaFunction::SIN },
70 {"easeOutBack" , AlphaFunction::EASE_OUT_BACK },
73 const unsigned int AlphaFunctionTableCount = sizeof(AlphaFunctionTable)/sizeof(AlphaFunctionTable[0]);
74 const char* const DEFAULT_ALPHA_NAME = "default";
75 static AlphaFunction DEFAULT_ALPHA_FUNCTION = AlphaFunction::DEFAULT;
79 AlphaFunction GetAlphaFunction( const std::string& alphaFuncName )
81 // This will normally get called just a few times during the application, so no point in doing anything clever
82 for( unsigned int i = 0; i < AlphaFunctionTableCount; i++)
84 const AlphaFuncStruct& alphaStruct( AlphaFunctionTable[i] );
86 if( std::strcmp( alphaStruct.name , alphaFuncName.c_str() ) == 0 )
88 return alphaStruct.alphaFunc;
92 DALI_LOG_ERROR("Failed to find alpha func |%s| \n", alphaFuncName.c_str() );
93 return DEFAULT_ALPHA_FUNCTION;
96 const char* const GetAlphaFunctionName( AlphaFunction alphaFunc )
98 // This may get called 3 times during the application, so no point
99 // in doing anything clever
101 for( unsigned int i = 0; i < AlphaFunctionTableCount; i++)
103 const AlphaFuncStruct& alphaStruct( AlphaFunctionTable[i] );
106 if( alphaStruct.alphaFunc.GetBuiltinFunction() == alphaFunc.GetBuiltinFunction() )
108 return alphaStruct.name;
115 struct AnimationParameters
117 AnimationParameters( const Animation& anim)
118 : propertyIndex( Property::INVALID_INDEX ),
119 alphaFunction( DEFAULT_ALPHA_FUNCTION),
121 duration(anim.GetDuration()),
122 optionsFound( false )
127 Property::Index propertyIndex;
128 Property::Value value;
130 AlphaFunction alphaFunction;
136 void GetAnimationOptions( v8::Isolate* isolate,
137 v8::Local<v8::Value > options,
138 AnimationParameters& animParams )
140 // animation options is an optional parameter passed in which holds
142 // var animOptions = {
147 v8::HandleScope handleScope( isolate );
149 if( options->IsObject() )
151 v8::Local<v8::Object> obj = options->ToObject();
152 v8::Local<v8::Value> alphaValue = obj->Get( v8::String::NewFromUtf8( isolate, "alpha" ) );
153 if( alphaValue->IsString() )
155 animParams.optionsFound = true;
156 std::string alphaName = V8Utils::v8StringToStdString( alphaValue );
157 animParams.alphaFunction = GetAlphaFunction( alphaName );
160 v8::Local<v8::Value> delayValue = obj->Get( v8::String::NewFromUtf8( isolate, "delay" ) );
161 if( delayValue->IsNumber() )
163 animParams.optionsFound = true;
164 v8::Local<v8::Number> num = delayValue->ToNumber();
165 animParams.delay = num->Value();
168 v8::Local<v8::Value> durationValue = obj->Get( v8::String::NewFromUtf8( isolate, "duration" ) );
169 if( durationValue->IsNumber() )
171 animParams.optionsFound = true;
172 v8::Local<v8::Number> num = durationValue->ToNumber();
173 animParams.duration = num->Value();
178 KeyFrames GetKeyFrames( v8::Isolate* isolate, v8::Local<v8::Value > keyFrameArray )
180 // keyframe object is an array of
183 // value: property value ( position/ rotation etc)
186 v8::HandleScope handleScope( isolate );
188 if( !keyFrameArray->IsObject() || !keyFrameArray->IsArray() )
190 DALI_SCRIPT_EXCEPTION( isolate, "missing keyframe array" );
194 KeyFrames keyframes = KeyFrames::New();
196 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast( keyFrameArray );
197 for( uint32_t i=0; i < array->Length() ; ++i)
199 v8::Handle<v8::Value> arrayItem = array->Get( i );
201 if(!arrayItem->IsObject() )
203 DALI_SCRIPT_EXCEPTION( isolate, "missing keyframe object" );
206 v8::Handle<v8::Object> keyFrameObject = arrayItem->ToObject();
208 // get keyframe.progress
209 v8::Handle<v8::Value> progress = keyFrameObject->Get(v8::String::NewFromUtf8( isolate, "progress"));
210 if( !progress->IsNumber() )
212 DALI_SCRIPT_EXCEPTION( isolate, "keyframe missing progress property" );
216 // get keyframe.value
218 v8::Handle<v8::Value> propertyValue = keyFrameObject->Get(v8::String::NewFromUtf8( isolate, "value"));
219 Property::Value value = V8Utils::GetPropertyValueFromObject( found, isolate, propertyValue );
222 DALI_SCRIPT_EXCEPTION( isolate, "keyframe missing value property" );
226 // get keyframe.alpha
227 v8::Handle<v8::Value> alphaValue = keyFrameObject->Get(v8::String::NewFromUtf8( isolate, "alpha"));
228 if( alphaValue->IsString() )
230 std::string alphaName = V8Utils::v8StringToStdString( alphaValue );
231 AlphaFunction alphaFunction = GetAlphaFunction( alphaName );
232 keyframes.Add( progress->NumberValue(), value, alphaFunction );
236 keyframes.Add( progress->NumberValue(), value );
243 bool GetAnimationParameters( v8::Isolate* isolate,
244 const v8::FunctionCallbackInfo< v8::Value >& args,
245 AnimationParameters& animParams,
246 AnimationApi::AnimationParameterType type)
248 // used for things like anim.AnimateBy( myImageActor, property-name, property-value (or Javascript number array));
249 // 1 extract property handle from param1.
250 // 2 extract property name from param2 ( in the format "uColor" )
251 // 3 extract PropertyValue from param3
252 // 4 extract animation options ( delay, duration, alpha func)
256 animParams.target = V8Utils::GetHandleParameter( PARAMETER_0, foundHandle, isolate, args );
259 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 0 (Handle)" );
263 // 2 extract property name
265 std::string propertyName = V8Utils::GetStringParameter( PARAMETER_1, foundPropName, isolate, args );
268 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 1 ( PropertyName )" );
271 // try both properties with dashes and without
272 Property::Index index = animParams.target.GetPropertyIndex( propertyName );
274 if( index == Property::INVALID_INDEX )
276 index = animParams.target.GetPropertyIndex( propertyName );
279 animParams.propertyIndex = index;
281 if( type == AnimationApi::PROPERTY_VALUE )
283 // 3 extract property value
284 bool foundPropValue( false );
285 animParams.value = V8Utils::GetPropertyValueParameter( PARAMETER_2, foundPropValue, isolate, args );
286 if( !foundPropValue )
288 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 2 ( value )" );
292 else // type == KEYFRAMES
294 animParams.keyFrames = GetKeyFrames(isolate, args[2]);
296 // 4 extract animation options
297 GetAnimationOptions( isolate, args[3], animParams );
302 Animation GetAnimation( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
304 v8::HandleScope handleScope( isolate );
306 v8::Local<v8::Object> object = args.This();
307 v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField( 0 ) );
308 void* ptr = field->Value();
310 AnimationWrapper* wrapper = static_cast<AnimationWrapper *>( ptr );
311 return wrapper->GetAnimation();
315 } // un-named namespace
323 * @param {float} duration
326 Animation AnimationApi::New( const v8::FunctionCallbackInfo< v8::Value >& args )
328 v8::Isolate* isolate = args.GetIsolate();
329 v8::HandleScope handleScope( isolate );
332 float value = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 1.f /* default */);
335 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
339 return Animation::New( value );
343 * Set the animation duration.
344 * @method setDuration
346 * @param {float} duration in seconds
349 void AnimationApi::SetDuration( const v8::FunctionCallbackInfo< v8::Value >& args )
351 v8::Isolate* isolate = args.GetIsolate();
352 v8::HandleScope handleScope( isolate );
354 Animation anim = GetAnimation( isolate, args );
357 float value = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 1.f /* default */);
360 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
363 anim.SetDuration( value );
366 * Get the animation duration.
367 * @method getDuration
369 * @return {float} duration in seconds
372 void AnimationApi::GetDuration( const v8::FunctionCallbackInfo< v8::Value >& args )
374 v8::Isolate* isolate = args.GetIsolate();
375 v8::HandleScope handleScope( isolate );
377 Animation anim = GetAnimation( isolate, args );
379 args.GetReturnValue().Set( v8::Number::New( isolate, anim.GetDuration() ) );
383 * Set whether the animation will loop.
386 * @param {bool} looping enabled
389 void AnimationApi::SetLooping( const v8::FunctionCallbackInfo< v8::Value >& args )
391 v8::Isolate* isolate = args.GetIsolate();
392 v8::HandleScope handleScope( isolate );
394 Animation anim = GetAnimation( isolate, args );
397 bool value = V8Utils::GetBooleanParameter( PARAMETER_0, found, isolate, args );
400 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
404 anim.SetLooping( value );
409 * Query whether the animation will loop.
412 * @return {bool} looping enabled
415 void AnimationApi::IsLooping( const v8::FunctionCallbackInfo< v8::Value >& args )
417 v8::Isolate* isolate = args.GetIsolate();
418 v8::HandleScope handleScope( isolate );
420 Animation anim = GetAnimation( isolate, args );
422 args.GetReturnValue().Set( v8::Boolean::New( isolate, anim.IsLooping() ) );
426 * Set the end action of the animation.
428 * This action is performed when the animation ends.
429 * Default end action is bake
430 * @method setEndAction
432 * @param {integer} bake mode
434 * anim.setEndAction( dali.ANIMATION_BAKE ); // When the animation ends, the animated property values are saved.
435 * anim.setEndAction( dali.ANIMATION_DISCARD ); // When the animation ends, the animated property values are forgotten.
436 * anim.setEndAction( dali.ANIMATION_BAKE_FINAL ); // If the animation is stopped, the animated property values are saved as if the animation had run to completion, otherwise behaves like Bake.
438 void AnimationApi::SetEndAction( const v8::FunctionCallbackInfo< v8::Value >& args )
440 v8::Isolate* isolate = args.GetIsolate();
441 v8::HandleScope handleScope( isolate );
443 Animation anim = GetAnimation( isolate, args );
446 int value = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
449 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
453 anim.SetEndAction( static_cast<Animation::EndAction>( value ) );
458 * Returns the end action of the animation.
460 * @method getEndAction
462 * @return {integer} bake mode
464 * There are 3 different bake modes
466 * dali.ANIMATION_BAKE // When the animation ends, the animated property values are saved.
467 * dali.ANIMATION_DISCARD // When the animation ends, the animated property values are forgotten.
468 * dali.ANIMATION_BAKE_FINAL // If the animation is stopped, the animated property values are saved as if the animation had run to completion, otherwise behaves like Bake.
470 void AnimationApi::GetEndAction( const v8::FunctionCallbackInfo< v8::Value >& args )
472 v8::Isolate* isolate = args.GetIsolate();
473 v8::HandleScope handleScope( isolate );
475 Animation anim = GetAnimation( isolate, args );
477 args.GetReturnValue().Set( v8::Integer::New( isolate, anim.GetEndAction() ) );
481 * Set the disconnect action of the animation.
482 * If any of the animated property owners are disconnected from the stage, this action is performed.
483 * Default disconnection action is BakeFinal.
484 * @method setDisconnectAction
486 * @param {integer} end mode
488 * There are 3 different end modes
490 * dali.ANIMATION_BAKE // When the animation is destroyed, the animated property values are saved.
491 * dali.ANIMATION_DISCARD // When the animation is destroyed, the animated property values are forgotten.
492 * dali.ANIMATION_BAKE_FINAL // When the animation is destroyed, the animated property values are saved as if the animation had run to completion, otherwise behaves like Bake.
494 void AnimationApi::SetDisconnectAction( const v8::FunctionCallbackInfo< v8::Value >& args )
496 v8::Isolate* isolate = args.GetIsolate();
497 v8::HandleScope handleScope( isolate );
499 Animation anim = GetAnimation( isolate, args );
502 int value = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
505 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
509 anim.SetDisconnectAction( static_cast<Animation::EndAction>( value ) );
514 * Returns the disconnect action of the animation.
515 * @method getDisconnectAction
517 * @return {integer} end mode
519 void AnimationApi::GetDisconnectAction( const v8::FunctionCallbackInfo< v8::Value >& args )
521 v8::Isolate* isolate = args.GetIsolate();
522 v8::HandleScope handleScope( isolate );
524 Animation anim = GetAnimation( isolate, args );
526 args.GetReturnValue().Set( v8::Integer::New( isolate, anim.GetDisconnectAction() ) );
529 * Set the default alpha function for an animation.
530 * @method setDefaultAlphaFunction
532 * @param {string} alpha function
534 void AnimationApi::SetDefaultAlphaFunction( const v8::FunctionCallbackInfo< v8::Value >& args )
536 v8::Isolate* isolate = args.GetIsolate();
537 v8::HandleScope handleScope( isolate );
539 Animation anim = GetAnimation( isolate, args );
542 std::string alphaFunc = V8Utils::GetStringParameter( PARAMETER_0, found, isolate, args );
545 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
549 AlphaFunction func = GetAlphaFunction( alphaFunc );
550 anim.SetDefaultAlphaFunction( func );
555 * Get the default alpha function for an animation.
556 * @method getDefaultAlphaFunction
558 * @return {string} alpha function
560 void AnimationApi::GetDefaultAlphaFunction( const v8::FunctionCallbackInfo<v8::Value>& args )
562 v8::Isolate* isolate = args.GetIsolate();
563 v8::HandleScope handleScope( isolate );
565 Animation anim = GetAnimation( isolate, args );
567 std::string alphaName = GetAlphaFunctionName( anim.GetDefaultAlphaFunction() );
570 args.GetReturnValue().Set( v8::String::NewFromUtf8( isolate, alphaName.c_str() ) );
574 * Get the current progress of the animation.
575 * @method getCurrentProgress
577 * @return {float} The current progress as a normalized value between [0..1].
580 void AnimationApi::GetCurrentProgress( const v8::FunctionCallbackInfo< v8::Value >& args )
582 v8::Isolate* isolate = args.GetIsolate();
583 v8::HandleScope handleScope( isolate );
585 Animation anim = GetAnimation( isolate, args );
587 args.GetReturnValue().Set( v8::Number::New( isolate, anim.GetCurrentProgress() ) );
591 * Specifies an speed factor for the animation.
593 * The speed factor is a multiplier of the normal velocity of the animation. Values between [0,1] will
594 * slow down the animation and values above one will speed up the animation. It is also possible to specify a negative multiplier
595 * to play the animation in reverse.
597 * @method setSpeedFactor
599 * @param {float} value which will multiply the velocity.
601 * anim.setSpeedFactor(2);
602 * anim.play(); // plays the animation twice as fast
605 * anim.setSpeedFactor(0.5);
606 * anim.play(); // plays the animation half speed
609 void AnimationApi::SetSpeedFactor( const v8::FunctionCallbackInfo< v8::Value >& args )
611 v8::Isolate* isolate = args.GetIsolate();
612 v8::HandleScope handleScope( isolate );
614 Animation anim = GetAnimation( isolate, args );
617 float speedFactor = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 0.f );
620 DALI_SCRIPT_EXCEPTION( isolate, "float parameter missing" );
624 anim.SetSpeedFactor( speedFactor );
630 * Retrieve the speed factor of the animation
633 * @method getSpeedFactor
635 * @return {float} speed factor
637 void AnimationApi::GetSpeedFactor( const v8::FunctionCallbackInfo< v8::Value >& args )
639 v8::Isolate* isolate = args.GetIsolate();
640 v8::HandleScope handleScope( isolate );
642 Animation anim = GetAnimation( isolate, args );
644 args.GetReturnValue().Set( v8::Number::New( isolate, anim.GetSpeedFactor() ) );
648 * Set the playing range.
649 * Animation will play between the values specified.
650 * Both values ( range.x and range.y ) should be between 0-1,
651 * otherwise they will be ignored.
652 * If the range provided is not in proper order ( minimum,maximum), it will be reordered.
653 * @method setPlayRange
655 * @param {Object} Range
656 * @param {Float} Range.start
657 * @param {Float} Range.end
659 * var range = { start:0.1, end:0.6 };
660 * anim.setPlayRange( range );
662 void AnimationApi::SetPlayRange( const v8::FunctionCallbackInfo< v8::Value >& args )
664 v8::Isolate* isolate = args.GetIsolate();
665 v8::HandleScope handleScope( isolate );
667 Animation anim = GetAnimation( isolate, args );
670 if( args.Length() != 1 )
672 DALI_SCRIPT_EXCEPTION( isolate, "missing / invalid parameters" );
675 v8::Local<v8::Value > rangeValue = args[0];
676 if( !rangeValue->IsObject() )
678 DALI_SCRIPT_EXCEPTION( isolate, "invalid parameters" );
681 v8::Local<v8::Object> obj = rangeValue->ToObject();
682 v8::Local<v8::Value> startValue = obj->Get( v8::String::NewFromUtf8( isolate, "start" ) );
683 v8::Local<v8::Value> endValue = obj->Get( v8::String::NewFromUtf8( isolate, "end" ) );
685 if( startValue->IsNumber() && endValue->IsNumber())
687 range.x= startValue->ToNumber()->Value();
688 range.y = endValue->ToNumber()->Value();
692 DALI_SCRIPT_EXCEPTION( isolate, "missing start/end value" );
696 anim.SetPlayRange( range );
701 * Get the playing range.
702 * @method getPlayRange
704 * @return {Object} Range with { start: , end: } properties.
706 void AnimationApi::GetPlayRange( const v8::FunctionCallbackInfo< v8::Value >& args )
708 v8::Isolate* isolate = args.GetIsolate();
709 v8::EscapableHandleScope handleScope( isolate );
710 Animation anim = GetAnimation( isolate, args );
713 v8::Local<v8::Object> rangeObject = v8::Object::New( isolate );
715 Vector2 range = anim.GetPlayRange();
718 rangeObject->Set( v8::String::NewFromUtf8( isolate, "start"), v8::Number::New( isolate,range.x ));
721 rangeObject->Set( v8::String::NewFromUtf8( isolate, "end"), v8::Number::New( isolate,range.y ));
723 args.GetReturnValue().Set( rangeObject );
728 * Sets the progress of the animation.
729 * The animation will play (or continue playing) from this point. The progress
730 * must be in the 0-1 interval or in the play range interval if defined ( See SetPlayRange ),
731 * otherwise, it will be ignored.
733 * @method setCurrentProgress
735 * @param {float} progress The new progress as a normalized value between [0,1] or between the
736 * play range if specified.
738 void AnimationApi::SetCurrentProgress( const v8::FunctionCallbackInfo< v8::Value >& args )
740 v8::Isolate* isolate = args.GetIsolate();
741 v8::HandleScope handleScope( isolate );
743 Animation anim = GetAnimation( isolate, args );
747 float progress = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 0.f );
750 DALI_SCRIPT_EXCEPTION( isolate, "float parameter missing" );
753 anim.SetCurrentProgress( progress );
759 * Play the animation from a given point.
760 * The progress must be in the 0-1 interval or in the play range interval if defined ( See SetPlayRange ),
761 * otherwise, it will be ignored.
764 * @param {float} progress A value between [0,1], or between the play range if specified, form where the animation should start playing
766 void AnimationApi::PlayFrom( const v8::FunctionCallbackInfo< v8::Value >& args )
768 v8::Isolate* isolate = args.GetIsolate();
769 v8::HandleScope handleScope( isolate );
771 Animation anim = GetAnimation( isolate, args );
775 float progress = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 0.f );
778 DALI_SCRIPT_EXCEPTION( isolate, "float parameter missing" );
781 anim.PlayFrom( progress );
790 void AnimationApi::Play( const v8::FunctionCallbackInfo<v8::Value>& args )
792 v8::Isolate* isolate = args.GetIsolate();
793 v8::HandleScope handleScope( isolate );
795 Animation anim = GetAnimation( isolate, args );
799 * Pause the animation
803 void AnimationApi::Pause( const v8::FunctionCallbackInfo<v8::Value>& args )
805 v8::Isolate* isolate = args.GetIsolate();
806 v8::HandleScope handleScope( isolate );
808 Animation anim = GetAnimation( isolate, args );
816 void AnimationApi::Stop( const v8::FunctionCallbackInfo<v8::Value>& args )
818 v8::Isolate* isolate = args.GetIsolate();
819 v8::HandleScope handleScope( isolate );
821 Animation anim = GetAnimation( isolate, args );
825 * Clear the animation
826 * This disconnects any objects that were being animated, effectively stopping the animation.
830 void AnimationApi::Clear( const v8::FunctionCallbackInfo<v8::Value>& args )
832 v8::Isolate* isolate = args.GetIsolate();
833 v8::HandleScope handleScope( isolate );
835 Animation anim = GetAnimation( isolate, args );
840 void AnimationApi::Animate( const v8::FunctionCallbackInfo<v8::Value>& args )
842 v8::Isolate* isolate = args.GetIsolate();
843 v8::HandleScope handleScope( isolate );
845 Animation anim = GetAnimation( isolate, args );
846 AnimationParameters animParams( anim );
850 Dali::Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
853 DALI_SCRIPT_EXCEPTION( isolate, "Missing actor parameter");
859 BaseWrappedObject* wrapper = V8Utils::GetWrappedDaliObjectParameter( PARAMETER_1, BaseWrappedObject::PATH, isolate, args);
860 PathWrapper* pathWrapper = static_cast< PathWrapper*>( wrapper );
865 path = pathWrapper->GetPath();
869 Vector3 forward = V8Utils::GetVector3Parameter( PARAMETER_2, bFound, isolate, args );
875 //Get animation options
876 GetAnimationOptions( isolate, args[3], animParams );
877 if( animParams.optionsFound )
879 anim.Animate( actor, path, forward, animParams.alphaFunction, TimePeriod( animParams.delay, animParams.duration) );
883 anim.Animate( actor, path, forward );
889 * Animate a property value by a relative amount.
891 * The effect will start & end when the animation begins & ends.
894 * @param {Object} target object that contains a property to be animated (e.g. myActor )
895 * @param {String} property name (e.g. "position" )
896 * @param {Object} relativeValue The property value will change by this amount.
897 * @param {Object} [options] Animation options.
898 * @param {Float} [options.delay] amount to delay the start of the animation in seconds
899 * @param {Float} [options.duration] duration of the animation
900 * @param {String} [options.alpha] Animation alpha function (e.g. "linear")
904 * // animation x position
905 * var anim = new dali.Animation( 1 );
906 * anim.animateBy( imageActor,"positionX", 30 );
909 * // animate x,y,z position with the optional animation options
911 * delay: 3, // 3 second delay before starting
912 * duration: 5, // 5 second duration
913 * alpha:"easeInOutSine" // Speeds up and slows to a gradual stop
916 * anim.animateBy( imageActor,"position", [100,200,0], options );
919 void AnimationApi::AnimateBy( const v8::FunctionCallbackInfo<v8::Value>& args )
921 v8::Isolate* isolate = args.GetIsolate();
922 v8::HandleScope handleScope( isolate );
924 Animation anim = GetAnimation( isolate, args );
925 AnimationParameters animParams( anim );
927 // grab all the parameters
928 bool ok = GetAnimationParameters( isolate, args, animParams, AnimationApi::PROPERTY_VALUE);
931 // GetAnimationParameters will log
935 if( animParams.optionsFound )
937 anim.AnimateBy( Property( animParams.target, animParams.propertyIndex ),
939 animParams.alphaFunction,
940 TimePeriod( animParams.delay, animParams.duration) );
944 anim.AnimateBy( Property( animParams.target, animParams.propertyIndex ), animParams.value );
951 * Animate a property to a destination value.
953 * The effect will start & end when the animation begins & ends.
956 * @param {Object} target object that contains a property to be animated (e.g. myActor )
957 * @param {String} property name (e.g. "position" )
958 * @param {Object} destinationValue The property value will changed to this value
959 * @param {Object} [options] Animation options.
960 * @param {Float} [options.delay] amount to delay the start of the animation in seconds
961 * @param {Float} [options.duration] duration of the animation
962 * @param {String} [options.alpha] Animation alpha function (e.g. "linear")
966 * var anim = new dali.Animation( 1 );
967 * anim.animateTo( imageActor,"positionX", 30 );
971 * // with the optional animation options object
973 * delay: 3, // 3 second delay before starting
974 * duration: 5, // 5 second duration
975 * alpha:"easeInOutSine" // Speeds up and slows to a gradual stop
978 * anim.animateTo( imageActor,"position", [100,200,0], options );
981 void AnimationApi::AnimateTo( const v8::FunctionCallbackInfo< v8::Value >& args )
983 v8::Isolate* isolate = args.GetIsolate();
984 v8::HandleScope handleScope( isolate );
986 Animation anim = GetAnimation( isolate, args );
987 AnimationParameters animParams( anim );
989 // grab all the parameters
990 bool ok = GetAnimationParameters( isolate, args, animParams, AnimationApi::PROPERTY_VALUE );
993 // GetAnimationParameters will log
997 if( animParams.optionsFound )
1000 anim.AnimateTo( Property( animParams.target,animParams.propertyIndex ),
1002 animParams.alphaFunction,
1003 TimePeriod( animParams.delay, animParams.duration) );
1007 anim.AnimateTo( Property( animParams.target, animParams.propertyIndex ), animParams.value );
1013 * Animate a property between keyframes.
1015 * The effect will start & end when the animation begins & ends.
1016 * @method animateBetween
1018 * @param {Object} target object that contains a property to be animated (e.g. myActor )
1019 * @param {String} property name (e.g. "position" )
1020 * @param {Object} keyframes array of keyframe objects
1021 * @param {Object} [options] Animation options.
1022 * @param {Float} [options.delay] amount to delay the start of the animation in seconds
1023 * @param {Float} [options.duration] duration of the animation
1024 * @param {String} [options.alpha] Animation alpha function (e.g. "linear")
1029 * create some keyframes to move an actor around a square, and return to the start
1031 * <img src="../assets/img/animation/keyframe-animation.png">
1046 * value: [500,500,0]
1058 * anim.animateBetween( imageActor,"position", keyframes );
1061 void AnimationApi::AnimateBetween( const v8::FunctionCallbackInfo< v8::Value >& args )
1063 v8::Isolate* isolate = args.GetIsolate();
1064 v8::HandleScope handleScope( isolate );
1066 Animation anim = GetAnimation( isolate, args );
1067 AnimationParameters animParams( anim );
1069 // grab all the parameters
1070 bool ok = GetAnimationParameters( isolate, args, animParams, AnimationApi::KEYFRAMES );
1073 // GetAnimationParameters will log
1077 // if animation options exist...
1078 if( animParams.optionsFound )
1081 anim.AnimateBetween( Property( animParams.target,animParams.propertyIndex ),
1082 animParams.keyFrames,
1083 animParams.alphaFunction,
1084 TimePeriod( animParams.delay, animParams.duration) );
1088 anim.AnimateBetween( Property( animParams.target, animParams.propertyIndex ), animParams.keyFrames );
1093 * show an actor during the animation.
1095 * This is a helper, which simulates animating the visibility property of an actor
1096 * with zero duration ( it is just a boolean).
1097 * e.g. it performs anim.AnimateTo( actor,"visible",true, { delay:delay: duration:0 } );
1100 * @param {Object} Actor
1101 * @param {float} delay until the actor is shown
1103 void AnimationApi::Show( const v8::FunctionCallbackInfo< v8::Value >& args )
1105 v8::Isolate* isolate = args.GetIsolate();
1106 v8::HandleScope handleScope( isolate );
1107 Animation anim = GetAnimation( isolate, args );
1108 bool found( false );
1110 Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
1113 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 0 actor" );
1117 float delay = V8Utils::GetFloatParameter( PARAMETER_1, found, isolate, args, 1.f /* default */);
1120 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 1 delay" );
1123 anim.Show( actor, delay );
1128 * hide an actor during the animation.
1130 * This is a helper, which simulates animating the visibility property of an actor
1131 * with zero duration ( it is just a boolean).
1132 * e.g. it performs anim.AnimateTo( actor,"visible",false, { delay:delay: duration:0 } );
1135 * @param {Object} Actor
1136 * @param {float} delay until the actor is hidden
1138 void AnimationApi::Hide( const v8::FunctionCallbackInfo< v8::Value >& args )
1140 v8::Isolate* isolate = args.GetIsolate();
1141 v8::HandleScope handleScope( isolate );
1142 Animation anim = GetAnimation( isolate, args );
1143 bool found( false );
1144 Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
1147 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 0 actor" );
1152 float delay = V8Utils::GetFloatParameter( PARAMETER_1, found, isolate, args, 1.f /* default */);
1155 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 1 delay" );
1158 anim.Hide( actor, delay );
1164 } // namespace V8Plugin