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