1ae60ecd42a026367e2b300c6e0d6d7c628f6d77
[platform/core/uifw/dali-toolkit.git] / plugins / dali-script-v8 / src / actors / actor-api.cpp
1 /*
2  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 // CLASS HEADER
19 #include "actor-api.h"
20
21 // EXTERNAL INCLUDES
22 #include <dali-toolkit/public-api/controls/text-controls/text-label.h>
23
24 // INTERNAL INCLUDES
25 #include <v8-utils.h>
26 #include <actors/actor-wrapper.h>
27 #include <animation/path-constrainer-wrapper.h>
28 #include <rendering/renderer-wrapper.h>
29 #include <rendering/renderer-api.h>
30
31 namespace Dali
32 {
33
34 namespace V8Plugin
35 {
36
37 namespace  // unanmed namespace
38 {
39 Actor GetActor( v8::Isolate* isolate, const v8::FunctionCallbackInfo<v8::Value>& args )
40 {
41   HandleWrapper* handleWrapper = HandleWrapper::Unwrap( isolate, args.This() );
42   return Actor::DownCast( handleWrapper->mHandle );
43 }
44 } //unanmed namespace
45
46
47 namespace TextLabelApi
48 {
49  Actor New( const v8::FunctionCallbackInfo< v8::Value >& args )
50  {
51    return Dali::Toolkit::TextLabel::New();
52  }
53 }
54
55 /***************************************
56  * ACTOR API FUNCTIONS
57  ****************************************/
58 /**
59  * Constructor
60  *
61  * @for Actor
62  * @constructor
63  * @method Actor
64  * @return {Object} actor
65  */
66 Actor ActorApi::New( const v8::FunctionCallbackInfo< v8::Value >& args )
67 {
68   return Actor::New();
69 }
70
71 /**
72  * get the actors unique id
73  *
74  * @for Actor
75  * @method getId
76  * @return {Integer} id
77  */
78 void ActorApi::GetId( const v8::FunctionCallbackInfo<v8::Value>& args )
79 {
80   v8::Isolate* isolate = args.GetIsolate();
81   v8::HandleScope handleScope( isolate );
82   Actor actor = GetActor( isolate, args );
83
84   args.GetReturnValue().Set( v8::Integer::New( isolate, actor.GetId() ) );
85 }
86
87 /**
88  * Query whether an actor is the root actor, which is owned by the Stage
89  *
90  * @for Actor
91  * @method isRoot
92  * @return {Boolean} true if it is root
93  *
94  */
95 void ActorApi::IsRoot( const v8::FunctionCallbackInfo<v8::Value>& args )
96 {
97   v8::Isolate* isolate = args.GetIsolate();
98   v8::HandleScope handleScope( isolate );
99   Actor actor = GetActor( isolate, args );
100
101   args.GetReturnValue().Set( v8::Boolean::New( isolate, actor.IsRoot() ) );
102 }
103
104 /**
105  *
106  * Query whether the actor is connected to the Stage.
107  * When an actor is connected, it will be directly or indirectly parented to the root Actor.
108  * The root Actor is provided automatically by dali.stage, and is always considered to be connected.
109  *
110  * @for Actor
111  * @method onStage
112  * @return {Boolean} True if the actor is connected to the Stage
113  */
114 void ActorApi::OnStage( const v8::FunctionCallbackInfo<v8::Value>& args )
115 {
116   v8::Isolate* isolate = args.GetIsolate();
117   v8::HandleScope handleScope( isolate );
118   Actor actor = GetActor( isolate, args );
119
120   args.GetReturnValue().Set( v8::Boolean::New( isolate, actor.OnStage() ) );
121 }
122
123 /**
124  * Query whether an actor is a layer
125  *
126  * @for Actor
127  * @method isLayer
128  * @return {Boolean} true if it is a layer
129  */
130 void ActorApi::IsLayer( const v8::FunctionCallbackInfo<v8::Value>& args )
131 {
132   v8::Isolate* isolate = args.GetIsolate();
133   v8::HandleScope handleScope( isolate );
134   Actor actor = GetActor( isolate, args );
135
136   args.GetReturnValue().Set( v8::Boolean::New( isolate, actor.IsLayer() ) );
137 }
138
139 /**
140  * Gets the layer in which the actor is present.
141  *
142  * @for Actor
143  * @method getLayer
144  * @return {Object} Layer
145  */
146 void ActorApi::GetLayer( const v8::FunctionCallbackInfo<v8::Value>& args )
147 {
148   v8::Isolate* isolate = args.GetIsolate();
149   v8::HandleScope handleScope( isolate );
150   Actor actor = GetActor( isolate, args );
151   Layer layer = actor.GetLayer();
152   if( layer ) // actors don't always have a layer
153   {
154     v8::Handle < v8::Object > wrappedLayer = ActorWrapper::ActorWrapper::WrapActor( isolate, layer, ActorWrapper::LAYER_ACTOR );
155     args.GetReturnValue().Set( wrappedLayer );
156   }
157   // else return an empty object
158 }
159
160 /**
161  * Adds a child Actor to this Actor.
162  *
163  * NOTE! if the child already has a parent, it will be removed from old parent
164  * and reparented to this actor. This may change childs position, color, shader effect,
165  * scale etc as it now inherits them from this actor
166  *
167  * Pre-conditions
168  * - The child actor is not the same as the parent actor.
169  * - The actor is not the Root actor
170
171  * Once added The child will be referenced by its parent. This means that the child will be kept alive,
172  * even if the handle passed into this method is reset or destroyed.
173  *
174  * @for Actor
175  * @method add
176  * @param {Object} Actor
177  */
178 void ActorApi::AddActor( const v8::FunctionCallbackInfo<v8::Value>& args )
179 {
180   v8::Isolate* isolate = args.GetIsolate();
181   v8::HandleScope handleScope( isolate );
182   Actor parent = GetActor( isolate, args );
183   bool found(false);
184   Actor child = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
185   if( found )
186   {
187     parent.Add( child );
188   }
189   else
190   {
191     DALI_SCRIPT_EXCEPTION( isolate, "child parameter missing" );
192   }
193 }
194
195 /**
196  * Removes a child Actor from this Actor.
197  *
198  * If the actor was not a child of this actor, this is a no-op.
199  *
200  * Preconditions:
201  * -  The child actor is not the same as the parent actor.
202  *
203  * @for Actor
204  * @param{Object} Actor the child actor
205  * @method Remove
206  */
207 void ActorApi::RemoveActor( const v8::FunctionCallbackInfo<v8::Value>& args )
208 {
209   v8::Isolate* isolate = args.GetIsolate();
210   v8::HandleScope handleScope( isolate );
211   Actor parent = GetActor( isolate, args );
212   bool found( false );
213   Actor child = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
214
215   if( found )
216   {
217     parent.Remove( child );
218   }
219   else
220   {
221     DALI_SCRIPT_EXCEPTION( isolate, "child parameter missing" );
222   }
223 }
224
225 /**
226  * Checks whether an Actor is equal to this Actor.
227  *
228  * @for Actor
229  * @method iIsEqualTo
230  * @param {Object} Actor
231  */
232 void ActorApi::IsEqualTo( const v8::FunctionCallbackInfo<v8::Value>& args )
233 {
234   v8::Isolate* isolate = args.GetIsolate();
235   v8::HandleScope handleScope( isolate );
236   Actor self = GetActor( isolate, args );
237   bool found( false );
238
239   Actor actor = V8Utils::GetActorParameter( PARAMETER_0, found, isolate, args );
240   if( found )
241   {
242     args.GetReturnValue().Set( v8::Boolean::New( isolate, (actor == self) ) );
243   }
244   else
245   {
246     DALI_SCRIPT_EXCEPTION( isolate, "actor parameter missing" );
247   }
248 }
249
250 /** Removes an actor from its parent.
251  *
252  * If the actor has no parent, this method does nothing.
253  *
254  * @for Actor
255  * @method Unparent
256  */
257 void ActorApi::Unparent( const v8::FunctionCallbackInfo< v8::Value >& args)
258 {
259   v8::Isolate* isolate = args.GetIsolate();
260   v8::HandleScope handleScope( isolate );
261   Actor actor = GetActor( isolate, args );
262   actor.Unparent();
263 }
264
265 /**
266  * get number of child actors
267  *
268  * @for Actor
269  * @method getChildCount
270  * @return {Integer} count
271  */
272 void ActorApi::GetChildCount( const v8::FunctionCallbackInfo<v8::Value>& args )
273 {
274   v8::Isolate* isolate = args.GetIsolate();
275   v8::HandleScope handleScope( isolate );
276   Actor actor = GetActor( isolate, args );
277
278   args.GetReturnValue().Set( v8::Integer::New( isolate, actor.GetChildCount() ) );
279 }
280
281 /**
282  * Retrieve and child actor by index.
283  *
284  * @for Actor
285  * @method getChildAt
286  * @param {Integer} actor index
287  * @return {Object} actor on success, empty actor handle if not found
288  */
289 void ActorApi::GetChildAt( const v8::FunctionCallbackInfo<v8::Value>& args )
290 {
291   v8::Isolate* isolate = args.GetIsolate();
292   v8::HandleScope handleScope( isolate );
293   Actor parent = GetActor( isolate, args );
294   bool found( false );
295   int id = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
296   if( !found )
297   {
298     DALI_SCRIPT_EXCEPTION( isolate, "Integer parameter missing" );
299     return;
300   }
301   Actor childActor = parent.GetChildAt( id );
302   if( childActor )
303   {
304     // wrap the child
305     v8::Handle < v8::Object > wrappedActor = ActorWrapper::WrapActor( isolate, childActor );
306     args.GetReturnValue().Set( wrappedActor );
307   }
308 }
309
310 /**
311  * Search through this actor's hierarchy for an actor with the given name
312  * The actor itself is also considered in the search
313  *
314  * @for Actor
315  * @method findChildByName
316  * @param {String} actor name
317  * @return {Object} actor on success, empty actor handle if not found
318  */
319 void ActorApi::FindChildByName( const v8::FunctionCallbackInfo<v8::Value>& args )
320 {
321   v8::Isolate* isolate = args.GetIsolate();
322   v8::HandleScope handleScope( isolate );
323   Actor parent = GetActor( isolate, args );
324   bool found( false );
325   std::string name = V8Utils::GetStringParameter( PARAMETER_0, found, isolate, args );
326   if( !found )
327   {
328     DALI_SCRIPT_EXCEPTION( isolate, "string parameter missing" );
329     return;
330   }
331   Actor childActor = parent.FindChildByName( name );
332   if( childActor )
333   {
334     // wrap the child
335     v8::Handle < v8::Object > wrappedLayer = ActorWrapper::WrapActor( isolate, childActor );
336     args.GetReturnValue().Set( wrappedLayer );
337   }
338 }
339
340 /**
341  * Search through this actor's hierarchy for an actor with the given unique ID.
342  * The actor itself is also considered in the search
343  *
344  * @for Actor
345  * @method findChildById
346  * @param {Integer} id
347  * @return {Object} actor on success, empty actor handle if not found
348  */
349 void ActorApi::FindChildById( const v8::FunctionCallbackInfo<v8::Value>& args )
350 {
351   v8::Isolate* isolate = args.GetIsolate();
352   v8::HandleScope handleScope( isolate );
353   Actor parent = GetActor( isolate, args );
354
355   bool found( false );
356   int id = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
357   if( !found )
358   {
359     DALI_SCRIPT_EXCEPTION( isolate, "Integer parameter missing" );
360     return;
361   }
362   Actor childActor = parent.FindChildById( id );
363   if( childActor )
364   {
365     // wrap the child
366     v8::Local < v8::Object > wrappedLayer = ActorWrapper::WrapActor( isolate, childActor );
367     args.GetReturnValue().Set( wrappedLayer );
368   }
369 }
370
371
372 /**
373  * retrieve the actor's parent.
374  *
375  * @for Actor
376  * @method getParent
377  * @return {Object} actor on success, empty actor handle if actor has no parent
378  */
379 void ActorApi::GetParent( const v8::FunctionCallbackInfo<v8::Value>& args )
380 {
381   v8::Isolate* isolate = args.GetIsolate();
382   v8::HandleScope handleScope( isolate );
383   Actor actor = GetActor( isolate, args );
384   Actor parent = actor.GetParent();
385
386   if( parent )
387   {
388     v8::Local < v8::Object > wrappedLayer = ActorWrapper::WrapActor( isolate, parent );
389     args.GetReturnValue().Set( wrappedLayer );
390   }
391 }
392 /**
393  * Converts screen coordinates into the actor's coordinate system using the default camera.
394  *
395  * The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
396  *
397  * @example
398  *    var local = actor.screenToLocal( [ 10, 53 ]);
399  *    var xPos = local.x;
400  *    var yPos = local.y;
401  *
402  *
403  * @for Actor
404  * @method screenToLocal
405  * @param {Object}  ScreenCoordinates array of 2 objects
406  * @return {Object} local coordinates object with x,y properties
407  */
408 void ActorApi::ScreenToLocal( const v8::FunctionCallbackInfo<v8::Value>& args )
409 {
410   v8::Isolate* isolate = args.GetIsolate();
411   v8::HandleScope handleScope( isolate );
412   Actor actor = GetActor( isolate, args );
413
414   //ool ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const;
415   bool found( false );
416
417   int argCount( args.Length() );
418   Vector2 vector;
419
420   if( argCount == 1 )
421   {
422     vector = V8Utils::GetVector2Parameter( PARAMETER_0, found, isolate, args );
423     if( !found )
424     {
425       DALI_SCRIPT_EXCEPTION( isolate, "invalid parameters (x,y)" );
426       return;
427     }
428   }
429   else
430   {
431     DALI_SCRIPT_EXCEPTION( isolate, "invalid parameters (x,y)" );
432     return;
433   }
434   float localX, localY;
435   actor.ScreenToLocal( localX, localY, vector.x, vector.y );
436
437   v8::Local < v8::Object > localCoordinates = v8::Object::New( isolate );
438
439   localCoordinates->Set( v8::String::NewFromUtf8( isolate, "x" ), v8::Number::New( isolate, localX ) );
440   localCoordinates->Set( v8::String::NewFromUtf8( isolate, "y" ), v8::Number::New( isolate, localY ) );
441
442   args.GetReturnValue().Set( localCoordinates );
443
444 }
445
446 /**
447  * Sets whether the actor should be focusable by keyboard navigation.
448  *
449  * @for Actor
450  * @method setKeyboardFocusable
451  * @param {Boolean}  folcusable
452  */
453 void ActorApi::SetKeyboardFocusable( const v8::FunctionCallbackInfo<v8::Value>& args )
454 {
455   v8::Isolate* isolate = args.GetIsolate();
456   v8::HandleScope handleScope( isolate );
457   Actor actor = GetActor( isolate, args );
458   bool parameterFound( false );
459   bool focus = V8Utils::GetBooleanParameter( PARAMETER_0, parameterFound, isolate, args );
460   if( !parameterFound )
461   {
462     DALI_SCRIPT_EXCEPTION( isolate, "boolean parameter missing" );
463     return;
464   }
465
466   actor.SetKeyboardFocusable( focus );
467 }
468
469 /**
470  * Returns whether the actor is focusable by keyboard navigation.
471  *
472  *
473  * @for Actor
474  * @method isKeyboardFocusable
475  * @return {Boolean}  folcusable
476  */
477 void ActorApi::IsKeyboardFocusable( const v8::FunctionCallbackInfo<v8::Value>& args )
478 {
479   v8::Isolate* isolate = args.GetIsolate();
480   v8::HandleScope handleScope( isolate );
481   Actor actor = GetActor( isolate, args );
482
483   args.GetReturnValue().Set( v8::Boolean::New( isolate, actor.IsKeyboardFocusable() ) );
484
485 }
486 /**
487  * retrieve the actor type
488  *
489  * @for Actor
490  * @method getActorType
491  * @return {String} Actor, ImageActor, MeshActor, Layer, CameraActor ...
492  */
493 void ActorApi::GetActorType( const v8::FunctionCallbackInfo<v8::Value>& args )
494 {
495   v8::Isolate* isolate = args.GetIsolate();
496   v8::HandleScope handleScope( isolate );
497   Actor actor = GetActor( isolate, args );
498
499   std::string name = actor.GetTypeName();
500   v8::Local < v8::String > v8String = v8::String::NewFromUtf8( isolate, name.c_str() );
501   args.GetReturnValue().Set( v8String );
502 }
503 /**
504  * Return the natural size of the actor.
505  *
506  * @for Actor
507  * @method getNaturalSize
508  * @return {Object} { x, y, z }
509  */
510 void ActorApi::GetNaturalSize( const v8::FunctionCallbackInfo<v8::Value>& args )
511 {
512   v8::Isolate* isolate = args.GetIsolate();
513   v8::HandleScope handleScope( isolate );
514   Actor actor = GetActor( isolate, args );
515
516   Vector3 size( actor.GetNaturalSize() );
517
518   v8::Local<v8::Object> sizeObject = v8::Object::New( isolate );
519
520   sizeObject->Set( v8::String::NewFromUtf8( isolate, "x" ), v8::Integer::New( isolate, size.width ) );
521   sizeObject->Set( v8::String::NewFromUtf8( isolate, "y" ), v8::Integer::New( isolate, size.height ) );
522   sizeObject->Set( v8::String::NewFromUtf8( isolate, "z" ), v8::Integer::New( isolate, size.depth ) );
523
524   args.GetReturnValue().Set( sizeObject );
525 }
526
527 /**
528  *  Calculate the width of the actor given a height
529  *
530  * The natural size is used for default calculation.
531  * size 0 is treated as aspect ratio 1:1.
532  * @for Actor
533  * @method getWidthForHeight
534  * @param {Float} height to use
535  * @return {Float} Return the width based on the height
536  * @example
537  *   myTextLabel.getWidthForHeight(40);
538  *
539  * // DALi uses this formula internally
540  * // width = naturalSize.width * height / naturalSize.height;
541  *
542  *
543  */
544 void ActorApi::GetWidthForHeight( const v8::FunctionCallbackInfo<v8::Value>& args )
545 {
546   v8::Isolate* isolate = args.GetIsolate();
547   v8::HandleScope handleScope( isolate );
548   Actor actor = GetActor( isolate, args );
549
550   bool found;
551   float height = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 0.f );
552   if( !found )
553   {
554     DALI_SCRIPT_EXCEPTION( isolate, "missing height parameter");
555     return;
556   }
557   args.GetReturnValue().Set( v8::Number::New( isolate, actor.GetWidthForHeight( height ) ) );
558 }
559
560 /**
561  *  Calculate the height of the actor given a width
562  *
563  * The natural size is used for default calculation.
564  * size 0 is treated as aspect ratio 1:1.
565  * @for Actor
566  * @method getHeightForWidth
567  * @param {Float} width to use
568  * @return {Float} Return the height based on the width
569  * @example
570  *   myTextLabel.getHeightForWidth(250);
571  *
572  * // DALi uses this formula internally
573  * // height = naturalSize.height * width / naturalSize.width
574  */
575 void ActorApi::GetHeightForWidth( const v8::FunctionCallbackInfo<v8::Value>& args )
576 {
577   v8::Isolate* isolate = args.GetIsolate();
578   v8::HandleScope handleScope( isolate );
579   Actor actor = GetActor( isolate, args );
580
581   bool found;
582   float width = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 0.f );
583   if( !found )
584   {
585     DALI_SCRIPT_EXCEPTION( isolate, "missing width parameter");
586     return;
587   }
588   args.GetReturnValue().Set( v8::Number::New( isolate, actor.GetHeightForWidth( width ) ) );
589 }
590 /**
591  * Move an actor relative to its existing position.
592  * @example
593  *
594  *    // using an array
595  *    actor.translateBy( [20,40,0] );
596  *
597  * @for Actor
598  * @method translateBy
599  * @param {object} an array of 3 numbers
600  */
601 void ActorApi::TranslateBy( const v8::FunctionCallbackInfo<v8::Value>& args )
602 {
603   v8::Isolate* isolate = args.GetIsolate();
604   v8::HandleScope handleScope( isolate );
605   Actor actor = GetActor( isolate, args );
606
607   //Get displacement vector
608   Vector3 vector;
609   int argCount( args.Length() );
610   if( argCount == 1 )
611   {
612     bool found(false);
613     vector = V8Utils::GetVector3Parameter( PARAMETER_0, found, isolate, args );
614     if( !found )
615     {
616       DALI_SCRIPT_EXCEPTION( isolate, "Vector3 move parameter missing" );
617       return;
618     }
619   }
620   else
621   {
622     DALI_SCRIPT_EXCEPTION( isolate, "Vector3 move parameter missing" );
623     return;
624   }
625   actor.TranslateBy( vector );
626
627 }
628
629
630 /**
631  * Apply a relative rotation to an actor.
632  * @example
633  *
634  *     var rotation =new dali.Rotation( pitch, roll, yaw );
635  *     actor.rotateBy( rotation );
636  *
637  * @for Actor
638  * @method rotateBy
639  * @param {object} dali rotation object
640  */
641 void ActorApi::RotateBy( const v8::FunctionCallbackInfo<v8::Value>& args )
642 {
643   v8::Isolate* isolate = args.GetIsolate();
644   v8::HandleScope handleScope( isolate );
645   Actor actor = GetActor( isolate, args );
646
647   bool found( false );
648   Property::Value rotation = V8Utils::GetPropertyValueParameter( PARAMETER_0, found, isolate, args );
649
650   if( rotation.GetType() != Property::ROTATION )
651   {
652     DALI_SCRIPT_EXCEPTION( isolate, "Rotation parameter missing" );
653     return;
654   }
655   // the rotation parameter has to be either a AngleAxis or a Quaternion
656   // both will work when calling Get( Quaternion);
657
658   Quaternion quaternionValue;
659   rotation.Get( quaternionValue );
660
661   actor.RotateBy( quaternionValue );
662 }
663
664 /**
665  * Apply a relative scale to an actor.
666  * @example
667  *    // Double actor width and height ( keep depth the same )
668  *    // using an array
669  *    actor.scaleBy( [2,2,1] );
670  *
671  *
672  * @for Actor
673  * @method scaleBy
674  * @param {object} JavaScript array
675  */
676 void ActorApi::ScaleBy( const v8::FunctionCallbackInfo<v8::Value>& args )
677 {
678   v8::Isolate* isolate = args.GetIsolate();
679   v8::HandleScope handleScope( isolate );
680   Actor actor = GetActor( isolate, args );
681
682   Vector3 vector;
683   int argCount( args.Length() );
684   if( argCount == 1 )
685   {
686     bool found(false);
687     vector = V8Utils::GetVector3Parameter( PARAMETER_0, found, isolate, args );
688     if( !found )
689     {
690       DALI_SCRIPT_EXCEPTION( isolate, "Vector3 move parameter missing" );
691       return;
692     }
693   }
694   else
695   {
696     DALI_SCRIPT_EXCEPTION( isolate, "Vector3 parameter missing" );
697     return;
698   }
699   actor.ScaleBy( vector );
700 }
701
702 /**
703  * Add a renderer to this actor.
704  * @example
705  *
706  *     var renderer = new dali.Renderer( geometry, material );
707  *     actor.addRenderer( renderer );
708  *
709  * @for Actor
710  * @method addRenderer
711  * @param {object} renderer Renderer to add to the actor
712  * @return {integer} The index of the Renderer that was added
713  */
714 void ActorApi::AddRenderer( const v8::FunctionCallbackInfo<v8::Value>& args )
715 {
716   v8::Isolate* isolate = args.GetIsolate();
717   v8::HandleScope handleScope( isolate );
718   Actor actor = GetActor( isolate, args );
719
720   unsigned int index = 0;
721
722   bool found( false );
723   Renderer renderer = RendererApi::GetRendererFromParams( 0, found, isolate, args );
724   if( found )
725   {
726     index = actor.AddRenderer(renderer);
727   }
728   else
729   {
730     DALI_SCRIPT_EXCEPTION( isolate, "Renderer parameter missing" );
731     return;
732   }
733
734   args.GetReturnValue().Set( v8::Integer::New( isolate, index ) );
735 }
736
737 /**
738  * Get the number of renderers on this actor.
739  * @example
740  *
741  *     var count = actor.getRendererCount();
742  *
743  * @for Actor
744  * @method getRendererCount
745  * @return {integer} the number of renderers on this actor
746  */
747 void ActorApi::GetRendererCount( const v8::FunctionCallbackInfo<v8::Value>& args )
748 {
749   v8::Isolate* isolate = args.GetIsolate();
750   v8::HandleScope handleScope( isolate );
751
752   Actor actor = GetActor( isolate, args );
753   args.GetReturnValue().Set( v8::Integer::New( isolate, actor.GetRendererCount() ) );
754 }
755
756 /**
757  * Get a Renderer by index.
758  * @example
759  *
760  *     var renderer = actor.getRendererAt( 0 );
761  *
762  * @for Actor
763  * @method getRendererAt
764  * @param {integer} index The index of the renderer to fetch, which must be between 0 and getRendererCount()-1
765  * @return {object} The renderer at the specified index
766  */
767 void ActorApi::GetRendererAt( const v8::FunctionCallbackInfo<v8::Value>& args )
768 {
769   v8::Isolate* isolate = args.GetIsolate();
770   v8::HandleScope handleScope( isolate );
771   Actor actor = GetActor( isolate, args );
772
773   Renderer renderer;
774
775   bool found( false );
776   int index = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0);
777   if( !found )
778   {
779     DALI_SCRIPT_EXCEPTION( isolate, "invalid index parameter" );
780     return;
781   }
782   else
783   {
784     renderer = actor.GetRendererAt(static_cast<unsigned int>(index));
785     if( !renderer )
786     {
787       DALI_SCRIPT_EXCEPTION( isolate, "renderer not found" );
788       return;
789     }
790   }
791
792   // Wrap the renderer
793   v8::Local<v8::Object> localObject = RendererWrapper::WrapRenderer( isolate, renderer );
794   args.GetReturnValue().Set( localObject );
795 }
796
797 /**
798  * Remove an renderer from the actor by index.
799  * @example
800  *
801  *     actor.removeRenderer( 0 );
802  *
803  * @for Actor
804  * @method removeRenderer
805  * @param {integer} index Index of the renderer to be removed, which must be between 0 and getRendererCount()-1
806  */
807 void ActorApi::RemoveRenderer( const v8::FunctionCallbackInfo<v8::Value>& args )
808 {
809   v8::Isolate* isolate = args.GetIsolate();
810   v8::HandleScope handleScope( isolate );
811   Actor actor = GetActor( isolate, args );
812
813   bool found( false );
814   int index = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0);
815   if( !found )
816   {
817     DALI_SCRIPT_EXCEPTION( isolate, "invalid index parameter" );
818   }
819   else
820   {
821     actor.RemoveRenderer(static_cast<unsigned int>(index));
822   }
823 }
824
825
826 } // namespace V8Plugin
827
828 } // namespace Dali