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