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