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 <dali/integration-api/debug.h>
28 #include <animation/animation-wrapper.h>
29 #include <object/property-value-wrapper.h>
37 namespace // un named namespace
40 struct AnimationParameters
42 AnimationParameters( const Animation& anim)
43 : propertyIndex( Property::INVALID_INDEX ),
44 alphaFunction( AlphaFunction::DEFAULT),
46 duration(anim.GetDuration()),
52 Property::Index propertyIndex;
53 Property::Value value;
55 AlphaFunction alphaFunction;
61 void GetAnimationOptions( v8::Isolate* isolate,
62 v8::Local<v8::Value > options,
63 AnimationParameters& animParams )
65 // animation options is an optional parameter passed in which holds
67 // var animOptions = {
72 v8::HandleScope handleScope( isolate );
74 if( options->IsObject() )
76 v8::Local<v8::Object> obj = options->ToObject();
77 v8::Local<v8::Value> alphaValue = obj->Get( v8::String::NewFromUtf8( isolate, "alpha" ) );
78 if( alphaValue->IsUint32() )
80 animParams.optionsFound = true;
81 animParams.alphaFunction = static_cast<AlphaFunction::BuiltinFunction>(alphaValue->ToUint32()->Value());
84 v8::Local<v8::Value> delayValue = obj->Get( v8::String::NewFromUtf8( isolate, "delay" ) );
85 if( delayValue->IsNumber() )
87 animParams.optionsFound = true;
88 v8::Local<v8::Number> num = delayValue->ToNumber();
89 animParams.delay = num->Value();
92 v8::Local<v8::Value> durationValue = obj->Get( v8::String::NewFromUtf8( isolate, "duration" ) );
93 if( durationValue->IsNumber() )
95 animParams.optionsFound = true;
96 v8::Local<v8::Number> num = durationValue->ToNumber();
97 animParams.duration = num->Value();
102 KeyFrames GetKeyFrames( v8::Isolate* isolate, v8::Local<v8::Value > keyFrameArray )
104 // keyframe object is an array of
107 // value: property value ( position/ rotation etc)
110 v8::HandleScope handleScope( isolate );
112 if( !keyFrameArray->IsObject() || !keyFrameArray->IsArray() )
114 DALI_SCRIPT_EXCEPTION( isolate, "missing keyframe array" );
118 KeyFrames keyframes = KeyFrames::New();
120 v8::Local<v8::Array> array = v8::Local<v8::Array>::Cast( keyFrameArray );
121 for( uint32_t i=0; i < array->Length() ; ++i)
123 v8::Handle<v8::Value> arrayItem = array->Get( i );
125 if(!arrayItem->IsObject() )
127 DALI_SCRIPT_EXCEPTION( isolate, "missing keyframe object" );
130 v8::Handle<v8::Object> keyFrameObject = arrayItem->ToObject();
132 // get keyframe.progress
133 v8::Handle<v8::Value> progress = keyFrameObject->Get(v8::String::NewFromUtf8( isolate, "progress"));
134 if( !progress->IsNumber() )
136 DALI_SCRIPT_EXCEPTION( isolate, "keyframe missing progress property" );
140 // get keyframe.value
142 v8::Handle<v8::Value> propertyValue = keyFrameObject->Get(v8::String::NewFromUtf8( isolate, "value"));
143 Property::Value value = V8Utils::GetPropertyValueFromObject( found, isolate, propertyValue );
146 DALI_SCRIPT_EXCEPTION( isolate, "keyframe missing value property" );
150 // get keyframe.alpha
151 v8::Handle<v8::Value> alphaValue = keyFrameObject->Get(v8::String::NewFromUtf8( isolate, "alpha"));
152 if( alphaValue->IsUint32() )
154 AlphaFunction alphaFunction = static_cast<AlphaFunction::BuiltinFunction>(alphaValue->ToUint32()->Value());
155 keyframes.Add( progress->NumberValue(), value, alphaFunction );
159 keyframes.Add( progress->NumberValue(), value );
166 bool GetAnimationParameters( v8::Isolate* isolate,
167 const v8::FunctionCallbackInfo< v8::Value >& args,
168 AnimationParameters& animParams,
169 AnimationApi::AnimationParameterType type)
171 // used for things like anim.AnimateBy( myImageView, property-name, property-value (or Javascript number array));
172 // 1 extract property handle from param1.
173 // 2 extract property name from param2 ( in the format "uColor" )
174 // 3 extract PropertyValue from param3
175 // 4 extract animation options ( delay, duration, alpha func)
179 animParams.target = V8Utils::GetHandleParameter( PARAMETER_0, foundHandle, isolate, args );
182 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 0 (Handle)" );
186 // 2 extract property name
188 std::string propertyName = V8Utils::GetStringParameter( PARAMETER_1, foundPropName, isolate, args );
191 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 1 ( PropertyName )" );
194 // try both properties with dashes and without
195 Property::Index index = animParams.target.GetPropertyIndex( propertyName );
197 if( index == Property::INVALID_INDEX )
199 index = animParams.target.GetPropertyIndex( propertyName );
202 animParams.propertyIndex = index;
204 if( type == AnimationApi::PROPERTY_VALUE )
206 // 3 extract property value
207 bool foundPropValue( false );
208 animParams.value = V8Utils::GetPropertyValueParameter( PARAMETER_2, foundPropValue, isolate, args );
209 if( !foundPropValue )
211 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 2 ( value )" );
215 else // type == KEYFRAMES
217 animParams.keyFrames = GetKeyFrames(isolate, args[2]);
219 // 4 extract animation options
220 GetAnimationOptions( isolate, args[3], animParams );
225 Animation GetAnimation( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
227 v8::HandleScope handleScope( isolate );
229 v8::Local<v8::Object> object = args.This();
230 v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField( 0 ) );
231 void* ptr = field->Value();
233 AnimationWrapper* wrapper = static_cast<AnimationWrapper *>( ptr );
234 return wrapper->GetAnimation();
238 } // un-named namespace
246 * @param {float} duration
249 Animation AnimationApi::New( const v8::FunctionCallbackInfo< v8::Value >& args )
251 v8::Isolate* isolate = args.GetIsolate();
252 v8::HandleScope handleScope( isolate );
255 float value = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 1.f /* default */);
258 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
262 return Animation::New( value );
266 * Set the animation duration.
267 * @method setDuration
269 * @param {float} duration in seconds
272 void AnimationApi::SetDuration( const v8::FunctionCallbackInfo< v8::Value >& args )
274 v8::Isolate* isolate = args.GetIsolate();
275 v8::HandleScope handleScope( isolate );
277 Animation anim = GetAnimation( isolate, args );
280 float value = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 1.f /* default */);
283 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
286 anim.SetDuration( value );
289 * Get the animation duration.
290 * @method getDuration
292 * @return {float} duration in seconds
295 void AnimationApi::GetDuration( const v8::FunctionCallbackInfo< v8::Value >& args )
297 v8::Isolate* isolate = args.GetIsolate();
298 v8::HandleScope handleScope( isolate );
300 Animation anim = GetAnimation( isolate, args );
302 args.GetReturnValue().Set( v8::Number::New( isolate, anim.GetDuration() ) );
306 * Set whether the animation will loop.
309 * @param {bool} looping enabled
312 void AnimationApi::SetLooping( const v8::FunctionCallbackInfo< v8::Value >& args )
314 v8::Isolate* isolate = args.GetIsolate();
315 v8::HandleScope handleScope( isolate );
317 Animation anim = GetAnimation( isolate, args );
320 bool value = V8Utils::GetBooleanParameter( PARAMETER_0, found, isolate, args );
323 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
327 anim.SetLooping( value );
332 * Query whether the animation will loop.
335 * @return {bool} looping enabled
338 void AnimationApi::IsLooping( const v8::FunctionCallbackInfo< v8::Value >& args )
340 v8::Isolate* isolate = args.GetIsolate();
341 v8::HandleScope handleScope( isolate );
343 Animation anim = GetAnimation( isolate, args );
345 args.GetReturnValue().Set( v8::Boolean::New( isolate, anim.IsLooping() ) );
349 * Set the end action of the animation.
351 * This action is performed when the animation ends.
352 * Default end action is bake
353 * @method setEndAction
355 * @param {integer} bake mode
357 * anim.setEndAction( dali.ANIMATION_BAKE ); // When the animation ends, the animated property values are saved.
358 * anim.setEndAction( dali.ANIMATION_DISCARD ); // When the animation ends, the animated property values are forgotten.
359 * 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.
361 void AnimationApi::SetEndAction( const v8::FunctionCallbackInfo< v8::Value >& args )
363 v8::Isolate* isolate = args.GetIsolate();
364 v8::HandleScope handleScope( isolate );
366 Animation anim = GetAnimation( isolate, args );
369 int value = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
372 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
376 anim.SetEndAction( static_cast<Animation::EndAction>( value ) );
381 * Returns the end action of the animation.
383 * @method getEndAction
385 * @return {integer} bake mode
387 * There are 3 different bake modes
389 * dali.ANIMATION_BAKE // When the animation ends, the animated property values are saved.
390 * dali.ANIMATION_DISCARD // When the animation ends, the animated property values are forgotten.
391 * 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.
393 void AnimationApi::GetEndAction( const v8::FunctionCallbackInfo< v8::Value >& args )
395 v8::Isolate* isolate = args.GetIsolate();
396 v8::HandleScope handleScope( isolate );
398 Animation anim = GetAnimation( isolate, args );
400 args.GetReturnValue().Set( v8::Integer::New( isolate, anim.GetEndAction() ) );
404 * Set the disconnect action of the animation.
405 * If any of the animated property owners are disconnected from the stage, this action is performed.
406 * Default disconnection action is BakeFinal.
407 * @method setDisconnectAction
409 * @param {integer} end mode
411 * There are 3 different end modes
413 * dali.ANIMATION_BAKE // When the animation is destroyed, the animated property values are saved.
414 * dali.ANIMATION_DISCARD // When the animation is destroyed, the animated property values are forgotten.
415 * 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.
417 void AnimationApi::SetDisconnectAction( const v8::FunctionCallbackInfo< v8::Value >& args )
419 v8::Isolate* isolate = args.GetIsolate();
420 v8::HandleScope handleScope( isolate );
422 Animation anim = GetAnimation( isolate, args );
425 int value = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
428 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
432 anim.SetDisconnectAction( static_cast<Animation::EndAction>( value ) );
437 * Returns the disconnect action of the animation.
438 * @method getDisconnectAction
440 * @return {integer} end mode
442 void AnimationApi::GetDisconnectAction( const v8::FunctionCallbackInfo< v8::Value >& args )
444 v8::Isolate* isolate = args.GetIsolate();
445 v8::HandleScope handleScope( isolate );
447 Animation anim = GetAnimation( isolate, args );
449 args.GetReturnValue().Set( v8::Integer::New( isolate, anim.GetDisconnectAction() ) );
452 * Set the default alpha function for an animation.
453 * @method setDefaultAlphaFunction
455 * @param {Integer} alpha function
457 void AnimationApi::SetDefaultAlphaFunction( const v8::FunctionCallbackInfo< v8::Value >& args )
459 v8::Isolate* isolate = args.GetIsolate();
460 v8::HandleScope handleScope( isolate );
462 Animation anim = GetAnimation( isolate, args );
465 int alphaFunc = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
468 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
472 AlphaFunction func = static_cast<AlphaFunction::BuiltinFunction>(alphaFunc);
473 anim.SetDefaultAlphaFunction( func );
477 * Get the default alpha function for an animation.
478 * @method getDefaultAlphaFunction
480 * @return {Integer} alpha function
482 void AnimationApi::GetDefaultAlphaFunction( const v8::FunctionCallbackInfo<v8::Value>& args )
484 v8::Isolate* isolate = args.GetIsolate();
485 v8::HandleScope handleScope( isolate );
487 Animation anim = GetAnimation( isolate, args );
489 AlphaFunction alphaFunc = anim.GetDefaultAlphaFunction();
492 args.GetReturnValue().Set( v8::Integer::New( isolate, alphaFunc.GetBuiltinFunction() ) );
496 * Get the current progress of the animation.
497 * @method getCurrentProgress
499 * @return {float} The current progress as a normalized value between [0..1].
502 void AnimationApi::GetCurrentProgress( const v8::FunctionCallbackInfo< v8::Value >& args )
504 v8::Isolate* isolate = args.GetIsolate();
505 v8::HandleScope handleScope( isolate );
507 Animation anim = GetAnimation( isolate, args );
509 args.GetReturnValue().Set( v8::Number::New( isolate, anim.GetCurrentProgress() ) );
513 * Specifies an speed factor for the animation.
515 * The speed factor is a multiplier of the normal velocity of the animation. Values between [0,1] will
516 * slow down the animation and values above one will speed up the animation. It is also possible to specify a negative multiplier
517 * to play the animation in reverse.
519 * @method setSpeedFactor
521 * @param {float} value which will multiply the velocity.
523 * anim.setSpeedFactor(2);
524 * anim.play(); // plays the animation twice as fast
527 * anim.setSpeedFactor(0.5);
528 * anim.play(); // plays the animation half speed
531 void AnimationApi::SetSpeedFactor( const v8::FunctionCallbackInfo< v8::Value >& args )
533 v8::Isolate* isolate = args.GetIsolate();
534 v8::HandleScope handleScope( isolate );
536 Animation anim = GetAnimation( isolate, args );
539 float speedFactor = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 0.f );
542 DALI_SCRIPT_EXCEPTION( isolate, "float parameter missing" );
546 anim.SetSpeedFactor( speedFactor );
552 * Retrieve the speed factor of the animation
555 * @method getSpeedFactor
557 * @return {float} speed factor
559 void AnimationApi::GetSpeedFactor( const v8::FunctionCallbackInfo< v8::Value >& args )
561 v8::Isolate* isolate = args.GetIsolate();
562 v8::HandleScope handleScope( isolate );
564 Animation anim = GetAnimation( isolate, args );
566 args.GetReturnValue().Set( v8::Number::New( isolate, anim.GetSpeedFactor() ) );
570 * Set the playing range.
571 * Animation will play between the values specified.
572 * Both values ( range.x and range.y ) should be between 0-1,
573 * otherwise they will be ignored.
574 * If the range provided is not in proper order ( minimum,maximum), it will be reordered.
575 * @method setPlayRange
577 * @param {Object} Range
578 * @param {Float} Range.start
579 * @param {Float} Range.end
581 * var range = { start:0.1, end:0.6 };
582 * anim.setPlayRange( range );
584 void AnimationApi::SetPlayRange( const v8::FunctionCallbackInfo< v8::Value >& args )
586 v8::Isolate* isolate = args.GetIsolate();
587 v8::HandleScope handleScope( isolate );
589 Animation anim = GetAnimation( isolate, args );
592 if( args.Length() != 1 )
594 DALI_SCRIPT_EXCEPTION( isolate, "missing / invalid parameters" );
597 v8::Local<v8::Value > rangeValue = args[0];
598 if( !rangeValue->IsObject() )
600 DALI_SCRIPT_EXCEPTION( isolate, "invalid parameters" );
603 v8::Local<v8::Object> obj = rangeValue->ToObject();
604 v8::Local<v8::Value> startValue = obj->Get( v8::String::NewFromUtf8( isolate, "start" ) );
605 v8::Local<v8::Value> endValue = obj->Get( v8::String::NewFromUtf8( isolate, "end" ) );
607 if( startValue->IsNumber() && endValue->IsNumber())
609 range.x= startValue->ToNumber()->Value();
610 range.y = endValue->ToNumber()->Value();
614 DALI_SCRIPT_EXCEPTION( isolate, "missing start/end value" );
618 anim.SetPlayRange( range );
623 * Get the playing range.
624 * @method getPlayRange
626 * @return {Object} Range with { start: , end: } properties.
628 void AnimationApi::GetPlayRange( const v8::FunctionCallbackInfo< v8::Value >& args )
630 v8::Isolate* isolate = args.GetIsolate();
631 v8::EscapableHandleScope handleScope( isolate );
632 Animation anim = GetAnimation( isolate, args );
635 v8::Local<v8::Object> rangeObject = v8::Object::New( isolate );
637 Vector2 range = anim.GetPlayRange();
640 rangeObject->Set( v8::String::NewFromUtf8( isolate, "start"), v8::Number::New( isolate,range.x ));
643 rangeObject->Set( v8::String::NewFromUtf8( isolate, "end"), v8::Number::New( isolate,range.y ));
645 args.GetReturnValue().Set( rangeObject );
650 * Sets the progress of the animation.
651 * The animation will play (or continue playing) from this point. The progress
652 * must be in the 0-1 interval or in the play range interval if defined ( See SetPlayRange ),
653 * otherwise, it will be ignored.
655 * @method setCurrentProgress
657 * @param {float} progress The new progress as a normalized value between [0,1] or between the
658 * play range if specified.
660 void AnimationApi::SetCurrentProgress( const v8::FunctionCallbackInfo< v8::Value >& args )
662 v8::Isolate* isolate = args.GetIsolate();
663 v8::HandleScope handleScope( isolate );
665 Animation anim = GetAnimation( isolate, args );
669 float progress = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 0.f );
672 DALI_SCRIPT_EXCEPTION( isolate, "float parameter missing" );
675 anim.SetCurrentProgress( progress );
681 * Play the animation from a given point.
682 * The progress must be in the 0-1 interval or in the play range interval if defined ( See SetPlayRange ),
683 * otherwise, it will be ignored.
686 * @param {float} progress A value between [0,1], or between the play range if specified, form where the animation should start playing
688 void AnimationApi::PlayFrom( const v8::FunctionCallbackInfo< v8::Value >& args )
690 v8::Isolate* isolate = args.GetIsolate();
691 v8::HandleScope handleScope( isolate );
693 Animation anim = GetAnimation( isolate, args );
697 float progress = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 0.f );
700 DALI_SCRIPT_EXCEPTION( isolate, "float parameter missing" );
703 anim.PlayFrom( progress );
712 void AnimationApi::Play( const v8::FunctionCallbackInfo<v8::Value>& args )
714 v8::Isolate* isolate = args.GetIsolate();
715 v8::HandleScope handleScope( isolate );
717 Animation anim = GetAnimation( isolate, args );
721 * Pause the animation
725 void AnimationApi::Pause( const v8::FunctionCallbackInfo<v8::Value>& args )
727 v8::Isolate* isolate = args.GetIsolate();
728 v8::HandleScope handleScope( isolate );
730 Animation anim = GetAnimation( isolate, args );
738 void AnimationApi::Stop( const v8::FunctionCallbackInfo<v8::Value>& args )
740 v8::Isolate* isolate = args.GetIsolate();
741 v8::HandleScope handleScope( isolate );
743 Animation anim = GetAnimation( isolate, args );
747 * Clear the animation
748 * This disconnects any objects that were being animated, effectively stopping the animation.
752 void AnimationApi::Clear( const v8::FunctionCallbackInfo<v8::Value>& args )
754 v8::Isolate* isolate = args.GetIsolate();
755 v8::HandleScope handleScope( isolate );
757 Animation anim = GetAnimation( isolate, args );
762 void AnimationApi::Animate( const v8::FunctionCallbackInfo<v8::Value>& args )
764 v8::Isolate* isolate = args.GetIsolate();
765 v8::HandleScope handleScope( isolate );
767 Animation anim = GetAnimation( isolate, args );
768 AnimationParameters animParams( anim );
772 Dali::Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
775 DALI_SCRIPT_EXCEPTION( isolate, "Missing actor parameter");
781 BaseWrappedObject* wrapper = V8Utils::GetWrappedDaliObjectParameter( PARAMETER_1, BaseWrappedObject::PATH, isolate, args);
782 PathWrapper* pathWrapper = static_cast< PathWrapper*>( wrapper );
787 path = pathWrapper->GetPath();
791 Vector3 forward = V8Utils::GetVector3Parameter( PARAMETER_2, bFound, isolate, args );
797 //Get animation options
798 GetAnimationOptions( isolate, args[3], animParams );
799 if( animParams.optionsFound )
801 anim.Animate( actor, path, forward, animParams.alphaFunction, TimePeriod( animParams.delay, animParams.duration) );
805 anim.Animate( actor, path, forward );
811 * Animate a property value by a relative amount.
813 * The effect will start & end when the animation begins & ends.
816 * @param {Object} target object that contains a property to be animated (e.g. myActor )
817 * @param {String} property name (e.g. "position" )
818 * @param {Object} relativeValue The property value will change by this amount.
819 * @param {Object} [options] Animation options.
820 * @param {Float} [options.delay] amount to delay the start of the animation in seconds
821 * @param {Float} [options.duration] duration of the animation
822 * @param {String} [options.alpha] Animation alpha function (e.g. "linear")
826 * // animation x position
827 * var anim = new dali.Animation( 1 );
828 * anim.animateBy( imageActor,"positionX", 30 );
831 * // animate x,y,z position with the optional animation options
833 * delay: 3, // 3 second delay before starting
834 * duration: 5, // 5 second duration
835 * alpha:"easeInOutSine" // Speeds up and slows to a gradual stop
838 * anim.animateBy( imageActor,"position", [100,200,0], options );
841 void AnimationApi::AnimateBy( const v8::FunctionCallbackInfo<v8::Value>& args )
843 v8::Isolate* isolate = args.GetIsolate();
844 v8::HandleScope handleScope( isolate );
846 Animation anim = GetAnimation( isolate, args );
847 AnimationParameters animParams( anim );
849 // grab all the parameters
850 bool ok = GetAnimationParameters( isolate, args, animParams, AnimationApi::PROPERTY_VALUE);
853 // GetAnimationParameters will log
857 if( animParams.optionsFound )
859 anim.AnimateBy( Property( animParams.target, animParams.propertyIndex ),
861 animParams.alphaFunction,
862 TimePeriod( animParams.delay, animParams.duration) );
866 anim.AnimateBy( Property( animParams.target, animParams.propertyIndex ), animParams.value );
873 * Animate a property to a destination value.
875 * The effect will start & end when the animation begins & ends.
878 * @param {Object} target object that contains a property to be animated (e.g. myActor )
879 * @param {String} property name (e.g. "position" )
880 * @param {Object} destinationValue The property value will changed to this value
881 * @param {Object} [options] Animation options.
882 * @param {Float} [options.delay] amount to delay the start of the animation in seconds
883 * @param {Float} [options.duration] duration of the animation
884 * @param {String} [options.alpha] Animation alpha function (e.g. "linear")
888 * var anim = new dali.Animation( 1 );
889 * anim.animateTo( imageActor,"positionX", 30 );
893 * // with the optional animation options object
895 * delay: 3, // 3 second delay before starting
896 * duration: 5, // 5 second duration
897 * alpha:"easeInOutSine" // Speeds up and slows to a gradual stop
900 * anim.animateTo( imageActor,"position", [100,200,0], options );
903 void AnimationApi::AnimateTo( const v8::FunctionCallbackInfo< v8::Value >& args )
905 v8::Isolate* isolate = args.GetIsolate();
906 v8::HandleScope handleScope( isolate );
908 Animation anim = GetAnimation( isolate, args );
909 AnimationParameters animParams( anim );
911 // grab all the parameters
912 bool ok = GetAnimationParameters( isolate, args, animParams, AnimationApi::PROPERTY_VALUE );
915 // GetAnimationParameters will log
919 if( animParams.optionsFound )
922 anim.AnimateTo( Property( animParams.target,animParams.propertyIndex ),
924 animParams.alphaFunction,
925 TimePeriod( animParams.delay, animParams.duration) );
929 anim.AnimateTo( Property( animParams.target, animParams.propertyIndex ), animParams.value );
935 * Animate a property between keyframes.
937 * The effect will start & end when the animation begins & ends.
938 * @method animateBetween
940 * @param {Object} target object that contains a property to be animated (e.g. myActor )
941 * @param {String} property name (e.g. "position" )
942 * @param {Object} keyframes array of keyframe objects
943 * @param {Object} [options] Animation options.
944 * @param {Float} [options.delay] amount to delay the start of the animation in seconds
945 * @param {Float} [options.duration] duration of the animation
946 * @param {String} [options.alpha] Animation alpha function (e.g. "linear")
951 * create some keyframes to move an actor around a square, and return to the start
953 * <img src="../assets/img/animation/keyframe-animation.png">
980 * anim.animateBetween( imageActor,"position", keyframes );
983 void AnimationApi::AnimateBetween( 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::KEYFRAMES );
995 // GetAnimationParameters will log
999 // if animation options exist...
1000 if( animParams.optionsFound )
1003 anim.AnimateBetween( Property( animParams.target,animParams.propertyIndex ),
1004 animParams.keyFrames,
1005 animParams.alphaFunction,
1006 TimePeriod( animParams.delay, animParams.duration) );
1010 anim.AnimateBetween( Property( animParams.target, animParams.propertyIndex ), animParams.keyFrames );
1015 * show an actor during the animation.
1017 * This is a helper, which simulates animating the visibility property of an actor
1018 * with zero duration ( it is just a boolean).
1019 * e.g. it performs anim.AnimateTo( actor,"visible",true, { delay:delay: duration:0 } );
1022 * @param {Object} Actor
1023 * @param {float} delay until the actor is shown
1025 void AnimationApi::Show( const v8::FunctionCallbackInfo< v8::Value >& args )
1027 v8::Isolate* isolate = args.GetIsolate();
1028 v8::HandleScope handleScope( isolate );
1029 Animation anim = GetAnimation( isolate, args );
1030 bool found( false );
1032 Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
1035 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 0 actor" );
1039 float delay = V8Utils::GetFloatParameter( PARAMETER_1, found, isolate, args, 1.f /* default */);
1042 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 1 delay" );
1045 anim.Show( actor, delay );
1050 * hide an actor during the animation.
1052 * This is a helper, which simulates animating the visibility property of an actor
1053 * with zero duration ( it is just a boolean).
1054 * e.g. it performs anim.AnimateTo( actor,"visible",false, { delay:delay: duration:0 } );
1057 * @param {Object} Actor
1058 * @param {float} delay until the actor is hidden
1060 void AnimationApi::Hide( const v8::FunctionCallbackInfo< v8::Value >& args )
1062 v8::Isolate* isolate = args.GetIsolate();
1063 v8::HandleScope handleScope( isolate );
1064 Animation anim = GetAnimation( isolate, args );
1065 bool found( false );
1066 Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
1069 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 0 actor" );
1074 float delay = V8Utils::GetFloatParameter( PARAMETER_1, found, isolate, args, 1.f /* default */);
1077 DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 1 delay" );
1080 anim.Hide( actor, delay );
1086 } // namespace V8Plugin