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