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