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