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 GestureDetector;
59 typedef IntrusivePtr<Actor> ActorPtr;
60 typedef IntrusivePtr<ShaderEffect> ShaderEffectPtr;
61 typedef Dali::ActorContainer ActorContainer; // Store handles to return via public-api
62 typedef ActorContainer::iterator ActorIter;
63 typedef ActorContainer::const_iterator ActorConstIter;
66 * Actor is the primary object which Dali applications interact with.
67 * UI controls can be built by combining multiple actors.
68 * Multi-Touch events are received through signals emitted by the actor tree.
70 * An Actor is a proxy for a Node in the scene graph.
71 * When an Actor is added to the Stage, it creates a node and attaches it to the scene graph.
72 * The scene-graph can be updated in a separate thread, so the attachment is done using an asynchronous message.
73 * When a tree of Actors is detached from the Stage, a message is sent to destroy the associated nodes.
75 class Actor : public ProxyObject
81 * @return A smart-pointer to the newly allocated Actor.
83 static ActorPtr New();
86 * Retrieve the name of the actor.
89 const std::string& GetName() const;
92 * Set the name of the actor.
93 * @param[in] name The new name.
95 void SetName(const std::string& name);
98 * @copydoc Dali::Actor::GetId
100 unsigned int GetId() const;
105 * Attach an object to an actor.
106 * @pre The actor does not already have an attachment.
107 * @param[in] attachment The object to attach.
109 void Attach(ActorAttachment& attachment);
112 * Retreive the object attached to an actor.
113 * @return The attachment.
115 ActorAttachmentPtr GetAttachment();
120 * Query whether an actor is the root actor, which is owned by the Stage.
121 * @return True if the actor is a root actor.
129 * Query whether the actor is connected to the Stage.
131 bool OnStage() const;
134 * Query whether the actor is a RenderableActor derived type.
135 * @return True if the actor is renderable.
137 bool IsRenderable() const
139 // inlined as this is called a lot in hit testing
140 return mIsRenderable;
144 * Query whether the actor is of class Dali::Layer
145 * @return True if the actor is a layer.
149 // inlined as this is called a lot in hit testing
154 * Gets the layer in which the actor is present
155 * @return The layer, which will be uninitialized if the actor is off-stage.
157 Dali::Layer GetLayer();
160 * Adds a child Actor to this Actor.
161 * @pre The child actor is not the same as the parent actor.
162 * @pre The child actor does not already have a parent.
163 * @param [in] child The child.
164 * @post The child will be referenced by its parent.
166 void Add(Actor& child);
169 * Removes a child Actor from this Actor.
170 * @param [in] child The child.
171 * @post The child will be unreferenced.
173 void Remove(Actor& child);
176 * @copydoc Dali::Actor::Unparent
181 * Retrieve the number of children held by the actor.
182 * @return The number of children
184 unsigned int GetChildCount() const;
187 * @copydoc Dali::Actor::GetChildAt
189 Dali::Actor GetChildAt(unsigned int index) const;
192 * Retrieve the Actor's children.
193 * @return A copy of the container of children.
195 ActorContainer GetChildren();
198 * Retrieve the Actor's children.
199 * @return A const reference to the container of children.
201 const ActorContainer& GetChildren() const;
204 * Retrieve a reference to Actor's children.
205 * @note Not for public use.
206 * @return A reference to the container of children.
208 ActorContainer& GetChildrenInternal()
214 * @copydoc Dali::Actor::FindChildByName
216 ActorPtr FindChildByName(const std::string& actorName);
219 * @copydoc Dali::Actor::FindChildByAlias
221 Dali::Actor FindChildByAlias(const std::string& actorAlias);
224 * @copydoc Dali::Actor::FindChildById
226 ActorPtr FindChildById(const unsigned int id);
229 * Retrieve the parent of an Actor.
230 * @return The parent actor, or NULL if the Actor does not have a parent.
232 Actor* GetParent() const
238 * Sets the size of an actor.
239 * ActorAttachments attached to the actor, can be scaled to fit within this area.
240 * This does not interfere with the actors scale factor.
241 * @param [in] width The new width.
242 * @param [in] height The new height.
244 void SetSize(float width, float height);
247 * Sets the size of an actor.
248 * ActorAttachments attached to the actor, can be scaled to fit within this area.
249 * This does not interfere with the actors scale factor.
250 * @param [in] width The size of the actor along the x-axis.
251 * @param [in] height The size of the actor along the y-axis.
252 * @param [in] depth The size of the actor along the z-axis.
254 void SetSize(float width, float height, float depth);
257 * Sets the size of an actor.
258 * ActorAttachments attached to the actor, can be scaled to fit within this area.
259 * This does not interfere with the actors scale factor.
260 * @param [in] size The new size.
262 void SetSize(const Vector2& size);
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 Vector3& size);
273 * Set the width component of the Actor's size.
274 * @param [in] width The new width component.
276 void SetWidth( float width );
279 * Set the height component of the Actor's size.
280 * @param [in] height The new height component.
282 void SetHeight( float height );
285 * Set the depth component of the Actor's size.
286 * @param [in] depth The new depth component.
288 void SetDepth( float depth );
291 * Retrieve the Actor's size.
292 * @return The Actor's size.
294 const Vector3& GetCurrentSize() const;
297 * Set the origin of an actor, within its parent's area.
298 * This is expressed in 2D unit coordinates, such that (0.0, 0.0, 0.5) is the top-left corner of the parent,
299 * and (1.0, 1.0, 0.5) is the bottom-right corner.
300 * The default parent-origin is top-left (0.0, 0.0, 0.5).
301 * An actor position is the distance between this origin, and the actors anchor-point.
302 * @param [in] origin The new parent-origin.
304 void SetParentOrigin(const Vector3& origin);
307 * Set the x component of the parent-origin
308 * @param [in] x The new x value.
310 void SetParentOriginX( float x );
313 * Set the y component of the parent-origin
314 * @param [in] y The new y value.
316 void SetParentOriginY( float y );
319 * Set the z component of the parent-origin
320 * @param [in] z The new z value.
322 void SetParentOriginZ( float z );
325 * Retrieve the parent-origin of an actor.
326 * @return The parent-origin.
328 const Vector3& GetCurrentParentOrigin() const;
331 * Set the anchor-point of an actor. This is expressed in 2D unit coordinates, such that
332 * (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.
333 * The default anchor point is top-left (0.0, 0.0, 0.5).
334 * An actor position is the distance between its parent-origin, and this anchor-point.
335 * An actor's rotation is centered around its anchor-point.
336 * @param [in] anchorPoint The new anchor-point.
338 void SetAnchorPoint(const Vector3& anchorPoint);
341 * Set the x component of the anchor-point.
342 * @param [in] x The new x value.
344 void SetAnchorPointX( float x );
347 * Set the y component of the anchor-point.
348 * @param [in] y The new y value.
350 void SetAnchorPointY( float y );
353 * Set the z component of the anchor-point.
354 * @param [in] z The new z value.
356 void SetAnchorPointZ( float z );
359 * Retrieve the anchor-point of an actor.
360 * @return The anchor-point.
362 const Vector3& GetCurrentAnchorPoint() const;
365 * Sets the position of the Actor.
366 * The coordinates are relative to the Actor's parent.
367 * The Actor's z position will be set to 0.0f.
368 * @param [in] x The new x position
369 * @param [in] y The new y position
371 void SetPosition(float x, float y);
374 * Sets the position of the Actor.
375 * The coordinates are relative to the Actor's parent.
376 * @param [in] x The new x position
377 * @param [in] y The new y position
378 * @param [in] z The new z position
380 void SetPosition(float x, float y, float z);
383 * Sets the position of the Actor.
384 * The coordinates are relative to the Actor's parent.
385 * @param [in] position The new position.
387 void SetPosition(const Vector3& position);
390 * Set the position of an actor along the X-axis.
391 * @param [in] x The new x position
396 * Set the position of an actor along the Y-axis.
397 * @param [in] y The new y position.
402 * Set the position of an actor along the Z-axis.
403 * @param [in] z The new z position
408 * Move an actor relative to its existing position.
409 * @param[in] distance The actor will move by this distance.
411 void MoveBy(const Vector3& distance);
414 * Retrieve the position of the Actor.
415 * The coordinates are relative to the Actor's parent.
416 * @return the Actor's position.
418 const Vector3& GetCurrentPosition() const;
421 * @copydoc Dali::Actor::GetCurrentWorldPosition()
423 const Vector3& GetCurrentWorldPosition() const;
426 * @copydoc Dali::Actor::SetPositionInheritanceMode()
428 void SetPositionInheritanceMode( PositionInheritanceMode mode );
431 * @copydoc Dali::Actor::GetPositionInheritanceMode()
433 PositionInheritanceMode GetPositionInheritanceMode() const;
436 * Sets the rotation of the Actor.
437 * @param [in] angleRadians The new rotation angle in radians.
438 * @param [in] axis The new axis of rotation.
440 void SetRotation(const Radian& angleRadians, const Vector3& axis);
443 * Sets the rotation of the Actor.
444 * @param [in] rotation The new rotation.
446 void SetRotation(const Quaternion& rotation);
449 * Rotate an actor around its existing rotation axis.
450 * @param[in] angleRadians The angle to the rotation to combine with the existing rotation.
451 * @param[in] axis The axis of the rotation to combine with the existing rotation.
453 void RotateBy(const Radian& angleRadians, const Vector3& axis);
456 * Apply a relative rotation to an actor.
457 * @param[in] relativeRotation The rotation to combine with the actors existing rotation.
459 void RotateBy(const Quaternion& relativeRotation);
462 * Retreive the Actor's rotation.
463 * @return the rotation.
465 const Quaternion& GetCurrentRotation() const;
468 * Set whether a child actor inherits it's parent's orientation. Default is to inherit.
469 * Switching this off means that using SetRotation() sets the actor's world orientation.
470 * @param[in] inherit - true if the actor should inherit orientation, false otherwise.
472 void SetInheritRotation(bool inherit);
475 * Returns whether the actor inherit's it's parent's orientation.
476 * @return true if the actor inherit's it's parent orientation, false if it uses world orientation.
478 bool IsRotationInherited() const;
481 * @copydoc Dali::Actor::GetCurrentWorldRotation()
483 const Quaternion& GetCurrentWorldRotation() const;
486 * Sets a scale factor applied to an actor.
487 * @param [in] scale The scale factor applied on all axes.
489 void SetScale(float scale);
492 * Sets a scale factor applied to an actor.
493 * @param [in] scaleX The scale factor applied along the x-axis.
494 * @param [in] scaleY The scale factor applied along the y-axis.
495 * @param [in] scaleZ The scale factor applied along the z-axis.
497 void SetScale(float scaleX, float scaleY, float scaleZ);
500 * Sets a scale factor applied to an actor.
501 * @param [in] scale A vector representing the scale factor for each axis.
503 void SetScale(const Vector3& scale);
506 * Set the x component of the scale factor.
507 * @param [in] x The new x value.
509 void SetScaleX( float x );
512 * Set the y component of the scale factor.
513 * @param [in] y The new y value.
515 void SetScaleY( float y );
518 * Set the z component of the scale factor.
519 * @param [in] z The new z value.
521 void SetScaleZ( float z );
524 * Apply a relative scale to an actor.
525 * @param[in] relativeScale The scale to combine with the actors existing scale.
527 void ScaleBy(const Vector3& relativeScale);
530 * Retrieve the scale factor applied to an actor.
531 * @return A vector representing the scale factor for each axis.
533 const Vector3& GetCurrentScale() const;
536 * @copydoc Dali::Actor::GetCurrentWorldScale()
538 const Vector3& GetCurrentWorldScale() const;
541 * @copydoc Dali::Actor::SetInheritScale()
543 void SetInheritScale( bool inherit );
546 * @copydoc Dali::Actor::IsScaleInherited()
548 bool IsScaleInherited() const;
551 * @copydoc Dali::Actor::GetCurrentWorldMatrix()
553 Matrix GetCurrentWorldMatrix() const;
558 * Sets the visibility flag of an actor.
559 * @param [in] visible The new visibility flag.
561 void SetVisible(bool visible);
564 * Retrieve the visibility flag of an actor.
565 * @return The visibility flag.
567 bool IsVisible() const;
570 * Sets the opacity of an actor.
571 * @param [in] opacity The new opacity.
573 void SetOpacity(float opacity);
576 * Apply a relative opacity change to an actor.
577 * @param[in] relativeOpacity The opacity to combine with the actors existing opacity.
579 void OpacityBy(float relativeOpacity);
582 * Retrieve the actor's opacity.
583 * @return The actor's opacity.
585 float GetCurrentOpacity() const;
588 * Sets whether an actor should emit touch signals; see SignalTouch().
589 * An actor is sensitive by default, which means that as soon as an application connects to the SignalTouch(),
590 * the touch event signal will be emitted.
592 * If the application wishes to temporarily disable the touch event signal emission, then they can do so by calling:
594 * actor.SetSensitive(false);
597 * Then, to re-enable the touch event signal emission, the application should call:
599 * actor.SetSensitive(true);
602 * @see SignalTouch().
603 * @note If an actor's sensitivity is set to false, then it's children will not emit a touch event signal either.
604 * @param[in] sensitive true to enable emission of the touch event signals, false otherwise.
606 void SetSensitive(bool sensitive)
608 mSensitive = sensitive;
612 * Query whether an actor emits touch event signals.
613 * @see SetSensitive(bool)
614 * @return true, if emission of touch event signals is enabled, false otherwise.
616 bool IsSensitive() const
622 * Set whether the actor inherits a shader effect from its parent.
623 * The inherited effect can be overridden using SetShaderEffect()
624 * @param [in] inherit True if the parent effect is inherited.
626 void SetInheritShaderEffect(bool inherit);
629 * Query whether the actor inherits a shader effect from its parent.
630 * @return True if the parent effect is inherited.
632 bool GetInheritShaderEffect() const;
635 * Sets the shader effect for the Actor.
636 * Shader effects provide special effects like rippling and bending.
637 * Setting a shader effect removes any shader effect previously set by SetShaderEffect.
638 * @param [in] effect The shader effect.
640 void SetShaderEffect(ShaderEffect& effect);
643 * Retrieve the shader effect for the Actor.
644 * @return The shader effect
646 ShaderEffectPtr GetShaderEffect() const;
649 * Removes the current shader effect.
651 void RemoveShaderEffect();
654 * @copydoc Dali::Actor::SetDrawMode
656 void SetDrawMode( DrawMode::Type drawMode );
659 * @copydoc Dali::Actor::GetDrawMode
661 DrawMode::Type GetDrawMode() const;
664 * @copydoc Dali::Actor::SetOverlay
666 void SetOverlay(bool enable);
669 * @copydoc Dali::Actor::IsOverlay
671 bool IsOverlay() const;
674 * Sets whether an actor transmits geometry scaling to it's children.
675 * The default value is for it not to transmit scaling.
676 * @param[in] transmitGeometryScaling True to transmit scaling.
678 void SetTransmitGeometryScaling(bool transmitGeometryScaling);
681 * Get the TransmitGeometryScaling property for this actor.
682 * @return True if geometry scaling is applied to the inherited scale.
684 bool GetTransmitGeometryScaling() const;
687 * Sets the initial volume of the actor. Used for scaling the
688 * actor appropriately as the actor is sized when transmitGeometryScaling
691 * @param[in] volume the volume of the model and it's children
693 void SetInitialVolume(const Vector3& volume);
696 * Sets the actor's color. The final color of actor depends on its color mode.
697 * This final color is applied to the drawable elements of an actor.
698 * @param [in] color The new color.
700 void SetColor(const Vector4& color);
703 * Set the red component of the color.
704 * @param [in] red The new red component.
706 void SetColorRed( float red );
709 * Set the green component of the color.
710 * @param [in] green The new green component.
712 void SetColorGreen( float green );
715 * Set the blue component of the scale factor.
716 * @param [in] blue The new blue value.
718 void SetColorBlue( float blue );
721 * Apply a relative color change to an actor.
722 * @param[in] relativeColor The color to combine with the actors existing color.
724 void ColorBy(const Vector4& relativeColor);
727 * Retrieve the actor's color.
730 const Vector4& GetCurrentColor() const;
733 * Sets the actor's color mode.
734 * Color mode specifies whether Actor uses its own color or inherits its parent color
735 * @param [in] colorMode to use.
737 void SetColorMode(ColorMode colorMode);
740 * Returns the actor's color mode.
741 * @return currently used colorMode.
743 ColorMode GetColorMode() const;
746 * @copydoc Dali::Actor::GetCurrentWorldColor()
748 const Vector4& GetCurrentWorldColor() const;
750 #ifdef DYNAMICS_SUPPORT
754 /// @copydoc Dali::Actor::DisableDynamics
755 void DisableDynamics();
757 /// @copydoc Dali::Actor::EnableDynamics(Dali::DynamicsBodyConfig)
758 DynamicsBodyPtr EnableDynamics(DynamicsBodyConfigPtr bodyConfig);
760 /// @copydoc Dali::Actor::GetDynamicsBody
761 DynamicsBodyPtr GetDynamicsBody() const;
763 /// @copydoc Dali::Actor::AddDynamicsJoint(Dali::Actor,const Vector3&)
764 DynamicsJointPtr AddDynamicsJoint( ActorPtr attachedActor, const Vector3& offset );
766 /// @copydoc Dali::Actor::AddDynamicsJoint(Dali::Actor,const Vector3&,const Vector3&)
767 DynamicsJointPtr AddDynamicsJoint( ActorPtr attachedActor, const Vector3& offsetA, const Vector3& offsetB );
769 /// @copydoc Dali::Actor::GetNumberOfJoints
770 const int GetNumberOfJoints() const;
772 /// @copydoc Dali::Actor::GetDynamicsJointByIndex
773 DynamicsJointPtr GetDynamicsJointByIndex( const int index ) const;
775 /// @copydoc Dali::Actor::GetDynamicsJoint
776 DynamicsJointPtr GetDynamicsJoint( ActorPtr attachedActor ) const;
778 /// @copydoc Dali::Actor::RemoveDynamicsJoint
779 void RemoveDynamicsJoint( DynamicsJointPtr joint );
782 * Hold a reference to a DynamicsJoint
783 * @param[in] joint The joint
785 void ReferenceJoint( DynamicsJointPtr joint );
788 * Release a reference to a DynamicsJoint
789 * @param[in] joint The joint
791 void ReleaseJoint( DynamicsJointPtr joint );
794 * Set this actor to be the root actor in the dynamics simulation
795 * All children of the actor are added/removed from the simulation.
796 * @param[in] flag When true sets this actor to be the simulation world root actor and
797 * if OnStage() all dynamics enabled child actors are added to the simulation,
798 * when false stops this actor being the simulation root and if OnStage() all
799 * dynamics enabled child actors are removed from the simulation.
801 void SetDynamicsRoot(bool flag);
805 * Check if this actor is the root actor in the dynamics simulation
806 * @return true if this is the dynamics root actor.
808 bool IsDynamicsRoot() const;
811 * Add actor to the dynamics simulation
812 * Invoked when the actor is staged, or it's parent becomes the simulation root
814 void ConnectDynamics();
817 * Remove actor from the dynamics simulation
818 * Invoked when the actor is unstaged, or it's parent stops being the the simulation root
820 void DisconnectDynamics();
823 * An actor in a DynamicsJoint relationship has been staged
824 * @param[in] actor The actor passed into AddDynamicsJoint()
826 void AttachedActorOnStage( Dali::Actor actor );
829 * An actor in a DynamicsJoint relationship has been unstaged
830 * @param[in] actor The actor passed into AddDynamicsJoint()
832 void AttachedActorOffStage( Dali::Actor actor );
834 #endif // DYNAMICS_SUPPORT
838 * Converts screen coordinates into the actor's coordinate system.
839 * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
840 * @param[out] localX On return, the X-coordinate relative to the actor.
841 * @param[out] localY On return, the Y-coordinate relative to the actor.
842 * @param[in] screenX The screen X-coordinate.
843 * @param[in] screenY The screen Y-coordinate.
844 * @return True if the conversion succeeded.
846 bool ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const;
849 * Converts screen coordinates into the actor's coordinate system.
850 * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
851 * @param[in] renderTask The render-task used to display the actor.
852 * @param[out] localX On return, the X-coordinate relative to the actor.
853 * @param[out] localY On return, the Y-coordinate relative to the actor.
854 * @param[in] screenX The screen X-coordinate.
855 * @param[in] screenY The screen Y-coordinate.
856 * @return True if the conversion succeeded.
858 bool ScreenToLocal(RenderTask& renderTask, float& localX, float& localY, float screenX, float screenY) const;
861 * Converts from the actor's coordinate system to screen coordinates.
862 * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
863 * @param[in] viewMatrix The view-matrix
864 * @param[in] projectionMatrix The projection-matrix
865 * @param[in] viewport The view-port
866 * @param[out] localX On return, the X-coordinate relative to the actor.
867 * @param[out] localY On return, the Y-coordinate relative to the actor.
868 * @param[in] screenX The screen X-coordinate.
869 * @param[in] screenY The screen Y-coordinate.
870 * @return True if the conversion succeeded.
872 bool ScreenToLocal( const Matrix& viewMatrix,
873 const Matrix& projectionMatrix,
874 const Viewport& viewport,
878 float screenY ) const;
881 * Performs a ray-sphere test with the given pick-ray and the actor's bounding sphere.
882 * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
883 * @param[in] rayOrigin The ray origin in the world's reference system.
884 * @param[in] rayDir The ray director vector in the world's reference system.
885 * @return True if the ray intersects the actor's bounding sphere.
887 bool RaySphereTest( const Vector4& rayOrigin, const Vector4& rayDir ) const;
890 * Performs a ray-actor test with the given pick-ray and the actor's geometry.
891 * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
892 * @param[in] rayOrigin The ray origin in the world's reference system.
893 * @param[in] rayDir The ray director vector in the world's reference system.
894 * @param[out] hitPointLocal The hit point in the Actor's local reference system.
895 * @param[out] distance The distance from the hit point to the camera.
896 * @return True if the ray intersects the actor's geometry.
898 bool RayActorTest( const Vector4& rayOrigin, const Vector4& rayDir, Vector4& hitPointLocal, float& distance ) const;
901 * Sets whether the actor should receive a notification when touch motion events leave
902 * the boundary of the actor.
904 * @note By default, this is set to false as most actors do not require this.
905 * @note Need to connect to the SignalTouch to actually receive this event.
907 * @param[in] required Should be set to true if a Leave event is required
909 void SetLeaveRequired(bool required);
912 * This returns whether the actor requires touch events whenever touch motion events leave
913 * the boundary of the actor.
914 * @return true if a Leave event is required, false otherwise.
916 bool GetLeaveRequired() const;
919 * @copydoc Dali::Actor::SetKeyboardFocusable()
921 void SetKeyboardFocusable( bool focusable );
924 * @copydoc Dali::Actor::IsKeyboardFocusable()
926 bool IsKeyboardFocusable() const;
929 * Query whether the application or derived actor type requires touch events.
930 * @return True if touch events are required.
932 bool GetTouchRequired() const;
935 * Query whether the application or derived actor type requires mouse wheel events.
936 * @return True if mouse wheel events are required.
938 bool GetMouseWheelEventRequired() const;
941 * Query whether the actor is actually hittable. This method checks whether the actor is
942 * sensitive, has the visibility flag set to true and is not fully transparent.
943 * @return true, if it can be hit, false otherwise.
945 bool IsHittable() const;
950 * Adds a gesture detector to the actor so that the actor is aware that it requires this type of
952 * @param[in] detector The detector being added.
953 * @note A raw pointer to the detector is stored, so the detector MUST remove itself when it is
954 * destroyed using RemoveGestureDetector()
956 void AddGestureDetector( GestureDetector& detector );
959 * Removes a previously added gesture detector from the actor. If no more gesture detectors of
960 * this type are registered with this actor then the actor will no longer be hit-tested for that
962 * @param[in] detector The detector to remove.
964 void RemoveGestureDetector( GestureDetector& detector );
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 mouse wheel event signals.
983 * @param[in] event The mouse wheel event.
984 * @return True if the event was consumed.
986 bool EmitMouseWheelEventSignal(const MouseWheelEvent& event);
989 * @copydoc Dali::Actor::TouchedSignal()
991 Dali::Actor::TouchSignalV2& TouchedSignal();
994 * @copydoc Dali::Actor::MouseWheelEventSignal()
996 Dali::Actor::MouseWheelEventSignalV2& MouseWheelEventSignal();
999 * @copydoc Dali::Actor::SetSizeSignal()
1001 Dali::Actor::SetSizeSignalV2& SetSizeSignal();
1004 * @copydoc Dali::Actor::OnStageSignal()
1006 Dali::Actor::OnStageSignalV2& OnStageSignal();
1009 * @copydoc Dali::Actor::OffStageSignal()
1011 Dali::Actor::OffStageSignalV2& OffStageSignal();
1014 * Connects a callback function with the object's signals.
1015 * @param[in] object The object providing the signal.
1016 * @param[in] tracker Used to disconnect the signal.
1017 * @param[in] signalName The signal to connect to.
1018 * @param[in] functor A newly allocated FunctorDelegate.
1019 * @return True if the signal was connected.
1020 * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
1022 static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
1025 * Performs actions as requested using the action name.
1026 * @param[in] object The object on which to perform the action.
1027 * @param[in] actionName The action to perform.
1028 * @param[in] attributes The attributes with which to perfrom this action.
1029 * @return true if the action was done.
1031 static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
1033 public: // For Animation
1036 * For use in derived classes.
1037 * This should only be called by Animation, when the actor is resized using Animation::Resize().
1039 virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize) {}
1052 * Protected Constructor. See Actor::New().
1053 * The second-phase construction Initialize() member should be called immediately after this.
1054 * @param[in] derivedType The derived type of actor (if any).
1056 Actor( DerivedType derivedType );
1059 * Second-phase constructor. Must be called immediately after creating a new Actor;
1061 void Initialize(void);
1064 * A reference counted object may only be deleted by calling Unreference()
1069 * Called on a child during Add() when the parent actor is connected to the Stage.
1070 * @param[in] stage The stage.
1072 void ConnectToStage(Stage& stage);
1075 * Helper for ConnectToStage, to recursively connect a tree of actors.
1076 * This is atomic i.e. not interrupted by user callbacks.
1077 * @param[in] stage The stage.
1078 * @param[out] connectionList On return, the list of connected actors which require notification.
1080 void RecursiveConnectToStage( Stage& stage, ActorContainer& connectionList );
1083 * Connect the Node associated with this Actor to the scene-graph.
1085 void ConnectToSceneGraph();
1088 * Helper for ConnectToStage, to notify a connected actor through the public API.
1090 void NotifyStageConnection();
1093 * Called on a child during Remove() when the actor was previously on the Stage.
1095 void DisconnectFromStage();
1098 * Helper for DisconnectFromStage, to recursively disconnect a tree of actors.
1099 * This is atomic i.e. not interrupted by user callbacks.
1100 * @param[out] disconnectionList On return, the list of disconnected actors which require notification.
1102 void RecursiveDisconnectFromStage( ActorContainer& disconnectionList );
1105 * Disconnect the Node associated with this Actor from the scene-graph.
1107 void DisconnectFromSceneGraph();
1110 * Helper for DisconnectFromStage, to notify a disconnected actor through the public API.
1112 void NotifyStageDisconnection();
1115 * When the Actor is OnStage, checks whether the corresponding Node is connected to the scene graph.
1116 * @return True if the Actor is OnStage & has a Node connected to the scene graph.
1118 bool IsNodeConnected() const;
1120 public: // Default property extensions from ProxyObject
1123 * @copydoc Dali::Internal::ProxyObject::IsSceneObjectRemovable()
1125 virtual bool IsSceneObjectRemovable() const;
1128 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyCount()
1130 virtual unsigned int GetDefaultPropertyCount() const;
1133 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndices()
1135 virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
1138 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyName()
1140 virtual const std::string& GetDefaultPropertyName(Property::Index index) const;
1143 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndex()
1145 virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
1148 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyWritable()
1150 virtual bool IsDefaultPropertyWritable(Property::Index index) const;
1153 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAnimatable()
1155 virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
1158 * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAConstraintInput()
1160 virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
1163 * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyType()
1165 virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
1168 * @copydoc Dali::Internal::ProxyObject::SetDefaultProperty()
1170 virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
1173 * @copydoc Dali::Internal::ProxyObject::SetCustomProperty()
1175 virtual void SetCustomProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value );
1178 * @copydoc Dali::Internal::ProxyObject::GetDefaultProperty()
1180 virtual Property::Value GetDefaultProperty( Property::Index index ) const;
1183 * @copydoc Dali::Internal::ProxyObject::InstallSceneObjectProperty()
1185 virtual void InstallSceneObjectProperty( SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index );
1188 * @copydoc Dali::Internal::ProxyObject::GetSceneObject()
1190 virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
1193 * @copydoc Dali::Internal::ProxyObject::GetSceneObjectAnimatableProperty()
1195 virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
1198 * @copydoc Dali::Internal::ProxyObject::GetSceneObjectInputProperty()
1200 virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
1203 * @copydoc Dali::Internal::ProxyObject::GetPropertyComponentIndex()
1205 virtual int GetPropertyComponentIndex( Property::Index index ) const;
1213 Actor(const Actor&);
1216 Actor& operator=(const Actor& rhs);
1219 * Set the actors parent.
1220 * @param[in] parent The new parent.
1222 void SetParent(Actor* parent);
1225 * Helper to create a Node for this Actor.
1226 * To be overriden in derived classes.
1227 * @return A newly allocated node.
1229 virtual SceneGraph::Node* CreateNode() const;
1232 * For use in derived classes, called after Initialize()
1234 virtual void OnInitialize() {}
1237 * For use in internal derived classes.
1238 * This is called during ConnectToStage(), after the actor has finished adding its node to the scene-graph.
1239 * The derived class must not modify the actor hierachy (Add/Remove children) during this callback.
1241 virtual void OnStageConnectionInternal() {}
1244 * For use in internal derived classes.
1245 * This is called during DisconnectFromStage(), before the actor removes its node from the scene-graph.
1246 * The derived class must not modify the actor hierachy (Add/Remove children) during this callback.
1248 virtual void OnStageDisconnectionInternal() {}
1251 * For use in external (CustomActor) derived classes.
1252 * This is called after the atomic ConnectToStage() traversal has been completed.
1254 virtual void OnStageConnectionExternal() {}
1257 * For use in external (CustomActor) derived classes.
1258 * This is called after the atomic DisconnectFromStage() traversal has been completed.
1260 virtual void OnStageDisconnectionExternal() {}
1263 * For use in derived classes; this is called after Add() has added a child.
1264 * @param[in] child The child that was added.
1266 virtual void OnChildAdd( Actor& child ) {}
1269 * For use in derived classes; this is called after Remove() has removed a child.
1270 * @param[in] child The child that was removed.
1272 virtual void OnChildRemove( Actor& child ) {}
1275 * For use in derived classes.
1276 * This is called after SizeSet() has been called.
1278 virtual void OnSizeSet(const Vector3& targetSize) {}
1281 * For use in derived classes.
1282 * This is called after a non animatable custom property is set.
1283 * @param [in] index The index of the property.
1284 * @param [in] propertyValue The value of the property.
1286 virtual void OnPropertySet( Property::Index index, Property::Value propertyValue ) {}
1289 * For use in derived classes.
1290 * This is only called if mTouchRequired is true, and the touch-signal was not consumed.
1291 * @param[in] event The touch event.
1292 * @return True if the event should be consumed.
1294 virtual bool OnTouchEvent(const TouchEvent& event) { return false; }
1297 * For use in derived classes.
1298 * This is only called if the mouse wheel signal was not consumed.
1299 * @param[in] event The mouse event.
1300 * @return True if the event should be consumed.
1302 virtual bool OnMouseWheelEvent(const MouseWheelEvent& event) { return false; }
1305 * For use in derived class
1306 * If an alias for a child exists, return the child otherwise return an empty handle.
1307 * For example 'previous' could return the last selected child.
1308 * @pre The Actor has been initialized.
1309 * @param[in] actorAlias the name of the actor to find
1310 * @return A handle to the actor if found, or an empty handle if not.
1312 virtual Dali::Actor GetChildByAlias(const std::string& actorAlias) { return Dali::Actor(); }
1315 * Support function for FindChildByAlias
1316 * @pre The Actor has been initialized.
1317 * @param[in] actorAlias the name of the aliased actor to find
1318 * @return A handle to the actor if found, or an empty handle if not.
1320 Dali::Actor DoGetChildByAlias(const std::string& actorAlias);
1324 StagePtr mStage; ///< Used to send messages to Node; valid until Core destruction
1325 Actor* mParent; ///< Each actor (except the root) can have one parent
1326 ActorContainer* mChildren; ///< Container of referenced actors
1327 const SceneGraph::Node* mNode; ///< Not owned
1328 Vector3* mParentOrigin; // NULL means ParentOrigin::DEFAULT. ParentOrigin is non-animatable
1329 Vector3* mAnchorPoint; // NULL means AnchorPoint::DEFAULT. AnchorPoint is non-animatable
1331 #ifdef DYNAMICS_SUPPORT
1332 DynamicsData* mDynamicsData; ///< optional physics data
1335 GestureData* mGestureData; /// Optional Gesture data. Only created when actor requires gestures
1337 ActorAttachmentPtr mAttachment; ///< Optional referenced attachment
1338 ShaderEffectPtr mShaderEffect; ///< Optional referenced shader effect
1341 Dali::Actor::TouchSignalV2 mTouchedSignalV2;
1342 Dali::Actor::MouseWheelEventSignalV2 mMouseWheelEventSignalV2;
1343 Dali::Actor::SetSizeSignalV2 mSetSizeSignalV2;
1344 Dali::Actor::OnStageSignalV2 mOnStageSignalV2;
1345 Dali::Actor::OffStageSignalV2 mOffStageSignalV2;
1347 std::string mName; ///< Name of the actor
1348 unsigned int mId; ///< A unique ID to identify the actor starting from 1, and 0 is reserved
1350 const bool mIsRoot : 1; ///< Flag to identify the root actor
1351 const bool mIsRenderable : 1; ///< Flag to identify that this is a renderable actor
1352 const bool mIsLayer : 1; ///< Flag to identify that this is a layer
1353 bool mIsOnStage : 1; ///< Flag to identify whether the actor is on-stage
1354 bool mIsDynamicsRoot : 1; ///< Flag to identify if this is the dynamics world root
1355 bool mSensitive : 1; ///< Whether the actor emits touch event signals
1356 bool mLeaveRequired : 1; ///< Whether a touch event signal is emitted when the a touch leaves the actor's bounds
1357 bool mKeyboardFocusable : 1; ///< Whether the actor should be focusable by keyboard navigation
1358 bool mDerivedRequiresTouch : 1; ///< Whether the derived actor type requires touch event signals
1359 bool mDerivedRequiresMouseWheelEvent : 1; ///< Whether the derived actor type requires mouse wheel event signals
1360 bool mOnStageSignalled : 1; ///< Set to true before OnStageConnection signal is emitted, and false before OnStageDisconnection
1361 bool mInheritRotation : 1; ///< Cached: Whether the parent's rotation should be inherited.
1362 bool mInheritScale : 1; ///< Cached: Whether the parent's scale should be inherited.
1363 DrawMode::Type mDrawMode : 2; ///< Cached: How the actor and its children should be drawn
1364 PositionInheritanceMode mPositionInheritanceMode : 2; ///< Cached: Determines how position is inherited
1365 ColorMode mColorMode : 2; ///< Cached: Determines whether mWorldColor is inherited
1367 // Default properties
1368 typedef std::map<std::string, Property::Index> DefaultPropertyLookup;
1372 static ActorContainer mNullChildren; ///< Empty container (shared by all actors, returned by GetChildren() const)
1373 static unsigned int mActorCounter; ///< A counter to track the actor instance creation
1375 // Default properties
1376 static DefaultPropertyLookup* mDefaultPropertyLookup;
1381 * @brief Structure for setting up default properties and their details.
1383 struct PropertyDetails
1385 std::string name; ///< The name of the property.
1386 Property::Type type; ///< The property type.
1387 bool writable:1; ///< Whether the property is writable
1388 bool animatable:1; ///< Whether the property is animatable.
1389 bool constraintInput:1; ///< Whether the property can be used as an input to a constraint.
1392 } // namespace Internal
1394 // Helpers for public-api forwarding methods
1396 inline Internal::Actor& GetImplementation(Dali::Actor& actor)
1398 DALI_ASSERT_ALWAYS(actor && "Actor handle is empty");
1400 BaseObject& handle = actor.GetBaseObject();
1402 return static_cast<Internal::Actor&>(handle);
1405 inline const Internal::Actor& GetImplementation(const Dali::Actor& actor)
1407 DALI_ASSERT_ALWAYS(actor && "Actor handle is empty");
1409 const BaseObject& handle = actor.GetBaseObject();
1411 return static_cast<const Internal::Actor&>(handle);
1416 #endif // __DALI_INTERNAL_ACTOR_H__