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