X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=plugins%2Fdali-script-v8%2Fsrc%2Fobject%2Fhandle-wrapper.cpp;h=2705eb0ce9d3223e2dc5834294fda029c3d920ad;hp=88a6e3e4e5d813d3203417427f2a443ad7573bce;hb=8c31a5ca493d17693e53f9909a4453b1fa058ab3;hpb=e8efa9549ccedae5b8377c9eb331aa8392895879 diff --git a/plugins/dali-script-v8/src/object/handle-wrapper.cpp b/plugins/dali-script-v8/src/object/handle-wrapper.cpp index 88a6e3e..2705eb0 100644 --- a/plugins/dali-script-v8/src/object/handle-wrapper.cpp +++ b/plugins/dali-script-v8/src/object/handle-wrapper.cpp @@ -33,6 +33,24 @@ namespace Dali namespace V8Plugin { +namespace // un-named name space +{ + +/** + * Contains a list of all functions that can be called + */ +const ApiFunction HandleFunctionTable[]= +{ + { "RegisterAnimatableProperty", HandleWrapper::RegisterAnimatableProperty }, +}; + +const unsigned int HandleFunctionTableCount = sizeof(HandleFunctionTable)/sizeof(HandleFunctionTable[0]); +} //un-named space + +/** + * @class Handle + */ + HandleWrapper::HandleWrapper( BaseWrappedObject::Type type, Handle handle, GarbageCollectorInterface& gc ) : @@ -175,10 +193,67 @@ void HandleWrapper::AddInterceptsToTemplate( v8::Isolate* isolate, v8::LocalSetNamedPropertyHandler( HandleWrapper::PropertyGet, HandleWrapper::PropertySet); + // add function properties + ObjectTemplateHelper::InstallFunctions( isolate, objTemplate, HandleFunctionTable, HandleFunctionTableCount ); + ObjectTemplateHelper::AddSignalConnectAndDisconnect( isolate, objTemplate ); } +/** + * Register a new animatable property. + * + * The object should support dynamic properties. + * Property names are expected to be unique, but this is not enforced. + * Property indices are unique to each registered custom property in a given object. + * returns dali.PROPERTY_INVALID_INDEX if registration failed. This can happen if you try + * to register animatable property on an object that does not have scene graph object. + * + * @method registerAnimatableProperty + * @for Handle + * @param {string} name The name of the property. + * @param {Object} propertyValue The new value of the property. + * @return {integer} The index of the property or dali.PROPERTY_INVALID_INDEX if registration failed + * @example + * + * var morphPropertyIdex = actor.registerAnimatableProperty("uMorphAmount", 0.0f); + * var fadeColorPropertyIdex = handle.registerAnimatableProperty("uFadeColor", [1.0, 0.0, 0.0, 1.0]); + * + */ +void HandleWrapper::RegisterAnimatableProperty( const v8::FunctionCallbackInfo< v8::Value >& args ) +{ + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope handleScope( isolate ); + + // unwrap the object + HandleWrapper* handleWrapper = Unwrap( isolate, args.This() ); + if( !handleWrapper ) + { + return; + } + + Handle handle = handleWrapper->mHandle; + + bool found( false ); + std::string propertyName = V8Utils::GetStringParameter( PARAMETER_0, found, isolate, args ); + if( !found ) + { + DALI_SCRIPT_EXCEPTION( isolate, "bad property name parameter" ); + return; + } + + found = false; + Dali::Property::Value daliPropertyValue = V8Utils::GetPropertyValueParameter(PARAMETER_1, found, isolate, args ); + if( !found || Dali::Property::NONE == daliPropertyValue.GetType() ) + { + DALI_SCRIPT_EXCEPTION( isolate, "bad property value parameter" ); + return; + } + else + { + args.GetReturnValue().Set( v8::Integer::New( isolate, handle.RegisterProperty(propertyName, daliPropertyValue) ) ); + } +} } // namespace V8Plugin