Remove unused FindActorByAlias
[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) 2014 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <string>
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/common/vector-wrapper.h>
26 #include <dali/public-api/object/ref-object.h>
27 #include <dali/public-api/actors/actor.h>
28 #include <dali/public-api/common/dali-common.h>
29 #include <dali/public-api/events/gesture.h>
30 #include <dali/public-api/math/viewport.h>
31 #include <dali/internal/event/common/object-impl.h>
32 #include <dali/internal/event/common/stage-def.h>
33 #include <dali/internal/event/actors/actor-declarations.h>
34 #include <dali/internal/event/actor-attachments/actor-attachment-declarations.h>
35 #include <dali/internal/update/nodes/node-declarations.h>
36
37 #ifdef DYNAMICS_SUPPORT
38 #include <dali/internal/event/dynamics/dynamics-declarations.h>
39 #endif
40
41 namespace Dali
42 {
43
44 struct KeyEvent;
45 struct TouchEvent;
46 struct HoverEvent;
47 struct MouseWheelEvent;
48
49 namespace Internal
50 {
51
52 class Actor;
53 class ActorGestureData;
54 class Animation;
55 class RenderTask;
56 struct DynamicsData;
57
58 typedef IntrusivePtr<Actor>                   ActorPtr;
59 typedef Dali::ActorContainer                  ActorContainer; // Store handles to return via public-api
60 typedef ActorContainer::iterator              ActorIter;
61 typedef ActorContainer::const_iterator        ActorConstIter;
62
63 /**
64  * Actor is the primary object which Dali applications interact with.
65  * UI controls can be built by combining multiple actors.
66  * Multi-Touch events are received through signals emitted by the actor tree.
67  *
68  * An Actor is a proxy for a Node in the scene graph.
69  * When an Actor is added to the Stage, it creates a node and attaches it to the scene graph.
70  * The scene-graph can be updated in a separate thread, so the attachment is done using an asynchronous message.
71  * When a tree of Actors is detached from the Stage, a message is sent to destroy the associated nodes.
72  */
73 class Actor : public Object
74 {
75 public:
76
77   /**
78    * Create a new actor.
79    * @return A smart-pointer to the newly allocated Actor.
80    */
81   static ActorPtr New();
82
83   /**
84    * Retrieve the name of the actor.
85    * @return The name.
86    */
87   const std::string& GetName() const;
88
89   /**
90    * Set the name of the actor.
91    * @param[in] name The new name.
92    */
93   void SetName(const std::string& name);
94
95   /**
96    * @copydoc Dali::Actor::GetId
97    */
98   unsigned int GetId() const;
99
100   // Attachments
101
102   /**
103    * Attach an object to an actor.
104    * @pre The actor does not already have an attachment.
105    * @param[in] attachment The object to attach.
106    */
107   void Attach(ActorAttachment& attachment);
108
109   /**
110    * Retreive the object attached to an actor.
111    * @return The attachment.
112    */
113   ActorAttachmentPtr GetAttachment();
114
115   // Containment
116
117   /**
118    * Query whether an actor is the root actor, which is owned by the Stage.
119    * @return True if the actor is a root actor.
120    */
121   bool IsRoot() const
122   {
123     return mIsRoot;
124   }
125
126   /**
127    * Query whether the actor is connected to the Stage.
128    */
129   bool OnStage() const;
130
131   /**
132    * Query whether the actor is a RenderableActor derived type.
133    * @return True if the actor is renderable.
134    */
135   bool IsRenderable() const
136   {
137     // inlined as this is called a lot in hit testing
138     return mIsRenderable;
139   }
140
141   /**
142    * Query whether the actor is of class Dali::Layer
143    * @return True if the actor is a layer.
144    */
145   bool IsLayer() const
146   {
147     // inlined as this is called a lot in hit testing
148     return mIsLayer;
149   }
150
151   /**
152    * Gets the layer in which the actor is present
153    * @return The layer, which will be uninitialized if the actor is off-stage.
154    */
155   Dali::Layer GetLayer();
156
157   /**
158    * Adds a child Actor to this Actor.
159    * @pre The child actor is not the same as the parent actor.
160    * @pre The child actor does not already have a parent.
161    * @param [in] child The child.
162    * @post The child will be referenced by its parent.
163    */
164   void Add(Actor& child);
165
166   /**
167    * Inserts a child Actor to this Actor's child list
168    * @pre The child actor is not the same as the parent actor.
169    * @pre The child actor does not already have a parent.
170    * @param [in] index in childlist to insert child at
171    * @param [in] child The child.
172    * @post The child will be referenced by its parent.
173    */
174   void Insert(unsigned int index, Actor& child);
175
176   /**
177    * Removes a child Actor from this Actor.
178    * @param [in] child The child.
179    * @post The child will be unreferenced.
180    */
181   void Remove(Actor& child);
182
183   /**
184    * @copydoc Dali::Actor::Unparent
185    */
186   void Unparent();
187
188   /**
189    * Retrieve the number of children held by the actor.
190    * @return The number of children
191    */
192   unsigned int GetChildCount() const;
193
194   /**
195    * @copydoc Dali::Actor::GetChildAt
196    */
197   Dali::Actor GetChildAt(unsigned int index) const;
198
199   /**
200    * Retrieve the Actor's children.
201    * @return A copy of the container of children.
202    */
203   ActorContainer GetChildren();
204
205   /**
206    * Retrieve the Actor's children.
207    * @return A const reference to the container of children.
208    */
209   const ActorContainer& GetChildren() const;
210
211   /**
212    * Retrieve a reference to Actor's children.
213    * @note Not for public use.
214    * @return A reference to the container of children.
215    */
216   ActorContainer& GetChildrenInternal()
217   {
218     return *mChildren;
219   }
220
221   /**
222    * @copydoc Dali::Actor::FindChildByName
223    */
224   ActorPtr FindChildByName(const std::string& actorName);
225
226   /**
227    * @copydoc Dali::Actor::FindChildById
228    */
229   ActorPtr FindChildById(const unsigned int id);
230
231   /**
232    * Retrieve the parent of an Actor.
233    * @return The parent actor, or NULL if the Actor does not have a parent.
234    */
235   Actor* GetParent() const
236   {
237     return mParent;
238   }
239
240   /**
241    * Sets the size of an actor.
242    * ActorAttachments attached to the actor, can be scaled to fit within this area.
243    * This does not interfere with the actors scale factor.
244    * @param [in] width  The new width.
245    * @param [in] height The new height.
246    */
247   void SetSize(float width, float height);
248
249   /**
250    * Sets the size of an actor.
251    * ActorAttachments attached to the actor, can be scaled to fit within this area.
252    * This does not interfere with the actors scale factor.
253    * @param [in] width The size of the actor along the x-axis.
254    * @param [in] height The size of the actor along the y-axis.
255    * @param [in] depth The size of the actor along the z-axis.
256    */
257   void SetSize(float width, float height, float depth);
258
259   /**
260    * Sets the size of an actor.
261    * ActorAttachments attached to the actor, can be scaled to fit within this area.
262    * This does not interfere with the actors scale factor.
263    * @param [in] size The new size.
264    */
265   void SetSize(const Vector2& size);
266
267   /**
268    * Sets the size of an actor.
269    * ActorAttachments attached to the actor, can be scaled to fit within this area.
270    * This does not interfere with the actors scale factor.
271    * @param [in] size The new size.
272    */
273   void SetSize(const Vector3& size);
274
275   /**
276    * Set the width component of the Actor's size.
277    * @param [in] width The new width component.
278    */
279   void SetWidth( float width );
280
281   /**
282    * Set the height component of the Actor's size.
283    * @param [in] height The new height component.
284    */
285   void SetHeight( float height );
286
287   /**
288    * Set the depth component of the Actor's size.
289    * @param [in] depth The new depth component.
290    */
291   void SetDepth( float depth );
292
293   /**
294    * Retrieve the Actor's size from event side.
295    * This size will be the size set or if animating then the target size.
296    * @return The Actor's size.
297    */
298   const Vector3& GetSize() const;
299
300   /**
301    * Retrieve the Actor's size from update side.
302    * This size will be the size set or animating but will be a frame behind.
303    * @return The Actor's size.
304    */
305   const Vector3& GetCurrentSize() const;
306
307   /**
308    * Return the natural size of the actor
309    *
310    * @return The actor's natural size
311    */
312   virtual Vector3 GetNaturalSize() const;
313
314   /**
315    * Set the origin of an actor, within its parent's area.
316    * This is expressed in 2D unit coordinates, such that (0.0, 0.0, 0.5) is the top-left corner of the parent,
317    * and (1.0, 1.0, 0.5) is the bottom-right corner.
318    * The default parent-origin is top-left (0.0, 0.0, 0.5).
319    * An actor position is the distance between this origin, and the actors anchor-point.
320    * @param [in] origin The new parent-origin.
321    */
322   void SetParentOrigin(const Vector3& origin);
323
324   /**
325    * Set the x component of the parent-origin
326    * @param [in] x The new x value.
327    */
328   void SetParentOriginX( float x );
329
330   /**
331    * Set the y component of the parent-origin
332    * @param [in] y The new y value.
333    */
334   void SetParentOriginY( float y );
335
336   /**
337    * Set the z component of the parent-origin
338    * @param [in] z The new z value.
339    */
340   void SetParentOriginZ( float z );
341
342   /**
343    * Retrieve the parent-origin of an actor.
344    * @return The parent-origin.
345    */
346   const Vector3& GetCurrentParentOrigin() const;
347
348   /**
349    * Set the anchor-point of an actor. This is expressed in 2D unit coordinates, such that
350    * (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.
351    * The default anchor point is top-left (0.0, 0.0, 0.5).
352    * An actor position is the distance between its parent-origin, and this anchor-point.
353    * An actor's rotation is centered around its anchor-point.
354    * @param [in] anchorPoint The new anchor-point.
355    */
356   void SetAnchorPoint(const Vector3& anchorPoint);
357
358   /**
359    * Set the x component of the anchor-point.
360    * @param [in] x The new x value.
361    */
362   void SetAnchorPointX( float x );
363
364   /**
365    * Set the y component of the anchor-point.
366    * @param [in] y The new y value.
367    */
368   void SetAnchorPointY( float y );
369
370   /**
371    * Set the z component of the anchor-point.
372    * @param [in] z The new z value.
373    */
374   void SetAnchorPointZ( float z );
375
376   /**
377    * Retrieve the anchor-point of an actor.
378    * @return The anchor-point.
379    */
380   const Vector3& GetCurrentAnchorPoint() const;
381
382   /**
383    * Sets the position of the Actor.
384    * The coordinates are relative to the Actor's parent.
385    * The Actor's z position will be set to 0.0f.
386    * @param [in] x The new x position
387    * @param [in] y The new y position
388    */
389   void SetPosition(float x, float y);
390
391   /**
392    * Sets the position of the Actor.
393    * The coordinates are relative to the Actor's parent.
394    * @param [in] x The new x position
395    * @param [in] y The new y position
396    * @param [in] z The new z position
397    */
398   void SetPosition(float x, float y, float z);
399
400   /**
401    * Sets the position of the Actor.
402    * The coordinates are relative to the Actor's parent.
403    * @param [in] position The new position.
404    */
405   void SetPosition(const Vector3& position);
406
407   /**
408    * Set the position of an actor along the X-axis.
409    * @param [in] x The new x position
410    */
411   void SetX(float x);
412
413   /**
414    * Set the position of an actor along the Y-axis.
415    * @param [in] y The new y position.
416    */
417   void SetY(float y);
418
419   /**
420    * Set the position of an actor along the Z-axis.
421    * @param [in] z The new z position
422    */
423   void SetZ(float z);
424
425   /**
426    * Move an actor relative to its existing position.
427    * @param[in] distance The actor will move by this distance.
428    */
429   void MoveBy(const Vector3& distance);
430
431   /**
432    * Retrieve the position of the Actor.
433    * The coordinates are relative to the Actor's parent.
434    * @return the Actor's position.
435    */
436   const Vector3& GetCurrentPosition() const;
437
438   /**
439    * @copydoc Dali::Actor::GetCurrentWorldPosition()
440    */
441   const Vector3& GetCurrentWorldPosition() const;
442
443   /**
444    * @copydoc Dali::Actor::SetPositionInheritanceMode()
445    */
446   void SetPositionInheritanceMode( PositionInheritanceMode mode );
447
448   /**
449    * @copydoc Dali::Actor::GetPositionInheritanceMode()
450    */
451   PositionInheritanceMode GetPositionInheritanceMode() const;
452
453   /**
454    * Sets the rotation of the Actor.
455    * @param [in] angleRadians The new rotation angle in radians.
456    * @param [in] axis The new axis of rotation.
457    */
458   void SetRotation(const Radian& angleRadians, const Vector3& axis);
459
460   /**
461    * Sets the rotation of the Actor.
462    * @param [in] rotation The new rotation.
463    */
464   void SetRotation(const Quaternion& rotation);
465
466   /**
467    * Rotate an actor around its existing rotation axis.
468    * @param[in] angleRadians The angle to the rotation to combine with the existing rotation.
469    * @param[in] axis The axis of the rotation to combine with the existing rotation.
470    */
471   void RotateBy(const Radian& angleRadians, const Vector3& axis);
472
473   /**
474    * Apply a relative rotation to an actor.
475    * @param[in] relativeRotation The rotation to combine with the actors existing rotation.
476    */
477   void RotateBy(const Quaternion& relativeRotation);
478
479   /**
480    * Retreive the Actor's rotation.
481    * @return the rotation.
482    */
483   const Quaternion& GetCurrentRotation() const;
484
485   /**
486    * Set whether a child actor inherits it's parent's orientation. Default is to inherit.
487    * Switching this off means that using SetRotation() sets the actor's world orientation.
488    * @param[in] inherit - true if the actor should inherit orientation, false otherwise.
489    */
490   void SetInheritRotation(bool inherit);
491
492   /**
493    * Returns whether the actor inherit's it's parent's orientation.
494    * @return true if the actor inherit's it's parent orientation, false if it uses world orientation.
495    */
496   bool IsRotationInherited() const;
497
498   /**
499    * @brief Defines how a child actors size is affected by its parents size.
500    * @param[in] mode The size relative to parent mode to use.
501    */
502   void SetSizeMode(SizeMode mode);
503
504   /**
505    * Query how the child actors size is affected by its parents size.
506    * @return The size relative to parent mode in use.
507    */
508   SizeMode GetSizeMode() const;
509
510   /**
511    * Sets the factor of the parents size used for the child actor.
512    * Note: Only used if SizeMode is SIZE_RELATIVE_TO_PARENT or SIZE_FIXED_OFFSET_FROM_PARENT.
513    * @param[in] factor The vector to multiply the parents size by to get the childs size.
514    */
515   void SetSizeModeFactor(const Vector3& factor);
516
517   /**
518    * Gets the factor of the parents size used for the child actor.
519    * Note: Only used if SizeMode is SIZE_RELATIVE_TO_PARENT or SIZE_FIXED_OFFSET_FROM_PARENT.
520    * @return The vector being used to multiply the parents size by to get the childs size.
521    */
522   const Vector3& GetSizeModeFactor() const;
523
524   /**
525    * @copydoc Dali::Actor::GetCurrentWorldRotation()
526    */
527   const Quaternion& GetCurrentWorldRotation() const;
528
529   /**
530    * Sets a scale factor applied to an actor.
531    * @param [in] scale The scale factor applied on all axes.
532    */
533   void SetScale(float scale);
534
535   /**
536    * Sets a scale factor applied to an actor.
537    * @param [in] scaleX The scale factor applied along the x-axis.
538    * @param [in] scaleY The scale factor applied along the y-axis.
539    * @param [in] scaleZ The scale factor applied along the z-axis.
540    */
541   void SetScale(float scaleX, float scaleY, float scaleZ);
542
543   /**
544    * Sets a scale factor applied to an actor.
545    * @param [in] scale A vector representing the scale factor for each axis.
546    */
547   void SetScale(const Vector3& scale);
548
549   /**
550    * Set the x component of the scale factor.
551    * @param [in] x The new x value.
552    */
553   void SetScaleX( float x );
554
555   /**
556    * Set the y component of the scale factor.
557    * @param [in] y The new y value.
558    */
559   void SetScaleY( float y );
560
561   /**
562    * Set the z component of the scale factor.
563    * @param [in] z The new z value.
564    */
565   void SetScaleZ( float z );
566
567   /**
568    * Apply a relative scale to an actor.
569    * @param[in] relativeScale The scale to combine with the actors existing scale.
570    */
571   void ScaleBy(const Vector3& relativeScale);
572
573   /**
574    * Retrieve the scale factor applied to an actor.
575    * @return A vector representing the scale factor for each axis.
576    */
577   const Vector3& GetCurrentScale() const;
578
579   /**
580    * @copydoc Dali::Actor::GetCurrentWorldScale()
581    */
582   const Vector3& GetCurrentWorldScale() const;
583
584   /**
585    * @copydoc Dali::Actor::SetInheritScale()
586    */
587   void SetInheritScale( bool inherit );
588
589   /**
590    * @copydoc Dali::Actor::IsScaleInherited()
591    */
592   bool IsScaleInherited() const;
593
594   /**
595    * @copydoc Dali::Actor::GetCurrentWorldMatrix()
596    */
597   Matrix GetCurrentWorldMatrix() const;
598
599   // Visibility
600
601   /**
602    * Sets the visibility flag of an actor.
603    * @param [in] visible The new visibility flag.
604    */
605   void SetVisible(bool visible);
606
607   /**
608    * Retrieve the visibility flag of an actor.
609    * @return The visibility flag.
610    */
611   bool IsVisible() const;
612
613   /**
614    * Sets the opacity of an actor.
615    * @param [in] opacity The new opacity.
616    */
617   void SetOpacity(float opacity);
618
619   /**
620    * Apply a relative opacity change to an actor.
621    * @param[in] relativeOpacity The opacity to combine with the actors existing opacity.
622    */
623   void OpacityBy(float relativeOpacity);
624
625   /**
626    * Retrieve the actor's opacity.
627    * @return The actor's opacity.
628    */
629   float GetCurrentOpacity() const;
630
631   /**
632    * Sets whether an actor should emit touch or hover signals; see SignalTouch() and SignalHover().
633    * An actor is sensitive by default, which means that as soon as an application connects to the SignalTouch(),
634    * the touch event signal will be emitted, and as soon as an application connects to the SignalHover(), the
635    * hover event signal will be emitted.
636    *
637    * If the application wishes to temporarily disable the touch or hover event signal emission, then they can do so by calling:
638    * @code
639    * actor.SetSensitive(false);
640    * @endcode
641    *
642    * Then, to re-enable the touch or hover event signal emission, the application should call:
643    * @code
644    * actor.SetSensitive(true);
645    * @endcode
646    *
647    * @see SignalTouch() and SignalHover().
648    * @note If an actor's sensitivity is set to false, then it's children will not emit a touch or hover event signal either.
649    * @param[in]  sensitive  true to enable emission of the touch or hover event signals, false otherwise.
650    */
651   void SetSensitive(bool sensitive)
652   {
653     mSensitive = sensitive;
654   }
655
656   /**
657    * Query whether an actor emits touch or hover event signals.
658    * @see SetSensitive(bool)
659    * @return true, if emission of touch or hover event signals is enabled, false otherwise.
660    */
661   bool IsSensitive() const
662   {
663     return mSensitive;
664   }
665
666   /**
667    * @copydoc Dali::Actor::SetDrawMode
668    */
669   void SetDrawMode( DrawMode::Type drawMode );
670
671   /**
672    * @copydoc Dali::Actor::GetDrawMode
673    */
674   DrawMode::Type GetDrawMode() const;
675
676   /**
677    * @copydoc Dali::Actor::SetOverlay
678    */
679   void SetOverlay(bool enable);
680
681   /**
682    * @copydoc Dali::Actor::IsOverlay
683    */
684   bool IsOverlay() const;
685
686   /**
687    * Sets whether an actor transmits geometry scaling to it's children.
688    * The default value is for it not to transmit scaling.
689    * @param[in] transmitGeometryScaling True to transmit scaling.
690    */
691   void SetTransmitGeometryScaling(bool transmitGeometryScaling);
692
693   /**
694    * Get the TransmitGeometryScaling property for this actor.
695    * @return True if geometry scaling is applied to the inherited scale.
696    */
697   bool GetTransmitGeometryScaling() const;
698
699   /**
700    * Sets the initial volume of the actor. Used for scaling the
701    * actor appropriately as the actor is sized when transmitGeometryScaling
702    * is set to true.
703    *
704    * @param[in] volume the volume of the model and it's children
705    */
706   void SetInitialVolume(const Vector3& volume);
707
708   /**
709    * Sets the actor's color.  The final color of actor depends on its color mode.
710    * This final color is applied to the drawable elements of an actor.
711    * @param [in] color The new color.
712    */
713   void SetColor(const Vector4& color);
714
715   /**
716    * Set the red component of the color.
717    * @param [in] red The new red component.
718    */
719   void SetColorRed( float red );
720
721   /**
722    * Set the green component of the color.
723    * @param [in] green The new green component.
724    */
725   void SetColorGreen( float green );
726
727   /**
728    * Set the blue component of the scale factor.
729    * @param [in] blue The new blue value.
730    */
731   void SetColorBlue( float blue );
732
733   /**
734    * Apply a relative color change to an actor.
735    * @param[in] relativeColor The color to combine with the actors existing color.
736    */
737   void ColorBy(const Vector4& relativeColor);
738
739   /**
740    * Retrieve the actor's color.
741    * @return The color.
742    */
743   const Vector4& GetCurrentColor() const;
744
745   /**
746    * Sets the actor's color mode.
747    * Color mode specifies whether Actor uses its own color or inherits its parent color
748    * @param [in] colorMode to use.
749    */
750   void SetColorMode(ColorMode colorMode);
751
752   /**
753    * Returns the actor's color mode.
754    * @return currently used colorMode.
755    */
756   ColorMode GetColorMode() const;
757
758   /**
759    * @copydoc Dali::Actor::GetCurrentWorldColor()
760    */
761   const Vector4& GetCurrentWorldColor() const;
762
763 #ifdef DYNAMICS_SUPPORT
764
765   // Dynamics
766
767   /// @copydoc Dali::Actor::DisableDynamics
768   void DisableDynamics();
769
770   /// @copydoc Dali::Actor::EnableDynamics(Dali::DynamicsBodyConfig)
771   DynamicsBodyPtr  EnableDynamics(DynamicsBodyConfigPtr bodyConfig);
772
773   /// @copydoc Dali::Actor::GetDynamicsBody
774   DynamicsBodyPtr GetDynamicsBody() const;
775
776   /// @copydoc Dali::Actor::AddDynamicsJoint(Dali::Actor,const Vector3&)
777   DynamicsJointPtr AddDynamicsJoint( ActorPtr attachedActor, const Vector3& offset );
778
779   /// @copydoc Dali::Actor::AddDynamicsJoint(Dali::Actor,const Vector3&,const Vector3&)
780   DynamicsJointPtr AddDynamicsJoint( ActorPtr attachedActor, const Vector3& offsetA, const Vector3& offsetB );
781
782   /// @copydoc Dali::Actor::GetNumberOfJoints
783   const int GetNumberOfJoints() const;
784
785   /// @copydoc Dali::Actor::GetDynamicsJointByIndex
786   DynamicsJointPtr GetDynamicsJointByIndex( const int index ) const;
787
788   /// @copydoc Dali::Actor::GetDynamicsJoint
789   DynamicsJointPtr GetDynamicsJoint( ActorPtr attachedActor ) const;
790
791   /// @copydoc Dali::Actor::RemoveDynamicsJoint
792   void RemoveDynamicsJoint( DynamicsJointPtr joint );
793
794   /**
795    * Hold a reference to a DynamicsJoint
796    * @param[in] joint The joint
797    */
798   void ReferenceJoint( DynamicsJointPtr joint );
799
800   /**
801    * Release a reference to a DynamicsJoint
802    * @param[in] joint The joint
803    */
804   void ReleaseJoint( DynamicsJointPtr joint );
805
806   /**
807    * Set this actor to be the root actor in the dynamics simulation
808    * All children of the actor are added/removed from the simulation.
809    * @param[in] flag  When true sets this actor to be the simulation world root actor and
810    *                  if OnStage() all dynamics enabled child actors are added to the simulation,
811    *                  when false stops this actor being the simulation root and if OnStage() all
812    *                  dynamics enabled child actors are removed from the simulation.
813    */
814   void SetDynamicsRoot(bool flag);
815
816 private:
817   /**
818    * Check if this actor is the root actor in the dynamics simulation
819    * @return true if this is the dynamics root actor.
820    */
821   bool IsDynamicsRoot() const;
822
823   /**
824    * Add actor to the dynamics simulation
825    * Invoked when the actor is staged, or it's parent becomes the simulation root
826    */
827   void ConnectDynamics();
828
829   /**
830    * Remove actor from the dynamics simulation
831    * Invoked when the actor is unstaged, or it's parent stops being the the simulation root
832    */
833   void DisconnectDynamics();
834
835   /**
836    * An actor in a DynamicsJoint relationship has been staged
837    * @param[in] actor The actor passed into AddDynamicsJoint()
838    */
839   void AttachedActorOnStage( Dali::Actor actor );
840
841   /**
842    * An actor in a DynamicsJoint relationship has been unstaged
843    * @param[in] actor The actor passed into AddDynamicsJoint()
844    */
845   void AttachedActorOffStage( Dali::Actor actor );
846
847 #endif // DYNAMICS_SUPPORT
848
849 public:
850   /**
851    * Converts screen coordinates into the actor's coordinate system.
852    * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
853    * @param[out] localX On return, the X-coordinate relative to the actor.
854    * @param[out] localY On return, the Y-coordinate relative to the actor.
855    * @param[in] screenX The screen X-coordinate.
856    * @param[in] screenY The screen Y-coordinate.
857    * @return True if the conversion succeeded.
858    */
859   bool ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const;
860
861   /**
862    * Converts screen coordinates into the actor's coordinate system.
863    * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
864    * @param[in] renderTask The render-task used to display the actor.
865    * @param[out] localX On return, the X-coordinate relative to the actor.
866    * @param[out] localY On return, the Y-coordinate relative to the actor.
867    * @param[in] screenX The screen X-coordinate.
868    * @param[in] screenY The screen Y-coordinate.
869    * @return True if the conversion succeeded.
870    */
871   bool ScreenToLocal(RenderTask& renderTask, float& localX, float& localY, float screenX, float screenY) const;
872
873   /**
874    * Converts from the actor's coordinate system to screen coordinates.
875    * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
876    * @param[in] viewMatrix The view-matrix
877    * @param[in] projectionMatrix The projection-matrix
878    * @param[in] viewport The view-port
879    * @param[out] localX On return, the X-coordinate relative to the actor.
880    * @param[out] localY On return, the Y-coordinate relative to the actor.
881    * @param[in] screenX The screen X-coordinate.
882    * @param[in] screenY The screen Y-coordinate.
883    * @return True if the conversion succeeded.
884    */
885   bool ScreenToLocal( const Matrix& viewMatrix,
886                       const Matrix& projectionMatrix,
887                       const Viewport& viewport,
888                       float& localX,
889                       float& localY,
890                       float screenX,
891                       float screenY ) const;
892
893   /**
894    * Performs a ray-sphere test with the given pick-ray and the actor's bounding sphere.
895    * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
896    * @param[in] rayOrigin The ray origin in the world's reference system.
897    * @param[in] rayDir The ray director vector in the world's reference system.
898    * @return True if the ray intersects the actor's bounding sphere.
899    */
900   bool RaySphereTest( const Vector4& rayOrigin, const Vector4& rayDir ) const;
901
902   /**
903    * Performs a ray-actor test with the given pick-ray and the actor's geometry.
904    * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
905    * @param[in] rayOrigin The ray origin in the world's reference system.
906    * @param[in] rayDir The ray director vector in the world's reference system.
907    * @param[out] hitPointLocal The hit point in the Actor's local reference system.
908    * @param[out] distance The distance from the hit point to the camera.
909    * @return True if the ray intersects the actor's geometry.
910    */
911   bool RayActorTest( const Vector4& rayOrigin, const Vector4& rayDir, Vector4& hitPointLocal, float& distance ) const;
912
913   /**
914    * Sets whether the actor should receive a notification when touch or hover motion events leave
915    * the boundary of the actor.
916    *
917    * @note By default, this is set to false as most actors do not require this.
918    * @note Need to connect to the SignalTouch or SignalHover to actually receive this event.
919    *
920    * @param[in]  required  Should be set to true if a Leave event is required
921    */
922   void SetLeaveRequired(bool required);
923
924   /**
925    * This returns whether the actor requires touch or hover events whenever touch or hover motion events leave
926    * the boundary of the actor.
927    * @return true if a Leave event is required, false otherwise.
928    */
929   bool GetLeaveRequired() const;
930
931   /**
932    * @copydoc Dali::Actor::SetKeyboardFocusable()
933    */
934   void SetKeyboardFocusable( bool focusable );
935
936   /**
937    * @copydoc Dali::Actor::IsKeyboardFocusable()
938    */
939   bool IsKeyboardFocusable() const;
940
941   /**
942    * Query whether the application or derived actor type requires touch events.
943    * @return True if touch events are required.
944    */
945   bool GetTouchRequired() const;
946
947   /**
948    * Query whether the application or derived actor type requires hover events.
949    * @return True if hover events are required.
950    */
951   bool GetHoverRequired() const;
952
953   /**
954    * Query whether the application or derived actor type requires mouse wheel events.
955    * @return True if mouse wheel events are required.
956    */
957   bool GetMouseWheelEventRequired() const;
958
959   /**
960    * Query whether the actor is actually hittable.  This method checks whether the actor is
961    * sensitive, has the visibility flag set to true and is not fully transparent.
962    * @return true, if it can be hit, false otherwise.
963    */
964   bool IsHittable() const;
965
966   // Gestures
967
968   /**
969    * Retrieve the gesture data associated with this actor. The first call to this method will
970    * allocate space for the ActorGestureData so this should only be called if an actor really does
971    * require gestures.
972    * @return Reference to the ActorGestureData for this actor.
973    * @note Once the gesture-data is created for an actor it is likely that gestures are required
974    * throughout the actor's lifetime so it will only be deleted when the actor is destroyed.
975    */
976   ActorGestureData& GetGestureData();
977
978   /**
979    * Queries whether the actor requires the gesture type.
980    * @param[in] type The gesture type.
981    */
982   bool IsGestureRequred( Gesture::Type type ) const;
983
984   // Signals
985
986   /**
987    * Used by the EventProcessor to emit touch event signals.
988    * @param[in] event The touch event.
989    * @return True if the event was consumed.
990    */
991   bool EmitTouchEventSignal(const TouchEvent& event);
992
993   /**
994    * Used by the EventProcessor to emit hover event signals.
995    * @param[in] event The hover event.
996    * @return True if the event was consumed.
997    */
998   bool EmitHoverEventSignal(const HoverEvent& event);
999
1000   /**
1001    * Used by the EventProcessor to emit mouse wheel event signals.
1002    * @param[in] event The mouse wheel event.
1003    * @return True if the event was consumed.
1004    */
1005   bool EmitMouseWheelEventSignal(const MouseWheelEvent& event);
1006
1007   /**
1008    * @copydoc Dali::Actor::TouchedSignal()
1009    */
1010   Dali::Actor::TouchSignalType& TouchedSignal();
1011
1012   /**
1013    * @copydoc Dali::Actor::HoveredSignal()
1014    */
1015   Dali::Actor::HoverSignalType& HoveredSignal();
1016
1017   /**
1018    * @copydoc Dali::Actor::MouseWheelEventSignal()
1019    */
1020   Dali::Actor::MouseWheelEventSignalType& MouseWheelEventSignal();
1021
1022   /**
1023    * @copydoc Dali::Actor::OnStageSignal()
1024    */
1025   Dali::Actor::OnStageSignalType& OnStageSignal();
1026
1027   /**
1028    * @copydoc Dali::Actor::OffStageSignal()
1029    */
1030   Dali::Actor::OffStageSignalType& OffStageSignal();
1031
1032   /**
1033    * Connects a callback function with the object's signals.
1034    * @param[in] object The object providing the signal.
1035    * @param[in] tracker Used to disconnect the signal.
1036    * @param[in] signalName The signal to connect to.
1037    * @param[in] functor A newly allocated FunctorDelegate.
1038    * @return True if the signal was connected.
1039    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
1040    */
1041   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
1042
1043   /**
1044    * Performs actions as requested using the action name.
1045    * @param[in] object The object on which to perform the action.
1046    * @param[in] actionName The action to perform.
1047    * @param[in] attributes The attributes with which to perfrom this action.
1048    * @return true if the action was done.
1049    */
1050   static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
1051
1052 public:  // For Animation
1053
1054   /**
1055    * This should only be called by Animation, when the actor is resized using Animation::Resize().
1056    *
1057    * @param[in] animation The animation that resized the actor
1058    * @param[in] targetSize The new target size of the actor
1059    */
1060   void NotifySizeAnimation( Animation& animation, const Vector3& targetSize);
1061
1062   /**
1063    * For use in derived classes.
1064    * This should only be called by Animation, when the actor is resized using Animation::Resize().
1065    */
1066   virtual void OnSizeAnimation( Animation& animation, const Vector3& targetSize) {}
1067
1068 protected:
1069
1070   enum DerivedType
1071   {
1072     BASIC,
1073     RENDERABLE,
1074     LAYER,
1075     ROOT_LAYER
1076   };
1077
1078   /**
1079    * Protected Constructor.  See Actor::New().
1080    * The second-phase construction Initialize() member should be called immediately after this.
1081    * @param[in] derivedType The derived type of actor (if any).
1082    */
1083   Actor( DerivedType derivedType );
1084
1085   /**
1086    * Second-phase constructor. Must be called immediately after creating a new Actor;
1087    */
1088   void Initialize(void);
1089
1090   /**
1091    * A reference counted object may only be deleted by calling Unreference()
1092    */
1093   virtual ~Actor();
1094
1095   /**
1096    * Called on a child during Add() when the parent actor is connected to the Stage.
1097    * @param[in] stage The stage.
1098    * @param[in] index If set, it is only used for positioning the actor within the parent's child list.
1099    */
1100   void ConnectToStage( int index = -1 );
1101
1102   /**
1103    * Helper for ConnectToStage, to recursively connect a tree of actors.
1104    * This is atomic i.e. not interrupted by user callbacks.
1105    * @param[in] index If set, it is only used for positioning the actor within the parent's child list.
1106    * @param[out] connectionList On return, the list of connected actors which require notification.
1107    */
1108   void RecursiveConnectToStage( ActorContainer& connectionList, int index = -1 );
1109
1110   /**
1111    * Connect the Node associated with this Actor to the scene-graph.
1112    * @param[in] index If set, it is only used for positioning the actor within the parent's child list.
1113    */
1114   void ConnectToSceneGraph(int index = -1);
1115
1116   /**
1117    * Helper for ConnectToStage, to notify a connected actor through the public API.
1118    */
1119   void NotifyStageConnection();
1120
1121   /**
1122    * Called on a child during Remove() when the actor was previously on the Stage.
1123    */
1124   void DisconnectFromStage();
1125
1126   /**
1127    * Helper for DisconnectFromStage, to recursively disconnect a tree of actors.
1128    * This is atomic i.e. not interrupted by user callbacks.
1129    * @param[out] disconnectionList On return, the list of disconnected actors which require notification.
1130    */
1131   void RecursiveDisconnectFromStage( ActorContainer& disconnectionList );
1132
1133   /**
1134    * Disconnect the Node associated with this Actor from the scene-graph.
1135    */
1136   void DisconnectFromSceneGraph();
1137
1138   /**
1139    * Helper for DisconnectFromStage, to notify a disconnected actor through the public API.
1140    */
1141   void NotifyStageDisconnection();
1142
1143   /**
1144    * When the Actor is OnStage, checks whether the corresponding Node is connected to the scene graph.
1145    * @return True if the Actor is OnStage & has a Node connected to the scene graph.
1146    */
1147   bool IsNodeConnected() const;
1148
1149   /**
1150    * Calculate the size of the z dimension for a 2D size
1151    *
1152    * @param[in] size The 2D size (X, Y) to calculate Z from
1153    *
1154    * @return Return the Z dimension for this size
1155    */
1156   float CalculateSizeZ( const Vector2& size ) const;
1157
1158 public: // Default property extensions from Object
1159
1160   /**
1161    * @copydoc Dali::Internal::Object::GetDefaultPropertyCount()
1162    */
1163   virtual unsigned int GetDefaultPropertyCount() const;
1164
1165   /**
1166    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndices()
1167    */
1168   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
1169
1170   /**
1171    * @copydoc Dali::Internal::Object::GetDefaultPropertyName()
1172    */
1173   virtual const char* GetDefaultPropertyName(Property::Index index) const;
1174
1175   /**
1176    * @copydoc Dali::Internal::Object::GetDefaultPropertyIndex()
1177    */
1178   virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
1179
1180   /**
1181    * @copydoc Dali::Internal::Object::IsDefaultPropertyWritable()
1182    */
1183   virtual bool IsDefaultPropertyWritable(Property::Index index) const;
1184
1185   /**
1186    * @copydoc Dali::Internal::Object::IsDefaultPropertyAnimatable()
1187    */
1188   virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
1189
1190   /**
1191    * @copydoc Dali::Internal::Object::IsDefaultPropertyAConstraintInput()
1192    */
1193   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
1194
1195   /**
1196    * @copydoc Dali::Internal::Object::GetDefaultPropertyType()
1197    */
1198   virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
1199
1200   /**
1201    * @copydoc Dali::Internal::Object::SetDefaultProperty()
1202    */
1203   virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
1204
1205   /**
1206    * @copydoc Dali::Internal::Object::SetSceneGraphProperty()
1207    */
1208   virtual void SetSceneGraphProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value );
1209
1210   /**
1211    * @copydoc Dali::Internal::Object::GetDefaultProperty()
1212    */
1213   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
1214
1215   /**
1216    * @copydoc Dali::Internal::Object::GetPropertyOwner()
1217    */
1218   virtual const SceneGraph::PropertyOwner* GetPropertyOwner() const;
1219
1220   /**
1221    * @copydoc Dali::Internal::Object::GetSceneObject()
1222    */
1223   virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
1224
1225   /**
1226    * @copydoc Dali::Internal::Object::GetSceneObjectAnimatableProperty()
1227    */
1228   virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
1229
1230   /**
1231    * @copydoc Dali::Internal::Object::GetSceneObjectInputProperty()
1232    */
1233   virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
1234
1235   /**
1236    * @copydoc Dali::Internal::Object::GetPropertyComponentIndex()
1237    */
1238   virtual int GetPropertyComponentIndex( Property::Index index ) const;
1239
1240 private:
1241
1242   // Undefined
1243   Actor();
1244
1245   // Undefined
1246   Actor(const Actor&);
1247
1248   // Undefined
1249   Actor& operator=(const Actor& rhs);
1250
1251   /**
1252    * Set the actors parent.
1253    * @param[in] parent The new parent.
1254    * @param[in] index If set, it is only used for positioning the actor within the parent's child list.
1255    */
1256   void SetParent(Actor* parent, int index = -1);
1257
1258   /**
1259    * Helper to create a Node for this Actor.
1260    * To be overriden in derived classes.
1261    * @return A newly allocated node.
1262    */
1263   virtual SceneGraph::Node* CreateNode() const;
1264
1265   /**
1266    * For use in derived classes, called after Initialize()
1267    */
1268   virtual void OnInitialize() {}
1269
1270   /**
1271    * For use in internal derived classes.
1272    * This is called during ConnectToStage(), after the actor has finished adding its node to the scene-graph.
1273    * The derived class must not modify the actor hierachy (Add/Remove children) during this callback.
1274    */
1275   virtual void OnStageConnectionInternal() {}
1276
1277   /**
1278    * For use in internal derived classes.
1279    * This is called during DisconnectFromStage(), before the actor removes its node from the scene-graph.
1280    * The derived class must not modify the actor hierachy (Add/Remove children) during this callback.
1281    */
1282   virtual void OnStageDisconnectionInternal() {}
1283
1284   /**
1285    * For use in external (CustomActor) derived classes.
1286    * This is called after the atomic ConnectToStage() traversal has been completed.
1287    */
1288   virtual void OnStageConnectionExternal() {}
1289
1290   /**
1291    * For use in external (CustomActor) derived classes.
1292    * This is called after the atomic DisconnectFromStage() traversal has been completed.
1293    */
1294   virtual void OnStageDisconnectionExternal() {}
1295
1296   /**
1297    * For use in derived classes; this is called after Add() has added a child.
1298    * @param[in] child The child that was added.
1299    */
1300   virtual void OnChildAdd( Actor& child ) {}
1301
1302   /**
1303    * For use in derived classes; this is called after Remove() has removed a child.
1304    * @param[in] child The child that was removed.
1305    */
1306   virtual void OnChildRemove( Actor& child ) {}
1307
1308   /**
1309    * For use in derived classes.
1310    * This is called after SizeSet() has been called.
1311    */
1312   virtual void OnSizeSet(const Vector3& targetSize) {}
1313
1314   /**
1315    * For use in derived classes.
1316    * This is only called if mDerivedRequiresTouch is true, and the touch-signal was not consumed.
1317    * @param[in] event The touch event.
1318    * @return True if the event should be consumed.
1319    */
1320   virtual bool OnTouchEvent(const TouchEvent& event) { return false; }
1321
1322   /**
1323    * For use in derived classes.
1324    * This is only called if mDerivedRequiresHover is true, and the hover-signal was not consumed.
1325    * @param[in] event The hover event.
1326    * @return True if the event should be consumed.
1327    */
1328   virtual bool OnHoverEvent(const HoverEvent& event) { return false; }
1329
1330   /**
1331    * For use in derived classes.
1332    * This is only called if the mouse wheel signal was not consumed.
1333    * @param[in] event The mouse event.
1334    * @return True if the event should be consumed.
1335    */
1336   virtual bool OnMouseWheelEvent(const MouseWheelEvent& event) { return false; }
1337
1338 protected:
1339
1340   StagePtr                mStage;        ///< Used to send messages to Node; valid until Core destruction
1341   Actor*                  mParent;       ///< Each actor (except the root) can have one parent
1342   ActorContainer*         mChildren;     ///< Container of referenced actors
1343   const SceneGraph::Node* mNode;         ///< Not owned
1344   Vector3*                mParentOrigin; ///< NULL means ParentOrigin::DEFAULT. ParentOrigin is non-animatable
1345   Vector3*                mAnchorPoint;  ///< NULL means AnchorPoint::DEFAULT. AnchorPoint is non-animatable
1346
1347 #ifdef DYNAMICS_SUPPORT
1348   DynamicsData*           mDynamicsData; ///< optional physics data
1349 #endif
1350
1351   ActorGestureData*       mGestureData;  ///< Optional Gesture data. Only created when actor requires gestures
1352
1353   ActorAttachmentPtr      mAttachment;   ///< Optional referenced attachment
1354
1355   // Signals
1356   Dali::Actor::TouchSignalType             mTouchedSignal;
1357   Dali::Actor::HoverSignalType             mHoveredSignal;
1358   Dali::Actor::MouseWheelEventSignalType   mMouseWheelEventSignal;
1359   Dali::Actor::OnStageSignalType           mOnStageSignal;
1360   Dali::Actor::OffStageSignalType          mOffStageSignal;
1361
1362   Vector3         mSize;      ///< Event-side storage for size (not a pointer as most actors will have a size)
1363   Vector3         mSizeModeFactor; ///< Factor of parent size used for certain SizeModes.
1364
1365   std::string     mName;      ///< Name of the actor
1366   unsigned int    mId;        ///< A unique ID to identify the actor starting from 1, and 0 is reserved
1367
1368   const bool mIsRoot                               : 1; ///< Flag to identify the root actor
1369   const bool mIsRenderable                         : 1; ///< Flag to identify that this is a renderable actor
1370   const bool mIsLayer                              : 1; ///< Flag to identify that this is a layer
1371   bool mIsOnStage                                  : 1; ///< Flag to identify whether the actor is on-stage
1372   bool mIsDynamicsRoot                             : 1; ///< Flag to identify if this is the dynamics world root
1373   bool mSensitive                                  : 1; ///< Whether the actor emits touch event signals
1374   bool mLeaveRequired                              : 1; ///< Whether a touch event signal is emitted when the a touch leaves the actor's bounds
1375   bool mKeyboardFocusable                          : 1; ///< Whether the actor should be focusable by keyboard navigation
1376   bool mDerivedRequiresTouch                       : 1; ///< Whether the derived actor type requires touch event signals
1377   bool mDerivedRequiresHover                       : 1; ///< Whether the derived actor type requires hover event signals
1378   bool mDerivedRequiresMouseWheelEvent             : 1; ///< Whether the derived actor type requires mouse wheel event signals
1379   bool mOnStageSignalled                           : 1; ///< Set to true before OnStageConnection signal is emitted, and false before OnStageDisconnection
1380   bool mInheritRotation                            : 1; ///< Cached: Whether the parent's rotation should be inherited.
1381   bool mInheritScale                               : 1; ///< Cached: Whether the parent's scale should be inherited.
1382   DrawMode::Type mDrawMode                         : 2; ///< Cached: How the actor and its children should be drawn
1383   PositionInheritanceMode mPositionInheritanceMode : 2; ///< Cached: Determines how position is inherited
1384   ColorMode mColorMode                             : 2; ///< Cached: Determines whether mWorldColor is inherited
1385   SizeMode mSizeMode                               : 2; ///< Cached: Determines how the actors parent affects the actors size.
1386
1387 private:
1388
1389   static ActorContainer mNullChildren; ///< Empty container (shared by all actors, returned by GetChildren() const)
1390   static unsigned int   mActorCounter; ///< A counter to track the actor instance creation
1391
1392 };
1393
1394 } // namespace Internal
1395
1396 // Helpers for public-api forwarding methods
1397
1398 inline Internal::Actor& GetImplementation(Dali::Actor& actor)
1399 {
1400   DALI_ASSERT_ALWAYS(actor && "Actor handle is empty");
1401
1402   BaseObject& handle = actor.GetBaseObject();
1403
1404   return static_cast<Internal::Actor&>(handle);
1405 }
1406
1407 inline const Internal::Actor& GetImplementation(const Dali::Actor& actor)
1408 {
1409   DALI_ASSERT_ALWAYS(actor && "Actor handle is empty");
1410
1411   const BaseObject& handle = actor.GetBaseObject();
1412
1413   return static_cast<const Internal::Actor&>(handle);
1414 }
1415
1416 } // namespace Dali
1417
1418 #endif // __DALI_INTERNAL_ACTOR_H__