Remove ImageActor usage from V8 plugin
[platform/core/uifw/dali-toolkit.git] / plugins / dali-script-v8 / src / animation / animation-api.cpp
index 653f1d3..3a63034 100644 (file)
@@ -20,7 +20,6 @@
 #include "path-wrapper.h"
 
 // EXTERNAL INCLUDES
-#include <cstring> // for strcmp
 #include <dali/integration-api/debug.h>
 
 
@@ -38,85 +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"               , AlphaFunction::DEFAULT              },
- {"linear"                , AlphaFunction::LINEAR               },
- {"reverse"               , AlphaFunction::REVERSE              },
-
- {"easeInSquare"          , AlphaFunction::EASE_IN_SQUARE       },
- {"easeOutSquare"         , AlphaFunction::EASE_OUT_SQUARE      },
-
- {"easeIn"                , AlphaFunction::EASE_IN               },
- {"easeOut"               , AlphaFunction::EASE_OUT              },
- {"easeInOut"             , AlphaFunction::EASE_IN_OUT           },
-
- {"easeInSine"            , AlphaFunction::EASE_IN_SINE          },
- {"easeOutSine"           , AlphaFunction::EASE_OUT_SINE         },
- {"easeInOutSine"         , AlphaFunction::EASE_IN_OUT_SINE      },
-
- {"bounce"                , AlphaFunction::BOUNCE                },
- {"sin"                   , AlphaFunction::SIN                   },
- {"easeOutBack"           , AlphaFunction::EASE_OUT_BACK         },
-
-};
-const unsigned int AlphaFunctionTableCount = sizeof(AlphaFunctionTable)/sizeof(AlphaFunctionTable[0]);
-const char* const DEFAULT_ALPHA_NAME = "default";
-static AlphaFunction DEFAULT_ALPHA_FUNCTION = AlphaFunction::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 DEFAULT_ALPHA_FUNCTION;
-}
-
-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.GetBuiltinFunction()  == alphaFunc.GetBuiltinFunction() )
-    {
-      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 )
@@ -150,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" ) );
@@ -225,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
@@ -245,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)
 
@@ -273,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;
@@ -531,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 )
 {
@@ -541,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 )
 {
@@ -566,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() ) );
 }
 
 /**
@@ -905,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
@@ -915,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 )
@@ -966,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();
  *
  *
@@ -977,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 )
@@ -1057,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 )