From: Ferran Sole Date: Fri, 10 Apr 2015 10:11:00 +0000 (+0100) Subject: PathConstrainer changes in JS Plugin + LinearConstrainer X-Git-Tag: accepted/tizen/common/20150529.134100~40 X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=commitdiff_plain;h=5b6fb7aeb709bac7797bbc6400b0c76996faebf2 PathConstrainer changes in JS Plugin + LinearConstrainer 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 --- diff --git a/plugins/dali-script-v8/file.list b/plugins/dali-script-v8/file.list index 9dc4293..9914d3a 100644 --- a/plugins/dali-script-v8/file.list +++ b/plugins/dali-script-v8/file.list @@ -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)/animation/constrainer-api.cpp \ + $(v8_plugin_dir)/animation/linear-constrainer-wrapper.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 \ diff --git a/plugins/dali-script-v8/src/actors/actor-api.cpp b/plugins/dali-script-v8/src/actors/actor-api.cpp index 926c5cd..b36f68a 100644 --- a/plugins/dali-script-v8/src/actors/actor-api.cpp +++ b/plugins/dali-script-v8/src/actors/actor-api.cpp @@ -24,7 +24,7 @@ // INTERNAL INCLUDES #include #include -#include +#include namespace Dali { @@ -610,111 +610,6 @@ void ActorApi::ScaleBy( const v8::FunctionCallbackInfo& args ) 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 diff --git a/plugins/dali-script-v8/src/actors/actor-api.h b/plugins/dali-script-v8/src/actors/actor-api.h index 509c976..8543f11 100644 --- a/plugins/dali-script-v8/src/actors/actor-api.h +++ b/plugins/dali-script-v8/src/actors/actor-api.h @@ -68,12 +68,6 @@ namespace ActorApi 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 ); diff --git a/plugins/dali-script-v8/src/actors/actor-wrapper.cpp b/plugins/dali-script-v8/src/actors/actor-wrapper.cpp index 7e4dcc4..1686958 100644 --- a/plugins/dali-script-v8/src/actors/actor-wrapper.cpp +++ b/plugins/dali-script-v8/src/actors/actor-wrapper.cpp @@ -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 - { "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 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 index 0000000..701f4d4 --- /dev/null +++ b/plugins/dali-script-v8/src/animation/constrainer-api.cpp @@ -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 //For FLT_MAX + +// INTERNAL INCLUDES +#include +#include +#include +#include + +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 object = args.This(); + v8::Local field = v8::Local::Cast( object->GetInternalField( 0 ) ); + void* ptr = field->Value(); + + PathConstrainerWrapper* wrapper = static_cast( ptr ); + return wrapper->GetPathConstrainer(); +} + +LinearConstrainer GetLinearConstrainer( v8::Isolate* isolate, const v8::FunctionCallbackInfo< v8::Value >& args ) +{ + v8::HandleScope handleScope( isolate ); + + v8::Local object = args.This(); + v8::Local field = v8::Local::Cast( object->GetInternalField( 0 ) ); + void* ptr = field->Value(); + + LinearConstrainerWrapper* wrapper = static_cast( 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 obj = args[0]->ToObject(); + v8::Local member = obj->Get( v8::String::NewFromUtf8( isolate, "target" ) ); + + //Get target actor + if( member->IsObject() ) + { + v8::Local 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 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 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 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 index 0000000..15d49ea --- /dev/null +++ b/plugins/dali-script-v8/src/animation/constrainer-api.h @@ -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 + + +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 index 0000000..02d009c --- /dev/null +++ b/plugins/dali-script-v8/src/animation/linear-constrainer-wrapper.cpp @@ -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 +#include +#include +#include + +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 LinearConstrainerWrapper::MakeLinearConstrainerTemplate( v8::Isolate* isolate ) +{ + v8::EscapableHandleScope handleScope( isolate ); + + v8::Local 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 LinearConstrainerWrapper::WrapLinearConstrainer( v8::Isolate* isolate, LinearConstrainer linearConstrainer ) +{ + v8::EscapableHandleScope handleScope( isolate ); + v8::Local objectTemplate; + + objectTemplate = MakeLinearConstrainerTemplate( isolate ); + + // create an instance of the template + v8::Local 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 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 index 0000000..610ab62 --- /dev/null +++ b/plugins/dali-script-v8/src/animation/linear-constrainer-wrapper.h @@ -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 +#include + +// INTERNAL INCLUDES +#include + + +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 WrapLinearConstrainer(v8::Isolate* isolate, LinearConstrainer pathConstrainer ); + + /* + * Get the wrapped PathConstrainer + */ + LinearConstrainer GetLinearConstrainer(); + +private: + + /** + * Create a v8 object template for the PathConstrainer + */ + static v8::Handle MakeLinearConstrainerTemplate( v8::Isolate* isolate ); + + Dali::LinearConstrainer mLinearConstrainer; +}; + +} // namespace V8Plugin + +} // namespace Dali + +#endif // header diff --git a/plugins/dali-script-v8/src/animation/path-constraint-wrapper.cpp b/plugins/dali-script-v8/src/animation/path-constrainer-wrapper.cpp similarity index 54% rename from plugins/dali-script-v8/src/animation/path-constraint-wrapper.cpp rename to plugins/dali-script-v8/src/animation/path-constrainer-wrapper.cpp index 72434d9..4060533 100644 --- a/plugins/dali-script-v8/src/animation/path-constraint-wrapper.cpp +++ b/plugins/dali-script-v8/src/animation/path-constrainer-wrapper.cpp @@ -16,12 +16,13 @@ */ // CLASS HEADER -#include "path-constraint-wrapper.h" +#include "path-constrainer-wrapper.h" // INTERNAL INCLUDES -#include +#include #include #include +#include namespace Dali { @@ -29,37 +30,52 @@ namespace Dali 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 PathConstraintWrapper::MakePathConstraintTemplate( v8::Isolate* isolate ) +v8::Handle PathConstrainerWrapper::MakePathConstrainerTemplate( v8::Isolate* isolate ) { v8::EscapableHandleScope handleScope( isolate ); v8::Local 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 PathConstraintWrapper::WrapPathConstraint( v8::Isolate* isolate, PathConstraint pathConstraint ) +v8::Handle PathConstrainerWrapper::WrapPathConstrainer( v8::Isolate* isolate, PathConstrainer pathConstrainer ) { v8::EscapableHandleScope handleScope( isolate ); v8::Local objectTemplate; - objectTemplate = MakePathConstraintTemplate( isolate ); + objectTemplate = MakePathConstrainerTemplate( isolate ); // create an instance of the template v8::Local 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. @@ -68,18 +84,18 @@ v8::Handle PathConstraintWrapper::WrapPathConstraint( v8::Isolate* i 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 - * @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 ); @@ -90,30 +106,11 @@ void PathConstraintWrapper::NewPathConstraint( const v8::FunctionCallbackInfo< v 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 localObject = WrapPathConstraint( isolate, pathConstraint ); + PathConstrainer pathConstrainer = PathConstrainer::New(); + v8::Local localObject = WrapPathConstrainer( isolate, pathConstrainer ); args.GetReturnValue().Set( localObject ); } - } // namespace V8Plugin } // namespace Dali diff --git a/plugins/dali-script-v8/src/animation/path-constraint-wrapper.h b/plugins/dali-script-v8/src/animation/path-constrainer-wrapper.h similarity index 51% rename from plugins/dali-script-v8/src/animation/path-constraint-wrapper.h rename to plugins/dali-script-v8/src/animation/path-constrainer-wrapper.h index bbc4c92..cb98765 100644 --- a/plugins/dali-script-v8/src/animation/path-constraint-wrapper.h +++ b/plugins/dali-script-v8/src/animation/path-constrainer-wrapper.h @@ -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. @@ -19,8 +19,8 @@ */ // EXTERNAL INCLUDES +#include #include -#include // INTERNAL INCLUDES #include @@ -33,9 +33,9 @@ namespace V8Plugin { /** - * Wraps a Path. + * Wraps a PathConstrainer. */ -class PathConstraintWrapper : public HandleWrapper +class PathConstrainerWrapper : public HandleWrapper { public: @@ -43,37 +43,37 @@ public: /** * Constructor */ - PathConstraintWrapper( PathConstraint pathConstraint, GarbageCollectorInterface& gc ); + PathConstrainerWrapper( PathConstrainer pathConstrainer, GarbageCollectorInterface& gc ); /** * 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 */ - 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 WrapPathConstraint(v8::Isolate* isolate, PathConstraint pathConstraint ); + static v8::Handle WrapPathConstrainer(v8::Isolate* isolate, PathConstrainer pathConstrainer ); /* - * Get the wrapped PathConstraint + * Get the wrapped PathConstrainer */ - PathConstraint GetPathConstraint(); + PathConstrainer GetPathConstrainer(); private: /** - * Create a v8 object template for the PathConstraint + * Create a v8 object template for the PathConstrainer */ - static v8::Handle MakePathConstraintTemplate( v8::Isolate* isolate ); + static v8::Handle MakePathConstrainerTemplate( v8::Isolate* isolate ); - PathConstraint mPathConstraint; + Dali::PathConstrainer mPathConstrainer; }; } // namespace V8Plugin diff --git a/plugins/dali-script-v8/src/dali-wrapper.cpp b/plugins/dali-script-v8/src/dali-wrapper.cpp index 38231b8..09205d7 100644 --- a/plugins/dali-script-v8/src/dali-wrapper.cpp +++ b/plugins/dali-script-v8/src/dali-wrapper.cpp @@ -25,8 +25,9 @@ #include #include #include +#include +#include #include -#include #include #include #include @@ -59,7 +60,8 @@ const ApiFunction ConstructorFunctionTable[]= { "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 }, diff --git a/plugins/dali-script-v8/src/shared/base-wrapped-object.h b/plugins/dali-script-v8/src/shared/base-wrapped-object.h index fee9d8c..b9f2cb8 100644 --- a/plugins/dali-script-v8/src/shared/base-wrapped-object.h +++ b/plugins/dali-script-v8/src/shared/base-wrapped-object.h @@ -71,7 +71,8 @@ public: CONNECTION, ANIMATION, PATH, - PATH_CONSTRAINT, + PATH_CONSTRAINER, + LINEAR_CONSTRAINER, BUILDER, STAGE, FONT,