Merge branch 'tizen' of platform/core/uifw/dali-core into devel/new_mesh
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / actor-impl.h
1 #ifndef __DALI_INTERNAL_ACTOR_H__
2 #define __DALI_INTERNAL_ACTOR_H__
3
4 /*
5  * Copyright (c) 2014 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <string>
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/common/vector-wrapper.h>
26 #include <dali/public-api/object/ref-object.h>
27 #include <dali/public-api/actors/actor.h>
28 #include <dali/public-api/common/dali-common.h>
29 #include <dali/public-api/events/gesture.h>
30 #include <dali/public-api/math/viewport.h>
31 #include <dali/internal/event/common/object-impl.h>
32 #include <dali/public-api/size-negotiation/relayout-container.h>
33 #include <dali/internal/event/common/stage-def.h>
34 #include <dali/internal/event/actors/actor-declarations.h>
35 #include <dali/internal/event/actors/renderer-impl.h>
36 #include <dali/internal/event/actor-attachments/actor-attachment-declarations.h>
37 #include <dali/internal/update/nodes/node-declarations.h>
38
39 #ifdef DYNAMICS_SUPPORT
40 #include <dali/internal/event/dynamics/dynamics-declarations.h>
41 #endif
42
43 namespace Dali
44 {
45
46 struct KeyEvent;
47 struct TouchEvent;
48 struct HoverEvent;
49 struct MouseWheelEvent;
50
51 namespace Internal
52 {
53
54 class Actor;
55 class ActorGestureData;
56 class Animation;
57 class RenderTask;
58 class Renderer;
59 struct DynamicsData;
60
61 typedef IntrusivePtr< Actor > ActorPtr;
62 typedef Dali::ActorContainer ActorContainer; // Store handles to return via public-api
63 typedef ActorContainer::iterator ActorIter;
64 typedef ActorContainer::const_iterator ActorConstIter;
65
66 /**
67  * Actor is the primary object which Dali applications interact with.
68  * UI controls can be built by combining multiple actors.
69  * Multi-Touch events are received through signals emitted by the actor tree.
70  *
71  * An Actor is a proxy for a Node in the scene graph.
72  * When an Actor is added to the Stage, it creates a node and attaches it to the scene graph.
73  * The scene-graph can be updated in a separate thread, so the attachment is done using an asynchronous message.
74  * When a tree of Actors is detached from the Stage, a message is sent to destroy the associated nodes.
75  */
76 class Actor : public Object
77 {
78 public:
79
80   /**
81    * @brief Struct to hold an actor and a dimension
82    */
83   struct ActorDimensionPair
84   {
85     /**
86      * @brief Constructor
87      *
88      * @param[in] newActor The actor to assign
89      * @param[in] newDimension The dimension to assign
90      */
91     ActorDimensionPair( Actor* newActor, Dimension newDimension )
92     : actor( newActor ),
93       dimension( newDimension )
94     {
95     }
96
97     /**
98      * @brief Equality operator
99      *
100      * @param[in] lhs The left hand side argument
101      * @param[in] rhs The right hand side argument
102      */
103     bool operator== ( const ActorDimensionPair& rhs )
104     {
105       return ( actor == rhs.actor ) && ( dimension == rhs.dimension );
106     }
107
108     Actor* actor;           ///< The actor to hold
109     Dimension dimension;    ///< The dimension to hold
110   };
111
112   typedef std::vector< ActorDimensionPair > ActorDimensionStack;
113
114 public:
115
116   /**
117    * Create a new actor.
118    * @return A smart-pointer to the newly allocated Actor.
119    */
120   static ActorPtr New();
121
122   /**
123    * Retrieve the name of the actor.
124    * @return The name.
125    */
126   const std::string& GetName() const;
127
128   /**
129    * Set the name of the actor.
130    * @param[in] name The new name.
131    */
132   void SetName( const std::string& name );
133
134   /**
135    * @copydoc Dali::Actor::GetId
136    */
137   unsigned int GetId() const;
138
139   // Attachments
140
141   /**
142    * Attach an object to an actor.
143    * @pre The actor does not already have an attachment.
144    * @param[in] attachment The object to attach.
145    */
146   void Attach( ActorAttachment& attachment );
147
148   /**
149    * Retreive the object attached to an actor.
150    * @return The attachment.
151    */
152   ActorAttachmentPtr GetAttachment();
153
154   // Containment
155
156   /**
157    * Query whether an actor is the root actor, which is owned by the Stage.
158    * @return True if the actor is a root actor.
159    */
160   bool IsRoot() const
161   {
162     return mIsRoot;
163   }
164
165   /**
166    * Query whether the actor is connected to the Stage.
167    */
168   bool OnStage() const;
169
170   /**
171    * Query whether the actor is a RenderableActor derived type.
172    * @return True if the actor is renderable.
173    */
174   bool IsRenderable() const
175   {
176     // inlined as this is called a lot in hit testing
177     return mIsRenderable;
178   }
179
180   /**
181    * Query whether the actor is of class Dali::Layer
182    * @return True if the actor is a layer.
183    */
184   bool IsLayer() const
185   {
186     // inlined as this is called a lot in hit testing
187     return mIsLayer;
188   }
189
190   /**
191    * Gets the layer in which the actor is present
192    * @return The layer, which will be uninitialized if the actor is off-stage.
193    */
194   Dali::Layer GetLayer();
195
196   /**
197    * Adds a child Actor to this Actor.
198    * @pre The child actor is not the same as the parent actor.
199    * @pre The child actor does not already have a parent.
200    * @param [in] child The child.
201    * @post The child will be referenced by its parent.
202    */
203   void Add( Actor& child );
204
205   /**
206    * Inserts a child Actor to this Actor's child list
207    * @pre The child actor is not the same as the parent actor.
208    * @pre The child actor does not already have a parent.
209    * @param [in] index in childlist to insert child at
210    * @param [in] child The child.
211    * @post The child will be referenced by its parent.
212    */
213   void Insert( unsigned int index, Actor& child );
214
215   /**
216    * Removes a child Actor from this Actor.
217    * @param [in] child The child.
218    * @post The child will be unreferenced.
219    */
220   void Remove( Actor& child );
221
222   /**
223    * @copydoc Dali::Actor::Unparent
224    */
225   void Unparent();
226
227   /**
228    * Retrieve the number of children held by the actor.
229    * @return The number of children
230    */
231   unsigned int GetChildCount() const;
232
233   /**
234    * @copydoc Dali::Actor::GetChildAt
235    */
236   Dali::Actor GetChildAt( unsigned int index ) const;
237
238   /**
239    * Retrieve the Actor's children.
240    * @return A copy of the container of children.
241    */
242   ActorContainer GetChildren();
243
244   /**
245    * Retrieve the Actor's children.
246    * @return A const reference to the container of children.
247    */
248   const ActorContainer& GetChildren() const;
249
250   /**
251    * Retrieve a reference to Actor's children.
252    * @note Not for public use.
253    * @return A reference to the container of children.
254    */
255   ActorContainer& GetChildrenInternal()
256   {
257     return *mChildren;
258   }
259
260   /**
261    * @copydoc Dali::Actor::FindChildByName
262    */
263   ActorPtr FindChildByName( const std::string& actorName );
264
265   /**
266    * @copydoc Dali::Actor::FindChildById
267    */
268   ActorPtr FindChildById( const unsigned int id );
269
270   /**
271    * Retrieve the parent of an Actor.
272    * @return The parent actor, or NULL if the Actor does not have a parent.
273    */
274   Actor* GetParent() const
275   {
276     return mParent;
277   }
278
279   /**
280    * Sets the size of an actor.
281    * ActorAttachments attached to the actor, can be scaled to fit within this area.
282    * This does not interfere with the actors scale factor.
283    * @param [in] width  The new width.
284    * @param [in] height The new height.
285    */
286   void SetSize( float width, float height );
287
288   /**
289    * Sets the size of an actor.
290    * ActorAttachments attached to the actor, can be scaled to fit within this area.
291    * This does not interfere with the actors scale factor.
292    * @param [in] width The size of the actor along the x-axis.
293    * @param [in] height The size of the actor along the y-axis.
294    * @param [in] depth The size of the actor along the z-axis.
295    */
296   void SetSize( float width, float height, float depth );
297
298   /**
299    * Sets the size of an actor.
300    * ActorAttachments attached to the actor, can be scaled to fit within this area.
301    * This does not interfere with the actors scale factor.
302    * @param [in] size The new size.
303    */
304   void SetSize( const Vector2& size );
305
306   /**
307    * Sets the size of an actor.
308    * ActorAttachments attached to the actor, can be scaled to fit within this area.
309    * This does not interfere with the actors scale factor.
310    * @param [in] size The new size.
311    */
312   void SetSize( const Vector3& size );
313
314   /**
315    * Set the width component of the Actor's size.
316    * @param [in] width The new width component.
317    */
318   void SetWidth( float width );
319
320   /**
321    * Set the height component of the Actor's size.
322    * @param [in] height The new height component.
323    */
324   void SetHeight( float height );
325
326   /**
327    * Set the depth component of the Actor's size.
328    * @param [in] depth The new depth component.
329    */
330   void SetDepth( float depth );
331
332   /**
333    * Retrieve the Actor's size from event side.
334    * This size will be the size set or if animating then the target size.
335    * @return The Actor's size.
336    */
337   const Vector3& GetTargetSize() const;
338
339   /**
340    * Retrieve the Actor's size from update side.
341    * This size will be the size set or animating but will be a frame behind.
342    * @return The Actor's size.
343    */
344   const Vector3& GetCurrentSize() const;
345
346   /**
347    * Return the natural size of the actor
348    *
349    * @return The actor's natural size
350    */
351   virtual Vector3 GetNaturalSize() const;
352
353   /**
354    * Set the origin of an actor, within its parent's area.
355    * This is expressed in 2D unit coordinates, such that (0.0, 0.0, 0.5) is the top-left corner of the parent,
356    * and (1.0, 1.0, 0.5) is the bottom-right corner.
357    * The default parent-origin is top-left (0.0, 0.0, 0.5).
358    * An actor position is the distance between this origin, and the actors anchor-point.
359    * @param [in] origin The new parent-origin.
360    */
361   void SetParentOrigin( const Vector3& origin );
362
363   /**
364    * Set the x component of the parent-origin
365    * @param [in] x The new x value.
366    */
367   void SetParentOriginX( float x );
368
369   /**
370    * Set the y component of the parent-origin
371    * @param [in] y The new y value.
372    */
373   void SetParentOriginY( float y );
374
375   /**
376    * Set the z component of the parent-origin
377    * @param [in] z The new z value.
378    */
379   void SetParentOriginZ( float z );
380
381   /**
382    * Retrieve the parent-origin of an actor.
383    * @return The parent-origin.
384    */
385   const Vector3& GetCurrentParentOrigin() const;
386
387   /**
388    * Set the anchor-point of an actor. This is expressed in 2D unit coordinates, such that
389    * (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.
390    * The default anchor point is top-left (0.0, 0.0, 0.5).
391    * An actor position is the distance between its parent-origin, and this anchor-point.
392    * An actor's rotation is centered around its anchor-point.
393    * @param [in] anchorPoint The new anchor-point.
394    */
395   void SetAnchorPoint( const Vector3& anchorPoint );
396
397   /**
398    * Set the x component of the anchor-point.
399    * @param [in] x The new x value.
400    */
401   void SetAnchorPointX( float x );
402
403   /**
404    * Set the y component of the anchor-point.
405    * @param [in] y The new y value.
406    */
407   void SetAnchorPointY( float y );
408
409   /**
410    * Set the z component of the anchor-point.
411    * @param [in] z The new z value.
412    */
413   void SetAnchorPointZ( float z );
414
415   /**
416    * Retrieve the anchor-point of an actor.
417    * @return The anchor-point.
418    */
419   const Vector3& GetCurrentAnchorPoint() const;
420
421   /**
422    * Sets the position of the Actor.
423    * The coordinates are relative to the Actor's parent.
424    * The Actor's z position will be set to 0.0f.
425    * @param [in] x The new x position
426    * @param [in] y The new y position
427    */
428   void SetPosition( float x, float y );
429
430   /**
431    * Sets the position of the Actor.
432    * The coordinates are relative to the Actor's parent.
433    * @param [in] x The new x position
434    * @param [in] y The new y position
435    * @param [in] z The new z position
436    */
437   void SetPosition( float x, float y, float z );
438
439   /**
440    * Sets the position of the Actor.
441    * The coordinates are relative to the Actor's parent.
442    * @param [in] position The new position.
443    */
444   void SetPosition( const Vector3& position );
445
446   /**
447    * Set the position of an actor along the X-axis.
448    * @param [in] x The new x position
449    */
450   void SetX( float x );
451
452   /**
453    * Set the position of an actor along the Y-axis.
454    * @param [in] y The new y position.
455    */
456   void SetY( float y );
457
458   /**
459    * Set the position of an actor along the Z-axis.
460    * @param [in] z The new z position
461    */
462   void SetZ( float z );
463
464   /**
465    * Translate an actor relative to its existing position.
466    * @param[in] distance The actor will move by this distance.
467    */
468   void TranslateBy( const Vector3& distance );
469
470   /**
471    * Retrieve the position of the Actor.
472    * The coordinates are relative to the Actor's parent.
473    * @return the Actor's position.
474    */
475   const Vector3& GetCurrentPosition() const;
476
477   /**
478    * @copydoc Dali::Actor::GetCurrentWorldPosition()
479    */
480   const Vector3& GetCurrentWorldPosition() const;
481
482   /**
483    * @copydoc Dali::Actor::SetPositionInheritanceMode()
484    */
485   void SetPositionInheritanceMode( PositionInheritanceMode mode );
486
487   /**
488    * @copydoc Dali::Actor::GetPositionInheritanceMode()
489    */
490   PositionInheritanceMode GetPositionInheritanceMode() const;
491
492   /**
493    * Sets the orientation of the Actor.
494    * @param [in] angleRadians The new orientation angle in radians.
495    * @param [in] axis The new axis of orientation.
496    */
497   void SetOrientation( const Radian& angleRadians, const Vector3& axis );
498
499   /**
500    * Sets the orientation of the Actor.
501    * @param [in] orientation The new orientation.
502    */
503   void SetOrientation( const Quaternion& orientation );
504
505   /**
506    * Rotate an actor around its existing rotation axis.
507    * @param[in] angleRadians The angle to the rotation to combine with the existing rotation.
508    * @param[in] axis The axis of the rotation to combine with the existing rotation.
509    */
510   void RotateBy( const Radian& angleRadians, const Vector3& axis );
511
512   /**
513    * Apply a relative rotation to an actor.
514    * @param[in] relativeRotation The rotation to combine with the actors existing rotation.
515    */
516   void RotateBy( const Quaternion& relativeRotation );
517
518   /**
519    * Retreive the Actor's orientation.
520    * @return the orientation.
521    */
522   const Quaternion& GetCurrentOrientation() const;
523
524   /**
525    * Set whether a child actor inherits it's parent's orientation. Default is to inherit.
526    * Switching this off means that using SetOrientation() sets the actor's world orientation.
527    * @param[in] inherit - true if the actor should inherit orientation, false otherwise.
528    */
529   void SetInheritOrientation( bool inherit );
530
531   /**
532    * Returns whether the actor inherit's it's parent's orientation.
533    * @return true if the actor inherit's it's parent orientation, false if it uses world orientation.
534    */
535   bool IsOrientationInherited() const;
536
537   /**
538    * @brief Defines how a child actors size is affected by its parents size.
539    * @param[in] mode The size relative to parent mode to use.
540    */
541   void SetSizeMode( SizeMode mode );
542
543   /**
544    * Query how the child actors size is affected by its parents size.
545    * @return The size relative to parent mode in use.
546    */
547   SizeMode GetSizeMode() const;
548
549   /**
550    * Sets the factor of the parents size used for the child actor.
551    * Note: Only used if SizeMode is SIZE_RELATIVE_TO_PARENT or SIZE_FIXED_OFFSET_FROM_PARENT.
552    * @param[in] factor The vector to multiply the parents size by to get the childs size.
553    */
554   void SetSizeModeFactor( const Vector3& factor );
555
556   /**
557    * Gets the factor of the parents size used for the child actor.
558    * Note: Only used if SizeMode is SIZE_RELATIVE_TO_PARENT or SIZE_FIXED_OFFSET_FROM_PARENT.
559    * @return The vector being used to multiply the parents size by to get the childs size.
560    */
561   const Vector3& GetSizeModeFactor() const;
562
563   /**
564    * @copydoc Dali::Actor::GetCurrentWorldOrientation()
565    */
566   const Quaternion& GetCurrentWorldOrientation() const;
567
568   /**
569    * Sets a scale factor applied to an actor.
570    * @param [in] scale The scale factor applied on all axes.
571    */
572   void SetScale( float scale );
573
574   /**
575    * Sets a scale factor applied to an actor.
576    * @param [in] scaleX The scale factor applied along the x-axis.
577    * @param [in] scaleY The scale factor applied along the y-axis.
578    * @param [in] scaleZ The scale factor applied along the z-axis.
579    */
580   void SetScale( float scaleX, float scaleY, float scaleZ );
581
582   /**
583    * Sets a scale factor applied to an actor.
584    * @param [in] scale A vector representing the scale factor for each axis.
585    */
586   void SetScale( const Vector3& scale );
587
588   /**
589    * Set the x component of the scale factor.
590    * @param [in] x The new x value.
591    */
592   void SetScaleX( float x );
593
594   /**
595    * Set the y component of the scale factor.
596    * @param [in] y The new y value.
597    */
598   void SetScaleY( float y );
599
600   /**
601    * Set the z component of the scale factor.
602    * @param [in] z The new z value.
603    */
604   void SetScaleZ( float z );
605
606   /**
607    * Apply a relative scale to an actor.
608    * @param[in] relativeScale The scale to combine with the actors existing scale.
609    */
610   void ScaleBy( const Vector3& relativeScale );
611
612   /**
613    * Retrieve the scale factor applied to an actor.
614    * @return A vector representing the scale factor for each axis.
615    */
616   const Vector3& GetCurrentScale() const;
617
618   /**
619    * @copydoc Dali::Actor::GetCurrentWorldScale()
620    */
621   const Vector3& GetCurrentWorldScale() const;
622
623   /**
624    * @copydoc Dali::Actor::SetInheritScale()
625    */
626   void SetInheritScale( bool inherit );
627
628   /**
629    * @copydoc Dali::Actor::IsScaleInherited()
630    */
631   bool IsScaleInherited() const;
632
633   /**
634    * @copydoc Dali::Actor::GetCurrentWorldMatrix()
635    */
636   Matrix GetCurrentWorldMatrix() const;
637
638   // Visibility
639
640   /**
641    * Sets the visibility flag of an actor.
642    * @param [in] visible The new visibility flag.
643    */
644   void SetVisible( bool visible );
645
646   /**
647    * Retrieve the visibility flag of an actor.
648    * @return The visibility flag.
649    */
650   bool IsVisible() const;
651
652   /**
653    * Sets the opacity of an actor.
654    * @param [in] opacity The new opacity.
655    */
656   void SetOpacity( float opacity );
657
658   /**
659    * Retrieve the actor's opacity.
660    * @return The actor's opacity.
661    */
662   float GetCurrentOpacity() const;
663
664   /**
665    * Sets whether an actor should emit touch or hover signals; see SignalTouch() and SignalHover().
666    * An actor is sensitive by default, which means that as soon as an application connects to the SignalTouch(),
667    * the touch event signal will be emitted, and as soon as an application connects to the SignalHover(), the
668    * hover event signal will be emitted.
669    *
670    * If the application wishes to temporarily disable the touch or hover event signal emission, then they can do so by calling:
671    * @code
672    * actor.SetSensitive(false);
673    * @endcode
674    *
675    * Then, to re-enable the touch or hover event signal emission, the application should call:
676    * @code
677    * actor.SetSensitive(true);
678    * @endcode
679    *
680    * @see SignalTouch() and SignalHover().
681    * @note If an actor's sensitivity is set to false, then it's children will not emit a touch or hover event signal either.
682    * @param[in]  sensitive  true to enable emission of the touch or hover event signals, false otherwise.
683    */
684   void SetSensitive( bool sensitive )
685   {
686     mSensitive = sensitive;
687   }
688
689   /**
690    * Query whether an actor emits touch or hover event signals.
691    * @see SetSensitive(bool)
692    * @return true, if emission of touch or hover event signals is enabled, false otherwise.
693    */
694   bool IsSensitive() const
695   {
696     return mSensitive;
697   }
698
699   /**
700    * @copydoc Dali::Actor::SetDrawMode
701    */
702   void SetDrawMode( DrawMode::Type drawMode );
703
704   /**
705    * @copydoc Dali::Actor::GetDrawMode
706    */
707   DrawMode::Type GetDrawMode() const;
708
709   /**
710    * @copydoc Dali::Actor::SetOverlay
711    */
712   void SetOverlay( bool enable );
713
714   /**
715    * @copydoc Dali::Actor::IsOverlay
716    */
717   bool IsOverlay() const;
718
719   /**
720    * Sets the actor's color.  The final color of actor depends on its color mode.
721    * This final color is applied to the drawable elements of an actor.
722    * @param [in] color The new color.
723    */
724   void SetColor( const Vector4& color );
725
726   /**
727    * Set the red component of the color.
728    * @param [in] red The new red component.
729    */
730   void SetColorRed( float red );
731
732   /**
733    * Set the green component of the color.
734    * @param [in] green The new green component.
735    */
736   void SetColorGreen( float green );
737
738   /**
739    * Set the blue component of the scale factor.
740    * @param [in] blue The new blue value.
741    */
742   void SetColorBlue( float blue );
743
744   /**
745    * Retrieve the actor's color.
746    * @return The color.
747    */
748   const Vector4& GetCurrentColor() const;
749
750   /**
751    * Sets the actor's color mode.
752    * Color mode specifies whether Actor uses its own color or inherits its parent color
753    * @param [in] colorMode to use.
754    */
755   void SetColorMode( ColorMode colorMode );
756
757   /**
758    * Returns the actor's color mode.
759    * @return currently used colorMode.
760    */
761   ColorMode GetColorMode() const;
762
763   /**
764    * @copydoc Dali::Actor::GetCurrentWorldColor()
765    */
766   const Vector4& GetCurrentWorldColor() const;
767
768 public:
769
770   // Size negotiation virtual functions
771
772   /**
773    * @brief Called after the size negotiation has been finished for this control.
774    *
775    * The control is expected to assign this given size to itself/its children.
776    *
777    * Should be overridden by derived classes if they need to layout
778    * actors differently after certain operations like add or remove
779    * actors, resize or after changing specific properties.
780    *
781    * Note! As this function is called from inside the size negotiation algorithm, you cannot
782    * call RequestRelayout (the call would just be ignored)
783    *
784    * @param[in]      size       The allocated size.
785    * @param[in,out]  container  The control should add actors to this container that it is not able
786    *                            to allocate a size for.
787    */
788   virtual void OnRelayout( const Vector2& size, RelayoutContainer& container )
789   {
790   }
791
792   /**
793    * @brief Notification for deriving classes when the resize policy is set
794    *
795    * @param[in] policy The policy being set
796    * @param[in] dimension The dimension the policy is being set for
797    */
798   virtual void OnSetResizePolicy( ResizePolicy policy, Dimension dimension ) {}
799
800   /**
801    * @brief Virtual method to notify deriving classes that relayout dependencies have been
802    * met and the size for this object is about to be calculated for the given dimension
803    *
804    * @param dimension The dimension that is about to be calculated
805    */
806   virtual void OnCalculateRelayoutSize( Dimension dimension );
807
808   /**
809    * @brief Virtual method to notify deriving classes that the size for a dimension
810    * has just been negotiated
811    *
812    * @param[in] size The new size for the given dimension
813    * @param[in] dimension The dimension that was just negotiated
814    */
815   virtual void OnLayoutNegotiated( float size, Dimension dimension );
816
817   /**
818    * @brief Determine if this actor is dependent on it's children for relayout
819    *
820    * @param dimension The dimension(s) to check for
821    * @return Return if the actor is dependent on it's children
822    */
823   virtual bool RelayoutDependentOnChildren( Dimension dimension = ALL_DIMENSIONS );
824
825   /**
826    * @brief Determine if this actor is dependent on it's children for relayout.
827    *
828    * Called from deriving classes
829    *
830    * @param dimension The dimension(s) to check for
831    * @return Return if the actor is dependent on it's children
832    */
833   virtual bool RelayoutDependentOnChildrenBase( Dimension dimension = ALL_DIMENSIONS );
834
835   /**
836    * @brief Calculate the size for a child
837    *
838    * @param[in] child The child actor to calculate the size for
839    * @param[in] dimension The dimension to calculate the size for. E.g. width or height.
840    * @return Return the calculated size for the given dimension
841    */
842   virtual float CalculateChildSize( const Dali::Actor& child, Dimension dimension );
843
844   /**
845    * @brief This method is called during size negotiation when a height is required for a given width.
846    *
847    * Derived classes should override this if they wish to customize the height returned.
848    *
849    * @param width to use.
850    * @return the height based on the width.
851    */
852   virtual float GetHeightForWidth( float width );
853
854   /**
855    * @brief This method is called during size negotiation when a width is required for a given height.
856    *
857    * Derived classes should override this if they wish to customize the width returned.
858    *
859    * @param height to use.
860    * @return the width based on the width.
861    */
862   virtual float GetWidthForHeight( float height );
863
864 public:
865
866   // Size negotiation
867
868   /**
869    * @brief Called by the RelayoutController to negotiate the size of an actor.
870    *
871    * The size allocated by the the algorithm is passed in which the
872    * actor must adhere to.  A container is passed in as well which
873    * the actor should populate with actors it has not / or does not
874    * need to handle in its size negotiation.
875    *
876    * @param[in]      size       The allocated size.
877    * @param[in,out]  container  The container that holds actors that are fed back into the
878    *                            RelayoutController algorithm.
879    */
880   void NegotiateSize( const Vector2& size, RelayoutContainer& container );
881
882   /**
883    * @copydoc Dali::Actor::SetResizePolicy()
884    */
885   void SetResizePolicy( ResizePolicy policy, Dimension dimension = ALL_DIMENSIONS );
886
887   /**
888    * @copydoc Dali::Actor::GetResizePolicy()
889    */
890   ResizePolicy GetResizePolicy( Dimension dimension ) const;
891
892   /**
893    * @copydoc Dali::Actor::SetSizeScalePolicy()
894    */
895   void SetSizeScalePolicy( SizeScalePolicy policy );
896
897   /**
898    * @copydoc Dali::Actor::GetSizeScalePolicy()
899    */
900   SizeScalePolicy GetSizeScalePolicy() const;
901
902   /**
903    * @copydoc Dali::Actor::SetDimensionDependency()
904    */
905   void SetDimensionDependency( Dimension dimension, Dimension dependency );
906
907   /**
908    * @copydoc Dali::Actor::GetDimensionDependency()
909    */
910   Dimension GetDimensionDependency( Dimension dimension ) const;
911
912   /**
913    * @copydoc Dali::Actor::SetRelayoutEnabled()
914    */
915   void SetRelayoutEnabled( bool relayoutEnabled );
916
917   /**
918    * @copydoc Dali::Actor::IsRelayoutEnabled()
919    */
920   bool IsRelayoutEnabled() const;
921
922   /**
923    * @brief Mark an actor as having it's layout dirty
924    *
925    * @param dirty Whether to mark actor as dirty or not
926    * @param dimension The dimension(s) to mark as dirty
927    */
928   void SetLayoutDirty( bool dirty, Dimension dimension = ALL_DIMENSIONS );
929
930   /**
931    * @brief Return if any of an actor's dimensions are marked as dirty
932    *
933    * @param dimension The dimension(s) to check
934    * @return Return if any of the requested dimensions are dirty
935    */
936   bool IsLayoutDirty( Dimension dimension = ALL_DIMENSIONS ) const;
937
938   /**
939    * @brief Returns if relayout is enabled and the actor is not dirty
940    *
941    * @return Return if it is possible to relayout the actor
942    */
943   bool RelayoutPossible( Dimension dimension = ALL_DIMENSIONS ) const;
944
945   /**
946    * @brief Returns if relayout is enabled and the actor is dirty
947    *
948    * @return Return if it is required to relayout the actor
949    */
950   bool RelayoutRequired( Dimension dimension = ALL_DIMENSIONS ) const;
951
952   /**
953    * @brief Request a relayout, which means performing a size negotiation on this actor, its parent and children (and potentially whole scene)
954    *
955    * This method is automatically called from OnStageConnection(), OnChildAdd(),
956    * OnChildRemove(), SetSizePolicy(), SetMinimumSize() and SetMaximumSize().
957    *
958    * This method can also be called from a derived class every time it needs a different size.
959    * At the end of event processing, the relayout process starts and
960    * all controls which requested Relayout will have their sizes (re)negotiated.
961    *
962    * @note RelayoutRequest() can be called multiple times; the size negotiation is still
963    * only performed once, i.e. there is no need to keep track of this in the calling side.
964    */
965   void RelayoutRequest( Dimension dimension = ALL_DIMENSIONS );
966
967   /**
968    * @brief Request to relayout of all actors in the sub-tree below the given actor.
969    *
970    * This flags the actor and all actors below it for relayout. The actual
971    * relayout is performed at the end of the frame. This means that multiple calls to relayout
972    * will not cause multiple relayouts to occur.
973    */
974   void RelayoutRequestTree();
975
976   /*
977    * @copydoc Dali::Actor::PropagateRelayoutFlags
978    */
979   void PropagateRelayoutFlags();
980
981   /**
982    * @brief Determine if this actor is dependent on it's parent for relayout
983    *
984    * @param dimension The dimension(s) to check for
985    * @return Return if the actor is dependent on it's parent
986    */
987   bool RelayoutDependentOnParent( Dimension dimension = ALL_DIMENSIONS );
988
989   /**
990    * @brief Determine if this actor has another dimension depedent on the specified one
991    *
992    * @param dimension The dimension to check for
993    * @param dependentDimension The dimension to check for dependency with
994    * @return Return if the actor is dependent on this dimension
995    */
996   bool RelayoutDependentOnDimension( Dimension dimension, Dimension dependentDimension );
997
998   /**
999    * Negotiate sizes for a control in all dimensions
1000    *
1001    * @param[in] allocatedSize The size constraint that the control must respect
1002    */
1003   void NegotiateDimensions( const Vector2& allocatedSize );
1004
1005   /**
1006    * Negotiate size for a specific dimension
1007    *
1008    * The algorithm adopts a recursive dependency checking approach. Meaning, that wherever dependencies
1009    * are found, e.g. an actor dependent on its parent, the dependency will be calculated first with NegotiatedDimension and
1010    * LayoutDimensionNegotiated flags being filled in on the actor.
1011    *
1012    * @post All actors that exist in the dependency chain connected to the given actor will have had their NegotiatedDimensions
1013    * calculated and set as well as the LayoutDimensionNegotiated flags.
1014    *
1015    * @param[in] dimension The dimension to negotiate on
1016    * @param[in] allocatedSize The size constraint that the actor must respect
1017    */
1018   void NegotiateDimension( Dimension dimension, const Vector2& allocatedSize, ActorDimensionStack& recursionStack );
1019
1020   /**
1021    * @brief Calculate the size of a dimension
1022    *
1023    * @param[in] dimension The dimension to calculate the size for
1024    * @param[in] maximumSize The upper bounds on the size
1025    * @return Return the calculated size for the dimension
1026    */
1027   float CalculateSize( Dimension dimension, const Vector2& maximumSize );
1028
1029   /**
1030    * @brief Constain a dimension given the relayout constraints on this actor
1031    *
1032    * @param[in] size The size to constrain
1033    * @param[in] dimension The dimension the size exists in
1034    * @return Return the constrained size
1035    */
1036   float ConstrainDimension( float size, Dimension dimension );
1037
1038   /**
1039    * Negotiate a dimension based on the size of the parent
1040    *
1041    * @param[in] dimension The dimension to negotiate on
1042    * @return Return the negotiated size
1043    */
1044   float NegotiateFromParent( Dimension dimension );
1045
1046   /**
1047    * Negotiate a dimension based on the size of the parent. Fitting inside.
1048    *
1049    * @param[in] dimension The dimension to negotiate on
1050    * @return Return the negotiated size
1051    */
1052   float NegotiateFromParentFit( Dimension dimension );
1053
1054   /**
1055    * Negotiate a dimension based on the size of the parent. Flooding the whole space.
1056    *
1057    * @param[in] dimension The dimension to negotiate on
1058    * @return Return the negotiated size
1059    */
1060   float NegotiateFromParentFlood( Dimension dimension );
1061
1062   /**
1063    * @brief Negotiate a dimension based on the size of the children
1064    *
1065    * @param[in] dimension The dimension to negotiate on
1066    * @return Return the negotiated size
1067    */
1068   float NegotiateFromChildren( Dimension dimension );
1069
1070   /**
1071    * Set the negotiated dimension value for the given dimension(s)
1072    *
1073    * @param negotiatedDimension The value to set
1074    * @param dimension The dimension(s) to set the value for
1075    */
1076   void SetNegotiatedDimension( float negotiatedDimension, Dimension dimension = ALL_DIMENSIONS );
1077
1078   /**
1079    * Return the value of negotiated dimension for the given dimension
1080    *
1081    * @param dimension The dimension to retrieve
1082    * @return Return the value of the negotiated dimension
1083    */
1084   float GetNegotiatedDimension( Dimension dimension ) const;
1085
1086   /**
1087    * @brief Set the padding for a dimension
1088    *
1089    * @param[in] padding Padding for the dimension. X = start (e.g. left, bottom), y = end (e.g. right, top)
1090    * @param[in] dimension The dimension to set
1091    */
1092   void SetPadding( const Vector2& padding, Dimension dimension );
1093
1094   /**
1095    * Return the value of padding for the given dimension
1096    *
1097    * @param dimension The dimension to retrieve
1098    * @return Return the value of padding for the dimension
1099    */
1100   Vector2 GetPadding( Dimension dimension ) const;
1101
1102   /**
1103    * Return the actor size for a given dimension
1104    *
1105    * @param[in] dimension The dimension to retrieve the size for
1106    * @return Return the size for the given dimension
1107    */
1108   float GetSize( Dimension dimension ) const;
1109
1110   /**
1111    * Return the natural size of the actor for a given dimension
1112    *
1113    * @param[in] dimension The dimension to retrieve the size for
1114    * @return Return the natural size for the given dimension
1115    */
1116   float GetNaturalSize( Dimension dimension ) const;
1117
1118   /**
1119    * @brief Return the amount of size allocated for relayout
1120    *
1121    * May include padding
1122    *
1123    * @param[in] dimension The dimension to retrieve
1124    * @return Return the size
1125    */
1126   float GetRelayoutSize( Dimension dimension ) const;
1127
1128   /**
1129    * @brief If the size has been negotiated return that else return normal size
1130    *
1131    * @param[in] dimension The dimension to retrieve
1132    * @return Return the size
1133    */
1134   float GetLatestSize( Dimension dimension ) const;
1135
1136   /**
1137    * Apply the negotiated size to the actor
1138    *
1139    * @param[in] container The container to fill with actors that require further relayout
1140    */
1141   void SetNegotiatedSize( RelayoutContainer& container );
1142
1143   /**
1144    * @brief Flag the actor as having it's layout dimension negotiated.
1145    *
1146    * @param[in] negotiated The status of the flag to set.
1147    * @param[in] dimension The dimension to set the flag for
1148    */
1149   void SetLayoutNegotiated( bool negotiated, Dimension dimension = ALL_DIMENSIONS );
1150
1151   /**
1152    * @brief Test whether the layout dimension for this actor has been negotiated or not.
1153    *
1154    * @param[in] dimension The dimension to determine the value of the flag for
1155    * @return Return if the layout dimension is negotiated or not.
1156    */
1157   bool IsLayoutNegotiated( Dimension dimension = ALL_DIMENSIONS ) const;
1158
1159   /**
1160    * @brief Calculate the size for a child
1161    *
1162    * @param[in] child The child actor to calculate the size for
1163    * @param[in] dimension The dimension to calculate the size for. E.g. width or height.
1164    * @return Return the calculated size for the given dimension
1165    */
1166   float CalculateChildSizeBase( const Dali::Actor& child, Dimension dimension );
1167
1168   /**
1169    * @copydoc Dali::Actor::SetPreferredSize
1170    */
1171   void SetPreferredSize( const Vector2& size );
1172
1173   /**
1174    * @copydoc Dali::Actor::GetPreferredSize
1175    */
1176   Vector2 GetPreferredSize() const;
1177
1178   /**
1179    * @copydoc Dali::Actor::SetMinimumSize
1180    */
1181   void SetMinimumSize( float size, Dimension dimension = ALL_DIMENSIONS );
1182
1183   /**
1184    * @copydoc Dali::Actor::GetMinimumSize
1185    */
1186   float GetMinimumSize( Dimension dimension ) const;
1187
1188   /**
1189    * @copydoc Dali::Actor::SetMaximumSize
1190    */
1191   void SetMaximumSize( float size, Dimension dimension = ALL_DIMENSIONS );
1192
1193   /**
1194    * @copydoc Dali::Actor::GetMaximumSize
1195    */
1196   float GetMaximumSize( Dimension dimension ) const;
1197   /**
1198    * @copydoc Dali::Actor::AddRenderer()
1199    */
1200   unsigned int AddRenderer( Renderer& renderer );
1201
1202   /**
1203    * @copydoc Dali::Actor::GetRendererCount()
1204    */
1205   unsigned int GetRendererCount() const;
1206
1207   /**
1208    * @copydoc Dali::Actor::GetRendererAt()
1209    */
1210   Renderer& GetRendererAt( unsigned int index );
1211
1212   /**
1213    * @copydoc Dali::Actor::RemoveRenderer()
1214    */
1215   void RemoveRenderer( Renderer& renderer );
1216
1217   /**
1218    * @copydoc Dali::Actor::RemoveRenderer()
1219    */
1220   void RemoveRenderer( unsigned int index );
1221
1222 #ifdef DYNAMICS_SUPPORT
1223
1224   // Dynamics
1225
1226   /// @copydoc Dali::Actor::DisableDynamics
1227   void DisableDynamics();
1228
1229   /// @copydoc Dali::Actor::EnableDynamics(Dali::DynamicsBodyConfig)
1230   DynamicsBodyPtr EnableDynamics(DynamicsBodyConfigPtr bodyConfig);
1231
1232   /// @copydoc Dali::Actor::GetDynamicsBody
1233   DynamicsBodyPtr GetDynamicsBody() const;
1234
1235   /// @copydoc Dali::Actor::AddDynamicsJoint(Dali::Actor,const Vector3&)
1236   DynamicsJointPtr AddDynamicsJoint( ActorPtr attachedActor, const Vector3& offset );
1237
1238   /// @copydoc Dali::Actor::AddDynamicsJoint(Dali::Actor,const Vector3&,const Vector3&)
1239   DynamicsJointPtr AddDynamicsJoint( ActorPtr attachedActor, const Vector3& offsetA, const Vector3& offsetB );
1240
1241   /// @copydoc Dali::Actor::GetNumberOfJoints
1242   const int GetNumberOfJoints() const;
1243
1244   /// @copydoc Dali::Actor::GetDynamicsJointByIndex
1245   DynamicsJointPtr GetDynamicsJointByIndex( const int index ) const;
1246
1247   /// @copydoc Dali::Actor::GetDynamicsJoint
1248   DynamicsJointPtr GetDynamicsJoint( ActorPtr attachedActor ) const;
1249
1250   /// @copydoc Dali::Actor::RemoveDynamicsJoint
1251   void RemoveDynamicsJoint( DynamicsJointPtr joint );
1252
1253   /**
1254    * Hold a reference to a DynamicsJoint
1255    * @param[in] joint The joint
1256    */
1257   void ReferenceJoint( DynamicsJointPtr joint );
1258
1259   /**
1260    * Release a reference to a DynamicsJoint
1261    * @param[in] joint The joint
1262    */
1263   void ReleaseJoint( DynamicsJointPtr joint );
1264
1265   /**
1266    * Set this actor to be the root actor in the dynamics simulation
1267    * All children of the actor are added/removed from the simulation.
1268    * @param[in] flag  When true sets this actor to be the simulation world root actor and
1269    *                  if OnStage() all dynamics enabled child actors are added to the simulation,
1270    *                  when false stops this actor being the simulation root and if OnStage() all
1271    *                  dynamics enabled child actors are removed from the simulation.
1272    */
1273   void SetDynamicsRoot(bool flag);
1274
1275 private:
1276   /**
1277    * Check if this actor is the root actor in the dynamics simulation
1278    * @return true if this is the dynamics root actor.
1279    */
1280   bool IsDynamicsRoot() const;
1281
1282   /**
1283    * Add actor to the dynamics simulation
1284    * Invoked when the actor is staged, or it's parent becomes the simulation root
1285    */
1286   void ConnectDynamics();
1287
1288   /**
1289    * Remove actor from the dynamics simulation
1290    * Invoked when the actor is unstaged, or it's parent stops being the the simulation root
1291    */
1292   void DisconnectDynamics();
1293
1294   /**
1295    * An actor in a DynamicsJoint relationship has been staged
1296    * @param[in] actor The actor passed into AddDynamicsJoint()
1297    */
1298   void AttachedActorOnStage( Dali::Actor actor );
1299
1300   /**
1301    * An actor in a DynamicsJoint relationship has been unstaged
1302    * @param[in] actor The actor passed into AddDynamicsJoint()
1303    */
1304   void AttachedActorOffStage( Dali::Actor actor );
1305
1306 #endif // DYNAMICS_SUPPORT
1307
1308 public:
1309   /**
1310    * Converts screen coordinates into the actor's coordinate system.
1311    * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
1312    * @param[out] localX On return, the X-coordinate relative to the actor.
1313    * @param[out] localY On return, the Y-coordinate relative to the actor.
1314    * @param[in] screenX The screen X-coordinate.
1315    * @param[in] screenY The screen Y-coordinate.
1316    * @return True if the conversion succeeded.
1317    */
1318   bool ScreenToLocal( float& localX, float& localY, float screenX, float screenY ) const;
1319
1320   /**
1321    * Converts screen coordinates into the actor's coordinate system.
1322    * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
1323    * @param[in] renderTask The render-task used to display the actor.
1324    * @param[out] localX On return, the X-coordinate relative to the actor.
1325    * @param[out] localY On return, the Y-coordinate relative to the actor.
1326    * @param[in] screenX The screen X-coordinate.
1327    * @param[in] screenY The screen Y-coordinate.
1328    * @return True if the conversion succeeded.
1329    */
1330   bool ScreenToLocal( RenderTask& renderTask, float& localX, float& localY, float screenX, float screenY ) const;
1331
1332   /**
1333    * Converts from the actor's coordinate system to screen coordinates.
1334    * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
1335    * @param[in] viewMatrix The view-matrix
1336    * @param[in] projectionMatrix The projection-matrix
1337    * @param[in] viewport The view-port
1338    * @param[out] localX On return, the X-coordinate relative to the actor.
1339    * @param[out] localY On return, the Y-coordinate relative to the actor.
1340    * @param[in] screenX The screen X-coordinate.
1341    * @param[in] screenY The screen Y-coordinate.
1342    * @return True if the conversion succeeded.
1343    */
1344   bool ScreenToLocal( const Matrix& viewMatrix,
1345                       const Matrix& projectionMatrix,
1346                       const Viewport& viewport,
1347                       float& localX,
1348                       float& localY,
1349                       float screenX,
1350                       float screenY ) const;
1351
1352   /**
1353    * Performs a ray-sphere test with the given pick-ray and the actor's bounding sphere.
1354    * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
1355    * @param[in] rayOrigin The ray origin in the world's reference system.
1356    * @param[in] rayDir The ray director vector in the world's reference system.
1357    * @return True if the ray intersects the actor's bounding sphere.
1358    */
1359   bool RaySphereTest( const Vector4& rayOrigin, const Vector4& rayDir ) const;
1360
1361   /**
1362    * Performs a ray-actor test with the given pick-ray and the actor's geometry.
1363    * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
1364    * @param[in] rayOrigin The ray origin in the world's reference system.
1365    * @param[in] rayDir The ray director vector in the world's reference system.
1366    * @param[out] hitPointLocal The hit point in the Actor's local reference system.
1367    * @param[out] distance The distance from the hit point to the camera.
1368    * @return True if the ray intersects the actor's geometry.
1369    */
1370   bool RayActorTest( const Vector4& rayOrigin,
1371                      const Vector4& rayDir,
1372                      Vector4& hitPointLocal,
1373                      float& distance ) const;
1374
1375   /**
1376    * Sets whether the actor should receive a notification when touch or hover motion events leave
1377    * the boundary of the actor.
1378    *
1379    * @note By default, this is set to false as most actors do not require this.
1380    * @note Need to connect to the SignalTouch or SignalHover to actually receive this event.
1381    *
1382    * @param[in]  required  Should be set to true if a Leave event is required
1383    */
1384   void SetLeaveRequired( bool required );
1385
1386   /**
1387    * This returns whether the actor requires touch or hover events whenever touch or hover motion events leave
1388    * the boundary of the actor.
1389    * @return true if a Leave event is required, false otherwise.
1390    */
1391   bool GetLeaveRequired() const;
1392
1393   /**
1394    * @copydoc Dali::Actor::SetKeyboardFocusable()
1395    */
1396   void SetKeyboardFocusable( bool focusable );
1397
1398   /**
1399    * @copydoc Dali::Actor::IsKeyboardFocusable()
1400    */
1401   bool IsKeyboardFocusable() const;
1402
1403   /**
1404    * Query whether the application or derived actor type requires touch events.
1405    * @return True if touch events are required.
1406    */
1407   bool GetTouchRequired() const;
1408
1409   /**
1410    * Query whether the application or derived actor type requires hover events.
1411    * @return True if hover events are required.
1412    */
1413   bool GetHoverRequired() const;
1414
1415   /**
1416    * Query whether the application or derived actor type requires mouse wheel events.
1417    * @return True if mouse wheel events are required.
1418    */
1419   bool GetMouseWheelEventRequired() const;
1420
1421   /**
1422    * Query whether the actor is actually hittable.  This method checks whether the actor is
1423    * sensitive, has the visibility flag set to true and is not fully transparent.
1424    * @return true, if it can be hit, false otherwise.
1425    */
1426   bool IsHittable() const;
1427
1428   // Gestures
1429
1430   /**
1431    * Retrieve the gesture data associated with this actor. The first call to this method will
1432    * allocate space for the ActorGestureData so this should only be called if an actor really does
1433    * require gestures.
1434    * @return Reference to the ActorGestureData for this actor.
1435    * @note Once the gesture-data is created for an actor it is likely that gestures are required
1436    * throughout the actor's lifetime so it will only be deleted when the actor is destroyed.
1437    */
1438   ActorGestureData& GetGestureData();
1439
1440   /**
1441    * Queries whether the actor requires the gesture type.
1442    * @param[in] type The gesture type.
1443    */
1444   bool IsGestureRequred( Gesture::Type type ) const;
1445
1446   // Signals
1447
1448   /**
1449    * Used by the EventProcessor to emit touch event signals.
1450    * @param[in] event The touch event.
1451    * @return True if the event was consumed.
1452    */
1453   bool EmitTouchEventSignal( const TouchEvent& event );
1454
1455   /**
1456    * Used by the EventProcessor to emit hover event signals.
1457    * @param[in] event The hover event.
1458    * @return True if the event was consumed.
1459    */
1460   bool EmitHoverEventSignal( const HoverEvent& event );
1461
1462   /**
1463    * Used by the EventProcessor to emit mouse wheel event signals.
1464    * @param[in] event The mouse wheel event.
1465    * @return True if the event was consumed.
1466    */
1467   bool EmitMouseWheelEventSignal( const MouseWheelEvent& event );
1468
1469   /**
1470    * @copydoc Dali::Actor::TouchedSignal()
1471    */
1472   Dali::Actor::TouchSignalType& TouchedSignal();
1473
1474   /**
1475    * @copydoc Dali::Actor::HoveredSignal()
1476    */
1477   Dali::Actor::HoverSignalType& HoveredSignal();
1478
1479   /**
1480    * @copydoc Dali::Actor::MouseWheelEventSignal()
1481    */
1482   Dali::Actor::MouseWheelEventSignalType& MouseWheelEventSignal();
1483
1484   /**
1485    * @copydoc Dali::Actor::OnStageSignal()
1486    */
1487   Dali::Actor::OnStageSignalType& OnStageSignal();
1488
1489   /**
1490    * @copydoc Dali::Actor::OffStageSignal()
1491    */
1492   Dali::Actor::OffStageSignalType& OffStageSignal();
1493
1494   /**
1495    * @copydoc Dali::Actor::OnRelayoutSignal()
1496    */
1497   Dali::Actor::OnRelayoutSignalType& OnRelayoutSignal();
1498
1499   /**
1500    * Connects a callback function with the object's signals.
1501    * @param[in] object The object providing the signal.
1502    * @param[in] tracker Used to disconnect the signal.
1503    * @param[in] signalName The signal to connect to.
1504    * @param[in] functor A newly allocated FunctorDelegate.
1505    * @return True if the signal was connected.
1506    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
1507    */
1508   static bool DoConnectSignal( BaseObject* object,
1509                                ConnectionTrackerInterface* tracker,
1510                                const std::string& signalName,
1511                                FunctorDelegate* functor );
1512
1513   /**
1514    * Performs actions as requested using the action name.
1515    * @param[in] object The object on which to perform the action.
1516    * @param[in] actionName The action to perform.
1517    * @param[in] attributes The attributes with which to perfrom this action.
1518    * @return true if the action was done.
1519    */
1520   static bool DoAction( BaseObject* object,
1521                         const std::string& actionName,
1522                         const std::vector< Property::Value >& attributes );
1523
1524 public:
1525   // For Animation
1526
1527   /**
1528    * This should only be called by Animation, when the actor is resized using Animation::Resize().
1529    *
1530    * @param[in] animation The animation that resized the actor
1531    * @param[in] targetSize The new target size of the actor
1532    */
1533   void NotifySizeAnimation( Animation& animation, const Vector3& targetSize );
1534
1535   /**
1536    * For use in derived classes.
1537    * This should only be called by Animation, when the actor is resized using Animation::Resize().
1538    */
1539   virtual void OnSizeAnimation( Animation& animation, const Vector3& targetSize )
1540   {
1541   }
1542
1543 protected:
1544
1545   enum DerivedType
1546   {
1547     BASIC, RENDERABLE, LAYER, ROOT_LAYER
1548   };
1549
1550   /**
1551    * Protected Constructor.  See Actor::New().
1552    * The second-phase construction Initialize() member should be called immediately after this.
1553    * @param[in] derivedType The derived type of actor (if any).
1554    */
1555   Actor( DerivedType derivedType );
1556
1557   /**
1558    * Second-phase constructor. Must be called immediately after creating a new Actor;
1559    */
1560   void Initialize( void );
1561
1562   /**
1563    * A reference counted object may only be deleted by calling Unreference()
1564    */
1565   virtual ~Actor();
1566
1567   /**
1568    * Called on a child during Add() when the parent actor is connected to the Stage.
1569    * @param[in] stage The stage.
1570    * @param[in] index If set, it is only used for positioning the actor within the parent's child list.
1571    */
1572   void ConnectToStage( int index = -1 );
1573
1574   /**
1575    * Helper for ConnectToStage, to recursively connect a tree of actors.
1576    * This is atomic i.e. not interrupted by user callbacks.
1577    * @param[in] index If set, it is only used for positioning the actor within the parent's child list.
1578    * @param[out] connectionList On return, the list of connected actors which require notification.
1579    */
1580   void RecursiveConnectToStage( ActorContainer& connectionList, int index = -1 );
1581
1582   /**
1583    * Connect the Node associated with this Actor to the scene-graph.
1584    * @param[in] index If set, it is only used for positioning the actor within the parent's child list.
1585    */
1586   void ConnectToSceneGraph( int index = -1 );
1587
1588   /**
1589    * Helper for ConnectToStage, to notify a connected actor through the public API.
1590    */
1591   void NotifyStageConnection();
1592
1593   /**
1594    * Called on a child during Remove() when the actor was previously on the Stage.
1595    */
1596   void DisconnectFromStage();
1597
1598   /**
1599    * Helper for DisconnectFromStage, to recursively disconnect a tree of actors.
1600    * This is atomic i.e. not interrupted by user callbacks.
1601    * @param[out] disconnectionList On return, the list of disconnected actors which require notification.
1602    */
1603   void RecursiveDisconnectFromStage( ActorContainer& disconnectionList );
1604
1605   /**
1606    * Disconnect the Node associated with this Actor from the scene-graph.
1607    */
1608   void DisconnectFromSceneGraph();
1609
1610   /**
1611    * Helper for DisconnectFromStage, to notify a disconnected actor through the public API.
1612    */
1613   void NotifyStageDisconnection();
1614
1615   /**
1616    * When the Actor is OnStage, checks whether the corresponding Node is connected to the scene graph.
1617    * @return True if the Actor is OnStage & has a Node connected to the scene graph.
1618    */
1619   bool IsNodeConnected() const;
1620
1621   /**
1622    * Calculate the size of the z dimension for a 2D size
1623    *
1624    * @param[in] size The 2D size (X, Y) to calculate Z from
1625    *
1626    * @return Return the Z dimension for this size
1627    */
1628   float CalculateSizeZ( const Vector2& size ) const;
1629
1630 public:
1631   // Default property extensions from Object
1632
1633   /**
1634    * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
1635    */
1636   virtual unsigned int GetDefaultPropertyCount() const;
1637
1638   /**
1639    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
1640    */
1641   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
1642
1643   /**
1644    * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
1645    */
1646   virtual const char* GetDefaultPropertyName( Property::Index index ) const;
1647
1648   /**
1649    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
1650    */
1651   virtual Property::Index GetDefaultPropertyIndex( const std::string& name ) const;
1652
1653   /**
1654    * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
1655    */
1656   virtual bool IsDefaultPropertyWritable( Property::Index index ) const;
1657
1658   /**
1659    * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
1660    */
1661   virtual bool IsDefaultPropertyAnimatable( Property::Index index ) const;
1662
1663   /**
1664    * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
1665    */
1666   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
1667
1668   /**
1669    * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
1670    */
1671   virtual Property::Type GetDefaultPropertyType( Property::Index index ) const;
1672
1673   /**
1674    * @copydoc Dali::Internal::Object::SetDefaultProperty()
1675    */
1676   virtual void SetDefaultProperty( Property::Index index, const Property::Value& propertyValue );
1677
1678   /**
1679    * @copydoc Dali::Internal::Object::SetSceneGraphProperty()
1680    */
1681   virtual void SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value );
1682
1683   /**
1684    * @copydoc Dali::Internal::Object::GetDefaultProperty()
1685    */
1686   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
1687
1688   /**
1689    * @copydoc Dali::Internal::Object::GetPropertyOwner()
1690    */
1691   virtual const SceneGraph::PropertyOwner* GetPropertyOwner() const;
1692
1693   /**
1694    * @copydoc Dali::Internal::Object::GetSceneObject()
1695    */
1696   virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
1697
1698   /**
1699    * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
1700    */
1701   virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
1702
1703   /**
1704    * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
1705    */
1706   virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
1707
1708   /**
1709    * @copydoc Dali::Internal::Object::GetPropertyComponentIndex()
1710    */
1711   virtual int GetPropertyComponentIndex( Property::Index index ) const;
1712
1713 private:
1714
1715   // Undefined
1716   Actor();
1717
1718   // Undefined
1719   Actor( const Actor& );
1720
1721   // Undefined
1722   Actor& operator=( const Actor& rhs );
1723
1724   /**
1725    * Set the actors parent.
1726    * @param[in] parent The new parent.
1727    * @param[in] index If set, it is only used for positioning the actor within the parent's child list.
1728    */
1729   void SetParent( Actor* parent, int index = -1 );
1730
1731   /**
1732    * Helper to create a Node for this Actor.
1733    * To be overriden in derived classes.
1734    * @return A newly allocated node.
1735    */
1736   virtual SceneGraph::Node* CreateNode() const;
1737
1738   /**
1739    * For use in derived classes, called after Initialize()
1740    */
1741   virtual void OnInitialize()
1742   {
1743   }
1744
1745   /**
1746    * For use in internal derived classes.
1747    * This is called during ConnectToStage(), after the actor has finished adding its node to the scene-graph.
1748    * The derived class must not modify the actor hierachy (Add/Remove children) during this callback.
1749    */
1750   virtual void OnStageConnectionInternal()
1751   {
1752   }
1753
1754   /**
1755    * For use in internal derived classes.
1756    * This is called during DisconnectFromStage(), before the actor removes its node from the scene-graph.
1757    * The derived class must not modify the actor hierachy (Add/Remove children) during this callback.
1758    */
1759   virtual void OnStageDisconnectionInternal()
1760   {
1761   }
1762
1763   /**
1764    * For use in external (CustomActor) derived classes.
1765    * This is called after the atomic ConnectToStage() traversal has been completed.
1766    */
1767   virtual void OnStageConnectionExternal()
1768   {
1769   }
1770
1771   /**
1772    * For use in external (CustomActor) derived classes.
1773    * This is called after the atomic DisconnectFromStage() traversal has been completed.
1774    */
1775   virtual void OnStageDisconnectionExternal()
1776   {
1777   }
1778
1779   /**
1780    * For use in derived classes; this is called after Add() has added a child.
1781    * @param[in] child The child that was added.
1782    */
1783   virtual void OnChildAdd( Actor& child )
1784   {
1785   }
1786
1787   /**
1788    * For use in derived classes; this is called after Remove() has removed a child.
1789    * @param[in] child The child that was removed.
1790    */
1791   virtual void OnChildRemove( Actor& child )
1792   {
1793   }
1794
1795   /**
1796    * For use in derived classes.
1797    * This is called after SizeSet() has been called.
1798    */
1799   virtual void OnSizeSet( const Vector3& targetSize )
1800   {
1801   }
1802
1803   /**
1804    * For use in derived classes.
1805    * This is only called if mDerivedRequiresTouch is true, and the touch-signal was not consumed.
1806    * @param[in] event The touch event.
1807    * @return True if the event should be consumed.
1808    */
1809   virtual bool OnTouchEvent( const TouchEvent& event )
1810   {
1811     return false;
1812   }
1813
1814   /**
1815    * For use in derived classes.
1816    * This is only called if mDerivedRequiresHover is true, and the hover-signal was not consumed.
1817    * @param[in] event The hover event.
1818    * @return True if the event should be consumed.
1819    */
1820   virtual bool OnHoverEvent( const HoverEvent& event )
1821   {
1822     return false;
1823   }
1824
1825   /**
1826    * For use in derived classes.
1827    * This is only called if the mouse wheel signal was not consumed.
1828    * @param[in] event The mouse event.
1829    * @return True if the event should be consumed.
1830    */
1831   virtual bool OnMouseWheelEvent( const MouseWheelEvent& event )
1832   {
1833     return false;
1834   }
1835
1836   /**
1837    * @brief Ensure the relayout data is allocated
1838    */
1839   void EnsureRelayoutData() const;
1840
1841   /**
1842    * @brief Apply the size set policy to the input size
1843    *
1844    * @param[in] size The size to apply the policy to
1845    * @return Return the adjusted size
1846    */
1847   Vector2 ApplySizeSetPolicy( const Vector2 size );
1848
1849 protected:
1850
1851   StagePtr mStage;                ///< Used to send messages to Node; valid until Core destruction
1852   Actor* mParent;                 ///< Each actor (except the root) can have one parent
1853   ActorContainer* mChildren;      ///< Container of referenced actors
1854   const SceneGraph::Node* mNode;  ///< Not owned
1855   Vector3* mParentOrigin;         ///< NULL means ParentOrigin::DEFAULT. ParentOrigin is non-animatable
1856   Vector3* mAnchorPoint;          ///< NULL means AnchorPoint::DEFAULT. AnchorPoint is non-animatable
1857
1858   struct RelayoutData;
1859   mutable RelayoutData* mRelayoutData; ///< Struct to hold optional collection of relayout variables
1860
1861 #ifdef DYNAMICS_SUPPORT
1862   DynamicsData* mDynamicsData; ///< optional physics data
1863 #endif
1864
1865   ActorGestureData* mGestureData;   ///< Optional Gesture data. Only created when actor requires gestures
1866
1867   ActorAttachmentPtr mAttachment;   ///< Optional referenced attachment
1868
1869   // Signals
1870   Dali::Actor::TouchSignalType             mTouchedSignal;
1871   Dali::Actor::HoverSignalType             mHoveredSignal;
1872   Dali::Actor::MouseWheelEventSignalType   mMouseWheelEventSignal;
1873   Dali::Actor::OnStageSignalType           mOnStageSignal;
1874   Dali::Actor::OffStageSignalType          mOffStageSignal;
1875   Dali::Actor::OnRelayoutSignalType        mOnRelayoutSignal;
1876
1877   Vector3         mTargetSize;      ///< Event-side storage for size (not a pointer as most actors will have a size)
1878
1879   std::string     mName;      ///< Name of the actor
1880   unsigned int    mId;        ///< A unique ID to identify the actor starting from 1, and 0 is reserved
1881
1882   const bool mIsRoot                               : 1; ///< Flag to identify the root actor
1883   const bool mIsRenderable                         : 1; ///< Flag to identify that this is a renderable actor
1884   const bool mIsLayer                              : 1; ///< Flag to identify that this is a layer
1885   bool mIsOnStage                                  : 1; ///< Flag to identify whether the actor is on-stage
1886   bool mIsDynamicsRoot                             : 1; ///< Flag to identify if this is the dynamics world root
1887   bool mSensitive                                  : 1; ///< Whether the actor emits touch event signals
1888   bool mLeaveRequired                              : 1; ///< Whether a touch event signal is emitted when the a touch leaves the actor's bounds
1889   bool mKeyboardFocusable                          : 1; ///< Whether the actor should be focusable by keyboard navigation
1890   bool mDerivedRequiresTouch                       : 1; ///< Whether the derived actor type requires touch event signals
1891   bool mDerivedRequiresHover                       : 1; ///< Whether the derived actor type requires hover event signals
1892   bool mDerivedRequiresMouseWheelEvent             : 1; ///< Whether the derived actor type requires mouse wheel event signals
1893   bool mOnStageSignalled                           : 1; ///< Set to true before OnStageConnection signal is emitted, and false before OnStageDisconnection
1894   bool mInheritOrientation                         : 1; ///< Cached: Whether the parent's orientation should be inherited.
1895   bool mInheritScale                               : 1; ///< Cached: Whether the parent's scale should be inherited.
1896   DrawMode::Type mDrawMode                         : 2; ///< Cached: How the actor and its children should be drawn
1897   PositionInheritanceMode mPositionInheritanceMode : 2; ///< Cached: Determines how position is inherited
1898   ColorMode mColorMode                             : 2; ///< Cached: Determines whether mWorldColor is inherited
1899
1900 private:
1901
1902   static ActorContainer mNullChildren;  ///< Empty container (shared by all actors, returned by GetChildren() const)
1903   static unsigned int mActorCounter;    ///< A counter to track the actor instance creation
1904
1905 };
1906
1907 } // namespace Internal
1908
1909 // Helpers for public-api forwarding methods
1910
1911 inline Internal::Actor& GetImplementation( Dali::Actor& actor )
1912 {
1913   DALI_ASSERT_ALWAYS( actor && "Actor handle is empty" );
1914
1915   BaseObject& handle = actor.GetBaseObject();
1916
1917   return static_cast< Internal::Actor& >( handle );
1918 }
1919
1920 inline const Internal::Actor& GetImplementation( const Dali::Actor& actor )
1921 {
1922   DALI_ASSERT_ALWAYS( actor && "Actor handle is empty" );
1923
1924   const BaseObject& handle = actor.GetBaseObject();
1925
1926   return static_cast< const Internal::Actor& >( handle );
1927 }
1928
1929 } // namespace Dali
1930
1931 #endif // __DALI_INTERNAL_ACTOR_H__