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