X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=plugins%2Fdali-script-v8%2Fsrc%2Factors%2Fimage-actor-api.cpp;h=7394fa030782553b5b029bef533149a5dfdff595;hb=16679931e0ac1f5d56f657ed579fc0cb524461e5;hp=fa93c7f46ca2e71f202b10c2f7ab9a915087d4b6;hpb=4c85a797e24c20bfb1670c079e5f66a9a5d6fa0e;p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git diff --git a/plugins/dali-script-v8/src/actors/image-actor-api.cpp b/plugins/dali-script-v8/src/actors/image-actor-api.cpp index fa93c7f..7394fa0 100644 --- a/plugins/dali-script-v8/src/actors/image-actor-api.cpp +++ b/plugins/dali-script-v8/src/actors/image-actor-api.cpp @@ -24,7 +24,8 @@ #include #include #include - +#include +#include namespace Dali { @@ -151,60 +152,311 @@ void ImageActorApi::GetImage( const v8::FunctionCallbackInfo& args ) } /** - * Tell the image actor to use the natural size of the current image - * or future images. + * Allows modification of an actors position in the depth sort algorithm. * - * Calling SetSize on this actor or animating the size of the actor - * overrides this behaviour. + * The offset can be altered for each coplanar actor hence allowing an order of painting. + * @param { Number } depthOffset the offset to be given to the actor. Positive values pushing it further back. + * @for ImageActor + * @method setSortModifier + */ +void ImageActorApi::SetSortModifier( const v8::FunctionCallbackInfo& args ) +{ + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope handleScope( isolate ); + ImageActor imageActor = GetImageActor( isolate, args ); + + bool found( false ); + float value = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 0.f ); + if( !found ) + { + DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" ); + return; + } + imageActor.SetSortModifier( value ); +} + +/** + * Retrieves the offset used to modify an actors position in the depth sort algorithm. + * @for ImageActor + * @method getSortModifier . + * @return { Number} the offset that has been given to the actor. Positive values pushing it further back + */ +void ImageActorApi::GetSortModifier( const v8::FunctionCallbackInfo& args ) +{ + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope handleScope( isolate ); + ImageActor imageActor = GetImageActor( isolate, args ); + + args.GetReturnValue().Set( v8::Number::New( isolate, imageActor.GetSortModifier() ) ); + +} + +/** + * Set the face-culling mode for this actor. + * @for ImageActor + * @method setCullFace + * @param {Number} cullMode + * @example + * // cull mode should be one of the following constants + * dali.CULL_FACE_DISABLE // Face culling disabled + * dali.CULL_FRONT_FACE // Cull front facing polygons + * dali.CULL_BACK_FACE // Cull back facing polygons + * dali.CULL_FRONT_AND_BACK_FACE // Cull front and back facing polygons + * actor.SetCullFace( dali.CULL_FRONT_FACE ); + */ +void ImageActorApi::SetCullFace( const v8::FunctionCallbackInfo& args ) +{ + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope handleScope( isolate ); + ImageActor imageActor = GetImageActor( isolate, args ); + + bool found( false ); + int cullMode = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 ); + if( !found ) + { + DALI_SCRIPT_EXCEPTION( isolate, "bad parameter" ); + return; + } + + imageActor.SetCullFace( static_cast( cullMode ) ); + +} + +/** + * Retrieve the face-culling mode for this actor. + * @for ImageActor + * @method getCullFace + * @return {Number} cullMode + * @example + * // cull mode is one of the following + * dali.CULL_FACE_DISABLE // Face culling disabled + * dali.CULL_FRONT_FACE // Cull front facing polygons + * dali.CULL_BACK_FACE // Cull back facing polygons + * dali.CULL_FRONT_AND_BACK_FACE // Cull front and back facing polygon + */ +void ImageActorApi::GetCullFace( const v8::FunctionCallbackInfo& args ) +{ + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope handleScope( isolate ); + ImageActor imageActor = GetImageActor( isolate, args ); + + args.GetReturnValue().Set( v8::Integer::New( isolate, imageActor.GetCullFace() ) ); + +} + +/** + * Sets the blending mode. * - * The image actor uses the natural image size after an image - * has been loaded. + * If blending is disabled (BLENDING_OFF) fade in and fade out animations do not work. + * + * @example + * // blend mode is one of the following + * dali.BLENDING_OFF // Blending is disabled. + * dali.BLENDING_AUTO // Blending is enabled if there is alpha channel. + * dali.BLENDING_ON // Blending is enabled. + * actor.SetBlendMode( dali.BLENDING_AUTO ); + * + * @for ImageActor + * @method setBlendMode + * @param { Number } blendMode + */ +void ImageActorApi::SetBlendMode( const v8::FunctionCallbackInfo& args ) +{ + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope handleScope( isolate ); + ImageActor imageActor = GetImageActor( isolate, args ); + + bool found( false ); + int mode = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 ); + if( !found ) + { + DALI_SCRIPT_EXCEPTION( isolate, "invalid BlendMode parameter" ); + return; + } + imageActor.SetBlendMode( static_cast( mode ) ); + +} + +/** * @for ImageActor - * @method setToNaturalSize + * @method getBlendMode + * @return { Number } blendMode + * @example returns one of the following: + * + * dali.BLENDING_OFF // Blending is disabled. + * dali.BLENDING_AUTO // Blending is enabled if there is alpha channel. + * dali.BLENDING_ON // Blending is enabled. + * */ -void ImageActorApi::SetToNaturalSize( const v8::FunctionCallbackInfo& args ) +void ImageActorApi::GetBlendMode( const v8::FunctionCallbackInfo& args ) { v8::Isolate* isolate = args.GetIsolate(); v8::HandleScope handleScope( isolate ); ImageActor imageActor = GetImageActor( isolate, args ); - imageActor.SetToNaturalSize(); + args.GetReturnValue().Set( v8::Integer::New( isolate, imageActor.GetBlendMode() ) ); } /** - * Query whether a pixel area has been set. * @for ImageActor - * @method isPixelAreaSet - * @return {Boolean} True if a pixel area has been set. + * @method setBlendFunc + * @param {Number} SourceBlending RGB + * @param {Number} DestinationBlending RGB + * @param {Number} SourceBlending Alpha + * @param {Number} DestinatinoBlending Alpha + * @example + * //blending constants + dali.BLEND_FACTOR_ZERO + dali.BLEND_FACTOR_ONE + dali.BLEND_FACTOR_SRC_COLOR + dali.BLEND_FACTOR_ONE_MINUS_SRC_COLOR + dali.BLEND_FACTOR_SRC_ALPHA + dali.BLEND_FACTOR_ONE_MINUS_SRC_ALPHA + dali.BLEND_FACTOR_DST_ALPHA + dali.BLEND_FACTOR_ONE_MINUS_DST_ALPHA + dali.BLEND_FACTOR_DST_COLOR + dali.BLEND_FACTOR_ONE_MINUS_DST_COLOR + dali.BLEND_FACTOR_SRC_ALPHA_SATURATE + dali.BLEND_FACTOR_CONSTANT_COLOR + dali.BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR + dali.BLEND_FACTOR_CONSTANT_ALPHA + dali.BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA + + actor.setBlendFunc( dali.BLEND_FACTOR_CONSTANT_COLOR, BLEND_FACTOR_ONE_MINUS_CONSTANT_COLOR, + dali.BLEND_FACTOR_CONSTANT_ALPHA, BLEND_FACTOR_ONE_MINUS_CONSTANT_ALPHA); + + ); */ -void ImageActorApi::IsPixelAreaSet( const v8::FunctionCallbackInfo& args ) +void ImageActorApi::SetBlendFunc( const v8::FunctionCallbackInfo< v8::Value >& args ) { v8::Isolate* isolate = args.GetIsolate(); v8::HandleScope handleScope( isolate ); ImageActor imageActor = GetImageActor( isolate, args ); - args.GetReturnValue().Set( v8::Boolean::New( isolate, imageActor.IsPixelAreaSet() ) ); + int params[4]; + bool foundAllParams(false); + V8Utils::ReadIntegerArguments( foundAllParams, ¶ms[0], 4, args,0 ); + if( foundAllParams ) + { + imageActor.SetBlendFunc( static_cast< Dali::BlendingFactor::Type>(params[0]), + static_cast< Dali::BlendingFactor::Type>(params[1]), + static_cast< Dali::BlendingFactor::Type>(params[2]), + static_cast< Dali::BlendingFactor::Type>(params[3])); + } + else + { + DALI_SCRIPT_EXCEPTION( isolate, "invalid BlendMode parameter"); + return; + } } /** - * Remove any pixel areas specified with SetPixelArea; the entire image will be displayed. + * @for ImageActor + * @method GetBlendFunc + * @return {Object} BlendProperties + * @example Blend properties object has 4 fields * - * The actor size will change to that of the Image unless a custom size was set, e.g. via - * actor.size + * blendProperties.sourceRgb // source rgb enum + * blendProperties.destinationRgb // destination rgb enum + * blendProperties.sourceAlpha source // alpha enum + * blendProperties.destinationAlpha // destination alpha enum + */ +void ImageActorApi::GetBlendFunc( const v8::FunctionCallbackInfo< v8::Value >& args ) +{ + // @todo pass by reference doesn't work in Javascript so need to decide what to return + // for now just return a vector 4... + + BlendingFactor::Type srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha; + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope handleScope( isolate ); + ImageActor imageActor = GetImageActor( isolate, args ); + + imageActor.GetBlendFunc( srcFactorRgb, destFactorRgb, srcFactorAlpha, destFactorAlpha ); + + v8::Local blendInfo = v8::Object::New( isolate ); + + blendInfo->Set( v8::String::NewFromUtf8( isolate, "sourceRgb" ), v8::Integer::New( isolate, srcFactorRgb) ); + blendInfo->Set( v8::String::NewFromUtf8( isolate, "destinationRgb" ), v8::Integer::New( isolate, destFactorRgb ) ); + blendInfo->Set( v8::String::NewFromUtf8( isolate, "sourceAlpha" ), v8::Integer::New( isolate, srcFactorAlpha ) ); + blendInfo->Set( v8::String::NewFromUtf8( isolate, "destinationAlpha" ), v8::Integer::New( isolate, destFactorAlpha ) ); + + args.GetReturnValue().Set( blendInfo ); + +} + +/** * @for ImageActor - * @method clearPixelArea + * @method getShaderEffect + * @return {Object} ShaderEffect object + * + * Retrieve the shader effect for the Actor. + * + * @example + * var shaderEffect = actor.getShaderEffect(); + * */ -void ImageActorApi::ClearPixelArea( const v8::FunctionCallbackInfo& args ) +void ImageActorApi::GetShaderEffect( const v8::FunctionCallbackInfo& args ) { v8::Isolate* isolate = args.GetIsolate(); v8::HandleScope handleScope( isolate ); ImageActor imageActor = GetImageActor( isolate, args ); - imageActor.ClearPixelArea(); + v8::Local < v8::Object > object = ShaderEffectWrapper::WrapShaderEffect( isolate, imageActor.GetShaderEffect() ); + args.GetReturnValue().Set( object ); + } +/** + * @for ImageActor + * @method setShaderEffect + * @param {Object} shaderEffect The shader effect. + * + * Sets the shader effect for the Actor. + * + * Shader effects provide special effects like rippling and bending. + * Setting a shader effect removes any shader effect previously set by SetShaderEffect. + * @example + * // first create the shaderOptions, then the shaderEffect + * var shader = new dali.ShaderEffect( shaderOptions ); + * actor.setShaderEffect( shader ); + * + */ +void ImageActorApi::SetShaderEffect( const v8::FunctionCallbackInfo& args ) +{ + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope handleScope( isolate ); + ImageActor imageActor = GetImageActor( isolate, args ); + + bool found( false ); + ShaderEffect effect = ShaderEffectApi::GetShaderEffectFromParams( 0, found, isolate, args ); + if( found ) + { + imageActor.SetShaderEffect( effect ); + } + else + { + DALI_SCRIPT_EXCEPTION( isolate, "shader effect parameter missing" ); + } +} +/** + * + * Removes the current shader effect + * + * @example + * actor.removeShaderEffect(); + * + * @for ImageActor + * @method removeShaderEffect + */ +void ImageActorApi::RemoveShaderEffect( const v8::FunctionCallbackInfo& args ) +{ + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope handleScope( isolate ); + ImageActor imageActor = GetImageActor( isolate, args ); + imageActor.RemoveShaderEffect(); +} } // namespace V8Plugin