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