DALi Version 1.1.30
[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  * Return the value of negotiated dimension for the given dimension
522  *
523  * @for Actor
524  * @method getRelayoutSize
525  * @param {Integer} dimension The dimension of layout to retrieve (either dali.DIMENSION_WIDTH or dali.DIMENSION_HEIGHT)
526  * @return {Number} The value of the negotiated dimension
527  */
528 void ActorApi::GetRelayoutSize( const v8::FunctionCallbackInfo<v8::Value>& args )
529 {
530   v8::Isolate* isolate = args.GetIsolate();
531   v8::HandleScope handleScope( isolate );
532   Actor actor = GetActor( isolate, args );
533
534   bool found;
535   int dimension = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0 );
536   if( !found )
537   {
538     DALI_SCRIPT_EXCEPTION( isolate, "missing dimension parameter");
539     return;
540   }
541
542   args.GetReturnValue().Set( v8::Number::New( isolate, actor.GetRelayoutSize( static_cast<Dimension::Type>(dimension) ) ) );
543 }
544
545 /**
546  *  Calculate the width of the actor given a height
547  *
548  * The natural size is used for default calculation.
549  * size 0 is treated as aspect ratio 1:1.
550  * @for Actor
551  * @method getWidthForHeight
552  * @param {Float} height to use
553  * @return {Float} Return the width based on the height
554  * @example
555  *   myTextLabel.getWidthForHeight(40);
556  *
557  * // DALi uses this formula internally
558  * // width = naturalSize.width * height / naturalSize.height;
559  *
560  *
561  */
562 void ActorApi::GetWidthForHeight( const v8::FunctionCallbackInfo<v8::Value>& args )
563 {
564   v8::Isolate* isolate = args.GetIsolate();
565   v8::HandleScope handleScope( isolate );
566   Actor actor = GetActor( isolate, args );
567
568   bool found;
569   float height = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 0.f );
570   if( !found )
571   {
572     DALI_SCRIPT_EXCEPTION( isolate, "missing height parameter");
573     return;
574   }
575   args.GetReturnValue().Set( v8::Number::New( isolate, actor.GetWidthForHeight( height ) ) );
576 }
577
578 /**
579  *  Calculate the height of the actor given a width
580  *
581  * The natural size is used for default calculation.
582  * size 0 is treated as aspect ratio 1:1.
583  * @for Actor
584  * @method getHeightForWidth
585  * @param {Float} width to use
586  * @return {Float} Return the height based on the width
587  * @example
588  *   myTextLabel.getHeightForWidth(250);
589  *
590  * // DALi uses this formula internally
591  * // height = naturalSize.height * width / naturalSize.width
592  */
593 void ActorApi::GetHeightForWidth( const v8::FunctionCallbackInfo<v8::Value>& args )
594 {
595   v8::Isolate* isolate = args.GetIsolate();
596   v8::HandleScope handleScope( isolate );
597   Actor actor = GetActor( isolate, args );
598
599   bool found;
600   float width = V8Utils::GetFloatParameter( PARAMETER_0, found, isolate, args, 0.f );
601   if( !found )
602   {
603     DALI_SCRIPT_EXCEPTION( isolate, "missing width parameter");
604     return;
605   }
606   args.GetReturnValue().Set( v8::Number::New( isolate, actor.GetHeightForWidth( width ) ) );
607 }
608 /**
609  * Move an actor relative to its existing position.
610  * @example
611  *
612  *    // using an array
613  *    actor.translateBy( [20,40,0] );
614  *
615  * @for Actor
616  * @method translateBy
617  * @param {object} an array of 3 numbers
618  */
619 void ActorApi::TranslateBy( const v8::FunctionCallbackInfo<v8::Value>& args )
620 {
621   v8::Isolate* isolate = args.GetIsolate();
622   v8::HandleScope handleScope( isolate );
623   Actor actor = GetActor( isolate, args );
624
625   //Get displacement vector
626   Vector3 vector;
627   int argCount( args.Length() );
628   if( argCount == 1 )
629   {
630     bool found(false);
631     vector = V8Utils::GetVector3Parameter( PARAMETER_0, found, isolate, args );
632     if( !found )
633     {
634       DALI_SCRIPT_EXCEPTION( isolate, "Vector3 move parameter missing" );
635       return;
636     }
637   }
638   else
639   {
640     DALI_SCRIPT_EXCEPTION( isolate, "Vector3 move parameter missing" );
641     return;
642   }
643   actor.TranslateBy( vector );
644
645 }
646
647
648 /**
649  * Apply a relative rotation to an actor.
650  * @example
651  *
652  *     var rotation =new dali.Rotation( pitch, roll, yaw );
653  *     actor.rotateBy( rotation );
654  *
655  * @for Actor
656  * @method rotateBy
657  * @param {object} dali rotation object
658  */
659 void ActorApi::RotateBy( const v8::FunctionCallbackInfo<v8::Value>& args )
660 {
661   v8::Isolate* isolate = args.GetIsolate();
662   v8::HandleScope handleScope( isolate );
663   Actor actor = GetActor( isolate, args );
664
665   bool found( false );
666   Property::Value rotation = V8Utils::GetPropertyValueParameter( PARAMETER_0, found, isolate, args );
667
668   if( rotation.GetType() != Property::ROTATION )
669   {
670     DALI_SCRIPT_EXCEPTION( isolate, "Rotation parameter missing" );
671     return;
672   }
673   // the rotation parameter has to be either a AngleAxis or a Quaternion
674   // both will work when calling Get( Quaternion);
675
676   Quaternion quaternionValue;
677   rotation.Get( quaternionValue );
678
679   actor.RotateBy( quaternionValue );
680 }
681
682 /**
683  * Apply a relative scale to an actor.
684  * @example
685  *    // Double actor width and height ( keep depth the same )
686  *    // using an array
687  *    actor.scaleBy( [2,2,1] );
688  *
689  *
690  * @for Actor
691  * @method scaleBy
692  * @param {object} JavaScript array
693  */
694 void ActorApi::ScaleBy( const v8::FunctionCallbackInfo<v8::Value>& args )
695 {
696   v8::Isolate* isolate = args.GetIsolate();
697   v8::HandleScope handleScope( isolate );
698   Actor actor = GetActor( isolate, args );
699
700   Vector3 vector;
701   int argCount( args.Length() );
702   if( argCount == 1 )
703   {
704     bool found(false);
705     vector = V8Utils::GetVector3Parameter( PARAMETER_0, found, isolate, args );
706     if( !found )
707     {
708       DALI_SCRIPT_EXCEPTION( isolate, "Vector3 move parameter missing" );
709       return;
710     }
711   }
712   else
713   {
714     DALI_SCRIPT_EXCEPTION( isolate, "Vector3 parameter missing" );
715     return;
716   }
717   actor.ScaleBy( vector );
718 }
719
720 /**
721  * Add a renderer to this actor.
722  * @example
723  *
724  *     var renderer = new dali.Renderer( geometry, material );
725  *     actor.addRenderer( renderer );
726  *
727  * @for Actor
728  * @method addRenderer
729  * @param {object} renderer Renderer to add to the actor
730  * @return {integer} The index of the Renderer that was added
731  */
732 void ActorApi::AddRenderer( const v8::FunctionCallbackInfo<v8::Value>& args )
733 {
734   v8::Isolate* isolate = args.GetIsolate();
735   v8::HandleScope handleScope( isolate );
736   Actor actor = GetActor( isolate, args );
737
738   unsigned int index = 0;
739
740   bool found( false );
741   Renderer renderer = RendererApi::GetRendererFromParams( 0, found, isolate, args );
742   if( found )
743   {
744     index = actor.AddRenderer(renderer);
745   }
746   else
747   {
748     DALI_SCRIPT_EXCEPTION( isolate, "Renderer parameter missing" );
749     return;
750   }
751
752   args.GetReturnValue().Set( v8::Integer::New( isolate, index ) );
753 }
754
755 /**
756  * Get the number of renderers on this actor.
757  * @example
758  *
759  *     var count = actor.getRendererCount();
760  *
761  * @for Actor
762  * @method getRendererCount
763  * @return {integer} the number of renderers on this actor
764  */
765 void ActorApi::GetRendererCount( const v8::FunctionCallbackInfo<v8::Value>& args )
766 {
767   v8::Isolate* isolate = args.GetIsolate();
768   v8::HandleScope handleScope( isolate );
769
770   Actor actor = GetActor( isolate, args );
771   args.GetReturnValue().Set( v8::Integer::New( isolate, actor.GetRendererCount() ) );
772 }
773
774 /**
775  * Get a Renderer by index.
776  * @example
777  *
778  *     var renderer = actor.getRendererAt( 0 );
779  *
780  * @for Actor
781  * @method getRendererAt
782  * @param {integer} index The index of the renderer to fetch, which must be between 0 and getRendererCount()-1
783  * @return {object} The renderer at the specified index
784  */
785 void ActorApi::GetRendererAt( const v8::FunctionCallbackInfo<v8::Value>& args )
786 {
787   v8::Isolate* isolate = args.GetIsolate();
788   v8::HandleScope handleScope( isolate );
789   Actor actor = GetActor( isolate, args );
790
791   Renderer renderer;
792
793   bool found( false );
794   int index = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0);
795   if( !found )
796   {
797     DALI_SCRIPT_EXCEPTION( isolate, "invalid index parameter" );
798     return;
799   }
800   else
801   {
802     renderer = actor.GetRendererAt(static_cast<unsigned int>(index));
803     if( !renderer )
804     {
805       DALI_SCRIPT_EXCEPTION( isolate, "renderer not found" );
806       return;
807     }
808   }
809
810   // Wrap the renderer
811   v8::Local<v8::Object> localObject = RendererWrapper::WrapRenderer( isolate, renderer );
812   args.GetReturnValue().Set( localObject );
813 }
814
815 /**
816  * Remove an renderer from the actor by index.
817  * @example
818  *
819  *     actor.removeRenderer( 0 );
820  *
821  * @for Actor
822  * @method removeRenderer
823  * @param {integer} index Index of the renderer to be removed, which must be between 0 and getRendererCount()-1
824  */
825 void ActorApi::RemoveRenderer( const v8::FunctionCallbackInfo<v8::Value>& args )
826 {
827   v8::Isolate* isolate = args.GetIsolate();
828   v8::HandleScope handleScope( isolate );
829   Actor actor = GetActor( isolate, args );
830
831   bool found( false );
832   int index = V8Utils::GetIntegerParameter( PARAMETER_0, found, isolate, args, 0);
833   if( !found )
834   {
835     DALI_SCRIPT_EXCEPTION( isolate, "invalid index parameter" );
836   }
837   else
838   {
839     actor.RemoveRenderer(static_cast<unsigned int>(index));
840   }
841 }
842
843
844 } // namespace V8Plugin
845
846 } // namespace Dali