JavaScript binding for new mesh APIs
[platform/core/uifw/dali-toolkit.git] / plugins / dali-script-v8 / src / actors / actor-wrapper.cpp
index 704c2d1..a462723 100644 (file)
@@ -20,6 +20,7 @@
 
 // EXTERNAL INCLUDES
 #include <dali/public-api/object/type-registry.h>
+#include <dali-toolkit/public-api/controls/control.h>
 
 // INTERNAL INCLUDES
 #include <actors/layer-api.h>
@@ -39,7 +40,6 @@ v8::Persistent<v8::ObjectTemplate> ActorWrapper::mActorTemplate;
 v8::Persistent<v8::ObjectTemplate> ActorWrapper::mImageActorTemplate;
 v8::Persistent<v8::ObjectTemplate> ActorWrapper::mCameraActorTemplate;
 v8::Persistent<v8::ObjectTemplate> ActorWrapper::mLayerActorTemplate;
-v8::Persistent<v8::ObjectTemplate> ActorWrapper::mTextLabelTemplate;
 
 namespace
 {
@@ -61,8 +61,7 @@ const ActorTemplate ActorTemplateLookup[]=
     { &ActorWrapper::mActorTemplate },        // ACTOR
     { &ActorWrapper::mImageActorTemplate },   // IMAGE_ACTOR
     { &ActorWrapper::mLayerActorTemplate },   // LAYER_ACTOR
-    { &ActorWrapper::mCameraActorTemplate},   // CAMERA_ACTOR
-    { &ActorWrapper::mTextLabelTemplate }
+    { &ActorWrapper::mCameraActorTemplate}    // CAMERA_ACTOR
 };
 
 /**
@@ -89,6 +88,7 @@ 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[]=
 {
@@ -96,8 +96,6 @@ const ActorApiStruct ActorApiLookup[]=
   {"ImageActor", ActorWrapper::IMAGE_ACTOR,  ImageActorApi::New,  ACTOR_API | IMAGE_ACTOR_API   },
   {"Layer",      ActorWrapper::LAYER_ACTOR,  LayerApi::New,       ACTOR_API | LAYER_API                                },
   {"CameraActor",ActorWrapper::CAMERA_ACTOR, CameraActorApi::New, ACTOR_API | CAMERA_ACTOR_API                         },
-  {"TextLabel",  ActorWrapper::TEXT_LABEL,   TextLabelApi::New,   ACTOR_API },
-
 };
 
 const unsigned int ActorApiLookupCount = sizeof(ActorApiLookup)/sizeof(ActorApiLookup[0]);
@@ -118,20 +116,8 @@ 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
   {
@@ -197,6 +183,9 @@ 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
     { "TranslateBy",         ActorApi::TranslateBy,              ACTOR_API },
@@ -238,6 +227,11 @@ const ActorFunctions ActorFunctionTable[]=
     { "SetKeyboardFocusable", ActorApi::SetKeyboardFocusable,  ACTOR_API }, //-- should this be a property???
     { "IsKeyboardFocusable" , ActorApi::IsKeyboardFocusable,   ACTOR_API }, //-- should this be a property???
 
+    { "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)
      **************************************/
@@ -271,8 +265,6 @@ const ActorFunctions ActorFunctionTable[]=
     // ignore GetNinePatchBorder use imageActor.border
     { "SetSortModifier",    ImageActorApi::SetSortModifier,   IMAGE_ACTOR_API  },
     { "GetSortModifier",    ImageActorApi::GetSortModifier,   IMAGE_ACTOR_API  },
-    { "SetCullFace",        ImageActorApi::SetCullFace,       IMAGE_ACTOR_API  },
-    { "GetCullFace",        ImageActorApi::GetCullFace,       IMAGE_ACTOR_API  },
     { "SetBlendMode",       ImageActorApi::SetBlendMode,      IMAGE_ACTOR_API  },
     { "GetBlendMode",       ImageActorApi::GetBlendMode,      IMAGE_ACTOR_API  },
     { "SetBlendFunc",       ImageActorApi::SetBlendFunc,      IMAGE_ACTOR_API  },
@@ -333,7 +325,10 @@ ActorWrapper::ActorWrapper( Actor actor,
 v8::Handle<v8::Object> ActorWrapper::WrapActor(v8::Isolate* isolate, Actor actor )
 {
   v8::EscapableHandleScope handleScope( isolate );
-  v8::Local<v8::Object> 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<v8::Object> object = WrapActor( isolate, actor, type );
 
   return handleScope.Escape( object );
 }
@@ -440,6 +435,42 @@ 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<v8::Object> 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
  */