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[]=
52 {"default" , AlphaFunctions::Default },
53 {"linear" , AlphaFunctions::Linear },
54 {"square" , AlphaFunctions::Square },
55 {"reverse" , AlphaFunctions::Reverse },
56 {"easeIn" , AlphaFunctions::EaseIn },
57 {"easeOut" , AlphaFunctions::EaseOut },
58 {"easeInOut" , AlphaFunctions::EaseInOut },
59 {"easeInSine" , AlphaFunctions::EaseInSine },
60 {"easeOutSine" , AlphaFunctions::EaseOutSine },
61 {"easeInOutSine" , AlphaFunctions::EaseInOutSine },
62 {"easeInSine33" , AlphaFunctions::EaseInSine33 },
63 {"easeOutSine33" , AlphaFunctions::EaseOutSine33 },
64 {"easeInOutSine33" , AlphaFunctions::EaseInOutSine33 },
65 {"easeInOutSine50" , AlphaFunctions::EaseInOutSine50 },
66 {"easeInOutSine60" , AlphaFunctions::EaseInOutSine60 },
67 {"easeInOutSine70" , AlphaFunctions::EaseInOutSine70 },
68 {"easeInOutSine80" , AlphaFunctions::EaseInOutSine80 },
69 {"easeInOutSine90" , AlphaFunctions::EaseInOutSine90 },
70 {"doubleEaseInOutSine60" , AlphaFunctions::DoubleEaseInOutSine60},
71 {"easeOutQuint50" , AlphaFunctions::EaseOutQuint50 },
72 {"easeOutQuint80" , AlphaFunctions::EaseOutQuint80 },
73 {"bounce" , AlphaFunctions::Bounce },
74 {"bounceBack" , AlphaFunctions::BounceBack },
75 {"easeInBack" , AlphaFunctions::EaseInBack },
76 {"easeOutBack" , AlphaFunctions::EaseOutBack },
77 {"easeInOutBack" , AlphaFunctions::EaseInOutBack },
78 {"sin" , AlphaFunctions::Sin },
79 {"sin2x" , AlphaFunctions::Sin2x }
81 const unsigned int AlphaFunctionTableCount = sizeof(AlphaFunctionTable)/sizeof(AlphaFunctionTable[0]);
82 const char* const DEFAULT_ALPHA_NAME = "default";
83 static AlphaFunction DEFAULT_ALPHA_FUNCTION = AlphaFunctions::Default;
87 AlphaFunction GetAlphaFunction( const std::string& alphaFuncName )
89 // This will normally get called just a few times during the application, so no point in doing anything clever
90 for( unsigned int i = 0; i < AlphaFunctionTableCount; i++)
92 const AlphaFuncStruct& alphaStruct( AlphaFunctionTable[i] );
94 if( std::strcmp( alphaStruct.name , alphaFuncName.c_str() ) == 0 )
96 return alphaStruct.alphaFunc;
100 DALI_LOG_ERROR("Failed to find alpha func |%s| \n", alphaFuncName.c_str() );
101 return AlphaFunctions::Default;
104 const char* const GetAlphaFunctionName( AlphaFunction alphaFunc )
106 // This may get called 3 times during the application, so no point
107 // in doing anything clever
109 for( unsigned int i = 0; i < AlphaFunctionTableCount; i++)
111 const AlphaFuncStruct& alphaStruct( AlphaFunctionTable[i] );
114 if( alphaStruct.alphaFunc == alphaFunc )
116 return alphaStruct.name;
123 struct AnimationParameters
125 AnimationParameters( const Animation& anim)
126 : propertyIndex( Property::INVALID_INDEX ),
127 alphaFunction( DEFAULT_ALPHA_FUNCTION),
129 duration(anim.GetDuration()),
130 optionsFound( false )
135 Property::Index propertyIndex;
136 Property::Value value;
138 AlphaFunction alphaFunction;
144 void GetAnimationOptions( v8::Isolate* isolate,
145 v8::Local<v8::Value > options,
146 AnimationParameters& animParams )
148 // animation options is an optional parameter passed in which holds
150 // var animOptions = {
155 v8::HandleScope handleScope( isolate );
157 if( options->IsObject() )
159 v8::Local<v8::Object> obj = options->ToObject();
160 v8::Local<v8::Value> alphaValue = obj->Get( v8::String::NewFromUtf8( isolate, "alpha" ) );
161 if( alphaValue->IsString() )
163 animParams.optionsFound = true;
164 std::string alphaName = V8Utils::v8StringToStdString( alphaValue );
165 animParams.alphaFunction = GetAlphaFunction( alphaName );
168 v8::Local<v8::Value> delayValue = obj->Get( v8::String::NewFromUtf8( isolate, "delay" ) );
169 if( delayValue->IsNumber() )
171 animParams.optionsFound = true;
172 v8::Local<v8::Number> num = delayValue->ToNumber();
173 animParams.delay = num->Value();
176 v8::Local<v8::Value> durationValue = obj->Get( v8::String::NewFromUtf8( isolate, "duration" ) );
177 if( durationValue->IsNumber() )
179 animParams.optionsFound = true;
180 v8::Local<v8::Number> num = durationValue->ToNumber();
181 animParams.duration = num->Value();
186 KeyFrames GetKeyFrames( v8::Isolate* isolate, v8::Local<v8::Value > keyFrameArray )
188 // keyframe object is an array of
191 // value: property value ( position/ rotation etc)
194 v8::HandleScope handleScope( isolate );
196 if( !keyFrameArray->IsObject() || !keyFrameArray->IsArray() )
198 DALI_SCRIPT_EXCEPTION( isolate, "missing keyframe array" );
202 KeyFrames keyframes = KeyFrames::New();
204 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast( keyFrameArray );
205 for( uint32_t i=0; i < array->Length() ; ++i)
207 v8::Handle<v8::Value> arrayItem = array->Get( i );
209 if(!arrayItem->IsObject() )
211 DALI_SCRIPT_EXCEPTION( isolate, "missing keyframe object" );
214 v8::Handle<v8::Object> keyFrameObject = arrayItem->ToObject();
216 // get keyframe.progress
217 v8::Handle<v8::Value> progress = keyFrameObject->Get(v8::String::NewFromUtf8( isolate, "progress"));
218 if( !progress->IsNumber() )
220 DALI_SCRIPT_EXCEPTION( isolate, "keyframe missing progress property" );
224 // get keyframe.value
226 v8::Handle<v8::Value> propertyValue = keyFrameObject->Get(v8::String::NewFromUtf8( isolate, "value"));
227 Property::Value value = V8Utils::GetPropertyValueFromObject( found, isolate, propertyValue );
230 DALI_SCRIPT_EXCEPTION( isolate, "keyframe missing value property" );
234 // get keyframe.alpha
235 v8::Handle<v8::Value> alphaValue = keyFrameObject->Get(v8::String::NewFromUtf8( isolate, "alpha"));
236 if( alphaValue->IsString() )
238 std::string alphaName = V8Utils::v8StringToStdString( alphaValue );
239 AlphaFunction alphaFunction = GetAlphaFunction( alphaName );
240 keyframes.Add( progress->NumberValue(), value, alphaFunction );
244 keyframes.Add( progress->NumberValue(), value );
251 bool GetAnimationParameters( v8::Isolate* isolate,
252 const v8::FunctionCallbackInfo< v8::Value >& args,
253 AnimationParameters& animParams,
254 AnimationApi::AnimationParameterType type)
256 // used for things like anim.AnimateBy( myImageActor, property-name, property-value (or Javascript number array));
257 // 1 extract property handle from param1.
258 // 2 extract property name from param2 ( can be in the format "u-color" or "uColor"
259 // 3 extract PropertyValue from param3
260 // 4 extract animation options ( delay, duration, alpha func)
264 animParams.target = V8Utils::GetHandleParameter( PARAMETER_0, foundHandle, isolate, args );
267 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 0 (Handle)" );
271 // 2 extract property name
273 std::string propertyName = V8Utils::GetStringParameter( PARAMETER_1, foundPropName, isolate, args );
276 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 1 ( PropertyName )" );
279 // try both properties with dashes and without
280 Property::Index index = animParams.target.GetPropertyIndex( propertyName );
282 if( index == Property::INVALID_INDEX )
284 // convert the property name from "uColor" to "u-color"
285 std::string convetedName = V8Utils::JavaScriptNameToPropertyName( propertyName );
286 index = animParams.target.GetPropertyIndex( convetedName );
289 animParams.propertyIndex = index;
291 if( type == AnimationApi::PROPERTY_VALUE )
293 // 3 extract property value
294 bool foundPropValue( false );
295 animParams.value = V8Utils::GetPropertyValueParameter( PARAMETER_2, foundPropValue, isolate, args );
296 if( !foundPropValue )
298 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 2 ( value )" );
302 else // type == KEYFRAMES
304 animParams.keyFrames = GetKeyFrames(isolate, args[2]);
306 // 4 extract animation options
307 GetAnimationOptions( isolate, args[3], animParams );
312 Animation GetAnimation( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
314 v8::HandleScope handleScope( isolate );
316 v8::Local<v8::Object> object = args.This();
317 v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField( 0 ) );
318 void* ptr = field->Value();
320 AnimationWrapper* wrapper = static_cast<AnimationWrapper *>( ptr );
321 return wrapper->GetAnimation();
325 } // un-named namespace
333 * @param {float} duration
336 Animation AnimationApi::New( const v8::FunctionCallbackInfo< v8::Value >& args )
338 v8::Isolate* isolate = args.GetIsolate();
339 v8::HandleScope handleScope( isolate );
342 float value = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 1.f /* default */);
345 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
349 return Animation::New( value );
353 * Set the animation duration.
354 * @method setDuration
356 * @param {float} duration in seconds
359 void AnimationApi::SetDuration( const v8::FunctionCallbackInfo< v8::Value >& args )
361 v8::Isolate* isolate = args.GetIsolate();
362 v8::HandleScope handleScope( isolate );
364 Animation anim = GetAnimation( isolate, args );
367 float value = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 1.f /* default */);
370 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
373 anim.SetDuration( value );
376 * Get the animation duration.
377 * @method getDuration
379 * @return {float} duration in seconds
382 void AnimationApi::GetDuration( const v8::FunctionCallbackInfo< v8::Value >& args )
384 v8::Isolate* isolate = args.GetIsolate();
385 v8::HandleScope handleScope( isolate );
387 Animation anim = GetAnimation( isolate, args );
389 args.GetReturnValue().Set( v8::Number::New( isolate, anim.GetDuration() ) );
393 * Set whether the animation will loop.
396 * @param {bool} looping enabled
399 void AnimationApi::SetLooping( const v8::FunctionCallbackInfo< v8::Value >& args )
401 v8::Isolate* isolate = args.GetIsolate();
402 v8::HandleScope handleScope( isolate );
404 Animation anim = GetAnimation( isolate, args );
407 bool value = V8Utils::GetBooleanParameter( PARAMETER_0, found, isolate, args );
410 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
414 anim.SetLooping( value );
419 * Query whether the animation will loop.
422 * @return {bool} looping enabled
425 void AnimationApi::IsLooping( const v8::FunctionCallbackInfo< v8::Value >& args )
427 v8::Isolate* isolate = args.GetIsolate();
428 v8::HandleScope handleScope( isolate );
430 Animation anim = GetAnimation( isolate, args );
432 args.GetReturnValue().Set( v8::Boolean::New( isolate, anim.IsLooping() ) );
436 * Set the end action of the animation.
438 * This action is performed when the animation ends.
439 * Default end action is bake
440 * @method setEndAction
442 * @param {integer} bake mode
444 * anim.setEndAction( dali.ANIMATION_BAKE ); // When the animation ends, the animated property values are saved.
445 * anim.setEndAction( dali.ANIMATION_DISCARD ); // When the animation ends, the animated property values are forgotten.
446 * 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.
448 void AnimationApi::SetEndAction( const v8::FunctionCallbackInfo< v8::Value >& args )
450 v8::Isolate* isolate = args.GetIsolate();
451 v8::HandleScope handleScope( isolate );
453 Animation anim = GetAnimation( isolate, args );
456 int value = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
459 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
463 anim.SetEndAction( static_cast<Animation::EndAction>( value ) );
468 * Returns the end action of the animation.
470 * @method getEndAction
472 * @return {integer} bake mode
474 * There are 3 different bake modes
476 * dali.ANIMATION_BAKE // When the animation ends, the animated property values are saved.
477 * dali.ANIMATION_DISCARD // When the animation ends, the animated property values are forgotten.
478 * 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.
480 void AnimationApi::GetEndAction( const v8::FunctionCallbackInfo< v8::Value >& args )
482 v8::Isolate* isolate = args.GetIsolate();
483 v8::HandleScope handleScope( isolate );
485 Animation anim = GetAnimation( isolate, args );
487 args.GetReturnValue().Set( v8::Integer::New( isolate, anim.GetEndAction() ) );
491 * Set the disconnect action of the animation.
492 * If any of the animated property owners are disconnected from the stage, this action is performed.
493 * Default disconnection action is BakeFinal.
494 * @method setDisconnectAction
496 * @param {integer} end mode
498 * There are 3 different end modes
500 * dali.ANIMATION_BAKE // When the animation is destroyed, the animated property values are saved.
501 * dali.ANIMATION_DISCARD // When the animation is destroyed, the animated property values are forgotten.
502 * 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.
504 void AnimationApi::SetDisconnectAction( const v8::FunctionCallbackInfo< v8::Value >& args )
506 v8::Isolate* isolate = args.GetIsolate();
507 v8::HandleScope handleScope( isolate );
509 Animation anim = GetAnimation( isolate, args );
512 int value = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
515 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
519 anim.SetDisconnectAction( static_cast<Animation::EndAction>( value ) );
524 * Returns the disconnect action of the animation.
525 * @method getDisconnectAction
527 * @return {integer} end mode
529 void AnimationApi::GetDisconnectAction( const v8::FunctionCallbackInfo< v8::Value >& args )
531 v8::Isolate* isolate = args.GetIsolate();
532 v8::HandleScope handleScope( isolate );
534 Animation anim = GetAnimation( isolate, args );
536 args.GetReturnValue().Set( v8::Integer::New( isolate, anim.GetDisconnectAction() ) );
539 * Set the default alpha function for an animation.
540 * @method setDefaultAlphaFunction
542 * @param {string} alpha function
544 void AnimationApi::SetDefaultAlphaFunction( const v8::FunctionCallbackInfo< v8::Value >& args )
546 v8::Isolate* isolate = args.GetIsolate();
547 v8::HandleScope handleScope( isolate );
549 Animation anim = GetAnimation( isolate, args );
552 std::string alphaFunc = V8Utils::GetStringParameter( PARAMETER_0, found, isolate, args );
555 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
559 AlphaFunction func = GetAlphaFunction( alphaFunc );
560 anim.SetDefaultAlphaFunction( func );
565 * Get the default alpha function for an animation.
566 * @method getDefaultAlphaFunction
568 * @return {string} alpha function
570 void AnimationApi::GetDefaultAlphaFunction( const v8::FunctionCallbackInfo<v8::Value>& args )
572 v8::Isolate* isolate = args.GetIsolate();
573 v8::HandleScope handleScope( isolate );
575 Animation anim = GetAnimation( isolate, args );
577 std::string alphaName = GetAlphaFunctionName( anim.GetDefaultAlphaFunction() );
580 args.GetReturnValue().Set( v8::String::NewFromUtf8( isolate, alphaName.c_str() ) );
584 * Get the current progress of the animation.
585 * @method getCurrentProgress
587 * @return {float} The current progress as a normalized value between [0..1].
590 void AnimationApi::GetCurrentProgress( const v8::FunctionCallbackInfo< v8::Value >& args )
592 v8::Isolate* isolate = args.GetIsolate();
593 v8::HandleScope handleScope( isolate );
595 Animation anim = GetAnimation( isolate, args );
597 args.GetReturnValue().Set( v8::Number::New( isolate, anim.GetCurrentProgress() ) );
601 * Specifies an speed factor for the animation.
603 * The speed factor is a multiplier of the normal velocity of the animation. Values between [0,1] will
604 * slow down the animation and values above one will speed up the animation. It is also possible to specify a negative multiplier
605 * to play the animation in reverse.
607 * @method setSpeedFactor
609 * @param {float} value which will multiply the velocity.
611 * anim.setSpeedFactor(2);
612 * anim.play(); // plays the animation twice as fast
615 * anim.setSpeedFactor(0.5);
616 * anim.play(); // plays the animation half speed
619 void AnimationApi::SetSpeedFactor( const v8::FunctionCallbackInfo< v8::Value >& args )
621 v8::Isolate* isolate = args.GetIsolate();
622 v8::HandleScope handleScope( isolate );
624 Animation anim = GetAnimation( isolate, args );
627 float speedFactor = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 0.f );
630 DALI_SCRIPT_EXCEPTION( isolate, "float parameter missing" );
634 anim.SetSpeedFactor( speedFactor );
640 * Retrieve the speed factor of the animation
643 * @method getSpeedFactor
645 * @return {float} speed factor
647 void AnimationApi::GetSpeedFactor( const v8::FunctionCallbackInfo< v8::Value >& args )
649 v8::Isolate* isolate = args.GetIsolate();
650 v8::HandleScope handleScope( isolate );
652 Animation anim = GetAnimation( isolate, args );
654 args.GetReturnValue().Set( v8::Number::New( isolate, anim.GetSpeedFactor() ) );
658 * Set the playing range.
659 * Animation will play between the values specified.
660 * Both values ( range.x and range.y ) should be between 0-1,
661 * otherwise they will be ignored.
662 * If the range provided is not in proper order ( minimum,maximum), it will be reordered.
663 * @method setPlayRange
665 * @param {Object} Range
666 * @param {Float} Range.start
667 * @param {Float} Range.end
669 * var range = { start:0.1, end:0.6 };
670 * anim.setPlayRange( range );
672 void AnimationApi::SetPlayRange( const v8::FunctionCallbackInfo< v8::Value >& args )
674 v8::Isolate* isolate = args.GetIsolate();
675 v8::HandleScope handleScope( isolate );
677 Animation anim = GetAnimation( isolate, args );
680 if( args.Length() != 1 )
682 DALI_SCRIPT_EXCEPTION( isolate, "missing / invalid parameters" );
685 v8::Local<v8::Value > rangeValue = args[0];
686 if( !rangeValue->IsObject() )
688 DALI_SCRIPT_EXCEPTION( isolate, "invalid parameters" );
691 v8::Local<v8::Object> obj = rangeValue->ToObject();
692 v8::Local<v8::Value> startValue = obj->Get( v8::String::NewFromUtf8( isolate, "start" ) );
693 v8::Local<v8::Value> endValue = obj->Get( v8::String::NewFromUtf8( isolate, "end" ) );
695 if( startValue->IsNumber() && endValue->IsNumber())
697 range.x= startValue->ToNumber()->Value();
698 range.y = endValue->ToNumber()->Value();
702 DALI_SCRIPT_EXCEPTION( isolate, "missing start/end value" );
706 anim.SetPlayRange( range );
711 * Get the playing range.
712 * @method getPlayRange
714 * @return {Object} Range with { start: , end: } properties.
716 void AnimationApi::GetPlayRange( const v8::FunctionCallbackInfo< v8::Value >& args )
718 v8::Isolate* isolate = args.GetIsolate();
719 v8::EscapableHandleScope handleScope( isolate );
720 Animation anim = GetAnimation( isolate, args );
723 v8::Local<v8::Object> rangeObject = v8::Object::New( isolate );
725 Vector2 range = anim.GetPlayRange();
728 rangeObject->Set( v8::String::NewFromUtf8( isolate, "start"), v8::Number::New( isolate,range.x ));
731 rangeObject->Set( v8::String::NewFromUtf8( isolate, "end"), v8::Number::New( isolate,range.y ));
733 args.GetReturnValue().Set( rangeObject );
738 * Sets the progress of the animation.
739 * The animation will play (or continue playing) from this point. The progress
740 * must be in the 0-1 interval or in the play range interval if defined ( See SetPlayRange ),
741 * otherwise, it will be ignored.
743 * @method setCurrentProgress
745 * @param {float} progress The new progress as a normalized value between [0,1] or between the
746 * play range if specified.
748 void AnimationApi::SetCurrentProgress( const v8::FunctionCallbackInfo< v8::Value >& args )
750 v8::Isolate* isolate = args.GetIsolate();
751 v8::HandleScope handleScope( isolate );
753 Animation anim = GetAnimation( isolate, args );
757 float progress = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 0.f );
760 DALI_SCRIPT_EXCEPTION( isolate, "float parameter missing" );
763 anim.SetCurrentProgress( progress );
769 * Play the animation from a given point.
770 * The progress must be in the 0-1 interval or in the play range interval if defined ( See SetPlayRange ),
771 * otherwise, it will be ignored.
774 * @param {float} progress A value between [0,1], or between the play range if specified, form where the animation should start playing
776 void AnimationApi::PlayFrom( const v8::FunctionCallbackInfo< v8::Value >& args )
778 v8::Isolate* isolate = args.GetIsolate();
779 v8::HandleScope handleScope( isolate );
781 Animation anim = GetAnimation( isolate, args );
785 float progress = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 0.f );
788 DALI_SCRIPT_EXCEPTION( isolate, "float parameter missing" );
791 anim.PlayFrom( progress );
800 void AnimationApi::Play( const v8::FunctionCallbackInfo<v8::Value>& args )
802 v8::Isolate* isolate = args.GetIsolate();
803 v8::HandleScope handleScope( isolate );
805 Animation anim = GetAnimation( isolate, args );
809 * Pause the animation
813 void AnimationApi::Pause( const v8::FunctionCallbackInfo<v8::Value>& args )
815 v8::Isolate* isolate = args.GetIsolate();
816 v8::HandleScope handleScope( isolate );
818 Animation anim = GetAnimation( isolate, args );
826 void AnimationApi::Stop( const v8::FunctionCallbackInfo<v8::Value>& args )
828 v8::Isolate* isolate = args.GetIsolate();
829 v8::HandleScope handleScope( isolate );
831 Animation anim = GetAnimation( isolate, args );
835 * Clear the animation
836 * This disconnects any objects that were being animated, effectively stopping the animation.
840 void AnimationApi::Clear( const v8::FunctionCallbackInfo<v8::Value>& args )
842 v8::Isolate* isolate = args.GetIsolate();
843 v8::HandleScope handleScope( isolate );
845 Animation anim = GetAnimation( isolate, args );
850 void AnimationApi::Animate( const v8::FunctionCallbackInfo<v8::Value>& args )
852 v8::Isolate* isolate = args.GetIsolate();
853 v8::HandleScope handleScope( isolate );
855 Animation anim = GetAnimation( isolate, args );
856 AnimationParameters animParams( anim );
860 Dali::Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
863 DALI_SCRIPT_EXCEPTION( isolate, "Missing actor parameter");
869 BaseWrappedObject* wrapper = V8Utils::GetWrappedDaliObjectParameter( PARAMETER_1, BaseWrappedObject::PATH, isolate, args);
870 PathWrapper* pathWrapper = static_cast< PathWrapper*>( wrapper );
875 path = pathWrapper->GetPath();
879 Vector3 forward = V8Utils::GetVector3Parameter( PARAMETER_2, bFound, isolate, args );
885 //Get animation options
886 GetAnimationOptions( isolate, args[3], animParams );
887 if( animParams.optionsFound )
889 anim.Animate( actor, path, forward, animParams.alphaFunction, TimePeriod( animParams.delay, animParams.duration) );
893 anim.Animate( actor, path, forward );
899 * Animate a property value by a relative amount.
901 * The effect will start & end when the animation begins & ends.
904 * @param {Object} target object that contains a property to be animated (e.g. myActor )
905 * @param {String} property name (e.g. "position" )
906 * @param {Object} relativeValue The property value will change by this amount.
907 * @param {Object} [options] Animation options.
908 * @param {Float} [options.delay] amount to delay the start of the animation in seconds
909 * @param {Float} [options.duration] duration of the animation
910 * @param {String} [options.alpha] Animation alpha function (e.g. "linear")
914 * // animation x position
915 * var anim = new dali.Animation( 1 );
916 * anim.animateBy( imageActor,"positionX", 30 );
919 * // animate x,y,z position with the optional animation options
921 * delay: 3, // 3 second delay before starting
922 * duration: 5, // 5 second duration
923 * alpha:"easeInOutSine" // Speeds up and slows to a gradual stop
926 * anim.animateBy( imageActor,"position", [100,200,0], options );
929 void AnimationApi::AnimateBy( const v8::FunctionCallbackInfo<v8::Value>& args )
931 v8::Isolate* isolate = args.GetIsolate();
932 v8::HandleScope handleScope( isolate );
934 Animation anim = GetAnimation( isolate, args );
935 AnimationParameters animParams( anim );
937 // grab all the parameters
938 bool ok = GetAnimationParameters( isolate, args, animParams, AnimationApi::PROPERTY_VALUE);
941 // GetAnimationParameters will log
945 if( animParams.optionsFound )
947 anim.AnimateBy( Property( animParams.target, animParams.propertyIndex ),
949 animParams.alphaFunction,
950 TimePeriod( animParams.delay, animParams.duration) );
954 anim.AnimateBy( Property( animParams.target, animParams.propertyIndex ), animParams.value );
961 * Animate a property to a destination value.
963 * The effect will start & end when the animation begins & ends.
966 * @param {Object} target object that contains a property to be animated (e.g. myActor )
967 * @param {String} property name (e.g. "position" )
968 * @param {Object} destinationValue The property value will changed to this value
969 * @param {Object} [options] Animation options.
970 * @param {Float} [options.delay] amount to delay the start of the animation in seconds
971 * @param {Float} [options.duration] duration of the animation
972 * @param {String} [options.alpha] Animation alpha function (e.g. "linear")
976 * var anim = new dali.Animation( 1 );
977 * anim.animateTo( imageActor,"positionX", 30 );
981 * // with the optional animation options object
983 * delay: 3, // 3 second delay before starting
984 * duration: 5, // 5 second duration
985 * alpha:"easeInOutSine" // Speeds up and slows to a gradual stop
988 * anim.animateTo( imageActor,"position", [100,200,0], options );
991 void AnimationApi::AnimateTo( const v8::FunctionCallbackInfo< v8::Value >& args )
993 v8::Isolate* isolate = args.GetIsolate();
994 v8::HandleScope handleScope( isolate );
996 Animation anim = GetAnimation( isolate, args );
997 AnimationParameters animParams( anim );
999 // grab all the parameters
1000 bool ok = GetAnimationParameters( isolate, args, animParams, AnimationApi::PROPERTY_VALUE );
1003 // GetAnimationParameters will log
1007 if( animParams.optionsFound )
1010 anim.AnimateTo( Property( animParams.target,animParams.propertyIndex ),
1012 animParams.alphaFunction,
1013 TimePeriod( animParams.delay, animParams.duration) );
1017 anim.AnimateTo( Property( animParams.target, animParams.propertyIndex ), animParams.value );
1023 * Animate a property between keyframes.
1025 * The effect will start & end when the animation begins & ends.
1026 * @method animateBetween
1028 * @param {Object} target object that contains a property to be animated (e.g. myActor )
1029 * @param {String} property name (e.g. "position" )
1030 * @param {Object} keyframes array of keyframe objects
1031 * @param {Object} [options] Animation options.
1032 * @param {Float} [options.delay] amount to delay the start of the animation in seconds
1033 * @param {Float} [options.duration] duration of the animation
1034 * @param {String} [options.alpha] Animation alpha function (e.g. "linear")
1039 * create some keyframes to move an actor around a square, and return to the start
1041 * <img src="../assets/img/keyframe-animation.png">
1056 * value: [500,500,0]
1068 * anim.animateBetween( imageActor,"position", keyframes );
1071 void AnimationApi::AnimateBetween( const v8::FunctionCallbackInfo< v8::Value >& args )
1073 v8::Isolate* isolate = args.GetIsolate();
1074 v8::HandleScope handleScope( isolate );
1076 Animation anim = GetAnimation( isolate, args );
1077 AnimationParameters animParams( anim );
1079 // grab all the parameters
1080 bool ok = GetAnimationParameters( isolate, args, animParams, AnimationApi::KEYFRAMES );
1083 // GetAnimationParameters will log
1087 // if animation options exist...
1088 if( animParams.optionsFound )
1091 anim.AnimateBetween( Property( animParams.target,animParams.propertyIndex ),
1092 animParams.keyFrames,
1093 animParams.alphaFunction,
1094 TimePeriod( animParams.delay, animParams.duration) );
1098 anim.AnimateBetween( Property( animParams.target, animParams.propertyIndex ), animParams.keyFrames );
1103 * show an actor during the animation.
1105 * This is a helper, which simulates animating the visibility property of an actor
1106 * with zero duration ( it is just a boolean).
1107 * e.g. it performs anim.AnimateTo( actor,"visible",true, { delay:delay: duration:0 } );
1110 * @param {Object} Actor
1111 * @param {float} delay until the actor is shown
1113 void AnimationApi::Show( const v8::FunctionCallbackInfo< v8::Value >& args )
1115 v8::Isolate* isolate = args.GetIsolate();
1116 v8::HandleScope handleScope( isolate );
1117 Animation anim = GetAnimation( isolate, args );
1118 bool found( false );
1120 Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
1123 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 0 actor" );
1127 float delay = V8Utils::GetFloatParameter( PARAMETER_1, found, isolate, args, 1.f /* default */);
1130 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 1 delay" );
1133 anim.Show( actor, delay );
1138 * hide an actor during the animation.
1140 * This is a helper, which simulates animating the visibility property of an actor
1141 * with zero duration ( it is just a boolean).
1142 * e.g. it performs anim.AnimateTo( actor,"visible",false, { delay:delay: duration:0 } );
1145 * @param {Object} Actor
1146 * @param {float} delay until the actor is hidden
1148 void AnimationApi::Hide( const v8::FunctionCallbackInfo< v8::Value >& args )
1150 v8::Isolate* isolate = args.GetIsolate();
1151 v8::HandleScope handleScope( isolate );
1152 Animation anim = GetAnimation( isolate, args );
1153 bool found( false );
1154 Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
1157 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 0 actor" );
1162 float delay = V8Utils::GetFloatParameter( PARAMETER_1, found, isolate, args, 1.f /* default */);
1165 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 1 delay" );
1168 anim.Hide( actor, delay );
1174 } // namespace V8Plugin