Remove ImageActor usage from V8 plugin
[platform/core/uifw/dali-toolkit.git] / plugins / dali-script-v8 / src / animation / animation-api.cpp
index 1a11440..3a63034 100644 (file)
@@ -20,7 +20,6 @@
 #include "path-wrapper.h"
 
 // EXTERNAL INCLUDES
-#include <cstring> // for strcmp
 #include <dali/integration-api/debug.h>
 
 
@@ -38,93 +37,11 @@ namespace V8Plugin
 namespace // un named namespace
 {
 
-// @todo think about alternative ways of passing around
-struct AlphaFuncStruct
-{
-  const char* const name;
-  AlphaFunction alphaFunc;
-};
-/**
- * Contains a list of alpha functions that can be used.
- */
-const AlphaFuncStruct AlphaFunctionTable[]=
-{
- {"default"               , AlphaFunctions::Default              },
- {"linear"                , AlphaFunctions::Linear               },
- {"square"                , AlphaFunctions::Square               },
- {"reverse"               , AlphaFunctions::Reverse              },
- {"easeIn"                , AlphaFunctions::EaseIn               },
- {"easeOut"               , AlphaFunctions::EaseOut              },
- {"easeInOut"             , AlphaFunctions::EaseInOut            },
- {"easeInSine"            , AlphaFunctions::EaseInSine           },
- {"easeOutSine"           , AlphaFunctions::EaseOutSine          },
- {"easeInOutSine"         , AlphaFunctions::EaseInOutSine        },
- {"easeInSine33"          , AlphaFunctions::EaseInSine33         },
- {"easeOutSine33"         , AlphaFunctions::EaseOutSine33        },
- {"easeInOutSine33"       , AlphaFunctions::EaseInOutSine33      },
- {"easeInOutSine50"       , AlphaFunctions::EaseInOutSine50      },
- {"easeInOutSine60"       , AlphaFunctions::EaseInOutSine60      },
- {"easeInOutSine70"       , AlphaFunctions::EaseInOutSine70      },
- {"easeInOutSine80"       , AlphaFunctions::EaseInOutSine80      },
- {"easeInOutSine90"       , AlphaFunctions::EaseInOutSine90      },
- {"doubleEaseInOutSine60" , AlphaFunctions::DoubleEaseInOutSine60},
- {"easeOutQuint50"        , AlphaFunctions::EaseOutQuint50       },
- {"easeOutQuint80"        , AlphaFunctions::EaseOutQuint80       },
- {"bounce"                , AlphaFunctions::Bounce               },
- {"bounceBack"            , AlphaFunctions::BounceBack           },
- {"easeInBack"            , AlphaFunctions::EaseInBack           },
- {"easeOutBack"           , AlphaFunctions::EaseOutBack          },
- {"easeInOutBack"         , AlphaFunctions::EaseInOutBack        },
- {"sin"                   , AlphaFunctions::Sin                  },
- {"sin2x"                 , AlphaFunctions::Sin2x                }
-};
-const unsigned int AlphaFunctionTableCount = sizeof(AlphaFunctionTable)/sizeof(AlphaFunctionTable[0]);
-const char* const DEFAULT_ALPHA_NAME = "default";
-static AlphaFunction DEFAULT_ALPHA_FUNCTION = AlphaFunctions::Default;
-
-
-
-AlphaFunction GetAlphaFunction( const std::string& alphaFuncName )
-{
-  // This will normally get called just a few times during the application, so no point in doing anything clever
-  for( unsigned int i = 0; i < AlphaFunctionTableCount; i++)
-  {
-    const AlphaFuncStruct& alphaStruct( AlphaFunctionTable[i] );
-
-    if( std::strcmp( alphaStruct.name , alphaFuncName.c_str() ) == 0 )
-    {
-      return alphaStruct.alphaFunc;
-    }
-  }
-
-  DALI_LOG_ERROR("Failed to find alpha func |%s| \n", alphaFuncName.c_str() );
-  return AlphaFunctions::Default;
-}
-
-const char* const GetAlphaFunctionName(  AlphaFunction alphaFunc )
-{
-  // This may get called 3 times during the application, so no point
-  // in doing anything clever
-
-  for( unsigned int i = 0; i < AlphaFunctionTableCount; i++)
-  {
-    const AlphaFuncStruct& alphaStruct( AlphaFunctionTable[i] );
-
-
-    if( alphaStruct.alphaFunc  == alphaFunc )
-    {
-      return alphaStruct.name;
-    }
-  }
-  return "default";
-}
-
-
 struct AnimationParameters
 {
   AnimationParameters( const Animation& anim)
   : propertyIndex( Property::INVALID_INDEX  ),
-    alphaFunction( DEFAULT_ALPHA_FUNCTION),
+    alphaFunction( AlphaFunction::DEFAULT),
     delay( 0.f ),
     duration(anim.GetDuration()),
     optionsFound( false )
@@ -158,11 +75,10 @@ void GetAnimationOptions( v8::Isolate* isolate,
   {
     v8::Local<v8::Object> obj = options->ToObject();
     v8::Local<v8::Value> alphaValue = obj->Get( v8::String::NewFromUtf8( isolate, "alpha" ) );
-    if( alphaValue->IsString() )
+    if( alphaValue->IsUint32() )
     {
       animParams.optionsFound = true;
-      std::string alphaName = V8Utils::v8StringToStdString( alphaValue );
-      animParams.alphaFunction = GetAlphaFunction( alphaName );
+      animParams.alphaFunction = static_cast<AlphaFunction::BuiltinFunction>(alphaValue->ToUint32()->Value());
     }
 
     v8::Local<v8::Value> delayValue = obj->Get( v8::String::NewFromUtf8( isolate, "delay" ) );
@@ -233,10 +149,9 @@ KeyFrames GetKeyFrames( v8::Isolate* isolate, v8::Local<v8::Value > keyFrameArra
 
     // get keyframe.alpha
     v8::Handle<v8::Value> alphaValue = keyFrameObject->Get(v8::String::NewFromUtf8( isolate, "alpha"));
-    if( alphaValue->IsString() )
+    if( alphaValue->IsUint32() )
     {
-      std::string alphaName = V8Utils::v8StringToStdString( alphaValue );
-      AlphaFunction alphaFunction = GetAlphaFunction( alphaName );
+      AlphaFunction alphaFunction = static_cast<AlphaFunction::BuiltinFunction>(alphaValue->ToUint32()->Value());
       keyframes.Add( progress->NumberValue(), value, alphaFunction );
     }
     else
@@ -253,9 +168,9 @@ bool GetAnimationParameters(  v8::Isolate* isolate,
                               AnimationParameters& animParams,
                               AnimationApi::AnimationParameterType type)
 {
-  // used for things like anim.AnimateBy(  myImageActor, property-name,  property-value (or Javascript number array));
+  // used for things like anim.AnimateBy(  myImageView, property-name,  property-value (or Javascript number array));
   // 1 extract property handle from param1.
-  // 2 extract property name from param2  ( can be in the format "u-color" or "uColor"
+  // 2 extract property name from param2  ( in the format "uColor" )
   // 3 extract PropertyValue from param3
   // 4 extract animation options ( delay, duration, alpha func)
 
@@ -281,9 +196,7 @@ bool GetAnimationParameters(  v8::Isolate* isolate,
 
   if( index == Property::INVALID_INDEX )
   {
-    // convert the property name from "uColor" to "u-color"
-    std::string convetedName = V8Utils::JavaScriptNameToPropertyName( propertyName );
-    index = animParams.target.GetPropertyIndex( convetedName );
+    index = animParams.target.GetPropertyIndex( propertyName );
   }
 
   animParams.propertyIndex = index;
@@ -539,7 +452,7 @@ void AnimationApi::GetDisconnectAction( const v8::FunctionCallbackInfo< v8::Valu
  * Set the default alpha function for an animation.
  * @method setDefaultAlphaFunction
  * @for Animation
- * @param {string} alpha function
+ * @param {Integer} alpha function
  */
 void AnimationApi::SetDefaultAlphaFunction( const v8::FunctionCallbackInfo< v8::Value >& args )
 {
@@ -549,23 +462,22 @@ void AnimationApi::SetDefaultAlphaFunction( const v8::FunctionCallbackInfo< v8::
   Animation anim = GetAnimation( isolate, args );
 
   bool found( false );
-  std::string alphaFunc = V8Utils::GetStringParameter( PARAMETER_0, found, isolate, args );
+  int alphaFunc = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
   if( !found )
   {
     DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" );
   }
   else
   {
-    AlphaFunction func = GetAlphaFunction( alphaFunc );
+    AlphaFunction func = static_cast<AlphaFunction::BuiltinFunction>(alphaFunc);
     anim.SetDefaultAlphaFunction( func );
   }
-
 }
 /**
  * Get the default alpha function for an animation.
  * @method getDefaultAlphaFunction
  * @for Animation
- * @return {string} alpha function
+ * @return {Integer} alpha function
  */
 void AnimationApi::GetDefaultAlphaFunction( const v8::FunctionCallbackInfo<v8::Value>& args )
 {
@@ -574,10 +486,10 @@ void AnimationApi::GetDefaultAlphaFunction( const v8::FunctionCallbackInfo<v8::V
 
   Animation anim = GetAnimation( isolate, args );
 
-  std::string alphaName = GetAlphaFunctionName(  anim.GetDefaultAlphaFunction() );
+  AlphaFunction alphaFunc = anim.GetDefaultAlphaFunction();
 
 
-  args.GetReturnValue().Set( v8::String::NewFromUtf8( isolate, alphaName.c_str() ) );
+  args.GetReturnValue().Set( v8::Integer::New( isolate, alphaFunc.GetBuiltinFunction() ) );
 }
 
 /**
@@ -913,7 +825,7 @@ void AnimationApi::Animate( const v8::FunctionCallbackInfo<v8::Value>& args )
  *
  *     // animation x position
  *     var anim = new dali.Animation( 1 );
- *     anim.animateBy( imageActor,"positionX", 30 );
+ *     anim.animateBy( actor,"positionX", 30 );
  *     anim.play();
  *
  *     // animate x,y,z position with the optional animation options
@@ -923,7 +835,7 @@ void AnimationApi::Animate( const v8::FunctionCallbackInfo<v8::Value>& args )
  *        alpha:"easeInOutSine"   // Speeds up and slows to a gradual stop
  *     }
  *
- *     anim.animateBy( imageActor,"position", [100,200,0], options );
+ *     anim.animateBy( actor,"position", [100,200,0], options );
  *
  */
 void AnimationApi::AnimateBy( const v8::FunctionCallbackInfo<v8::Value>& args )
@@ -974,7 +886,7 @@ void AnimationApi::AnimateBy( const v8::FunctionCallbackInfo<v8::Value>& args )
  * @example
  *
  *     var anim = new dali.Animation( 1 );
- *     anim.animateTo( imageActor,"positionX", 30 );
+ *     anim.animateTo( actor,"positionX", 30 );
  *     anim.play();
  *
  *
@@ -985,7 +897,7 @@ void AnimationApi::AnimateBy( const v8::FunctionCallbackInfo<v8::Value>& args )
  *        alpha:"easeInOutSine"   // Speeds up and slows to a gradual stop
  *     }
  *
- *     anim.animateTo( imageActor,"position", [100,200,0], options );
+ *     anim.animateTo( actor,"position", [100,200,0], options );
  *
  */
 void AnimationApi::AnimateTo( const v8::FunctionCallbackInfo< v8::Value >& args )
@@ -1038,7 +950,7 @@ void AnimationApi::AnimateTo( const v8::FunctionCallbackInfo< v8::Value >& args
  *
  *  create some keyframes to move an actor around a square, and return to the start
  * </br >
- *  <img src="../assets/img/keyframe-animation.png">
+ *  <img src="../assets/img/animation/keyframe-animation.png">
  *
  *
  *     var keyframes = [
@@ -1065,7 +977,7 @@ void AnimationApi::AnimateTo( const v8::FunctionCallbackInfo< v8::Value >& args
  *     } ];
  *
  *
- *     anim.animateBetween( imageActor,"position", keyframes );
+ *     anim.animateBetween( actor,"position", keyframes );
  *
  */
 void AnimationApi::AnimateBetween( const v8::FunctionCallbackInfo< v8::Value >& args )