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