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