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