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/actor-attachments/actor-attachment-declarations.h>
35 #include <dali/internal/update/nodes/node-declarations.h>
37 #ifdef DYNAMICS_SUPPORT
38 #include <dali/internal/event/dynamics/dynamics-declarations.h>
47 struct MouseWheelEvent;
53 class ActorGestureData;
58 typedef IntrusivePtr<Actor> ActorPtr;
59 typedef Dali::ActorContainer ActorContainer; // Store handles to return via public-api
60 typedef ActorContainer::iterator ActorIter;
61 typedef ActorContainer::const_iterator ActorConstIter;
64 * Actor is the primary object which Dali applications interact with.
65 * UI controls can be built by combining multiple actors.
66 * Multi-Touch events are received through signals emitted by the actor tree.
68 * An Actor is a proxy for a Node in the scene graph.
69 * When an Actor is added to the Stage, it creates a node and attaches it to the scene graph.
70 * The scene-graph can be updated in a separate thread, so the attachment is done using an asynchronous message.
71 * When a tree of Actors is detached from the Stage, a message is sent to destroy the associated nodes.
73 class Actor : public Object
79 * @return A smart-pointer to the newly allocated Actor.
81 static ActorPtr New();
84 * Retrieve the name of the actor.
87 const std::string& GetName() const;
90 * Set the name of the actor.
91 * @param[in] name The new name.
93 void SetName(const std::string& name);
96 * @copydoc Dali::Actor::GetId
98 unsigned int GetId() const;
103 * Attach an object to an actor.
104 * @pre The actor does not already have an attachment.
105 * @param[in] attachment The object to attach.
107 void Attach(ActorAttachment& attachment);
110 * Retreive the object attached to an actor.
111 * @return The attachment.
113 ActorAttachmentPtr GetAttachment();
118 * Query whether an actor is the root actor, which is owned by the Stage.
119 * @return True if the actor is a root actor.
127 * Query whether the actor is connected to the Stage.
129 bool OnStage() const;
132 * Query whether the actor is a RenderableActor derived type.
133 * @return True if the actor is renderable.
135 bool IsRenderable() const
137 // inlined as this is called a lot in hit testing
138 return mIsRenderable;
142 * Query whether the actor is of class Dali::Layer
143 * @return True if the actor is a layer.
147 // inlined as this is called a lot in hit testing
152 * Gets the layer in which the actor is present
153 * @return The layer, which will be uninitialized if the actor is off-stage.
155 Dali::Layer GetLayer();
158 * Adds a child Actor to this Actor.
159 * @pre The child actor is not the same as the parent actor.
160 * @pre The child actor does not already have a parent.
161 * @param [in] child The child.
162 * @post The child will be referenced by its parent.
164 void Add(Actor& child);
167 * Inserts a child Actor to this Actor's child list
168 * @pre The child actor is not the same as the parent actor.
169 * @pre The child actor does not already have a parent.
170 * @param [in] index in childlist to insert child at
171 * @param [in] child The child.
172 * @post The child will be referenced by its parent.
174 void Insert(unsigned int index, Actor& child);
177 * Removes a child Actor from this Actor.
178 * @param [in] child The child.
179 * @post The child will be unreferenced.
181 void Remove(Actor& child);
184 * @copydoc Dali::Actor::Unparent
189 * Retrieve the number of children held by the actor.
190 * @return The number of children
192 unsigned int GetChildCount() const;
195 * @copydoc Dali::Actor::GetChildAt
197 Dali::Actor GetChildAt(unsigned int index) const;
200 * Retrieve the Actor's children.
201 * @return A copy of the container of children.
203 ActorContainer GetChildren();
206 * Retrieve the Actor's children.
207 * @return A const reference to the container of children.
209 const ActorContainer& GetChildren() const;
212 * Retrieve a reference to Actor's children.
213 * @note Not for public use.
214 * @return A reference to the container of children.
216 ActorContainer& GetChildrenInternal()
222 * @copydoc Dali::Actor::FindChildByName
224 ActorPtr FindChildByName(const std::string& actorName);
227 * @copydoc Dali::Actor::FindChildById
229 ActorPtr FindChildById(const unsigned int id);
232 * Retrieve the parent of an Actor.
233 * @return The parent actor, or NULL if the Actor does not have a parent.
235 Actor* GetParent() const
241 * Sets the size of an actor.
242 * ActorAttachments attached to the actor, can be scaled to fit within this area.
243 * This does not interfere with the actors scale factor.
244 * @param [in] width The new width.
245 * @param [in] height The new height.
247 void SetSize(float width, float height);
250 * Sets the size of an actor.
251 * ActorAttachments attached to the actor, can be scaled to fit within this area.
252 * This does not interfere with the actors scale factor.
253 * @param [in] width The size of the actor along the x-axis.
254 * @param [in] height The size of the actor along the y-axis.
255 * @param [in] depth The size of the actor along the z-axis.
257 void SetSize(float width, float height, float depth);
260 * Sets the size of an actor.
261 * ActorAttachments attached to the actor, can be scaled to fit within this area.
262 * This does not interfere with the actors scale factor.
263 * @param [in] size The new size.
265 void SetSize(const Vector2& size);
268 * Sets the size of an actor.
269 * ActorAttachments attached to the actor, can be scaled to fit within this area.
270 * This does not interfere with the actors scale factor.
271 * @param [in] size The new size.
273 void SetSize(const Vector3& size);
276 * Set the width component of the Actor's size.
277 * @param [in] width The new width component.
279 void SetWidth( float width );
282 * Set the height component of the Actor's size.
283 * @param [in] height The new height component.
285 void SetHeight( float height );
288 * Set the depth component of the Actor's size.
289 * @param [in] depth The new depth component.
291 void SetDepth( float depth );
294 * Retrieve the Actor's size from event side.
295 * This size will be the size set or if animating then the target size.
296 * @return The Actor's size.
298 const Vector3& GetSize() const;
301 * Retrieve the Actor's size from update side.
302 * This size will be the size set or animating but will be a frame behind.
303 * @return The Actor's size.
305 const Vector3& GetCurrentSize() const;
308 * Return the natural size of the actor
310 * @return The actor's natural size
312 virtual Vector3 GetNaturalSize() const;
315 * Set the origin of an actor, within its parent's area.
316 * This is expressed in 2D unit coordinates, such that (0.0, 0.0, 0.5) is the top-left corner of the parent,
317 * and (1.0, 1.0, 0.5) is the bottom-right corner.
318 * The default parent-origin is top-left (0.0, 0.0, 0.5).
319 * An actor position is the distance between this origin, and the actors anchor-point.
320 * @param [in] origin The new parent-origin.
322 void SetParentOrigin(const Vector3& origin);
325 * Set the x component of the parent-origin
326 * @param [in] x The new x value.
328 void SetParentOriginX( float x );
331 * Set the y component of the parent-origin
332 * @param [in] y The new y value.
334 void SetParentOriginY( float y );
337 * Set the z component of the parent-origin
338 * @param [in] z The new z value.
340 void SetParentOriginZ( float z );
343 * Retrieve the parent-origin of an actor.
344 * @return The parent-origin.
346 const Vector3& GetCurrentParentOrigin() const;
349 * Set the anchor-point of an actor. This is expressed in 2D unit coordinates, such that
350 * (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.
351 * The default anchor point is top-left (0.0, 0.0, 0.5).
352 * An actor position is the distance between its parent-origin, and this anchor-point.
353 * An actor's rotation is centered around its anchor-point.
354 * @param [in] anchorPoint The new anchor-point.
356 void SetAnchorPoint(const Vector3& anchorPoint);
359 * Set the x component of the anchor-point.
360 * @param [in] x The new x value.
362 void SetAnchorPointX( float x );
365 * Set the y component of the anchor-point.
366 * @param [in] y The new y value.
368 void SetAnchorPointY( float y );
371 * Set the z component of the anchor-point.
372 * @param [in] z The new z value.
374 void SetAnchorPointZ( float z );
377 * Retrieve the anchor-point of an actor.
378 * @return The anchor-point.
380 const Vector3& GetCurrentAnchorPoint() const;
383 * Sets the position of the Actor.
384 * The coordinates are relative to the Actor's parent.
385 * The Actor's z position will be set to 0.0f.
386 * @param [in] x The new x position
387 * @param [in] y The new y position
389 void SetPosition(float x, float y);
392 * Sets the position of the Actor.
393 * The coordinates are relative to the Actor's parent.
394 * @param [in] x The new x position
395 * @param [in] y The new y position
396 * @param [in] z The new z position
398 void SetPosition(float x, float y, float z);
401 * Sets the position of the Actor.
402 * The coordinates are relative to the Actor's parent.
403 * @param [in] position The new position.
405 void SetPosition(const Vector3& position);
408 * Set the position of an actor along the X-axis.
409 * @param [in] x The new x position
414 * Set the position of an actor along the Y-axis.
415 * @param [in] y The new y position.
420 * Set the position of an actor along the Z-axis.
421 * @param [in] z The new z position
426 * Translate an actor relative to its existing position.
427 * @param[in] distance The actor will move by this distance.
429 void TranslateBy(const Vector3& distance);
432 * Retrieve the position of the Actor.
433 * The coordinates are relative to the Actor's parent.
434 * @return the Actor's position.
436 const Vector3& GetCurrentPosition() const;
439 * @copydoc Dali::Actor::GetCurrentWorldPosition()
441 const Vector3& GetCurrentWorldPosition() const;
444 * @copydoc Dali::Actor::SetPositionInheritanceMode()
446 void SetPositionInheritanceMode( PositionInheritanceMode mode );
449 * @copydoc Dali::Actor::GetPositionInheritanceMode()
451 PositionInheritanceMode GetPositionInheritanceMode() const;
454 * Sets the orientation of the Actor.
455 * @param [in] angleRadians The new orientation angle in radians.
456 * @param [in] axis The new axis of orientation.
458 void SetOrientation(const Radian& angleRadians, const Vector3& axis);
461 * Sets the orientation of the Actor.
462 * @param [in] orientation The new orientation.
464 void SetOrientation(const Quaternion& orientation);
467 * Rotate an actor around its existing rotation axis.
468 * @param[in] angleRadians The angle to the rotation to combine with the existing rotation.
469 * @param[in] axis The axis of the rotation to combine with the existing rotation.
471 void RotateBy(const Radian& angleRadians, const Vector3& axis);
474 * Apply a relative rotation to an actor.
475 * @param[in] relativeRotation The rotation to combine with the actors existing rotation.
477 void RotateBy(const Quaternion& relativeRotation);
480 * Retreive the Actor's orientation.
481 * @return the orientation.
483 const Quaternion& GetCurrentOrientation() const;
486 * Set whether a child actor inherits it's parent's orientation. Default is to inherit.
487 * Switching this off means that using SetOrientation() sets the actor's world orientation.
488 * @param[in] inherit - true if the actor should inherit orientation, false otherwise.
490 void SetInheritOrientation(bool inherit);
493 * Returns whether the actor inherit's it's parent's orientation.
494 * @return true if the actor inherit's it's parent orientation, false if it uses world orientation.
496 bool IsOrientationInherited() const;
499 * @brief Defines how a child actors size is affected by its parents size.
500 * @param[in] mode The size relative to parent mode to use.
502 void SetSizeMode(SizeMode mode);
505 * Query how the child actors size is affected by its parents size.
506 * @return The size relative to parent mode in use.
508 SizeMode GetSizeMode() const;
511 * Sets the factor of the parents size used for the child actor.
512 * Note: Only used if SizeMode is SIZE_RELATIVE_TO_PARENT or SIZE_FIXED_OFFSET_FROM_PARENT.
513 * @param[in] factor The vector to multiply the parents size by to get the childs size.
515 void SetSizeModeFactor(const Vector3& factor);
518 * Gets 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 * @return The vector being used to multiply the parents size by to get the childs size.
522 const Vector3& GetSizeModeFactor() const;
525 * @copydoc Dali::Actor::GetCurrentWorldOrientation()
527 const Quaternion& GetCurrentWorldOrientation() const;
530 * Sets a scale factor applied to an actor.
531 * @param [in] scale The scale factor applied on all axes.
533 void SetScale(float scale);
536 * Sets a scale factor applied to an actor.
537 * @param [in] scaleX The scale factor applied along the x-axis.
538 * @param [in] scaleY The scale factor applied along the y-axis.
539 * @param [in] scaleZ The scale factor applied along the z-axis.
541 void SetScale(float scaleX, float scaleY, float scaleZ);
544 * Sets a scale factor applied to an actor.
545 * @param [in] scale A vector representing the scale factor for each axis.
547 void SetScale(const Vector3& scale);
550 * Set the x component of the scale factor.
551 * @param [in] x The new x value.
553 void SetScaleX( float x );
556 * Set the y component of the scale factor.
557 * @param [in] y The new y value.
559 void SetScaleY( float y );
562 * Set the z component of the scale factor.
563 * @param [in] z The new z value.
565 void SetScaleZ( float z );
568 * Apply a relative scale to an actor.
569 * @param[in] relativeScale The scale to combine with the actors existing scale.
571 void ScaleBy(const Vector3& relativeScale);
574 * Retrieve the scale factor applied to an actor.
575 * @return A vector representing the scale factor for each axis.
577 const Vector3& GetCurrentScale() const;
580 * @copydoc Dali::Actor::GetCurrentWorldScale()
582 const Vector3& GetCurrentWorldScale() const;
585 * @copydoc Dali::Actor::SetInheritScale()
587 void SetInheritScale( bool inherit );
590 * @copydoc Dali::Actor::IsScaleInherited()
592 bool IsScaleInherited() const;
595 * @copydoc Dali::Actor::GetCurrentWorldMatrix()
597 Matrix GetCurrentWorldMatrix() const;
602 * Sets the visibility flag of an actor.
603 * @param [in] visible The new visibility flag.
605 void SetVisible(bool visible);
608 * Retrieve the visibility flag of an actor.
609 * @return The visibility flag.
611 bool IsVisible() const;
614 * Sets the opacity of an actor.
615 * @param [in] opacity The new opacity.
617 void SetOpacity(float opacity);
620 * Retrieve the actor's opacity.
621 * @return The actor's opacity.
623 float GetCurrentOpacity() const;
626 * Sets whether an actor should emit touch or hover signals; see SignalTouch() and SignalHover().
627 * An actor is sensitive by default, which means that as soon as an application connects to the SignalTouch(),
628 * the touch event signal will be emitted, and as soon as an application connects to the SignalHover(), the
629 * hover event signal will be emitted.
631 * If the application wishes to temporarily disable the touch or hover event signal emission, then they can do so by calling:
633 * actor.SetSensitive(false);
636 * Then, to re-enable the touch or hover event signal emission, the application should call:
638 * actor.SetSensitive(true);
641 * @see SignalTouch() and SignalHover().
642 * @note If an actor's sensitivity is set to false, then it's children will not emit a touch or hover event signal either.
643 * @param[in] sensitive true to enable emission of the touch or hover event signals, false otherwise.
645 void SetSensitive(bool sensitive)
647 mSensitive = sensitive;
651 * Query whether an actor emits touch or hover event signals.
652 * @see SetSensitive(bool)
653 * @return true, if emission of touch or hover event signals is enabled, false otherwise.
655 bool IsSensitive() const
661 * @copydoc Dali::Actor::SetDrawMode
663 void SetDrawMode( DrawMode::Type drawMode );
666 * @copydoc Dali::Actor::GetDrawMode
668 DrawMode::Type GetDrawMode() const;
671 * @copydoc Dali::Actor::SetOverlay
673 void SetOverlay(bool enable);
676 * @copydoc Dali::Actor::IsOverlay
678 bool IsOverlay() const;
681 * Sets whether an actor transmits geometry scaling to it's children.
682 * The default value is for it not to transmit scaling.
683 * @param[in] transmitGeometryScaling True to transmit scaling.
685 void SetTransmitGeometryScaling(bool transmitGeometryScaling);
688 * Get the TransmitGeometryScaling property for this actor.
689 * @return True if geometry scaling is applied to the inherited scale.
691 bool GetTransmitGeometryScaling() const;
694 * Sets the initial volume of the actor. Used for scaling the
695 * actor appropriately as the actor is sized when transmitGeometryScaling
698 * @param[in] volume the volume of the model and it's children
700 void SetInitialVolume(const Vector3& volume);
703 * Sets the actor's color. The final color of actor depends on its color mode.
704 * This final color is applied to the drawable elements of an actor.
705 * @param [in] color The new color.
707 void SetColor(const Vector4& color);
710 * Set the red component of the color.
711 * @param [in] red The new red component.
713 void SetColorRed( float red );
716 * Set the green component of the color.
717 * @param [in] green The new green component.
719 void SetColorGreen( float green );
722 * Set the blue component of the scale factor.
723 * @param [in] blue The new blue value.
725 void SetColorBlue( float blue );
728 * Retrieve the actor's color.
731 const Vector4& GetCurrentColor() const;
734 * Sets the actor's color mode.
735 * Color mode specifies whether Actor uses its own color or inherits its parent color
736 * @param [in] colorMode to use.
738 void SetColorMode(ColorMode colorMode);
741 * Returns the actor's color mode.
742 * @return currently used colorMode.
744 ColorMode GetColorMode() const;
747 * @copydoc Dali::Actor::GetCurrentWorldColor()
749 const Vector4& GetCurrentWorldColor() const;
751 #ifdef DYNAMICS_SUPPORT
755 /// @copydoc Dali::Actor::DisableDynamics
756 void DisableDynamics();
758 /// @copydoc Dali::Actor::EnableDynamics(Dali::DynamicsBodyConfig)
759 DynamicsBodyPtr EnableDynamics(DynamicsBodyConfigPtr bodyConfig);
761 /// @copydoc Dali::Actor::GetDynamicsBody
762 DynamicsBodyPtr GetDynamicsBody() const;
764 /// @copydoc Dali::Actor::AddDynamicsJoint(Dali::Actor,const Vector3&)
765 DynamicsJointPtr AddDynamicsJoint( ActorPtr attachedActor, const Vector3& offset );
767 /// @copydoc Dali::Actor::AddDynamicsJoint(Dali::Actor,const Vector3&,const Vector3&)
768 DynamicsJointPtr AddDynamicsJoint( ActorPtr attachedActor, const Vector3& offsetA, const Vector3& offsetB );
770 /// @copydoc Dali::Actor::GetNumberOfJoints
771 const int GetNumberOfJoints() const;
773 /// @copydoc Dali::Actor::GetDynamicsJointByIndex
774 DynamicsJointPtr GetDynamicsJointByIndex( const int index ) const;
776 /// @copydoc Dali::Actor::GetDynamicsJoint
777 DynamicsJointPtr GetDynamicsJoint( ActorPtr attachedActor ) const;
779 /// @copydoc Dali::Actor::RemoveDynamicsJoint
780 void RemoveDynamicsJoint( DynamicsJointPtr joint );
783 * Hold a reference to a DynamicsJoint
784 * @param[in] joint The joint
786 void ReferenceJoint( DynamicsJointPtr joint );
789 * Release a reference to a DynamicsJoint
790 * @param[in] joint The joint
792 void ReleaseJoint( DynamicsJointPtr joint );
795 * Set this actor to be the root actor in the dynamics simulation
796 * All children of the actor are added/removed from the simulation.
797 * @param[in] flag When true sets this actor to be the simulation world root actor and
798 * if OnStage() all dynamics enabled child actors are added to the simulation,
799 * when false stops this actor being the simulation root and if OnStage() all
800 * dynamics enabled child actors are removed from the simulation.
802 void SetDynamicsRoot(bool flag);
806 * Check if this actor is the root actor in the dynamics simulation
807 * @return true if this is the dynamics root actor.
809 bool IsDynamicsRoot() const;
812 * Add actor to the dynamics simulation
813 * Invoked when the actor is staged, or it's parent becomes the simulation root
815 void ConnectDynamics();
818 * Remove actor from the dynamics simulation
819 * Invoked when the actor is unstaged, or it's parent stops being the the simulation root
821 void DisconnectDynamics();
824 * An actor in a DynamicsJoint relationship has been staged
825 * @param[in] actor The actor passed into AddDynamicsJoint()
827 void AttachedActorOnStage( Dali::Actor actor );
830 * An actor in a DynamicsJoint relationship has been unstaged
831 * @param[in] actor The actor passed into AddDynamicsJoint()
833 void AttachedActorOffStage( Dali::Actor actor );
835 #endif // DYNAMICS_SUPPORT
839 * Converts screen coordinates into the actor's coordinate system.
840 * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
841 * @param[out] localX On return, the X-coordinate relative to the actor.
842 * @param[out] localY On return, the Y-coordinate relative to the actor.
843 * @param[in] screenX The screen X-coordinate.
844 * @param[in] screenY The screen Y-coordinate.
845 * @return True if the conversion succeeded.
847 bool ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const;
850 * Converts screen coordinates into the actor's coordinate system.
851 * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
852 * @param[in] renderTask The render-task used to display the actor.
853 * @param[out] localX On return, the X-coordinate relative to the actor.
854 * @param[out] localY On return, the Y-coordinate relative to the actor.
855 * @param[in] screenX The screen X-coordinate.
856 * @param[in] screenY The screen Y-coordinate.
857 * @return True if the conversion succeeded.
859 bool ScreenToLocal(RenderTask& renderTask, float& localX, float& localY, float screenX, float screenY) const;
862 * Converts from the actor's coordinate system to screen coordinates.
863 * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
864 * @param[in] viewMatrix The view-matrix
865 * @param[in] projectionMatrix The projection-matrix
866 * @param[in] viewport The view-port
867 * @param[out] localX On return, the X-coordinate relative to the actor.
868 * @param[out] localY On return, the Y-coordinate relative to the actor.
869 * @param[in] screenX The screen X-coordinate.
870 * @param[in] screenY The screen Y-coordinate.
871 * @return True if the conversion succeeded.
873 bool ScreenToLocal( const Matrix& viewMatrix,
874 const Matrix& projectionMatrix,
875 const Viewport& viewport,
879 float screenY ) const;
882 * Performs a ray-sphere test with the given pick-ray and the actor's bounding sphere.
883 * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
884 * @param[in] rayOrigin The ray origin in the world's reference system.
885 * @param[in] rayDir The ray director vector in the world's reference system.
886 * @return True if the ray intersects the actor's bounding sphere.
888 bool RaySphereTest( const Vector4& rayOrigin, const Vector4& rayDir ) const;
891 * Performs a ray-actor test with the given pick-ray and the actor's geometry.
892 * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
893 * @param[in] rayOrigin The ray origin in the world's reference system.
894 * @param[in] rayDir The ray director vector in the world's reference system.
895 * @param[out] hitPointLocal The hit point in the Actor's local reference system.
896 * @param[out] distance The distance from the hit point to the camera.
897 * @return True if the ray intersects the actor's geometry.
899 bool RayActorTest( const Vector4& rayOrigin, const Vector4& rayDir, Vector4& hitPointLocal, float& distance ) const;
902 * Sets whether the actor should receive a notification when touch or hover motion events leave
903 * the boundary of the actor.
905 * @note By default, this is set to false as most actors do not require this.
906 * @note Need to connect to the SignalTouch or SignalHover to actually receive this event.
908 * @param[in] required Should be set to true if a Leave event is required
910 void SetLeaveRequired(bool required);
913 * This returns whether the actor requires touch or hover events whenever touch or hover motion events leave
914 * the boundary of the actor.
915 * @return true if a Leave event is required, false otherwise.
917 bool GetLeaveRequired() const;
920 * @copydoc Dali::Actor::SetKeyboardFocusable()
922 void SetKeyboardFocusable( bool focusable );
925 * @copydoc Dali::Actor::IsKeyboardFocusable()
927 bool IsKeyboardFocusable() const;
930 * Query whether the application or derived actor type requires touch events.
931 * @return True if touch events are required.
933 bool GetTouchRequired() const;
936 * Query whether the application or derived actor type requires hover events.
937 * @return True if hover events are required.
939 bool GetHoverRequired() const;
942 * Query whether the application or derived actor type requires mouse wheel events.
943 * @return True if mouse wheel events are required.
945 bool GetMouseWheelEventRequired() const;
948 * Query whether the actor is actually hittable. This method checks whether the actor is
949 * sensitive, has the visibility flag set to true and is not fully transparent.
950 * @return true, if it can be hit, false otherwise.
952 bool IsHittable() const;
957 * Retrieve the gesture data associated with this actor. The first call to this method will
958 * allocate space for the ActorGestureData so this should only be called if an actor really does
960 * @return Reference to the ActorGestureData for this actor.
961 * @note Once the gesture-data is created for an actor it is likely that gestures are required
962 * throughout the actor's lifetime so it will only be deleted when the actor is destroyed.
964 ActorGestureData& GetGestureData();
967 * Queries whether the actor requires the gesture type.
968 * @param[in] type The gesture type.
970 bool IsGestureRequred( Gesture::Type type ) const;
975 * Used by the EventProcessor to emit touch event signals.
976 * @param[in] event The touch event.
977 * @return True if the event was consumed.
979 bool EmitTouchEventSignal(const TouchEvent& event);
982 * Used by the EventProcessor to emit hover event signals.
983 * @param[in] event The hover event.
984 * @return True if the event was consumed.
986 bool EmitHoverEventSignal(const HoverEvent& event);
989 * Used by the EventProcessor to emit mouse wheel event signals.
990 * @param[in] event The mouse wheel event.
991 * @return True if the event was consumed.
993 bool EmitMouseWheelEventSignal(const MouseWheelEvent& event);
996 * @copydoc Dali::Actor::TouchedSignal()
998 Dali::Actor::TouchSignalType& TouchedSignal();
1001 * @copydoc Dali::Actor::HoveredSignal()
1003 Dali::Actor::HoverSignalType& HoveredSignal();
1006 * @copydoc Dali::Actor::MouseWheelEventSignal()
1008 Dali::Actor::MouseWheelEventSignalType& MouseWheelEventSignal();
1011 * @copydoc Dali::Actor::OnStageSignal()
1013 Dali::Actor::OnStageSignalType& OnStageSignal();
1016 * @copydoc Dali::Actor::OffStageSignal()
1018 Dali::Actor::OffStageSignalType& OffStageSignal();
1021 * Connects a callback function with the object's signals.
1022 * @param[in] object The object providing the signal.
1023 * @param[in] tracker Used to disconnect the signal.
1024 * @param[in] signalName The signal to connect to.
1025 * @param[in] functor A newly allocated FunctorDelegate.
1026 * @return True if the signal was connected.
1027 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
1029 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
1032 * Performs actions as requested using the action name.
1033 * @param[in] object The object on which to perform the action.
1034 * @param[in] actionName The action to perform.
1035 * @param[in] attributes The attributes with which to perfrom this action.
1036 * @return true if the action was done.
1038 static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
1040 public: // For Animation
1043 * This should only be called by Animation, when the actor is resized using Animation::Resize().
1045 * @param[in] animation The animation that resized the actor
1046 * @param[in] targetSize The new target size of the actor
1048 void NotifySizeAnimation( Animation& animation, const Vector3& targetSize);
1051 * For use in derived classes.
1052 * This should only be called by Animation, when the actor is resized using Animation::Resize().
1054 virtual void OnSizeAnimation( Animation& animation, const Vector3& targetSize) {}
1067 * Protected Constructor. See Actor::New().
1068 * The second-phase construction Initialize() member should be called immediately after this.
1069 * @param[in] derivedType The derived type of actor (if any).
1071 Actor( DerivedType derivedType );
1074 * Second-phase constructor. Must be called immediately after creating a new Actor;
1076 void Initialize(void);
1079 * A reference counted object may only be deleted by calling Unreference()
1084 * Called on a child during Add() when the parent actor is connected to the Stage.
1085 * @param[in] stage The stage.
1086 * @param[in] index If set, it is only used for positioning the actor within the parent's child list.
1088 void ConnectToStage( int index = -1 );
1091 * Helper for ConnectToStage, to recursively connect a tree of actors.
1092 * This is atomic i.e. not interrupted by user callbacks.
1093 * @param[in] index If set, it is only used for positioning the actor within the parent's child list.
1094 * @param[out] connectionList On return, the list of connected actors which require notification.
1096 void RecursiveConnectToStage( ActorContainer& connectionList, int index = -1 );
1099 * Connect the Node associated with this Actor to the scene-graph.
1100 * @param[in] index If set, it is only used for positioning the actor within the parent's child list.
1102 void ConnectToSceneGraph(int index = -1);
1105 * Helper for ConnectToStage, to notify a connected actor through the public API.
1107 void NotifyStageConnection();
1110 * Called on a child during Remove() when the actor was previously on the Stage.
1112 void DisconnectFromStage();
1115 * Helper for DisconnectFromStage, to recursively disconnect a tree of actors.
1116 * This is atomic i.e. not interrupted by user callbacks.
1117 * @param[out] disconnectionList On return, the list of disconnected actors which require notification.
1119 void RecursiveDisconnectFromStage( ActorContainer& disconnectionList );
1122 * Disconnect the Node associated with this Actor from the scene-graph.
1124 void DisconnectFromSceneGraph();
1127 * Helper for DisconnectFromStage, to notify a disconnected actor through the public API.
1129 void NotifyStageDisconnection();
1132 * When the Actor is OnStage, checks whether the corresponding Node is connected to the scene graph.
1133 * @return True if the Actor is OnStage & has a Node connected to the scene graph.
1135 bool IsNodeConnected() const;
1138 * Calculate the size of the z dimension for a 2D size
1140 * @param[in] size The 2D size (X, Y) to calculate Z from
1142 * @return Return the Z dimension for this size
1144 float CalculateSizeZ( const Vector2& size ) const;
1146 public: // Default property extensions from Object
1149 * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
1151 virtual unsigned int GetDefaultPropertyCount() const;
1154 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
1156 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
1159 * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
1161 virtual const char* GetDefaultPropertyName(Property::Index index) const;
1164 * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
1166 virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
1169 * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
1171 virtual bool IsDefaultPropertyWritable(Property::Index index) const;
1174 * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
1176 virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
1179 * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
1181 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
1184 * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
1186 virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
1189 * @copydoc Dali::Internal::Object::SetDefaultProperty()
1191 virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
1194 * @copydoc Dali::Internal::Object::SetSceneGraphProperty()
1196 virtual void SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value );
1199 * @copydoc Dali::Internal::Object::GetDefaultProperty()
1201 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
1204 * @copydoc Dali::Internal::Object::GetPropertyOwner()
1206 virtual const SceneGraph::PropertyOwner* GetPropertyOwner() const;
1209 * @copydoc Dali::Internal::Object::GetSceneObject()
1211 virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
1214 * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
1216 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
1219 * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
1221 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
1224 * @copydoc Dali::Internal::Object::GetPropertyComponentIndex()
1226 virtual int GetPropertyComponentIndex( Property::Index index ) const;
1234 Actor(const Actor&);
1237 Actor& operator=(const Actor& rhs);
1240 * Set the actors parent.
1241 * @param[in] parent The new parent.
1242 * @param[in] index If set, it is only used for positioning the actor within the parent's child list.
1244 void SetParent(Actor* parent, int index = -1);
1247 * Helper to create a Node for this Actor.
1248 * To be overriden in derived classes.
1249 * @return A newly allocated node.
1251 virtual SceneGraph::Node* CreateNode() const;
1254 * For use in derived classes, called after Initialize()
1256 virtual void OnInitialize() {}
1259 * For use in internal derived classes.
1260 * This is called during ConnectToStage(), after the actor has finished adding its node to the scene-graph.
1261 * The derived class must not modify the actor hierachy (Add/Remove children) during this callback.
1263 virtual void OnStageConnectionInternal() {}
1266 * For use in internal derived classes.
1267 * This is called during DisconnectFromStage(), before the actor removes its node from the scene-graph.
1268 * The derived class must not modify the actor hierachy (Add/Remove children) during this callback.
1270 virtual void OnStageDisconnectionInternal() {}
1273 * For use in external (CustomActor) derived classes.
1274 * This is called after the atomic ConnectToStage() traversal has been completed.
1276 virtual void OnStageConnectionExternal() {}
1279 * For use in external (CustomActor) derived classes.
1280 * This is called after the atomic DisconnectFromStage() traversal has been completed.
1282 virtual void OnStageDisconnectionExternal() {}
1285 * For use in derived classes; this is called after Add() has added a child.
1286 * @param[in] child The child that was added.
1288 virtual void OnChildAdd( Actor& child ) {}
1291 * For use in derived classes; this is called after Remove() has removed a child.
1292 * @param[in] child The child that was removed.
1294 virtual void OnChildRemove( Actor& child ) {}
1297 * For use in derived classes.
1298 * This is called after SizeSet() has been called.
1300 virtual void OnSizeSet(const Vector3& targetSize) {}
1303 * For use in derived classes.
1304 * This is only called if mDerivedRequiresTouch is true, and the touch-signal was not consumed.
1305 * @param[in] event The touch event.
1306 * @return True if the event should be consumed.
1308 virtual bool OnTouchEvent(const TouchEvent& event) { return false; }
1311 * For use in derived classes.
1312 * This is only called if mDerivedRequiresHover is true, and the hover-signal was not consumed.
1313 * @param[in] event The hover event.
1314 * @return True if the event should be consumed.
1316 virtual bool OnHoverEvent(const HoverEvent& event) { return false; }
1319 * For use in derived classes.
1320 * This is only called if the mouse wheel signal was not consumed.
1321 * @param[in] event The mouse event.
1322 * @return True if the event should be consumed.
1324 virtual bool OnMouseWheelEvent(const MouseWheelEvent& event) { return false; }
1328 StagePtr mStage; ///< Used to send messages to Node; valid until Core destruction
1329 Actor* mParent; ///< Each actor (except the root) can have one parent
1330 ActorContainer* mChildren; ///< Container of referenced actors
1331 const SceneGraph::Node* mNode; ///< Not owned
1332 Vector3* mParentOrigin; ///< NULL means ParentOrigin::DEFAULT. ParentOrigin is non-animatable
1333 Vector3* mAnchorPoint; ///< NULL means AnchorPoint::DEFAULT. AnchorPoint is non-animatable
1335 #ifdef DYNAMICS_SUPPORT
1336 DynamicsData* mDynamicsData; ///< optional physics data
1339 ActorGestureData* mGestureData; ///< Optional Gesture data. Only created when actor requires gestures
1341 ActorAttachmentPtr mAttachment; ///< Optional referenced attachment
1344 Dali::Actor::TouchSignalType mTouchedSignal;
1345 Dali::Actor::HoverSignalType mHoveredSignal;
1346 Dali::Actor::MouseWheelEventSignalType mMouseWheelEventSignal;
1347 Dali::Actor::OnStageSignalType mOnStageSignal;
1348 Dali::Actor::OffStageSignalType mOffStageSignal;
1350 Vector3 mSize; ///< Event-side storage for size (not a pointer as most actors will have a size)
1351 Vector3 mSizeModeFactor; ///< Factor of parent size used for certain SizeModes.
1353 std::string mName; ///< Name of the actor
1354 unsigned int mId; ///< A unique ID to identify the actor starting from 1, and 0 is reserved
1356 const bool mIsRoot : 1; ///< Flag to identify the root actor
1357 const bool mIsRenderable : 1; ///< Flag to identify that this is a renderable actor
1358 const bool mIsLayer : 1; ///< Flag to identify that this is a layer
1359 bool mIsOnStage : 1; ///< Flag to identify whether the actor is on-stage
1360 bool mIsDynamicsRoot : 1; ///< Flag to identify if this is the dynamics world root
1361 bool mSensitive : 1; ///< Whether the actor emits touch event signals
1362 bool mLeaveRequired : 1; ///< Whether a touch event signal is emitted when the a touch leaves the actor's bounds
1363 bool mKeyboardFocusable : 1; ///< Whether the actor should be focusable by keyboard navigation
1364 bool mDerivedRequiresTouch : 1; ///< Whether the derived actor type requires touch event signals
1365 bool mDerivedRequiresHover : 1; ///< Whether the derived actor type requires hover event signals
1366 bool mDerivedRequiresMouseWheelEvent : 1; ///< Whether the derived actor type requires mouse wheel event signals
1367 bool mOnStageSignalled : 1; ///< Set to true before OnStageConnection signal is emitted, and false before OnStageDisconnection
1368 bool mInheritOrientation : 1; ///< Cached: Whether the parent's orientation should be inherited.
1369 bool mInheritScale : 1; ///< Cached: Whether the parent's scale should be inherited.
1370 DrawMode::Type mDrawMode : 2; ///< Cached: How the actor and its children should be drawn
1371 PositionInheritanceMode mPositionInheritanceMode : 2; ///< Cached: Determines how position is inherited
1372 ColorMode mColorMode : 2; ///< Cached: Determines whether mWorldColor is inherited
1373 SizeMode mSizeMode : 2; ///< Cached: Determines how the actors parent affects the actors size.
1377 static ActorContainer mNullChildren; ///< Empty container (shared by all actors, returned by GetChildren() const)
1378 static unsigned int mActorCounter; ///< A counter to track the actor instance creation
1382 } // namespace Internal
1384 // Helpers for public-api forwarding methods
1386 inline Internal::Actor& GetImplementation(Dali::Actor& actor)
1388 DALI_ASSERT_ALWAYS(actor && "Actor handle is empty");
1390 BaseObject& handle = actor.GetBaseObject();
1392 return static_cast<Internal::Actor&>(handle);
1395 inline const Internal::Actor& GetImplementation(const Dali::Actor& actor)
1397 DALI_ASSERT_ALWAYS(actor && "Actor handle is empty");
1399 const BaseObject& handle = actor.GetBaseObject();
1401 return static_cast<const Internal::Actor&>(handle);
1406 #endif // __DALI_INTERNAL_ACTOR_H__