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