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