X-Git-Url: http://review.tizen.org/git/?p=platform%2Fcore%2Fuifw%2Fdali-toolkit.git;a=blobdiff_plain;f=plugins%2Fdali-script-v8%2Fsrc%2Factors%2Factor-api.cpp;h=9459a46b71e4ef04caca894e22a2e253768fab92;hp=4027a1bf11f4c63552da5c02e29fd727a8a67a57;hb=a2de9cf491172cd5da9dc9ed60b17683dab6d7bc;hpb=6b7d48695715c6f2292338fccbeeb02873d1f89d diff --git a/plugins/dali-script-v8/src/actors/actor-api.cpp b/plugins/dali-script-v8/src/actors/actor-api.cpp index 4027a1b..9459a46 100644 --- a/plugins/dali-script-v8/src/actors/actor-api.cpp +++ b/plugins/dali-script-v8/src/actors/actor-api.cpp @@ -19,11 +19,14 @@ #include "actor-api.h" // EXTERNAL INCLUDES -#include +#include // INTERNAL INCLUDES #include #include +#include +#include +#include namespace Dali { @@ -33,21 +36,14 @@ namespace V8Plugin namespace // unanmed namespace { + Actor GetActor( v8::Isolate* isolate, const v8::FunctionCallbackInfo& args ) { HandleWrapper* handleWrapper = HandleWrapper::Unwrap( isolate, args.This() ); return Actor::DownCast( handleWrapper->mHandle ); } -} //unanmed namespace - -namespace TextViewApi -{ - Actor New( const v8::FunctionCallbackInfo< v8::Value >& args ) - { - return Dali::Toolkit::TextView::New(); - } -} +} //unanmed namespace /*************************************** * ACTOR API FUNCTIONS @@ -276,7 +272,7 @@ void ActorApi::GetChildCount( const v8::FunctionCallbackInfo& args ) } /** - * Retrieve and child actor by index. + * Retrieve a child actor by index. * * @for Actor * @method getChildAt @@ -485,7 +481,7 @@ void ActorApi::IsKeyboardFocusable( const v8::FunctionCallbackInfo& a * * @for Actor * @method getActorType - * @return {String} Actor, ImageActor, TextActor, MeshActor, Layer, CameraActor ... + * @return {String} Actor, Layer, CameraActor ... */ void ActorApi::GetActorType( const v8::FunctionCallbackInfo& args ) { @@ -498,6 +494,118 @@ void ActorApi::GetActorType( const v8::FunctionCallbackInfo& args ) args.GetReturnValue().Set( v8String ); } /** + * Return the natural size of the actor. + * + * @for Actor + * @method getNaturalSize + * @return {Object} { x, y, z } + */ +void ActorApi::GetNaturalSize( const v8::FunctionCallbackInfo& args ) +{ + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope handleScope( isolate ); + Actor actor = GetActor( isolate, args ); + + Vector3 size( actor.GetNaturalSize() ); + + v8::Local sizeObject = v8::Object::New( isolate ); + + sizeObject->Set( v8::String::NewFromUtf8( isolate, "x" ), v8::Integer::New( isolate, size.width ) ); + sizeObject->Set( v8::String::NewFromUtf8( isolate, "y" ), v8::Integer::New( isolate, size.height ) ); + sizeObject->Set( v8::String::NewFromUtf8( isolate, "z" ), v8::Integer::New( isolate, size.depth ) ); + + args.GetReturnValue().Set( sizeObject ); +} + +/** + * Return the value of negotiated dimension for the given dimension + * + * @for Actor + * @method getRelayoutSize + * @param {Integer} dimension The dimension of layout to retrieve (either dali.DIMENSION_WIDTH or dali.DIMENSION_HEIGHT) + * @return {Number} The value of the negotiated dimension + */ +void ActorApi::GetRelayoutSize( const v8::FunctionCallbackInfo& args ) +{ + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope handleScope( isolate ); + Actor actor = GetActor( isolate, args ); + + bool found; + int dimension = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 ); + if( !found ) + { + DALI_SCRIPT_EXCEPTION( isolate, "missing dimension parameter"); + return; + } + + args.GetReturnValue().Set( v8::Number::New( isolate, actor.GetRelayoutSize( static_cast(dimension) ) ) ); +} + +/** + * Calculate the width of the actor given a height + * + * The natural size is used for default calculation. + * size 0 is treated as aspect ratio 1:1. + * @for Actor + * @method getWidthForHeight + * @param {Float} height to use + * @return {Float} Return the width based on the height + * @example + * myTextLabel.getWidthForHeight(40); + * + * // DALi uses this formula internally + * // width = naturalSize.width * height / naturalSize.height; + * + * + */ +void ActorApi::GetWidthForHeight( const v8::FunctionCallbackInfo& args ) +{ + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope handleScope( isolate ); + Actor actor = GetActor( isolate, args ); + + bool found; + float height = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 0.f ); + if( !found ) + { + DALI_SCRIPT_EXCEPTION( isolate, "missing height parameter"); + return; + } + args.GetReturnValue().Set( v8::Number::New( isolate, actor.GetWidthForHeight( height ) ) ); +} + +/** + * Calculate the height of the actor given a width + * + * The natural size is used for default calculation. + * size 0 is treated as aspect ratio 1:1. + * @for Actor + * @method getHeightForWidth + * @param {Float} width to use + * @return {Float} Return the height based on the width + * @example + * myTextLabel.getHeightForWidth(250); + * + * // DALi uses this formula internally + * // height = naturalSize.height * width / naturalSize.width + */ +void ActorApi::GetHeightForWidth( const v8::FunctionCallbackInfo& args ) +{ + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope handleScope( isolate ); + Actor actor = GetActor( isolate, args ); + + bool found; + float width = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 0.f ); + if( !found ) + { + DALI_SCRIPT_EXCEPTION( isolate, "missing width parameter"); + return; + } + args.GetReturnValue().Set( v8::Number::New( isolate, actor.GetHeightForWidth( width ) ) ); +} +/** * Move an actor relative to its existing position. * @example * @@ -557,7 +665,7 @@ void ActorApi::RotateBy( const v8::FunctionCallbackInfo& args ) bool found( false ); Property::Value rotation = V8Utils::GetPropertyValueParameter( PARAMETER_0, found, isolate, args ); - if( rotation.GetType() != Property::ORIENTATION ) + if( rotation.GetType() != Property::ROTATION ) { DALI_SCRIPT_EXCEPTION( isolate, "Rotation parameter missing" ); return; @@ -609,6 +717,130 @@ void ActorApi::ScaleBy( const v8::FunctionCallbackInfo& args ) actor.ScaleBy( vector ); } +/** + * Add a renderer to this actor. + * @example + * + * var renderer = new dali.Renderer( geometry, shader ); + * actor.addRenderer( renderer ); + * + * @for Actor + * @method addRenderer + * @param {object} renderer Renderer to add to the actor + * @return {integer} The index of the Renderer that was added + */ +void ActorApi::AddRenderer( const v8::FunctionCallbackInfo& args ) +{ + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope handleScope( isolate ); + Actor actor = GetActor( isolate, args ); + + unsigned int index = 0; + + bool found( false ); + Renderer renderer = RendererApi::GetRendererFromParams( 0, found, isolate, args ); + if( found ) + { + index = actor.AddRenderer(renderer); + } + else + { + DALI_SCRIPT_EXCEPTION( isolate, "Renderer parameter missing" ); + return; + } + + args.GetReturnValue().Set( v8::Integer::New( isolate, index ) ); +} + +/** + * Get the number of renderers on this actor. + * @example + * + * var count = actor.getRendererCount(); + * + * @for Actor + * @method getRendererCount + * @return {integer} the number of renderers on this actor + */ +void ActorApi::GetRendererCount( const v8::FunctionCallbackInfo& args ) +{ + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope handleScope( isolate ); + + Actor actor = GetActor( isolate, args ); + args.GetReturnValue().Set( v8::Integer::New( isolate, actor.GetRendererCount() ) ); +} + +/** + * Get a Renderer by index. + * @example + * + * var renderer = actor.getRendererAt( 0 ); + * + * @for Actor + * @method getRendererAt + * @param {integer} index The index of the renderer to fetch, which must be between 0 and getRendererCount()-1 + * @return {object} The renderer at the specified index + */ +void ActorApi::GetRendererAt( const v8::FunctionCallbackInfo& args ) +{ + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope handleScope( isolate ); + Actor actor = GetActor( isolate, args ); + + Renderer renderer; + + bool found( false ); + int index = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0); + if( !found ) + { + DALI_SCRIPT_EXCEPTION( isolate, "invalid index parameter" ); + return; + } + else + { + renderer = actor.GetRendererAt(static_cast(index)); + if( !renderer ) + { + DALI_SCRIPT_EXCEPTION( isolate, "renderer not found" ); + return; + } + } + + // Wrap the renderer + v8::Local localObject = RendererWrapper::WrapRenderer( isolate, renderer ); + args.GetReturnValue().Set( localObject ); +} + +/** + * Remove an renderer from the actor by index. + * @example + * + * actor.removeRenderer( 0 ); + * + * @for Actor + * @method removeRenderer + * @param {integer} index Index of the renderer to be removed, which must be between 0 and getRendererCount()-1 + */ +void ActorApi::RemoveRenderer( const v8::FunctionCallbackInfo& args ) +{ + v8::Isolate* isolate = args.GetIsolate(); + v8::HandleScope handleScope( isolate ); + Actor actor = GetActor( isolate, args ); + + bool found( false ); + int index = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0); + if( !found ) + { + DALI_SCRIPT_EXCEPTION( isolate, "invalid index parameter" ); + } + else + { + actor.RemoveRenderer(static_cast(index)); + } +} + + } // namespace V8Plugin } // namespace Dali