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