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