PathConstrainer changes in JS Plugin + LinearConstrainer 64/38064/13
authorFerran Sole <ferran.sole@samsung.com>
Fri, 10 Apr 2015 10:11:00 +0000 (11:11 +0100)
committerFerran Sole <ferran.sole@samsung.com>
Tue, 12 May 2015 15:56:44 +0000 (08:56 -0700)
Sample code showing how to use PathConstrainer in Javascript:

var pathConstrainer = new dali.PathConstrainer();
pathConstrainer.points = [ point0, point1, point2 ];
pathConstrainer.controlPoints = [ controlPoint0, controlPoint1, controlPoint2, controlPoint3 ];
pathConstrainer.forward = [1.0,0.0,0.0];

var constraintPosition = {
                          "target":actor,
                          "targetProperty":"position",
                          "source":actor,
                          "sourceProperty":"color-alpha",
                          "range":[0.0,1.0]
                         };

pathConstrainer.applyConstraint( constraintPosition );

Change-Id: If5c5aee0d402b5c689b983a9848648d6700dec6b

12 files changed:
plugins/dali-script-v8/file.list
plugins/dali-script-v8/src/actors/actor-api.cpp
plugins/dali-script-v8/src/actors/actor-api.h
plugins/dali-script-v8/src/actors/actor-wrapper.cpp
plugins/dali-script-v8/src/animation/constrainer-api.cpp [new file with mode: 0644]
plugins/dali-script-v8/src/animation/constrainer-api.h [new file with mode: 0644]
plugins/dali-script-v8/src/animation/linear-constrainer-wrapper.cpp [new file with mode: 0644]
plugins/dali-script-v8/src/animation/linear-constrainer-wrapper.h [new file with mode: 0644]
plugins/dali-script-v8/src/animation/path-constrainer-wrapper.cpp [moved from plugins/dali-script-v8/src/animation/path-constraint-wrapper.cpp with 54% similarity]
plugins/dali-script-v8/src/animation/path-constrainer-wrapper.h [moved from plugins/dali-script-v8/src/animation/path-constraint-wrapper.h with 51% similarity]
plugins/dali-script-v8/src/dali-wrapper.cpp
plugins/dali-script-v8/src/shared/base-wrapped-object.h

index 9dc4293..9914d3a 100644 (file)
@@ -19,8 +19,10 @@ script_v8_plugin_src_files = \
    $(v8_plugin_dir)/constants/constants-wrapper.cpp \
    $(v8_plugin_dir)/animation/animation-api.cpp \
    $(v8_plugin_dir)/animation/animation-wrapper.cpp \
    $(v8_plugin_dir)/constants/constants-wrapper.cpp \
    $(v8_plugin_dir)/animation/animation-api.cpp \
    $(v8_plugin_dir)/animation/animation-wrapper.cpp \
+   $(v8_plugin_dir)/animation/constrainer-api.cpp \
+   $(v8_plugin_dir)/animation/linear-constrainer-wrapper.cpp \
    $(v8_plugin_dir)/animation/path-api.cpp \
    $(v8_plugin_dir)/animation/path-api.cpp \
-   $(v8_plugin_dir)/animation/path-constraint-wrapper.cpp \
+   $(v8_plugin_dir)/animation/path-constrainer-wrapper.cpp \
    $(v8_plugin_dir)/animation/path-wrapper.cpp \
    $(v8_plugin_dir)/stage/stage-wrapper.cpp \
    $(v8_plugin_dir)/events/event-object-generator.cpp \
    $(v8_plugin_dir)/animation/path-wrapper.cpp \
    $(v8_plugin_dir)/stage/stage-wrapper.cpp \
    $(v8_plugin_dir)/events/event-object-generator.cpp \
index 926c5cd..b36f68a 100644 (file)
@@ -24,7 +24,7 @@
 // INTERNAL INCLUDES
 #include <v8-utils.h>
 #include <actors/actor-wrapper.h>
 // INTERNAL INCLUDES
 #include <v8-utils.h>
 #include <actors/actor-wrapper.h>
-#include <animation/path-constraint-wrapper.h>
+#include <animation/path-constrainer-wrapper.h>
 
 namespace Dali
 {
 
 namespace Dali
 {
@@ -610,111 +610,6 @@ void ActorApi::ScaleBy( const v8::FunctionCallbackInfo<v8::Value>& args )
   actor.ScaleBy( vector );
 }
 
   actor.ScaleBy( vector );
 }
 
-void ActorApi::ApplyPathConstraint( const v8::FunctionCallbackInfo< v8::Value >& args )
-{
-  v8::Isolate* isolate = args.GetIsolate();
-  v8::HandleScope handleScope( isolate );
-
-  //Get target actor
-  Actor targetActor = GetActor( isolate, args );
-
-  //Get PathConstraint
-  bool found(false);
-  Handle pathConstraintHandle =  V8Utils::GetHandleParameter(PARAMETER_0, found, isolate, args );
-  if( !found )
-  {
-    DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 0 (PathConstraint)" );
-    return;
-  }
-  PathConstraint pathConstraint = PathConstraint::DownCast(pathConstraintHandle);
-
-  //Get target property
-  std::string propertyName = V8Utils::GetStringParameter( PARAMETER_1, found, isolate, args );
-  if(!found)
-  {
-    DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 1 (Property name)" );
-    return;
-  }
-
-  // try both properties with dashes and without
-  Property::Index targetPropertyIndex = targetActor.GetPropertyIndex( propertyName );
-  if( targetPropertyIndex == Property::INVALID_INDEX )
-  {
-    std::string convertedName = V8Utils::JavaScriptNameToPropertyName( propertyName );
-    targetPropertyIndex = targetActor.GetPropertyIndex( convertedName );
-
-    if( targetPropertyIndex == Property::INVALID_INDEX )
-    {
-      DALI_SCRIPT_EXCEPTION( isolate, "Property not found" );
-    }
-  }
-
-  //Get source actor
-  Actor sourceActor = V8Utils::GetActorParameter( PARAMETER_2, found, isolate, args );
-  if( !found )
-  {
-    DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 2 (Actor)" );
-  }
-
-  // try both properties with dashes and without
-  propertyName = V8Utils::GetStringParameter( PARAMETER_3, found, isolate, args );
-  if(!found)
-  {
-    DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 3 (Property name)" );
-    return;
-  }
-
-  Property::Index sourcePropertyIndex = sourceActor.GetPropertyIndex( propertyName );
-  if( sourcePropertyIndex == Property::INVALID_INDEX )
-  {
-    std::string convertedName = V8Utils::JavaScriptNameToPropertyName( propertyName );
-    sourcePropertyIndex = sourceActor.GetPropertyIndex( convertedName );
-
-    if( sourcePropertyIndex == Property::INVALID_INDEX )
-    {
-      DALI_SCRIPT_EXCEPTION( isolate, "Property not found" );
-      return;
-    }
-  }
-
-  //Check if forward vector is specified
-  Vector3 forward( 0.0f,0.0f,0.0f);
-  if( args.Length() > 4 )
-  {
-    forward =  V8Utils::GetVector3Parameter( PARAMETER_4, found, isolate, args );
-    if( !found )
-    {
-      DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 4 (Vector3)" );
-      return;
-    }
-  }
-
-  pathConstraint.Apply( Dali::Property(sourceActor,sourcePropertyIndex),
-                        Dali::Property(targetActor,targetPropertyIndex),
-                        forward );
-
-}
-
-void ActorApi::RemovePathConstraint( const v8::FunctionCallbackInfo< v8::Value >& args )
-{
-  v8::Isolate* isolate = args.GetIsolate();
-  v8::HandleScope handleScope( isolate );
-
-  //Get target actor
-  Actor actor = GetActor( isolate, args );
-
-  //Get PathConstraint
-  bool found(false);
-  Handle pathConstraintHandle =  V8Utils::GetHandleParameter(PARAMETER_0, found, isolate, args );
-  if( !found )
-  {
-    DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 0 (PathConstraint)" );
-    return;
-  }
-  PathConstraint pathConstraint = PathConstraint::DownCast(pathConstraintHandle);
-  pathConstraint.Remove(actor);
-}
-
 } // namespace V8Plugin
 
 } // namespace Dali
 } // namespace V8Plugin
 
 } // namespace Dali
index 509c976..8543f11 100644 (file)
@@ -68,12 +68,6 @@ namespace ActorApi
   void RotateBy( const v8::FunctionCallbackInfo< v8::Value >& args );
   void ScaleBy( const v8::FunctionCallbackInfo< v8::Value >& args );
 
   void RotateBy( const v8::FunctionCallbackInfo< v8::Value >& args );
   void ScaleBy( const v8::FunctionCallbackInfo< v8::Value >& args );
 
-  // new function just for JavaScript API, to apply a PathConstraint to an actor
-  void ApplyPathConstraint( const v8::FunctionCallbackInfo< v8::Value >& args );
-
-  // new function just for JavaScript API, to remove a PathConstraint from an actor
-  void RemovePathConstraint( const v8::FunctionCallbackInfo< v8::Value >& args );
-
   // new function just for JavaScript API, to help developers know what type of actor
   // they're dealing with, returns actor name as a string
   void GetActorType( const v8::FunctionCallbackInfo< v8::Value >& args );
   // new function just for JavaScript API, to help developers know what type of actor
   // they're dealing with, returns actor name as a string
   void GetActorType( const v8::FunctionCallbackInfo< v8::Value >& args );
index 7e4dcc4..1686958 100644 (file)
@@ -197,8 +197,6 @@ const ActorFunctions ActorFunctionTable[]=
     { "FindChildById",     ActorApi::FindChildById,    ACTOR_API },
     { "GetParent" ,        ActorApi::GetParent,        ACTOR_API },
     { "GetActorType" ,     ActorApi::GetActorType,     ACTOR_API }, // custom for javascript
     { "FindChildById",     ActorApi::FindChildById,    ACTOR_API },
     { "GetParent" ,        ActorApi::GetParent,        ACTOR_API },
     { "GetActorType" ,     ActorApi::GetActorType,     ACTOR_API }, // custom for javascript
-    { "ApplyPathConstraint",  ActorApi::ApplyPathConstraint,  ACTOR_API }, // custom for javascript
-    { "RemovePathConstraint", ActorApi::RemovePathConstraint, ACTOR_API }, // custom for javascript
 
     // ignore. SetParentOrigin() use Actor.parentOrigin
     // ignore. GetCurrentParentOrigin()  use Actor.parentOrigin
 
     // ignore. SetParentOrigin() use Actor.parentOrigin
     // ignore. GetCurrentParentOrigin()  use Actor.parentOrigin
diff --git a/plugins/dali-script-v8/src/animation/constrainer-api.cpp b/plugins/dali-script-v8/src/animation/constrainer-api.cpp
new file mode 100644 (file)
index 0000000..701f4d4
--- /dev/null
@@ -0,0 +1,292 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "constrainer-api.h"
+
+//EXTERNAL INCLUDES
+#include <cfloat> //For FLT_MAX
+
+// INTERNAL INCLUDES
+#include <animation/linear-constrainer-wrapper.h>
+#include <animation/path-constrainer-wrapper.h>
+#include <object/property-value-wrapper.h>
+#include <v8-utils.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace // un named namespace
+{
+
+PathConstrainer GetPathConstrainer( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+  v8::HandleScope handleScope( isolate );
+
+  v8::Local<v8::Object> object = args.This();
+  v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField( 0 ) );
+  void* ptr = field->Value();
+
+  PathConstrainerWrapper* wrapper = static_cast<PathConstrainerWrapper *>( ptr );
+  return wrapper->GetPathConstrainer();
+}
+
+LinearConstrainer GetLinearConstrainer( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+  v8::HandleScope handleScope( isolate );
+
+  v8::Local<v8::Object> object = args.This();
+  v8::Local<v8::External> field = v8::Local<v8::External>::Cast( object->GetInternalField( 0 ) );
+  void* ptr = field->Value();
+
+  LinearConstrainerWrapper* wrapper = static_cast<LinearConstrainerWrapper *>( ptr );
+  return wrapper->GetLinearConstrainer();
+}
+
+bool GetApplyParameters( const v8::FunctionCallbackInfo< v8::Value >& args, Actor& targetActor, Property::Index& targetPropertyIndex,
+                         Actor& sourceActor, Property::Index& sourcePropertyIndex, Vector2& range, Vector2& wrap )
+{
+  v8::Isolate* isolate = args.GetIsolate();
+  v8::HandleScope handleScope( isolate );
+
+  if( args[0]->IsObject() )
+  {
+    bool found(false);
+
+    v8::Local<v8::Object> obj = args[0]->ToObject();
+    v8::Local<v8::Value> member = obj->Get( v8::String::NewFromUtf8( isolate, "target" ) );
+
+    //Get target actor
+    if( member->IsObject() )
+    {
+      v8::Local<v8::Object> targetActorObject = member->ToObject();
+      targetActor = V8Utils::GetActorFromObject( isolate, found, targetActorObject );
+      if( !targetActor )
+      {
+        DALI_SCRIPT_EXCEPTION( isolate, "Target actor not found" );
+        return false;
+      }
+    }
+    else
+    {
+      DALI_SCRIPT_EXCEPTION( isolate, "Target actor not specified" );
+      return false;
+    }
+
+    //Get source actor
+    member = obj->Get( v8::String::NewFromUtf8( isolate, "source" ) );
+    if( member->IsObject() )
+    {
+      v8::Local<v8::Object> sourceActorObject = member->ToObject();
+      sourceActor = V8Utils::GetActorFromObject( isolate, found, sourceActorObject );
+      if( !sourceActor )
+      {
+        DALI_SCRIPT_EXCEPTION( isolate, "Source actor not found" );
+        return false;
+      }
+    }
+    else
+    {
+      DALI_SCRIPT_EXCEPTION( isolate, "Source actor not specified" );
+      return false;
+    }
+
+    //Get target property
+    member = obj->Get( v8::String::NewFromUtf8( isolate, "targetProperty" ) );
+    if( member->IsString() )
+    {
+      std::string propertyName = V8Utils::v8StringToStdString( member );
+      targetPropertyIndex = targetActor.GetPropertyIndex( propertyName );
+      if( targetPropertyIndex == Property::INVALID_INDEX )
+      {
+        std::string convertedName = V8Utils::JavaScriptNameToPropertyName( propertyName );
+        targetPropertyIndex = targetActor.GetPropertyIndex( convertedName );
+
+        if( targetPropertyIndex == Property::INVALID_INDEX )
+        {
+          DALI_SCRIPT_EXCEPTION( isolate, "Target property not found" );
+          return false;
+        }
+      }
+    }
+    else
+    {
+      DALI_SCRIPT_EXCEPTION( isolate, "Target property not specified" );
+      return false;
+    }
+
+    //Get source property
+    member = obj->Get( v8::String::NewFromUtf8( isolate, "sourceProperty" ) );
+    if( member->IsString() )
+    {
+      std::string propertyName = V8Utils::v8StringToStdString( member );
+      sourcePropertyIndex = targetActor.GetPropertyIndex( propertyName );
+      if( sourcePropertyIndex == Property::INVALID_INDEX )
+      {
+        std::string convertedName = V8Utils::JavaScriptNameToPropertyName( propertyName );
+        sourcePropertyIndex = targetActor.GetPropertyIndex( convertedName );
+
+        if( sourcePropertyIndex == Property::INVALID_INDEX )
+        {
+          DALI_SCRIPT_EXCEPTION( isolate, "Source property not found" );
+          return false;
+        }
+      }
+    }
+    else
+    {
+      DALI_SCRIPT_EXCEPTION( isolate, "Source property not specified" );
+      return false;
+    }
+
+    //Get range
+    member = obj->Get( v8::String::NewFromUtf8( isolate, "range" ) );
+    if( member->IsObject() )
+    {
+      v8::Local<v8::Object> rangeObject = member->ToObject();
+      Property::Value value = V8Utils::GetPropertyValueFromObject( found, isolate, rangeObject );
+      value.Get( range );
+    }
+    else
+    {
+      DALI_SCRIPT_EXCEPTION( isolate, "Range not specified" );
+      return false;
+    }
+
+    //Get wrap range
+    member = obj->Get( v8::String::NewFromUtf8( isolate, "wrap" ) );
+    if( member->IsObject() )
+    {
+      v8::Local<v8::Object> wrapObject = member->ToObject();
+      Property::Value value = V8Utils::GetPropertyValueFromObject( found, isolate, wrapObject );
+      value.Get( wrap );
+    }
+    else
+    {
+      wrap =  Vector2(-FLT_MAX, FLT_MAX);
+    }
+
+    return true;
+  }
+  else
+  {
+    DALI_SCRIPT_EXCEPTION( isolate, "Bad parameter (Object)" );
+    return false;
+  }
+}
+
+} // un-named namespace
+
+/**
+ * Apply the constraint
+ * @method applyConstraint
+ * @for PathConstrainer and LinearConstrainer
+ * @param {Object}  Constraint
+ * @param {Object}  Constraint.targetActor
+ * @param {String}  Constraint.targetProperty
+ * @param {String}  Constraint.sourceProperty
+ * @param {Vector2} Constraint.range
+ * @param {Vector2} Constraint.wrap
+ *
+ * @example
+ *
+ *        var constraintPosition = {  "target":targetActor,
+ *                                    "targetProperty":"position",
+ *                                    "source":sourceActor,
+ *                                    "sourceProperty":"color-alpha",
+ *                                    "range":range
+ *                                    "wrap":wrap
+ *                                 };
+ *        pathConstrainer.applyConstraint( constraintPosition );
+ */
+void ConstrainerApi::Apply( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+  v8::Isolate* isolate = args.GetIsolate();
+  v8::HandleScope handleScope( isolate );
+
+  Actor target, source;
+  Property::Index targetPropertyIndex = Property::INVALID_INDEX;
+  Property::Index sourcePropertyIndex = Property::INVALID_INDEX;
+
+  Vector2 range, wrap;
+  if( GetApplyParameters(args, target, targetPropertyIndex, source,  sourcePropertyIndex, range, wrap ) )
+  {
+
+    PathConstrainer pathConstrainer = GetPathConstrainer( isolate, args );
+    if( pathConstrainer )
+    {
+      pathConstrainer.Apply( Property(target, targetPropertyIndex),
+                             Property(source, sourcePropertyIndex),
+                             range, wrap );
+    }
+    else
+    {
+      LinearConstrainer linearConstrainer = GetLinearConstrainer( isolate, args );
+      if( linearConstrainer )
+      {
+        linearConstrainer.Apply( Property(target, targetPropertyIndex),
+                                 Property(source, sourcePropertyIndex),
+                                 range, wrap );
+      }
+    }
+  }
+}
+
+/**
+ * Remove the constraint
+ * @method remove
+ * @for PathConstrainer
+ * @param {Object} Actor
+ * @example
+ *        pathConstrainer.remove( targetActor );
+ */
+void ConstrainerApi::Remove( const v8::FunctionCallbackInfo< v8::Value >& args )
+{
+  v8::Isolate* isolate = args.GetIsolate();
+  v8::HandleScope handleScope( isolate );
+
+  //Get target actor
+  bool found( false );
+  Actor targetActor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
+  if( !found )
+  {
+    DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 0 (Actor)" );
+    return;
+  }
+
+
+  PathConstrainer pathConstrainer = GetPathConstrainer( isolate, args );
+  if( pathConstrainer )
+  {
+    pathConstrainer.Remove(targetActor);
+  }
+  else
+  {
+    LinearConstrainer linearConstrainer = GetLinearConstrainer( isolate, args );
+    if( linearConstrainer )
+    {
+      linearConstrainer.Remove(targetActor);
+    }
+  }
+}
+
+} // namespace V8Plugin
+
+} // namespace Dali
diff --git a/plugins/dali-script-v8/src/animation/constrainer-api.h b/plugins/dali-script-v8/src/animation/constrainer-api.h
new file mode 100644 (file)
index 0000000..15d49ea
--- /dev/null
@@ -0,0 +1,46 @@
+#ifndef __DALI_V8PLUGIN_CONSTRAINER_API_H__
+#define __DALI_V8PLUGIN_CONSTRAINER_API_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+
+// EXTERNAL INCLUDES
+#include <v8.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace ConstrainerApi
+{
+  /**
+   * Constrainer API see constrainer.h for a description
+   */
+  void Apply( const v8::FunctionCallbackInfo< v8::Value >& args );
+  void Remove( const v8::FunctionCallbackInfo< v8::Value >& args );
+
+}; // namespace ConstrainerApi
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header __DALI_V8PLUGIN_PATH_CONSTRAINER_API_H__
diff --git a/plugins/dali-script-v8/src/animation/linear-constrainer-wrapper.cpp b/plugins/dali-script-v8/src/animation/linear-constrainer-wrapper.cpp
new file mode 100644 (file)
index 0000000..02d009c
--- /dev/null
@@ -0,0 +1,117 @@
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// CLASS HEADER
+#include "linear-constrainer-wrapper.h"
+
+// INTERNAL INCLUDES
+#include <animation/constrainer-api.h>
+#include <dali-wrapper.h>
+#include <shared/object-template-helper.h>
+#include <v8-utils.h>
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+namespace
+{
+
+const ApiFunction ConstrainerFunctions[]=
+{
+ { "ApplyConstraint",  ConstrainerApi::Apply },
+ { "RemoveConstraint", ConstrainerApi::Remove }
+};
+const unsigned int ConstrainerFunctionTableCount = sizeof(ConstrainerFunctions)/sizeof(ConstrainerFunctions[0]);
+
+} //un-named space
+
+LinearConstrainerWrapper::LinearConstrainerWrapper( LinearConstrainer linearConstrainer, GarbageCollectorInterface& gc )
+:HandleWrapper( BaseWrappedObject::LINEAR_CONSTRAINER, linearConstrainer, gc ),
+ mLinearConstrainer( linearConstrainer )
+{
+}
+
+v8::Handle<v8::ObjectTemplate> LinearConstrainerWrapper::MakeLinearConstrainerTemplate( v8::Isolate* isolate )
+{
+  v8::EscapableHandleScope handleScope( isolate );
+
+  v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
+  objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
+
+  // add our function properties
+  ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, ConstrainerFunctions, ConstrainerFunctionTableCount );
+
+  // property handle intercepts property getters and setters and signals
+  HandleWrapper::AddInterceptsToTemplate( isolate, objTemplate );
+
+  return handleScope.Escape( objTemplate );
+}
+
+v8::Handle<v8::Object> LinearConstrainerWrapper::WrapLinearConstrainer( v8::Isolate* isolate, LinearConstrainer linearConstrainer )
+{
+  v8::EscapableHandleScope handleScope( isolate );
+  v8::Local<v8::ObjectTemplate> objectTemplate;
+
+  objectTemplate = MakeLinearConstrainerTemplate( isolate );
+
+  // create an instance of the template
+  v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
+
+  // create the pathconstrainer object
+  LinearConstrainerWrapper* pointer = new LinearConstrainerWrapper( linearConstrainer, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
+
+  // assign the JavaScript object to the wrapper.
+  // This also stores Dali object, in an internal field inside the JavaScript object.
+  pointer->SetJavascriptObject( isolate, localObject );
+
+  return handleScope.Escape( localObject );
+}
+
+LinearConstrainer LinearConstrainerWrapper::GetLinearConstrainer()
+{
+  return mLinearConstrainer;
+}
+
+/**
+ * Create an initialized PathConstrainer handle.
+ * @constructor
+ * @for PathConstrainer
+ * @method PathConstrainer
+ */
+void LinearConstrainerWrapper::NewLinearConstrainer( const v8::FunctionCallbackInfo< v8::Value >& args)
+{
+  v8::Isolate* isolate = args.GetIsolate();
+  v8::HandleScope handleScope( isolate );
+
+  if( !args.IsConstructCall() )
+  {
+    DALI_SCRIPT_EXCEPTION( isolate, "constructor called without 'new" );
+    return;
+  }
+
+  LinearConstrainer linearConstrainer = LinearConstrainer::New();
+  v8::Local<v8::Object> localObject = WrapLinearConstrainer( isolate, linearConstrainer );
+  args.GetReturnValue().Set( localObject );
+}
+
+
+} // namespace V8Plugin
+
+} // namespace Dali
diff --git a/plugins/dali-script-v8/src/animation/linear-constrainer-wrapper.h b/plugins/dali-script-v8/src/animation/linear-constrainer-wrapper.h
new file mode 100644 (file)
index 0000000..610ab62
--- /dev/null
@@ -0,0 +1,83 @@
+#ifndef __DALI_V8PLUGIN_LINEAR_CONSTRAINER_WRAPPER_H__
+#define __DALI_V8PLUGIN_LINEAR_CONSTRAINER_WRAPPER_H__
+
+/*
+ * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <dali/public-api/animation/linear-constrainer.h>
+#include <v8.h>
+
+// INTERNAL INCLUDES
+#include <object/handle-wrapper.h>
+
+
+namespace Dali
+{
+
+namespace V8Plugin
+{
+
+/**
+ * Wraps a LinearConstrainer.
+ */
+class LinearConstrainerWrapper : public HandleWrapper
+{
+
+public:
+
+  /**
+   * Constructor
+   */
+  LinearConstrainerWrapper( LinearConstrainer linearConstrainer, GarbageCollectorInterface& gc );
+
+  /**
+   * Virtual destructor
+   */
+  virtual ~LinearConstrainerWrapper(){};
+
+  /**
+   * Creates a new PathConstrainer wrapped inside a Javascript Object.
+   * @param[in] args v8 function call arguments interpreted
+   */
+  static void NewLinearConstrainer( const v8::FunctionCallbackInfo< v8::Value >& args);
+
+  /**
+   * Wraps a PathConstrainer inside a Javascript object
+   */
+  static v8::Handle<v8::Object> WrapLinearConstrainer(v8::Isolate* isolate, LinearConstrainer pathConstrainer );
+
+  /*
+   * Get the wrapped PathConstrainer
+   */
+  LinearConstrainer GetLinearConstrainer();
+
+private:
+
+  /**
+   * Create a v8 object template for the PathConstrainer
+   */
+  static v8::Handle<v8::ObjectTemplate> MakeLinearConstrainerTemplate( v8::Isolate* isolate );
+
+  Dali::LinearConstrainer mLinearConstrainer;
+};
+
+} // namespace V8Plugin
+
+} // namespace Dali
+
+#endif // header
  */
 
 // CLASS HEADER
  */
 
 // CLASS HEADER
-#include "path-constraint-wrapper.h"
+#include "path-constrainer-wrapper.h"
 
 // INTERNAL INCLUDES
 
 // INTERNAL INCLUDES
-#include <v8-utils.h>
+#include <animation/constrainer-api.h>
 #include <dali-wrapper.h>
 #include <shared/object-template-helper.h>
 #include <dali-wrapper.h>
 #include <shared/object-template-helper.h>
+#include <v8-utils.h>
 
 namespace Dali
 {
 
 namespace Dali
 {
@@ -29,37 +30,52 @@ namespace Dali
 namespace V8Plugin
 {
 
 namespace V8Plugin
 {
 
-PathConstraintWrapper::PathConstraintWrapper( PathConstraint pathConstraint, GarbageCollectorInterface& gc )
-:HandleWrapper( BaseWrappedObject::PATH_CONSTRAINT, pathConstraint, gc ),
- mPathConstraint( pathConstraint )
+namespace
+{
+
+const ApiFunction ConstrainerFunctions[]=
+{
+ { "ApplyConstraint",  ConstrainerApi::Apply },
+ { "RemoveConstraint", ConstrainerApi::Remove }
+};
+const unsigned int ConstrainerFunctionTableCount = sizeof(ConstrainerFunctions)/sizeof(ConstrainerFunctions[0]);
+
+} //un-named space
+
+PathConstrainerWrapper::PathConstrainerWrapper( PathConstrainer pathConstrainer, GarbageCollectorInterface& gc )
+:HandleWrapper( BaseWrappedObject::PATH_CONSTRAINER, pathConstrainer, gc ),
+ mPathConstrainer( pathConstrainer )
 {
 }
 
 {
 }
 
-v8::Handle<v8::ObjectTemplate> PathConstraintWrapper::MakePathConstraintTemplate( v8::Isolate* isolate )
+v8::Handle<v8::ObjectTemplate> PathConstrainerWrapper::MakePathConstrainerTemplate( v8::Isolate* isolate )
 {
   v8::EscapableHandleScope handleScope( isolate );
 
   v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
   objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
 
 {
   v8::EscapableHandleScope handleScope( isolate );
 
   v8::Local<v8::ObjectTemplate> objTemplate = v8::ObjectTemplate::New();
   objTemplate->SetInternalFieldCount( BaseWrappedObject::FIELD_COUNT );
 
+  // add our function properties
+  ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, ConstrainerFunctions, ConstrainerFunctionTableCount );
+
   // property handle intercepts property getters and setters and signals
   HandleWrapper::AddInterceptsToTemplate( isolate, objTemplate );
 
   return handleScope.Escape( objTemplate );
 }
 
   // property handle intercepts property getters and setters and signals
   HandleWrapper::AddInterceptsToTemplate( isolate, objTemplate );
 
   return handleScope.Escape( objTemplate );
 }
 
-v8::Handle<v8::Object> PathConstraintWrapper::WrapPathConstraint( v8::Isolate* isolate, PathConstraint pathConstraint )
+v8::Handle<v8::Object> PathConstrainerWrapper::WrapPathConstrainer( v8::Isolate* isolate, PathConstrainer pathConstrainer )
 {
   v8::EscapableHandleScope handleScope( isolate );
   v8::Local<v8::ObjectTemplate> objectTemplate;
 
 {
   v8::EscapableHandleScope handleScope( isolate );
   v8::Local<v8::ObjectTemplate> objectTemplate;
 
-  objectTemplate = MakePathConstraintTemplate( isolate );
+  objectTemplate = MakePathConstrainerTemplate( isolate );
 
   // create an instance of the template
   v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
 
 
   // create an instance of the template
   v8::Local<v8::Object> localObject = objectTemplate->NewInstance();
 
-  // create the pathconstraint object
-  PathConstraintWrapper* pointer = new PathConstraintWrapper( pathConstraint, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
+  // create the pathconstrainer object
+  PathConstrainerWrapper* pointer = new PathConstrainerWrapper( pathConstrainer, Dali::V8Plugin::DaliWrapper::Get().GetDaliGarbageCollector() );
 
   // assign the JavaScript object to the wrapper.
   // This also stores Dali object, in an internal field inside the JavaScript object.
 
   // assign the JavaScript object to the wrapper.
   // This also stores Dali object, in an internal field inside the JavaScript object.
@@ -68,18 +84,18 @@ v8::Handle<v8::Object> PathConstraintWrapper::WrapPathConstraint( v8::Isolate* i
   return handleScope.Escape( localObject );
 }
 
   return handleScope.Escape( localObject );
 }
 
-PathConstraint PathConstraintWrapper::GetPathConstraint()
+PathConstrainer PathConstrainerWrapper::GetPathConstrainer()
 {
 {
-  return mPathConstraint;
+  return mPathConstrainer;
 }
 
 /**
 }
 
 /**
- * Create an initialized PathConstraint handle.
+ * Create an initialized PathConstrainer handle.
  * @constructor
  * @constructor
- * @for Path
- * @method Path
+ * @for PathConstrainer
+ * @method PathConstrainer
  */
  */
-void PathConstraintWrapper::NewPathConstraint( const v8::FunctionCallbackInfo< v8::Value >& args)
+void PathConstrainerWrapper::NewPathConstrainer( const v8::FunctionCallbackInfo< v8::Value >& args)
 {
   v8::Isolate* isolate = args.GetIsolate();
   v8::HandleScope handleScope( isolate );
 {
   v8::Isolate* isolate = args.GetIsolate();
   v8::HandleScope handleScope( isolate );
@@ -90,30 +106,11 @@ void PathConstraintWrapper::NewPathConstraint( const v8::FunctionCallbackInfo< v
     return;
   }
 
     return;
   }
 
-  //Extract Path Handle
-  bool parameterFound;
-  Handle pathHandle = V8Utils::GetHandleParameter( PARAMETER_0, parameterFound, isolate, args );
-  if( !parameterFound )
-  {
-    DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 0 (Path)" );
-    return;
-  }
-  Dali::Path path = Path::DownCast(pathHandle);
-
-  //Extract range
-  Vector2 range = V8Utils::GetVector2Parameter( PARAMETER_1, parameterFound, isolate, args );
-  if( !parameterFound )
-  {
-    DALI_SCRIPT_EXCEPTION( isolate, "bad parameter 1 (Range)" );
-    return;
-  }
-
-  PathConstraint pathConstraint = PathConstraint::New(path, range );
-  v8::Local<v8::Object> localObject = WrapPathConstraint( isolate, pathConstraint );
+  PathConstrainer pathConstrainer = PathConstrainer::New();
+  v8::Local<v8::Object> localObject = WrapPathConstrainer( isolate, pathConstrainer );
   args.GetReturnValue().Set( localObject );
 }
 
   args.GetReturnValue().Set( localObject );
 }
 
-
 } // namespace V8Plugin
 
 } // namespace Dali
 } // namespace V8Plugin
 
 } // namespace Dali
@@ -1,5 +1,5 @@
-#ifndef __DALI_V8PLUGIN_PATH_CONSTRAINT_WRAPPER_H__
-#define __DALI_V8PLUGIN_PATH_CONSTRAINT_WRAPPER_H__
+#ifndef __DALI_V8PLUGIN_PATH_CONSTRAINER_WRAPPER_H__
+#define __DALI_V8PLUGIN_PATH_CONSTRAINER_WRAPPER_H__
 
 /*
  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
 
 /*
  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
@@ -19,8 +19,8 @@
  */
 
 // EXTERNAL INCLUDES
  */
 
 // EXTERNAL INCLUDES
+#include <dali/public-api/animation/path-constrainer.h>
 #include <v8.h>
 #include <v8.h>
-#include <dali/public-api/animation/path-constraint.h>
 
 // INTERNAL INCLUDES
 #include <object/handle-wrapper.h>
 
 // INTERNAL INCLUDES
 #include <object/handle-wrapper.h>
@@ -33,9 +33,9 @@ namespace V8Plugin
 {
 
 /**
 {
 
 /**
- * Wraps a Path.
+ * Wraps a PathConstrainer.
  */
  */
-class PathConstraintWrapper : public HandleWrapper
+class PathConstrainerWrapper : public HandleWrapper
 {
 
 public:
 {
 
 public:
@@ -43,37 +43,37 @@ public:
   /**
    * Constructor
    */
   /**
    * Constructor
    */
-  PathConstraintWrapper( PathConstraint pathConstraint, GarbageCollectorInterface& gc );
+  PathConstrainerWrapper( PathConstrainer pathConstrainer, GarbageCollectorInterface& gc );
 
   /**
    * Virtual destructor
    */
 
   /**
    * Virtual destructor
    */
-  virtual ~PathConstraintWrapper(){};
+  virtual ~PathConstrainerWrapper(){};
 
   /**
 
   /**
-   * Creates a new PathConstraint wrapped inside a Javascript Object.
+   * Creates a new PathConstrainer wrapped inside a Javascript Object.
    * @param[in] args v8 function call arguments interpreted
    */
    * @param[in] args v8 function call arguments interpreted
    */
-  static void NewPathConstraint( const v8::FunctionCallbackInfo< v8::Value >& args);
+  static void NewPathConstrainer( const v8::FunctionCallbackInfo< v8::Value >& args);
 
   /**
 
   /**
-   * Wraps a PathConstraint inside a Javascript object
+   * Wraps a PathConstrainer inside a Javascript object
    */
    */
-  static v8::Handle<v8::Object> WrapPathConstraint(v8::Isolate* isolate, PathConstraint pathConstraint );
+  static v8::Handle<v8::Object> WrapPathConstrainer(v8::Isolate* isolate, PathConstrainer pathConstrainer );
 
   /*
 
   /*
-   * Get the wrapped PathConstraint
+   * Get the wrapped PathConstrainer
    */
    */
-  PathConstraint GetPathConstraint();
+  PathConstrainer GetPathConstrainer();
 
 private:
 
   /**
 
 private:
 
   /**
-   * Create a v8 object template for the PathConstraint
+   * Create a v8 object template for the PathConstrainer
    */
    */
-  static v8::Handle<v8::ObjectTemplate> MakePathConstraintTemplate( v8::Isolate* isolate );
+  static v8::Handle<v8::ObjectTemplate> MakePathConstrainerTemplate( v8::Isolate* isolate );
 
 
-  PathConstraint mPathConstraint;
+  Dali::PathConstrainer mPathConstrainer;
 };
 
 } // namespace V8Plugin
 };
 
 } // namespace V8Plugin
index 38231b8..09205d7 100644 (file)
@@ -25,8 +25,9 @@
 #include <actors/actor-wrapper.h>
 #include <stage/stage-wrapper.h>
 #include <image/image-wrapper.h>
 #include <actors/actor-wrapper.h>
 #include <stage/stage-wrapper.h>
 #include <image/image-wrapper.h>
+#include <animation/linear-constrainer-wrapper.h>
+#include <animation/path-constrainer-wrapper.h>
 #include <animation/path-wrapper.h>
 #include <animation/path-wrapper.h>
-#include <animation/path-constraint-wrapper.h>
 #include <animation/animation-wrapper.h>
 #include <events/pan-gesture-detector-wrapper.h>
 #include <shader-effects/shader-effect-wrapper.h>
 #include <animation/animation-wrapper.h>
 #include <events/pan-gesture-detector-wrapper.h>
 #include <shader-effects/shader-effect-wrapper.h>
@@ -59,7 +60,8 @@ const ApiFunction ConstructorFunctionTable[]=
     { "Rotation",           PropertyValueWrapper::NewRotation},
     { "Matrix",             PropertyValueWrapper::NewMatrix},
     { "Path",               PathWrapper::NewPath },
     { "Rotation",           PropertyValueWrapper::NewRotation},
     { "Matrix",             PropertyValueWrapper::NewMatrix},
     { "Path",               PathWrapper::NewPath },
-    { "PathConstraint",     PathConstraintWrapper::NewPathConstraint },
+    { "PathConstrainer",    PathConstrainerWrapper::NewPathConstrainer},
+    { "LinearConstrainer",  LinearConstrainerWrapper::NewLinearConstrainer},
     { "Actor",              ActorWrapper::NewActor },
     { "TextActor",          ActorWrapper::NewActor },
     { "ImageActor",         ActorWrapper::NewActor },
     { "Actor",              ActorWrapper::NewActor },
     { "TextActor",          ActorWrapper::NewActor },
     { "ImageActor",         ActorWrapper::NewActor },
index fee9d8c..b9f2cb8 100644 (file)
@@ -71,7 +71,8 @@ public:
       CONNECTION,
       ANIMATION,
       PATH,
       CONNECTION,
       ANIMATION,
       PATH,
-      PATH_CONSTRAINT,
+      PATH_CONSTRAINER,
+      LINEAR_CONSTRAINER,
       BUILDER,
       STAGE,
       FONT,
       BUILDER,
       STAGE,
       FONT,