Dali 3D User Interface Engine
actor-impl.h
Go to the documentation of this file.
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
38 
39 namespace Dali
40 {
41 
42 struct KeyEvent;
43 struct TouchEvent;
44 struct HoverEvent;
45 struct WheelEvent;
46 
47 namespace Internal
48 {
49 
50 class Actor;
51 class ActorGestureData;
52 class Animation;
53 class RenderTask;
54 class Renderer;
55 
56 typedef std::vector< ActorPtr > ActorContainer;
57 typedef ActorContainer::iterator ActorIter;
58 typedef ActorContainer::const_iterator ActorConstIter;
59 
60 typedef std::vector< RendererPtr > RendererContainer;
61 typedef RendererContainer::iterator RendererIter;
62 
73 class Actor : public Object
74 {
75 public:
76 
81  {
88  ActorDimensionPair( Actor* newActor, Dimension::Type newDimension )
89  : actor( newActor ),
90  dimension( newDimension )
91  {
92  }
93 
100  bool operator== ( const ActorDimensionPair& rhs )
101  {
102  return ( actor == rhs.actor ) && ( dimension == rhs.dimension );
103  }
104 
107  };
108 
109  typedef std::vector< ActorDimensionPair > ActorDimensionStack;
110 
111 public:
112 
117  static ActorPtr New();
118 
123  const std::string& GetName() const;
124 
129  void SetName( const std::string& name );
130 
134  unsigned int GetId() const;
135 
136  // Attachments
137 
143  void Attach( ActorAttachment& attachment );
144 
150 
151  // Containment
152 
157  bool IsRoot() const
158  {
159  return mIsRoot;
160  }
161 
165  bool OnStage() const;
166 
171  bool IsRenderable() const
172  {
173  // inlined as this is called a lot in hit testing
174  return mRenderers && !mRenderers->empty();
175  }
176 
181  bool IsLayer() const
182  {
183  // inlined as this is called a lot in hit testing
184  return mIsLayer;
185  }
186 
192 
200  void Add( Actor& child );
201 
207  void Remove( Actor& child );
208 
212  void Unparent();
213 
218  unsigned int GetChildCount() const;
219 
223  ActorPtr GetChildAt( unsigned int index ) const;
224 
231  {
232  return *mChildren;
233  }
234 
238  ActorPtr FindChildByName( const std::string& actorName );
239 
243  ActorPtr FindChildById( const unsigned int id );
244 
249  Actor* GetParent() const
250  {
251  return mParent;
252  }
253 
261  void SetSize( float width, float height );
262 
271  void SetSize( float width, float height, float depth );
272 
279  void SetSize( const Vector2& size );
280 
286  void SetSizeInternal( const Vector2& size );
287 
294  void SetSize( const Vector3& size );
295 
301  void SetSizeInternal( const Vector3& size );
302 
307  void SetWidth( float width );
308 
313  void SetHeight( float height );
314 
319  void SetDepth( float depth );
320 
326  const Vector3& GetTargetSize() const;
327 
333  const Vector3& GetCurrentSize() const;
334 
340  virtual Vector3 GetNaturalSize() const;
341 
350  void SetParentOrigin( const Vector3& origin );
351 
356  void SetParentOriginX( float x );
357 
362  void SetParentOriginY( float y );
363 
368  void SetParentOriginZ( float z );
369 
374  const Vector3& GetCurrentParentOrigin() const;
375 
384  void SetAnchorPoint( const Vector3& anchorPoint );
385 
390  void SetAnchorPointX( float x );
391 
396  void SetAnchorPointY( float y );
397 
402  void SetAnchorPointZ( float z );
403 
408  const Vector3& GetCurrentAnchorPoint() const;
409 
417  void SetPosition( float x, float y );
418 
426  void SetPosition( float x, float y, float z );
427 
433  void SetPosition( const Vector3& position );
434 
439  void SetX( float x );
440 
445  void SetY( float y );
446 
451  void SetZ( float z );
452 
457  void TranslateBy( const Vector3& distance );
458 
464  const Vector3& GetCurrentPosition() const;
465 
471  const Vector3& GetTargetPosition() const;
472 
476  const Vector3& GetCurrentWorldPosition() const;
477 
482 
487 
493  void SetOrientation( const Radian& angleRadians, const Vector3& axis );
494 
499  void SetOrientation( const Quaternion& orientation );
500 
506  void RotateBy( const Radian& angleRadians, const Vector3& axis );
507 
512  void RotateBy( const Quaternion& relativeRotation );
513 
518  const Quaternion& GetCurrentOrientation() const;
519 
525  void SetInheritOrientation( bool inherit );
526 
531  bool IsOrientationInherited() const;
532 
538  void SetSizeModeFactor( const Vector3& factor );
539 
545  const Vector3& GetSizeModeFactor() const;
546 
550  const Quaternion& GetCurrentWorldOrientation() const;
551 
556  void SetScale( float scale );
557 
564  void SetScale( float scaleX, float scaleY, float scaleZ );
565 
570  void SetScale( const Vector3& scale );
571 
576  void SetScaleX( float x );
577 
582  void SetScaleY( float y );
583 
588  void SetScaleZ( float z );
589 
594  void ScaleBy( const Vector3& relativeScale );
595 
600  const Vector3& GetCurrentScale() const;
601 
605  const Vector3& GetCurrentWorldScale() const;
606 
610  void SetInheritScale( bool inherit );
611 
615  bool IsScaleInherited() const;
616 
621 
622  // Visibility
623 
628  void SetVisible( bool visible );
629 
634  bool IsVisible() const;
635 
640  void SetOpacity( float opacity );
641 
646  float GetCurrentOpacity() const;
647 
668  void SetSensitive( bool sensitive )
669  {
670  mSensitive = sensitive;
671  }
672 
678  bool IsSensitive() const
679  {
680  return mSensitive;
681  }
682 
686  void SetDrawMode( DrawMode::Type drawMode );
687 
691  DrawMode::Type GetDrawMode() const;
692 
696  void SetOverlay( bool enable );
697 
701  bool IsOverlay() const;
702 
708  void SetColor( const Vector4& color );
709 
714  void SetColorRed( float red );
715 
720  void SetColorGreen( float green );
721 
726  void SetColorBlue( float blue );
727 
732  const Vector4& GetCurrentColor() const;
733 
739  void SetColorMode( ColorMode colorMode );
740 
745  ColorMode GetColorMode() const;
746 
750  const Vector4& GetCurrentWorldColor() const;
751 
755  int GetHierarchyDepth() const
756  {
757  if( mIsOnStage )
758  {
759  return static_cast<int>(mDepth);
760  }
761 
762  return -1;
763  }
764 
765 public:
766 
767  // Size negotiation virtual functions
768 
785  virtual void OnRelayout( const Vector2& size, RelayoutContainer& container )
786  {
787  }
788 
795  virtual void OnSetResizePolicy( ResizePolicy::Type policy, Dimension::Type dimension ) {}
796 
803  virtual void OnCalculateRelayoutSize( Dimension::Type dimension );
804 
812  virtual void OnLayoutNegotiated( float size, Dimension::Type dimension );
813 
821 
831 
839  virtual float CalculateChildSize( const Dali::Actor& child, Dimension::Type dimension );
840 
849  virtual float GetHeightForWidth( float width );
850 
859  virtual float GetWidthForHeight( float height );
860 
861 public:
862 
863  // Size negotiation
864 
877  void NegotiateSize( const Vector2& size, RelayoutContainer& container );
878 
883 
888 
893 
898 
902  void SetDimensionDependency( Dimension::Type dimension, Dimension::Type dependency );
903 
908 
914  void SetRelayoutEnabled( bool relayoutEnabled );
915 
921  bool IsRelayoutEnabled() const;
922 
929  void SetLayoutDirty( bool dirty, Dimension::Type dimension = Dimension::ALL_DIMENSIONS );
930 
937  bool IsLayoutDirty( Dimension::Type dimension = Dimension::ALL_DIMENSIONS ) const;
938 
945 
952 
967 
975 
983  bool RelayoutDependentOnDimension( Dimension::Type dimension, Dimension::Type dependentDimension );
984 
990  void NegotiateDimensions( const Vector2& allocatedSize );
991 
1005  void NegotiateDimension( Dimension::Type dimension, const Vector2& allocatedSize, ActorDimensionStack& recursionStack );
1006 
1014  float CalculateSize( Dimension::Type dimension, const Vector2& maximumSize );
1015 
1023  float ClampDimension( float size, Dimension::Type dimension );
1024 
1031  float NegotiateFromParent( Dimension::Type dimension );
1032 
1039  float NegotiateFromParentFit( Dimension::Type dimension );
1040 
1047  float NegotiateFromParentFlood( Dimension::Type dimension );
1048 
1055  float NegotiateFromChildren( Dimension::Type dimension );
1056 
1063  void SetNegotiatedDimension( float negotiatedDimension, Dimension::Type dimension = Dimension::ALL_DIMENSIONS );
1064 
1071  float GetNegotiatedDimension( Dimension::Type dimension ) const;
1072 
1079  void SetPadding( const Vector2& padding, Dimension::Type dimension );
1080 
1087  Vector2 GetPadding( Dimension::Type dimension ) const;
1088 
1095  float GetSize( Dimension::Type dimension ) const;
1096 
1103  float GetNaturalSize( Dimension::Type dimension ) const;
1104 
1113  float GetRelayoutSize( Dimension::Type dimension ) const;
1114 
1121  float GetLatestSize( Dimension::Type dimension ) const;
1122 
1128  void SetNegotiatedSize( RelayoutContainer& container );
1129 
1136  void SetLayoutNegotiated( bool negotiated, Dimension::Type dimension = Dimension::ALL_DIMENSIONS );
1137 
1145 
1151  float GetHeightForWidthBase( float width );
1152 
1158  float GetWidthForHeightBase( float height );
1159 
1167  float CalculateChildSizeBase( const Dali::Actor& child, Dimension::Type dimension );
1168 
1174  void SetPreferredSize( const Vector2& size );
1175 
1181  Vector2 GetPreferredSize() const;
1182 
1186  void SetMinimumSize( float size, Dimension::Type dimension = Dimension::ALL_DIMENSIONS );
1187 
1191  float GetMinimumSize( Dimension::Type dimension ) const;
1192 
1196  void SetMaximumSize( float size, Dimension::Type dimension = Dimension::ALL_DIMENSIONS );
1197 
1201  float GetMaximumSize( Dimension::Type dimension ) const;
1202 
1206  unsigned int AddRenderer( Renderer& renderer );
1207 
1211  unsigned int GetRendererCount() const;
1212 
1216  RendererPtr GetRendererAt( unsigned int index );
1217 
1221  void RemoveRenderer( Renderer& renderer );
1222 
1226  void RemoveRenderer( unsigned int index );
1227 
1228 public:
1229 
1239  bool ScreenToLocal( float& localX, float& localY, float screenX, float screenY ) const;
1240 
1251  bool ScreenToLocal( const RenderTask& renderTask, float& localX, float& localY, float screenX, float screenY ) const;
1252 
1265  bool ScreenToLocal( const Matrix& viewMatrix,
1266  const Matrix& projectionMatrix,
1267  const Viewport& viewport,
1268  float& localX,
1269  float& localY,
1270  float screenX,
1271  float screenY ) const;
1272 
1280  bool RaySphereTest( const Vector4& rayOrigin, const Vector4& rayDir ) const;
1281 
1291  bool RayActorTest( const Vector4& rayOrigin,
1292  const Vector4& rayDir,
1293  Vector4& hitPointLocal,
1294  float& distance ) const;
1295 
1305  void SetLeaveRequired( bool required );
1306 
1312  bool GetLeaveRequired() const;
1313 
1317  void SetKeyboardFocusable( bool focusable );
1318 
1322  bool IsKeyboardFocusable() const;
1323 
1328  bool GetTouchRequired() const;
1329 
1334  bool GetHoverRequired() const;
1335 
1340  bool GetWheelEventRequired() const;
1341 
1347  bool IsHittable() const;
1348 
1349  // Gestures
1350 
1360 
1365  bool IsGestureRequred( Gesture::Type type ) const;
1366 
1367  // Signals
1368 
1374  bool EmitTouchEventSignal( const TouchEvent& event );
1375 
1381  bool EmitHoverEventSignal( const HoverEvent& event );
1382 
1388  bool EmitWheelEventSignal( const WheelEvent& event );
1389 
1394 
1399 
1404 
1409 
1414 
1419 
1429  static bool DoConnectSignal( BaseObject* object,
1430  ConnectionTrackerInterface* tracker,
1431  const std::string& signalName,
1432  FunctorDelegate* functor );
1433 
1441  static bool DoAction( BaseObject* object,
1442  const std::string& actionName,
1443  const Property::Map& attributes );
1444 
1445 public:
1446  // For Animation
1447 
1454  void NotifySizeAnimation( Animation& animation, const Vector3& targetSize );
1455 
1463  void NotifySizeAnimation( Animation& animation, float targetSize, Property::Index property );
1464 
1469  virtual void OnSizeAnimation( Animation& animation, const Vector3& targetSize )
1470  {
1471  }
1472 
1479  void NotifyPositionAnimation( Animation& animation, const Vector3& targetPosition );
1480 
1488  void NotifyPositionAnimation( Animation& animation, float targetPosition, Property::Index property );
1489 
1490 protected:
1491 
1493  {
1495  };
1496 
1502  Actor( DerivedType derivedType );
1503 
1507  void Initialize( void );
1508 
1512  virtual ~Actor();
1513 
1518  void ConnectToStage( unsigned int parentDepth );
1519 
1526  void RecursiveConnectToStage( ActorContainer& connectionList, unsigned int depth );
1527 
1531  void ConnectToSceneGraph();
1532 
1536  void NotifyStageConnection();
1537 
1541  void DisconnectFromStage();
1542 
1548  void RecursiveDisconnectFromStage( ActorContainer& disconnectionList );
1549 
1553  void DisconnectFromSceneGraph();
1554 
1558  void NotifyStageDisconnection();
1559 
1564  bool IsNodeConnected() const;
1565 
1566 public:
1567 
1568  // Default property extensions from Object
1569 
1573  virtual unsigned int GetDefaultPropertyCount() const;
1574 
1578  virtual void GetDefaultPropertyIndices( Property::IndexContainer& indices ) const;
1579 
1583  virtual const char* GetDefaultPropertyName( Property::Index index ) const;
1584 
1588  virtual Property::Index GetDefaultPropertyIndex( const std::string& name ) const;
1589 
1593  virtual bool IsDefaultPropertyWritable( Property::Index index ) const;
1594 
1598  virtual bool IsDefaultPropertyAnimatable( Property::Index index ) const;
1599 
1603  virtual bool IsDefaultPropertyAConstraintInput( Property::Index index ) const;
1604 
1608  virtual Property::Type GetDefaultPropertyType( Property::Index index ) const;
1609 
1613  virtual void SetDefaultProperty( Property::Index index, const Property::Value& propertyValue );
1614 
1618  virtual void SetSceneGraphProperty( Property::Index index, const PropertyMetadata& entry, const Property::Value& value );
1619 
1623  virtual Property::Value GetDefaultProperty( Property::Index index ) const;
1624 
1628  virtual const SceneGraph::PropertyOwner* GetPropertyOwner() const;
1629 
1633  virtual const SceneGraph::PropertyOwner* GetSceneObject() const;
1634 
1639 
1643  virtual const PropertyInputImpl* GetSceneObjectInputProperty( Property::Index index ) const;
1644 
1648  virtual int GetPropertyComponentIndex( Property::Index index ) const;
1649 
1650 private:
1651 
1652  // Undefined
1653  Actor();
1654 
1655  // Undefined
1656  Actor( const Actor& );
1657 
1658  // Undefined
1659  Actor& operator=( const Actor& rhs );
1660 
1665  void SetParent( Actor* parent );
1666 
1672  virtual SceneGraph::Node* CreateNode() const;
1673 
1677  virtual void OnInitialize()
1678  {
1679  }
1680 
1687  {
1688  }
1689 
1696  {
1697  }
1698 
1703  virtual void OnStageConnectionExternal( int depth )
1704  {
1705  }
1706 
1712  {
1713  }
1714 
1719  virtual void OnChildAdd( Actor& child )
1720  {
1721  }
1722 
1727  virtual void OnChildRemove( Actor& child )
1728  {
1729  }
1730 
1735  virtual void OnSizeSet( const Vector3& targetSize )
1736  {
1737  }
1738 
1745  virtual bool OnTouchEvent( const TouchEvent& event )
1746  {
1747  return false;
1748  }
1749 
1756  virtual bool OnHoverEvent( const HoverEvent& event )
1757  {
1758  return false;
1759  }
1760 
1767  virtual bool OnWheelEvent( const WheelEvent& event )
1768  {
1769  return false;
1770  }
1771 
1775  void EnsureRelayoutData();
1776 
1783  Vector2 ApplySizeSetPolicy( const Vector2 size );
1784 
1785 protected:
1786 
1790 
1794 
1797 
1799 
1801 
1802  // Signals
1809 
1812 
1813  std::string mName;
1814  unsigned int mId;
1815 
1816  unsigned short mDepth :12;
1817  const bool mIsRoot : 1;
1818  const bool mIsLayer : 1;
1819  bool mIsOnStage : 1;
1820  bool mSensitive : 1;
1821  bool mLeaveRequired : 1;
1827  bool mInsideOnSizeSet : 1;
1829  bool mInheritScale : 1;
1833 
1834 private:
1835 
1837  static unsigned int mActorCounter;
1838 
1839 };
1840 
1841 } // namespace Internal
1842 
1843 // Helpers for public-api forwarding methods
1844 
1846 {
1847  DALI_ASSERT_ALWAYS( actor && "Actor handle is empty" );
1848 
1849  BaseObject& handle = actor.GetBaseObject();
1850 
1851  return static_cast< Internal::Actor& >( handle );
1852 }
1853 
1854 inline const Internal::Actor& GetImplementation( const Dali::Actor& actor )
1855 {
1856  DALI_ASSERT_ALWAYS( actor && "Actor handle is empty" );
1857 
1858  const BaseObject& handle = actor.GetBaseObject();
1859 
1860  return static_cast< const Internal::Actor& >( handle );
1861 }
1862 
1863 } // namespace Dali
1864 
1865 #endif // __DALI_INTERNAL_ACTOR_H__
Dali Docs Home
Read more about Dali