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/proxy-object.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 ProxyObject
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::FindChildByAlias
229 Dali::Actor FindChildByAlias(const std::string& actorAlias);
232 * @copydoc Dali::Actor::FindChildById
234 ActorPtr FindChildById(const unsigned int id);
237 * Retrieve the parent of an Actor.
238 * @return The parent actor, or NULL if the Actor does not have a parent.
240 Actor* GetParent() const
246 * Sets the size of an actor.
247 * ActorAttachments attached to the actor, can be scaled to fit within this area.
248 * This does not interfere with the actors scale factor.
249 * @param [in] width The new width.
250 * @param [in] height The new height.
252 void SetSize(float width, float height);
255 * Sets the size of an actor.
256 * ActorAttachments attached to the actor, can be scaled to fit within this area.
257 * This does not interfere with the actors scale factor.
258 * @param [in] width The size of the actor along the x-axis.
259 * @param [in] height The size of the actor along the y-axis.
260 * @param [in] depth The size of the actor along the z-axis.
262 void SetSize(float width, float height, float depth);
265 * Sets the size of an actor.
266 * ActorAttachments attached to the actor, can be scaled to fit within this area.
267 * This does not interfere with the actors scale factor.
268 * @param [in] size The new size.
270 void SetSize(const Vector2& size);
273 * Sets the size of an actor.
274 * ActorAttachments attached to the actor, can be scaled to fit within this area.
275 * This does not interfere with the actors scale factor.
276 * @param [in] size The new size.
278 void SetSize(const Vector3& size);
281 * Set the width component of the Actor's size.
282 * @param [in] width The new width component.
284 void SetWidth( float width );
287 * Set the height component of the Actor's size.
288 * @param [in] height The new height component.
290 void SetHeight( float height );
293 * Set the depth component of the Actor's size.
294 * @param [in] depth The new depth component.
296 void SetDepth( float depth );
299 * Retrieve the Actor's size from event side.
300 * This size will be the size set or if animating then the target size.
301 * @return The Actor's size.
303 const Vector3& GetSize() const;
306 * Retrieve the Actor's size from update side.
307 * This size will be the size set or animating but will be a frame behind.
308 * @return The Actor's size.
310 const Vector3& GetCurrentSize() const;
313 * Return the natural size of the actor
315 * @return The actor's natural size
317 virtual Vector3 GetNaturalSize() const;
320 * Set the origin of an actor, within its parent's area.
321 * This is expressed in 2D unit coordinates, such that (0.0, 0.0, 0.5) is the top-left corner of the parent,
322 * and (1.0, 1.0, 0.5) is the bottom-right corner.
323 * The default parent-origin is top-left (0.0, 0.0, 0.5).
324 * An actor position is the distance between this origin, and the actors anchor-point.
325 * @param [in] origin The new parent-origin.
327 void SetParentOrigin(const Vector3& origin);
330 * Set the x component of the parent-origin
331 * @param [in] x The new x value.
333 void SetParentOriginX( float x );
336 * Set the y component of the parent-origin
337 * @param [in] y The new y value.
339 void SetParentOriginY( float y );
342 * Set the z component of the parent-origin
343 * @param [in] z The new z value.
345 void SetParentOriginZ( float z );
348 * Retrieve the parent-origin of an actor.
349 * @return The parent-origin.
351 const Vector3& GetCurrentParentOrigin() const;
354 * Set the anchor-point of an actor. This is expressed in 2D unit coordinates, such that
355 * (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.
356 * The default anchor point is top-left (0.0, 0.0, 0.5).
357 * An actor position is the distance between its parent-origin, and this anchor-point.
358 * An actor's rotation is centered around its anchor-point.
359 * @param [in] anchorPoint The new anchor-point.
361 void SetAnchorPoint(const Vector3& anchorPoint);
364 * Set the x component of the anchor-point.
365 * @param [in] x The new x value.
367 void SetAnchorPointX( float x );
370 * Set the y component of the anchor-point.
371 * @param [in] y The new y value.
373 void SetAnchorPointY( float y );
376 * Set the z component of the anchor-point.
377 * @param [in] z The new z value.
379 void SetAnchorPointZ( float z );
382 * Retrieve the anchor-point of an actor.
383 * @return The anchor-point.
385 const Vector3& GetCurrentAnchorPoint() const;
388 * Sets the position of the Actor.
389 * The coordinates are relative to the Actor's parent.
390 * The Actor's z position will be set to 0.0f.
391 * @param [in] x The new x position
392 * @param [in] y The new y position
394 void SetPosition(float x, float y);
397 * Sets the position of the Actor.
398 * The coordinates are relative to the Actor's parent.
399 * @param [in] x The new x position
400 * @param [in] y The new y position
401 * @param [in] z The new z position
403 void SetPosition(float x, float y, float z);
406 * Sets the position of the Actor.
407 * The coordinates are relative to the Actor's parent.
408 * @param [in] position The new position.
410 void SetPosition(const Vector3& position);
413 * Set the position of an actor along the X-axis.
414 * @param [in] x The new x position
419 * Set the position of an actor along the Y-axis.
420 * @param [in] y The new y position.
425 * Set the position of an actor along the Z-axis.
426 * @param [in] z The new z position
431 * Move an actor relative to its existing position.
432 * @param[in] distance The actor will move by this distance.
434 void MoveBy(const Vector3& distance);
437 * Retrieve the position of the Actor.
438 * The coordinates are relative to the Actor's parent.
439 * @return the Actor's position.
441 const Vector3& GetCurrentPosition() const;
444 * @copydoc Dali::Actor::GetCurrentWorldPosition()
446 const Vector3& GetCurrentWorldPosition() const;
449 * @copydoc Dali::Actor::SetPositionInheritanceMode()
451 void SetPositionInheritanceMode( PositionInheritanceMode mode );
454 * @copydoc Dali::Actor::GetPositionInheritanceMode()
456 PositionInheritanceMode GetPositionInheritanceMode() const;
459 * Sets the rotation of the Actor.
460 * @param [in] angleRadians The new rotation angle in radians.
461 * @param [in] axis The new axis of rotation.
463 void SetRotation(const Radian& angleRadians, const Vector3& axis);
466 * Sets the rotation of the Actor.
467 * @param [in] rotation The new rotation.
469 void SetRotation(const Quaternion& rotation);
472 * Rotate an actor around its existing rotation axis.
473 * @param[in] angleRadians The angle to the rotation to combine with the existing rotation.
474 * @param[in] axis The axis of the rotation to combine with the existing rotation.
476 void RotateBy(const Radian& angleRadians, const Vector3& axis);
479 * Apply a relative rotation to an actor.
480 * @param[in] relativeRotation The rotation to combine with the actors existing rotation.
482 void RotateBy(const Quaternion& relativeRotation);
485 * Retreive the Actor's rotation.
486 * @return the rotation.
488 const Quaternion& GetCurrentRotation() const;
491 * Set whether a child actor inherits it's parent's orientation. Default is to inherit.
492 * Switching this off means that using SetRotation() sets the actor's world orientation.
493 * @param[in] inherit - true if the actor should inherit orientation, false otherwise.
495 void SetInheritRotation(bool inherit);
498 * Returns whether the actor inherit's it's parent's orientation.
499 * @return true if the actor inherit's it's parent orientation, false if it uses world orientation.
501 bool IsRotationInherited() const;
504 * @copydoc Dali::Actor::GetCurrentWorldRotation()
506 const Quaternion& GetCurrentWorldRotation() const;
509 * Sets a scale factor applied to an actor.
510 * @param [in] scale The scale factor applied on all axes.
512 void SetScale(float scale);
515 * Sets a scale factor applied to an actor.
516 * @param [in] scaleX The scale factor applied along the x-axis.
517 * @param [in] scaleY The scale factor applied along the y-axis.
518 * @param [in] scaleZ The scale factor applied along the z-axis.
520 void SetScale(float scaleX, float scaleY, float scaleZ);
523 * Sets a scale factor applied to an actor.
524 * @param [in] scale A vector representing the scale factor for each axis.
526 void SetScale(const Vector3& scale);
529 * Set the x component of the scale factor.
530 * @param [in] x The new x value.
532 void SetScaleX( float x );
535 * Set the y component of the scale factor.
536 * @param [in] y The new y value.
538 void SetScaleY( float y );
541 * Set the z component of the scale factor.
542 * @param [in] z The new z value.
544 void SetScaleZ( float z );
547 * Apply a relative scale to an actor.
548 * @param[in] relativeScale The scale to combine with the actors existing scale.
550 void ScaleBy(const Vector3& relativeScale);
553 * Retrieve the scale factor applied to an actor.
554 * @return A vector representing the scale factor for each axis.
556 const Vector3& GetCurrentScale() const;
559 * @copydoc Dali::Actor::GetCurrentWorldScale()
561 const Vector3& GetCurrentWorldScale() const;
564 * @copydoc Dali::Actor::SetInheritScale()
566 void SetInheritScale( bool inherit );
569 * @copydoc Dali::Actor::IsScaleInherited()
571 bool IsScaleInherited() const;
574 * @copydoc Dali::Actor::GetCurrentWorldMatrix()
576 Matrix GetCurrentWorldMatrix() const;
581 * Sets the visibility flag of an actor.
582 * @param [in] visible The new visibility flag.
584 void SetVisible(bool visible);
587 * Retrieve the visibility flag of an actor.
588 * @return The visibility flag.
590 bool IsVisible() const;
593 * Sets the opacity of an actor.
594 * @param [in] opacity The new opacity.
596 void SetOpacity(float opacity);
599 * Apply a relative opacity change to an actor.
600 * @param[in] relativeOpacity The opacity to combine with the actors existing opacity.
602 void OpacityBy(float relativeOpacity);
605 * Retrieve the actor's opacity.
606 * @return The actor's opacity.
608 float GetCurrentOpacity() const;
611 * Sets whether an actor should emit touch or hover signals; see SignalTouch() and SignalHover().
612 * An actor is sensitive by default, which means that as soon as an application connects to the SignalTouch(),
613 * the touch event signal will be emitted, and as soon as an application connects to the SignalHover(), the
614 * hover event signal will be emitted.
616 * If the application wishes to temporarily disable the touch or hover event signal emission, then they can do so by calling:
618 * actor.SetSensitive(false);
621 * Then, to re-enable the touch or hover event signal emission, the application should call:
623 * actor.SetSensitive(true);
626 * @see SignalTouch() and SignalHover().
627 * @note If an actor's sensitivity is set to false, then it's children will not emit a touch or hover event signal either.
628 * @param[in] sensitive true to enable emission of the touch or hover event signals, false otherwise.
630 void SetSensitive(bool sensitive)
632 mSensitive = sensitive;
636 * Query whether an actor emits touch or hover event signals.
637 * @see SetSensitive(bool)
638 * @return true, if emission of touch or hover event signals is enabled, false otherwise.
640 bool IsSensitive() const
646 * @copydoc Dali::Actor::SetDrawMode
648 void SetDrawMode( DrawMode::Type drawMode );
651 * @copydoc Dali::Actor::GetDrawMode
653 DrawMode::Type GetDrawMode() const;
656 * @copydoc Dali::Actor::SetOverlay
658 void SetOverlay(bool enable);
661 * @copydoc Dali::Actor::IsOverlay
663 bool IsOverlay() const;
666 * Sets whether an actor transmits geometry scaling to it's children.
667 * The default value is for it not to transmit scaling.
668 * @param[in] transmitGeometryScaling True to transmit scaling.
670 void SetTransmitGeometryScaling(bool transmitGeometryScaling);
673 * Get the TransmitGeometryScaling property for this actor.
674 * @return True if geometry scaling is applied to the inherited scale.
676 bool GetTransmitGeometryScaling() const;
679 * Sets the initial volume of the actor. Used for scaling the
680 * actor appropriately as the actor is sized when transmitGeometryScaling
683 * @param[in] volume the volume of the model and it's children
685 void SetInitialVolume(const Vector3& volume);
688 * Sets the actor's color. The final color of actor depends on its color mode.
689 * This final color is applied to the drawable elements of an actor.
690 * @param [in] color The new color.
692 void SetColor(const Vector4& color);
695 * Set the red component of the color.
696 * @param [in] red The new red component.
698 void SetColorRed( float red );
701 * Set the green component of the color.
702 * @param [in] green The new green component.
704 void SetColorGreen( float green );
707 * Set the blue component of the scale factor.
708 * @param [in] blue The new blue value.
710 void SetColorBlue( float blue );
713 * Apply a relative color change to an actor.
714 * @param[in] relativeColor The color to combine with the actors existing color.
716 void ColorBy(const Vector4& relativeColor);
719 * Retrieve the actor's color.
722 const Vector4& GetCurrentColor() const;
725 * Sets the actor's color mode.
726 * Color mode specifies whether Actor uses its own color or inherits its parent color
727 * @param [in] colorMode to use.
729 void SetColorMode(ColorMode colorMode);
732 * Returns the actor's color mode.
733 * @return currently used colorMode.
735 ColorMode GetColorMode() const;
738 * @copydoc Dali::Actor::GetCurrentWorldColor()
740 const Vector4& GetCurrentWorldColor() const;
742 #ifdef DYNAMICS_SUPPORT
746 /// @copydoc Dali::Actor::DisableDynamics
747 void DisableDynamics();
749 /// @copydoc Dali::Actor::EnableDynamics(Dali::DynamicsBodyConfig)
750 DynamicsBodyPtr EnableDynamics(DynamicsBodyConfigPtr bodyConfig);
752 /// @copydoc Dali::Actor::GetDynamicsBody
753 DynamicsBodyPtr GetDynamicsBody() const;
755 /// @copydoc Dali::Actor::AddDynamicsJoint(Dali::Actor,const Vector3&)
756 DynamicsJointPtr AddDynamicsJoint( ActorPtr attachedActor, const Vector3& offset );
758 /// @copydoc Dali::Actor::AddDynamicsJoint(Dali::Actor,const Vector3&,const Vector3&)
759 DynamicsJointPtr AddDynamicsJoint( ActorPtr attachedActor, const Vector3& offsetA, const Vector3& offsetB );
761 /// @copydoc Dali::Actor::GetNumberOfJoints
762 const int GetNumberOfJoints() const;
764 /// @copydoc Dali::Actor::GetDynamicsJointByIndex
765 DynamicsJointPtr GetDynamicsJointByIndex( const int index ) const;
767 /// @copydoc Dali::Actor::GetDynamicsJoint
768 DynamicsJointPtr GetDynamicsJoint( ActorPtr attachedActor ) const;
770 /// @copydoc Dali::Actor::RemoveDynamicsJoint
771 void RemoveDynamicsJoint( DynamicsJointPtr joint );
774 * Hold a reference to a DynamicsJoint
775 * @param[in] joint The joint
777 void ReferenceJoint( DynamicsJointPtr joint );
780 * Release a reference to a DynamicsJoint
781 * @param[in] joint The joint
783 void ReleaseJoint( DynamicsJointPtr joint );
786 * Set this actor to be the root actor in the dynamics simulation
787 * All children of the actor are added/removed from the simulation.
788 * @param[in] flag When true sets this actor to be the simulation world root actor and
789 * if OnStage() all dynamics enabled child actors are added to the simulation,
790 * when false stops this actor being the simulation root and if OnStage() all
791 * dynamics enabled child actors are removed from the simulation.
793 void SetDynamicsRoot(bool flag);
797 * Check if this actor is the root actor in the dynamics simulation
798 * @return true if this is the dynamics root actor.
800 bool IsDynamicsRoot() const;
803 * Add actor to the dynamics simulation
804 * Invoked when the actor is staged, or it's parent becomes the simulation root
806 void ConnectDynamics();
809 * Remove actor from the dynamics simulation
810 * Invoked when the actor is unstaged, or it's parent stops being the the simulation root
812 void DisconnectDynamics();
815 * An actor in a DynamicsJoint relationship has been staged
816 * @param[in] actor The actor passed into AddDynamicsJoint()
818 void AttachedActorOnStage( Dali::Actor actor );
821 * An actor in a DynamicsJoint relationship has been unstaged
822 * @param[in] actor The actor passed into AddDynamicsJoint()
824 void AttachedActorOffStage( Dali::Actor actor );
826 #endif // DYNAMICS_SUPPORT
830 * Converts screen coordinates into the actor's coordinate system.
831 * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
832 * @param[out] localX On return, the X-coordinate relative to the actor.
833 * @param[out] localY On return, the Y-coordinate relative to the actor.
834 * @param[in] screenX The screen X-coordinate.
835 * @param[in] screenY The screen Y-coordinate.
836 * @return True if the conversion succeeded.
838 bool ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const;
841 * Converts screen coordinates into the actor's coordinate system.
842 * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
843 * @param[in] renderTask The render-task used to display the actor.
844 * @param[out] localX On return, the X-coordinate relative to the actor.
845 * @param[out] localY On return, the Y-coordinate relative to the actor.
846 * @param[in] screenX The screen X-coordinate.
847 * @param[in] screenY The screen Y-coordinate.
848 * @return True if the conversion succeeded.
850 bool ScreenToLocal(RenderTask& renderTask, float& localX, float& localY, float screenX, float screenY) const;
853 * Converts from the actor's coordinate system to screen coordinates.
854 * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
855 * @param[in] viewMatrix The view-matrix
856 * @param[in] projectionMatrix The projection-matrix
857 * @param[in] viewport The view-port
858 * @param[out] localX On return, the X-coordinate relative to the actor.
859 * @param[out] localY On return, the Y-coordinate relative to the actor.
860 * @param[in] screenX The screen X-coordinate.
861 * @param[in] screenY The screen Y-coordinate.
862 * @return True if the conversion succeeded.
864 bool ScreenToLocal( const Matrix& viewMatrix,
865 const Matrix& projectionMatrix,
866 const Viewport& viewport,
870 float screenY ) const;
873 * Performs a ray-sphere test with the given pick-ray and the actor's bounding sphere.
874 * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
875 * @param[in] rayOrigin The ray origin in the world's reference system.
876 * @param[in] rayDir The ray director vector in the world's reference system.
877 * @return True if the ray intersects the actor's bounding sphere.
879 bool RaySphereTest( const Vector4& rayOrigin, const Vector4& rayDir ) const;
882 * Performs a ray-actor test with the given pick-ray and the actor's geometry.
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 * @param[out] hitPointLocal The hit point in the Actor's local reference system.
887 * @param[out] distance The distance from the hit point to the camera.
888 * @return True if the ray intersects the actor's geometry.
890 bool RayActorTest( const Vector4& rayOrigin, const Vector4& rayDir, Vector4& hitPointLocal, float& distance ) const;
893 * Sets whether the actor should receive a notification when touch or hover motion events leave
894 * the boundary of the actor.
896 * @note By default, this is set to false as most actors do not require this.
897 * @note Need to connect to the SignalTouch or SignalHover to actually receive this event.
899 * @param[in] required Should be set to true if a Leave event is required
901 void SetLeaveRequired(bool required);
904 * This returns whether the actor requires touch or hover events whenever touch or hover motion events leave
905 * the boundary of the actor.
906 * @return true if a Leave event is required, false otherwise.
908 bool GetLeaveRequired() const;
911 * @copydoc Dali::Actor::SetKeyboardFocusable()
913 void SetKeyboardFocusable( bool focusable );
916 * @copydoc Dali::Actor::IsKeyboardFocusable()
918 bool IsKeyboardFocusable() const;
921 * Query whether the application or derived actor type requires touch events.
922 * @return True if touch events are required.
924 bool GetTouchRequired() const;
927 * Query whether the application or derived actor type requires hover events.
928 * @return True if hover events are required.
930 bool GetHoverRequired() const;
933 * Query whether the application or derived actor type requires mouse wheel events.
934 * @return True if mouse wheel events are required.
936 bool GetMouseWheelEventRequired() const;
939 * Query whether the actor is actually hittable. This method checks whether the actor is
940 * sensitive, has the visibility flag set to true and is not fully transparent.
941 * @return true, if it can be hit, false otherwise.
943 bool IsHittable() const;
948 * Retrieve the gesture data associated with this actor. The first call to this method will
949 * allocate space for the ActorGestureData so this should only be called if an actor really does
951 * @return Reference to the ActorGestureData for this actor.
952 * @note Once the gesture-data is created for an actor it is likely that gestures are required
953 * throughout the actor's lifetime so it will only be deleted when the actor is destroyed.
955 ActorGestureData& GetGestureData();
958 * Queries whether the actor requires the gesture type.
959 * @param[in] type The gesture type.
961 bool IsGestureRequred( Gesture::Type type ) const;
966 * Used by the EventProcessor to emit touch event signals.
967 * @param[in] event The touch event.
968 * @return True if the event was consumed.
970 bool EmitTouchEventSignal(const TouchEvent& event);
973 * Used by the EventProcessor to emit hover event signals.
974 * @param[in] event The hover event.
975 * @return True if the event was consumed.
977 bool EmitHoverEventSignal(const HoverEvent& event);
980 * Used by the EventProcessor to emit mouse wheel event signals.
981 * @param[in] event The mouse wheel event.
982 * @return True if the event was consumed.
984 bool EmitMouseWheelEventSignal(const MouseWheelEvent& event);
987 * @copydoc Dali::Actor::TouchedSignal()
989 Dali::Actor::TouchSignalV2& TouchedSignal();
992 * @copydoc Dali::Actor::HoveredSignal()
994 Dali::Actor::HoverSignalV2& HoveredSignal();
997 * @copydoc Dali::Actor::MouseWheelEventSignal()
999 Dali::Actor::MouseWheelEventSignalV2& MouseWheelEventSignal();
1002 * @copydoc Dali::Actor::SetSizeSignal()
1004 Dali::Actor::SetSizeSignalV2& SetSizeSignal();
1007 * @copydoc Dali::Actor::OnStageSignal()
1009 Dali::Actor::OnStageSignalV2& OnStageSignal();
1012 * @copydoc Dali::Actor::OffStageSignal()
1014 Dali::Actor::OffStageSignalV2& OffStageSignal();
1017 * Connects a callback function with the object's signals.
1018 * @param[in] object The object providing the signal.
1019 * @param[in] tracker Used to disconnect the signal.
1020 * @param[in] signalName The signal to connect to.
1021 * @param[in] functor A newly allocated FunctorDelegate.
1022 * @return True if the signal was connected.
1023 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
1025 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
1028 * Performs actions as requested using the action name.
1029 * @param[in] object The object on which to perform the action.
1030 * @param[in] actionName The action to perform.
1031 * @param[in] attributes The attributes with which to perfrom this action.
1032 * @return true if the action was done.
1034 static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
1036 public: // For Animation
1039 * This should only be called by Animation, when the actor is resized using Animation::Resize().
1041 * @param[in] animation The animation that resized the actor
1042 * @param[in] targetSize The new target size of the actor
1044 void NotifySizeAnimation( Animation& animation, const Vector3& targetSize);
1047 * For use in derived classes.
1048 * This should only be called by Animation, when the actor is resized using Animation::Resize().
1050 virtual void OnSizeAnimation( Animation& animation, const Vector3& targetSize) {}
1063 * Protected Constructor. See Actor::New().
1064 * The second-phase construction Initialize() member should be called immediately after this.
1065 * @param[in] derivedType The derived type of actor (if any).
1067 Actor( DerivedType derivedType );
1070 * Second-phase constructor. Must be called immediately after creating a new Actor;
1072 void Initialize(void);
1075 * A reference counted object may only be deleted by calling Unreference()
1080 * Called on a child during Add() when the parent actor is connected to the Stage.
1081 * @param[in] stage The stage.
1082 * @param[in] index If set, it is only used for positioning the actor within the parent's child list.
1084 void ConnectToStage(Stage& stage, int index = -1);
1087 * Helper for ConnectToStage, to recursively connect a tree of actors.
1088 * This is atomic i.e. not interrupted by user callbacks.
1089 * @param[in] stage The stage.
1090 * @param[in] index If set, it is only used for positioning the actor within the parent's child list.
1091 * @param[out] connectionList On return, the list of connected actors which require notification.
1093 void RecursiveConnectToStage( Stage& stage, ActorContainer& connectionList, int index = -1 );
1096 * Connect the Node associated with this Actor to the scene-graph.
1097 * @param[in] index If set, it is only used for positioning the actor within the parent's child list.
1099 void ConnectToSceneGraph(int index = -1);
1102 * Helper for ConnectToStage, to notify a connected actor through the public API.
1104 void NotifyStageConnection();
1107 * Called on a child during Remove() when the actor was previously on the Stage.
1109 void DisconnectFromStage();
1112 * Helper for DisconnectFromStage, to recursively disconnect a tree of actors.
1113 * This is atomic i.e. not interrupted by user callbacks.
1114 * @param[out] disconnectionList On return, the list of disconnected actors which require notification.
1116 void RecursiveDisconnectFromStage( ActorContainer& disconnectionList );
1119 * Disconnect the Node associated with this Actor from the scene-graph.
1121 void DisconnectFromSceneGraph();
1124 * Helper for DisconnectFromStage, to notify a disconnected actor through the public API.
1126 void NotifyStageDisconnection();
1129 * When the Actor is OnStage, checks whether the corresponding Node is connected to the scene graph.
1130 * @return True if the Actor is OnStage & has a Node connected to the scene graph.
1132 bool IsNodeConnected() const;
1135 * Calculate the size of the z dimension for a 2D size
1137 * @param[in] size The 2D size (X, Y) to calculate Z from
1139 * @return Return the Z dimension for this size
1141 float CalculateSizeZ( const Vector2& size ) const;
1143 public: // Default property extensions from ProxyObject
1146 * @copydoc Dali::Internal::ProxyObject::IsSceneObjectRemovable()
1148 virtual bool IsSceneObjectRemovable() const;
1151 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyCount()
1153 virtual unsigned int GetDefaultPropertyCount() const;
1156 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndices()
1158 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
1161 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyName()
1163 virtual const char* GetDefaultPropertyName(Property::Index index) const;
1166 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndex()
1168 virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
1171 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyWritable()
1173 virtual bool IsDefaultPropertyWritable(Property::Index index) const;
1176 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAnimatable()
1178 virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
1181 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAConstraintInput()
1183 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
1186 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyType()
1188 virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
1191 * @copydoc Dali::Internal::ProxyObject::SetDefaultProperty()
1193 virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
1196 * @copydoc Dali::Internal::ProxyObject::SetCustomProperty()
1198 virtual void SetCustomProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value );
1201 * @copydoc Dali::Internal::ProxyObject::GetDefaultProperty()
1203 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
1206 * @copydoc Dali::Internal::ProxyObject::InstallSceneObjectProperty()
1208 virtual void InstallSceneObjectProperty( SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index );
1211 * @copydoc Dali::Internal::ProxyObject::GetSceneObject()
1213 virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
1216 * @copydoc Dali::Internal::ProxyObject::GetSceneObjectAnimatableProperty()
1218 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
1221 * @copydoc Dali::Internal::ProxyObject::GetSceneObjectInputProperty()
1223 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
1226 * @copydoc Dali::Internal::ProxyObject::GetPropertyComponentIndex()
1228 virtual int GetPropertyComponentIndex( Property::Index index ) const;
1236 Actor(const Actor&);
1239 Actor& operator=(const Actor& rhs);
1242 * Set the actors parent.
1243 * @param[in] parent The new parent.
1244 * @param[in] index If set, it is only used for positioning the actor within the parent's child list.
1246 void SetParent(Actor* parent, int index = -1);
1249 * Helper to create a Node for this Actor.
1250 * To be overriden in derived classes.
1251 * @return A newly allocated node.
1253 virtual SceneGraph::Node* CreateNode() const;
1256 * For use in derived classes, called after Initialize()
1258 virtual void OnInitialize() {}
1261 * For use in internal derived classes.
1262 * This is called during ConnectToStage(), after the actor has finished adding its node to the scene-graph.
1263 * The derived class must not modify the actor hierachy (Add/Remove children) during this callback.
1265 virtual void OnStageConnectionInternal() {}
1268 * For use in internal derived classes.
1269 * This is called during DisconnectFromStage(), before the actor removes its node from the scene-graph.
1270 * The derived class must not modify the actor hierachy (Add/Remove children) during this callback.
1272 virtual void OnStageDisconnectionInternal() {}
1275 * For use in external (CustomActor) derived classes.
1276 * This is called after the atomic ConnectToStage() traversal has been completed.
1278 virtual void OnStageConnectionExternal() {}
1281 * For use in external (CustomActor) derived classes.
1282 * This is called after the atomic DisconnectFromStage() traversal has been completed.
1284 virtual void OnStageDisconnectionExternal() {}
1287 * For use in derived classes; this is called after Add() has added a child.
1288 * @param[in] child The child that was added.
1290 virtual void OnChildAdd( Actor& child ) {}
1293 * For use in derived classes; this is called after Remove() has removed a child.
1294 * @param[in] child The child that was removed.
1296 virtual void OnChildRemove( Actor& child ) {}
1299 * For use in derived classes.
1300 * This is called after SizeSet() has been called.
1302 virtual void OnSizeSet(const Vector3& targetSize) {}
1305 * For use in derived classes.
1306 * This is called after a non animatable custom property is set.
1307 * @param [in] index The index of the property.
1308 * @param [in] propertyValue The value of the property.
1310 virtual void OnPropertySet( Property::Index index, Property::Value propertyValue ) {}
1313 * For use in derived classes.
1314 * This is only called if mDerivedRequiresTouch is true, and the touch-signal was not consumed.
1315 * @param[in] event The touch event.
1316 * @return True if the event should be consumed.
1318 virtual bool OnTouchEvent(const TouchEvent& event) { return false; }
1321 * For use in derived classes.
1322 * This is only called if mDerivedRequiresHover is true, and the hover-signal was not consumed.
1323 * @param[in] event The hover event.
1324 * @return True if the event should be consumed.
1326 virtual bool OnHoverEvent(const HoverEvent& event) { return false; }
1329 * For use in derived classes.
1330 * This is only called if the mouse wheel signal was not consumed.
1331 * @param[in] event The mouse event.
1332 * @return True if the event should be consumed.
1334 virtual bool OnMouseWheelEvent(const MouseWheelEvent& event) { return false; }
1337 * For use in derived class
1338 * If an alias for a child exists, return the child otherwise return an empty handle.
1339 * For example 'previous' could return the last selected child.
1340 * @pre The Actor has been initialized.
1341 * @param[in] actorAlias the name of the actor to find
1342 * @return A handle to the actor if found, or an empty handle if not.
1344 virtual Dali::Actor GetChildByAlias(const std::string& actorAlias) { return Dali::Actor(); }
1347 * Support function for FindChildByAlias
1348 * @pre The Actor has been initialized.
1349 * @param[in] actorAlias the name of the aliased actor to find
1350 * @return A handle to the actor if found, or an empty handle if not.
1352 Dali::Actor DoGetChildByAlias(const std::string& actorAlias);
1356 StagePtr mStage; ///< Used to send messages to Node; valid until Core destruction
1357 Actor* mParent; ///< Each actor (except the root) can have one parent
1358 ActorContainer* mChildren; ///< Container of referenced actors
1359 const SceneGraph::Node* mNode; ///< Not owned
1360 Vector3* mParentOrigin; // NULL means ParentOrigin::DEFAULT. ParentOrigin is non-animatable
1361 Vector3* mAnchorPoint; // NULL means AnchorPoint::DEFAULT. AnchorPoint is non-animatable
1363 #ifdef DYNAMICS_SUPPORT
1364 DynamicsData* mDynamicsData; ///< optional physics data
1367 ActorGestureData* mGestureData; /// Optional Gesture data. Only created when actor requires gestures
1369 ActorAttachmentPtr mAttachment; ///< Optional referenced attachment
1372 Dali::Actor::TouchSignalV2 mTouchedSignalV2;
1373 Dali::Actor::HoverSignalV2 mHoveredSignalV2;
1374 Dali::Actor::MouseWheelEventSignalV2 mMouseWheelEventSignalV2;
1375 Dali::Actor::SetSizeSignalV2 mSetSizeSignalV2;
1376 Dali::Actor::OnStageSignalV2 mOnStageSignalV2;
1377 Dali::Actor::OffStageSignalV2 mOffStageSignalV2;
1379 Vector3 mSize; ///< Event-side storage for size (not a pointer as most actors will have a size)
1381 std::string mName; ///< Name of the actor
1382 unsigned int mId; ///< A unique ID to identify the actor starting from 1, and 0 is reserved
1384 const bool mIsRoot : 1; ///< Flag to identify the root actor
1385 const bool mIsRenderable : 1; ///< Flag to identify that this is a renderable actor
1386 const bool mIsLayer : 1; ///< Flag to identify that this is a layer
1387 bool mIsOnStage : 1; ///< Flag to identify whether the actor is on-stage
1388 bool mIsDynamicsRoot : 1; ///< Flag to identify if this is the dynamics world root
1389 bool mSensitive : 1; ///< Whether the actor emits touch event signals
1390 bool mLeaveRequired : 1; ///< Whether a touch event signal is emitted when the a touch leaves the actor's bounds
1391 bool mKeyboardFocusable : 1; ///< Whether the actor should be focusable by keyboard navigation
1392 bool mDerivedRequiresTouch : 1; ///< Whether the derived actor type requires touch event signals
1393 bool mDerivedRequiresHover : 1; ///< Whether the derived actor type requires hover event signals
1394 bool mDerivedRequiresMouseWheelEvent : 1; ///< Whether the derived actor type requires mouse wheel event signals
1395 bool mOnStageSignalled : 1; ///< Set to true before OnStageConnection signal is emitted, and false before OnStageDisconnection
1396 bool mInheritRotation : 1; ///< Cached: Whether the parent's rotation should be inherited.
1397 bool mInheritScale : 1; ///< Cached: Whether the parent's scale should be inherited.
1398 DrawMode::Type mDrawMode : 2; ///< Cached: How the actor and its children should be drawn
1399 PositionInheritanceMode mPositionInheritanceMode : 2; ///< Cached: Determines how position is inherited
1400 ColorMode mColorMode : 2; ///< Cached: Determines whether mWorldColor is inherited
1404 static ActorContainer mNullChildren; ///< Empty container (shared by all actors, returned by GetChildren() const)
1405 static unsigned int mActorCounter; ///< A counter to track the actor instance creation
1409 } // namespace Internal
1411 // Helpers for public-api forwarding methods
1413 inline Internal::Actor& GetImplementation(Dali::Actor& actor)
1415 DALI_ASSERT_ALWAYS(actor && "Actor handle is empty");
1417 BaseObject& handle = actor.GetBaseObject();
1419 return static_cast<Internal::Actor&>(handle);
1422 inline const Internal::Actor& GetImplementation(const Dali::Actor& actor)
1424 DALI_ASSERT_ALWAYS(actor && "Actor handle is empty");
1426 const BaseObject& handle = actor.GetBaseObject();
1428 return static_cast<const Internal::Actor&>(handle);
1433 #endif // __DALI_INTERNAL_ACTOR_H__