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