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