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 ( can be in the format "u-color" or "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 // convert the property name from "uColor" to "u-color"
277 std::string convetedName = V8Utils::JavaScriptNameToPropertyName( propertyName );
278 index = animParams.target.GetPropertyIndex( convetedName );
281 animParams.propertyIndex = index;
283 if( type == AnimationApi::PROPERTY_VALUE )
285 // 3 extract property value
286 bool foundPropValue( false );
287 animParams.value = V8Utils::GetPropertyValueParameter( PARAMETER_2, foundPropValue, isolate, args );
288 if( !foundPropValue )
290 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 2 ( value )" );
294 else // type == KEYFRAMES
296 animParams.keyFrames = GetKeyFrames(isolate, args[2]);
298 // 4 extract animation options
299 GetAnimationOptions( isolate, args[3], animParams );
304 Animation GetAnimation( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
306 v8::HandleScope handleScope( isolate );
308 v8::Local<v8::Object> object = args.This();
309 v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField( 0 ) );
310 void* ptr = field->Value();
312 AnimationWrapper* wrapper = static_cast<AnimationWrapper *>( ptr );
313 return wrapper->GetAnimation();
317 } // un-named namespace
325 * @param {float} duration
328 Animation AnimationApi::New( const v8::FunctionCallbackInfo< v8::Value >& args )
330 v8::Isolate* isolate = args.GetIsolate();
331 v8::HandleScope handleScope( isolate );
334 float value = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 1.f /* default */);
337 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
341 return Animation::New( value );
345 * Set the animation duration.
346 * @method setDuration
348 * @param {float} duration in seconds
351 void AnimationApi::SetDuration( const v8::FunctionCallbackInfo< v8::Value >& args )
353 v8::Isolate* isolate = args.GetIsolate();
354 v8::HandleScope handleScope( isolate );
356 Animation anim = GetAnimation( isolate, args );
359 float value = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 1.f /* default */);
362 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
365 anim.SetDuration( value );
368 * Get the animation duration.
369 * @method getDuration
371 * @return {float} duration in seconds
374 void AnimationApi::GetDuration( const v8::FunctionCallbackInfo< v8::Value >& args )
376 v8::Isolate* isolate = args.GetIsolate();
377 v8::HandleScope handleScope( isolate );
379 Animation anim = GetAnimation( isolate, args );
381 args.GetReturnValue().Set( v8::Number::New( isolate, anim.GetDuration() ) );
385 * Set whether the animation will loop.
388 * @param {bool} looping enabled
391 void AnimationApi::SetLooping( const v8::FunctionCallbackInfo< v8::Value >& args )
393 v8::Isolate* isolate = args.GetIsolate();
394 v8::HandleScope handleScope( isolate );
396 Animation anim = GetAnimation( isolate, args );
399 bool value = V8Utils::GetBooleanParameter( PARAMETER_0, found, isolate, args );
402 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
406 anim.SetLooping( value );
411 * Query whether the animation will loop.
414 * @return {bool} looping enabled
417 void AnimationApi::IsLooping( const v8::FunctionCallbackInfo< v8::Value >& args )
419 v8::Isolate* isolate = args.GetIsolate();
420 v8::HandleScope handleScope( isolate );
422 Animation anim = GetAnimation( isolate, args );
424 args.GetReturnValue().Set( v8::Boolean::New( isolate, anim.IsLooping() ) );
428 * Set the end action of the animation.
430 * This action is performed when the animation ends.
431 * Default end action is bake
432 * @method setEndAction
434 * @param {integer} bake mode
436 * anim.setEndAction( dali.ANIMATION_BAKE ); // When the animation ends, the animated property values are saved.
437 * anim.setEndAction( dali.ANIMATION_DISCARD ); // When the animation ends, the animated property values are forgotten.
438 * 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.
440 void AnimationApi::SetEndAction( const v8::FunctionCallbackInfo< v8::Value >& args )
442 v8::Isolate* isolate = args.GetIsolate();
443 v8::HandleScope handleScope( isolate );
445 Animation anim = GetAnimation( isolate, args );
448 int value = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
451 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
455 anim.SetEndAction( static_cast<Animation::EndAction>( value ) );
460 * Returns the end action of the animation.
462 * @method getEndAction
464 * @return {integer} bake mode
466 * There are 3 different bake modes
468 * dali.ANIMATION_BAKE // When the animation ends, the animated property values are saved.
469 * dali.ANIMATION_DISCARD // When the animation ends, the animated property values are forgotten.
470 * 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.
472 void AnimationApi::GetEndAction( const v8::FunctionCallbackInfo< v8::Value >& args )
474 v8::Isolate* isolate = args.GetIsolate();
475 v8::HandleScope handleScope( isolate );
477 Animation anim = GetAnimation( isolate, args );
479 args.GetReturnValue().Set( v8::Integer::New( isolate, anim.GetEndAction() ) );
483 * Set the disconnect action of the animation.
484 * If any of the animated property owners are disconnected from the stage, this action is performed.
485 * Default disconnection action is BakeFinal.
486 * @method setDisconnectAction
488 * @param {integer} end mode
490 * There are 3 different end modes
492 * dali.ANIMATION_BAKE // When the animation is destroyed, the animated property values are saved.
493 * dali.ANIMATION_DISCARD // When the animation is destroyed, the animated property values are forgotten.
494 * 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.
496 void AnimationApi::SetDisconnectAction( const v8::FunctionCallbackInfo< v8::Value >& args )
498 v8::Isolate* isolate = args.GetIsolate();
499 v8::HandleScope handleScope( isolate );
501 Animation anim = GetAnimation( isolate, args );
504 int value = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
507 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
511 anim.SetDisconnectAction( static_cast<Animation::EndAction>( value ) );
516 * Returns the disconnect action of the animation.
517 * @method getDisconnectAction
519 * @return {integer} end mode
521 void AnimationApi::GetDisconnectAction( const v8::FunctionCallbackInfo< v8::Value >& args )
523 v8::Isolate* isolate = args.GetIsolate();
524 v8::HandleScope handleScope( isolate );
526 Animation anim = GetAnimation( isolate, args );
528 args.GetReturnValue().Set( v8::Integer::New( isolate, anim.GetDisconnectAction() ) );
531 * Set the default alpha function for an animation.
532 * @method setDefaultAlphaFunction
534 * @param {string} alpha function
536 void AnimationApi::SetDefaultAlphaFunction( const v8::FunctionCallbackInfo< v8::Value >& args )
538 v8::Isolate* isolate = args.GetIsolate();
539 v8::HandleScope handleScope( isolate );
541 Animation anim = GetAnimation( isolate, args );
544 std::string alphaFunc = V8Utils::GetStringParameter( PARAMETER_0, found, isolate, args );
547 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
551 AlphaFunction func = GetAlphaFunction( alphaFunc );
552 anim.SetDefaultAlphaFunction( func );
557 * Get the default alpha function for an animation.
558 * @method getDefaultAlphaFunction
560 * @return {string} alpha function
562 void AnimationApi::GetDefaultAlphaFunction( const v8::FunctionCallbackInfo<v8::Value>& args )
564 v8::Isolate* isolate = args.GetIsolate();
565 v8::HandleScope handleScope( isolate );
567 Animation anim = GetAnimation( isolate, args );
569 std::string alphaName = GetAlphaFunctionName( anim.GetDefaultAlphaFunction() );
572 args.GetReturnValue().Set( v8::String::NewFromUtf8( isolate, alphaName.c_str() ) );
576 * Get the current progress of the animation.
577 * @method getCurrentProgress
579 * @return {float} The current progress as a normalized value between [0..1].
582 void AnimationApi::GetCurrentProgress( const v8::FunctionCallbackInfo< v8::Value >& args )
584 v8::Isolate* isolate = args.GetIsolate();
585 v8::HandleScope handleScope( isolate );
587 Animation anim = GetAnimation( isolate, args );
589 args.GetReturnValue().Set( v8::Number::New( isolate, anim.GetCurrentProgress() ) );
593 * Specifies an speed factor for the animation.
595 * The speed factor is a multiplier of the normal velocity of the animation. Values between [0,1] will
596 * slow down the animation and values above one will speed up the animation. It is also possible to specify a negative multiplier
597 * to play the animation in reverse.
599 * @method setSpeedFactor
601 * @param {float} value which will multiply the velocity.
603 * anim.setSpeedFactor(2);
604 * anim.play(); // plays the animation twice as fast
607 * anim.setSpeedFactor(0.5);
608 * anim.play(); // plays the animation half speed
611 void AnimationApi::SetSpeedFactor( const v8::FunctionCallbackInfo< v8::Value >& args )
613 v8::Isolate* isolate = args.GetIsolate();
614 v8::HandleScope handleScope( isolate );
616 Animation anim = GetAnimation( isolate, args );
619 float speedFactor = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 0.f );
622 DALI_SCRIPT_EXCEPTION( isolate, "float parameter missing" );
626 anim.SetSpeedFactor( speedFactor );
632 * Retrieve the speed factor of the animation
635 * @method getSpeedFactor
637 * @return {float} speed factor
639 void AnimationApi::GetSpeedFactor( const v8::FunctionCallbackInfo< v8::Value >& args )
641 v8::Isolate* isolate = args.GetIsolate();
642 v8::HandleScope handleScope( isolate );
644 Animation anim = GetAnimation( isolate, args );
646 args.GetReturnValue().Set( v8::Number::New( isolate, anim.GetSpeedFactor() ) );
650 * Set the playing range.
651 * Animation will play between the values specified.
652 * Both values ( range.x and range.y ) should be between 0-1,
653 * otherwise they will be ignored.
654 * If the range provided is not in proper order ( minimum,maximum), it will be reordered.
655 * @method setPlayRange
657 * @param {Object} Range
658 * @param {Float} Range.start
659 * @param {Float} Range.end
661 * var range = { start:0.1, end:0.6 };
662 * anim.setPlayRange( range );
664 void AnimationApi::SetPlayRange( const v8::FunctionCallbackInfo< v8::Value >& args )
666 v8::Isolate* isolate = args.GetIsolate();
667 v8::HandleScope handleScope( isolate );
669 Animation anim = GetAnimation( isolate, args );
672 if( args.Length() != 1 )
674 DALI_SCRIPT_EXCEPTION( isolate, "missing / invalid parameters" );
677 v8::Local<v8::Value > rangeValue = args[0];
678 if( !rangeValue->IsObject() )
680 DALI_SCRIPT_EXCEPTION( isolate, "invalid parameters" );
683 v8::Local<v8::Object> obj = rangeValue->ToObject();
684 v8::Local<v8::Value> startValue = obj->Get( v8::String::NewFromUtf8( isolate, "start" ) );
685 v8::Local<v8::Value> endValue = obj->Get( v8::String::NewFromUtf8( isolate, "end" ) );
687 if( startValue->IsNumber() && endValue->IsNumber())
689 range.x= startValue->ToNumber()->Value();
690 range.y = endValue->ToNumber()->Value();
694 DALI_SCRIPT_EXCEPTION( isolate, "missing start/end value" );
698 anim.SetPlayRange( range );
703 * Get the playing range.
704 * @method getPlayRange
706 * @return {Object} Range with { start: , end: } properties.
708 void AnimationApi::GetPlayRange( const v8::FunctionCallbackInfo< v8::Value >& args )
710 v8::Isolate* isolate = args.GetIsolate();
711 v8::EscapableHandleScope handleScope( isolate );
712 Animation anim = GetAnimation( isolate, args );
715 v8::Local<v8::Object> rangeObject = v8::Object::New( isolate );
717 Vector2 range = anim.GetPlayRange();
720 rangeObject->Set( v8::String::NewFromUtf8( isolate, "start"), v8::Number::New( isolate,range.x ));
723 rangeObject->Set( v8::String::NewFromUtf8( isolate, "end"), v8::Number::New( isolate,range.y ));
725 args.GetReturnValue().Set( rangeObject );
730 * Sets the progress of the animation.
731 * The animation will play (or continue playing) from this point. The progress
732 * must be in the 0-1 interval or in the play range interval if defined ( See SetPlayRange ),
733 * otherwise, it will be ignored.
735 * @method setCurrentProgress
737 * @param {float} progress The new progress as a normalized value between [0,1] or between the
738 * play range if specified.
740 void AnimationApi::SetCurrentProgress( const v8::FunctionCallbackInfo< v8::Value >& args )
742 v8::Isolate* isolate = args.GetIsolate();
743 v8::HandleScope handleScope( isolate );
745 Animation anim = GetAnimation( isolate, args );
749 float progress = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 0.f );
752 DALI_SCRIPT_EXCEPTION( isolate, "float parameter missing" );
755 anim.SetCurrentProgress( progress );
761 * Play the animation from a given point.
762 * The progress must be in the 0-1 interval or in the play range interval if defined ( See SetPlayRange ),
763 * otherwise, it will be ignored.
766 * @param {float} progress A value between [0,1], or between the play range if specified, form where the animation should start playing
768 void AnimationApi::PlayFrom( const v8::FunctionCallbackInfo< v8::Value >& args )
770 v8::Isolate* isolate = args.GetIsolate();
771 v8::HandleScope handleScope( isolate );
773 Animation anim = GetAnimation( isolate, args );
777 float progress = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 0.f );
780 DALI_SCRIPT_EXCEPTION( isolate, "float parameter missing" );
783 anim.PlayFrom( progress );
792 void AnimationApi::Play( const v8::FunctionCallbackInfo<v8::Value>& args )
794 v8::Isolate* isolate = args.GetIsolate();
795 v8::HandleScope handleScope( isolate );
797 Animation anim = GetAnimation( isolate, args );
801 * Pause the animation
805 void AnimationApi::Pause( const v8::FunctionCallbackInfo<v8::Value>& args )
807 v8::Isolate* isolate = args.GetIsolate();
808 v8::HandleScope handleScope( isolate );
810 Animation anim = GetAnimation( isolate, args );
818 void AnimationApi::Stop( const v8::FunctionCallbackInfo<v8::Value>& args )
820 v8::Isolate* isolate = args.GetIsolate();
821 v8::HandleScope handleScope( isolate );
823 Animation anim = GetAnimation( isolate, args );
827 * Clear the animation
828 * This disconnects any objects that were being animated, effectively stopping the animation.
832 void AnimationApi::Clear( const v8::FunctionCallbackInfo<v8::Value>& args )
834 v8::Isolate* isolate = args.GetIsolate();
835 v8::HandleScope handleScope( isolate );
837 Animation anim = GetAnimation( isolate, args );
842 void AnimationApi::Animate( const v8::FunctionCallbackInfo<v8::Value>& args )
844 v8::Isolate* isolate = args.GetIsolate();
845 v8::HandleScope handleScope( isolate );
847 Animation anim = GetAnimation( isolate, args );
848 AnimationParameters animParams( anim );
852 Dali::Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
855 DALI_SCRIPT_EXCEPTION( isolate, "Missing actor parameter");
861 BaseWrappedObject* wrapper = V8Utils::GetWrappedDaliObjectParameter( PARAMETER_1, BaseWrappedObject::PATH, isolate, args);
862 PathWrapper* pathWrapper = static_cast< PathWrapper*>( wrapper );
867 path = pathWrapper->GetPath();
871 Vector3 forward = V8Utils::GetVector3Parameter( PARAMETER_2, bFound, isolate, args );
877 //Get animation options
878 GetAnimationOptions( isolate, args[3], animParams );
879 if( animParams.optionsFound )
881 anim.Animate( actor, path, forward, animParams.alphaFunction, TimePeriod( animParams.delay, animParams.duration) );
885 anim.Animate( actor, path, forward );
891 * Animate a property value by a relative amount.
893 * The effect will start & end when the animation begins & ends.
896 * @param {Object} target object that contains a property to be animated (e.g. myActor )
897 * @param {String} property name (e.g. "position" )
898 * @param {Object} relativeValue The property value will change by this amount.
899 * @param {Object} [options] Animation options.
900 * @param {Float} [options.delay] amount to delay the start of the animation in seconds
901 * @param {Float} [options.duration] duration of the animation
902 * @param {String} [options.alpha] Animation alpha function (e.g. "linear")
906 * // animation x position
907 * var anim = new dali.Animation( 1 );
908 * anim.animateBy( imageActor,"positionX", 30 );
911 * // animate x,y,z position with the optional animation options
913 * delay: 3, // 3 second delay before starting
914 * duration: 5, // 5 second duration
915 * alpha:"easeInOutSine" // Speeds up and slows to a gradual stop
918 * anim.animateBy( imageActor,"position", [100,200,0], options );
921 void AnimationApi::AnimateBy( const v8::FunctionCallbackInfo<v8::Value>& args )
923 v8::Isolate* isolate = args.GetIsolate();
924 v8::HandleScope handleScope( isolate );
926 Animation anim = GetAnimation( isolate, args );
927 AnimationParameters animParams( anim );
929 // grab all the parameters
930 bool ok = GetAnimationParameters( isolate, args, animParams, AnimationApi::PROPERTY_VALUE);
933 // GetAnimationParameters will log
937 if( animParams.optionsFound )
939 anim.AnimateBy( Property( animParams.target, animParams.propertyIndex ),
941 animParams.alphaFunction,
942 TimePeriod( animParams.delay, animParams.duration) );
946 anim.AnimateBy( Property( animParams.target, animParams.propertyIndex ), animParams.value );
953 * Animate a property to a destination value.
955 * The effect will start & end when the animation begins & ends.
958 * @param {Object} target object that contains a property to be animated (e.g. myActor )
959 * @param {String} property name (e.g. "position" )
960 * @param {Object} destinationValue The property value will changed to this value
961 * @param {Object} [options] Animation options.
962 * @param {Float} [options.delay] amount to delay the start of the animation in seconds
963 * @param {Float} [options.duration] duration of the animation
964 * @param {String} [options.alpha] Animation alpha function (e.g. "linear")
968 * var anim = new dali.Animation( 1 );
969 * anim.animateTo( imageActor,"positionX", 30 );
973 * // with the optional animation options object
975 * delay: 3, // 3 second delay before starting
976 * duration: 5, // 5 second duration
977 * alpha:"easeInOutSine" // Speeds up and slows to a gradual stop
980 * anim.animateTo( imageActor,"position", [100,200,0], options );
983 void AnimationApi::AnimateTo( const v8::FunctionCallbackInfo< v8::Value >& args )
985 v8::Isolate* isolate = args.GetIsolate();
986 v8::HandleScope handleScope( isolate );
988 Animation anim = GetAnimation( isolate, args );
989 AnimationParameters animParams( anim );
991 // grab all the parameters
992 bool ok = GetAnimationParameters( isolate, args, animParams, AnimationApi::PROPERTY_VALUE );
995 // GetAnimationParameters will log
999 if( animParams.optionsFound )
1002 anim.AnimateTo( Property( animParams.target,animParams.propertyIndex ),
1004 animParams.alphaFunction,
1005 TimePeriod( animParams.delay, animParams.duration) );
1009 anim.AnimateTo( Property( animParams.target, animParams.propertyIndex ), animParams.value );
1015 * Animate a property between keyframes.
1017 * The effect will start & end when the animation begins & ends.
1018 * @method animateBetween
1020 * @param {Object} target object that contains a property to be animated (e.g. myActor )
1021 * @param {String} property name (e.g. "position" )
1022 * @param {Object} keyframes array of keyframe objects
1023 * @param {Object} [options] Animation options.
1024 * @param {Float} [options.delay] amount to delay the start of the animation in seconds
1025 * @param {Float} [options.duration] duration of the animation
1026 * @param {String} [options.alpha] Animation alpha function (e.g. "linear")
1031 * create some keyframes to move an actor around a square, and return to the start
1033 * <img src="../assets/img/animation/keyframe-animation.png">
1048 * value: [500,500,0]
1060 * anim.animateBetween( imageActor,"position", keyframes );
1063 void AnimationApi::AnimateBetween( const v8::FunctionCallbackInfo< v8::Value >& args )
1065 v8::Isolate* isolate = args.GetIsolate();
1066 v8::HandleScope handleScope( isolate );
1068 Animation anim = GetAnimation( isolate, args );
1069 AnimationParameters animParams( anim );
1071 // grab all the parameters
1072 bool ok = GetAnimationParameters( isolate, args, animParams, AnimationApi::KEYFRAMES );
1075 // GetAnimationParameters will log
1079 // if animation options exist...
1080 if( animParams.optionsFound )
1083 anim.AnimateBetween( Property( animParams.target,animParams.propertyIndex ),
1084 animParams.keyFrames,
1085 animParams.alphaFunction,
1086 TimePeriod( animParams.delay, animParams.duration) );
1090 anim.AnimateBetween( Property( animParams.target, animParams.propertyIndex ), animParams.keyFrames );
1095 * show an actor during the animation.
1097 * This is a helper, which simulates animating the visibility property of an actor
1098 * with zero duration ( it is just a boolean).
1099 * e.g. it performs anim.AnimateTo( actor,"visible",true, { delay:delay: duration:0 } );
1102 * @param {Object} Actor
1103 * @param {float} delay until the actor is shown
1105 void AnimationApi::Show( const v8::FunctionCallbackInfo< v8::Value >& args )
1107 v8::Isolate* isolate = args.GetIsolate();
1108 v8::HandleScope handleScope( isolate );
1109 Animation anim = GetAnimation( isolate, args );
1110 bool found( false );
1112 Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
1115 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 0 actor" );
1119 float delay = V8Utils::GetFloatParameter( PARAMETER_1, found, isolate, args, 1.f /* default */);
1122 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 1 delay" );
1125 anim.Show( actor, delay );
1130 * hide an actor during the animation.
1132 * This is a helper, which simulates animating the visibility property of an actor
1133 * with zero duration ( it is just a boolean).
1134 * e.g. it performs anim.AnimateTo( actor,"visible",false, { delay:delay: duration:0 } );
1137 * @param {Object} Actor
1138 * @param {float} delay until the actor is hidden
1140 void AnimationApi::Hide( const v8::FunctionCallbackInfo< v8::Value >& args )
1142 v8::Isolate* isolate = args.GetIsolate();
1143 v8::HandleScope handleScope( isolate );
1144 Animation anim = GetAnimation( isolate, args );
1145 bool found( false );
1146 Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
1149 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 0 actor" );
1154 float delay = V8Utils::GetFloatParameter( PARAMETER_1, found, isolate, args, 1.f /* default */);
1157 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 1 delay" );
1160 anim.Hide( actor, delay );
1166 } // namespace V8Plugin