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