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