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/map-wrapper.h>
26 #include <dali/public-api/common/vector-wrapper.h>
27 #include <dali/public-api/object/ref-object.h>
28 #include <dali/public-api/actors/actor.h>
29 #include <dali/public-api/common/dali-common.h>
30 #include <dali/public-api/events/gesture.h>
31 #include <dali/public-api/math/viewport.h>
32 #include <dali/internal/event/common/proxy-object.h>
33 #include <dali/internal/event/common/stage-def.h>
34 #include <dali/internal/event/actors/actor-declarations.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>
47 struct MouseWheelEvent;
53 class ActorGestureData;
57 typedef IntrusivePtr<Actor> ActorPtr;
58 typedef Dali::ActorContainer ActorContainer; // Store handles to return via public-api
59 typedef ActorContainer::iterator ActorIter;
60 typedef ActorContainer::const_iterator ActorConstIter;
63 * Actor is the primary object which Dali applications interact with.
64 * UI controls can be built by combining multiple actors.
65 * Multi-Touch events are received through signals emitted by the actor tree.
67 * An Actor is a proxy for a Node in the scene graph.
68 * When an Actor is added to the Stage, it creates a node and attaches it to the scene graph.
69 * The scene-graph can be updated in a separate thread, so the attachment is done using an asynchronous message.
70 * When a tree of Actors is detached from the Stage, a message is sent to destroy the associated nodes.
72 class Actor : public ProxyObject
78 * @return A smart-pointer to the newly allocated Actor.
80 static ActorPtr New();
83 * Retrieve the name of the actor.
86 const std::string& GetName() const;
89 * Set the name of the actor.
90 * @param[in] name The new name.
92 void SetName(const std::string& name);
95 * @copydoc Dali::Actor::GetId
97 unsigned int GetId() const;
102 * Attach an object to an actor.
103 * @pre The actor does not already have an attachment.
104 * @param[in] attachment The object to attach.
106 void Attach(ActorAttachment& attachment);
109 * Retreive the object attached to an actor.
110 * @return The attachment.
112 ActorAttachmentPtr GetAttachment();
117 * Query whether an actor is the root actor, which is owned by the Stage.
118 * @return True if the actor is a root actor.
126 * Query whether the actor is connected to the Stage.
128 bool OnStage() const;
131 * Query whether the actor is a RenderableActor derived type.
132 * @return True if the actor is renderable.
134 bool IsRenderable() const
136 // inlined as this is called a lot in hit testing
137 return mIsRenderable;
141 * Query whether the actor is of class Dali::Layer
142 * @return True if the actor is a layer.
146 // inlined as this is called a lot in hit testing
151 * Gets the layer in which the actor is present
152 * @return The layer, which will be uninitialized if the actor is off-stage.
154 Dali::Layer GetLayer();
157 * Adds a child Actor to this Actor.
158 * @pre The child actor is not the same as the parent actor.
159 * @pre The child actor does not already have a parent.
160 * @param [in] child The child.
161 * @post The child will be referenced by its parent.
163 void Add(Actor& child);
166 * Removes a child Actor from this Actor.
167 * @param [in] child The child.
168 * @post The child will be unreferenced.
170 void Remove(Actor& child);
173 * @copydoc Dali::Actor::Unparent
178 * Retrieve the number of children held by the actor.
179 * @return The number of children
181 unsigned int GetChildCount() const;
184 * @copydoc Dali::Actor::GetChildAt
186 Dali::Actor GetChildAt(unsigned int index) const;
189 * Retrieve the Actor's children.
190 * @return A copy of the container of children.
192 ActorContainer GetChildren();
195 * Retrieve the Actor's children.
196 * @return A const reference to the container of children.
198 const ActorContainer& GetChildren() const;
201 * Retrieve a reference to Actor's children.
202 * @note Not for public use.
203 * @return A reference to the container of children.
205 ActorContainer& GetChildrenInternal()
211 * @copydoc Dali::Actor::FindChildByName
213 ActorPtr FindChildByName(const std::string& actorName);
216 * @copydoc Dali::Actor::FindChildByAlias
218 Dali::Actor FindChildByAlias(const std::string& actorAlias);
221 * @copydoc Dali::Actor::FindChildById
223 ActorPtr FindChildById(const unsigned int id);
226 * Retrieve the parent of an Actor.
227 * @return The parent actor, or NULL if the Actor does not have a parent.
229 Actor* GetParent() const
235 * Sets the size of an actor.
236 * ActorAttachments attached to the actor, can be scaled to fit within this area.
237 * This does not interfere with the actors scale factor.
238 * @param [in] width The new width.
239 * @param [in] height The new height.
241 void SetSize(float width, float height);
244 * Sets the size of an actor.
245 * ActorAttachments attached to the actor, can be scaled to fit within this area.
246 * This does not interfere with the actors scale factor.
247 * @param [in] width The size of the actor along the x-axis.
248 * @param [in] height The size of the actor along the y-axis.
249 * @param [in] depth The size of the actor along the z-axis.
251 void SetSize(float width, float height, float depth);
254 * Sets the size of an actor.
255 * ActorAttachments attached to the actor, can be scaled to fit within this area.
256 * This does not interfere with the actors scale factor.
257 * @param [in] size The new size.
259 void SetSize(const Vector2& size);
262 * Sets the size of an actor.
263 * ActorAttachments attached to the actor, can be scaled to fit within this area.
264 * This does not interfere with the actors scale factor.
265 * @param [in] size The new size.
267 void SetSize(const Vector3& size);
270 * Set the width component of the Actor's size.
271 * @param [in] width The new width component.
273 void SetWidth( float width );
276 * Set the height component of the Actor's size.
277 * @param [in] height The new height component.
279 void SetHeight( float height );
282 * Set the depth component of the Actor's size.
283 * @param [in] depth The new depth component.
285 void SetDepth( float depth );
288 * Retrieve the Actor's size.
289 * @return The Actor's size.
291 const Vector3& GetCurrentSize() const;
294 * Set the origin of an actor, within its parent's area.
295 * This is expressed in 2D unit coordinates, such that (0.0, 0.0, 0.5) is the top-left corner of the parent,
296 * and (1.0, 1.0, 0.5) is the bottom-right corner.
297 * The default parent-origin is top-left (0.0, 0.0, 0.5).
298 * An actor position is the distance between this origin, and the actors anchor-point.
299 * @param [in] origin The new parent-origin.
301 void SetParentOrigin(const Vector3& origin);
304 * Set the x component of the parent-origin
305 * @param [in] x The new x value.
307 void SetParentOriginX( float x );
310 * Set the y component of the parent-origin
311 * @param [in] y The new y value.
313 void SetParentOriginY( float y );
316 * Set the z component of the parent-origin
317 * @param [in] z The new z value.
319 void SetParentOriginZ( float z );
322 * Retrieve the parent-origin of an actor.
323 * @return The parent-origin.
325 const Vector3& GetCurrentParentOrigin() const;
328 * Set the anchor-point of an actor. This is expressed in 2D unit coordinates, such that
329 * (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.
330 * The default anchor point is top-left (0.0, 0.0, 0.5).
331 * An actor position is the distance between its parent-origin, and this anchor-point.
332 * An actor's rotation is centered around its anchor-point.
333 * @param [in] anchorPoint The new anchor-point.
335 void SetAnchorPoint(const Vector3& anchorPoint);
338 * Set the x component of the anchor-point.
339 * @param [in] x The new x value.
341 void SetAnchorPointX( float x );
344 * Set the y component of the anchor-point.
345 * @param [in] y The new y value.
347 void SetAnchorPointY( float y );
350 * Set the z component of the anchor-point.
351 * @param [in] z The new z value.
353 void SetAnchorPointZ( float z );
356 * Retrieve the anchor-point of an actor.
357 * @return The anchor-point.
359 const Vector3& GetCurrentAnchorPoint() const;
362 * Sets the position of the Actor.
363 * The coordinates are relative to the Actor's parent.
364 * The Actor's z position will be set to 0.0f.
365 * @param [in] x The new x position
366 * @param [in] y The new y position
368 void SetPosition(float x, float y);
371 * Sets the position of the Actor.
372 * The coordinates are relative to the Actor's parent.
373 * @param [in] x The new x position
374 * @param [in] y The new y position
375 * @param [in] z The new z position
377 void SetPosition(float x, float y, float z);
380 * Sets the position of the Actor.
381 * The coordinates are relative to the Actor's parent.
382 * @param [in] position The new position.
384 void SetPosition(const Vector3& position);
387 * Set the position of an actor along the X-axis.
388 * @param [in] x The new x position
393 * Set the position of an actor along the Y-axis.
394 * @param [in] y The new y position.
399 * Set the position of an actor along the Z-axis.
400 * @param [in] z The new z position
405 * Move an actor relative to its existing position.
406 * @param[in] distance The actor will move by this distance.
408 void MoveBy(const Vector3& distance);
411 * Retrieve the position of the Actor.
412 * The coordinates are relative to the Actor's parent.
413 * @return the Actor's position.
415 const Vector3& GetCurrentPosition() const;
418 * @copydoc Dali::Actor::GetCurrentWorldPosition()
420 const Vector3& GetCurrentWorldPosition() const;
423 * @copydoc Dali::Actor::SetPositionInheritanceMode()
425 void SetPositionInheritanceMode( PositionInheritanceMode mode );
428 * @copydoc Dali::Actor::GetPositionInheritanceMode()
430 PositionInheritanceMode GetPositionInheritanceMode() const;
433 * Sets the rotation of the Actor.
434 * @param [in] angleRadians The new rotation angle in radians.
435 * @param [in] axis The new axis of rotation.
437 void SetRotation(const Radian& angleRadians, const Vector3& axis);
440 * Sets the rotation of the Actor.
441 * @param [in] rotation The new rotation.
443 void SetRotation(const Quaternion& rotation);
446 * Rotate an actor around its existing rotation axis.
447 * @param[in] angleRadians The angle to the rotation to combine with the existing rotation.
448 * @param[in] axis The axis of the rotation to combine with the existing rotation.
450 void RotateBy(const Radian& angleRadians, const Vector3& axis);
453 * Apply a relative rotation to an actor.
454 * @param[in] relativeRotation The rotation to combine with the actors existing rotation.
456 void RotateBy(const Quaternion& relativeRotation);
459 * Retreive the Actor's rotation.
460 * @return the rotation.
462 const Quaternion& GetCurrentRotation() const;
465 * Set whether a child actor inherits it's parent's orientation. Default is to inherit.
466 * Switching this off means that using SetRotation() sets the actor's world orientation.
467 * @param[in] inherit - true if the actor should inherit orientation, false otherwise.
469 void SetInheritRotation(bool inherit);
472 * Returns whether the actor inherit's it's parent's orientation.
473 * @return true if the actor inherit's it's parent orientation, false if it uses world orientation.
475 bool IsRotationInherited() const;
478 * @copydoc Dali::Actor::GetCurrentWorldRotation()
480 const Quaternion& GetCurrentWorldRotation() const;
483 * Sets a scale factor applied to an actor.
484 * @param [in] scale The scale factor applied on all axes.
486 void SetScale(float scale);
489 * Sets a scale factor applied to an actor.
490 * @param [in] scaleX The scale factor applied along the x-axis.
491 * @param [in] scaleY The scale factor applied along the y-axis.
492 * @param [in] scaleZ The scale factor applied along the z-axis.
494 void SetScale(float scaleX, float scaleY, float scaleZ);
497 * Sets a scale factor applied to an actor.
498 * @param [in] scale A vector representing the scale factor for each axis.
500 void SetScale(const Vector3& scale);
503 * Set the x component of the scale factor.
504 * @param [in] x The new x value.
506 void SetScaleX( float x );
509 * Set the y component of the scale factor.
510 * @param [in] y The new y value.
512 void SetScaleY( float y );
515 * Set the z component of the scale factor.
516 * @param [in] z The new z value.
518 void SetScaleZ( float z );
521 * Apply a relative scale to an actor.
522 * @param[in] relativeScale The scale to combine with the actors existing scale.
524 void ScaleBy(const Vector3& relativeScale);
527 * Retrieve the scale factor applied to an actor.
528 * @return A vector representing the scale factor for each axis.
530 const Vector3& GetCurrentScale() const;
533 * @copydoc Dali::Actor::GetCurrentWorldScale()
535 const Vector3& GetCurrentWorldScale() const;
538 * @copydoc Dali::Actor::SetInheritScale()
540 void SetInheritScale( bool inherit );
543 * @copydoc Dali::Actor::IsScaleInherited()
545 bool IsScaleInherited() const;
548 * @copydoc Dali::Actor::GetCurrentWorldMatrix()
550 Matrix GetCurrentWorldMatrix() const;
555 * Sets the visibility flag of an actor.
556 * @param [in] visible The new visibility flag.
558 void SetVisible(bool visible);
561 * Retrieve the visibility flag of an actor.
562 * @return The visibility flag.
564 bool IsVisible() const;
567 * Sets the opacity of an actor.
568 * @param [in] opacity The new opacity.
570 void SetOpacity(float opacity);
573 * Apply a relative opacity change to an actor.
574 * @param[in] relativeOpacity The opacity to combine with the actors existing opacity.
576 void OpacityBy(float relativeOpacity);
579 * Retrieve the actor's opacity.
580 * @return The actor's opacity.
582 float GetCurrentOpacity() const;
585 * Sets whether an actor should emit touch signals; see SignalTouch().
586 * An actor is sensitive by default, which means that as soon as an application connects to the SignalTouch(),
587 * the touch event signal will be emitted.
589 * If the application wishes to temporarily disable the touch event signal emission, then they can do so by calling:
591 * actor.SetSensitive(false);
594 * Then, to re-enable the touch event signal emission, the application should call:
596 * actor.SetSensitive(true);
599 * @see SignalTouch().
600 * @note If an actor's sensitivity is set to false, then it's children will not emit a touch event signal either.
601 * @param[in] sensitive true to enable emission of the touch event signals, false otherwise.
603 void SetSensitive(bool sensitive)
605 mSensitive = sensitive;
609 * Query whether an actor emits touch event signals.
610 * @see SetSensitive(bool)
611 * @return true, if emission of touch event signals is enabled, false otherwise.
613 bool IsSensitive() const
619 * @copydoc Dali::Actor::SetDrawMode
621 void SetDrawMode( DrawMode::Type drawMode );
624 * @copydoc Dali::Actor::GetDrawMode
626 DrawMode::Type GetDrawMode() const;
629 * @copydoc Dali::Actor::SetOverlay
631 void SetOverlay(bool enable);
634 * @copydoc Dali::Actor::IsOverlay
636 bool IsOverlay() const;
639 * Sets whether an actor transmits geometry scaling to it's children.
640 * The default value is for it not to transmit scaling.
641 * @param[in] transmitGeometryScaling True to transmit scaling.
643 void SetTransmitGeometryScaling(bool transmitGeometryScaling);
646 * Get the TransmitGeometryScaling property for this actor.
647 * @return True if geometry scaling is applied to the inherited scale.
649 bool GetTransmitGeometryScaling() const;
652 * Sets the initial volume of the actor. Used for scaling the
653 * actor appropriately as the actor is sized when transmitGeometryScaling
656 * @param[in] volume the volume of the model and it's children
658 void SetInitialVolume(const Vector3& volume);
661 * Sets the actor's color. The final color of actor depends on its color mode.
662 * This final color is applied to the drawable elements of an actor.
663 * @param [in] color The new color.
665 void SetColor(const Vector4& color);
668 * Set the red component of the color.
669 * @param [in] red The new red component.
671 void SetColorRed( float red );
674 * Set the green component of the color.
675 * @param [in] green The new green component.
677 void SetColorGreen( float green );
680 * Set the blue component of the scale factor.
681 * @param [in] blue The new blue value.
683 void SetColorBlue( float blue );
686 * Apply a relative color change to an actor.
687 * @param[in] relativeColor The color to combine with the actors existing color.
689 void ColorBy(const Vector4& relativeColor);
692 * Retrieve the actor's color.
695 const Vector4& GetCurrentColor() const;
698 * Sets the actor's color mode.
699 * Color mode specifies whether Actor uses its own color or inherits its parent color
700 * @param [in] colorMode to use.
702 void SetColorMode(ColorMode colorMode);
705 * Returns the actor's color mode.
706 * @return currently used colorMode.
708 ColorMode GetColorMode() const;
711 * @copydoc Dali::Actor::GetCurrentWorldColor()
713 const Vector4& GetCurrentWorldColor() const;
715 #ifdef DYNAMICS_SUPPORT
719 /// @copydoc Dali::Actor::DisableDynamics
720 void DisableDynamics();
722 /// @copydoc Dali::Actor::EnableDynamics(Dali::DynamicsBodyConfig)
723 DynamicsBodyPtr EnableDynamics(DynamicsBodyConfigPtr bodyConfig);
725 /// @copydoc Dali::Actor::GetDynamicsBody
726 DynamicsBodyPtr GetDynamicsBody() const;
728 /// @copydoc Dali::Actor::AddDynamicsJoint(Dali::Actor,const Vector3&)
729 DynamicsJointPtr AddDynamicsJoint( ActorPtr attachedActor, const Vector3& offset );
731 /// @copydoc Dali::Actor::AddDynamicsJoint(Dali::Actor,const Vector3&,const Vector3&)
732 DynamicsJointPtr AddDynamicsJoint( ActorPtr attachedActor, const Vector3& offsetA, const Vector3& offsetB );
734 /// @copydoc Dali::Actor::GetNumberOfJoints
735 const int GetNumberOfJoints() const;
737 /// @copydoc Dali::Actor::GetDynamicsJointByIndex
738 DynamicsJointPtr GetDynamicsJointByIndex( const int index ) const;
740 /// @copydoc Dali::Actor::GetDynamicsJoint
741 DynamicsJointPtr GetDynamicsJoint( ActorPtr attachedActor ) const;
743 /// @copydoc Dali::Actor::RemoveDynamicsJoint
744 void RemoveDynamicsJoint( DynamicsJointPtr joint );
747 * Hold a reference to a DynamicsJoint
748 * @param[in] joint The joint
750 void ReferenceJoint( DynamicsJointPtr joint );
753 * Release a reference to a DynamicsJoint
754 * @param[in] joint The joint
756 void ReleaseJoint( DynamicsJointPtr joint );
759 * Set this actor to be the root actor in the dynamics simulation
760 * All children of the actor are added/removed from the simulation.
761 * @param[in] flag When true sets this actor to be the simulation world root actor and
762 * if OnStage() all dynamics enabled child actors are added to the simulation,
763 * when false stops this actor being the simulation root and if OnStage() all
764 * dynamics enabled child actors are removed from the simulation.
766 void SetDynamicsRoot(bool flag);
770 * Check if this actor is the root actor in the dynamics simulation
771 * @return true if this is the dynamics root actor.
773 bool IsDynamicsRoot() const;
776 * Add actor to the dynamics simulation
777 * Invoked when the actor is staged, or it's parent becomes the simulation root
779 void ConnectDynamics();
782 * Remove actor from the dynamics simulation
783 * Invoked when the actor is unstaged, or it's parent stops being the the simulation root
785 void DisconnectDynamics();
788 * An actor in a DynamicsJoint relationship has been staged
789 * @param[in] actor The actor passed into AddDynamicsJoint()
791 void AttachedActorOnStage( Dali::Actor actor );
794 * An actor in a DynamicsJoint relationship has been unstaged
795 * @param[in] actor The actor passed into AddDynamicsJoint()
797 void AttachedActorOffStage( Dali::Actor actor );
799 #endif // DYNAMICS_SUPPORT
803 * Converts screen coordinates into the actor's coordinate system.
804 * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
805 * @param[out] localX On return, the X-coordinate relative to the actor.
806 * @param[out] localY On return, the Y-coordinate relative to the actor.
807 * @param[in] screenX The screen X-coordinate.
808 * @param[in] screenY The screen Y-coordinate.
809 * @return True if the conversion succeeded.
811 bool ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const;
814 * Converts screen coordinates into the actor's coordinate system.
815 * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
816 * @param[in] renderTask The render-task used to display the actor.
817 * @param[out] localX On return, the X-coordinate relative to the actor.
818 * @param[out] localY On return, the Y-coordinate relative to the actor.
819 * @param[in] screenX The screen X-coordinate.
820 * @param[in] screenY The screen Y-coordinate.
821 * @return True if the conversion succeeded.
823 bool ScreenToLocal(RenderTask& renderTask, float& localX, float& localY, float screenX, float screenY) const;
826 * Converts from the actor's coordinate system to screen coordinates.
827 * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
828 * @param[in] viewMatrix The view-matrix
829 * @param[in] projectionMatrix The projection-matrix
830 * @param[in] viewport The view-port
831 * @param[out] localX On return, the X-coordinate relative to the actor.
832 * @param[out] localY On return, the Y-coordinate relative to the actor.
833 * @param[in] screenX The screen X-coordinate.
834 * @param[in] screenY The screen Y-coordinate.
835 * @return True if the conversion succeeded.
837 bool ScreenToLocal( const Matrix& viewMatrix,
838 const Matrix& projectionMatrix,
839 const Viewport& viewport,
843 float screenY ) const;
846 * Performs a ray-sphere test with the given pick-ray and the actor's bounding sphere.
847 * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
848 * @param[in] rayOrigin The ray origin in the world's reference system.
849 * @param[in] rayDir The ray director vector in the world's reference system.
850 * @return True if the ray intersects the actor's bounding sphere.
852 bool RaySphereTest( const Vector4& rayOrigin, const Vector4& rayDir ) const;
855 * Performs a ray-actor test with the given pick-ray and the actor's geometry.
856 * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
857 * @param[in] rayOrigin The ray origin in the world's reference system.
858 * @param[in] rayDir The ray director vector in the world's reference system.
859 * @param[out] hitPointLocal The hit point in the Actor's local reference system.
860 * @param[out] distance The distance from the hit point to the camera.
861 * @return True if the ray intersects the actor's geometry.
863 bool RayActorTest( const Vector4& rayOrigin, const Vector4& rayDir, Vector4& hitPointLocal, float& distance ) const;
866 * Sets whether the actor should receive a notification when touch motion events leave
867 * the boundary of the actor.
869 * @note By default, this is set to false as most actors do not require this.
870 * @note Need to connect to the SignalTouch to actually receive this event.
872 * @param[in] required Should be set to true if a Leave event is required
874 void SetLeaveRequired(bool required);
877 * This returns whether the actor requires touch events whenever touch motion events leave
878 * the boundary of the actor.
879 * @return true if a Leave event is required, false otherwise.
881 bool GetLeaveRequired() const;
884 * @copydoc Dali::Actor::SetKeyboardFocusable()
886 void SetKeyboardFocusable( bool focusable );
889 * @copydoc Dali::Actor::IsKeyboardFocusable()
891 bool IsKeyboardFocusable() const;
894 * Query whether the application or derived actor type requires touch events.
895 * @return True if touch events are required.
897 bool GetTouchRequired() const;
900 * Query whether the application or derived actor type requires mouse wheel events.
901 * @return True if mouse wheel events are required.
903 bool GetMouseWheelEventRequired() const;
906 * Query whether the actor is actually hittable. This method checks whether the actor is
907 * sensitive, has the visibility flag set to true and is not fully transparent.
908 * @return true, if it can be hit, false otherwise.
910 bool IsHittable() const;
915 * Retrieve the gesture data associated with this actor. The first call to this method will
916 * allocate space for the ActorGestureData so this should only be called if an actor really does
918 * @return Reference to the ActorGestureData for this actor.
919 * @note Once the gesture-data is created for an actor it is likely that gestures are required
920 * throughout the actor's lifetime so it will only be deleted when the actor is destroyed.
922 ActorGestureData& GetGestureData();
925 * Queries whether the actor requires the gesture type.
926 * @param[in] type The gesture type.
928 bool IsGestureRequred( Gesture::Type type ) const;
933 * Used by the EventProcessor to emit touch event signals.
934 * @param[in] event The touch event.
935 * @return True if the event was consumed.
937 bool EmitTouchEventSignal(const TouchEvent& event);
940 * Used by the EventProcessor to emit mouse wheel event signals.
941 * @param[in] event The mouse wheel event.
942 * @return True if the event was consumed.
944 bool EmitMouseWheelEventSignal(const MouseWheelEvent& event);
947 * @copydoc Dali::Actor::TouchedSignal()
949 Dali::Actor::TouchSignalV2& TouchedSignal();
952 * @copydoc Dali::Actor::MouseWheelEventSignal()
954 Dali::Actor::MouseWheelEventSignalV2& MouseWheelEventSignal();
957 * @copydoc Dali::Actor::SetSizeSignal()
959 Dali::Actor::SetSizeSignalV2& SetSizeSignal();
962 * @copydoc Dali::Actor::OnStageSignal()
964 Dali::Actor::OnStageSignalV2& OnStageSignal();
967 * @copydoc Dali::Actor::OffStageSignal()
969 Dali::Actor::OffStageSignalV2& OffStageSignal();
972 * Connects a callback function with the object's signals.
973 * @param[in] object The object providing the signal.
974 * @param[in] tracker Used to disconnect the signal.
975 * @param[in] signalName The signal to connect to.
976 * @param[in] functor A newly allocated FunctorDelegate.
977 * @return True if the signal was connected.
978 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
980 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
983 * Performs actions as requested using the action name.
984 * @param[in] object The object on which to perform the action.
985 * @param[in] actionName The action to perform.
986 * @param[in] attributes The attributes with which to perfrom this action.
987 * @return true if the action was done.
989 static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
991 public: // For Animation
994 * For use in derived classes.
995 * This should only be called by Animation, when the actor is resized using Animation::Resize().
997 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize) {}
1010 * Protected Constructor. See Actor::New().
1011 * The second-phase construction Initialize() member should be called immediately after this.
1012 * @param[in] derivedType The derived type of actor (if any).
1014 Actor( DerivedType derivedType );
1017 * Second-phase constructor. Must be called immediately after creating a new Actor;
1019 void Initialize(void);
1022 * A reference counted object may only be deleted by calling Unreference()
1027 * Called on a child during Add() when the parent actor is connected to the Stage.
1028 * @param[in] stage The stage.
1030 void ConnectToStage(Stage& stage);
1033 * Helper for ConnectToStage, to recursively connect a tree of actors.
1034 * This is atomic i.e. not interrupted by user callbacks.
1035 * @param[in] stage The stage.
1036 * @param[out] connectionList On return, the list of connected actors which require notification.
1038 void RecursiveConnectToStage( Stage& stage, ActorContainer& connectionList );
1041 * Connect the Node associated with this Actor to the scene-graph.
1043 void ConnectToSceneGraph();
1046 * Helper for ConnectToStage, to notify a connected actor through the public API.
1048 void NotifyStageConnection();
1051 * Called on a child during Remove() when the actor was previously on the Stage.
1053 void DisconnectFromStage();
1056 * Helper for DisconnectFromStage, to recursively disconnect a tree of actors.
1057 * This is atomic i.e. not interrupted by user callbacks.
1058 * @param[out] disconnectionList On return, the list of disconnected actors which require notification.
1060 void RecursiveDisconnectFromStage( ActorContainer& disconnectionList );
1063 * Disconnect the Node associated with this Actor from the scene-graph.
1065 void DisconnectFromSceneGraph();
1068 * Helper for DisconnectFromStage, to notify a disconnected actor through the public API.
1070 void NotifyStageDisconnection();
1073 * When the Actor is OnStage, checks whether the corresponding Node is connected to the scene graph.
1074 * @return True if the Actor is OnStage & has a Node connected to the scene graph.
1076 bool IsNodeConnected() const;
1078 public: // Default property extensions from ProxyObject
1081 * @copydoc Dali::Internal::ProxyObject::IsSceneObjectRemovable()
1083 virtual bool IsSceneObjectRemovable() const;
1086 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyCount()
1088 virtual unsigned int GetDefaultPropertyCount() const;
1091 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndices()
1093 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
1096 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyName()
1098 virtual const std::string& GetDefaultPropertyName(Property::Index index) const;
1101 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndex()
1103 virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
1106 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyWritable()
1108 virtual bool IsDefaultPropertyWritable(Property::Index index) const;
1111 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAnimatable()
1113 virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
1116 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAConstraintInput()
1118 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
1121 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyType()
1123 virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
1126 * @copydoc Dali::Internal::ProxyObject::SetDefaultProperty()
1128 virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
1131 * @copydoc Dali::Internal::ProxyObject::SetCustomProperty()
1133 virtual void SetCustomProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value );
1136 * @copydoc Dali::Internal::ProxyObject::GetDefaultProperty()
1138 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
1141 * @copydoc Dali::Internal::ProxyObject::InstallSceneObjectProperty()
1143 virtual void InstallSceneObjectProperty( SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index );
1146 * @copydoc Dali::Internal::ProxyObject::GetSceneObject()
1148 virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
1151 * @copydoc Dali::Internal::ProxyObject::GetSceneObjectAnimatableProperty()
1153 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
1156 * @copydoc Dali::Internal::ProxyObject::GetSceneObjectInputProperty()
1158 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
1161 * @copydoc Dali::Internal::ProxyObject::GetPropertyComponentIndex()
1163 virtual int GetPropertyComponentIndex( Property::Index index ) const;
1171 Actor(const Actor&);
1174 Actor& operator=(const Actor& rhs);
1177 * Set the actors parent.
1178 * @param[in] parent The new parent.
1180 void SetParent(Actor* parent);
1183 * Helper to create a Node for this Actor.
1184 * To be overriden in derived classes.
1185 * @return A newly allocated node.
1187 virtual SceneGraph::Node* CreateNode() const;
1190 * For use in derived classes, called after Initialize()
1192 virtual void OnInitialize() {}
1195 * For use in internal derived classes.
1196 * This is called during ConnectToStage(), after the actor has finished adding its node to the scene-graph.
1197 * The derived class must not modify the actor hierachy (Add/Remove children) during this callback.
1199 virtual void OnStageConnectionInternal() {}
1202 * For use in internal derived classes.
1203 * This is called during DisconnectFromStage(), before the actor removes its node from the scene-graph.
1204 * The derived class must not modify the actor hierachy (Add/Remove children) during this callback.
1206 virtual void OnStageDisconnectionInternal() {}
1209 * For use in external (CustomActor) derived classes.
1210 * This is called after the atomic ConnectToStage() traversal has been completed.
1212 virtual void OnStageConnectionExternal() {}
1215 * For use in external (CustomActor) derived classes.
1216 * This is called after the atomic DisconnectFromStage() traversal has been completed.
1218 virtual void OnStageDisconnectionExternal() {}
1221 * For use in derived classes; this is called after Add() has added a child.
1222 * @param[in] child The child that was added.
1224 virtual void OnChildAdd( Actor& child ) {}
1227 * For use in derived classes; this is called after Remove() has removed a child.
1228 * @param[in] child The child that was removed.
1230 virtual void OnChildRemove( Actor& child ) {}
1233 * For use in derived classes.
1234 * This is called after SizeSet() has been called.
1236 virtual void OnSizeSet(const Vector3& targetSize) {}
1239 * For use in derived classes.
1240 * This is called after a non animatable custom property is set.
1241 * @param [in] index The index of the property.
1242 * @param [in] propertyValue The value of the property.
1244 virtual void OnPropertySet( Property::Index index, Property::Value propertyValue ) {}
1247 * For use in derived classes.
1248 * This is only called if mTouchRequired is true, and the touch-signal was not consumed.
1249 * @param[in] event The touch event.
1250 * @return True if the event should be consumed.
1252 virtual bool OnTouchEvent(const TouchEvent& event) { return false; }
1255 * For use in derived classes.
1256 * This is only called if the mouse wheel signal was not consumed.
1257 * @param[in] event The mouse event.
1258 * @return True if the event should be consumed.
1260 virtual bool OnMouseWheelEvent(const MouseWheelEvent& event) { return false; }
1263 * For use in derived class
1264 * If an alias for a child exists, return the child otherwise return an empty handle.
1265 * For example 'previous' could return the last selected child.
1266 * @pre The Actor has been initialized.
1267 * @param[in] actorAlias the name of the actor to find
1268 * @return A handle to the actor if found, or an empty handle if not.
1270 virtual Dali::Actor GetChildByAlias(const std::string& actorAlias) { return Dali::Actor(); }
1273 * Support function for FindChildByAlias
1274 * @pre The Actor has been initialized.
1275 * @param[in] actorAlias the name of the aliased actor to find
1276 * @return A handle to the actor if found, or an empty handle if not.
1278 Dali::Actor DoGetChildByAlias(const std::string& actorAlias);
1282 StagePtr mStage; ///< Used to send messages to Node; valid until Core destruction
1283 Actor* mParent; ///< Each actor (except the root) can have one parent
1284 ActorContainer* mChildren; ///< Container of referenced actors
1285 const SceneGraph::Node* mNode; ///< Not owned
1286 Vector3* mParentOrigin; // NULL means ParentOrigin::DEFAULT. ParentOrigin is non-animatable
1287 Vector3* mAnchorPoint; // NULL means AnchorPoint::DEFAULT. AnchorPoint is non-animatable
1289 #ifdef DYNAMICS_SUPPORT
1290 DynamicsData* mDynamicsData; ///< optional physics data
1293 ActorGestureData* mGestureData; /// Optional Gesture data. Only created when actor requires gestures
1295 ActorAttachmentPtr mAttachment; ///< Optional referenced attachment
1298 Dali::Actor::TouchSignalV2 mTouchedSignalV2;
1299 Dali::Actor::MouseWheelEventSignalV2 mMouseWheelEventSignalV2;
1300 Dali::Actor::SetSizeSignalV2 mSetSizeSignalV2;
1301 Dali::Actor::OnStageSignalV2 mOnStageSignalV2;
1302 Dali::Actor::OffStageSignalV2 mOffStageSignalV2;
1304 std::string mName; ///< Name of the actor
1305 unsigned int mId; ///< A unique ID to identify the actor starting from 1, and 0 is reserved
1307 const bool mIsRoot : 1; ///< Flag to identify the root actor
1308 const bool mIsRenderable : 1; ///< Flag to identify that this is a renderable actor
1309 const bool mIsLayer : 1; ///< Flag to identify that this is a layer
1310 bool mIsOnStage : 1; ///< Flag to identify whether the actor is on-stage
1311 bool mIsDynamicsRoot : 1; ///< Flag to identify if this is the dynamics world root
1312 bool mSensitive : 1; ///< Whether the actor emits touch event signals
1313 bool mLeaveRequired : 1; ///< Whether a touch event signal is emitted when the a touch leaves the actor's bounds
1314 bool mKeyboardFocusable : 1; ///< Whether the actor should be focusable by keyboard navigation
1315 bool mDerivedRequiresTouch : 1; ///< Whether the derived actor type requires touch event signals
1316 bool mDerivedRequiresMouseWheelEvent : 1; ///< Whether the derived actor type requires mouse wheel event signals
1317 bool mOnStageSignalled : 1; ///< Set to true before OnStageConnection signal is emitted, and false before OnStageDisconnection
1318 bool mInheritRotation : 1; ///< Cached: Whether the parent's rotation should be inherited.
1319 bool mInheritScale : 1; ///< Cached: Whether the parent's scale should be inherited.
1320 DrawMode::Type mDrawMode : 2; ///< Cached: How the actor and its children should be drawn
1321 PositionInheritanceMode mPositionInheritanceMode : 2; ///< Cached: Determines how position is inherited
1322 ColorMode mColorMode : 2; ///< Cached: Determines whether mWorldColor is inherited
1324 // Default properties
1325 typedef std::map<std::string, Property::Index> DefaultPropertyLookup;
1329 static ActorContainer mNullChildren; ///< Empty container (shared by all actors, returned by GetChildren() const)
1330 static unsigned int mActorCounter; ///< A counter to track the actor instance creation
1332 // Default properties
1333 static DefaultPropertyLookup* mDefaultPropertyLookup;
1338 * @brief Structure for setting up default properties and their details.
1340 struct PropertyDetails
1342 std::string name; ///< The name of the property.
1343 Property::Type type; ///< The property type.
1344 bool writable:1; ///< Whether the property is writable
1345 bool animatable:1; ///< Whether the property is animatable.
1346 bool constraintInput:1; ///< Whether the property can be used as an input to a constraint.
1349 } // namespace Internal
1351 // Helpers for public-api forwarding methods
1353 inline Internal::Actor& GetImplementation(Dali::Actor& actor)
1355 DALI_ASSERT_ALWAYS(actor && "Actor handle is empty");
1357 BaseObject& handle = actor.GetBaseObject();
1359 return static_cast<Internal::Actor&>(handle);
1362 inline const Internal::Actor& GetImplementation(const Dali::Actor& actor)
1364 DALI_ASSERT_ALWAYS(actor && "Actor handle is empty");
1366 const BaseObject& handle = actor.GetBaseObject();
1368 return static_cast<const Internal::Actor&>(handle);
1373 #endif // __DALI_INTERNAL_ACTOR_H__