Merge "Added api function to specify speed factor of an animation" into tizen
[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/events/gesture.h>
31 #include <dali/public-api/math/viewport.h>
32 #include <dali/internal/event/common/proxy-object.h>
33 #include <dali/internal/event/common/stage-def.h>
34 #include <dali/internal/event/actors/actor-declarations.h>
35 #include <dali/internal/event/actor-attachments/actor-attachment-declarations.h>
36 #include <dali/internal/update/nodes/node-declarations.h>
37
38 #ifdef DYNAMICS_SUPPORT
39 #include <dali/internal/event/dynamics/dynamics-declarations.h>
40 #endif
41
42 namespace Dali
43 {
44
45 struct KeyEvent;
46 struct TouchEvent;
47 struct MouseWheelEvent;
48
49 namespace Internal
50 {
51
52 class Actor;
53 class ActorGestureData;
54 class RenderTask;
55 struct DynamicsData;
56
57 typedef IntrusivePtr<Actor>                   ActorPtr;
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    * Inserts a child Actor to this Actor's child list
167    * @pre The child actor is not the same as the parent actor.
168    * @pre The child actor does not already have a parent.
169    * @param [in] index in childlist to insert child at
170    * @param [in] child The child.
171    * @post The child will be referenced by its parent.
172    */
173   void Insert(unsigned int index, Actor& child);
174
175   /**
176    * Removes a child Actor from this Actor.
177    * @param [in] child The child.
178    * @post The child will be unreferenced.
179    */
180   void Remove(Actor& child);
181
182   /**
183    * @copydoc Dali::Actor::Unparent
184    */
185   void Unparent();
186
187   /**
188    * Retrieve the number of children held by the actor.
189    * @return The number of children
190    */
191   unsigned int GetChildCount() const;
192
193   /**
194    * @copydoc Dali::Actor::GetChildAt
195    */
196   Dali::Actor GetChildAt(unsigned int index) const;
197
198   /**
199    * Retrieve the Actor's children.
200    * @return A copy of the container of children.
201    */
202   ActorContainer GetChildren();
203
204   /**
205    * Retrieve the Actor's children.
206    * @return A const reference to the container of children.
207    */
208   const ActorContainer& GetChildren() const;
209
210   /**
211    * Retrieve a reference to Actor's children.
212    * @note Not for public use.
213    * @return A reference to the container of children.
214    */
215   ActorContainer& GetChildrenInternal()
216   {
217     return *mChildren;
218   }
219
220   /**
221    * @copydoc Dali::Actor::FindChildByName
222    */
223   ActorPtr FindChildByName(const std::string& actorName);
224
225   /**
226    * @copydoc Dali::Actor::FindChildByAlias
227    */
228   Dali::Actor FindChildByAlias(const std::string& actorAlias);
229
230   /**
231    * @copydoc Dali::Actor::FindChildById
232    */
233   ActorPtr FindChildById(const unsigned int id);
234
235   /**
236    * Retrieve the parent of an Actor.
237    * @return The parent actor, or NULL if the Actor does not have a parent.
238    */
239   Actor* GetParent() const
240   {
241     return mParent;
242   }
243
244   /**
245    * Sets the size of an actor.
246    * ActorAttachments attached to the actor, can be scaled to fit within this area.
247    * This does not interfere with the actors scale factor.
248    * @param [in] width  The new width.
249    * @param [in] height The new height.
250    */
251   void SetSize(float width, float height);
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] width The size of the actor along the x-axis.
258    * @param [in] height The size of the actor along the y-axis.
259    * @param [in] depth The size of the actor along the z-axis.
260    */
261   void SetSize(float width, float height, float depth);
262
263   /**
264    * Sets the size of an actor.
265    * ActorAttachments attached to the actor, can be scaled to fit within this area.
266    * This does not interfere with the actors scale factor.
267    * @param [in] size The new size.
268    */
269   void SetSize(const Vector2& size);
270
271   /**
272    * Sets the size of an actor.
273    * ActorAttachments attached to the actor, can be scaled to fit within this area.
274    * This does not interfere with the actors scale factor.
275    * @param [in] size The new size.
276    */
277   void SetSize(const Vector3& size);
278
279   /**
280    * Set the width component of the Actor's size.
281    * @param [in] width The new width component.
282    */
283   void SetWidth( float width );
284
285   /**
286    * Set the height component of the Actor's size.
287    * @param [in] height The new height component.
288    */
289   void SetHeight( float height );
290
291   /**
292    * Set the depth component of the Actor's size.
293    * @param [in] depth The new depth component.
294    */
295   void SetDepth( float depth );
296
297   /**
298    * Retrieve the Actor's size.
299    * @return The Actor's size.
300    */
301   const Vector3& GetCurrentSize() const;
302
303   /**
304    * Set the origin of an actor, within its parent's area.
305    * This is expressed in 2D unit coordinates, such that (0.0, 0.0, 0.5) is the top-left corner of the parent,
306    * and (1.0, 1.0, 0.5) is the bottom-right corner.
307    * The default parent-origin is top-left (0.0, 0.0, 0.5).
308    * An actor position is the distance between this origin, and the actors anchor-point.
309    * @param [in] origin The new parent-origin.
310    */
311   void SetParentOrigin(const Vector3& origin);
312
313   /**
314    * Set the x component of the parent-origin
315    * @param [in] x The new x value.
316    */
317   void SetParentOriginX( float x );
318
319   /**
320    * Set the y component of the parent-origin
321    * @param [in] y The new y value.
322    */
323   void SetParentOriginY( float y );
324
325   /**
326    * Set the z component of the parent-origin
327    * @param [in] z The new z value.
328    */
329   void SetParentOriginZ( float z );
330
331   /**
332    * Retrieve the parent-origin of an actor.
333    * @return The parent-origin.
334    */
335   const Vector3& GetCurrentParentOrigin() const;
336
337   /**
338    * Set the anchor-point of an actor. This is expressed in 2D unit coordinates, such that
339    * (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.
340    * The default anchor point is top-left (0.0, 0.0, 0.5).
341    * An actor position is the distance between its parent-origin, and this anchor-point.
342    * An actor's rotation is centered around its anchor-point.
343    * @param [in] anchorPoint The new anchor-point.
344    */
345   void SetAnchorPoint(const Vector3& anchorPoint);
346
347   /**
348    * Set the x component of the anchor-point.
349    * @param [in] x The new x value.
350    */
351   void SetAnchorPointX( float x );
352
353   /**
354    * Set the y component of the anchor-point.
355    * @param [in] y The new y value.
356    */
357   void SetAnchorPointY( float y );
358
359   /**
360    * Set the z component of the anchor-point.
361    * @param [in] z The new z value.
362    */
363   void SetAnchorPointZ( float z );
364
365   /**
366    * Retrieve the anchor-point of an actor.
367    * @return The anchor-point.
368    */
369   const Vector3& GetCurrentAnchorPoint() const;
370
371   /**
372    * Sets the position of the Actor.
373    * The coordinates are relative to the Actor's parent.
374    * The Actor's z position will be set to 0.0f.
375    * @param [in] x The new x position
376    * @param [in] y The new y position
377    */
378   void SetPosition(float x, float y);
379
380   /**
381    * Sets the position of the Actor.
382    * The coordinates are relative to the Actor's parent.
383    * @param [in] x The new x position
384    * @param [in] y The new y position
385    * @param [in] z The new z position
386    */
387   void SetPosition(float x, float y, float z);
388
389   /**
390    * Sets the position of the Actor.
391    * The coordinates are relative to the Actor's parent.
392    * @param [in] position The new position.
393    */
394   void SetPosition(const Vector3& position);
395
396   /**
397    * Set the position of an actor along the X-axis.
398    * @param [in] x The new x position
399    */
400   void SetX(float x);
401
402   /**
403    * Set the position of an actor along the Y-axis.
404    * @param [in] y The new y position.
405    */
406   void SetY(float y);
407
408   /**
409    * Set the position of an actor along the Z-axis.
410    * @param [in] z The new z position
411    */
412   void SetZ(float z);
413
414   /**
415    * Move an actor relative to its existing position.
416    * @param[in] distance The actor will move by this distance.
417    */
418   void MoveBy(const Vector3& distance);
419
420   /**
421    * Retrieve the position of the Actor.
422    * The coordinates are relative to the Actor's parent.
423    * @return the Actor's position.
424    */
425   const Vector3& GetCurrentPosition() const;
426
427   /**
428    * @copydoc Dali::Actor::GetCurrentWorldPosition()
429    */
430   const Vector3& GetCurrentWorldPosition() const;
431
432   /**
433    * @copydoc Dali::Actor::SetPositionInheritanceMode()
434    */
435   void SetPositionInheritanceMode( PositionInheritanceMode mode );
436
437   /**
438    * @copydoc Dali::Actor::GetPositionInheritanceMode()
439    */
440   PositionInheritanceMode GetPositionInheritanceMode() const;
441
442   /**
443    * Sets the rotation of the Actor.
444    * @param [in] angleRadians The new rotation angle in radians.
445    * @param [in] axis The new axis of rotation.
446    */
447   void SetRotation(const Radian& angleRadians, const Vector3& axis);
448
449   /**
450    * Sets the rotation of the Actor.
451    * @param [in] rotation The new rotation.
452    */
453   void SetRotation(const Quaternion& rotation);
454
455   /**
456    * Rotate an actor around its existing rotation axis.
457    * @param[in] angleRadians The angle to the rotation to combine with the existing rotation.
458    * @param[in] axis The axis of the rotation to combine with the existing rotation.
459    */
460   void RotateBy(const Radian& angleRadians, const Vector3& axis);
461
462   /**
463    * Apply a relative rotation to an actor.
464    * @param[in] relativeRotation The rotation to combine with the actors existing rotation.
465    */
466   void RotateBy(const Quaternion& relativeRotation);
467
468   /**
469    * Retreive the Actor's rotation.
470    * @return the rotation.
471    */
472   const Quaternion& GetCurrentRotation() const;
473
474   /**
475    * Set whether a child actor inherits it's parent's orientation. Default is to inherit.
476    * Switching this off means that using SetRotation() sets the actor's world orientation.
477    * @param[in] inherit - true if the actor should inherit orientation, false otherwise.
478    */
479   void SetInheritRotation(bool inherit);
480
481   /**
482    * Returns whether the actor inherit's it's parent's orientation.
483    * @return true if the actor inherit's it's parent orientation, false if it uses world orientation.
484    */
485   bool IsRotationInherited() const;
486
487   /**
488    * @copydoc Dali::Actor::GetCurrentWorldRotation()
489    */
490   const Quaternion& GetCurrentWorldRotation() const;
491
492   /**
493    * Sets a scale factor applied to an actor.
494    * @param [in] scale The scale factor applied on all axes.
495    */
496   void SetScale(float scale);
497
498   /**
499    * Sets a scale factor applied to an actor.
500    * @param [in] scaleX The scale factor applied along the x-axis.
501    * @param [in] scaleY The scale factor applied along the y-axis.
502    * @param [in] scaleZ The scale factor applied along the z-axis.
503    */
504   void SetScale(float scaleX, float scaleY, float scaleZ);
505
506   /**
507    * Sets a scale factor applied to an actor.
508    * @param [in] scale A vector representing the scale factor for each axis.
509    */
510   void SetScale(const Vector3& scale);
511
512   /**
513    * Set the x component of the scale factor.
514    * @param [in] x The new x value.
515    */
516   void SetScaleX( float x );
517
518   /**
519    * Set the y component of the scale factor.
520    * @param [in] y The new y value.
521    */
522   void SetScaleY( float y );
523
524   /**
525    * Set the z component of the scale factor.
526    * @param [in] z The new z value.
527    */
528   void SetScaleZ( float z );
529
530   /**
531    * Apply a relative scale to an actor.
532    * @param[in] relativeScale The scale to combine with the actors existing scale.
533    */
534   void ScaleBy(const Vector3& relativeScale);
535
536   /**
537    * Retrieve the scale factor applied to an actor.
538    * @return A vector representing the scale factor for each axis.
539    */
540   const Vector3& GetCurrentScale() const;
541
542   /**
543    * @copydoc Dali::Actor::GetCurrentWorldScale()
544    */
545   const Vector3& GetCurrentWorldScale() const;
546
547   /**
548    * @copydoc Dali::Actor::SetInheritScale()
549    */
550   void SetInheritScale( bool inherit );
551
552   /**
553    * @copydoc Dali::Actor::IsScaleInherited()
554    */
555   bool IsScaleInherited() const;
556
557   /**
558    * @copydoc Dali::Actor::GetCurrentWorldMatrix()
559    */
560   Matrix GetCurrentWorldMatrix() const;
561
562   // Visibility
563
564   /**
565    * Sets the visibility flag of an actor.
566    * @param [in] visible The new visibility flag.
567    */
568   void SetVisible(bool visible);
569
570   /**
571    * Retrieve the visibility flag of an actor.
572    * @return The visibility flag.
573    */
574   bool IsVisible() const;
575
576   /**
577    * Sets the opacity of an actor.
578    * @param [in] opacity The new opacity.
579    */
580   void SetOpacity(float opacity);
581
582   /**
583    * Apply a relative opacity change to an actor.
584    * @param[in] relativeOpacity The opacity to combine with the actors existing opacity.
585    */
586   void OpacityBy(float relativeOpacity);
587
588   /**
589    * Retrieve the actor's opacity.
590    * @return The actor's opacity.
591    */
592   float GetCurrentOpacity() const;
593
594   /**
595    * Sets whether an actor should emit touch signals; see SignalTouch().
596    * An actor is sensitive by default, which means that as soon as an application connects to the SignalTouch(),
597    * the touch event signal will be emitted.
598    *
599    * If the application wishes to temporarily disable the touch event signal emission, then they can do so by calling:
600    * @code
601    * actor.SetSensitive(false);
602    * @endcode
603    *
604    * Then, to re-enable the touch event signal emission, the application should call:
605    * @code
606    * actor.SetSensitive(true);
607    * @endcode
608    *
609    * @see SignalTouch().
610    * @note If an actor's sensitivity is set to false, then it's children will not emit a touch event signal either.
611    * @param[in]  sensitive  true to enable emission of the touch event signals, false otherwise.
612    */
613   void SetSensitive(bool sensitive)
614   {
615     mSensitive = sensitive;
616   }
617
618   /**
619    * Query whether an actor emits touch event signals.
620    * @see SetSensitive(bool)
621    * @return true, if emission of touch event signals is enabled, false otherwise.
622    */
623   bool IsSensitive() const
624   {
625     return mSensitive;
626   }
627
628   /**
629    * @copydoc Dali::Actor::SetDrawMode
630    */
631   void SetDrawMode( DrawMode::Type drawMode );
632
633   /**
634    * @copydoc Dali::Actor::GetDrawMode
635    */
636   DrawMode::Type GetDrawMode() const;
637
638   /**
639    * @copydoc Dali::Actor::SetOverlay
640    */
641   void SetOverlay(bool enable);
642
643   /**
644    * @copydoc Dali::Actor::IsOverlay
645    */
646   bool IsOverlay() const;
647
648   /**
649    * Sets whether an actor transmits geometry scaling to it's children.
650    * The default value is for it not to transmit scaling.
651    * @param[in] transmitGeometryScaling True to transmit scaling.
652    */
653   void SetTransmitGeometryScaling(bool transmitGeometryScaling);
654
655   /**
656    * Get the TransmitGeometryScaling property for this actor.
657    * @return True if geometry scaling is applied to the inherited scale.
658    */
659   bool GetTransmitGeometryScaling() const;
660
661   /**
662    * Sets the initial volume of the actor. Used for scaling the
663    * actor appropriately as the actor is sized when transmitGeometryScaling
664    * is set to true.
665    *
666    * @param[in] volume the volume of the model and it's children
667    */
668   void SetInitialVolume(const Vector3& volume);
669
670   /**
671    * Sets the actor's color.  The final color of actor depends on its color mode.
672    * This final color is applied to the drawable elements of an actor.
673    * @param [in] color The new color.
674    */
675   void SetColor(const Vector4& color);
676
677   /**
678    * Set the red component of the color.
679    * @param [in] red The new red component.
680    */
681   void SetColorRed( float red );
682
683   /**
684    * Set the green component of the color.
685    * @param [in] green The new green component.
686    */
687   void SetColorGreen( float green );
688
689   /**
690    * Set the blue component of the scale factor.
691    * @param [in] blue The new blue value.
692    */
693   void SetColorBlue( float blue );
694
695   /**
696    * Apply a relative color change to an actor.
697    * @param[in] relativeColor The color to combine with the actors existing color.
698    */
699   void ColorBy(const Vector4& relativeColor);
700
701   /**
702    * Retrieve the actor's color.
703    * @return The color.
704    */
705   const Vector4& GetCurrentColor() const;
706
707   /**
708    * Sets the actor's color mode.
709    * Color mode specifies whether Actor uses its own color or inherits its parent color
710    * @param [in] colorMode to use.
711    */
712   void SetColorMode(ColorMode colorMode);
713
714   /**
715    * Returns the actor's color mode.
716    * @return currently used colorMode.
717    */
718   ColorMode GetColorMode() const;
719
720   /**
721    * @copydoc Dali::Actor::GetCurrentWorldColor()
722    */
723   const Vector4& GetCurrentWorldColor() const;
724
725 #ifdef DYNAMICS_SUPPORT
726
727   // Dynamics
728
729   /// @copydoc Dali::Actor::DisableDynamics
730   void DisableDynamics();
731
732   /// @copydoc Dali::Actor::EnableDynamics(Dali::DynamicsBodyConfig)
733   DynamicsBodyPtr  EnableDynamics(DynamicsBodyConfigPtr bodyConfig);
734
735   /// @copydoc Dali::Actor::GetDynamicsBody
736   DynamicsBodyPtr GetDynamicsBody() const;
737
738   /// @copydoc Dali::Actor::AddDynamicsJoint(Dali::Actor,const Vector3&)
739   DynamicsJointPtr AddDynamicsJoint( ActorPtr attachedActor, const Vector3& offset );
740
741   /// @copydoc Dali::Actor::AddDynamicsJoint(Dali::Actor,const Vector3&,const Vector3&)
742   DynamicsJointPtr AddDynamicsJoint( ActorPtr attachedActor, const Vector3& offsetA, const Vector3& offsetB );
743
744   /// @copydoc Dali::Actor::GetNumberOfJoints
745   const int GetNumberOfJoints() const;
746
747   /// @copydoc Dali::Actor::GetDynamicsJointByIndex
748   DynamicsJointPtr GetDynamicsJointByIndex( const int index ) const;
749
750   /// @copydoc Dali::Actor::GetDynamicsJoint
751   DynamicsJointPtr GetDynamicsJoint( ActorPtr attachedActor ) const;
752
753   /// @copydoc Dali::Actor::RemoveDynamicsJoint
754   void RemoveDynamicsJoint( DynamicsJointPtr joint );
755
756   /**
757    * Hold a reference to a DynamicsJoint
758    * @param[in] joint The joint
759    */
760   void ReferenceJoint( DynamicsJointPtr joint );
761
762   /**
763    * Release a reference to a DynamicsJoint
764    * @param[in] joint The joint
765    */
766   void ReleaseJoint( DynamicsJointPtr joint );
767
768   /**
769    * Set this actor to be the root actor in the dynamics simulation
770    * All children of the actor are added/removed from the simulation.
771    * @param[in] flag  When true sets this actor to be the simulation world root actor and
772    *                  if OnStage() all dynamics enabled child actors are added to the simulation,
773    *                  when false stops this actor being the simulation root and if OnStage() all
774    *                  dynamics enabled child actors are removed from the simulation.
775    */
776   void SetDynamicsRoot(bool flag);
777
778 private:
779   /**
780    * Check if this actor is the root actor in the dynamics simulation
781    * @return true if this is the dynamics root actor.
782    */
783   bool IsDynamicsRoot() const;
784
785   /**
786    * Add actor to the dynamics simulation
787    * Invoked when the actor is staged, or it's parent becomes the simulation root
788    */
789   void ConnectDynamics();
790
791   /**
792    * Remove actor from the dynamics simulation
793    * Invoked when the actor is unstaged, or it's parent stops being the the simulation root
794    */
795   void DisconnectDynamics();
796
797   /**
798    * An actor in a DynamicsJoint relationship has been staged
799    * @param[in] actor The actor passed into AddDynamicsJoint()
800    */
801   void AttachedActorOnStage( Dali::Actor actor );
802
803   /**
804    * An actor in a DynamicsJoint relationship has been unstaged
805    * @param[in] actor The actor passed into AddDynamicsJoint()
806    */
807   void AttachedActorOffStage( Dali::Actor actor );
808
809 #endif // DYNAMICS_SUPPORT
810
811 public:
812   /**
813    * Converts screen coordinates into the actor's coordinate system.
814    * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
815    * @param[out] localX On return, the X-coordinate relative to the actor.
816    * @param[out] localY On return, the Y-coordinate relative to the actor.
817    * @param[in] screenX The screen X-coordinate.
818    * @param[in] screenY The screen Y-coordinate.
819    * @return True if the conversion succeeded.
820    */
821   bool ScreenToLocal(float& localX, float& localY, float screenX, float screenY) const;
822
823   /**
824    * Converts screen coordinates into the actor's coordinate system.
825    * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
826    * @param[in] renderTask The render-task used to display the actor.
827    * @param[out] localX On return, the X-coordinate relative to the actor.
828    * @param[out] localY On return, the Y-coordinate relative to the actor.
829    * @param[in] screenX The screen X-coordinate.
830    * @param[in] screenY The screen Y-coordinate.
831    * @return True if the conversion succeeded.
832    */
833   bool ScreenToLocal(RenderTask& renderTask, float& localX, float& localY, float screenX, float screenY) const;
834
835   /**
836    * Converts from the actor's coordinate system to screen coordinates.
837    * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
838    * @param[in] viewMatrix The view-matrix
839    * @param[in] projectionMatrix The projection-matrix
840    * @param[in] viewport The view-port
841    * @param[out] localX On return, the X-coordinate relative to the actor.
842    * @param[out] localY On return, the Y-coordinate relative to the actor.
843    * @param[in] screenX The screen X-coordinate.
844    * @param[in] screenY The screen Y-coordinate.
845    * @return True if the conversion succeeded.
846    */
847   bool ScreenToLocal( const Matrix& viewMatrix,
848                       const Matrix& projectionMatrix,
849                       const Viewport& viewport,
850                       float& localX,
851                       float& localY,
852                       float screenX,
853                       float screenY ) const;
854
855   /**
856    * Performs a ray-sphere test with the given pick-ray and the actor's bounding sphere.
857    * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
858    * @param[in] rayOrigin The ray origin in the world's reference system.
859    * @param[in] rayDir The ray director vector in the world's reference system.
860    * @return True if the ray intersects the actor's bounding sphere.
861    */
862   bool RaySphereTest( const Vector4& rayOrigin, const Vector4& rayDir ) const;
863
864   /**
865    * Performs a ray-actor test with the given pick-ray and the actor's geometry.
866    * @note The actor coordinates are relative to the top-left (0.0, 0.0, 0.5)
867    * @param[in] rayOrigin The ray origin in the world's reference system.
868    * @param[in] rayDir The ray director vector in the world's reference system.
869    * @param[out] hitPointLocal The hit point in the Actor's local reference system.
870    * @param[out] distance The distance from the hit point to the camera.
871    * @return True if the ray intersects the actor's geometry.
872    */
873   bool RayActorTest( const Vector4& rayOrigin, const Vector4& rayDir, Vector4& hitPointLocal, float& distance ) const;
874
875   /**
876    * Sets whether the actor should receive a notification when touch motion events leave
877    * the boundary of the actor.
878    *
879    * @note By default, this is set to false as most actors do not require this.
880    * @note Need to connect to the SignalTouch to actually receive this event.
881    *
882    * @param[in]  required  Should be set to true if a Leave event is required
883    */
884   void SetLeaveRequired(bool required);
885
886   /**
887    * This returns whether the actor requires touch events whenever touch motion events leave
888    * the boundary of the actor.
889    * @return true if a Leave event is required, false otherwise.
890    */
891   bool GetLeaveRequired() const;
892
893   /**
894    * @copydoc Dali::Actor::SetKeyboardFocusable()
895    */
896   void SetKeyboardFocusable( bool focusable );
897
898   /**
899    * @copydoc Dali::Actor::IsKeyboardFocusable()
900    */
901   bool IsKeyboardFocusable() const;
902
903   /**
904    * Query whether the application or derived actor type requires touch events.
905    * @return True if touch events are required.
906    */
907   bool GetTouchRequired() const;
908
909   /**
910    * Query whether the application or derived actor type requires mouse wheel events.
911    * @return True if mouse wheel events are required.
912    */
913   bool GetMouseWheelEventRequired() const;
914
915   /**
916    * Query whether the actor is actually hittable.  This method checks whether the actor is
917    * sensitive, has the visibility flag set to true and is not fully transparent.
918    * @return true, if it can be hit, false otherwise.
919    */
920   bool IsHittable() const;
921
922   // Gestures
923
924   /**
925    * Retrieve the gesture data associated with this actor. The first call to this method will
926    * allocate space for the ActorGestureData so this should only be called if an actor really does
927    * require gestures.
928    * @return Reference to the ActorGestureData for this actor.
929    * @note Once the gesture-data is created for an actor it is likely that gestures are required
930    * throughout the actor's lifetime so it will only be deleted when the actor is destroyed.
931    */
932   ActorGestureData& GetGestureData();
933
934   /**
935    * Queries whether the actor requires the gesture type.
936    * @param[in] type The gesture type.
937    */
938   bool IsGestureRequred( Gesture::Type type ) const;
939
940   // Signals
941
942   /**
943    * Used by the EventProcessor to emit touch event signals.
944    * @param[in] event The touch event.
945    * @return True if the event was consumed.
946    */
947   bool EmitTouchEventSignal(const TouchEvent& event);
948
949   /**
950    * Used by the EventProcessor to emit mouse wheel event signals.
951    * @param[in] event The mouse wheel event.
952    * @return True if the event was consumed.
953    */
954   bool EmitMouseWheelEventSignal(const MouseWheelEvent& event);
955
956   /**
957    * @copydoc Dali::Actor::TouchedSignal()
958    */
959   Dali::Actor::TouchSignalV2& TouchedSignal();
960
961   /**
962    * @copydoc Dali::Actor::MouseWheelEventSignal()
963    */
964   Dali::Actor::MouseWheelEventSignalV2& MouseWheelEventSignal();
965
966   /**
967    * @copydoc Dali::Actor::SetSizeSignal()
968    */
969   Dali::Actor::SetSizeSignalV2& SetSizeSignal();
970
971   /**
972    * @copydoc Dali::Actor::OnStageSignal()
973    */
974   Dali::Actor::OnStageSignalV2& OnStageSignal();
975
976   /**
977    * @copydoc Dali::Actor::OffStageSignal()
978    */
979   Dali::Actor::OffStageSignalV2& OffStageSignal();
980
981   /**
982    * Connects a callback function with the object's signals.
983    * @param[in] object The object providing the signal.
984    * @param[in] tracker Used to disconnect the signal.
985    * @param[in] signalName The signal to connect to.
986    * @param[in] functor A newly allocated FunctorDelegate.
987    * @return True if the signal was connected.
988    * @post If a signal was connected, ownership of functor was passed to CallbackBase. Otherwise the caller is responsible for deleting the unused functor.
989    */
990   static bool DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor );
991
992   /**
993    * Performs actions as requested using the action name.
994    * @param[in] object The object on which to perform the action.
995    * @param[in] actionName The action to perform.
996    * @param[in] attributes The attributes with which to perfrom this action.
997    * @return true if the action was done.
998    */
999   static bool DoAction(BaseObject* object, const std::string& actionName, const std::vector<Property::Value>& attributes);
1000
1001 public:  // For Animation
1002
1003   /**
1004    * For use in derived classes.
1005    * This should only be called by Animation, when the actor is resized using Animation::Resize().
1006    */
1007   virtual void OnSizeAnimation(Animation& animation, const Vector3& targetSize) {}
1008
1009 protected:
1010
1011   enum DerivedType
1012   {
1013     BASIC,
1014     RENDERABLE,
1015     LAYER,
1016     ROOT_LAYER
1017   };
1018
1019   /**
1020    * Protected Constructor.  See Actor::New().
1021    * The second-phase construction Initialize() member should be called immediately after this.
1022    * @param[in] derivedType The derived type of actor (if any).
1023    */
1024   Actor( DerivedType derivedType );
1025
1026   /**
1027    * Second-phase constructor. Must be called immediately after creating a new Actor;
1028    */
1029   void Initialize(void);
1030
1031   /**
1032    * A reference counted object may only be deleted by calling Unreference()
1033    */
1034   virtual ~Actor();
1035
1036   /**
1037    * Called on a child during Add() when the parent actor is connected to the Stage.
1038    * @param[in] stage The stage.
1039    * @param[in] index If set, it is only used for positioning the actor within the parent's child list.
1040    */
1041   void ConnectToStage(Stage& stage, int index = -1);
1042
1043   /**
1044    * Helper for ConnectToStage, to recursively connect a tree of actors.
1045    * This is atomic i.e. not interrupted by user callbacks.
1046    * @param[in] stage The stage.
1047    * @param[in] index If set, it is only used for positioning the actor within the parent's child list.
1048    * @param[out] connectionList On return, the list of connected actors which require notification.
1049    */
1050   void RecursiveConnectToStage( Stage& stage, ActorContainer& connectionList, int index = -1 );
1051
1052   /**
1053    * Connect the Node associated with this Actor to the scene-graph.
1054    * @param[in] index If set, it is only used for positioning the actor within the parent's child list.
1055    */
1056   void ConnectToSceneGraph(int index = -1);
1057
1058   /**
1059    * Helper for ConnectToStage, to notify a connected actor through the public API.
1060    */
1061   void NotifyStageConnection();
1062
1063   /**
1064    * Called on a child during Remove() when the actor was previously on the Stage.
1065    */
1066   void DisconnectFromStage();
1067
1068   /**
1069    * Helper for DisconnectFromStage, to recursively disconnect a tree of actors.
1070    * This is atomic i.e. not interrupted by user callbacks.
1071    * @param[out] disconnectionList On return, the list of disconnected actors which require notification.
1072    */
1073   void RecursiveDisconnectFromStage( ActorContainer& disconnectionList );
1074
1075   /**
1076    * Disconnect the Node associated with this Actor from the scene-graph.
1077    */
1078   void DisconnectFromSceneGraph();
1079
1080   /**
1081    * Helper for DisconnectFromStage, to notify a disconnected actor through the public API.
1082    */
1083   void NotifyStageDisconnection();
1084
1085   /**
1086    * When the Actor is OnStage, checks whether the corresponding Node is connected to the scene graph.
1087    * @return True if the Actor is OnStage & has a Node connected to the scene graph.
1088    */
1089   bool IsNodeConnected() const;
1090
1091 public: // Default property extensions from ProxyObject
1092
1093   /**
1094    * @copydoc Dali::Internal::ProxyObject::IsSceneObjectRemovable()
1095    */
1096   virtual bool IsSceneObjectRemovable() const;
1097
1098   /**
1099    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyCount()
1100    */
1101   virtual unsigned int GetDefaultPropertyCount() const;
1102
1103   /**
1104    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndices()
1105    */
1106   virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
1107
1108   /**
1109    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyName()
1110    */
1111   virtual const std::string& GetDefaultPropertyName(Property::Index index) const;
1112
1113   /**
1114    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyIndex()
1115    */
1116   virtual Property::Index GetDefaultPropertyIndex(const std::string& name) const;
1117
1118   /**
1119    * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyWritable()
1120    */
1121   virtual bool IsDefaultPropertyWritable(Property::Index index) const;
1122
1123   /**
1124    * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAnimatable()
1125    */
1126   virtual bool IsDefaultPropertyAnimatable(Property::Index index) const;
1127
1128   /**
1129    * @copydoc Dali::Internal::ProxyObject::IsDefaultPropertyAConstraintInput()
1130    */
1131   virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
1132
1133   /**
1134    * @copydoc Dali::Internal::ProxyObject::GetDefaultPropertyType()
1135    */
1136   virtual Property::Type GetDefaultPropertyType(Property::Index index) const;
1137
1138   /**
1139    * @copydoc Dali::Internal::ProxyObject::SetDefaultProperty()
1140    */
1141   virtual void SetDefaultProperty(Property::Index index, const Property::Value& propertyValue);
1142
1143   /**
1144    * @copydoc Dali::Internal::ProxyObject::SetCustomProperty()
1145    */
1146   virtual void SetCustomProperty( Property::Index index, const CustomProperty& entry, const Property::Value& value );
1147
1148   /**
1149    * @copydoc Dali::Internal::ProxyObject::GetDefaultProperty()
1150    */
1151   virtual Property::Value GetDefaultProperty( Property::Index index ) const;
1152
1153   /**
1154    * @copydoc Dali::Internal::ProxyObject::InstallSceneObjectProperty()
1155    */
1156   virtual void InstallSceneObjectProperty( SceneGraph::PropertyBase& newProperty, const std::string& name, unsigned int index );
1157
1158   /**
1159    * @copydoc Dali::Internal::ProxyObject::GetSceneObject()
1160    */
1161   virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
1162
1163   /**
1164    * @copydoc Dali::Internal::ProxyObject::GetSceneObjectAnimatableProperty()
1165    */
1166   virtual const SceneGraph::PropertyBase* GetSceneObjectAnimatableProperty( Property::Index index ) const;
1167
1168   /**
1169    * @copydoc Dali::Internal::ProxyObject::GetSceneObjectInputProperty()
1170    */
1171   virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
1172
1173   /**
1174    * @copydoc Dali::Internal::ProxyObject::GetPropertyComponentIndex()
1175    */
1176   virtual int GetPropertyComponentIndex( Property::Index index ) const;
1177
1178 private:
1179
1180   // Undefined
1181   Actor();
1182
1183   // Undefined
1184   Actor(const Actor&);
1185
1186   // Undefined
1187   Actor& operator=(const Actor& rhs);
1188
1189   /**
1190    * Set the actors parent.
1191    * @param[in] parent The new parent.
1192    * @param[in] index If set, it is only used for positioning the actor within the parent's child list.
1193    */
1194   void SetParent(Actor* parent, int index = -1);
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   ActorGestureData*       mGestureData; /// Optional Gesture data. Only created when actor requires gestures
1308
1309   ActorAttachmentPtr      mAttachment;   ///< Optional referenced attachment
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__