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