Fix SCREEN_POSITION error
[platform/core/uifw/dali-core.git] / dali / internal / event / actors / actor-impl.cpp
index e0e1604..d36e103 100644 (file)
@@ -33,7 +33,6 @@
 #include <dali/public-api/math/radian.h>
 #include <dali/public-api/object/type-registry.h>
 #include <dali/devel-api/actors/actor-devel.h>
-#include <dali/devel-api/object/weak-handle.h>
 #include <dali/devel-api/scripting/scripting.h>
 #include <dali/internal/common/internal-constants.h>
 #include <dali/internal/event/common/event-thread-services.h>
@@ -208,6 +207,8 @@ DALI_PROPERTY( "minimumSize",               VECTOR2,  true,  false, false, Dali:
 DALI_PROPERTY( "maximumSize",               VECTOR2,  true,  false, false, Dali::Actor::Property::MAXIMUM_SIZE )
 DALI_PROPERTY( "inheritPosition",           BOOLEAN,  true,  false, false, Dali::Actor::Property::INHERIT_POSITION )
 DALI_PROPERTY( "clippingMode",              STRING,   true,  false, false, Dali::Actor::Property::CLIPPING_MODE )
+DALI_PROPERTY( "layoutDirection",           STRING,   true,  false, false, Dali::Actor::Property::LAYOUT_DIRECTION )
+DALI_PROPERTY( "inheritLayoutDirection",    BOOLEAN,  true,  false, false, Dali::Actor::Property::INHERIT_LAYOUT_DIRECTION )
 DALI_PROPERTY( "siblingOrder",              INTEGER,  true,  false, false, Dali::DevelActor::Property::SIBLING_ORDER )
 DALI_PROPERTY( "opacity",                   FLOAT,    true,  true,  true,  Dali::DevelActor::Property::OPACITY )
 DALI_PROPERTY( "screenPosition",            VECTOR2,  false, false, false, Dali::DevelActor::Property::SCREEN_POSITION )
@@ -307,6 +308,10 @@ DALI_ENUM_TO_STRING_WITH_SCOPE( ClippingMode, DISABLED )
 DALI_ENUM_TO_STRING_WITH_SCOPE( ClippingMode, CLIP_CHILDREN )
 DALI_ENUM_TO_STRING_TABLE_END( CLIPPING_MODE )
 
+DALI_ENUM_TO_STRING_TABLE_BEGIN( LAYOUT_DIRECTION )
+DALI_ENUM_TO_STRING_WITH_SCOPE( LayoutDirection, LEFT_TO_RIGHT )
+DALI_ENUM_TO_STRING_WITH_SCOPE( LayoutDirection, RIGHT_TO_LEFT )
+DALI_ENUM_TO_STRING_TABLE_END( LAYOUT_DIRECTION )
 
 bool GetAnchorPointConstant( const std::string& value, Vector3& anchor )
 {
@@ -489,6 +494,8 @@ void Actor::Add( Actor& child )
       // Notification for derived classes
       OnChildAdd( child );
 
+      InheritLayoutDirectionRecursively( ActorPtr( &child ), mLayoutDirection );
+
       // Only put in a relayout request if there is a suitable dependency
       if( RelayoutDependentOnChildren() )
       {
@@ -811,7 +818,7 @@ const Vector2 Actor::GetCurrentScreenPosition() const
   {
     StagePtr stage = Stage::GetCurrent();
     Vector3 worldPosition =  mNode->GetWorldPosition( GetEventThreadServices().GetEventBufferIndex() );
-    Vector3 actorSize = GetCurrentSize() * GetCurrentScale();
+    Vector3 actorSize = GetCurrentSize() * GetCurrentWorldScale();
     Vector2 halfStageSize( stage->GetSize() * 0.5f ); // World position origin is center of stage
     Vector3 halfActorSize( actorSize * 0.5f );
     Vector3 anchorPointOffSet = halfActorSize - actorSize * ( mPositionUsesAnchorPoint ? GetCurrentAnchorPoint() : AnchorPoint::TOP_LEFT );
@@ -1986,6 +1993,15 @@ void Actor::EmitVisibilityChangedSignal( bool visible, DevelActor::VisibilityCha
   }
 }
 
+void Actor::EmitLayoutDirectionChangedSignal( LayoutDirection::Type type )
+{
+  if( ! mLayoutDirectionChangedSignal.Empty() )
+  {
+    Dali::Actor handle( this );
+    mLayoutDirectionChangedSignal.Emit( handle, type );
+  }
+}
+
 Dali::Actor::TouchSignalType& Actor::TouchedSignal()
 {
   return mTouchedSignal;
@@ -2026,6 +2042,11 @@ DevelActor::VisibilityChangedSignalType& Actor::VisibilityChangedSignal()
   return mVisibilityChangedSignal;
 }
 
+Dali::Actor::LayoutDirectionChangedSignalType& Actor::LayoutDirectionChangedSignal()
+{
+  return mLayoutDirectionChangedSignal;
+}
+
 bool Actor::DoConnectSignal( BaseObject* object, ConnectionTrackerInterface* tracker, const std::string& signalName, FunctorDelegate* functor )
 {
   bool connected( true );
@@ -2102,6 +2123,8 @@ Actor::Actor( DerivedType derivedType )
   mInheritScale( true ),
   mPositionUsesAnchorPoint( true ),
   mVisible( true ),
+  mInheritLayoutDirection( true ),
+  mLayoutDirection( LayoutDirection::LEFT_TO_RIGHT ),
   mDrawMode( DrawMode::NORMAL ),
   mPositionInheritanceMode( Node::DEFAULT_POSITION_INHERITANCE_MODE ),
   mColorMode( Node::DEFAULT_COLOR_MODE ),
@@ -2860,6 +2883,28 @@ void Actor::SetDefaultProperty( Property::Index index, const Property::Value& pr
       break;
     }
 
+    case Dali::Actor::Property::LAYOUT_DIRECTION:
+    {
+      Dali::LayoutDirection::Type direction = mLayoutDirection;
+      mInheritLayoutDirection = false;
+
+      if( Scripting::GetEnumerationProperty< LayoutDirection::Type >( property, LAYOUT_DIRECTION_TABLE, LAYOUT_DIRECTION_TABLE_COUNT, direction ) )
+      {
+        InheritLayoutDirectionRecursively( this, direction, true );
+      }
+      break;
+    }
+
+    case Dali::Actor::Property::INHERIT_LAYOUT_DIRECTION:
+    {
+      bool value = false;
+      if( property.Get( value ) )
+      {
+        SetInheritLayoutDirection( value );
+      }
+      break;
+    }
+
     default:
     {
       // this can happen in the case of a non-animatable default property so just do nothing
@@ -4102,6 +4147,18 @@ bool Actor::GetCachedPropertyValue( Property::Index index, Property::Value& valu
       break;
     }
 
+    case Dali::Actor::Property::LAYOUT_DIRECTION:
+    {
+      value = mLayoutDirection;
+      break;
+    }
+
+    case Dali::Actor::Property::INHERIT_LAYOUT_DIRECTION:
+    {
+      value = IsLayoutDirectionInherited();
+      break;
+    }
+
     default:
     {
       // Must be a scene-graph only property
@@ -4742,7 +4799,7 @@ void Actor::NegotiateDimensions( const Vector2& allocatedSize )
   }
 }
 
-Vector2 Actor::ApplySizeSetPolicy( const Vector2 size )
+Vector2 Actor::ApplySizeSetPolicy( const Vector2& size )
 {
   switch( mRelayoutData->sizeSetPolicy )
   {
@@ -4864,8 +4921,6 @@ void Actor::NegotiateSize( const Vector2& allocatedSize, RelayoutContainer& cont
   SetNegotiatedSize( container );
 
   // Negotiate down to children
-  const Vector2 newBounds = mTargetSize.GetVectorXY();
-
   for( unsigned int i = 0, count = GetChildCount(); i < count; ++i )
   {
     ActorPtr child = GetChildAt( i );
@@ -4887,7 +4942,7 @@ void Actor::NegotiateSize( const Vector2& allocatedSize, RelayoutContainer& cont
     // Only relayout if required
     if( child->RelayoutRequired() )
     {
-      container.Add( Dali::Actor( child.Get() ), newBounds );
+      container.Add( Dali::Actor( child.Get() ), mTargetSize.GetVectorXY() );
     }
   }
   DALI_LOG_TIMER_END( NegSizeTimer1, gLogRelayoutFilter, Debug::Concise, "NegotiateSize() took: ");
@@ -5153,7 +5208,7 @@ void Actor::Lower()
     ActorContainer& siblings = *(mParent->mChildren);
     if( siblings.front() != this ) // If not already at beginning
     {
-      for( size_t i=0; i<siblings.size(); ++i )
+      for( size_t i=1; i<siblings.size(); ++i )
       {
         if( siblings[i] == this )
         {
@@ -5274,6 +5329,46 @@ void Actor::LowerBelow( Internal::Actor& target )
   }
 }
 
+void Actor::SetInheritLayoutDirection( bool inherit )
+{
+  if( mInheritLayoutDirection != inherit )
+  {
+    mInheritLayoutDirection = inherit;
+
+    if( inherit && mParent )
+    {
+      InheritLayoutDirectionRecursively( this, mParent->mLayoutDirection );
+    }
+  }
+}
+
+bool Actor::IsLayoutDirectionInherited() const
+{
+  return mInheritLayoutDirection;
+}
+
+void Actor::InheritLayoutDirectionRecursively( ActorPtr actor, Dali::LayoutDirection::Type direction, bool set )
+{
+  if( actor && ( actor->mInheritLayoutDirection || set ) )
+  {
+    if( actor->mLayoutDirection != direction)
+    {
+      actor->mLayoutDirection = direction;
+      actor->EmitLayoutDirectionChangedSignal( direction );
+      actor->RelayoutRequest();
+    }
+
+    if( actor->GetChildCount() > 0 )
+    {
+      ActorContainer& children = actor->GetChildrenInternal();
+      for( ActorIter iter = children.begin(), endIter = children.end(); iter != endIter; ++iter )
+      {
+        InheritLayoutDirectionRecursively( *iter, direction );
+      }
+    }
+  }
+}
+
 } // namespace Internal
 
 } // namespace Dali