Add more shared C++/JavaScript docs and add JavaScript wrapping guide
[platform/core/uifw/dali-toolkit.git] / plugins / dali-script-v8 / docs / content / actor.js
1 /**
2  *
3  ## Actor API
4
5   Actor is the primary object with which Dali applications interact. UI controls can be built by combining multiple actors.
6
7   There are different types of Actors supported by Dali. They all have the same
8   base functionality of the actor class.
9
10 ```
11 var actor = new dali.Actor();
12 var imageActor = new dali.ImageActor();
13 var textActor = new dali.TextActor("hello world");
14 var meshActor = new dali.MeshActor();
15 var camera = new dali.CameraActor();
16 var layer = new dali.Layer();
17 ```
18
19 ### Hello world example
20 ```
21 var myActor = new dali.TextActor("hello-world");
22
23 myActor.name = "my first actor";
24 myActor.color = [ 1, 0, 0, 1];    // Red,Green,Blue, Alpha ( 1 == max, 0 = none )
25 myActor.scale = [ 2, 2, 1];      // double the width and height
26
27 // by default an actor is anchored to the top-left of it's parent actor
28 // change it to the middle
29
30 myActor.parentOrigin = [0.5,0.5,0.5];
31
32 // add to the stage
33 dali.stage.add( myActor );
34 ```
35
36
37 ### Positioning Actors
38
39 An actor inherits its parent's position.  The relative position between the actor & parent is determined by 3 properties:
40
41 1) ParentOrigin.  This Vector3 property defines a point within the parent actor's area.
42
43 ![ ](../assets/img/parent-origin.png)
44
45
46 The default is "top-left", which can be visualized in 2D as (0, 0), but is actually Vector3(0, 0, 0.5) in the 3D DALi world.  The actor's position is relative to this point.
47 ```
48 // to change parent origin to the centre
49 myActor.parentOrigin = [0.5, 0.5, 0.5];
50 ```
51
52 2) AnchorPoint.  This Vector3 property defines a point within the child actor's area.
53
54 ![ ](../assets/img/anchor-point.png)
55
56 The default is "center", which can be visualized in 2D as (0.5, 0.5), but is actually Vector3(0.5, 0.5, 0.5) in the 3D DALi world.  The actor's position is also relative to this point.
57 ```
58 // setting anchor point to the centre
59 myActor.anchorPoint = [0.5, 0.5, 0.5];
60 ```
61
62 3) Position.  This is the position vector between the parent-origin and anchor-point.
63
64 ![ ](../assets/img/actor-position.png)
65
66 Therefore by default, an actors position is the distance between its center and the top-left corner of its parent.
67
68 An actor added directly to the stage with position (X = stageWidth*0.5, Y = stageHeight*0.5), would appear in the center of the screen.  Likewise an actor with position (X = actorWidth*0.5, Y = actorWidth*0.5), would appear at the top-left of the screen.
69
70 Note that since DALi is a 3D toolkit, this behaviour is the result of a default perspective camera setup.
71
72 ### Actor callback events
73
74 The actor provides the following call back events
75
76 | Name              | Description                            | Parameters passed to call back |
77 |-------------------|----------------------------------------|--------------------------|
78 |touched            | touch event                            | (actor, touchEvent )     |
79 |hovered            | mouse or pointer hovering over actor   | (actor, hoverEvent)      |
80 |mouse-wheel-event  | mouse wheel events                     | (actor, wheelEvent)      |
81 |on-stage           | actor has been moved on stage          | (actor)                  |
82 |off-stage          | actor has been moved off stage         | (actor)                  |
83
84
85 #### Touch event
86
87 Used to detect multiple touch events on the actor. The state of each touch point can be:
88 + "down"        = touch down
89 + "up"          = Touch up
90 + "motion"      = Finger dragged or hovered
91 + "leave"       =  Leave the boundary of an actor
92 + "stationary"  = No change from last event.  Useful when a multi-point event occurs where
93 all points are sent but indicates that this particular point has not changed since the last time
94 + "interrupted"  = A system event has occurred which has interrupted the touch or hover event sequence
95
96
97
98 ```
99 touchEvent = {
100   
101   pointCount: int,  // number of points touched ( multi-touch )
102   time: int,        // The time in milliseconds that the touch event occurred.
103   points = [ touchPoints ],    // array of TouchPoints, to support
104   
105   TouchPoint = {
106   
107     "deviceId" : int,      // Each touch point has a unique device ID
108     "state" : string,      // touch state ="down,up,motion,leave,stationary, interrupted }
109     "sourceActor" : actor, // the actor that is emitting the callback (the actor that is hit maybe a child of it)
110     "hitActor" : actor,    // actor that was hit
111     "local" :  {x,y},      // co-ordinates of top left of hit actor (local.x, local.y)
112     "screen" : {x,y}       // co-ordinates of top left of hit actor (screen.x, screen.y)
113     }
114 }
115
116 function OnPressed( actor, touchEvent )
117 {
118   var firstPoint = touchEvent.points[0];
119   log("first touch point = " + firstPoint.screen.x + "," +firstPoint.screen.x + "actor= "+firstPoint.hitActor );
120   
121   var anim = new dali.Animation( 4 );
122   var rotation = new dali.Rotation( 90, 0, 0 ); // pitch, yaw, roll
123   anim.animateBy( actor, "rotation", rotation );
124   anim.play();
125   return true;
126 }
127   
128 // connect to touch events
129 myActor.connect( "touched", onPressed );
130
131 ```
132
133 #### Hover event
134
135 ```
136 hoverEvent = {
137   
138   pointCount  // number of points hovered over
139   time        // The time in milliseconds that the hover event occurred.
140   points[]    // array of TouchPoints
141   
142   TouchPoint = {
143       // See touchEvent TouchPoint object
144   }
145 }
146 ```
147       // connect to touch events
148       myActor.connect( "hovered", onHover);
149
150 #### Mouse wheel event
151
152 ```
153 mouseWheelEvent = {
154   
155   direction,       // "vertical" or "horizontal" direction the wheel is being rolled
156   shiftPressed,    // boolean, shift key is held
157   ctrlPressed,     // boolean, ctrl key is held
158   altPressed,      // boolean, alt key is held
159   keyModifiers,    // bitmask of keys pressed
160   point {x,y},     // The co-ordinates of the mouse cursor relative to the top-left of the screen when the wheel is being rolled.
161   rolled,          // offset of mouse wheel rolling, positive = rolling down, negative = rolling up
162   timestamp        // The time in milliseconds that the mouse event occurred
163 }
164   
165 // connect to touch events
166 myActor.connect( "mouse-wheel-event", onMouseWheel );
167 ```
168 #### Key events
169
170 Key events are performed using the dali.stage object and dali.keyboardFocusManager.
171  - {{#crossLink "stage"}}Stage{{/crossLink}}
172
173
174 #### Multi-touch events
175
176 See
177  - {{#crossLink "MultiTouch"}}Multi Touch Events.{{/crossLink}}
178
179
180 ### Actor Properties
181
182  Name                   |    Type    | Writable     | Animatable
183 ------------------------|------------|--------------|-----------
184  anchorPoint            |VECTOR3     | ✔     | ✘
185  anchorPointX           |FLOAT       | ✔     | ✘
186  anchorPointY           |FLOAT       | ✔     | ✘
187  anchorPointZ           |FLOAT       | ✔     | ✘
188  size                   |VECTOR3     | ✔     | ✔
189  sizeWidth              |FLOAT       | ✔     | ✔
190  sizeHeight             |FLOAT       | ✔     | ✔
191  sizeDepth              |FLOAT       | ✔     | ✔
192  position               |VECTOR3     | ✔     | ✔
193  positionX              |FLOAT       | ✔     | ✔
194  positionY              |FLOAT       | ✔     | ✔
195  positionZ              |FLOAT       | ✔     | ✔
196  worldPosition          |VECTOR3     | ✘     | ✘
197  worldPositionX         |FLOAT       | ✘     | ✘
198  worldPositionY         |FLOAT       | ✘     | ✘
199  worldPositionZ         |FLOAT       | ✘     | ✘
200  rotation               |ROTATION    | ✔     | ✔
201  worldRotation          |ROTATION    | ✘     | ✘
202  scale                  |VECTOR3     | ✔     | ✔
203  scaleX                 |FLOAT       | ✔     | ✔
204  scaleY                 |FLOAT       | ✔     | ✔
205  scaleZ                 |FLOAT       | ✔     | ✔
206  worldScale             |VECTOR3     | ✘     | ✘
207  visible                |BOOLEAN     | ✔     | ✔
208  color                  |VECTOR4     | ✔     | ✔
209  colorRed               |FLOAT       | ✔     | ✔
210  colorGreen             |FLOAT       | ✔     | ✔
211  colorBlue              |FLOAT       | ✔     | ✔
212  colorAlpha             |FLOAT       | ✔     | ✔
213  worldColor             |VECTOR4     | ✘     | ✘
214  worldMatrix            |MATRIX      | ✘     | ✘
215  name                   |STRING      | ✔     | ✘
216  sensitive              |BOOLEAN     | ✔     | ✘
217  leaveRequired          |BOOLEAN     | ✔     | ✘
218  inheritRotation        |BOOLEAN     | ✔     | ✘
219  inheritScale           |BOOLEAN     | ✔     | ✘
220  colorMode              |NUMBER      | ✔     | ✘
221  positionInheritance    |NUMBER      | ✔     | ✘
222  drawMode               |NUMBER      | ✔     | ✘
223  sizeMode               |NUMBER      | ✔     | ✘
224  sizeModeFactor         |VECTOR3     | ✔     | ✘
225
226
227
228
229  * @class Actor
230  */
231
232
233 /**
234  * Actors parent origin
235  *
236  * @property parentOrigin
237  * @type dali Vector3
238  * @default TOP_LEFT (0.0, 0.0, 0.5).
239  */
240 parentOrigin
241
242 /**
243  * Actors parent origin X
244  *
245  * @property parentOriginX
246  * @readOnly
247  * @type Number
248  */
249 parent - origin - x
250
251 /**
252  * Actors parent origin-y
253  * @property parentOriginY
254  * @readOnly
255  * @type Number
256  */
257 parent - origin - y
258
259 /**
260  * Actors parent origin-z
261  * @property parentOriginZ
262  * @readOnly
263  * @type Number
264  */
265 parent - origin - z
266
267 /**
268  * Actors anchor point
269  * @property anchorPoint
270  * @type dali Vector3
271  * @default CENTER (0.5, 0.5, 0.5)
272  */
273 ANCHOR_POINT;
274
275 /**
276  * Actors anchor point x
277  * @property anchorPointX
278  * @type Number
279  */
280 ANCHOR_POINT_X
281
282 /**
283  * Actors anchor point y
284  * @property anchorPointY
285  * @type Number
286  */
287 ANCHOR_POINT_Y
288
289 /**
290  * Actors anchor point z
291  * @property anchorPointZ
292  * @type Number
293  */
294 ANCHOR_POINT_Z
295
296 /**
297  * Actors size
298  * @property size
299  * @type dali Vector3
300  */
301 SIZE
302
303
304 /**
305  * Actors width
306  * @property sizeWidth
307  * @type Number
308  */
309 SIZE_WIDTH
310
311 /**
312  * Actors height
313  * @property sizeHeight
314  * @type Number
315  */
316 SIZE_HEIGHT
317
318 /**
319  * Actors depth
320  * @property sizeDepth
321  * @type Number
322  */
323 SIZE_DEPTH
324
325
326 /**
327  * Actors position
328  * @property position
329  * @type dali Vector3
330  */
331 POSITION
332
333 /**
334  * Actors x position
335  * @property positionX
336  * @type Number
337  */
338 POSITION_X
339
340 /**
341  * Actors y position
342  * @property positionY
343  * @type Number
344  */
345 POSITION_Y
346
347 /**
348  * Actors z position
349  * @property positionZ
350  * @type Number
351  */
352 POSITION_Z
353
354
355 /**
356  * Actors world position
357  * @property position
358  * @type dali Vector3  ( read-only, not animatable )
359  */
360 WORLD_POSITION
361
362 /**
363  * Actors world x position
364  * @property worldPositionX
365  * @type Number ( read-only )
366  */
367 WORLD_POSITION_X
368
369 /**
370  * Actors world y position
371  * @property worldPositionY
372  * @type Number ( read-only )
373  */
374 WORLD_POSITION_Y
375
376 /**
377  * Actors world z position
378  * @property worldPositionZ
379  * @type Number ( read-only )
380  */
381 WORLD_POSITION_Z
382
383
384 /**
385  * Actors rotation
386  * @property rotation
387  * @type dali Rotation object
388  */
389 ROTATION
390
391
392 /**
393  * Actors world-rotation
394  * @property worldRotation
395  * @type dali Rotation object ( read only)
396  */
397 WORLD_ROTATION
398
399 /**
400  * Actors scale
401  * @property scale
402  * @type dali Vector3
403  */
404 SCALE
405
406 /**
407  * Actors x scale
408  * @property scaleX
409  * @type Number
410  */
411 SCALE_X
412
413 /**
414  * Actors y scale
415  * @property scaleY
416  * @type Number
417  */
418 SCALE_Y
419
420 /**
421  * Actors z scale
422  * @property scaleZ
423  * @type Number
424  */
425 SCALE_Z
426
427 /**
428  * Actors world scale
429  * @property worldScale
430  * @type dali Vector3 ( read only )
431  */
432 WORLD_SCALE
433
434 /**
435  * Actors visible flag
436  * If an actor is not visible, then the actor and its children will not be rendered.
437  * This is regardless of the individual visibility values of the children i.e. an actor will only be
438  * rendered if all of its parents have visibility set to true.
439  *
440  * @property visible
441  * @type Boolean
442  */
443 VISIBLE
444
445 /**
446  * Actors color.
447  * The final color of the actor depends on its color mode.
448  * 4 components, red, green, blue and alpha. Each range from 0..1
449  * @property color
450  * @type dali Vector 4
451  */
452 COLOR
453
454 /**
455  * Actors red color
456  * @property colorRed
457  * @type Number  ( 0..1)
458  */
459 COLOR_RED
460
461 /**
462  * Actors green color
463  * @property colorGreen
464  * @type Number  ( 0..1)
465  */
466 COLOR_GREEN
467
468 /**
469  * Actors blue color
470  * @property colorBlue
471  * @type Number  ( 0..1)
472  */
473 COLOR_BLUE
474
475 /**
476  * Actors world color.
477  * 4 components, red, green, blue and alpha. Each range from 0..1
478  * @property worldColor
479  * @type dali Vector 4 ( read only)
480  */
481 WORLD_COLOR
482
483 /**
484  * Actors name
485  * @property name
486  * @type String
487  */
488
489 /**
490  * Actors sensitive flag
491  * brief Sets whether an actor should emit touch event signals; @see SignalTouched().
492  *
493  * An actor is sensitive by default, which means that as soon as an application connects to the SignalTouched(),
494  * the touch event signal will be emitted.
495  *
496  * If the application wishes to temporarily disable the touch event signal emission, then they can do so by calling
497  *
498  *    actor.sensitve = false;
499  *
500  * Then, to re-enable the touch event signal emission, the application should call:
501  *
502  *    actor.sensitive = true;
503  *
504  * @property sensitive
505  * @type Boolean
506  * @default true ( is sensistive )
507  */
508 SENSITIVE
509
510 /**
511  * Controls whether the actor should receive a notification when touch motion events leave
512  * the boundary of the actor.
513  *
514  * Note: Need to connect to the SignalTouch to actually receive this event.
515  *  Should be set to true if a Leave event is required
516  * @type Boolean
517  * @property leaveRequired
518  * @default false, this is set to false as most actors do not require this.
519  */
520 LEAVE_REQUIRED
521
522 /**
523  * Set whether a child actor inherits it's parent's orientation.
524  * @type Boolean
525  * @property inheritRotation
526  * @default true
527  */
528 INHERIT_ROTATION,
529
530
531 /**
532  * Set whether a child actor inherits it's parent's scale.
533  * @type Boolean
534  * @property inheritScale
535  * @default true
536  */
537 INHERIT_SCALE,
538
539
540 /**
541  * Set how the actor and its children should be drawn.
542  *
543  * Not all actors are renderable, but DrawMode can be inherited from any actor.
544  * By default a renderable actor will be drawn as a 3D object. It will be depth-tested against
545  * other objects in the world i.e. it may be obscured if other objects are in front.
546  *
547  * If OVERLAY is used, the actor and its children will be drawn as a 2D overlay.
548  * Overlay actors are drawn in a separate pass, after all non-overlay actors within the Layer.
549  * For overlay actors, the drawing order is determined by the hierachy (depth-first search order),
550  * and depth-testing will not be used.
551  *
552  * If STENCIL is used, the actor and its children will be used to stencil-test other actors
553  * within the Layer. Stencil actors are therefore drawn into the stencil buffer before any other
554  * actors within the Layer.
555  *
556  * @example
557  *
558  *      var actor.drawMode = dali.DRAW_MODE_NORMAL;  // binary 00. The default draw-mode
559  *      var actor.drawMode = dali.DRAW_MODE_OVERLAY; // binary 01. Draw the actor and its children as an overlay
560  *      var actor.drawMode = dali.DRAW_MODE_STENCIL ;// binary 11. Draw the actor and its children into the stencil buffer
561  *
562  *
563  * @type Number
564  * @property drawMode
565  * @default 0 (Normal )
566  */
567 DRAW_MODE,
568
569
570 /**
571  * Sets the actor's color mode.
572  *
573  * This specifies whether the Actor uses its own color, or inherits
574  * its parent color. The default is USE_OWN_MULTIPLY_PARENT_ALPHA.
575  *
576  * @example
577  *    actor.colorMode = dali.COLOR_MODE_USE_OWN_COLOR; // Actor will use its own color
578  *    actor.colorMode = dali.COLOR_MODE_USE_PARENT_COLOR;  // Actor will use its parent color
579  *    actor.colorMode = dali. COLOR_MODE_USE_OWN_MULTIPLY_PARENT_COLOR; // Actor will blend its color with its parents color.
580  *    actor.colorMode = dali.COLOR_MODE_USE_OWN_MULTIPLY_PARENT_ALPHA ;  // Actor will blend its alpha with its parents alpha. This means when parent fades in or out child does as well. This is the default.
581  *
582  *
583  * @type Number
584  * @property colorMode
585  * @default 2 (USE_OWN_MULTIPLY_PARENT_ALPHA )
586  */
587 COLOR_MODE
588
589 /**
590  * Set the actors position inheritance mode.
591  *
592  * @example
593  *    actor.positionInheritance = dali.POSITION_INHERITANCE_INHERIT_PARENT_POSITION;  // Actor will inherit its parent position. This is the default
594  *    actor.positionInheritance = dali.POSITION_INHERITANCE_USE_PARENT_POSITION;      // Actor will copy its parent position. This is useful if many actors are stacked together in the same place. This option ignores parent origin and anchor point.
595  *    actor.positionInheritance = dali.POSITION_INHERITANCE_USE_PARENT_POSITION_PLUS_LOCAL_POSITION; // Actor will copy its parent position and add local position. This is useful if many actors are stacked together in the same place with an offset.  This option ignores parent origin and anchor point.
596  *    actor.positionInheritance = dali.POSITION_INHERITANCE_DONT_INHERIT_POSITION;           // Actor will not inherit position. Local position is treated as world position. This is useful if a constraint is used to override local position or if an actor is positioned globally. This option ignores parent origin, anchor point and local position.
597  *
598  * Switching this off means that using SetPosition() sets the actor's world position.
599  * @type Number
600  * @property positionInheritance
601  * @default 0 (INHERIT_PARENT_POSITION )
602  */
603 POSTITION_INHERITANCE
604
605
606 /**
607  *  Defines how a child actor's size is affected by its parent's size.
608  *
609  * The default is to ignore the parent's size and use the size property of this actor.
610  *
611  * If USE_OWN_SIZE is used, this option is bypassed and the actor's size
612  *     property is used.
613  *
614  * If SIZE_EQUAL_TO_PARENT is used, this actor's size will be equal to that
615  *     of its parent. The actor's size property is ignored.
616  *
617  * If SIZE_RELATIVE_TO_PARENT is used, this actor's size will be based on
618  *     its parent's size by multiplying the parent size by
619  *     SizeModeFactor.
620  *
621  * If SIZE_FIXED_OFFSET_FROM_PARENT is used, this actor's size will be based on
622  *     its parent's size plus SizeModeFactor.
623  *
624  *
625  * @example
626  *    actor.sizeMode = dali.USE_OWN_SIZE;
627  *    actor.sizeMode = dali.SIZE_EQUAL_TO_PARENT;
628  *    actor.sizeMode = dali.SIZE_RELATIVE_TO_PARENT;
629  *    actor.sizeMode = dali.SIZE_FIXED_OFFSET_FROM_PARENT
630  *
631  * @type Number
632  * @property sizeMode
633  * @default 0 (dali.SIZE_MODE_USE_OWN_SIZE; )
634  */
635  SIZE_MODE
636
637 /**
638  *
639  * @brief Sets the relative to parent size factor of the actor.
640  *
641  * This factor is only used when SizeMode is set to either:
642  * SIZE_RELATIVE_TO_PARENT or SIZE_FIXED_OFFSET_FROM_PARENT.
643  * This actor's size is set to the actor's parent size multipled by or added to this factor,
644  * depending on SideMode (See SetSizeMode).
645  * @type Vector3
646  * @property sizeModeFactor
647  */
648 SIZE_MODE_FACTOR