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