5 Actor is the primary object with which Dali applications interact. UI controls can be built by combining multiple actors.
7 There are different types of Actors supported by Dali. They all have the same
8 base functionality of the actor class.
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();
19 ### Hello world example </h3>
21 var myActor = new dali.TextActor("hello-world");
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
27 // by default an actor is anchored to the top-left of it's parent actor
28 // change it to the middle
30 myActor.parentOrigin = [0.5,0.5,0.5];
33 dali.stage.add( myActor );
37 ### Positioning Actors
39 An actor inherits its parent's position. The relative position between the actor & parent is determined by 3 properties:
41 1) ParentOrigin. This Vector3 property defines a point within the parent actor's area.
43 <img src="../assets/img/shared/parent-origin.png">
45 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 // to change parent origin to the centre
48 myActor.parentOrigin = [0.5, 0.5, 0.5];
51 2) AnchorPoint. This Vector3 property defines a point within the child actor's area.
53 <img src="../assets/img/shared/anchor-point.png">
55 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 // setting anchor point to the centre
58 myActor.anchorPoint = [0.5, 0.5, 0.5];
61 3) Position. This is the position vector between the parent-origin and anchor-point.
63 <img src="../assets/img/shared/actor-position.png">
65 Therefore by default, an actors position is the distance between its center and the top-left corner of its parent.
67 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 Note that since DALi is a 3D toolkit, this behaviour is the result of a default perspective camera setup.
71 ### Actor callback events
73 The actor provides the following call back events
75 | Name | Description | Parameters passed to call back |
76 |-------------------|----------------------------------------|--------------------------|
77 |touched | touch event | (actor, touchEvent ) |
78 |hovered | mouse or pointer hovering over actor | (actor, hoverEvent) |
79 |mouse-wheel-event | mouse wheel events | (actor, wheelEvent) |
80 |on-stage | actor has been moved on stage | (actor) |
81 |off-stage | actor has been moved off stage | (actor) |
86 Used to detect multiple touch events on the actor. The state of each touch point can be:
89 + "motion" = Finger dragged or hovered
90 + "leave" = Leave the boundary of an actor
91 + "stationary" = No change from last event. Useful when a multi-point event occurs where
92 all points are sent but indicates that this particular point has not changed since the last time
93 + "interrupted" = A system event has occurred which has interrupted the touch or hover event sequence
100 pointCount: int, // number of points touched ( multi-touch )
101 time: int, // The time in milliseconds that the touch event occurred.
102 points = [ touchPoints ], // array of TouchPoints, to support
106 "deviceId" : int, // Each touch point has a unique device ID
107 "state" : string, // touch state ="down,up,motion,leave,stationary, interrupted }
108 "sourceActor" : actor, // the actor that is emitting the callback (the actor that is hit maybe a child of it)
109 "hitActor" : actor, // actor that was hit
110 "local" : {x,y}, // co-ordinates of top left of hit actor (local.x, local.y)
111 "screen" : {x,y} // co-ordinates of top left of hit actor (screen.x, screen.y)
115 function OnPressed( actor, touchEvent )
117 var firstPoint = touchEvent.points[0];
118 log("first touch point = " + firstPoint.screen.x + "," +firstPoint.screen.x + "actor= "+firstPoint.hitActor );
120 var anim = new dali.Animation( 4 );
121 var rotation = new dali.Rotation( 90, 0, 0 ); // pitch, yaw, roll
122 anim.animateBy( actor, "rotation", rotation );
127 // connect to touch events
128 myActor.connect( "touched", onPressed );
137 pointCount // number of points hovered over
138 time // The time in milliseconds that the hover event occurred.
139 points[] // array of TouchPoints
142 // See touchEvent TouchPoint object
146 // connect to touch events
147 myActor.connect( "hovered", onHover);
149 #### Mouse wheel event
154 direction, // "vertical" or "horizontal" direction the wheel is being rolled
155 shiftPressed, // boolean, shift key is held
156 ctrlPressed, // boolean, ctrl key is held
157 altPressed, // boolean, alt key is held
158 keyModifiers, // bitmask of keys pressed
159 point {x,y}, // The co-ordinates of the mouse cursor relative to the top-left of the screen when the wheel is being rolled.
160 rolled, // offset of mouse wheel rolling, positive = rolling down, negative = rolling up
161 timestamp // The time in milliseconds that the mouse event occurred
164 // connect to touch events
165 myActor.connect( "mouse-wheel-event", onMouseWheel );
169 Key events are performed using the dali.stage object and dali.keyboardFocusManager.
170 - {{#crossLink "stage"}}Stage{{/crossLink}}
173 #### Multi-touch events
176 - {{#crossLink "MultiTouch"}}Multi Touch Events.{{/crossLink}}
181 Name | Type | Writable | Animatable
182 ------------------------|------------|--------------|-----------
183 anchorPoint |VECTOR3 | ✔ | ✘
184 anchorPointX |FLOAT | ✔ | ✘
185 anchorPointY |FLOAT | ✔ | ✘
186 anchorPointZ |FLOAT | ✔ | ✘
187 size |VECTOR3 | ✔ | ✔
188 sizeWidth |FLOAT | ✔ | ✔
189 sizeHeight |FLOAT | ✔ | ✔
190 sizeDepth |FLOAT | ✔ | ✔
191 position |VECTOR3 | ✔ | ✔
192 positionX |FLOAT | ✔ | ✔
193 positionY |FLOAT | ✔ | ✔
194 positionZ |FLOAT | ✔ | ✔
195 worldPosition |VECTOR3 | ✘ | ✘
196 worldPositionX |FLOAT | ✘ | ✘
197 worldPositionY |FLOAT | ✘ | ✘
198 worldPositionZ |FLOAT | ✘ | ✘
199 rotation |ROTATION | ✔ | ✔
200 worldRotation |ROTATION | ✘ | ✘
201 scale |VECTOR3 | ✔ | ✔
202 scaleX |FLOAT | ✔ | ✔
203 scaleY |FLOAT | ✔ | ✔
204 scaleZ |FLOAT | ✔ | ✔
205 worldScale |VECTOR3 | ✘ | ✘
206 visible |BOOLEAN | ✔ | ✔
207 color |VECTOR4 | ✔ | ✔
208 colorRed |FLOAT | ✔ | ✔
209 colorGreen |FLOAT | ✔ | ✔
210 colorBlue |FLOAT | ✔ | ✔
211 colorAlpha |FLOAT | ✔ | ✔
212 worldColor |VECTOR4 | ✘ | ✘
213 worldMatrix |MATRIX | ✘ | ✘
214 name |STRING | ✔ | ✘
215 sensitive |BOOLEAN | ✔ | ✘
216 leaveRequired |BOOLEAN | ✔ | ✘
217 inheritRotation |BOOLEAN | ✔ | ✘
218 inheritScale |BOOLEAN | ✔ | ✘
219 colorMode |NUMBER | ✔ | ✘
220 positionInheritance |NUMBER | ✔ | ✘
221 drawMode |NUMBER | ✔ | ✘
222 sizeMode |NUMBER | ✔ | ✘
223 sizeModeFactor |VECTOR3 | ✔ | ✘
233 * Actors parent origin
235 * @property parentOrigin
237 * @default TOP_LEFT (0.0, 0.0, 0.5).
242 * Actors parent origin X
244 * @property parentOriginX
251 * Actors parent origin-y
252 * @property parentOriginY
259 * Actors parent origin-z
260 * @property parentOriginZ
267 * Actors anchor point
268 * @property anchorPoint
270 * @default CENTER (0.5, 0.5, 0.5)
275 * Actors anchor point x
276 * @property anchorPointX
282 * Actors anchor point y
283 * @property anchorPointY
289 * Actors anchor point z
290 * @property anchorPointZ
305 * @property sizeWidth
312 * @property sizeHeight
319 * @property sizeDepth
334 * @property positionX
341 * @property positionY
348 * @property positionZ
355 * Actors world position
357 * @type dali Vector3 ( read-only, not animatable )
362 * Actors world x position
363 * @property worldPositionX
364 * @type Number ( read-only )
369 * Actors world y position
370 * @property worldPositionY
371 * @type Number ( read-only )
376 * Actors world z position
377 * @property worldPositionZ
378 * @type Number ( read-only )
386 * @type dali Rotation object
392 * Actors world-rotation
393 * @property worldRotation
394 * @type dali Rotation object ( read only)
428 * @property worldScale
429 * @type dali Vector3 ( read only )
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.
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
449 * @type dali Vector 4
456 * @type Number ( 0..1)
462 * @property colorGreen
463 * @type Number ( 0..1)
469 * @property colorBlue
470 * @type Number ( 0..1)
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)
489 * Actors sensitive flag
490 * brief Sets whether an actor should emit touch event signals; @see SignalTouched().
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.
495 * If the application wishes to temporarily disable the touch event signal emission, then they can do so by calling
497 * actor.sensitve = false;
499 * Then, to re-enable the touch event signal emission, the application should call:
501 * actor.sensitive = true;
503 * @property sensitive
505 * @default true ( is sensistive )
510 * Controls whether the actor should receive a notification when touch motion events leave
511 * the boundary of the actor.
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
516 * @property leaveRequired
517 * @default false, this is set to false as most actors do not require this.
522 * Set whether a child actor inherits it's parent's orientation.
524 * @property inheritRotation
531 * Set whether a child actor inherits it's parent's scale.
533 * @property inheritScale
540 * Set how the actor and its children should be drawn.
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.
546 * If OVERLAY 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.
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.
557 * var actor.drawMode = dali.DRAW_MODE_NORMAL; // binary 00. The default draw-mode
558 * var actor.drawMode = dali.DRAW_MODE_OVERLAY; // 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
564 * @default 0 (Normal )
570 * Sets the actor's color mode.
572 * This specifies whether the Actor uses its own color, or inherits
573 * its parent color. The default is USE_OWN_MULTIPLY_PARENT_ALPHA.
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.
583 * @property colorMode
584 * @default 2 (USE_OWN_MULTIPLY_PARENT_ALPHA )
589 * Set the actors position inheritance mode.
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.
597 * Switching this off means that using SetPosition() sets the actor's world position.
599 * @property positionInheritance
600 * @default 0 (INHERIT_PARENT_POSITION )
602 POSTITION_INHERITANCE
606 * Defines how a child actor's size is affected by its parent's size.
608 * The default is to ignore the parent's size and use the size property of this actor.
610 * If USE_OWN_SIZE is used, this option is bypassed and the actor's size
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.
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
620 * If SIZE_FIXED_OFFSET_FROM_PARENT is used, this actor's size will be based on
621 * its parent's size plus SizeModeFactor.
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
632 * @default 0 (dali.SIZE_MODE_USE_OWN_SIZE; )
638 * @brief Sets the relative to parent size factor of the actor.
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).
645 * @property sizeModeFactor