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