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"
24 #include <dali/integration-api/debug.h>
25 #include <animation/animation-wrapper.h>
26 #include <object/property-value-wrapper.h>
27 #include <dali/public-api/common/map-wrapper.h>
35 namespace // un named namespace
38 // @todo think about alternative ways of passing around
39 struct AlphaFuncStruct
41 const char* const name;
42 AlphaFunction alphaFunc;
45 * Contains a list of alpha functions that can be used.
46 * We use a stl map as lookup to map a string name to the function
48 const AlphaFuncStruct AlphaFunctionTable[]=
50 {"default" , AlphaFunctions::Default },
51 {"linear" , AlphaFunctions::Linear },
52 {"square" , AlphaFunctions::Square },
53 {"reverse" , AlphaFunctions::Reverse },
54 {"easeIn" , AlphaFunctions::EaseIn },
55 {"easeOut" , AlphaFunctions::EaseOut },
56 {"easeInOut" , AlphaFunctions::EaseInOut },
57 {"easeInSine" , AlphaFunctions::EaseInSine },
58 {"easeOutSine" , AlphaFunctions::EaseOutSine },
59 {"easeInOutSine" , AlphaFunctions::EaseInOutSine },
60 {"easeInSine33" , AlphaFunctions::EaseInSine33 },
61 {"easeOutSine33" , AlphaFunctions::EaseOutSine33 },
62 {"easeInOutSine33" , AlphaFunctions::EaseInOutSine33 },
63 {"easeInOutSine50" , AlphaFunctions::EaseInOutSine50 },
64 {"easeInOutSine60" , AlphaFunctions::EaseInOutSine60 },
65 {"easeInOutSine70" , AlphaFunctions::EaseInOutSine70 },
66 {"easeInOutSine80" , AlphaFunctions::EaseInOutSine80 },
67 {"easeInOutSine90" , AlphaFunctions::EaseInOutSine90 },
68 {"doubleEaseInOutSine60" , AlphaFunctions::DoubleEaseInOutSine60},
69 {"easeOutQuint50" , AlphaFunctions::EaseOutQuint50 },
70 {"easeOutQuint80" , AlphaFunctions::EaseOutQuint80 },
71 {"bounce" , AlphaFunctions::Bounce },
72 {"bounceBack" , AlphaFunctions::BounceBack },
73 {"easeInBack" , AlphaFunctions::EaseInBack },
74 {"easeOutBack" , AlphaFunctions::EaseOutBack },
75 {"easeInOutBack" , AlphaFunctions::EaseInOutBack },
76 {"sin" , AlphaFunctions::Sin },
77 {"sin2x" , AlphaFunctions::Sin2x }
79 const unsigned int AlphaFunctionTableCount = sizeof(AlphaFunctionTable)/sizeof(AlphaFunctionTable[0]);
80 const char* const DEFAULT_ALPHA_NAME = "default";
81 static AlphaFunction DEFAULT_ALPHA_FUNCTION = AlphaFunctions::Default;
85 AlphaFunction GetAlphaFunction( const std::string& alphaFuncName )
87 // This will normally get called just a few times during the application, so no point in doing anything clever
88 for( unsigned int i = 0; i < AlphaFunctionTableCount; i++)
90 const AlphaFuncStruct& alphaStruct( AlphaFunctionTable[i] );
92 if( std::strcmp( alphaStruct.name , alphaFuncName.c_str() ) == 0 )
94 return alphaStruct.alphaFunc;
98 DALI_LOG_ERROR("Failed to find alpha func |%s| \n", alphaFuncName.c_str() );
99 return AlphaFunctions::Default;
102 const char* const GetAlphaFunctionName( AlphaFunction alphaFunc )
104 // This may get called 3 times during the application, so no point
105 // in doing anything clever
107 for( unsigned int i = 0; i < AlphaFunctionTableCount; i++)
109 const AlphaFuncStruct& alphaStruct( AlphaFunctionTable[i] );
112 if( alphaStruct.alphaFunc == alphaFunc )
114 return alphaStruct.name;
121 struct AnimationParameters
123 AnimationParameters( const Animation& anim)
124 : propertyIndex( Property::INVALID_INDEX ),
125 alphaFunction( DEFAULT_ALPHA_FUNCTION),
127 duration(anim.GetDuration()),
128 optionsFound( false )
133 Property::Index propertyIndex;
134 Property::Value value;
136 AlphaFunction alphaFunction;
142 void GetAnimationOptions( v8::Isolate* isolate,
143 v8::Local<v8::Value > options,
144 AnimationParameters& animParams )
146 // animation options is an optional parameter passed in which holds
148 // var animOptions = {
153 v8::HandleScope handleScope( isolate );
155 if( options->IsObject() )
157 v8::Local<v8::Object> obj = options->ToObject();
158 v8::Local<v8::Value> alphaValue = obj->Get( v8::String::NewFromUtf8( isolate, "alpha" ) );
159 if( alphaValue->IsString() )
161 animParams.optionsFound = true;
162 std::string alphaName = V8Utils::v8StringToStdString( alphaValue );
163 animParams.alphaFunction = GetAlphaFunction( alphaName );
166 v8::Local<v8::Value> delayValue = obj->Get( v8::String::NewFromUtf8( isolate, "delay" ) );
167 if( delayValue->IsNumber() )
169 animParams.optionsFound = true;
170 v8::Local<v8::Number> num = delayValue->ToNumber();
171 animParams.delay = num->Value();
174 v8::Local<v8::Value> durationValue = obj->Get( v8::String::NewFromUtf8( isolate, "duration" ) );
175 if( durationValue->IsNumber() )
177 animParams.optionsFound = true;
178 v8::Local<v8::Number> num = durationValue->ToNumber();
179 animParams.duration = num->Value();
184 KeyFrames GetKeyFrames( v8::Isolate* isolate, v8::Local<v8::Value > keyFrameArray )
186 // keyframe object is an array of
189 // value: property value ( position/ rotation etc)
192 v8::HandleScope handleScope( isolate );
194 if( !keyFrameArray->IsObject() || !keyFrameArray->IsArray() )
196 DALI_SCRIPT_EXCEPTION( isolate, "missing keyframe array" );
200 KeyFrames keyframes = KeyFrames::New();
202 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast( keyFrameArray );
203 for( uint32_t i=0; i < array->Length() ; ++i)
205 v8::Handle<v8::Value> arrayItem = array->Get( i );
207 if(!arrayItem->IsObject() )
209 DALI_SCRIPT_EXCEPTION( isolate, "missing keyframe object" );
212 v8::Handle<v8::Object> keyFrameObject = arrayItem->ToObject();
214 // get keyframe.progress
215 v8::Handle<v8::Value> progress = keyFrameObject->Get(v8::String::NewFromUtf8( isolate, "progress"));
216 if( !progress->IsNumber() )
218 DALI_SCRIPT_EXCEPTION( isolate, "keyframe missing progress property" );
222 // get keyframe.value
224 v8::Handle<v8::Value> propertyValue = keyFrameObject->Get(v8::String::NewFromUtf8( isolate, "value"));
225 Property::Value value = V8Utils::GetPropertyValueFromObject( found, isolate, propertyValue );
228 DALI_SCRIPT_EXCEPTION( isolate, "keyframe missing value property" );
232 // get keyframe.alpha
233 v8::Handle<v8::Value> alphaValue = keyFrameObject->Get(v8::String::NewFromUtf8( isolate, "alpha"));
234 if( alphaValue->IsString() )
236 std::string alphaName = V8Utils::v8StringToStdString( alphaValue );
237 AlphaFunction alphaFunction = GetAlphaFunction( alphaName );
238 keyframes.Add( progress->NumberValue(), value, alphaFunction );
242 keyframes.Add( progress->NumberValue(), value );
249 bool GetAnimationParameters( v8::Isolate* isolate,
250 const v8::FunctionCallbackInfo< v8::Value >& args,
251 AnimationParameters& animParams,
252 AnimationApi::AnimationParameterType type)
254 // used for things like anim.AnimateBy( myImageActor, property-name, property-value (or Javascript number array));
255 // 1 extract property handle from param1.
256 // 2 extract property name from param2 ( can be in the format "u-color" or "uColor"
257 // 3 extract PropertyValue from param3
258 // 4 extract animation options ( delay, duration, alpha func)
262 animParams.target = V8Utils::GetHandleParameter( PARAMETER_0, foundHandle, isolate, args );
265 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 0 (Handle)" );
269 // 2 extract property name
271 std::string propertyName = V8Utils::GetStringParameter( PARAMETER_1, foundPropName, isolate, args );
274 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 1 ( PropertyName )" );
277 // try both properties with dashes and without
278 Property::Index index = animParams.target.GetPropertyIndex( propertyName );
280 if( index == Property::INVALID_INDEX )
282 // convert the property name from "uColor" to "u-color"
283 std::string convetedName = V8Utils::JavaScriptNameToPropertyName( propertyName );
284 index = animParams.target.GetPropertyIndex( convetedName );
287 animParams.propertyIndex = index;
289 if( type == AnimationApi::PROPERTY_VALUE )
291 // 3 extract property value
292 bool foundPropValue( false );
293 animParams.value = V8Utils::GetPropertyValueParameter( PARAMETER_2, foundPropValue, isolate, args );
294 if( !foundPropValue )
296 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 2 ( value )" );
300 else // type == KEYFRAMES
302 animParams.keyFrames = GetKeyFrames(isolate, args[2]);
304 // 4 extract animation options
305 GetAnimationOptions( isolate, args[3], animParams );
310 Animation GetAnimation( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
312 v8::HandleScope handleScope( isolate );
314 v8::Local<v8::Object> object = args.This();
315 v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField( 0 ) );
316 void* ptr = field->Value();
318 AnimationWrapper* wrapper = static_cast<AnimationWrapper *>( ptr );
319 return wrapper->GetAnimation();
323 } // un-named namespace
331 * @param {float} duration
334 Animation AnimationApi::New( const v8::FunctionCallbackInfo< v8::Value >& args )
336 v8::Isolate* isolate = args.GetIsolate();
337 v8::HandleScope handleScope( isolate );
340 float value = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 1.f /* default */);
343 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
347 return Animation::New( value );
351 * Set the animation duration.
352 * @method setDuration
354 * @param {float} duration in seconds
357 void AnimationApi::SetDuration( const v8::FunctionCallbackInfo< v8::Value >& args )
359 v8::Isolate* isolate = args.GetIsolate();
360 v8::HandleScope handleScope( isolate );
362 Animation anim = GetAnimation( isolate, args );
365 float value = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 1.f /* default */);
368 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
371 anim.SetDuration( value );
374 * Get the animation duration.
375 * @method getDuration
377 * @return {float} duration in seconds
380 void AnimationApi::GetDuration( const v8::FunctionCallbackInfo< v8::Value >& args )
382 v8::Isolate* isolate = args.GetIsolate();
383 v8::HandleScope handleScope( isolate );
385 Animation anim = GetAnimation( isolate, args );
387 args.GetReturnValue().Set( v8::Number::New( isolate, anim.GetDuration() ) );
391 * Set whether the animation will loop.
394 * @param {bool} looping enabled
397 void AnimationApi::SetLooping( const v8::FunctionCallbackInfo< v8::Value >& args )
399 v8::Isolate* isolate = args.GetIsolate();
400 v8::HandleScope handleScope( isolate );
402 Animation anim = GetAnimation( isolate, args );
405 bool value = V8Utils::GetBooleanParameter( PARAMETER_0, found, isolate, args );
408 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
412 anim.SetLooping( value );
417 * Query whether the animation will loop.
420 * @return {bool} looping enabled
423 void AnimationApi::IsLooping( const v8::FunctionCallbackInfo< v8::Value >& args )
425 v8::Isolate* isolate = args.GetIsolate();
426 v8::HandleScope handleScope( isolate );
428 Animation anim = GetAnimation( isolate, args );
430 args.GetReturnValue().Set( v8::Boolean::New( isolate, anim.IsLooping() ) );
434 * Set the end action of the animation.
436 * This action is performed when the animation ends.
437 * Default end action is bake
438 * @method setEndAction
440 * @param {integer} bake mode
442 * anim.setEndAction( dali.ANIMATION_BAKE ); // When the animation ends, the animated property values are saved.
443 * anim.setEndAction( dali.ANIMATION_DISCARD ); // When the animation ends, the animated property values are forgotten.
444 * 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.
446 void AnimationApi::SetEndAction( const v8::FunctionCallbackInfo< v8::Value >& args )
448 v8::Isolate* isolate = args.GetIsolate();
449 v8::HandleScope handleScope( isolate );
451 Animation anim = GetAnimation( isolate, args );
454 int value = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
457 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
461 anim.SetEndAction( static_cast<Animation::EndAction>( value ) );
466 * Returns the end action of the animation.
468 * @method getEndAction
470 * @return {integer} bake mode
472 * There are 3 different bake modes
474 * dali.ANIMATION_BAKE // When the animation ends, the animated property values are saved.
475 * dali.ANIMATION_DISCARD // When the animation ends, the animated property values are forgotten.
476 * 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.
478 void AnimationApi::GetEndAction( const v8::FunctionCallbackInfo< v8::Value >& args )
480 v8::Isolate* isolate = args.GetIsolate();
481 v8::HandleScope handleScope( isolate );
483 Animation anim = GetAnimation( isolate, args );
485 args.GetReturnValue().Set( v8::Integer::New( isolate, anim.GetEndAction() ) );
489 * Set the disconnect action of the animation.
490 * If any of the animated property owners are disconnected from the stage, this action is performed.
491 * Default disconnection action is BakeFinal.
492 * @method setDisconnectAction
494 * @param {integer} end mode
496 * There are 3 different end modes
498 * dali.ANIMATION_BAKE // When the animation is destroyed, the animated property values are saved.
499 * dali.ANIMATION_DISCARD // When the animation is destroyed, the animated property values are forgotten.
500 * 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.
502 void AnimationApi::SetDisconnectAction( const v8::FunctionCallbackInfo< v8::Value >& args )
504 v8::Isolate* isolate = args.GetIsolate();
505 v8::HandleScope handleScope( isolate );
507 Animation anim = GetAnimation( isolate, args );
510 int value = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
513 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
517 anim.SetDisconnectAction( static_cast<Animation::EndAction>( value ) );
522 * Returns the disconnect action of the animation.
523 * @method getDisconnectAction
525 * @return {integer} end mode
527 void AnimationApi::GetDisconnectAction( const v8::FunctionCallbackInfo< v8::Value >& args )
529 v8::Isolate* isolate = args.GetIsolate();
530 v8::HandleScope handleScope( isolate );
532 Animation anim = GetAnimation( isolate, args );
534 args.GetReturnValue().Set( v8::Integer::New( isolate, anim.GetDisconnectAction() ) );
537 * Set the default alpha function for an animation.
538 * @method setDefaultAlphaFunction
540 * @param {string} alpha function
542 void AnimationApi::SetDefaultAlphaFunction( const v8::FunctionCallbackInfo< v8::Value >& args )
544 v8::Isolate* isolate = args.GetIsolate();
545 v8::HandleScope handleScope( isolate );
547 Animation anim = GetAnimation( isolate, args );
550 std::string alphaFunc = V8Utils::GetStringParameter( PARAMETER_0, found, isolate, args );
553 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
557 AlphaFunction func = GetAlphaFunction( alphaFunc );
558 anim.SetDefaultAlphaFunction( func );
563 * Get the default alpha function for an animation.
564 * @method getDefaultAlphaFunction
566 * @return {string} alpha function
568 void AnimationApi::GetDefaultAlphaFunction( const v8::FunctionCallbackInfo<v8::Value>& args )
570 v8::Isolate* isolate = args.GetIsolate();
571 v8::HandleScope handleScope( isolate );
573 Animation anim = GetAnimation( isolate, args );
575 std::string alphaName = GetAlphaFunctionName( anim.GetDefaultAlphaFunction() );
578 args.GetReturnValue().Set( v8::String::NewFromUtf8( isolate, alphaName.c_str() ) );
582 * Get the current progress of the animation.
583 * @method getCurrentProgress
585 * @return {float} The current progress as a normalized value between [0..1].
588 void AnimationApi::GetCurrentProgress( const v8::FunctionCallbackInfo< v8::Value >& args )
590 v8::Isolate* isolate = args.GetIsolate();
591 v8::HandleScope handleScope( isolate );
593 Animation anim = GetAnimation( isolate, args );
595 args.GetReturnValue().Set( v8::Number::New( isolate, anim.GetCurrentProgress() ) );
599 * Specifies an speed factor for the animation.
601 * The speed factor is a multiplier of the normal velocity of the animation. Values between [0,1] will
602 * slow down the animation and values above one will speed up the animation. It is also possible to specify a negative multiplier
603 * to play the animation in reverse.
605 * @method setSpeedFactor
607 * @param {float} value which will multiply the velocity.
609 * anim.setSpeedFactor(2);
610 * anim.play(); // plays the animation twice as fast
613 * anim.setSpeedFactor(0.5);
614 * anim.play(); // plays the animation half speed
617 void AnimationApi::SetSpeedFactor( const v8::FunctionCallbackInfo< v8::Value >& args )
619 v8::Isolate* isolate = args.GetIsolate();
620 v8::HandleScope handleScope( isolate );
622 Animation anim = GetAnimation( isolate, args );
625 float speedFactor = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 0.f );
628 DALI_SCRIPT_EXCEPTION( isolate, "float parameter missing" );
632 anim.SetSpeedFactor( speedFactor );
638 * Retrieve the speed factor of the animation
641 * @method getSpeedFactor
643 * @return {float} speed factor
645 void AnimationApi::GetSpeedFactor( const v8::FunctionCallbackInfo< v8::Value >& args )
647 v8::Isolate* isolate = args.GetIsolate();
648 v8::HandleScope handleScope( isolate );
650 Animation anim = GetAnimation( isolate, args );
652 args.GetReturnValue().Set( v8::Number::New( isolate, anim.GetSpeedFactor() ) );
656 * Set the playing range.
657 * Animation will play between the values specified.
658 * Both values ( range.x and range.y ) should be between 0-1,
659 * otherwise they will be ignored.
660 * If the range provided is not in proper order ( minimum,maximum), it will be reordered.
661 * @method setPlayRange
663 * @param {Object} Range
664 * @param {Float} Range.start
665 * @param {Float} Range.end
667 * var range = { start:0.1, end:0.6 };
668 * anim.setPlayRange( range );
670 void AnimationApi::SetPlayRange( const v8::FunctionCallbackInfo< v8::Value >& args )
672 v8::Isolate* isolate = args.GetIsolate();
673 v8::HandleScope handleScope( isolate );
675 Animation anim = GetAnimation( isolate, args );
678 if( args.Length() != 1 )
680 DALI_SCRIPT_EXCEPTION( isolate, "missing / invalid parameters" );
683 v8::Local<v8::Value > rangeValue = args[0];
684 if( !rangeValue->IsObject() )
686 DALI_SCRIPT_EXCEPTION( isolate, "invalid parameters" );
689 v8::Local<v8::Object> obj = rangeValue->ToObject();
690 v8::Local<v8::Value> startValue = obj->Get( v8::String::NewFromUtf8( isolate, "start" ) );
691 v8::Local<v8::Value> endValue = obj->Get( v8::String::NewFromUtf8( isolate, "end" ) );
693 if( startValue->IsNumber() && endValue->IsNumber())
695 range.x= startValue->ToNumber()->Value();
696 range.y = endValue->ToNumber()->Value();
700 DALI_SCRIPT_EXCEPTION( isolate, "missing start/end value" );
704 anim.SetPlayRange( range );
709 * Get the playing range.
710 * @method getPlayRange
712 * @return {Object} Range with { start: , end: } properties.
714 void AnimationApi::GetPlayRange( const v8::FunctionCallbackInfo< v8::Value >& args )
716 v8::Isolate* isolate = args.GetIsolate();
717 v8::EscapableHandleScope handleScope( isolate );
718 Animation anim = GetAnimation( isolate, args );
721 v8::Local<v8::Object> rangeObject = v8::Object::New( isolate );
723 Vector2 range = anim.GetPlayRange();
726 rangeObject->Set( v8::String::NewFromUtf8( isolate, "start"), v8::Number::New( isolate,range.x ));
729 rangeObject->Set( v8::String::NewFromUtf8( isolate, "end"), v8::Number::New( isolate,range.y ));
731 args.GetReturnValue().Set( rangeObject );
736 * Sets the progress of the animation.
737 * The animation will play (or continue playing) from this point. The progress
738 * must be in the 0-1 interval or in the play range interval if defined ( See SetPlayRange ),
739 * otherwise, it will be ignored.
741 * @method setCurrentProgress
743 * @param {float} progress The new progress as a normalized value between [0,1] or between the
744 * play range if specified.
746 void AnimationApi::SetCurrentProgress( const v8::FunctionCallbackInfo< v8::Value >& args )
748 v8::Isolate* isolate = args.GetIsolate();
749 v8::HandleScope handleScope( isolate );
751 Animation anim = GetAnimation( isolate, args );
755 float progress = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 0.f );
758 DALI_SCRIPT_EXCEPTION( isolate, "float parameter missing" );
761 anim.SetCurrentProgress( progress );
767 * Play the animation from a given point.
768 * The progress must be in the 0-1 interval or in the play range interval if defined ( See SetPlayRange ),
769 * otherwise, it will be ignored.
772 * @param {float} progress A value between [0,1], or between the play range if specified, form where the animation should start playing
774 void AnimationApi::PlayFrom( const v8::FunctionCallbackInfo< v8::Value >& args )
776 v8::Isolate* isolate = args.GetIsolate();
777 v8::HandleScope handleScope( isolate );
779 Animation anim = GetAnimation( isolate, args );
783 float progress = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 0.f );
786 DALI_SCRIPT_EXCEPTION( isolate, "float parameter missing" );
789 anim.PlayFrom( progress );
798 void AnimationApi::Play( const v8::FunctionCallbackInfo<v8::Value>& args )
800 v8::Isolate* isolate = args.GetIsolate();
801 v8::HandleScope handleScope( isolate );
803 Animation anim = GetAnimation( isolate, args );
807 * Pause the animation
811 void AnimationApi::Pause( const v8::FunctionCallbackInfo<v8::Value>& args )
813 v8::Isolate* isolate = args.GetIsolate();
814 v8::HandleScope handleScope( isolate );
816 Animation anim = GetAnimation( isolate, args );
824 void AnimationApi::Stop( const v8::FunctionCallbackInfo<v8::Value>& args )
826 v8::Isolate* isolate = args.GetIsolate();
827 v8::HandleScope handleScope( isolate );
829 Animation anim = GetAnimation( isolate, args );
833 * Clear the animation
834 * This disconnects any objects that were being animated, effectively stopping the animation.
838 void AnimationApi::Clear( const v8::FunctionCallbackInfo<v8::Value>& args )
840 v8::Isolate* isolate = args.GetIsolate();
841 v8::HandleScope handleScope( isolate );
843 Animation anim = GetAnimation( isolate, args );
848 void AnimationApi::Animate( const v8::FunctionCallbackInfo<v8::Value>& args )
850 v8::Isolate* isolate = args.GetIsolate();
851 v8::HandleScope handleScope( isolate );
853 Animation anim = GetAnimation( isolate, args );
854 AnimationParameters animParams( anim );
858 Dali::Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
861 DALI_SCRIPT_EXCEPTION( isolate, "Missing actor parameter");
867 BaseWrappedObject* wrapper = V8Utils::GetWrappedDaliObjectParameter( PARAMETER_1, BaseWrappedObject::PATH, isolate, args);
868 PathWrapper* pathWrapper = static_cast< PathWrapper*>( wrapper );
873 path = pathWrapper->GetPath();
877 Vector3 forward = V8Utils::GetVector3Parameter( PARAMETER_2, bFound, isolate, args );
883 //Get animation options
884 GetAnimationOptions( isolate, args[3], animParams );
885 if( animParams.optionsFound )
887 anim.Animate( actor, path, forward, animParams.alphaFunction, TimePeriod( animParams.delay, animParams.duration) );
891 anim.Animate( actor, path, forward );
897 * Animate a property value by a relative amount.
899 * The effect will start & end when the animation begins & ends.
902 * @param {Object} target object that contains a property to be animated (e.g. myActor )
903 * @param {String} property name (e.g. "position" )
904 * @param {Object} relativeValue The property value will change by this amount.
905 * @param {Object} [options] Animation options.
906 * @param {Float} [options.delay] amount to delay the start of the animation in seconds
907 * @param {Float} [options.duration] duration of the animation
908 * @param {String} [options.alpha] Animation alpha function (e.g. "linear")
912 * // animation x position
913 * var anim = new dali.Animation( 1 );
914 * anim.animateBy( imageActor,"positionX", 30 );
917 * // animate x,y,z position with the optional animation options
919 * delay: 3, // 3 second delay before starting
920 * duration: 5, // 5 second duration
921 * alpha:"easeInOutSine" // Speeds up and slows to a gradual stop
924 * anim.animateBy( imageActor,"position", [100,200,0], options );
927 void AnimationApi::AnimateBy( const v8::FunctionCallbackInfo<v8::Value>& args )
929 v8::Isolate* isolate = args.GetIsolate();
930 v8::HandleScope handleScope( isolate );
932 Animation anim = GetAnimation( isolate, args );
933 AnimationParameters animParams( anim );
935 // grab all the parameters
936 bool ok = GetAnimationParameters( isolate, args, animParams, AnimationApi::PROPERTY_VALUE);
939 // GetAnimationParameters will log
943 if( animParams.optionsFound )
945 anim.AnimateBy( Property( animParams.target, animParams.propertyIndex ),
947 animParams.alphaFunction,
948 TimePeriod( animParams.delay, animParams.duration) );
952 anim.AnimateBy( Property( animParams.target, animParams.propertyIndex ), animParams.value );
959 * Animate a property to a destination value.
961 * The effect will start & end when the animation begins & ends.
964 * @param {Object} target object that contains a property to be animated (e.g. myActor )
965 * @param {String} property name (e.g. "position" )
966 * @param {Object} destinationValue The property value will changed to this value
967 * @param {Object} [options] Animation options.
968 * @param {Float} [options.delay] amount to delay the start of the animation in seconds
969 * @param {Float} [options.duration] duration of the animation
970 * @param {String} [options.alpha] Animation alpha function (e.g. "linear")
974 * var anim = new dali.Animation( 1 );
975 * anim.animateTo( imageActor,"positionX", 30 );
979 * // with the optional animation options object
981 * delay: 3, // 3 second delay before starting
982 * duration: 5, // 5 second duration
983 * alpha:"easeInOutSine" // Speeds up and slows to a gradual stop
986 * anim.animateTo( imageActor,"position", [100,200,0], options );
989 void AnimationApi::AnimateTo( const v8::FunctionCallbackInfo< v8::Value >& args )
991 v8::Isolate* isolate = args.GetIsolate();
992 v8::HandleScope handleScope( isolate );
994 Animation anim = GetAnimation( isolate, args );
995 AnimationParameters animParams( anim );
997 // grab all the parameters
998 bool ok = GetAnimationParameters( isolate, args, animParams, AnimationApi::PROPERTY_VALUE );
1001 // GetAnimationParameters will log
1005 if( animParams.optionsFound )
1008 anim.AnimateTo( Property( animParams.target,animParams.propertyIndex ),
1010 animParams.alphaFunction,
1011 TimePeriod( animParams.delay, animParams.duration) );
1015 anim.AnimateTo( Property( animParams.target, animParams.propertyIndex ), animParams.value );
1021 * Animate a property between keyframes.
1023 * The effect will start & end when the animation begins & ends.
1024 * @method animateBetween
1026 * @param {Object} target object that contains a property to be animated (e.g. myActor )
1027 * @param {String} property name (e.g. "position" )
1028 * @param {Object} keyframes array of keyframe objects
1029 * @param {Object} [options] Animation options.
1030 * @param {Float} [options.delay] amount to delay the start of the animation in seconds
1031 * @param {Float} [options.duration] duration of the animation
1032 * @param {String} [options.alpha] Animation alpha function (e.g. "linear")
1037 * create some keyframes to move an actor around a square, and return to the start
1039 * <img src="../assets/img/keyframe-animation.png">
1054 * value: [500,500,0]
1066 * anim.animateBetween( imageActor,"position", keyframes );
1069 void AnimationApi::AnimateBetween( const v8::FunctionCallbackInfo< v8::Value >& args )
1071 v8::Isolate* isolate = args.GetIsolate();
1072 v8::HandleScope handleScope( isolate );
1074 Animation anim = GetAnimation( isolate, args );
1075 AnimationParameters animParams( anim );
1077 // grab all the parameters
1078 bool ok = GetAnimationParameters( isolate, args, animParams, AnimationApi::KEYFRAMES );
1081 // GetAnimationParameters will log
1085 // if animation options exist...
1086 if( animParams.optionsFound )
1089 anim.AnimateBetween( Property( animParams.target,animParams.propertyIndex ),
1090 animParams.keyFrames,
1091 animParams.alphaFunction,
1092 TimePeriod( animParams.delay, animParams.duration) );
1096 anim.AnimateBetween( Property( animParams.target, animParams.propertyIndex ), animParams.keyFrames );
1101 * show an actor during the animation.
1103 * This is a helper, which simulates animating the visibility property of an actor
1104 * with zero duration ( it is just a boolean).
1105 * e.g. it performs anim.AnimateTo( actor,"visible",true, { delay:delay: duration:0 } );
1108 * @param {Object} Actor
1109 * @param {float} delay until the actor is shown
1111 void AnimationApi::Show( const v8::FunctionCallbackInfo< v8::Value >& args )
1113 v8::Isolate* isolate = args.GetIsolate();
1114 v8::HandleScope handleScope( isolate );
1115 Animation anim = GetAnimation( isolate, args );
1116 bool found( false );
1118 Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
1121 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 0 actor" );
1125 float delay = V8Utils::GetFloatParameter( PARAMETER_1, found, isolate, args, 1.f /* default */);
1128 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 1 delay" );
1131 anim.Show( actor, delay );
1136 * hide an actor during the animation.
1138 * This is a helper, which simulates animating the visibility property of an actor
1139 * with zero duration ( it is just a boolean).
1140 * e.g. it performs anim.AnimateTo( actor,"visible",false, { delay:delay: duration:0 } );
1143 * @param {Object} Actor
1144 * @param {float} delay until the actor is hidden
1146 void AnimationApi::Hide( const v8::FunctionCallbackInfo< v8::Value >& args )
1148 v8::Isolate* isolate = args.GetIsolate();
1149 v8::HandleScope handleScope( isolate );
1150 Animation anim = GetAnimation( isolate, args );
1151 bool found( false );
1152 Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
1155 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 0 actor" );
1160 float delay = V8Utils::GetFloatParameter( PARAMETER_1, found, isolate, args, 1.f /* default */);
1163 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 1 delay" );
1166 anim.Hide( actor, delay );
1172 } // namespace V8Plugin