1 #ifndef __DALI_ACTOR_H__
2 #define __DALI_ACTOR_H__
5 * Copyright (c) 2014 Samsung Electronics Co., Ltd.
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
22 #include <boost/function.hpp>
26 #include <dali/public-api/common/vector-wrapper.h>
27 #include <dali/public-api/animation/active-constraint-declarations.h>
28 #include <dali/public-api/actors/actor-enumerations.h>
29 #include <dali/public-api/actors/draw-mode.h>
30 #include <dali/public-api/object/constrainable.h>
31 #include <dali/public-api/signals/dali-signal.h>
36 namespace Internal DALI_INTERNAL
46 class DynamicsBodyConfig;
54 struct MouseWheelEvent;
60 * @brief Actor container.
62 typedef std::vector<Actor> ActorContainer;
63 typedef ActorContainer::iterator ActorIter; ///< Iterator for Dali::ActorContainer
64 typedef ActorContainer::const_iterator ActorConstIter; ///< Const iterator for Dali::ActorContainer
69 * @brief Actor is the primary object with which Dali applications interact.
71 * UI controls can be built by combining multiple actors.
73 * <h3>Multi-Touch Events:</h3>
75 * Touch or hover events are received via signals; see Actor::TouchedSignal() and Actor::HoveredSignal() for more details.
77 * <i>Hit Testing Rules Summary:</i>
79 * - An actor is only hittable if the actor's touch or hover signal has a connection.
80 * - An actor is only hittable when it is between the camera's near and far planes.
81 * - If an actor is made insensitive, then the actor and its children are not hittable; see IsSensitive()
82 * - If an actor's visibility flag is unset, then none of its children are hittable either; see IsVisible()
83 * - To be hittable, an actor must have a non-zero size.
84 * - If an actor's world color is fully transparent, then it is not hittable; see GetCurrentWorldColor()
86 * <i>Hit Test Algorithm:</i>
89 * - Hit testing is dependent on the camera used, which is specific to each RenderTask.
92 * - For each RenderTask, hit testing starts from the top-most layer and we go through all the
93 * layers until we have a hit or there are none left.
94 * - Before we perform a hit test within a layer, we check if all the layer's parents are visible
96 * - If they are not, we skip hit testing the actors in that layer altogether.
97 * - If a layer is set to consume all touch, then we do not check any layers behind this layer.
100 * - The final part of hit testing is performed by walking through the actor tree within a layer.
101 * - The following pseudocode shows the algorithm used:
103 * HIT-TEST-WITHIN-LAYER( ACTOR )
105 * // Only hit-test the actor and its children if it is sensitive and visible
106 * IF ( ACTOR-IS-SENSITIVE &&
109 * // Depth-first traversal within current layer, visiting parent first
111 * // Check whether current actor should be hit-tested
112 * IF ( ( TOUCH-SIGNAL-NOT-EMPTY || HOVER-SIGNAL-NOT-EMPTY ) &&
113 * ACTOR-HAS-NON-ZERO-SIZE &&
114 * ACTOR-WORLD-COLOR-IS-NOT-TRANSPARENT )
116 * // Hit-test current actor
119 * IF ( ACTOR-IS-OVERLAY || ( DISTANCE-TO-ACTOR < DISTANCE-TO-LAST-HIT-ACTOR ) )
121 * // The current actor is the closest actor that was underneath the touch
122 * LAST-HIT-ACTOR = CURRENT-ACTOR
127 * // Keep checking children, in case we hit something closer
128 * FOR-EACH CHILD (in order)
130 * IF ( CHILD-IS-NOT-A-LAYER )
132 * // Continue traversal for this child's sub-tree
133 * HIT-TEST-WITHIN-LAYER ( CHILD )
135 * // else we skip hit-testing the child's sub-tree altogether
140 * - Overlays always take priority (i.e. they're considered closer) regardless of distance.
141 * The overlay children take priority over their parents, and overlay siblings take priority
142 * over their previous siblings (i.e. reverse of rendering order):
152 * Hit Priority of above Actor tree (all overlays): 1 - Lowest. 6 - Highest.
154 * - Stencil Actors can be used to influence the result of hits on renderable actors within a layer.
155 * If a Stencil Actor exists on a layer and that Actor is marked visible then a successful
156 * hit on a renderable actor can only take place in the area that the stencil Actor marks as visible.
157 * The hit can be in any Stencil Actor in that layer, but must be in the region of one of them.
158 * Stencil Actor inheritance behaves as with rendering in that any child of a Stencil Actor will
159 * also be considered a Stencil Actor.
160 * Non-renderable actors can be hit regardless of whether a stencil actor is hit or not.
162 * <i>Touch or hover Event Delivery:</i>
165 * - The hit actor's touch or hover signal is emitted first; if it is not consumed by any of the listeners,
166 * the parent's touch or hover signal is emitted, and so on.
167 * - The following pseudocode shows the delivery mechanism:
169 * EMIT-TOUCH-SIGNAL( ACTOR )
171 * IF ( TOUCH-SIGNAL-NOT-EMPTY )
173 * // Only do the emission if touch signal of actor has connections.
174 * CONSUMED = TOUCHED-SIGNAL( TOUCH-EVENT )
177 * IF ( NOT-CONSUMED )
179 * // If event is not consumed then deliver it to the parent unless we reach the root actor
180 * IF ( ACTOR-PARENT )
182 * EMIT-TOUCH-SIGNAL( ACTOR-PARENT )
187 * EMIT-HOVER-SIGNAL( ACTOR )
189 * IF ( HOVER-SIGNAL-NOT-EMPTY )
191 * // Only do the emission if hover signal of actor has connections.
192 * CONSUMED = HOVERED-SIGNAL( HOVER-EVENT )
195 * IF ( NOT-CONSUMED )
197 * // If event is not consumed then deliver it to the parent unless we reach the root actor
198 * IF ( ACTOR-PARENT )
200 * EMIT-HOVER-SIGNAL( ACTOR-PARENT )
205 * - If there are several touch points, then the delivery is only to the first touch point's hit
206 * actor (and its parents). There will be NO touch or hover signal delivery for the hit actors of the
207 * other touch points.
208 * - The local coordinates are from the top-left (0.0f, 0.0f, 0.5f) of the hit actor.
211 * - A "Leave" state is set when the first point exits the bounds of the previous first point's
212 * hit actor (primary hit actor).
213 * - When this happens, the last primary hit actor's touch or hover signal is emitted with a "Leave" state
214 * (only if it requires leave signals); see SetLeaveRequired().
216 * - Interrupted State
217 * - If a system event occurs which interrupts the touch or hover processing, then the last primary hit
218 * actor's touch or hover signals are emitted with an "Interrupted" state.
219 * - If the last primary hit actor, or one of its parents, is no longer touchable or hoverable, then its
220 * touch or hover signals are also emitted with an "Interrupted" state.
221 * - If the consumed actor on touch-down is not the same as the consumed actor on touch-up, then
222 * touch signals are also emitted from the touch-down actor with an "Interrupted" state.
223 * - If the consumed actor on hover-start is not the same as the consumed actor on hover-finished, then
224 * hover signals are also emitted from the hover-started actor with an "Interrupted" state.
225 * <h3>Key Events:</h3>
227 * Key events are received by an actor once set to grab key events, only one actor can be set as focused.
231 class DALI_IMPORT_API Actor : public Constrainable
237 typedef Signal< bool (Actor, const TouchEvent&)> TouchSignalType; ///< Touch signal type
238 typedef Signal< bool (Actor, const HoverEvent&)> HoverSignalType; ///< Hover signal type
239 typedef Signal< bool (Actor, const MouseWheelEvent&) > MouseWheelEventSignalType;///< Mousewheel signal type
240 typedef Signal< void (Actor, const Vector3&) > SetSizeSignalType; ///< SetSize signal type
241 typedef Signal< void (Actor) > OnStageSignalType; ///< Stage connection signal type
242 typedef Signal< void (Actor) > OffStageSignalType; ///< Stage disconnection signal type
246 static const Property::Index PARENT_ORIGIN; ///< name "parent-origin", type VECTOR3
247 static const Property::Index PARENT_ORIGIN_X; ///< name "parent-origin-x", type FLOAT
248 static const Property::Index PARENT_ORIGIN_Y; ///< name "parent-origin-y", type FLOAT
249 static const Property::Index PARENT_ORIGIN_Z; ///< name "parent-origin-z", type FLOAT
250 static const Property::Index ANCHOR_POINT; ///< name "anchor-point", type VECTOR3
251 static const Property::Index ANCHOR_POINT_X; ///< name "anchor-point-x", type FLOAT
252 static const Property::Index ANCHOR_POINT_Y; ///< name "anchor-point-y", type FLOAT
253 static const Property::Index ANCHOR_POINT_Z; ///< name "anchor-point-z", type FLOAT
254 static const Property::Index SIZE; ///< name "size", type VECTOR3
255 static const Property::Index SIZE_WIDTH; ///< name "size-width", type FLOAT
256 static const Property::Index SIZE_HEIGHT; ///< name "size-height", type FLOAT
257 static const Property::Index SIZE_DEPTH; ///< name "size-depth", type FLOAT
258 static const Property::Index POSITION; ///< name "position", type VECTOR3
259 static const Property::Index POSITION_X; ///< name "position-x", type FLOAT
260 static const Property::Index POSITION_Y; ///< name "position-y", type FLOAT
261 static const Property::Index POSITION_Z; ///< name "position-z", type FLOAT
262 static const Property::Index WORLD_POSITION; ///< name "world-position", type VECTOR3 (read-only)
263 static const Property::Index WORLD_POSITION_X; ///< name "world-position-x", type FLOAT (read-only)
264 static const Property::Index WORLD_POSITION_Y; ///< name "world-position-y", type FLOAT (read-only)
265 static const Property::Index WORLD_POSITION_Z; ///< name "world-position-z", type FLOAT (read-only)
266 static const Property::Index ROTATION; ///< name "rotation", type ROTATION
267 static const Property::Index WORLD_ROTATION; ///< name "world-rotation", type ROTATION (read-only)
268 static const Property::Index SCALE; ///< name "scale", type VECTOR3
269 static const Property::Index SCALE_X; ///< name "scale-x", type FLOAT
270 static const Property::Index SCALE_Y; ///< name "scale-y", type FLOAT
271 static const Property::Index SCALE_Z; ///< name "scale-z", type FLOAT
272 static const Property::Index WORLD_SCALE; ///< name "world-scale", type VECTOR3 (read-only)
273 static const Property::Index VISIBLE; ///< name "visible", type BOOLEAN
274 static const Property::Index COLOR; ///< name "color", type VECTOR4
275 static const Property::Index COLOR_RED; ///< name "color-red", type FLOAT
276 static const Property::Index COLOR_GREEN; ///< name "color-green", type FLOAT
277 static const Property::Index COLOR_BLUE; ///< name "color-blue", type FLOAT
278 static const Property::Index COLOR_ALPHA; ///< name "color-alpha", type FLOAT
279 static const Property::Index WORLD_COLOR; ///< name "world-color", type VECTOR4 (read-only)
280 static const Property::Index WORLD_MATRIX; ///< name "world-matrix", type MATRIX (read-only)
281 static const Property::Index NAME; ///< name "name", type STRING
282 static const Property::Index SENSITIVE; ///< name "sensitive", type BOOLEAN
283 static const Property::Index LEAVE_REQUIRED; ///< name "leave-required", type BOOLEAN
284 static const Property::Index INHERIT_ROTATION; ///< name "inherit-rotation", type BOOLEAN
285 static const Property::Index INHERIT_SCALE; ///< name "inherit-scale", type BOOLEAN
286 static const Property::Index COLOR_MODE; ///< name "color-mode", type STRING
287 static const Property::Index POSITION_INHERITANCE; ///< name "position-inheritance", type STRING
288 static const Property::Index DRAW_MODE; ///< name "draw-mode", type STRING
293 static const char* const SIGNAL_TOUCHED; ///< name "touched", @see TouchedSignal()
294 static const char* const SIGNAL_HOVERED; ///< name "hovered", @see HoveredSignal()
295 static const char* const SIGNAL_MOUSE_WHEEL_EVENT; ///< name "mouse-wheel-event", @see MouseWheelEventSignal()
296 static const char* const SIGNAL_SET_SIZE; ///< name "set-size", @see SetSizeSignal()
297 static const char* const SIGNAL_ON_STAGE; ///< name "on-stage", @see OnStageSignal()
298 static const char* const SIGNAL_OFF_STAGE; ///< name "off-stage", @see OffStageSignal()
303 static const char* const ACTION_SHOW; ///< name "show", @see SetVisible()
304 static const char* const ACTION_HIDE; ///< name "hide", @see SetVisible()
310 * @brief Create an uninitialized Actor; this can be initialized with Actor::New().
312 * Calling member functions with an uninitialized Dali::Object is not allowed.
317 * @brief Create an initialized Actor.
319 * @return A handle to a newly allocated Dali resource.
324 * @brief Downcast an Object handle to Actor handle.
326 * If handle points to a Actor object the downcast produces valid
327 * handle. If not the returned handle is left uninitialized.
329 * @param[in] handle to An object
330 * @return handle to a Actor object or an uninitialized handle
332 static Actor DownCast( BaseHandle handle );
335 * @brief Dali::Actor is intended as a base class
337 * This is non-virtual since derived Handle types must not contain data or virtual methods.
342 * @brief Copy constructor
344 * @param [in] copy The actor to copy.
346 Actor(const Actor& copy);
349 * @brief Assignment operator
351 * @param [in] rhs The actor to copy.
353 Actor& operator=(const Actor& rhs);
356 * @brief Retrieve the Actor's name.
358 * @pre The Actor has been initialized.
359 * @return The Actor's name.
361 const std::string& GetName() const;
364 * @brief Sets the Actor's name.
366 * @pre The Actor has been initialized.
367 * @param [in] name The new name.
369 void SetName(const std::string& name);
372 * @brief Retrieve the unique ID of the actor.
374 * @pre The Actor has been initialized.
377 unsigned int GetId() const;
382 * @brief Query whether an actor is the root actor, which is owned by the Stage.
384 * @pre The Actor has been initialized.
385 * @return True if the actor is the root actor.
390 * @brief Query whether the actor is connected to the Stage.
392 * When an actor is connected, it will be directly or indirectly parented to the root Actor.
393 * @note The root Actor is provided automatically by Dali::Stage, and is always considered to be connected.
394 * @pre The Actor has been initialized.
395 * @return True if the actor is connected to the Stage.
397 bool OnStage() const;
400 * @brief Query whether the actor is of class Dali::Layer.
402 * @pre The Actor has been initialized.
403 * @return True if the actor is a layer.
405 bool IsLayer() const;
408 * @brief Gets the layer in which the actor is present.
410 * @pre The Actor has been initialized.
411 * @return The layer, which will be uninitialized if the actor is off-stage.
416 * @brief Adds a child Actor to this Actor.
418 * NOTE! if the child already has a parent, it will be removed from old parent
419 * and reparented to this actor. This may change childs position, color,
420 * scale etc as it now inherits them from this actor
421 * @pre This Actor (the parent) has been initialized.
422 * @pre The child actor has been initialized.
423 * @pre The child actor is not the same as the parent actor.
424 * @pre The actor is not the Root actor
425 * @param [in] child The child.
426 * @post The child will be referenced by its parent. This means that the child will be kept alive,
427 * even if the handle passed into this method is reset or destroyed.
428 * @post This may invalidate ActorContainer iterators.
430 void Add(Actor child);
433 * @brief Inserts a child Actor to this actor's list of children at the given index
435 * NOTE! if the child already has a parent, it will be removed from old parent
436 * and reparented to this actor. This may change childs position, color,
437 * scale etc as it now inherits them from this actor
438 * @pre This Actor (the parent) has been initialized.
439 * @pre The child actor has been initialized.
440 * @pre The child actor is not the same as the parent actor.
441 * @pre The actor is not the Root actor
442 * @param [in] index of actor to insert before
443 * @param [in] child The child.
444 * @post The child will be referenced by its parent. This means that the child will be kept alive,
445 * even if the handle passed into this method is reset or destroyed.
446 * @post If the index is greater than the current child count, it will be ignored and added at the end.
447 * @post This may invalidate ActorContainer iterators.
449 void Insert(unsigned int index, Actor child);
452 * @brief Removes a child Actor from this Actor.
454 * If the actor was not a child of this actor, this is a no-op.
455 * @pre This Actor (the parent) has been initialized.
456 * @pre The child actor is not the same as the parent actor.
457 * @param [in] child The child.
458 * @post This may invalidate ActorContainer iterators.
460 void Remove(Actor child);
463 * @brief Removes an actor from its parent.
465 * If the actor has no parent, this method does nothing.
466 * @pre The (child) actor has been initialized.
467 * @post This may invalidate ActorContainer iterators.
472 * @brief Retrieve the number of children held by the actor.
474 * @pre The Actor has been initialized.
475 * @return The number of children
477 unsigned int GetChildCount() const;
480 * @brief Retrieve and child actor by index.
482 * @pre The Actor has been initialized.
483 * @param[in] index The index of the child to retrieve
484 * @return The actor for the given index or empty handle if children not initialised
486 Actor GetChildAt(unsigned int index) const;
489 * @brief Search through this actor's hierarchy for an actor with the given name.
491 * The actor itself is also considered in the search
492 * @pre The Actor has been initialized.
493 * @param[in] actorName the name of the actor to find
494 * @return A handle to the actor if found, or an empty handle if not.
496 Actor FindChildByName(const std::string& actorName);
499 * @brief Search through this actor's hierarchy for an actor with the given name or alias.
501 * Actors can customize this function to provide actors with preferred alias'
502 * For example 'previous' could return the last selected child.
503 * If no aliased actor is found then FindChildByName() is called.
504 * @pre The Actor has been initialized.
505 * @param[in] actorAlias the name of the actor to find
506 * @return A handle to the actor if found, or an empty handle if not.
508 Actor FindChildByAlias(const std::string& actorAlias);
511 * @brief Search through this actor's hierarchy for an actor with the given unique ID.
513 * The actor itself is also considered in the search
514 * @pre The Actor has been initialized.
515 * @param[in] id the ID of the actor to find
516 * @return A handle to the actor if found, or an empty handle if not.
518 Actor FindChildById(const unsigned int id);
521 * @brief Retrieve the actor's parent.
523 * @pre The actor has been initialized.
524 * @return A handle to the actor's parent. If the actor has no parent, this handle will be invalid.
526 Actor GetParent() const;
531 * @brief Set the origin of an actor, within its parent's area.
533 * This is expressed in unit coordinates, such that (0.0, 0.0, 0.5) is the top-left corner of the parent,
534 * and (1.0, 1.0, 0.5) is the bottom-right corner.
535 * The default parent-origin is Dali::ParentOrigin::TOP_LEFT (0.0, 0.0, 0.5).
536 * An actor position is the distance between this origin, and the actors anchor-point.
537 * @see Dali::ParentOrigin for predefined parent origin values
538 * @pre The Actor has been initialized.
539 * @note This is an asynchronous method; the value written may not match a value subsequently read with GetCurrentParentOrigin().
540 * @param [in] origin The new parent-origin.
542 void SetParentOrigin(const Vector3& origin);
545 * @brief Retrieve the parent-origin of an actor.
547 * @pre The Actor has been initialized.
548 * @note This property can be animated; the return value may not match the value written with SetParentOrigin().
549 * @return The current parent-origin.
551 Vector3 GetCurrentParentOrigin() const;
554 * @brief Set the anchor-point of an actor.
556 * This is expressed in unit coordinates, such that (0.0, 0.0, 0.5)
557 * is the top-left corner of the actor, and (1.0, 1.0, 0.5) is the
558 * bottom-right corner. The default anchor point is
559 * Dali::AnchorPoint::CENTER (0.5, 0.5, 0.5).
560 * An actor position is the distance between its parent-origin, and this anchor-point.
561 * An actor's rotation is centered around its anchor-point.
562 * @see Dali::AnchorPoint for predefined anchor point values
563 * @pre The Actor has been initialized.
564 * @note This is an asynchronous method; the value written may not match a value subsequently read with GetCurrentAnchorPoint().
565 * @param [in] anchorPoint The new anchor-point.
567 void SetAnchorPoint(const Vector3& anchorPoint);
570 * @brief Retrieve the anchor-point of an actor.
572 * @pre The Actor has been initialized.
573 * @note This property can be animated; the return value may not match the value written with SetAnchorPoint().
574 * @return The current anchor-point.
576 Vector3 GetCurrentAnchorPoint() const;
579 * @brief Sets the size of an actor.
581 * Geometry can be scaled to fit within this area.
582 * This does not interfere with the actors scale factor.
583 * The actors default depth is the minimum of width & height.
584 * @pre The actor has been initialized.
585 * @note This is an asynchronous method; the value written may not match a value subsequently read with GetCurrentSize().
586 * @param [in] width The new width.
587 * @param [in] height The new height.
589 void SetSize(float width, float height);
592 * @brief Sets the size of an actor.
594 * Geometry can be scaled to fit within this area.
595 * This does not interfere with the actors scale factor.
596 * @pre The actor has been initialized.
597 * @note This is an asynchronous method; the value written may not match a value subsequently read with GetCurrentSize().
598 * @param [in] width The size of the actor along the x-axis.
599 * @param [in] height The size of the actor along the y-axis.
600 * @param [in] depth The size of the actor along the z-axis.
602 void SetSize(float width, float height, float depth);
605 * @brief Sets the size of an actor.
607 * Geometry can be scaled to fit within this area.
608 * This does not interfere with the actors scale factor.
609 * The actors default depth is the minimum of width & height.
610 * @pre The actor has been initialized.
611 * @note This is an asynchronous method; the value written may not match a value subsequently read with GetCurrentSize().
612 * @param [in] size The new size.
614 void SetSize(const Vector2& size);
617 * @brief Sets the size of an actor.
619 * Geometry can be scaled to fit within this area.
620 * This does not interfere with the actors scale factor.
621 * @pre The actor has been initialized.
622 * @note This is an asynchronous method; the value written may not match a value subsequently read with GetCurrentSize().
623 * @param [in] size The new size.
625 void SetSize(const Vector3& size);
628 * @brief Retrieve the actor's size.
630 * @pre The actor has been initialized.
631 * @note This return is the value that was set using SetSize or the target size of an animation
632 * @return The actor's current size.
634 Vector3 GetSize() const;
637 * @brief Retrieve the actor's size.
639 * @pre The actor has been initialized.
640 * @note This property can be animated; the return value may not match the value written with SetSize().
641 * @return The actor's current size.
643 Vector3 GetCurrentSize() const;
646 * Return the natural size of the actor.
648 * Deriving classes stipulate the natural size and by default an actor has a ZERO natural size.
650 * @return The actor's natural size
652 Vector3 GetNaturalSize() const;
655 * @brief Sets the position of the actor.
657 * The Actor's z position will be set to 0.0f.
658 * @pre The Actor has been initialized.
659 * @note This is an asynchronous method; the value written may not match a value subsequently read with GetCurrentPosition().
660 * @param [in] x The new x position
661 * @param [in] y The new y position
663 void SetPosition(float x, float y);
666 * @brief Sets the position of the Actor.
668 * @pre The Actor has been initialized.
669 * @note This is an asynchronous method; the value written may not match a value subsequently read with GetCurrentPosition().
670 * @param [in] x The new x position
671 * @param [in] y The new y position
672 * @param [in] z The new z position
674 void SetPosition(float x, float y, float z);
677 * @brief Sets the position of the Actor.
679 * @pre The Actor has been initialized.
680 * @note This is an asynchronous method; the value written may not match a value subsequently read with GetCurrentPosition().
681 * @param [in] position The new position
683 void SetPosition(const Vector3& position);
686 * @brief Set the position of an actor along the X-axis.
688 * @pre The Actor has been initialized.
689 * @note This is an asynchronous method; the value written may not match a value subsequently read with GetCurrentPosition().
690 * @param [in] x The new x position
695 * @brief Set the position of an actor along the Y-axis.
697 * @pre The Actor has been initialized.
698 * @note This is an asynchronous method; the value written may not match a value subsequently read with GetCurrentPosition().
699 * @param [in] y The new y position.
704 * @brief Set the position of an actor along the Z-axis.
706 * @pre The Actor has been initialized.
707 * @note This is an asynchronous method; the value written may not match a value subsequently read with GetCurrentPosition().
708 * @param [in] z The new z position
713 * @brief Move an actor relative to its existing position.
715 * @pre The actor has been initialized.
716 * @param[in] distance The actor will move by this distance.
718 void MoveBy(const Vector3& distance);
721 * @brief Retrieve the position of the Actor.
723 * @pre The Actor has been initialized.
724 * @note This property can be animated; the return value may not match the value written with SetPosition().
725 * @return the Actor's current position.
727 Vector3 GetCurrentPosition() const;
730 * @brief Retrieve the world-position of the Actor.
732 * @note The actor will not have a world-position, unless it has previously been added to the stage.
733 * @pre The Actor has been initialized.
734 * @return The Actor's current position in world coordinates.
736 Vector3 GetCurrentWorldPosition() const;
739 * @brief Set the actors position inheritance mode.
741 * The default is to inherit.
742 * Switching this off means that using SetPosition() sets the actor's world position.
743 * @see PositionInheritanceMode
744 * @pre The Actor has been initialized.
745 * @param[in] mode to use
747 void SetPositionInheritanceMode( PositionInheritanceMode mode );
750 * @brief Returns the actors position inheritance mode.
752 * @pre The Actor has been initialized.
753 * @return true if the actor inherit's it's parent orientation, false if it uses world orientation.
755 PositionInheritanceMode GetPositionInheritanceMode() const;
758 * @brief Sets the rotation of the Actor.
760 * An actor's rotation is centered around its anchor point.
761 * @pre The Actor has been initialized.
762 * @note This is an asynchronous method; the value written may not match a value subsequently read with GetCurrentRotation().
763 * @param [in] angle The new rotation angle in degrees.
764 * @param [in] axis The new axis of rotation.
766 void SetRotation(const Degree& angle, const Vector3& axis);
769 * @brief Sets the rotation of the Actor.
771 * An actor's rotation is centered around its anchor point.
772 * @pre The Actor has been initialized.
773 * @note This is an asynchronous method; the value written may not match a value subsequently read with GetCurrentRotation().
774 * @param [in] angle The new rotation angle in radians.
775 * @param [in] axis The new axis of rotation.
777 void SetRotation(const Radian& angle, const Vector3& axis);
780 * @brief Sets the rotation of the Actor.
782 * @pre The Actor has been initialized.
783 * @note This is an asynchronous method; the value written may not match a value subsequently read with GetCurrentRotation().
784 * @param [in] rotation The new rotation.
786 void SetRotation(const Quaternion& rotation);
789 * @brief Apply a relative rotation to an actor.
791 * @pre The actor has been initialized.
792 * @param[in] angle The angle to the rotation to combine with the existing rotation.
793 * @param[in] axis The axis of the rotation to combine with the existing rotation.
795 void RotateBy(const Degree& angle, const Vector3& axis);
798 * @brief Apply a relative rotation to an actor.
800 * @pre The actor has been initialized.
801 * @param[in] angle The angle to the rotation to combine with the existing rotation.
802 * @param[in] axis The axis of the rotation to combine with the existing rotation.
804 void RotateBy(const Radian& angle, const Vector3& axis);
807 * @brief Apply a relative rotation to an actor.
809 * @pre The actor has been initialized.
810 * @param[in] relativeRotation The rotation to combine with the existing rotation.
812 void RotateBy(const Quaternion& relativeRotation);
815 * @brief Retreive the Actor's rotation.
817 * @pre The Actor has been initialized.
818 * @note This property can be animated; the return value may not match the value written with SetRotation().
819 * @return The current rotation.
821 Quaternion GetCurrentRotation() const;
824 * @brief Set whether a child actor inherits it's parent's orientation.
826 * Default is to inherit.
827 * Switching this off means that using SetRotation() sets the actor's world orientation.
828 * @pre The Actor has been initialized.
829 * @param[in] inherit - true if the actor should inherit orientation, false otherwise.
831 void SetInheritRotation(bool inherit);
834 * @brief Returns whether the actor inherit's it's parent's orientation.
836 * @pre The Actor has been initialized.
837 * @return true if the actor inherit's it's parent orientation, false if it uses world orientation.
839 bool IsRotationInherited() const;
842 * @brief Retrieve the world-rotation of the Actor.
844 * @note The actor will not have a world-rotation, unless it has previously been added to the stage.
845 * @pre The Actor has been initialized.
846 * @return The Actor's current rotation in the world.
848 Quaternion GetCurrentWorldRotation() const;
851 * @brief Set the scale factor applied to an actor.
853 * @pre The Actor has been initialized.
854 * @note This is an asynchronous method; the value written may not match a value subsequently read with GetCurrentScale().
855 * @param [in] scale The scale factor applied on all axes.
857 void SetScale(float scale);
860 * @brief Set the scale factor applied to an actor.
862 * @pre The Actor has been initialized.
863 * @note This is an asynchronous method; the value written may not match a value subsequently read with GetCurrentScale().
864 * @param [in] scaleX The scale factor applied along the x-axis.
865 * @param [in] scaleY The scale factor applied along the y-axis.
866 * @param [in] scaleZ The scale factor applied along the z-axis.
868 void SetScale(float scaleX, float scaleY, float scaleZ);
871 * @brief Set the scale factor applied to an actor.
873 * @pre The Actor has been initialized.
874 * @note This is an asynchronous method; the value written may not match a value subsequently read with GetCurrentScale().
875 * @param [in] scale A vector representing the scale factor for each axis.
877 void SetScale(const Vector3& scale);
880 * @brief Apply a relative scale to an actor.
882 * @pre The actor has been initialized.
883 * @param[in] relativeScale The scale to combine with the actors existing scale.
885 void ScaleBy(const Vector3& relativeScale);
888 * @brief Retrieve the scale factor applied to an actor.
890 * @pre The Actor has been initialized.
891 * @note This property can be animated; the return value may not match the value written with SetScale().
892 * @return A vector representing the scale factor for each axis.
894 Vector3 GetCurrentScale() const;
897 * @brief Retrieve the world-scale of the Actor.
899 * @note The actor will not have a world-scale, unless it has previously been added to the stage.
900 * @pre The Actor has been initialized.
901 * @return The Actor's current scale in the world.
903 Vector3 GetCurrentWorldScale() const;
906 * @brief Set whether a child actor inherits it's parent's scale.
908 * Default is to inherit.
909 * Switching this off means that using SetScale() sets the actor's world scale.
910 * @pre The Actor has been initialized.
911 * @param[in] inherit - true if the actor should inherit scale, false otherwise.
913 void SetInheritScale( bool inherit );
916 * @brief Returns whether the actor inherit's it's parent's scale.
918 * @pre The Actor has been initialized.
919 * @return true if the actor inherit's it's parent scale, false if it uses world scale.
921 bool IsScaleInherited() const;
924 * @brief Retrieves the world-matrix of the actor.
926 * @note The actor will not have a world-matrix, unless it has previously been added to the stage.
927 * @pre The Actor has been initialized.
928 * @return The Actor's current world matrix
930 Matrix GetCurrentWorldMatrix() const;
932 // Visibility & Color
935 * @brief Sets the visibility flag of an actor.
937 * @pre The actor has been initialized.
938 * @note This is an asynchronous method; the value written may not match a value subsequently read with IsVisible().
939 * @note If an actor's visibility flag is set to false, then the actor and its children will not be rendered.
940 * This is regardless of the individual visibility values of the children i.e. an actor will only be
941 * rendered if all of its parents have visibility set to true.
942 * @param [in] visible The new visibility flag.
944 void SetVisible(bool visible);
947 * @brief Retrieve the visibility flag of an actor.
949 * @pre The actor has been initialized.
950 * @note This property can be animated; the return value may not match the value written with SetVisible().
951 * @note If an actor is not visible, then the actor and its children will not be rendered.
952 * This is regardless of the individual visibility values of the children i.e. an actor will only be
953 * rendered if all of its parents have visibility set to true.
954 * @return The visibility flag.
956 bool IsVisible() const;
959 * @brief Sets the opacity of an actor.
961 * @pre The actor has been initialized.
962 * @note This is an asynchronous method; the value written may not match a value subsequently read with GetCurrentOpacity().
963 * @param [in] opacity The new opacity.
965 void SetOpacity(float opacity);
968 * @brief Apply a relative opacity change to an actor.
970 * @pre The actor has been initialized.
971 * @param[in] relativeOpacity The opacity to combine with the actors existing opacity.
973 void OpacityBy(float relativeOpacity);
976 * @brief Retrieve the actor's opacity.
978 * @pre The actor has been initialized.
979 * @note This property can be animated; the return value may not match the value written with SetOpacity().
980 * @return The actor's opacity.
982 float GetCurrentOpacity() const;
985 * @brief Sets the actor's color; this is an RGBA value.
987 * The final color of the actor depends on its color mode.
988 * @pre The Actor has been initialized.
989 * @note This is an asynchronous method; the value written may not match a value subsequently read with GetCurrentColor().
990 * @param [in] color The new color.
992 void SetColor(const Vector4& color);
995 * @brief Apply a relative color change to an actor.
997 * @pre The actor has been initialized.
998 * @param[in] relativeColor The color to combine with the actors existing color.
1000 void ColorBy(const Vector4& relativeColor);
1003 * @brief Retrieve the actor's color.
1005 * Actor's own color is not clamped.
1006 * @pre The Actor has been initialized.
1007 * @note This property can be animated; the return value may not match the value written with SetColor().
1008 * @return The color.
1010 Vector4 GetCurrentColor() const;
1013 * @brief Sets the actor's color mode.
1015 * This specifies whether the Actor uses its own color, or inherits
1016 * its parent color. The default is USE_OWN_MULTIPLY_PARENT_ALPHA.
1017 * @pre The Actor has been initialized.
1018 * @param [in] colorMode to use.
1020 void SetColorMode( ColorMode colorMode );
1023 * @brief Returns the actor's color mode.
1025 * @pre The Actor has been initialized.
1026 * @return currently used colorMode.
1028 ColorMode GetColorMode() const;
1031 * @brief Retrieve the world-color of the Actor, where each component is clamped within the 0->1 range.
1033 * @note The actor will not have a world-color, unless it has previously been added to the stage.
1034 * @pre The Actor has been initialized.
1035 * @return The Actor's current color in the world.
1037 Vector4 GetCurrentWorldColor() const;
1040 * @brief Set how the actor and its children should be drawn.
1042 * Not all actors are renderable, but DrawMode can be inherited from any actor.
1043 * By default a renderable actor will be drawn as a 3D object. It will be depth-tested against
1044 * other objects in the world i.e. it may be obscured if other objects are in front.
1046 * If DrawMode::OVERLAY is used, the actor and its children will be drawn as a 2D overlay.
1047 * Overlay actors are drawn in a separate pass, after all non-overlay actors within the Layer.
1048 * For overlay actors, the drawing order is determined by the hierachy (depth-first search order),
1049 * and depth-testing will not be used.
1051 * If DrawMode::STENCIL is used, the actor and its children will be used to stencil-test other actors
1052 * within the Layer. Stencil actors are therefore drawn into the stencil buffer before any other
1053 * actors within the Layer.
1055 * @param[in] drawMode The new draw-mode to use.
1056 * @note Setting STENCIL will override OVERLAY, if that would otherwise have been inherited.
1057 * @note Layers do not inherit the DrawMode from their parents.
1059 void SetDrawMode( DrawMode::Type drawMode );
1062 * @brief Query how the actor and its children will be drawn.
1064 * @return True if the Actor is an overlay.
1066 DrawMode::Type GetDrawMode() const;
1071 * @brief Sets whether an actor should emit touch or hover signals; see SignalTouch() and SignalHover().
1073 * An actor is sensitive by default, which means that as soon as an application connects to the SignalTouch(),
1074 * the touch event signal will be emitted, and as soon as an application connects to the SignalHover(), the
1075 * hover event signal will be emitted.
1077 * If the application wishes to temporarily disable the touch or hover event signal emission, then they can do so by calling:
1079 * actor.SetSensitive(false);
1082 * Then, to re-enable the touch or hover event signal emission, the application should call:
1084 * actor.SetSensitive(true);
1087 * @see @see SignalTouch() and SignalHover().
1088 * @note If an actor's sensitivity is set to false, then it's children will not be hittable either.
1089 * This is regardless of the individual sensitivity values of the children i.e. an actor will only be
1090 * hittable if all of its parents have sensitivity set to true.
1091 * @pre The Actor has been initialized.
1092 * @param[in] sensitive true to enable emission of the touch or hover event signals, false otherwise.
1094 void SetSensitive(bool sensitive);
1097 * @brief Query whether an actor emits touch or hover event signals.
1099 * @note If an actor is not sensitive, then it's children will not be hittable either.
1100 * This is regardless of the individual sensitivity values of the children i.e. an actor will only be
1101 * hittable if all of its parents have sensitivity set to true.
1102 * @pre The Actor has been initialized.
1103 * @return true, if emission of touch or hover event signals is enabled, false otherwise.
1105 bool IsSensitive() const;
1108 * @brief Converts screen coordinates into the actor's coordinate system using the default camera.
1110 * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
1111 * @pre The Actor has been initialized.
1112 * @param[out] localX On return, the X-coordinate relative to the actor.
1113 * @param[out] localY On return, the Y-coordinate relative to the actor.
1114 * @param[in] screenX The screen X-coordinate.
1115 * @param[in] screenY The screen Y-coordinate.
1116 * @return True if the conversion succeeded.
1118 bool ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const;
1121 * @brief Sets whether the actor should receive a notification when touch or hover motion events leave
1122 * the boundary of the actor.
1124 * @note By default, this is set to false as most actors do not require this.
1125 * @note Need to connect to the SignalTouch or SignalHover to actually receive this event.
1127 * @pre The Actor has been initialized.
1128 * @param[in] required Should be set to true if a Leave event is required
1130 void SetLeaveRequired(bool required);
1133 * @brief This returns whether the actor requires touch or hover events whenever touch or hover motion events leave
1134 * the boundary of the actor.
1136 * @pre The Actor has been initialized.
1137 * @return true if a Leave event is required, false otherwise.
1139 bool GetLeaveRequired() const;
1142 * @brief Sets whether the actor should be focusable by keyboard navigation.
1144 * The default is true.
1145 * @pre The Actor has been initialized.
1146 * @param[in] focusable - true if the actor should be focusable by keyboard navigation,
1149 void SetKeyboardFocusable( bool focusable );
1152 * @brief Returns whether the actor is focusable by keyboard navigation.
1154 * @pre The Actor has been initialized.
1155 * @return true if the actor is focusable by keyboard navigation, false if not.
1157 bool IsKeyboardFocusable() const;
1162 * @brief This signal is emitted when touch input is received.
1164 * A callback of the following type may be connected:
1166 * bool YourCallbackName(Actor actor, const TouchEvent& event);
1168 * The return value of True, indicates that the touch event should be consumed.
1169 * Otherwise the signal will be emitted on the next sensitive parent of the actor.
1170 * @pre The Actor has been initialized.
1171 * @return The signal to connect to.
1173 TouchSignalType& TouchedSignal();
1176 * @brief This signal is emitted when hover input is received.
1178 * A callback of the following type may be connected:
1180 * bool YourCallbackName(Actor actor, const HoverEvent& event);
1182 * The return value of True, indicates that the hover event should be consumed.
1183 * Otherwise the signal will be emitted on the next sensitive parent of the actor.
1184 * @pre The Actor has been initialized.
1185 * @return The signal to connect to.
1187 HoverSignalType& HoveredSignal();
1190 * @brief This signal is emitted when mouse wheel event is received.
1192 * A callback of the following type may be connected:
1194 * bool YourCallbackName(Actor actor, const MouseWheelEvent& event);
1196 * The return value of True, indicates that the mouse wheel event should be consumed.
1197 * Otherwise the signal will be emitted on the next sensitive parent of the actor.
1198 * @pre The Actor has been initialized.
1199 * @return The signal to connect to.
1201 MouseWheelEventSignalType& MouseWheelEventSignal();
1204 * @brief Signal to indicate when the actor's size is set by application code.
1206 * This signal is emitted when actors size is being <b>set</b> by application code.
1207 * This signal is <b>not</b> emitted when size is animated
1208 * Note! GetCurrentSize might not return this same size as the set size message may still be queued
1209 * A callback of the following type may be connected:
1211 * void YourCallback(Actor actor, const Vector3& newSize);
1213 * @pre The Actor has been initialized.
1214 * @return The signal to connect to.
1216 SetSizeSignalType& SetSizeSignal();
1219 * @brief This signal is emitted after the actor has been connected to the stage.
1221 * When an actor is connected, it will be directly or indirectly parented to the root Actor.
1222 * @note The root Actor is provided automatically by Dali::Stage, and is always considered to be connected.
1224 * @note When the parent of a set of actors is connected to the stage, then all of the children
1225 * will received this callback.
1227 * For the following actor tree, the callback order will be A, B, D, E, C, and finally F.
1235 * @return The signal
1237 OnStageSignalType& OnStageSignal();
1240 * @brief This signal is emitted after the actor has been disconnected from the stage.
1242 * If an actor is disconnected it either has no parent, or is parented to a disconnected actor.
1244 * @note When the parent of a set of actors is disconnected to the stage, then all of the children
1245 * will received this callback, starting with the leaf actors.
1247 * For the following actor tree, the callback order will be D, E, B, F, C, and finally A.
1255 * @return The signal
1257 OffStageSignalType& OffStageSignal();
1262 * @brief Enable dynamics for this actor.
1264 * The actor will behave as a rigid/soft body in the simulation
1265 * @pre The actor is not already acting as a DynamicsBody and IsDynamicsRoot() returns false
1267 * @param [in] bodyConfig The DynamicsBodyConfig specifying the dynamics properties for this actor in the dynamics world.
1268 * @return The DynamicsBody
1270 DynamicsBody EnableDynamics(DynamicsBodyConfig bodyConfig);
1273 * @brief Add a joint constraint to this actor.
1275 * @param[in] attachedActor The other actor in the joint
1276 * @param[in] offset The offset (relative to this actor) of the origin of the joint
1277 * @return The new joint
1278 * @pre Both actors are dynamics enabled actors (IE Actor::EnableDynamics()) has been invoked for both actors).
1279 * @post If the two actors are already connected by a joint, The existing joint is returned
1280 * and offset is ignored.
1282 DynamicsJoint AddDynamicsJoint( Actor attachedActor, const Vector3& offset );
1285 * @brief Add a joint constraint to this actor.
1287 * @param[in] attachedActor The other actor in the joint
1288 * @param[in] offsetA The offset (relative to this actor) of the origin of the joint
1289 * @param[in] offsetB The offset (relative to attachedActor) of the origin of the joint
1290 * @return The new joint
1291 * @pre Both actors are dynamics enabled actors (IE Actor::EnableDynamics()) has been invoked for both actors).
1292 * @post If the two actors are already connected by a joint, The existing joint is returned
1293 * and offset is ignored.
1295 DynamicsJoint AddDynamicsJoint( Actor attachedActor, const Vector3& offsetA, const Vector3& offsetB );
1298 * @brief Get the number of DynamicsJoint objects added to this actor.
1300 * @return The number of DynamicsJoint objects added to this actor
1302 int GetNumberOfJoints() const;
1305 * @brief Get a joint by index.
1307 * @param[in] index The index of the joint.
1308 * Use GetNumberOfJoints to get the valid range of indices.
1309 * @return The joint.
1311 DynamicsJoint GetDynamicsJointByIndex( const int index );
1314 * @brief Get the joint between this actor and attachedActor.
1316 * @param[in] attachedActor The other actor in the joint
1317 * @return The joint.
1319 DynamicsJoint GetDynamicsJoint( Actor attachedActor );
1322 * @brief Remove a joint from this actor
1324 * @param[in] joint The joint to be removed
1326 void RemoveDynamicsJoint( DynamicsJoint joint );
1329 * @brief Disable dynamics for this actor.
1331 * The actor will be detached from the DynamicsBody/DynamicsJoint associated with it through EnableDynamics
1333 void DisableDynamics();
1336 * @brief Get the associated DynamicsBody.
1338 * @return A DynamicsBody
1340 DynamicsBody GetDynamicsBody();
1342 public: // Not intended for application developers
1345 * @brief This constructor is used by Dali New() methods.
1347 * @param [in] actor A pointer to a newly allocated Dali resource
1349 explicit DALI_INTERNAL Actor(Internal::Actor* actor);
1353 * @brief Helper for discarding an actor handle.
1355 * If the handle is empty, this method does nothing. Otherwise
1356 * actor.Unparent() will be called, followed by actor.Reset().
1357 * @param[in,out] actor A handle to an actor, or an empty handle.
1359 DALI_IMPORT_API void UnparentAndReset( Actor& actor );
1363 #endif // __DALI_ACTOR_H__