1 #ifndef __DALI_INTERNAL_ACTOR_H__
2 #define __DALI_INTERNAL_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.
25 #include <dali/public-api/common/vector-wrapper.h>
26 #include <dali/public-api/object/ref-object.h>
27 #include <dali/public-api/actors/actor.h>
28 #include <dali/public-api/common/dali-common.h>
29 #include <dali/public-api/events/gesture.h>
30 #include <dali/public-api/math/viewport.h>
31 #include <dali/internal/event/common/object-impl.h>
32 #include <dali/internal/event/common/stage-def.h>
33 #include <dali/internal/event/actors/actor-declarations.h>
34 #include <dali/internal/event/actors/renderer-impl.h>
35 #include <dali/internal/event/actor-attachments/actor-attachment-declarations.h>
36 #include <dali/internal/update/nodes/node-declarations.h>
38 #ifdef DYNAMICS_SUPPORT
39 #include <dali/internal/event/dynamics/dynamics-declarations.h>
48 struct MouseWheelEvent;
54 class ActorGestureData;
60 typedef IntrusivePtr<Actor> ActorPtr;
61 typedef Dali::ActorContainer ActorContainer; // Store handles to return via public-api
62 typedef ActorContainer::iterator ActorIter;
63 typedef ActorContainer::const_iterator ActorConstIter;
66 * Actor is the primary object which Dali applications interact with.
67 * UI controls can be built by combining multiple actors.
68 * Multi-Touch events are received through signals emitted by the actor tree.
70 * An Actor is a proxy for a Node in the scene graph.
71 * When an Actor is added to the Stage, it creates a node and attaches it to the scene graph.
72 * The scene-graph can be updated in a separate thread, so the attachment is done using an asynchronous message.
73 * When a tree of Actors is detached from the Stage, a message is sent to destroy the associated nodes.
75 class Actor : public Object
81 * @return A smart-pointer to the newly allocated Actor.
83 static ActorPtr New();
86 * Retrieve the name of the actor.
89 const std::string& GetName() const;
92 * Set the name of the actor.
93 * @param[in] name The new name.
95 void SetName(const std::string& name);
98 * @copydoc Dali::Actor::GetId
100 unsigned int GetId() const;
105 * Attach an object to an actor.
106 * @pre The actor does not already have an attachment.
107 * @param[in] attachment The object to attach.
109 void Attach(ActorAttachment& attachment);
112 * Retreive the object attached to an actor.
113 * @return The attachment.
115 ActorAttachmentPtr GetAttachment();
120 * Query whether an actor is the root actor, which is owned by the Stage.
121 * @return True if the actor is a root actor.
129 * Query whether the actor is connected to the Stage.
131 bool OnStage() const;
134 * Query whether the actor is a RenderableActor derived type.
135 * @return True if the actor is renderable.
137 bool IsRenderable() const
139 // inlined as this is called a lot in hit testing
140 return mIsRenderable;
144 * Query whether the actor is of class Dali::Layer
145 * @return True if the actor is a layer.
149 // inlined as this is called a lot in hit testing
154 * Gets the layer in which the actor is present
155 * @return The layer, which will be uninitialized if the actor is off-stage.
157 Dali::Layer GetLayer();
160 * Adds a child Actor to this Actor.
161 * @pre The child actor is not the same as the parent actor.
162 * @pre The child actor does not already have a parent.
163 * @param [in] child The child.
164 * @post The child will be referenced by its parent.
166 void Add(Actor& child);
169 * Inserts a child Actor to this Actor's child list
170 * @pre The child actor is not the same as the parent actor.
171 * @pre The child actor does not already have a parent.
172 * @param [in] index in childlist to insert child at
173 * @param [in] child The child.
174 * @post The child will be referenced by its parent.
176 void Insert(unsigned int index, Actor& child);
179 * Removes a child Actor from this Actor.
180 * @param [in] child The child.
181 * @post The child will be unreferenced.
183 void Remove(Actor& child);
186 * @copydoc Dali::Actor::Unparent
191 * Retrieve the number of children held by the actor.
192 * @return The number of children
194 unsigned int GetChildCount() const;
197 * @copydoc Dali::Actor::GetChildAt
199 Dali::Actor GetChildAt(unsigned int index) const;
202 * Retrieve the Actor's children.
203 * @return A copy of the container of children.
205 ActorContainer GetChildren();
208 * Retrieve the Actor's children.
209 * @return A const reference to the container of children.
211 const ActorContainer& GetChildren() const;
214 * Retrieve a reference to Actor's children.
215 * @note Not for public use.
216 * @return A reference to the container of children.
218 ActorContainer& GetChildrenInternal()
224 * @copydoc Dali::Actor::FindChildByName
226 ActorPtr FindChildByName(const std::string& actorName);
229 * @copydoc Dali::Actor::FindChildByAlias
231 Dali::Actor FindChildByAlias(const std::string& actorAlias);
234 * @copydoc Dali::Actor::FindChildById
236 ActorPtr FindChildById(const unsigned int id);
239 * Retrieve the parent of an Actor.
240 * @return The parent actor, or NULL if the Actor does not have a parent.
242 Actor* GetParent() const
248 * Sets the size of an actor.
249 * ActorAttachments attached to the actor, can be scaled to fit within this area.
250 * This does not interfere with the actors scale factor.
251 * @param [in] width The new width.
252 * @param [in] height The new height.
254 void SetSize(float width, float height);
257 * Sets the size of an actor.
258 * ActorAttachments attached to the actor, can be scaled to fit within this area.
259 * This does not interfere with the actors scale factor.
260 * @param [in] width The size of the actor along the x-axis.
261 * @param [in] height The size of the actor along the y-axis.
262 * @param [in] depth The size of the actor along the z-axis.
264 void SetSize(float width, float height, float depth);
267 * Sets the size of an actor.
268 * ActorAttachments attached to the actor, can be scaled to fit within this area.
269 * This does not interfere with the actors scale factor.
270 * @param [in] size The new size.
272 void SetSize(const Vector2& size);
275 * Sets the size of an actor.
276 * ActorAttachments attached to the actor, can be scaled to fit within this area.
277 * This does not interfere with the actors scale factor.
278 * @param [in] size The new size.
280 void SetSize(const Vector3& size);
283 * Set the width component of the Actor's size.
284 * @param [in] width The new width component.
286 void SetWidth( float width );
289 * Set the height component of the Actor's size.
290 * @param [in] height The new height component.
292 void SetHeight( float height );
295 * Set the depth component of the Actor's size.
296 * @param [in] depth The new depth component.
298 void SetDepth( float depth );
301 * Retrieve the Actor's size from event side.
302 * This size will be the size set or if animating then the target size.
303 * @return The Actor's size.
305 const Vector3& GetSize() const;
308 * Retrieve the Actor's size from update side.
309 * This size will be the size set or animating but will be a frame behind.
310 * @return The Actor's size.
312 const Vector3& GetCurrentSize() const;
315 * Return the natural size of the actor
317 * @return The actor's natural size
319 virtual Vector3 GetNaturalSize() const;
322 * Set the origin of an actor, within its parent's area.
323 * This is expressed in 2D unit coordinates, such that (0.0, 0.0, 0.5) is the top-left corner of the parent,
324 * and (1.0, 1.0, 0.5) is the bottom-right corner.
325 * The default parent-origin is top-left (0.0, 0.0, 0.5).
326 * An actor position is the distance between this origin, and the actors anchor-point.
327 * @param [in] origin The new parent-origin.
329 void SetParentOrigin(const Vector3& origin);
332 * Set the x component of the parent-origin
333 * @param [in] x The new x value.
335 void SetParentOriginX( float x );
338 * Set the y component of the parent-origin
339 * @param [in] y The new y value.
341 void SetParentOriginY( float y );
344 * Set the z component of the parent-origin
345 * @param [in] z The new z value.
347 void SetParentOriginZ( float z );
350 * Retrieve the parent-origin of an actor.
351 * @return The parent-origin.
353 const Vector3& GetCurrentParentOrigin() const;
356 * Set the anchor-point of an actor. This is expressed in 2D unit coordinates, such that
357 * (0.0, 0.0, 0.5) is the top-left corner of the actor, and (1.0, 1.0, 0.5) is the bottom-right corner.
358 * The default anchor point is top-left (0.0, 0.0, 0.5).
359 * An actor position is the distance between its parent-origin, and this anchor-point.
360 * An actor's rotation is centered around its anchor-point.
361 * @param [in] anchorPoint The new anchor-point.
363 void SetAnchorPoint(const Vector3& anchorPoint);
366 * Set the x component of the anchor-point.
367 * @param [in] x The new x value.
369 void SetAnchorPointX( float x );
372 * Set the y component of the anchor-point.
373 * @param [in] y The new y value.
375 void SetAnchorPointY( float y );
378 * Set the z component of the anchor-point.
379 * @param [in] z The new z value.
381 void SetAnchorPointZ( float z );
384 * Retrieve the anchor-point of an actor.
385 * @return The anchor-point.
387 const Vector3& GetCurrentAnchorPoint() const;
390 * Sets the position of the Actor.
391 * The coordinates are relative to the Actor's parent.
392 * The Actor's z position will be set to 0.0f.
393 * @param [in] x The new x position
394 * @param [in] y The new y position
396 void SetPosition(float x, float y);
399 * Sets the position of the Actor.
400 * The coordinates are relative to the Actor's parent.
401 * @param [in] x The new x position
402 * @param [in] y The new y position
403 * @param [in] z The new z position
405 void SetPosition(float x, float y, float z);
408 * Sets the position of the Actor.
409 * The coordinates are relative to the Actor's parent.
410 * @param [in] position The new position.
412 void SetPosition(const Vector3& position);
415 * Set the position of an actor along the X-axis.
416 * @param [in] x The new x position
421 * Set the position of an actor along the Y-axis.
422 * @param [in] y The new y position.
427 * Set the position of an actor along the Z-axis.
428 * @param [in] z The new z position
433 * Move an actor relative to its existing position.
434 * @param[in] distance The actor will move by this distance.
436 void MoveBy(const Vector3& distance);
439 * Retrieve the position of the Actor.
440 * The coordinates are relative to the Actor's parent.
441 * @return the Actor's position.
443 const Vector3& GetCurrentPosition() const;
446 * @copydoc Dali::Actor::GetCurrentWorldPosition()
448 const Vector3& GetCurrentWorldPosition() const;
451 * @copydoc Dali::Actor::SetPositionInheritanceMode()
453 void SetPositionInheritanceMode( PositionInheritanceMode mode );
456 * @copydoc Dali::Actor::GetPositionInheritanceMode()
458 PositionInheritanceMode GetPositionInheritanceMode() const;
461 * Sets the rotation of the Actor.
462 * @param [in] angleRadians The new rotation angle in radians.
463 * @param [in] axis The new axis of rotation.
465 void SetRotation(const Radian& angleRadians, const Vector3& axis);
468 * Sets the rotation of the Actor.
469 * @param [in] rotation The new rotation.
471 void SetRotation(const Quaternion& rotation);
474 * Rotate an actor around its existing rotation axis.
475 * @param[in] angleRadians The angle to the rotation to combine with the existing rotation.
476 * @param[in] axis The axis of the rotation to combine with the existing rotation.
478 void RotateBy(const Radian& angleRadians, const Vector3& axis);
481 * Apply a relative rotation to an actor.
482 * @param[in] relativeRotation The rotation to combine with the actors existing rotation.
484 void RotateBy(const Quaternion& relativeRotation);
487 * Retreive the Actor's rotation.
488 * @return the rotation.
490 const Quaternion& GetCurrentRotation() const;
493 * Set whether a child actor inherits it's parent's orientation. Default is to inherit.
494 * Switching this off means that using SetRotation() sets the actor's world orientation.
495 * @param[in] inherit - true if the actor should inherit orientation, false otherwise.
497 void SetInheritRotation(bool inherit);
500 * Returns whether the actor inherit's it's parent's orientation.
501 * @return true if the actor inherit's it's parent orientation, false if it uses world orientation.
503 bool IsRotationInherited() const;
506 * @brief Defines how a child actors size is affected by its parents size.
507 * @param[in] mode The size relative to parent mode to use.
509 void SetSizeMode(SizeMode mode);
512 * Query how the child actors size is affected by its parents size.
513 * @return The size relative to parent mode in use.
515 SizeMode GetSizeMode() const;
518 * Sets the factor of the parents size used for the child actor.
519 * Note: Only used if SizeMode is SIZE_RELATIVE_TO_PARENT or SIZE_FIXED_OFFSET_FROM_PARENT.
520 * @param[in] factor The vector to multiply the parents size by to get the childs size.
522 void SetSizeModeFactor(const Vector3& factor);
525 * Gets the factor of the parents size used for the child actor.
526 * Note: Only used if SizeMode is SIZE_RELATIVE_TO_PARENT or SIZE_FIXED_OFFSET_FROM_PARENT.
527 * @return The vector being used to multiply the parents size by to get the childs size.
529 const Vector3& GetSizeModeFactor() const;
532 * @copydoc Dali::Actor::GetCurrentWorldRotation()
534 const Quaternion& GetCurrentWorldRotation() const;
537 * Sets a scale factor applied to an actor.
538 * @param [in] scale The scale factor applied on all axes.
540 void SetScale(float scale);
543 * Sets a scale factor applied to an actor.
544 * @param [in] scaleX The scale factor applied along the x-axis.
545 * @param [in] scaleY The scale factor applied along the y-axis.
546 * @param [in] scaleZ The scale factor applied along the z-axis.
548 void SetScale(float scaleX, float scaleY, float scaleZ);
551 * Sets a scale factor applied to an actor.
552 * @param [in] scale A vector representing the scale factor for each axis.
554 void SetScale(const Vector3& scale);
557 * Set the x component of the scale factor.
558 * @param [in] x The new x value.
560 void SetScaleX( float x );
563 * Set the y component of the scale factor.
564 * @param [in] y The new y value.
566 void SetScaleY( float y );
569 * Set the z component of the scale factor.
570 * @param [in] z The new z value.
572 void SetScaleZ( float z );
575 * Apply a relative scale to an actor.
576 * @param[in] relativeScale The scale to combine with the actors existing scale.
578 void ScaleBy(const Vector3& relativeScale);
581 * Retrieve the scale factor applied to an actor.
582 * @return A vector representing the scale factor for each axis.
584 const Vector3& GetCurrentScale() const;
587 * @copydoc Dali::Actor::GetCurrentWorldScale()
589 const Vector3& GetCurrentWorldScale() const;
592 * @copydoc Dali::Actor::SetInheritScale()
594 void SetInheritScale( bool inherit );
597 * @copydoc Dali::Actor::IsScaleInherited()
599 bool IsScaleInherited() const;
602 * @copydoc Dali::Actor::GetCurrentWorldMatrix()
604 Matrix GetCurrentWorldMatrix() const;
609 * Sets the visibility flag of an actor.
610 * @param [in] visible The new visibility flag.
612 void SetVisible(bool visible);
615 * Retrieve the visibility flag of an actor.
616 * @return The visibility flag.
618 bool IsVisible() const;
621 * Sets the opacity of an actor.
622 * @param [in] opacity The new opacity.
624 void SetOpacity(float opacity);
627 * Apply a relative opacity change to an actor.
628 * @param[in] relativeOpacity The opacity to combine with the actors existing opacity.
630 void OpacityBy(float relativeOpacity);
633 * Retrieve the actor's opacity.
634 * @return The actor's opacity.
636 float GetCurrentOpacity() const;
639 * Sets whether an actor should emit touch or hover signals; see SignalTouch() and SignalHover().
640 * An actor is sensitive by default, which means that as soon as an application connects to the SignalTouch(),
641 * the touch event signal will be emitted, and as soon as an application connects to the SignalHover(), the
642 * hover event signal will be emitted.
644 * If the application wishes to temporarily disable the touch or hover event signal emission, then they can do so by calling:
646 * actor.SetSensitive(false);
649 * Then, to re-enable the touch or hover event signal emission, the application should call:
651 * actor.SetSensitive(true);
654 * @see SignalTouch() and SignalHover().
655 * @note If an actor's sensitivity is set to false, then it's children will not emit a touch or hover event signal either.
656 * @param[in] sensitive true to enable emission of the touch or hover event signals, false otherwise.
658 void SetSensitive(bool sensitive)
660 mSensitive = sensitive;
664 * Query whether an actor emits touch or hover event signals.
665 * @see SetSensitive(bool)
666 * @return true, if emission of touch or hover event signals is enabled, false otherwise.
668 bool IsSensitive() const
674 * @copydoc Dali::Actor::SetDrawMode
676 void SetDrawMode( DrawMode::Type drawMode );
679 * @copydoc Dali::Actor::GetDrawMode
681 DrawMode::Type GetDrawMode() const;
684 * @copydoc Dali::Actor::SetOverlay
686 void SetOverlay(bool enable);
689 * @copydoc Dali::Actor::IsOverlay
691 bool IsOverlay() const;
694 * Sets the actor's color. The final color of actor depends on its color mode.
695 * This final color is applied to the drawable elements of an actor.
696 * @param [in] color The new color.
698 void SetColor(const Vector4& color);
701 * Set the red component of the color.
702 * @param [in] red The new red component.
704 void SetColorRed( float red );
707 * Set the green component of the color.
708 * @param [in] green The new green component.
710 void SetColorGreen( float green );
713 * Set the blue component of the scale factor.
714 * @param [in] blue The new blue value.
716 void SetColorBlue( float blue );
719 * Apply a relative color change to an actor.
720 * @param[in] relativeColor The color to combine with the actors existing color.
722 void ColorBy(const Vector4& relativeColor);
725 * Retrieve the actor's color.
728 const Vector4& GetCurrentColor() const;
731 * Sets the actor's color mode.
732 * Color mode specifies whether Actor uses its own color or inherits its parent color
733 * @param [in] colorMode to use.
735 void SetColorMode(ColorMode colorMode);
738 * Returns the actor's color mode.
739 * @return currently used colorMode.
741 ColorMode GetColorMode() const;
744 * @copydoc Dali::Actor::GetCurrentWorldColor()
746 const Vector4& GetCurrentWorldColor() const;
749 * @copydoc Dali::Actor::AddRenderer()
751 unsigned int AddRenderer( Renderer& renderer );
754 * @copydoc Dali::Actor::GetRendererCount()
756 unsigned int GetRendererCount() const;
759 * @copydoc Dali::Actor::GetRendererAt()
761 Renderer& GetRendererAt( unsigned int index );
764 * @copydoc Dali::Actor::RemoveRenderer()
766 void RemoveRenderer( Renderer& renderer );
769 * @copydoc Dali::Actor::RemoveRenderer()
771 void RemoveRenderer( unsigned int index );
773 #ifdef DYNAMICS_SUPPORT
777 /// @copydoc Dali::Actor::DisableDynamics
778 void DisableDynamics();
780 /// @copydoc Dali::Actor::EnableDynamics(Dali::DynamicsBodyConfig)
781 DynamicsBodyPtr EnableDynamics(DynamicsBodyConfigPtr bodyConfig);
783 /// @copydoc Dali::Actor::GetDynamicsBody
784 DynamicsBodyPtr GetDynamicsBody() const;
786 /// @copydoc Dali::Actor::AddDynamicsJoint(Dali::Actor,const Vector3&)
787 DynamicsJointPtr AddDynamicsJoint( ActorPtr attachedActor, const Vector3& offset );
789 /// @copydoc Dali::Actor::AddDynamicsJoint(Dali::Actor,const Vector3&,const Vector3&)
790 DynamicsJointPtr AddDynamicsJoint( ActorPtr attachedActor, const Vector3& offsetA, const Vector3& offsetB );
792 /// @copydoc Dali::Actor::GetNumberOfJoints
793 const int GetNumberOfJoints() const;
795 /// @copydoc Dali::Actor::GetDynamicsJointByIndex
796 DynamicsJointPtr GetDynamicsJointByIndex( const int index ) const;
798 /// @copydoc Dali::Actor::GetDynamicsJoint
799 DynamicsJointPtr GetDynamicsJoint( ActorPtr attachedActor ) const;
801 /// @copydoc Dali::Actor::RemoveDynamicsJoint
802 void RemoveDynamicsJoint( DynamicsJointPtr joint );
805 * Hold a reference to a DynamicsJoint
806 * @param[in] joint The joint
808 void ReferenceJoint( DynamicsJointPtr joint );
811 * Release a reference to a DynamicsJoint
812 * @param[in] joint The joint
814 void ReleaseJoint( DynamicsJointPtr joint );
817 * Set this actor to be the root actor in the dynamics simulation
818 * All children of the actor are added/removed from the simulation.
819 * @param[in] flag When true sets this actor to be the simulation world root actor and
820 * if OnStage() all dynamics enabled child actors are added to the simulation,
821 * when false stops this actor being the simulation root and if OnStage() all
822 * dynamics enabled child actors are removed from the simulation.
824 void SetDynamicsRoot(bool flag);
828 * Check if this actor is the root actor in the dynamics simulation
829 * @return true if this is the dynamics root actor.
831 bool IsDynamicsRoot() const;
834 * Add actor to the dynamics simulation
835 * Invoked when the actor is staged, or it's parent becomes the simulation root
837 void ConnectDynamics();
840 * Remove actor from the dynamics simulation
841 * Invoked when the actor is unstaged, or it's parent stops being the the simulation root
843 void DisconnectDynamics();
846 * An actor in a DynamicsJoint relationship has been staged
847 * @param[in] actor The actor passed into AddDynamicsJoint()
849 void AttachedActorOnStage( Dali::Actor actor );
852 * An actor in a DynamicsJoint relationship has been unstaged
853 * @param[in] actor The actor passed into AddDynamicsJoint()
855 void AttachedActorOffStage( Dali::Actor actor );
857 #endif // DYNAMICS_SUPPORT
861 * Converts screen coordinates into the actor's coordinate system.
862 * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
863 * @param[out] localX On return, the X-coordinate relative to the actor.
864 * @param[out] localY On return, the Y-coordinate relative to the actor.
865 * @param[in] screenX The screen X-coordinate.
866 * @param[in] screenY The screen Y-coordinate.
867 * @return True if the conversion succeeded.
869 bool ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const;
872 * Converts screen coordinates into the actor's coordinate system.
873 * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
874 * @param[in] renderTask The render-task used to display the actor.
875 * @param[out] localX On return, the X-coordinate relative to the actor.
876 * @param[out] localY On return, the Y-coordinate relative to the actor.
877 * @param[in] screenX The screen X-coordinate.
878 * @param[in] screenY The screen Y-coordinate.
879 * @return True if the conversion succeeded.
881 bool ScreenToLocal(RenderTask& renderTask, float& localX, float& localY, float screenX, float screenY) const;
884 * Converts from the actor's coordinate system to screen coordinates.
885 * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
886 * @param[in] viewMatrix The view-matrix
887 * @param[in] projectionMatrix The projection-matrix
888 * @param[in] viewport The view-port
889 * @param[out] localX On return, the X-coordinate relative to the actor.
890 * @param[out] localY On return, the Y-coordinate relative to the actor.
891 * @param[in] screenX The screen X-coordinate.
892 * @param[in] screenY The screen Y-coordinate.
893 * @return True if the conversion succeeded.
895 bool ScreenToLocal( const Matrix& viewMatrix,
896 const Matrix& projectionMatrix,
897 const Viewport& viewport,
901 float screenY ) const;
904 * Performs a ray-sphere test with the given pick-ray and the actor's bounding sphere.
905 * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
906 * @param[in] rayOrigin The ray origin in the world's reference system.
907 * @param[in] rayDir The ray director vector in the world's reference system.
908 * @return True if the ray intersects the actor's bounding sphere.
910 bool RaySphereTest( const Vector4& rayOrigin, const Vector4& rayDir ) const;
913 * Performs a ray-actor test with the given pick-ray and the actor's geometry.
914 * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
915 * @param[in] rayOrigin The ray origin in the world's reference system.
916 * @param[in] rayDir The ray director vector in the world's reference system.
917 * @param[out] hitPointLocal The hit point in the Actor's local reference system.
918 * @param[out] distance The distance from the hit point to the camera.
919 * @return True if the ray intersects the actor's geometry.
921 bool RayActorTest( const Vector4& rayOrigin, const Vector4& rayDir, Vector4& hitPointLocal, float& distance ) const;
924 * Sets whether the actor should receive a notification when touch or hover motion events leave
925 * the boundary of the actor.
927 * @note By default, this is set to false as most actors do not require this.
928 * @note Need to connect to the SignalTouch or SignalHover to actually receive this event.
930 * @param[in] required Should be set to true if a Leave event is required
932 void SetLeaveRequired(bool required);
935 * This returns whether the actor requires touch or hover events whenever touch or hover motion events leave
936 * the boundary of the actor.
937 * @return true if a Leave event is required, false otherwise.
939 bool GetLeaveRequired() const;
942 * @copydoc Dali::Actor::SetKeyboardFocusable()
944 void SetKeyboardFocusable( bool focusable );
947 * @copydoc Dali::Actor::IsKeyboardFocusable()
949 bool IsKeyboardFocusable() const;
952 * Query whether the application or derived actor type requires touch events.
953 * @return True if touch events are required.
955 bool GetTouchRequired() const;
958 * Query whether the application or derived actor type requires hover events.
959 * @return True if hover events are required.
961 bool GetHoverRequired() const;
964 * Query whether the application or derived actor type requires mouse wheel events.
965 * @return True if mouse wheel events are required.
967 bool GetMouseWheelEventRequired() const;
970 * Query whether the actor is actually hittable. This method checks whether the actor is
971 * sensitive, has the visibility flag set to true and is not fully transparent.
972 * @return true, if it can be hit, false otherwise.
974 bool IsHittable() const;
979 * Retrieve the gesture data associated with this actor. The first call to this method will
980 * allocate space for the ActorGestureData so this should only be called if an actor really does
982 * @return Reference to the ActorGestureData for this actor.
983 * @note Once the gesture-data is created for an actor it is likely that gestures are required
984 * throughout the actor's lifetime so it will only be deleted when the actor is destroyed.
986 ActorGestureData& GetGestureData();
989 * Queries whether the actor requires the gesture type.
990 * @param[in] type The gesture type.
992 bool IsGestureRequred( Gesture::Type type ) const;
997 * Used by the EventProcessor to emit touch event signals.
998 * @param[in] event The touch event.
999 * @return True if the event was consumed.
1001 bool EmitTouchEventSignal(const TouchEvent& event);
1004 * Used by the EventProcessor to emit hover event signals.
1005 * @param[in] event The hover event.
1006 * @return True if the event was consumed.
1008 bool EmitHoverEventSignal(const HoverEvent& event);
1011 * Used by the EventProcessor to emit mouse wheel event signals.
1012 * @param[in] event The mouse wheel event.
1013 * @return True if the event was consumed.
1015 bool EmitMouseWheelEventSignal(const MouseWheelEvent& event);
1018 * @copydoc Dali::Actor::TouchedSignal()
1020 Dali::Actor::TouchSignalType& TouchedSignal();
1023 * @copydoc Dali::Actor::HoveredSignal()
1025 Dali::Actor::HoverSignalType& HoveredSignal();
1028 * @copydoc Dali::Actor::MouseWheelEventSignal()
1030 Dali::Actor::MouseWheelEventSignalType& MouseWheelEventSignal();
1033 * @copydoc Dali::Actor::OnStageSignal()
1035 Dali::Actor::OnStageSignalType& OnStageSignal();
1038 * @copydoc Dali::Actor::OffStageSignal()
1040 Dali::Actor::OffStageSignalType& OffStageSignal();
1043 * Connects a callback function with the object's signals.
1044 * @param[in] object The object providing the signal.
1045 * @param[in] tracker Used to disconnect the signal.
1046 * @param[in] signalName The signal to connect to.
1047 * @param[in] functor A newly allocated FunctorDelegate.
1048 * @return True if the signal was connected.
1049 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
1051 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
1054 * Performs actions as requested using the action name.
1055 * @param[in] object The object on which to perform the action.
1056 * @param[in] actionName The action to perform.
1057 * @param[in] attributes The attributes with which to perfrom this action.
1058 * @return true if the action was done.
1060 static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
1062 public: // For Animation
1065 * This should only be called by Animation, when the actor is resized using Animation::Resize().
1067 * @param[in] animation The animation that resized the actor
1068 * @param[in] targetSize The new target size of the actor
1070 void NotifySizeAnimation( Animation& animation, const Vector3& targetSize);
1073 * For use in derived classes.
1074 * This should only be called by Animation, when the actor is resized using Animation::Resize().
1076 virtual void OnSizeAnimation( Animation& animation, const Vector3& targetSize) {}
1089 * Protected Constructor. See Actor::New().
1090 * The second-phase construction Initialize() member should be called immediately after this.
1091 * @param[in] derivedType The derived type of actor (if any).
1093 Actor( DerivedType derivedType );
1096 * Second-phase constructor. Must be called immediately after creating a new Actor;
1098 void Initialize(void);
1101 * A reference counted object may only be deleted by calling Unreference()
1106 * Called on a child during Add() when the parent actor is connected to the Stage.
1107 * @param[in] stage The stage.
1108 * @param[in] index If set, it is only used for positioning the actor within the parent's child list.
1110 void ConnectToStage( int index = -1 );
1113 * Helper for ConnectToStage, to recursively connect a tree of actors.
1114 * This is atomic i.e. not interrupted by user callbacks.
1115 * @param[in] index If set, it is only used for positioning the actor within the parent's child list.
1116 * @param[out] connectionList On return, the list of connected actors which require notification.
1118 void RecursiveConnectToStage( ActorContainer& connectionList, int index = -1 );
1121 * Connect the Node associated with this Actor to the scene-graph.
1122 * @param[in] index If set, it is only used for positioning the actor within the parent's child list.
1124 void ConnectToSceneGraph(int index = -1);
1127 * Helper for ConnectToStage, to notify a connected actor through the public API.
1129 void NotifyStageConnection();
1132 * Called on a child during Remove() when the actor was previously on the Stage.
1134 void DisconnectFromStage();
1137 * Helper for DisconnectFromStage, to recursively disconnect a tree of actors.
1138 * This is atomic i.e. not interrupted by user callbacks.
1139 * @param[out] disconnectionList On return, the list of disconnected actors which require notification.
1141 void RecursiveDisconnectFromStage( ActorContainer& disconnectionList );
1144 * Disconnect the Node associated with this Actor from the scene-graph.
1146 void DisconnectFromSceneGraph();
1149 * Helper for DisconnectFromStage, to notify a disconnected actor through the public API.
1151 void NotifyStageDisconnection();
1154 * When the Actor is OnStage, checks whether the corresponding Node is connected to the scene graph.
1155 * @return True if the Actor is OnStage & has a Node connected to the scene graph.
1157 bool IsNodeConnected() const;
1160 * Calculate the size of the z dimension for a 2D size
1162 * @param[in] size The 2D size (X, Y) to calculate Z from
1164 * @return Return the Z dimension for this size
1166 float CalculateSizeZ( const Vector2& size ) const;
1168 public: // Default property extensions from Object
1171 * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
1173 virtual unsigned int GetDefaultPropertyCount() const;
1176 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
1178 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
1181 * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
1183 virtual const char* GetDefaultPropertyName(Property::Index index) const;
1186 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
1188 virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
1191 * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
1193 virtual bool IsDefaultPropertyWritable(Property::Index index) const;
1196 * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
1198 virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
1201 * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
1203 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
1206 * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
1208 virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
1211 * @copydoc Dali::Internal::Object::SetDefaultProperty()
1213 virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
1216 * @copydoc Dali::Internal::Object::SetSceneGraphProperty()
1218 virtual void SetSceneGraphProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value );
1221 * @copydoc Dali::Internal::Object::GetDefaultProperty()
1223 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
1226 * @copydoc Dali::Internal::Object::GetPropertyOwner()
1228 virtual const SceneGraph::PropertyOwner* GetPropertyOwner() const;
1231 * @copydoc Dali::Internal::Object::GetSceneObject()
1233 virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
1236 * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
1238 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
1241 * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
1243 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
1246 * @copydoc Dali::Internal::Object::GetPropertyComponentIndex()
1248 virtual int GetPropertyComponentIndex( Property::Index index ) const;
1256 Actor(const Actor&);
1259 Actor& operator=(const Actor& rhs);
1262 * Set the actors parent.
1263 * @param[in] parent The new parent.
1264 * @param[in] index If set, it is only used for positioning the actor within the parent's child list.
1266 void SetParent(Actor* parent, int index = -1);
1269 * Helper to create a Node for this Actor.
1270 * To be overriden in derived classes.
1271 * @return A newly allocated node.
1273 virtual SceneGraph::Node* CreateNode() const;
1276 * For use in derived classes, called after Initialize()
1278 virtual void OnInitialize() {}
1281 * For use in internal derived classes.
1282 * This is called during ConnectToStage(), after the actor has finished adding its node to the scene-graph.
1283 * The derived class must not modify the actor hierachy (Add/Remove children) during this callback.
1285 virtual void OnStageConnectionInternal() {}
1288 * For use in internal derived classes.
1289 * This is called during DisconnectFromStage(), before the actor removes its node from the scene-graph.
1290 * The derived class must not modify the actor hierachy (Add/Remove children) during this callback.
1292 virtual void OnStageDisconnectionInternal() {}
1295 * For use in external (CustomActor) derived classes.
1296 * This is called after the atomic ConnectToStage() traversal has been completed.
1298 virtual void OnStageConnectionExternal() {}
1301 * For use in external (CustomActor) derived classes.
1302 * This is called after the atomic DisconnectFromStage() traversal has been completed.
1304 virtual void OnStageDisconnectionExternal() {}
1307 * For use in derived classes; this is called after Add() has added a child.
1308 * @param[in] child The child that was added.
1310 virtual void OnChildAdd( Actor& child ) {}
1313 * For use in derived classes; this is called after Remove() has removed a child.
1314 * @param[in] child The child that was removed.
1316 virtual void OnChildRemove( Actor& child ) {}
1319 * For use in derived classes.
1320 * This is called after SizeSet() has been called.
1322 virtual void OnSizeSet(const Vector3& targetSize) {}
1325 * For use in derived classes.
1326 * This is only called if mDerivedRequiresTouch is true, and the touch-signal was not consumed.
1327 * @param[in] event The touch event.
1328 * @return True if the event should be consumed.
1330 virtual bool OnTouchEvent(const TouchEvent& event) { return false; }
1333 * For use in derived classes.
1334 * This is only called if mDerivedRequiresHover is true, and the hover-signal was not consumed.
1335 * @param[in] event The hover event.
1336 * @return True if the event should be consumed.
1338 virtual bool OnHoverEvent(const HoverEvent& event) { return false; }
1341 * For use in derived classes.
1342 * This is only called if the mouse wheel signal was not consumed.
1343 * @param[in] event The mouse event.
1344 * @return True if the event should be consumed.
1346 virtual bool OnMouseWheelEvent(const MouseWheelEvent& event) { return false; }
1349 * For use in derived class
1350 * If an alias for a child exists, return the child otherwise return an empty handle.
1351 * For example 'previous' could return the last selected child.
1352 * @pre The Actor has been initialized.
1353 * @param[in] actorAlias the name of the actor to find
1354 * @return A handle to the actor if found, or an empty handle if not.
1356 virtual Dali::Actor GetChildByAlias(const std::string& actorAlias) { return Dali::Actor(); }
1359 * Support function for FindChildByAlias
1360 * @pre The Actor has been initialized.
1361 * @param[in] actorAlias the name of the aliased actor to find
1362 * @return A handle to the actor if found, or an empty handle if not.
1364 Dali::Actor DoGetChildByAlias(const std::string& actorAlias);
1368 StagePtr mStage; ///< Used to send messages to Node; valid until Core destruction
1369 Actor* mParent; ///< Each actor (except the root) can have one parent
1370 ActorContainer* mChildren; ///< Container of referenced actors
1371 const SceneGraph::Node* mNode; ///< Not owned
1372 Vector3* mParentOrigin; ///< NULL means ParentOrigin::DEFAULT. ParentOrigin is non-animatable
1373 Vector3* mAnchorPoint; ///< NULL means AnchorPoint::DEFAULT. AnchorPoint is non-animatable
1375 #ifdef DYNAMICS_SUPPORT
1376 DynamicsData* mDynamicsData; ///< optional physics data
1379 ActorGestureData* mGestureData; ///< Optional Gesture data. Only created when actor requires gestures
1381 ActorAttachmentPtr mAttachment; ///< Optional referenced attachment
1384 Dali::Actor::TouchSignalType mTouchedSignal;
1385 Dali::Actor::HoverSignalType mHoveredSignal;
1386 Dali::Actor::MouseWheelEventSignalType mMouseWheelEventSignal;
1387 Dali::Actor::OnStageSignalType mOnStageSignal;
1388 Dali::Actor::OffStageSignalType mOffStageSignal;
1390 Vector3 mSize; ///< Event-side storage for size (not a pointer as most actors will have a size)
1391 Vector3 mSizeModeFactor; ///< Factor of parent size used for certain SizeModes.
1393 std::string mName; ///< Name of the actor
1394 unsigned int mId; ///< A unique ID to identify the actor starting from 1, and 0 is reserved
1396 const bool mIsRoot : 1; ///< Flag to identify the root actor
1397 const bool mIsRenderable : 1; ///< Flag to identify that this is a renderable actor
1398 const bool mIsLayer : 1; ///< Flag to identify that this is a layer
1399 bool mIsOnStage : 1; ///< Flag to identify whether the actor is on-stage
1400 bool mIsDynamicsRoot : 1; ///< Flag to identify if this is the dynamics world root
1401 bool mSensitive : 1; ///< Whether the actor emits touch event signals
1402 bool mLeaveRequired : 1; ///< Whether a touch event signal is emitted when the a touch leaves the actor's bounds
1403 bool mKeyboardFocusable : 1; ///< Whether the actor should be focusable by keyboard navigation
1404 bool mDerivedRequiresTouch : 1; ///< Whether the derived actor type requires touch event signals
1405 bool mDerivedRequiresHover : 1; ///< Whether the derived actor type requires hover event signals
1406 bool mDerivedRequiresMouseWheelEvent : 1; ///< Whether the derived actor type requires mouse wheel event signals
1407 bool mOnStageSignalled : 1; ///< Set to true before OnStageConnection signal is emitted, and false before OnStageDisconnection
1408 bool mInheritRotation : 1; ///< Cached: Whether the parent's rotation should be inherited.
1409 bool mInheritScale : 1; ///< Cached: Whether the parent's scale should be inherited.
1410 DrawMode::Type mDrawMode : 2; ///< Cached: How the actor and its children should be drawn
1411 PositionInheritanceMode mPositionInheritanceMode : 2; ///< Cached: Determines how position is inherited
1412 ColorMode mColorMode : 2; ///< Cached: Determines whether mWorldColor is inherited
1413 SizeMode mSizeMode : 2; ///< Cached: Determines how the actors parent affects the actors size.
1417 static ActorContainer mNullChildren; ///< Empty container (shared by all actors, returned by GetChildren() const)
1418 static unsigned int mActorCounter; ///< A counter to track the actor instance creation
1422 } // namespace Internal
1424 // Helpers for public-api forwarding methods
1426 inline Internal::Actor& GetImplementation(Dali::Actor& actor)
1428 DALI_ASSERT_ALWAYS(actor && "Actor handle is empty");
1430 BaseObject& handle = actor.GetBaseObject();
1432 return static_cast<Internal::Actor&>(handle);
1435 inline const Internal::Actor& GetImplementation(const Dali::Actor& actor)
1437 DALI_ASSERT_ALWAYS(actor && "Actor handle is empty");
1439 const BaseObject& handle = actor.GetBaseObject();
1441 return static_cast<const Internal::Actor&>(handle);
1446 #endif // __DALI_INTERNAL_ACTOR_H__