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-wrapper.cpp;h=d04eec38f18f962275727f7a637135a9f53bff39;hp=7d10f3ae5eed70a58fe02828c80b57ec88c6b27f;hb=00a82ee18b8b96362eb83cd84141e02ab3221702;hpb=4c85a797e24c20bfb1670c079e5f66a9a5d6fa0e diff --git a/plugins/dali-script-v8/src/actors/actor-wrapper.cpp b/plugins/dali-script-v8/src/actors/actor-wrapper.cpp index 7d10f3a..d04eec3 100644 --- a/plugins/dali-script-v8/src/actors/actor-wrapper.cpp +++ b/plugins/dali-script-v8/src/actors/actor-wrapper.cpp @@ -20,15 +20,12 @@ // EXTERNAL INCLUDES #include +#include // INTERNAL INCLUDES #include #include -#include -#include -#include #include -#include #include #include @@ -39,12 +36,8 @@ namespace V8Plugin { v8::Persistent ActorWrapper::mActorTemplate; -v8::Persistent ActorWrapper::mImageActorTemplate; -v8::Persistent ActorWrapper::mTextActorTemplate; -v8::Persistent ActorWrapper::mMeshActorTemplate; v8::Persistent ActorWrapper::mCameraActorTemplate; v8::Persistent ActorWrapper::mLayerActorTemplate; -v8::Persistent ActorWrapper::mTextViewTemplate; namespace { @@ -64,12 +57,8 @@ struct ActorTemplate const ActorTemplate ActorTemplateLookup[]= { { &ActorWrapper::mActorTemplate }, // ACTOR - { &ActorWrapper::mImageActorTemplate }, // IMAGE_ACTOR - { &ActorWrapper::mTextActorTemplate }, // TEXT_ACTOR - { &ActorWrapper::mMeshActorTemplate }, // MESH_ACTOR { &ActorWrapper::mLayerActorTemplate }, // LAYER_ACTOR - { &ActorWrapper::mCameraActorTemplate}, // CAMERA_ACTOR - { &ActorWrapper::mTextViewTemplate } + { &ActorWrapper::mCameraActorTemplate} // CAMERA_ACTOR }; /** @@ -78,12 +67,8 @@ const ActorTemplate ActorTemplateLookup[]= enum ActorApiBitMask { ACTOR_API = 1 << 0, - RENDERABLE_ACTOR_API = 1 << 1, - IMAGE_ACTOR_API = 1 << 2, - TEXT_ACTOR_API = 1 << 3, - MESH_ACTOR_API = 1 << 4, - LAYER_API = 1 << 5, - CAMERA_ACTOR_API = 1 << 6, + LAYER_API = 1 << 1, + CAMERA_ACTOR_API = 1 << 2, }; /** @@ -99,17 +84,13 @@ struct ActorApiStruct /** * Lookup table to match a actor type with a constructor and supported API's. + * HandleWrapper::ActorType is used to index this table */ const ActorApiStruct ActorApiLookup[]= { {"Actor", ActorWrapper::ACTOR, ActorApi::New, ACTOR_API }, - {"ImageActor", ActorWrapper::IMAGE_ACTOR, ImageActorApi::New, ACTOR_API | RENDERABLE_ACTOR_API | IMAGE_ACTOR_API }, - {"TextActor", ActorWrapper::TEXT_ACTOR, TextActorApi::New, ACTOR_API | RENDERABLE_ACTOR_API | TEXT_ACTOR_API }, - {"MeshActor", ActorWrapper::MESH_ACTOR, MeshActorApi::New, ACTOR_API | RENDERABLE_ACTOR_API | MESH_ACTOR_API }, {"Layer", ActorWrapper::LAYER_ACTOR, LayerApi::New, ACTOR_API | LAYER_API }, {"CameraActor",ActorWrapper::CAMERA_ACTOR, CameraActorApi::New, ACTOR_API | CAMERA_ACTOR_API }, - {"TextView", ActorWrapper::TEXT_VIEW, TextViewApi::New, ACTOR_API }, - }; const unsigned int ActorApiLookupCount = sizeof(ActorApiLookup)/sizeof(ActorApiLookup[0]); @@ -130,25 +111,13 @@ Actor CreateActor( const v8::FunctionCallbackInfo< v8::Value >& args, // if we don't currently support the actor type, then use type registry to create it if( actorType == ActorWrapper::UNKNOWN_ACTOR ) { - Dali::TypeInfo typeInfo = Dali::TypeRegistry::Get().GetTypeInfo( typeName ); - if( typeInfo ) // handle, check if it has a value - { - Dali::BaseHandle handle = typeInfo.CreateInstance(); - if( handle ) - { - actor = Actor::DownCast( handle ); - } - } - else - { - DALI_SCRIPT_EXCEPTION(args.GetIsolate(),"Unknown actor type"); + DALI_SCRIPT_EXCEPTION( args.GetIsolate(), "Unknown actor type" ); return Actor(); - } } else { // run the constructor for this type of actor so it can pull out - // custom parameters, e.g. new TextActor("hello world"); or ImageActor( MyImage ); + // custom parameters; actor = (ActorApiLookup[actorType].constructor)( args ); } return actor; @@ -177,7 +146,7 @@ struct ActorFunctions /** * Contains a list of all functions that can be called an - * actor / image-actor / mesh-actor/ layer / camera-actor + * actor / image-actor / layer / camera-actor */ const ActorFunctions ActorFunctionTable[]= { @@ -199,7 +168,6 @@ const ActorFunctions ActorFunctionTable[]= { "GetChildCount", ActorApi::GetChildCount, ACTOR_API }, { "GetChildAt" , ActorApi::GetChildAt, ACTOR_API }, { "FindChildByName", ActorApi::FindChildByName, ACTOR_API }, - { "FindChildByAlias", ActorApi::FindChildByAlias, ACTOR_API }, { "FindChildById", ActorApi::FindChildById, ACTOR_API }, { "GetParent" , ActorApi::GetParent, ACTOR_API }, { "GetActorType" , ActorApi::GetActorType, ACTOR_API }, // custom for javascript @@ -210,19 +178,22 @@ const ActorFunctions ActorFunctionTable[]= // ignore. GetCurrentAnchorPoint() use Actor.anchorPoint // ignore. SetSize() use Actor.size // ignore. GetCurrentSize() use Actor.size + { "GetNaturalSize", ActorApi::GetNaturalSize, ACTOR_API }, + { "GetWidthForHeight",ActorApi::GetWidthForHeight, ACTOR_API }, + { "GetHeightForWidth",ActorApi::GetHeightForWidth, ACTOR_API }, // ignore. SetPosition(....) use Actor.position // ignore. SetX, SetY, SetZ, use Actor.position.x, Actor.position.y, Actor.position.z - { "MoveBy", ActorApi::MoveBy, ACTOR_API }, + { "TranslateBy", ActorApi::TranslateBy, ACTOR_API }, // ignore GetCurrentPosition(). use Actor.position // ignore GetCurrentWorldPosition() use Actor.worldPosition // ignore SetPositionInheritanceMode() use Actor.positionInheritance // ignore GetPositionInheritanceMode() use Actor.positionInheritance - // ignore SetRotation() use Actor.rotation + // ignore SetOrientation() use Actor.orientation { "RotateBy", ActorApi::RotateBy, ACTOR_API }, - // ignore GetCurrentRotation() use Actor.rotation - // ignore SetInheritRotation() use Actor.inheritRotation - // ignore IsRotationInherited() use Actor.inheritRotation - // ignore GetCurrentWorldRotation() use Actor.worldRotation + // ignore GetCurrentOrientation() use Actor.orientation + // ignore SetInheritOrientation() use Actor.inheritOrientation + // ignore IsOrientationInherited() use Actor.inheritOrientation + // ignore GetCurrentWorldOrientation() use Actor.worldOrientation // ignore SetScale() use Actor.scale { "ScaleBy", ActorApi::ScaleBy, ACTOR_API }, // ignore GetCurrentScale() use Actor.scale @@ -233,16 +204,12 @@ const ActorFunctions ActorFunctionTable[]= // ignore SetVisible() use Actor.visible // ignore IsVisible() use Actor.visible // ignore SetOpacity() use Actor.opacity - { "OpactiyBy", ActorApi::OpacityBy, ACTOR_API }, // ignore GetCurrentOpacity() use Actor.opacity // ignore SetColor() use Actor.color - { "ColorBy", ActorApi::ColorBy, ACTOR_API }, // ignore GetCurrentColor() use Actor.color // ignore SetColorMode() use Actor.colorMode // ignore GetColorMode() use Actor.colorMode // ignore GetCurrentWorldColor() use Actor.worldColor - // ignore SetInheritShaderEffect() use Actor.inheritShaderEffect - // ignore GetInheritShaderEffect() use Actor.inheritShaderEffect // ignore SetDrawMode() use Actor.drawMode // ignore GetDrawMode() use Actor.drawMode // ignore SetSensitive() use Actor.sensitve @@ -253,27 +220,10 @@ const ActorFunctions ActorFunctionTable[]= { "SetKeyboardFocusable", ActorApi::SetKeyboardFocusable, ACTOR_API }, //-- should this be a property??? { "IsKeyboardFocusable" , ActorApi::IsKeyboardFocusable, ACTOR_API }, //-- should this be a property??? - /************************************** - * Renderable Actor API (in order of renderable-actor.h) - **************************************/ - { "SetSortModifier", RenderableActorApi::SetSortModifier, RENDERABLE_ACTOR_API }, - { "GetSortModifier", RenderableActorApi::GetSortModifier, RENDERABLE_ACTOR_API }, - { "SetCullFace", RenderableActorApi::SetCullFace, RENDERABLE_ACTOR_API }, - { "GetCullFace", RenderableActorApi::GetCullFace, RENDERABLE_ACTOR_API }, - { "SetBlendMode", RenderableActorApi::SetBlendMode, RENDERABLE_ACTOR_API }, - { "GetBlendMode", RenderableActorApi::GetBlendMode, RENDERABLE_ACTOR_API }, - { "SetBlendFunc", RenderableActorApi::SetBlendFunc, RENDERABLE_ACTOR_API }, - { "GetBlendFunc", RenderableActorApi::GetBlendFunc, RENDERABLE_ACTOR_API }, - { "SetBlendEquation", RenderableActorApi::SetBlendEquation, RENDERABLE_ACTOR_API }, - { "GetBlendEquation", RenderableActorApi::GetBlendEquation, RENDERABLE_ACTOR_API }, - { "SetBlendColor", RenderableActorApi::SetBlendColor, RENDERABLE_ACTOR_API }, - { "GetBlendColor", RenderableActorApi::GetBlendColor, RENDERABLE_ACTOR_API }, - { "SetShaderEffect", RenderableActorApi::SetShaderEffect, RENDERABLE_ACTOR_API }, - { "GetShaderEffect", RenderableActorApi::GetShaderEffect, RENDERABLE_ACTOR_API }, - { "RemoveShaderEffect", RenderableActorApi::RemoveShaderEffect,RENDERABLE_ACTOR_API }, - - - + { "AddRenderer", ActorApi::AddRenderer, ACTOR_API }, + { "GetRendererCount", ActorApi::GetRendererCount, ACTOR_API }, + { "GetRendererAt" , ActorApi::GetRendererAt, ACTOR_API }, + { "RemoveRenderer" , ActorApi::RemoveRenderer, ACTOR_API }, /************************************** * Layer API (in order of layer.h) @@ -295,70 +245,6 @@ const ActorFunctions ActorFunctionTable[]= // @todo SetSortFunction /************************************** - * Image Actor API (in order of image-actor.h) - **************************************/ - - { "SetImage", ImageActorApi::SetImage, IMAGE_ACTOR_API }, - { "GetImage", ImageActorApi::GetImage, IMAGE_ACTOR_API }, - { "SetToNaturalSize", ImageActorApi::SetToNaturalSize, IMAGE_ACTOR_API }, - // ignore SetPixelArea, use imageActor.pixelArea - // ignore GetPixelArea, use imageActor.pixelArea - { "IsPixelAreaSet", ImageActorApi::IsPixelAreaSet, IMAGE_ACTOR_API }, - { "ClearPixelArea", ImageActorApi::ClearPixelArea, IMAGE_ACTOR_API }, - // ignore SetStyle, use imageActor.style - // ignore GetStyle, use imageActor.style - // ignore SetNinePatchBorder use imageActor.border - // ignore GetNinePatchBorder use imageActor.border - // ignore SetFadeIn use imageActor.fadeIn - // ignore GetFadeIn use imageActor.fadeIn - // ignore SetFadeInDuration use imageActor.fadeInDuration - // ignore GetFadeInDuration use imageActor.fadeInDuration - //{ "GetCurrentImageSize", ImageActorApi::GetCurrentImageSize, IMAGE_ACTOR_API }, - - - /************************************** - * Text Actor API (in order of text-actor.h) - **************************************/ - //ignore SetText use textActor.text - { "SetToNaturalSize", TextActorApi::SetToNaturalSize, TEXT_ACTOR_API }, - // ignore GetFont use textActor.font - // ignore SetFont use textActor.font - // ignore SetGradient use textActor.gradientColor - // ignore GetGradient textActor.gradientColor - // ignore SetGradientStartPoint use textActor.gradientStartPoint - // ignore GetGradientStartPoint textActor.gradientStartPoint - // ignore SetGradientEndPoint use textActor.gradientEndPoint - // ignore GetGradientEndPoint textActor.gradientEndPoint - // @todo? SetTextStyle ( can use individual properties as a work around ) - // @todo? GetTextStyle ( can use individual properties as a work around ) - // ignore SetTextColor use textActor.textColor - // ignore GetTextColor use textActor.textColor - // ignore SetSmoothEdge use textActor.smoothEdge - // ignore SetOutline use textActor.outLineEnable, outlineColor, thicknessWidth - // ignore SetGlow use textActor.glowEnable, glowColor, glowIntensity - // ignore SetShadow use textActor.shadowEnable, shadowColor, shadowOffset, shadowSize - // ignore SetItalics use textActor.italicsAngle ? - // ignore GetItalics @todo add italics flag? or just stick with angle - // ignore GetItalicsAngle use textActor.italicsAngle - // ignore SetUnderline use textActor.underline - // ignore GetUnderline use textActor.underline - // ignore SetWeight use textActor.weight - // ignore GetWeight use textActor.weight - // ignore SetFontDetectionAutomatic use textActor.fontDetectionAutomatic - // ignore IsFontDetectionAutomatic use textActor.fontDetectionAutomatic - // ignore GetLoadingState text is loaded synchronously - // ignore TextAvailableSignal text is loaded synchronously - - /************************************** - * Mesh Actor API (in order of mesh-actor.h) - **************************************/ - // @todo a version of MeshActor::New( mesh ) - // @todo a version of MeshActor::New( AnimatableMesh ) - // @todo SetMaterial - // @todo GetMaterial - // @todo BindBonesToMesh - - /************************************** * Camera Actor API (in order of camera.h) **************************************/ // ignore SetType use camera.type @@ -396,7 +282,10 @@ ActorWrapper::ActorWrapper( Actor actor, v8::Handle ActorWrapper::WrapActor(v8::Isolate* isolate, Actor actor ) { v8::EscapableHandleScope handleScope( isolate ); - v8::Local object = WrapActor( isolate, actor, GetActorType( actor.GetTypeName() ) ); + + // Check whether the actor is a Control + ActorWrapper::ActorType type = Toolkit::Control::DownCast(actor) ? ACTOR : GetActorType( actor.GetTypeName() ); + v8::Local object = WrapActor( isolate, actor, type ); return handleScope.Escape( object ); } @@ -462,7 +351,7 @@ v8::Handle ActorWrapper::MakeDaliActorTemplate( v8::Isolate* const ActorFunctions property = ActorFunctionTable[i]; // check to see if the actor supports a certain type of API - // e.g. ImageActor will support ACTOR_API, RENDERABLE_API and IMAGE_ACTOR_API + // e.g. Layer will support ACTOR_API and LAYER_API if( supportApis & property.api ) { std::string funcName = V8Utils::GetJavaScriptFunctionName( property.name); @@ -490,7 +379,7 @@ void ActorWrapper::NewActor( const v8::FunctionCallbackInfo< v8::Value >& args) return; } - // find out the callee function name...e.g. TextActor, ImageActor, MeshActor + // find out the callee function name...e.g. CameraActor v8::Local callee = args.Callee(); v8::Local v8String = callee->GetName(); std::string typeName = V8Utils::v8StringToStdString( v8String ); @@ -503,8 +392,44 @@ void ActorWrapper::NewActor( const v8::FunctionCallbackInfo< v8::Value >& args) args.GetReturnValue().Set( localObject ); } +void ActorWrapper::NewControl( 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; + } + + bool found( false ); + std::string controlName = V8Utils::GetStringParameter( PARAMETER_0, found, isolate, args ); + + if( !found ) + { + DALI_SCRIPT_EXCEPTION( isolate, "missing control name" ); + return; + } + Actor control; + Dali::TypeInfo typeInfo = Dali::TypeRegistry::Get().GetTypeInfo( controlName ); + if( typeInfo ) // handle, check if it has a value + { + Dali::BaseHandle handle = typeInfo.CreateInstance(); + if( handle ) + { + control = Actor::DownCast( handle ); + } + } + + v8::Local localObject = WrapActor( isolate, control, ACTOR ); + + args.GetReturnValue().Set( localObject ); +} + + /** - * given an actor type name, e.g. ImageActor returns the type, e.g. ActorWrapper::IMAGE_ACTOR + * given an actor type name, e.g. CameraActor returns the type, e.g. ActorWrapper::CAMERA_ACTOR */ ActorWrapper::ActorType ActorWrapper::GetActorType( const std::string& name ) {