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