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