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